Oppaitime's version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

post_history.php 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <?php
  2. /*
  3. User post history page
  4. */
  5. if (!empty($LoggedUser['DisableForums'])) {
  6. error(403);
  7. }
  8. $UserID = empty($_GET['userid']) ? $LoggedUser['ID'] : $_GET['userid'];
  9. if (!is_number($UserID)) {
  10. error(0);
  11. }
  12. if (isset($LoggedUser['PostsPerPage'])) {
  13. $PerPage = $LoggedUser['PostsPerPage'];
  14. } else {
  15. $PerPage = POSTS_PER_PAGE;
  16. }
  17. list($Page, $Limit) = Format::page_limit($PerPage);
  18. $UserInfo = Users::user_info($UserID);
  19. extract(array_intersect_key($UserInfo, array_flip(array('Username', 'Enabled', 'Title', 'Avatar', 'Donor', 'Warned'))));
  20. View::show_header("Post history for $Username", 'subscriptions,comments,bbcode');
  21. $ViewingOwn = ($UserID == $LoggedUser['ID']);
  22. $ShowUnread = ($ViewingOwn && (!isset($_GET['showunread']) || !!$_GET['showunread']));
  23. $ShowGrouped = ($ViewingOwn && (!isset($_GET['group']) || !!$_GET['group']));
  24. if ($ShowGrouped) {
  25. $sql = '
  26. SELECT
  27. SQL_CALC_FOUND_ROWS
  28. MAX(p.ID) AS ID
  29. FROM forums_posts AS p
  30. LEFT JOIN forums_topics AS t ON t.ID = p.TopicID';
  31. if ($ShowUnread) {
  32. $sql .= '
  33. LEFT JOIN forums_last_read_topics AS l ON l.TopicID = t.ID AND l.UserID = '.$LoggedUser['ID'];
  34. }
  35. $sql .= "
  36. LEFT JOIN forums AS f ON f.ID = t.ForumID
  37. WHERE p.AuthorID = $UserID
  38. AND " . Forums::user_forums_sql();
  39. if ($ShowUnread) {
  40. $sql .= '
  41. AND ((t.IsLocked = \'0\' OR t.IsSticky = \'1\')
  42. AND (l.PostID < t.LastPostID OR l.PostID IS NULL))';
  43. }
  44. $sql .= "
  45. GROUP BY t.ID
  46. ORDER BY p.ID DESC
  47. LIMIT $Limit";
  48. $PostIDs = $DB->query($sql);
  49. $DB->query('SELECT FOUND_ROWS()');
  50. list($Results) = $DB->next_record();
  51. if ($Results > $PerPage * ($Page - 1)) {
  52. $DB->set_query_id($PostIDs);
  53. $PostIDs = $DB->collect('ID');
  54. $sql = "
  55. SELECT
  56. p.ID,
  57. p.AddedTime,
  58. p.Body,
  59. p.EditedUserID,
  60. p.EditedTime,
  61. ed.Username,
  62. p.TopicID,
  63. t.Title,
  64. t.LastPostID,
  65. l.PostID AS LastRead,
  66. t.IsLocked,
  67. t.IsSticky
  68. FROM forums_posts AS p
  69. LEFT JOIN users_main AS um ON um.ID = p.AuthorID
  70. LEFT JOIN users_info AS ui ON ui.UserID = p.AuthorID
  71. LEFT JOIN users_main AS ed ON ed.ID = p.EditedUserID
  72. JOIN forums_topics AS t ON t.ID = p.TopicID
  73. JOIN forums AS f ON f.ID = t.ForumID
  74. LEFT JOIN forums_last_read_topics AS l ON l.UserID = $UserID
  75. AND l.TopicID = t.ID
  76. WHERE p.ID IN (".implode(',', $PostIDs).')
  77. ORDER BY p.ID DESC';
  78. $Posts = $DB->query($sql);
  79. }
  80. } else {
  81. $sql = '
  82. SELECT
  83. SQL_CALC_FOUND_ROWS';
  84. if ($ShowGrouped) {
  85. $sql .= '
  86. *
  87. FROM (
  88. SELECT';
  89. }
  90. $sql .= '
  91. p.ID,
  92. p.AddedTime,
  93. p.Body,
  94. p.EditedUserID,
  95. p.EditedTime,
  96. ed.Username,
  97. p.TopicID,
  98. t.Title,
  99. t.LastPostID,';
  100. $sql .= ($UserID == $LoggedUser['ID']) ? '
  101. l.PostID AS LastRead,':'
  102. true AS LastRead,';
  103. $sql .= "
  104. t.IsLocked,
  105. t.IsSticky
  106. FROM forums_posts AS p
  107. LEFT JOIN users_main AS um ON um.ID = p.AuthorID
  108. LEFT JOIN users_info AS ui ON ui.UserID = p.AuthorID
  109. LEFT JOIN users_main AS ed ON ed.ID = p.EditedUserID
  110. JOIN forums_topics AS t ON t.ID = p.TopicID
  111. JOIN forums AS f ON f.ID = t.ForumID
  112. LEFT JOIN forums_last_read_topics AS l ON l.UserID = $UserID AND l.TopicID = t.ID
  113. WHERE p.AuthorID = $UserID
  114. AND " . Forums::user_forums_sql();
  115. if ($ShowUnread) {
  116. $sql .= '
  117. AND ( (t.IsLocked = \'0\' OR t.IsSticky = \'1\')
  118. AND (l.PostID < t.LastPostID OR l.PostID IS NULL)
  119. ) ';
  120. }
  121. $sql .= '
  122. ORDER BY p.ID DESC';
  123. if ($ShowGrouped) {
  124. $sql .= '
  125. ) AS sub
  126. GROUP BY TopicID
  127. ORDER BY ID DESC';
  128. }
  129. $sql .= " LIMIT $Limit";
  130. $Posts = $DB->query($sql);
  131. $DB->query('SELECT FOUND_ROWS()');
  132. list($Results) = $DB->next_record();
  133. $DB->set_query_id($Posts);
  134. }
  135. ?>
  136. <div class="thin">
  137. <div class="header">
  138. <h2>
  139. <?
  140. if ($ShowGrouped) {
  141. echo 'Grouped '.($ShowUnread ? 'unread ' : '')."post history for <a href=\"user.php?id=$UserID\">$Username</a>";
  142. }
  143. elseif ($ShowUnread) {
  144. echo "Unread post history for <a href=\"user.php?id=$UserID\">$Username</a>";
  145. }
  146. else {
  147. echo "Post history for <a href=\"user.php?id=$UserID\">$Username</a>";
  148. }
  149. ?>
  150. </h2>
  151. <div class="linkbox">
  152. <br /><br />
  153. <?
  154. if ($ViewingOwn) {
  155. $UserSubscriptions = Subscriptions::get_subscriptions();
  156. if (!$ShowUnread) {
  157. if ($ShowGrouped) { ?>
  158. <a href="userhistory.php?action=posts&amp;userid=<?=$UserID?>&amp;showunread=0&amp;group=0" class="brackets">Show all posts</a>&nbsp;&nbsp;&nbsp;
  159. <? } else { ?>
  160. <a href="userhistory.php?action=posts&amp;userid=<?=$UserID?>&amp;showunread=0&amp;group=1" class="brackets">Show all posts (grouped)</a>&nbsp;&nbsp;&nbsp;
  161. <? } ?>
  162. <a href="userhistory.php?action=posts&amp;userid=<?=$UserID?>&amp;showunread=1&amp;group=1" class="brackets">Only display posts with unread replies (grouped)</a>&nbsp;&nbsp;&nbsp;
  163. <? } else { ?>
  164. <a href="userhistory.php?action=posts&amp;userid=<?=$UserID?>&amp;showunread=0&amp;group=0" class="brackets">Show all posts</a>&nbsp;&nbsp;&nbsp;
  165. <? if (!$ShowGrouped) { ?>
  166. <a href="userhistory.php?action=posts&amp;userid=<?=$UserID?>&amp;showunread=1&amp;group=1" class="brackets">Only display posts with unread replies (grouped)</a>&nbsp;&nbsp;&nbsp;
  167. <? } else { ?>
  168. <a href="userhistory.php?action=posts&amp;userid=<?=$UserID?>&amp;showunread=1&amp;group=0" class="brackets">Only display posts with unread replies</a>&nbsp;&nbsp;&nbsp;
  169. <? }
  170. }
  171. ?>
  172. <a href="userhistory.php?action=subscriptions" class="brackets">Go to subscriptions</a>
  173. <?
  174. } else {
  175. ?>
  176. <a href="forums.php?action=search&amp;type=body&amp;user=<?=$Username?>" class="brackets">Search</a>
  177. <?
  178. }
  179. ?>
  180. </div>
  181. </div>
  182. <?
  183. if (empty($Results)) {
  184. ?>
  185. <div class="center">
  186. No topics<?=$ShowUnread ? ' with unread posts' : '' ?>
  187. </div>
  188. <?
  189. } else {
  190. ?>
  191. <div class="linkbox">
  192. <?
  193. $Pages = Format::get_pages($Page, $Results, $PerPage, 11);
  194. echo $Pages;
  195. ?>
  196. </div>
  197. <?
  198. $QueryID = $DB->get_query_id();
  199. while (list($PostID, $AddedTime, $Body, $EditedUserID, $EditedTime, $EditedUsername, $TopicID, $ThreadTitle, $LastPostID, $LastRead, $Locked, $Sticky) = $DB->next_record()) {
  200. ?>
  201. <table class="box forum_post vertical_margin<?=!Users::has_avatars_enabled() ? ' noavatar' : '' ?>" id="post<?=$PostID ?>">
  202. <colgroup>
  203. <? if (Users::has_avatars_enabled()) { ?>
  204. <col class="col_avatar" />
  205. <? } ?>
  206. <col class="col_post_body" />
  207. </colgroup>
  208. <tr class="colhead_dark">
  209. <td colspan="<?=Users::has_avatars_enabled() ? 2 : 1 ?>">
  210. <span style="float: left;">
  211. <?=time_diff($AddedTime) ?>
  212. in <a href="forums.php?action=viewthread&amp;threadid=<?=$TopicID?>&amp;postid=<?=$PostID?>#post<?=$PostID?>" class="tooltip" title="<?=display_str($ThreadTitle)?>"><?=Format::cut_string($ThreadTitle, 75)?></a>
  213. <?
  214. if ($ViewingOwn) {
  215. if ((!$Locked || $Sticky) && (!$LastRead || $LastRead < $LastPostID)) { ?>
  216. <span class="new">(New!)</span>
  217. <?
  218. }
  219. ?>
  220. </span>
  221. <? if (!empty($LastRead)) { ?>
  222. <span style="float: left;" class="tooltip last_read" title="Jump to last read">
  223. <a href="forums.php?action=viewthread&amp;threadid=<?=$TopicID?>&amp;postid=<?=$LastRead?>#post<?=$LastRead?>"></a>
  224. </span>
  225. <? }
  226. } else {
  227. ?>
  228. </span>
  229. <? }
  230. ?>
  231. <span id="bar<?=$PostID ?>" style="float: right;">
  232. <? if ($ViewingOwn && !in_array($TopicID, $UserSubscriptions)) { ?>
  233. <a href="#" onclick="Subscribe(<?=$TopicID?>); $('.subscribelink<?=$TopicID?>').remove(); return false;" class="brackets subscribelink<?=$TopicID?>">Subscribe</a>
  234. &nbsp;
  235. <? } ?>
  236. <a href="#">&uarr;</a>
  237. </span>
  238. </td>
  239. </tr>
  240. <?
  241. if (!$ShowGrouped) {
  242. ?>
  243. <tr>
  244. <? if (Users::has_avatars_enabled()) { ?>
  245. <td class="avatar" valign="top">
  246. <?=Users::show_avatar($Avatar, $UserID, $Username, $HeavyInfo['DisableAvatars'])?>
  247. </td>
  248. <? } ?>
  249. <td class="body" valign="top">
  250. <div id="content<?=$PostID?>">
  251. <?=Text::full_format($Body)?>
  252. <? if ($EditedUserID) { ?>
  253. <br />
  254. <br />
  255. <? if (check_perms('site_moderate_forums')) { ?>
  256. <a href="#content<?=$PostID?>" onclick="LoadEdit(<?=$PostID?>, 1);">&laquo;</a>
  257. <? } ?>
  258. Last edited by
  259. <?=Users::format_username($EditedUserID, false, false, false) ?> <?=time_diff($EditedTime, 2, true, true)?>
  260. <? } ?>
  261. </div>
  262. </td>
  263. </tr>
  264. <? }
  265. $DB->set_query_id($QueryID);
  266. ?>
  267. </table>
  268. <? } ?>
  269. <div class="linkbox">
  270. <?=$Pages?>
  271. </div>
  272. <? } ?>
  273. </div>
  274. <? View::show_footer(); ?>