PageRenderTime 40ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/dead/userhistory.php

https://bitbucket.org/nexea/x00n
PHP | 260 lines | 141 code | 102 blank | 17 comment | 33 complexity | a1fcc372bdb32d071898999d71e52cc5 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?
  2. ob_start("ob_gzhandler");
  3. require "include/bittorrent.php";
  4. dbconn(false);
  5. loggedinorreturn();
  6. $userid = $_GET["id"];
  7. if (!is_valid_id($userid)) stderr("Error", "Invalid ID");
  8. if (get_user_class()< UC_POWER_USER || ($CURUSER["id"] != $userid && get_user_class() < UC_MODERATOR))
  9. stderr("Error", "Permission denied");
  10. $page = $_GET["page"];
  11. $action = $_GET["action"];
  12. //-------- Global variables
  13. $perpage = 25;
  14. //-------- Action: View posts
  15. if ($action == "viewposts")
  16. {
  17. $select_is = "COUNT(DISTINCT p.id)";
  18. $from_is = "posts AS p JOIN topics as t ON p.topicid = t.id JOIN forums AS f ON t.forumid = f.id";
  19. $where_is = "p.userid = $userid AND f.minclassread <= " . $CURUSER['class'];
  20. $order_is = "p.id DESC";
  21. $query = "SELECT $select_is FROM $from_is WHERE $where_is";
  22. $res = mysql_query($query) or mysql_error();
  23. $arr = mysql_fetch_row($res) or stderr("Error", "No posts found");
  24. $postcount = $arr[0];
  25. //------ Make page menu
  26. list($pagertop, $pagerbottom, $limit) = pager($perpage, $postcount, $_SERVER["PHP_SELF"] . "?action=viewposts&id=$userid&");
  27. //------ Get user data
  28. $res = mysql_query("SELECT username, donor, warned, enabled FROM users WHERE id=$userid") or mysql_error();
  29. if (mysql_num_rows($res) == 1)
  30. {
  31. $arr = mysql_fetch_assoc($res);
  32. $subject = "<a href=userdetails.php?id=$userid><b>$arr[username]</b></a>" . get_user_icons($arr, true);
  33. }
  34. else
  35. $subject = "unknown[$userid]";
  36. //------ Get posts
  37. $from_is = "posts AS p JOIN topics as t ON p.topicid = t.id JOIN forums AS f ON t.forumid = f.id LEFT JOIN readposts as r ON p.topicid = r.topicid AND p.userid = r.userid";
  38. $select_is = "f.id AS f_id, f.name, t.id AS t_id, t.subject, t.lastpost, r.lastpostread, p.*";
  39. $query = "SELECT $select_is FROM $from_is WHERE $where_is ORDER BY $order_is $limit";
  40. $res = mysql_query($query) or mysql_error();
  41. if (mysql_num_rows($res) == 0) stderr("Error", "No posts found");
  42. stdhead("Posts history");
  43. print("<h1>Post history for $subject</h1>\n");
  44. if ($postcount > $perpage) echo $pagertop;
  45. //------ Print table
  46. begin_main_frame();
  47. begin_frame();
  48. while ($arr = mysql_fetch_assoc($res))
  49. {
  50. $postid = $arr["id"];
  51. $posterid = $arr["userid"];
  52. $topicid = $arr["t_id"];
  53. $topicname = $arr["subject"];
  54. $forumid = $arr["f_id"];
  55. $forumname = $arr["name"];
  56. $newposts = ($arr["lastpostread"] < $arr["lastpost"]) && $CURUSER["id"] == $userid;
  57. $added = $arr["added"] . " GMT (" . (get_elapsed_time(sql_timestamp_to_unix_timestamp($arr["added"]))) . " ago)";
  58. print("<p class=sub><table border=0 cellspacing=0 cellpadding=0><tr><td class=embedded>
  59. $added&nbsp;--&nbsp;<b>Forum:&nbsp;</b>
  60. <a href=/forums.php?action=viewforum&forumid=$forumid>$forumname</a>
  61. &nbsp;--&nbsp;<b>Topic:&nbsp;</b>
  62. <a href=/forums.php?action=viewtopic&topicid=$topicid>$topicname</a>
  63. &nbsp;--&nbsp;<b>Post:&nbsp;</b>
  64. #<a href=/forums.php?action=viewtopic&topicid=$topicid&page=p$postid#$postid>$postid</a>" .
  65. ($newposts ? " &nbsp;<b>(<font color=red>NEW!</font>)</b>" : "") .
  66. "</td></tr></table></p>\n");
  67. begin_table(true);
  68. $body = format_comment($arr["body"]);
  69. if (is_valid_id($arr['editedby']))
  70. {
  71. $subres = mysql_query("SELECT username FROM users WHERE id=$arr[editedby]");
  72. if (mysql_num_rows($subres) == 1)
  73. {
  74. $subrow = mysql_fetch_assoc($subres);
  75. $body .= "<p><font size=1 class=small>Last edited by <a href=userdetails.php?id=$arr[editedby]><b>$subrow[username]</b></a> at $arr[editedat] GMT</font></p>\n";
  76. }
  77. }
  78. print("<tr valign=top><td class=comment>$body</td></tr>\n");
  79. end_table();
  80. }
  81. end_frame();
  82. end_main_frame();
  83. if ($postcount > $perpage) echo $pagerbottom;
  84. stdfoot();
  85. die;
  86. }
  87. //-------- Action: View comments
  88. if ($action == "viewcomments")
  89. {
  90. $select_is = "COUNT(*)";
  91. // LEFT due to orphan comments
  92. $from_is = "comments AS c LEFT JOIN torrents as t
  93. ON c.torrent = t.id";
  94. $where_is = "c.user = $userid";
  95. $order_is = "c.id DESC";
  96. $query = "SELECT $select_is FROM $from_is WHERE $where_is ORDER BY $order_is";
  97. $res = mysql_query($query) or mysql_error();
  98. $arr = mysql_fetch_row($res) or stderr("Error", "No comments found");
  99. $commentcount = $arr[0];
  100. //------ Make page menu
  101. list($pagertop, $pagerbottom, $limit) = pager($perpage, $commentcount, $_SERVER["PHP_SELF"] . "?action=viewcomments&id=$userid&");
  102. //------ Get user data
  103. $res = mysql_query("SELECT username, donor, warned, enabled FROM users WHERE id=$userid") or mysql_error();
  104. if (mysql_num_rows($res) == 1)
  105. {
  106. $arr = mysql_fetch_assoc($res);
  107. $subject = "<a href=userdetails.php?id=$userid><b>$arr[username]</b></a>" . get_user_icons($arr, true);
  108. }
  109. else
  110. $subject = "unknown[$userid]";
  111. //------ Get comments
  112. $select_is = "t.name, c.torrent AS t_id, c.id, c.added, c.text";
  113. $query = "SELECT $select_is FROM $from_is WHERE $where_is ORDER BY $order_is $limit";
  114. $res = mysql_query($query) or mysql_error();
  115. if (mysql_num_rows($res) == 0) stderr("Error", "No comments found");
  116. stdhead("Comments history");
  117. print("<h1>Comments history for $subject</h1>\n");
  118. if ($commentcount > $perpage) echo $pagertop;
  119. //------ Print table
  120. begin_main_frame();
  121. begin_frame();
  122. while ($arr = mysql_fetch_assoc($res))
  123. {
  124. $commentid = $arr["id"];
  125. $torrent = $arr["name"];
  126. // make sure the line doesn't wrap
  127. if (strlen($torrent) > 55) $torrent = substr($torrent,0,52) . "...";
  128. $torrentid = $arr["t_id"];
  129. //find the page; this code should probably be in details.php instead
  130. $subres = mysql_query("SELECT COUNT(*) FROM comments WHERE torrent = $torrentid AND id < $commentid")
  131. or mysql_error();
  132. $subrow = mysql_fetch_row($subres);
  133. $count = $subrow[0];
  134. $comm_page = floor($count/20);
  135. $page_url = $comm_page?"&page=$comm_page":"";
  136. $added = $arr["added"] . " GMT (" . (get_elapsed_time(sql_timestamp_to_unix_timestamp($arr["added"]))) . " ago)";
  137. print("<p class=sub><table border=0 cellspacing=0 cellpadding=0><tr><td class=embedded>".
  138. "$added&nbsp;---&nbsp;<b>Torrent:&nbsp;</b>".
  139. ($torrent?("<a href=/details.php?id=$torrentid&tocomm=1>$torrent</a>"):" [Deleted] ").
  140. "&nbsp;---&nbsp;<b>Comment:&nbsp;</b>#<a href=/details.php?id=$torrentid&tocomm=1$page_url>$commentid</a>
  141. </td></tr></table></p>\n");
  142. begin_table(true);
  143. $body = format_comment($arr["text"]);
  144. print("<tr valign=top><td class=comment>$body</td></tr>\n");
  145. end_table();
  146. }
  147. end_frame();
  148. end_main_frame();
  149. if ($commentcount > $perpage) echo $pagerbottom;
  150. stdfoot();
  151. die;
  152. }
  153. //-------- Handle unknown action
  154. if ($action != "")
  155. stderr("History Error", "Unknown action '$action'.");
  156. //-------- Any other case
  157. stderr("History Error", "Invalid or no query.");
  158. ?>