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.

forum.php 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <?php
  2. /**********|| Page to show individual forums || ********************************\
  3. Things to expect in $_GET:
  4. ForumID: ID of the forum curently being browsed
  5. page: The page the user's on.
  6. page = 1 is the same as no page
  7. ********************************************************************************/
  8. //---------- Things to sort out before it can start printing/generating content
  9. // Check for lame SQL injection attempts
  10. $ForumID = $_GET['forumid'];
  11. if (!is_number($ForumID)) {
  12. error(0);
  13. }
  14. $Tooltip = "tooltip";
  15. if (isset($LoggedUser['PostsPerPage'])) {
  16. $PerPage = $LoggedUser['PostsPerPage'];
  17. } else {
  18. $PerPage = POSTS_PER_PAGE;
  19. }
  20. list($Page, $Limit) = Format::page_limit(TOPICS_PER_PAGE);
  21. //---------- Get some data to start processing
  22. // Caching anything beyond the first page of any given forum is just wasting RAM.
  23. // Users are more likely to search than to browse to page 2.
  24. if ($Page == 1) {
  25. list($Forum,,,$Stickies) = $Cache->get_value("forums_$ForumID");
  26. }
  27. if (!isset($Forum) || !is_array($Forum)) {
  28. $DB->query("
  29. SELECT
  30. ID,
  31. Title,
  32. AuthorID,
  33. IsLocked,
  34. IsSticky,
  35. NumPosts,
  36. LastPostID,
  37. LastPostTime,
  38. LastPostAuthorID
  39. FROM forums_topics
  40. WHERE ForumID = '$ForumID'
  41. ORDER BY IsSticky DESC, Ranking ASC, LastPostTime DESC
  42. LIMIT $Limit"); // Can be cached until someone makes a new post
  43. $Forum = $DB->to_array('ID', MYSQLI_ASSOC, false);
  44. if ($Page == 1) {
  45. $DB->query("
  46. SELECT COUNT(ID)
  47. FROM forums_topics
  48. WHERE ForumID = '$ForumID'
  49. AND IsSticky = '1'");
  50. list($Stickies) = $DB->next_record();
  51. $Cache->cache_value("forums_$ForumID", array($Forum, '', 0, $Stickies), 0);
  52. }
  53. }
  54. if (!isset($Forums[$ForumID])) {
  55. error(404);
  56. }
  57. // Make sure they're allowed to look at the page
  58. if (!check_perms('site_moderate_forums')) {
  59. if (isset($LoggedUser['CustomForums'][$ForumID]) && $LoggedUser['CustomForums'][$ForumID] === 0) {
  60. error(403);
  61. }
  62. }
  63. $ForumName = display_str($Forums[$ForumID]['Name']);
  64. if (!Forums::check_forumperm($ForumID)) {
  65. error(403);
  66. }
  67. // Start printing
  68. View::show_header('Forums &gt; '. $Forums[$ForumID]['Name'], '', '');
  69. ?>
  70. <div class="thin">
  71. <h2><a href="forums.php">Forums</a> &gt; <?=$ForumName?></h2>
  72. <div class="linkbox">
  73. <? if (Forums::check_forumperm($ForumID, 'Write') && Forums::check_forumperm($ForumID, 'Create')) { ?>
  74. <a href="forums.php?action=new&amp;forumid=<?=$ForumID?>" class="brackets">New thread</a>
  75. <? } ?>
  76. <a data-toggle-target="#searchforum" data-toggle-replace="Hide search" class="brackets">Search this forum</a>
  77. <div id="searchforum" class="hidden center">
  78. <div style="display: inline-block;">
  79. <h3>Search this forum:</h3>
  80. <form class="search_form" name="forum" action="forums.php" method="get">
  81. <table cellpadding="6" cellspacing="1" border="0" class="layout border">
  82. <tr>
  83. <td>
  84. <input type="hidden" name="action" value="search" />
  85. <input type="hidden" name="forums[]" value="<?=$ForumID?>" />
  86. <strong>Search for:</strong>
  87. </td>
  88. <td>
  89. <input type="search" id="searchbox" name="search" size="70" />
  90. </td>
  91. </tr>
  92. <tr>
  93. <td><strong>Search in:</strong></td>
  94. <td>
  95. <input type="radio" name="type" id="type_title" value="title" checked="checked" />
  96. <label for="type_title">Titles</label>
  97. <input type="radio" name="type" id="type_body" value="body" />
  98. <label for="type_body">Post bodies</label>
  99. </td>
  100. </tr>
  101. <tr>
  102. <td><strong>Posted by:</strong></td>
  103. <td><input type="search" id="username" name="user" placeholder="Username" size="70" /></td>
  104. </tr>
  105. <tr>
  106. <td colspan="2" style="text-align: center;">
  107. <input type="submit" name="submit" value="Search" />
  108. </td>
  109. </tr>
  110. </table>
  111. </form>
  112. <br />
  113. </div>
  114. </div>
  115. </div>
  116. <? if (check_perms('site_moderate_forums')) { ?>
  117. <div class="linkbox">
  118. <a href="forums.php?action=edit_rules&amp;forumid=<?=$ForumID?>" class="brackets">Change specific rules</a>
  119. </div>
  120. <? } ?>
  121. <? if (!empty($Forums[$ForumID]['SpecificRules'])) { ?>
  122. <div class="linkbox">
  123. <strong>Forum Specific Rules</strong>
  124. <? foreach ($Forums[$ForumID]['SpecificRules'] as $ThreadIDs) {
  125. $Thread = Forums::get_thread_info($ThreadIDs);
  126. if ($Thread === null) {
  127. error(404);
  128. }
  129. ?>
  130. <br />
  131. <a href="forums.php?action=viewthread&amp;threadid=<?=$ThreadIDs?>" class="brackets"><?=display_str($Thread['Title'])?></a>
  132. <? } ?>
  133. </div>
  134. <? } ?>
  135. <div class="linkbox pager">
  136. <?
  137. $Pages = Format::get_pages($Page, $Forums[$ForumID]['NumTopics'], TOPICS_PER_PAGE, 9);
  138. echo $Pages;
  139. ?>
  140. </div>
  141. <table class="forum_index" width="100%">
  142. <tr class="colhead">
  143. <td style="width: 2%;"></td>
  144. <td>Latest</td>
  145. <td style="width: 7%;">Replies</td>
  146. <td style="width: 14%;">Author</td>
  147. </tr>
  148. <?
  149. // Check that we have content to process
  150. if (count($Forum) === 0) {
  151. ?>
  152. <tr>
  153. <td colspan="4">
  154. No threads to display in this forum!
  155. </td>
  156. </tr>
  157. <?
  158. } else {
  159. // forums_last_read_topics is a record of the last post a user read in a topic, and what page that was on
  160. $DB->query("
  161. SELECT
  162. l.TopicID,
  163. l.PostID,
  164. CEIL((
  165. SELECT COUNT(p.ID)
  166. FROM forums_posts AS p
  167. WHERE p.TopicID = l.TopicID
  168. AND p.ID <= l.PostID
  169. ) / $PerPage
  170. ) AS Page
  171. FROM forums_last_read_topics AS l
  172. WHERE l.TopicID IN (".implode(', ', array_keys($Forum)).')
  173. AND l.UserID = \''.$LoggedUser['ID'].'\'');
  174. // Turns the result set into a multi-dimensional array, with
  175. // forums_last_read_topics.TopicID as the key.
  176. // This is done here so we get the benefit of the caching, and we
  177. // don't have to make a database query for each topic on the page
  178. $LastRead = $DB->to_array('TopicID');
  179. //---------- Begin printing
  180. foreach ($Forum as $Topic) {
  181. list($TopicID, $Title, $AuthorID, $Locked, $Sticky, $PostCount, $LastID, $LastTime, $LastAuthorID) = array_values($Topic);
  182. // Build list of page links
  183. // Only do this if there is more than one page
  184. $PageLinks = [];
  185. $ShownEllipses = false;
  186. $PagesText = '';
  187. $TopicPages = ceil($PostCount / $PerPage);
  188. if ($TopicPages > 1) {
  189. $PagesText = ' (';
  190. for ($i = 1; $i <= $TopicPages; $i++) {
  191. if ($TopicPages > 4 && ($i > 2 && $i <= $TopicPages - 2)) {
  192. if (!$ShownEllipses) {
  193. $PageLinks[] = '-';
  194. $ShownEllipses = true;
  195. }
  196. continue;
  197. }
  198. $PageLinks[] = "<a href=\"forums.php?action=viewthread&amp;threadid=$TopicID&amp;page=$i\">$i</a>";
  199. }
  200. $PagesText .= implode(' ', $PageLinks);
  201. $PagesText .= ')';
  202. }
  203. // handle read/unread posts - the reason we can't cache the whole page
  204. if ((!$Locked || $Sticky) && ((empty($LastRead[$TopicID]) || $LastRead[$TopicID]['PostID'] < $LastID) && strtotime($LastTime) > $LoggedUser['CatchupTime'])) {
  205. $Read = 'unread';
  206. } else {
  207. $Read = 'read';
  208. }
  209. if ($Locked) {
  210. $Read .= '_locked';
  211. }
  212. if ($Sticky) {
  213. $Read .= '_sticky';
  214. }
  215. ?>
  216. <tr class="row">
  217. <td class="<?=$Read?> <?=$Tooltip?>" title="<?=ucwords(str_replace('_', ' ', $Read))?>"></td>
  218. <td>
  219. <span style="float: left;" class="last_topic">
  220. <?
  221. $TopicLength = 75 - (2 * count($PageLinks));
  222. unset($PageLinks);
  223. $Title = display_str($Title);
  224. $DisplayTitle = $Title;
  225. ?>
  226. <strong>
  227. <a href="forums.php?action=viewthread&amp;threadid=<?=$TopicID?>" class="tooltip" data-title-plain="<?=$Title?>"><?=Format::cut_string($DisplayTitle, $TopicLength) ?></a>
  228. </strong>
  229. <?=$PagesText?>
  230. </span>
  231. <? if (!empty($LastRead[$TopicID])) { ?>
  232. <a class="<?=$Tooltip?> last_read" title="Jump to last read" href="forums.php?action=viewthread&amp;threadid=<?=$TopicID?>&amp;page=<?=$LastRead[$TopicID]['Page']?>#post<?=$LastRead[$TopicID]['PostID']?>">
  233. <svg width="15" height="11"><polygon points="0,3 0,8 8,8 8,11 15,5.5 8,0 8,3"/></svg>
  234. </a>
  235. <? } ?>
  236. <span style="float: right;" class="last_poster">
  237. by <?=Users::format_username($LastAuthorID, false, false, false, false, false)?> <?=time_diff($LastTime,1)?>
  238. </span>
  239. </td>
  240. <td class="number_column"><?=number_format($PostCount - 1)?></td>
  241. <td><?=Users::format_username($AuthorID, false, false, false, false, false)?></td>
  242. </tr>
  243. <? }
  244. } ?>
  245. </table>
  246. <!--<div class="breadcrumbs">
  247. <a href="forums.php">Forums</a> &gt; <?=$ForumName?>
  248. </div>-->
  249. <div class="linkbox pager">
  250. <?=$Pages?>
  251. </div>
  252. <div class="linkbox"><a href="forums.php?action=catchup&amp;forumid=<?=$ForumID?>&amp;auth=<?=$LoggedUser['AuthKey']?>" class="brackets">Catch up</a></div>
  253. </div>
  254. <? View::show_footer(); ?>