PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/userhistory.php

https://github.com/Bigjoos/U-232
PHP | 273 lines | 140 code | 109 blank | 24 comment | 32 complexity | f0177d19ee04592f7d36da0dad3d584a 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 . 'pager_functions.php');
  13. require_once(INCL_DIR . 'html_functions.php');
  14. dbconn(false);
  15. loggedinorreturn();
  16. $lang = array_merge(load_language('global'), load_language('userhistory'));
  17. $userid = (int) $_GET["id"];
  18. if (!is_valid_id($userid))
  19. stderr($lang['stderr_errorhead'], $lang['stderr_invalidid']);
  20. if ($CURUSER['class'] < UC_POWER_USER || ($CURUSER["id"] != $userid && $CURUSER['class'] < UC_MODERATOR))
  21. stderr($lang['stderr_errorhead'], $lang['stderr_perms']);
  22. $page = (isset($_GET['page']) ? htmlspecialchars($_GET["page"]) : ''); // not used?
  23. $action = (isset($_GET['action']) ? htmlspecialchars($_GET["action"]) : '');
  24. //-------- Global variables
  25. $perpage = 25;
  26. $HTMLOUT = '';
  27. //-------- Action: View posts
  28. if ($action == "viewposts") {
  29. $select_is = "COUNT(DISTINCT p.id)";
  30. $from_is = "posts AS p LEFT JOIN topics as t ON p.topicid = t.id LEFT JOIN forums AS f ON t.forumid = f.id";
  31. $where_is = "p.userid = " . sqlesc($userid) . " AND f.minclassread <= " . sqlesc($CURUSER['class']);
  32. $order_is = "p.id DESC";
  33. $query = "SELECT $select_is FROM $from_is WHERE $where_is";
  34. $res = sql_query($query) or sqlerr(__FILE__, __LINE__);
  35. $arr = mysqli_fetch_row($res) or stderr($lang['stderr_errorhead'], $lang['top_noposts']);
  36. $postcount = $arr[0];
  37. //------ Make page menu
  38. $pager = pager($perpage, $postcount, "userhistory.php?action=viewposts&amp;id=$userid&amp;");
  39. //------ Get user data
  40. $res = sql_query("SELECT id, username, class, donor, warned, leechwarn, chatpost, pirate, king, enabled FROM users WHERE id=".sqlesc($userid)) or sqlerr(__FILE__, __LINE__);
  41. if (mysqli_num_rows($res) == 1) {
  42. $arr = mysqli_fetch_assoc($res);
  43. $subject = "" . format_username($arr, true);
  44. } else
  45. $subject = $lang['posts_unknown'] . '[' . $userid . ']';
  46. //------ Get posts
  47. $from_is = "posts AS p LEFT JOIN topics as t ON p.topicid = t.id LEFT JOIN forums AS f ON t.forumid = f.id LEFT JOIN readposts as r ON p.topicid = r.topicid AND p.userid = r.userid";
  48. $select_is = "f.id AS f_id, f.name, t.id AS t_id, t.subject, t.lastpost, r.lastpostread, p.*";
  49. $query = "SELECT $select_is FROM $from_is WHERE $where_is ORDER BY $order_is {$pager['limit']}";
  50. $res = sql_query($query) or sqlerr(__FILE__, __LINE__);
  51. if (mysqli_num_rows($res) == 0)
  52. stderr($lang['stderr_errorhead'], $lang['top_noposts']);
  53. $HTMLOUT .= "<h1>{$lang['top_posthfor']} $subject</h1>\n";
  54. if ($postcount > $perpage)
  55. $HTMLOUT .= $pager['pagertop'];
  56. //------ Print table
  57. $HTMLOUT .= begin_main_frame();
  58. $HTMLOUT .= begin_frame();
  59. while ($arr = mysqli_fetch_assoc($res)) {
  60. $postid = intval($arr["id"]);
  61. $posterid = intval($arr["userid"]);
  62. $topicid = intval($arr["t_id"]);
  63. $topicname = htmlspecialchars($arr["subject"]);
  64. $forumid = intval($arr["f_id"]);
  65. $forumname = htmlspecialchars($arr["name"]);
  66. $dt = (time() - $INSTALLER09['readpost_expiry']);
  67. $newposts = 0;
  68. if ($arr['added'] > $dt)
  69. $newposts = ($arr["lastpostread"] < $arr["lastpost"]) && $CURUSER["id"] == $userid;
  70. $added = get_date($arr['added'], '');
  71. $HTMLOUT .= "<div class='sub'><table border='0' cellspacing='0' cellpadding='0'>
  72. <tr><td class='embedded'>
  73. $added&nbsp;--&nbsp;<b>{$lang['posts_forum']}:&nbsp;</b>
  74. <a href='forums.php?action=viewforum&amp;forumid=$forumid'>$forumname</a>
  75. &nbsp;--&nbsp;<b>{$lang['posts_topic']}:&nbsp;</b>
  76. <a href='forums.php?action=viewtopic&amp;topicid=$topicid'>$topicname</a>
  77. &nbsp;--&nbsp;<b>{$lang['posts_post']}:&nbsp;</b>
  78. #<a href='forums.php?action=viewtopic&amp;topicid=$topicid&amp;page=p$postid#$postid'>$postid</a>" . ($newposts ? " &nbsp;<b>(<font color='red'>{$lang['posts_new']}</font>)</b>" : "") . "</td></tr></table></div>\n";
  79. $HTMLOUT .= begin_table(true);
  80. $body = format_comment($arr["body"]);
  81. if (is_valid_id($arr['editedby'])) {
  82. $subres = sql_query("SELECT username FROM users WHERE id=" . sqlesc($arr['editedby'])) or sqlerr(__FILE__, __LINE__);
  83. if (mysqli_num_rows($subres) == 1) {
  84. $subrow = mysqli_fetch_assoc($subres);
  85. $body .= "<p><font size='1' class='small'>{$lang['posts_lasteditedby']} <a href='userdetails.php?id=" . intval($arr['editedby']) . "'><b>" . htmlspecialchars($subrow['username']) . "</b></a> {$lang['posts_at']} " . get_date($arr['editedat'], 'LONG', 1, 0) . " GMT</font></p>\n";
  86. }
  87. }
  88. $HTMLOUT .= "<tr valign='top'><td class='comment'>$body</td></tr>\n";
  89. $HTMLOUT .= end_table();
  90. }
  91. $HTMLOUT .= end_frame();
  92. $HTMLOUT .= end_main_frame();
  93. if ($postcount > $perpage)
  94. $HTMLOUT .= $pager['pagerbottom'];
  95. echo stdhead($lang['head_post']) . $HTMLOUT . stdfoot();
  96. die;
  97. }
  98. //-------- Action: View comments
  99. if ($action == "viewcomments") {
  100. $select_is = "COUNT(*)";
  101. // LEFT due to orphan comments
  102. $from_is = "comments AS c LEFT JOIN torrents as t
  103. ON c.torrent = t.id";
  104. $where_is = "c.user = " . sqlesc($userid);
  105. $order_is = "c.id DESC";
  106. $query = "SELECT $select_is FROM $from_is WHERE $where_is ORDER BY $order_is";
  107. $res = sql_query($query) or sqlerr(__FILE__, __LINE__);
  108. $arr = mysqli_fetch_row($res) or stderr($lang['stderr_errorhead'], $lang['top_nocomms']);
  109. $commentcount = intval($arr[0]);
  110. //------ Make page menu
  111. $pager = pager($perpage, $commentcount, "userhistory.php?action=viewcomments&amp;id=$userid&amp;");
  112. //------ Get user data
  113. $res = sql_query("SELECT id, class, username, donor, warned, leechwarn, chatpost, pirate, king, enabled FROM users WHERE id=" . sqlesc($userid)) or sqlerr(__FILE__, __LINE__);
  114. if (mysqli_num_rows($res) == 1) {
  115. $arr = mysqli_fetch_assoc($res);
  116. $subject = "" . format_username($arr, true);
  117. } else
  118. $subject = $lang['posts_unknown'] . '[' . $userid . ']';
  119. //------ Get comments
  120. $select_is = "t.name, c.torrent AS t_id, c.id, c.added, c.text";
  121. $query = "SELECT $select_is FROM $from_is WHERE $where_is ORDER BY $order_is {$pager['limit']}";
  122. $res = sql_query($query) or sqlerr(__FILE__, __LINE__);
  123. if (mysqli_num_rows($res) == 0)
  124. stderr($lang['stderr_errorhead'], $lang['top_nocomms']);
  125. $HTMLOUT .= "<h1>{$lang['top_commhfor']} $subject</h1>\n";
  126. if ($commentcount > $perpage)
  127. $HTMLOUT .= $pager['pagertop'];
  128. //------ Print table
  129. $HTMLOUT .= begin_main_frame();
  130. $HTMLOUT .= begin_frame();
  131. while ($arr = mysqli_fetch_assoc($res)) {
  132. $commentid = intval($arr["id"]);
  133. $torrent = htmlspecialchars($arr["name"]);
  134. // make sure the line doesn't wrap
  135. if (strlen($torrent) > 55)
  136. $torrent = substr($torrent, 0, 52) . "...";
  137. $torrentid = intval($arr["t_id"]);
  138. //find the page; this code should probably be in details.php instead
  139. $subres = sql_query("SELECT COUNT(*) FROM comments WHERE torrent = " . sqlesc($torrentid) . " AND id < " . sqlesc($commentid)) or sqlerr(__FILE__, __LINE__);
  140. $subrow = mysqli_fetch_row($subres);
  141. $count = $subrow[0];
  142. $comm_page = floor($count / 20);
  143. $page_url = $comm_page ? "&amp;page=$comm_page" : "";
  144. $added = get_date($arr['added'], '') . " (" . get_date($arr['added'], '', 0, 1) . ")";
  145. $HTMLOUT .= "<div class='sub'><table border='0' cellspacing='0' cellpadding='0'><tr><td class='embedded'>" . "$added&nbsp;---&nbsp;<b>{$lang['posts_torrent']}:&nbsp;</b>" . ($torrent ? ("<a href='details.php?id=$torrentid&amp;tocomm=1'>$torrent</a>") : " [{$lang['posts_del']}] ") . "&nbsp;---&nbsp;<b>{$lang['posts_comment']}:&nbsp;</b>#<a href='details.php?id=$torrentid&amp;tocomm=1$page_url'>$commentid</a>
  146. </td></tr></table></div>\n";
  147. $HTMLOUT .= begin_table(true);
  148. $body = format_comment($arr["text"]);
  149. $HTMLOUT .= "<tr valign='top'><td class='comment'>$body</td></tr>\n";
  150. $HTMLOUT .= end_table();
  151. }
  152. $HTMLOUT .= end_frame();
  153. $HTMLOUT .= end_main_frame();
  154. if ($commentcount > $perpage)
  155. $HTMLOUT .= $pager['pagerbottom'];
  156. echo stdhead($lang['head_comm']) . $HTMLOUT . stdfoot();
  157. die;
  158. }
  159. //-------- Handle unknown action
  160. if ($action != "")
  161. stderr($lang['stderr_histerrhead'], $lang['stderr_unknownact']);
  162. //-------- Any other case
  163. stderr($lang['stderr_histerrhead'], $lang['stderr_invalidq']);
  164. ?>