BioTorrents.de’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 9.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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 › '. $Forums[$ForumID]['Name'], '', '');
  69. ?>
  70. <div class="thin">
  71. <h2><a href="forums.php">Forums</a> › <?=$ForumName?>
  72. </h2>
  73. <div class="linkbox">
  74. <?php if (Forums::check_forumperm($ForumID, 'Write') && Forums::check_forumperm($ForumID, 'Create')) { ?>
  75. <a href="forums.php?action=new&amp;forumid=<?=$ForumID?>"
  76. class="brackets">New thread</a>
  77. <?php } ?>
  78. <a data-toggle-target="#searchforum" data-toggle-replace="Hide search" class="brackets">Search this forum</a>
  79. <div id="searchforum" class="hidden center">
  80. <div style="display: inline-block;">
  81. <h3>Search this forum:</h3>
  82. <form class="search_form" name="forum" action="forums.php" method="get">
  83. <table cellpadding="6" cellspacing="1" border="0" class="layout border">
  84. <tr>
  85. <td>
  86. <input type="hidden" name="action" value="search" />
  87. <input type="hidden" name="forums[]"
  88. value="<?=$ForumID?>" />
  89. <strong>Search Terms</strong>
  90. </td>
  91. <td>
  92. <input type="search" id="searchbox" name="search" size="70" />
  93. </td>
  94. </tr>
  95. <tr>
  96. <td><strong>Search In</strong></td>
  97. <td>
  98. <input type="radio" name="type" id="type_title" value="title" checked="checked" />
  99. <label for="type_title">Title</label>&nbsp;&nbsp;
  100. <input type="radio" name="type" id="type_body" value="body" />
  101. <label for="type_body">Body</label>
  102. </td>
  103. </tr>
  104. <tr>
  105. <td><strong>Posted By</strong></td>
  106. <td><input type="search" id="username" name="user" placeholder="Username" size="70" /></td>
  107. </tr>
  108. <tr>
  109. <td colspan="2" style="text-align: center;">
  110. <input type="submit" name="submit" value="Search" />
  111. </td>
  112. </tr>
  113. </table>
  114. </form>
  115. <br />
  116. </div>
  117. </div>
  118. </div>
  119. <?php if (check_perms('site_moderate_forums')) { ?>
  120. <div class="linkbox">
  121. <a href="forums.php?action=edit_rules&amp;forumid=<?=$ForumID?>"
  122. class="brackets">Change specific rules</a>
  123. </div>
  124. <?php } ?>
  125. <?php if (!empty($Forums[$ForumID]['SpecificRules'])) { ?>
  126. <div class="linkbox">
  127. <strong>Forum Specific Rules</strong>
  128. <?php foreach ($Forums[$ForumID]['SpecificRules'] as $ThreadIDs) {
  129. $Thread = Forums::get_thread_info($ThreadIDs);
  130. if ($Thread === null) {
  131. error(404);
  132. } ?>
  133. <br />
  134. <a href="forums.php?action=viewthread&amp;threadid=<?=$ThreadIDs?>"
  135. class="brackets"><?=display_str($Thread['Title'])?></a>
  136. <?php
  137. } ?>
  138. </div>
  139. <?php } ?>
  140. <div class="linkbox pager">
  141. <?php
  142. $Pages = Format::get_pages($Page, $Forums[$ForumID]['NumTopics'], TOPICS_PER_PAGE, 9);
  143. echo $Pages;
  144. ?>
  145. </div>
  146. <table class="forum_index alternate_rows" width="100%">
  147. <tr class="colhead">
  148. <td style="width: 2%;"></td>
  149. <td>Latest</td>
  150. <td style="width: 7%;">Replies</td>
  151. <td style="width: 14%;">Author</td>
  152. </tr>
  153. <?php
  154. // Check that we have content to process
  155. if (count($Forum) === 0) {
  156. ?>
  157. <tr>
  158. <td colspan="4">
  159. No threads to display in this forum!
  160. </td>
  161. </tr>
  162. <?php
  163. } else {
  164. // forums_last_read_topics is a record of the last post a user read in a topic, and what page that was on
  165. $DB->query("
  166. SELECT
  167. l.TopicID,
  168. l.PostID,
  169. CEIL((
  170. SELECT COUNT(p.ID)
  171. FROM forums_posts AS p
  172. WHERE p.TopicID = l.TopicID
  173. AND p.ID <= l.PostID
  174. ) / $PerPage
  175. ) AS Page
  176. FROM forums_last_read_topics AS l
  177. WHERE l.TopicID IN (".implode(', ', array_keys($Forum)).')
  178. AND l.UserID = \''.$LoggedUser['ID'].'\'');
  179. // Turns the result set into a multi-dimensional array, with
  180. // forums_last_read_topics.TopicID as the key.
  181. // This is done here so we get the benefit of the caching, and we
  182. // don't have to make a database query for each topic on the page
  183. $LastRead = $DB->to_array('TopicID');
  184. //---------- Begin printing
  185. foreach ($Forum as $Topic) {
  186. list($TopicID, $Title, $AuthorID, $Locked, $Sticky, $PostCount, $LastID, $LastTime, $LastAuthorID) = array_values($Topic);
  187. // Build list of page links
  188. // Only do this if there is more than one page
  189. $PageLinks = [];
  190. $ShownEllipses = false;
  191. $PagesText = '';
  192. $TopicPages = ceil($PostCount / $PerPage);
  193. if ($TopicPages > 1) {
  194. $PagesText = ' (';
  195. for ($i = 1; $i <= $TopicPages; $i++) {
  196. if ($TopicPages > 4 && ($i > 2 && $i <= $TopicPages - 2)) {
  197. if (!$ShownEllipses) {
  198. $PageLinks[] = '-';
  199. $ShownEllipses = true;
  200. }
  201. continue;
  202. }
  203. $PageLinks[] = "<a href=\"forums.php?action=viewthread&amp;threadid=$TopicID&amp;page=$i\">$i</a>";
  204. }
  205. $PagesText .= implode(' ', $PageLinks);
  206. $PagesText .= ')';
  207. }
  208. // handle read/unread posts - the reason we can't cache the whole page
  209. if ((!$Locked || $Sticky) && ((empty($LastRead[$TopicID]) || $LastRead[$TopicID]['PostID'] < $LastID) && strtotime($LastTime) > $LoggedUser['CatchupTime'])) {
  210. $Read = 'unread';
  211. } else {
  212. $Read = 'read';
  213. }
  214. if ($Locked) {
  215. $Read .= '_locked';
  216. }
  217. if ($Sticky) {
  218. $Read .= '_sticky';
  219. } ?>
  220. <tr class="row">
  221. <td
  222. class="<?=$Read?> <?=$Tooltip?>"
  223. title="<?=ucwords(str_replace('_', ' ', $Read))?>">
  224. </td>
  225. <td>
  226. <span class="float_left last_topic">
  227. <?php
  228. $TopicLength = 75 - (2 * count($PageLinks));
  229. unset($PageLinks);
  230. $Title = display_str($Title);
  231. $DisplayTitle = $Title; ?>
  232. <strong>
  233. <a href="forums.php?action=viewthread&amp;threadid=<?=$TopicID?>"
  234. class="tooltip" data-title-plain="<?=$Title?>"><?=Format::cut_string($DisplayTitle, $TopicLength) ?></a>
  235. </strong>
  236. <?=$PagesText?>
  237. </span>
  238. <?php if (!empty($LastRead[$TopicID])) { ?>
  239. <a class="<?=$Tooltip?> last_read" title="Jump to last read"
  240. href="forums.php?action=viewthread&amp;threadid=<?=$TopicID?>&amp;page=<?=$LastRead[$TopicID]['Page']?>#post<?=$LastRead[$TopicID]['PostID']?>">
  241. <svg width="15" height="11">
  242. <polygon points="0,3 0,8 8,8 8,11 15,5.5 8,0 8,3" /></svg>
  243. </a>
  244. <?php } ?>
  245. <span class="float_right last_poster">
  246. by <?=Users::format_username($LastAuthorID, false, false, false, false, false)?>
  247. <?=time_diff($LastTime, 1)?>
  248. </span>
  249. </td>
  250. <td class="number_column"><?=number_format($PostCount - 1)?>
  251. </td>
  252. <td><?=Users::format_username($AuthorID, false, false, false, false, false)?>
  253. </td>
  254. </tr>
  255. <?php
  256. }
  257. } ?>
  258. </table>
  259. <div class="breadcrumbs">
  260. <p>
  261. <a href="forums.php">Forums</a> › <?=$ForumName?>
  262. </p>
  263. </div>
  264. <div class="linkbox pager">
  265. <?=$Pages?>
  266. </div>
  267. <div class="linkbox"><a
  268. href="forums.php?action=catchup&amp;forumid=<?=$ForumID?>&amp;auth=<?=$LoggedUser['AuthKey']?>"
  269. class="brackets">Catch up</a></div>
  270. </div>
  271. <?php View::show_footer();