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

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