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

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