PageRenderTime 85ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/comment.php

https://github.com/Bigjoos/U-232-V1
PHP | 300 lines | 197 code | 74 blank | 29 comment | 57 complexity | 9a0dc9b0e4a6f62dcb1b8d281070bb94 MD5 | raw file
  1. <?php
  2. /**
  3. * http://btdev.net:1337/svn/test/Installer09_Beta
  4. * Licence Info: GPL
  5. * Copyright (C) 2010 BTDev Installer v.1
  6. * A bittorrent tracker source based on TBDev.net/tbsource/bytemonsoon.
  7. * Project Leaders: Mindless,putyn.
  8. **/
  9. require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'include'.DIRECTORY_SEPARATOR.'bittorrent.php');
  10. require_once(INCL_DIR.'user_functions.php');
  11. require_once(INCL_DIR.'bbcode_functions.php');
  12. require_once(INCL_DIR.'torrenttable_functions.php');
  13. dbconn(false);
  14. loggedinorreturn();
  15. $lang = array_merge( load_language('global'), load_language('comment') );
  16. if ($CURUSER['suspended'] == 'yes')
  17. stderr("Sorry", "Your account is suspended");
  18. flood_limit('comments');
  19. $action = (isset($_GET['action']) ? $_GET['action'] : 0);
  20. /** comment stuffs by pdq **/
  21. $locale = 'torrent';
  22. $locale_link = 'details';
  23. $extra_link = '';
  24. $sql_1 = 'name, owner, anonymous FROM torrents';// , anonymous
  25. $name = 'name';
  26. $table_type = $locale.'s';
  27. $_GET['type'] = (isset($_GET['type']) ? $_GET['type'] : (isset($_POST['locale']) ? $_POST['locale'] : ''));
  28. if (isset($_GET['type'])) {
  29. $type_options = array('torrent' => 'details',
  30. 'request' => 'viewrequests',
  31. //'user' => 'userdetails'
  32. );
  33. if (isset($type_options[$_GET['type']])) {
  34. $locale_link = $type_options[$_GET['type']];
  35. $locale = $_GET['type'];
  36. }
  37. switch ($_GET['type']) {
  38. case 'request':
  39. $sql_1 = 'request FROM requests';
  40. $name = 'request';
  41. $extra_link = '&req_details';
  42. $table_type = $locale.'s';
  43. break;
  44. // case 'user':
  45. // $sql_1 = 'username FROM users';
  46. // $name = 'username';
  47. // $table_type = $locale.'s';
  48. // break;
  49. default :
  50. //case 'torrent':
  51. $sql_1 = 'name, owner, anonymous FROM torrents';// , anonymous
  52. $name = 'name';
  53. $table_type = $locale.'s';
  54. break;
  55. }
  56. }
  57. /** end comment stuffs by pdq **/
  58. //$get_hash = isset($_POST['hash']) ? $_POST['hash'] : (isset($_GET['hash']) ? $_GET['hash'] : '');
  59. if ($action == 'add') {
  60. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  61. $id = (isset($_POST['tid']) ? $_POST['tid'] : 0);
  62. if (!is_valid_id($id))
  63. stderr("{$lang['comment_error']}", "{$lang['comment_invalid_id']}");
  64. //$res_hash = md5($TBDEV['salt1'].$CURUSER['id']);
  65. //if ($get_hash != $res_hash)
  66. // die('Something went wrong. Please re-submit');
  67. $res = mysql_query("SELECT $sql_1 WHERE id = $id") or sqlerr(__FILE__,__LINE__);
  68. $arr = mysql_fetch_array($res, MYSQL_NUM);
  69. if (!$arr)
  70. stderr("{$lang['comment_error']}", "No $locale with that ID.");
  71. $text = (isset($_POST['text']) ? trim($_POST['text']) : '');
  72. if (!$text)
  73. stderr("{$lang['comment_error']}", "{$lang['comment_body']}");
  74. $owner = (isset($arr['owner']) ? $arr['owner'] : 0);
  75. $arr['anonymous'] = (isset($arr['anonymous']) && $arr['anonymous'] == 'yes' ? 'yes' : 'no');
  76. if ($CURUSER['id'] == $owner && $arr['anonymous'] == 'yes' || (isset($_POST['anonymous']) && $_POST['anonymous'] == 'yes'))
  77. $anon = "'yes'";
  78. else
  79. $anon = "'no'";
  80. mysql_query("INSERT INTO comments (user, $locale, added, text, ori_text, anonymous) VALUES (".$CURUSER["id"].",$id, ".time().", " . sqlesc($text) .
  81. "," . sqlesc($text) . ", $anon)");
  82. $newid = mysql_insert_id();
  83. mysql_query("UPDATE $table_type SET comments = comments + 1 WHERE id = $id") or sqlerr(__FILE__, __LINE__);
  84. $mc1->delete_value('torrent_comments_'.$id);
  85. //if ($locale == 'torrent')
  86. // mysql_query("UPDATE users SET tcomments = tcomments + 1 WHERE id = $CURUSER[id]") or sqlerr(__FILE__, __LINE__);
  87. if ($TBDEV['karma'] && isset($CURUSER['seedbonus']))
  88. mysql_query("UPDATE users SET seedbonus = seedbonus+3.0 WHERE id = $CURUSER[id]") or sqlerr(__FILE__, __LINE__);
  89. //$Cache->delete_value('MyUser_'.$_COOKIE['session_key']);
  90. header("Refresh: 0; url=$locale_link.php?id=$id$extra_link&viewcomm=$newid#comm$newid");
  91. die;
  92. }
  93. $id = (isset($_GET['tid']) ? $_GET['tid'] : 0);
  94. if (!is_valid_id($id))
  95. stderr("{$lang['comment_error']}", "{$lang['comment_invalid_id']}");
  96. $res = mysql_query("SELECT $sql_1 WHERE id = $id") or sqlerr(__FILE__,__LINE__);
  97. $arr = mysql_fetch_assoc($res);
  98. if (!$arr)
  99. stderr("{$lang['comment_error']}", "No $locale with that ID.");
  100. $HTMLOUT = '';
  101. $HTMLOUT .= "<h1>{$lang['comment_add']}'".htmlspecialchars($arr[$name])."'</h1>
  102. <br /><form method='post' action='comment.php?action=add'>
  103. <input type='hidden' name='tid' value='{$id}'/>
  104. <input type='hidden' name='locale' value='$name' />";
  105. if($TBDEV['textbbcode'] && function_exists('textbbcode'))
  106. $HTMLOUT .= textbbcode("add", "text", "");
  107. else
  108. $HTMLOUT .= "<textarea name='text' rows='10' cols='60'></textarea>";
  109. $HTMLOUT .= "<br />
  110. <label for='anonymous'>Tick this to post anonymously</label>
  111. <input id='anonymous' type='checkbox' name='anonymous' value='yes' />
  112. <br /><input type='submit' class='btn' value='{$lang['comment_doit']}' /></form>";
  113. $res = mysql_query("SELECT comments.id, text, comments.added, comments.$locale, comments.anonymous, comments.editedby, comments.editedat, username, users.id as user, users.title, users.avatar, users.offavatar, users.av_w, users.av_h, users.class, users.reputation, users.donor, users.warned FROM comments LEFT JOIN users ON comments.user = users.id WHERE $locale = $id ORDER BY comments.id DESC LIMIT 5");
  114. $allrows = array();
  115. while ($row = mysql_fetch_assoc($res))
  116. $allrows[] = $row;
  117. if (count($allrows)) {
  118. require_once(INCL_DIR.'html_functions.php');
  119. require_once(INCL_DIR.'bbcode_functions.php');
  120. require_once(INCL_DIR.'torrenttable_functions.php');
  121. $HTMLOUT .= "<h2>{$lang['comment_recent']}</h2>\n";
  122. $HTMLOUT .= commenttable($allrows, $locale);
  123. }
  124. print stdhead("{$lang['comment_add']}'".$arr[$name]."'").$HTMLOUT.stdfoot();
  125. die;
  126. }
  127. elseif ($action == "edit") {
  128. $commentid = (isset($_GET['cid']) ? $_GET['cid'] : 0);
  129. if (!is_valid_id($commentid))
  130. stderr("{$lang['comment_error']}", "{$lang['comment_invalid_id']}");
  131. $res = mysql_query("SELECT c.*, t.$name, t.id as tid FROM comments AS c LEFT JOIN $table_type AS t ON c.$locale = t.id WHERE c.id=$commentid") or sqlerr(__FILE__,__LINE__);
  132. $arr = mysql_fetch_assoc($res);
  133. if (!$arr)
  134. stderr("{$lang['comment_error']}", "{$lang['comment_invalid_id']}.");
  135. if ($arr["user"] != $CURUSER["id"] && $CURUSER['class'] < UC_MODERATOR)
  136. stderr("{$lang['comment_error']}", "{$lang['comment_denied']}");
  137. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  138. $text = (isset($_POST['text']) ? $_POST['text'] : '');
  139. if ($text == '')
  140. stderr("{$lang['comment_error']}", "{$lang['comment_body']}");
  141. $text = sqlesc($text);
  142. $editedat = time();
  143. if (isset($_POST['lasteditedby']) || $CURUSER['class'] < UC_MODERATOR)
  144. mysql_query("UPDATE comments SET text=$text, editedat=$editedat, editedby=$CURUSER[id] WHERE id=$commentid") or sqlerr(__FILE__, __LINE__);
  145. else
  146. mysql_query("UPDATE comments SET text=$text, editedat=$editedat, editedby=0 WHERE id=$commentid") or sqlerr(__FILE__, __LINE__);
  147. $mc1->delete_value('torrent_comments_'.$commentid);
  148. //$Cache->delete_value('comment_id'.$commentid);
  149. header("Refresh: 0; url=$locale_link.php?id=$arr[tid]$extra_link&viewcomm=$commentid#comm$commentid");
  150. die;
  151. }
  152. $HTMLOUT = '';
  153. $HTMLOUT .= "<h1>{$lang['comment_edit']}'".htmlspecialchars($arr[$name])."'</h1>
  154. <form method='post' action='comment.php?action=edit&amp;cid=$commentid'>
  155. <input type='hidden' name='locale' value='$name' />
  156. <input type='hidden' name='tid' value='$arr[tid]' />
  157. <input type='hidden' name='cid' value='$commentid' />";
  158. if($TBDEV['textbbcode'] && function_exists('textbbcode'))
  159. $HTMLOUT .= textbbcode("edit", "text", $arr["text"]);
  160. else
  161. $HTMLOUT .= "<textarea name='text' rows='10' cols='60'>".$arr["text"]."</textarea>";
  162. $HTMLOUT .= '
  163. <br />'.($CURUSER['class'] >= UC_MODERATOR ? '<input type="checkbox" value="lasteditedby" checked="checked" name="lasteditedby" id="lasteditedby" /> Show Last Edited By<br /><br />' : '').
  164. ' <input type="submit" class="btn" value="'.$lang['comment_doit'].'" /></form>';
  165. print stdhead("{$lang['comment_edit']}'".$arr[$name]."'").$HTMLOUT.stdfoot();
  166. die;
  167. }
  168. elseif ($action == "delete") {
  169. if ($CURUSER['class'] < UC_MODERATOR)
  170. stderr("{$lang['comment_error']}", "{$lang['comment_denied']}");
  171. $commentid = (isset($_GET['cid']) ? $_GET['cid'] : 0);
  172. $tid = (isset($_GET['tid']) ? $_GET['tid'] : 0);
  173. if (!is_valid_id($commentid))
  174. stderr("{$lang['comment_error']}", "{$lang['comment_invalid_id']}");
  175. $sure = isset($_GET["sure"]) ? (int)$_GET["sure"] : false;
  176. if (!$sure) {
  177. //$referer = $_SERVER["HTTP_REFERER"];
  178. stderr("{$lang['comment_delete']}", "{$lang['comment_about_delete']}\n" .
  179. "<a href='comment.php?action=delete&amp;cid=$commentid&amp;tid=$tid&amp;sure=1" .
  180. ($locale == 'request' ? '&amp;type=request' : '')."'>
  181. here</a> {$lang['comment_delete_sure']}");
  182. }
  183. $res = mysql_query("SELECT $locale FROM comments WHERE id=$commentid") or sqlerr(__FILE__,__LINE__);
  184. $arr = mysql_fetch_assoc($res);
  185. $id = 0;
  186. if ($arr)
  187. $id = $arr[$locale];
  188. mysql_query("DELETE FROM comments WHERE id=$commentid") or sqlerr(__FILE__,__LINE__);
  189. if ($id && mysql_affected_rows() > 0)
  190. mysql_query("UPDATE $table_type SET comments = comments - 1 WHERE id = $id");
  191. $mc1->delete_value('torrent_comments_'.$id);
  192. //$Cache->delete_value('comment_id'.$commentid);
  193. //if ($locale == 'torrent')
  194. // mysql_query("UPDATE users SET tcomments = tcomments - 1 WHERE id = $CURUSER[id]") or sqlerr(__FILE__, __LINE__);
  195. if ($TBDEV['karma'] && isset($CURUSER['seedbonus']))
  196. mysql_query("UPDATE users SET seedbonus = seedbonus+3.0 WHERE id = $CURUSER[id]") or sqlerr(__FILE__, __LINE__);
  197. //$Cache->delete_value('MyUser_'.$_COOKIE['session_key']);
  198. header("Refresh: 0; url=$locale_link.php?id=$tid$extra_link");
  199. die;
  200. }
  201. elseif ($action == "vieworiginal") {
  202. if ($CURUSER['class'] < UC_MODERATOR)
  203. stderr("{$lang['comment_error']}", "{$lang['comment_denied']}");
  204. $commentid = (isset($_GET['cid']) ? $_GET['cid'] : 0);
  205. if (!is_valid_id($commentid))
  206. stderr("{$lang['comment_error']}", "{$lang['comment_invalid_id']}");
  207. $res = mysql_query("SELECT c.*, t.$name FROM comments AS c LEFT JOIN $table_type AS t ON c.$locale = t.id WHERE c.id=$commentid") or sqlerr(__FILE__,__LINE__);
  208. $arr = mysql_fetch_assoc($res);
  209. if (!$arr)
  210. stderr("{$lang['comment_error']}", "{$lang['comment_invalid_id']} $commentid.");
  211. $HTMLOUT = '';
  212. $HTMLOUT .= "<h1>{$lang['comment_original_content']}#$commentid</h1><p>
  213. <table width='500' border='1' cellspacing='0' cellpadding='5'>
  214. <tr><td class='comment'>
  215. ".htmlspecialchars($arr["ori_text"])."
  216. </td></tr></table>";
  217. $returnto = (isset($_SERVER['HTTP_REFERER']) ? htmlspecialchars($_SERVER['HTTP_REFERER']) : 0);
  218. if ($returnto)
  219. $HTMLOUT .= "<p>(<a href='$returnto'>back</a>)</p>\n";
  220. print stdhead("{$lang['comment_original']}").$HTMLOUT.stdfoot();
  221. die;
  222. }
  223. else
  224. stderr("{$lang['comment_error']}", "{$lang['comment_unknown']}");
  225. die;
  226. ?>