Advertisement
Guest User

asdsda

a guest
Oct 22nd, 2018
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 41.57 KB | None | 0 0
  1. <?php
  2. /**
  3. * MyBB 1.8
  4. * Copyright 2014 MyBB Group, All Rights Reserved
  5. *
  6. * Website: http://www.mybb.com
  7. * License: http://www.mybb.com/about/license
  8. *
  9. */
  10.  
  11. define("IN_MYBB", 1);
  12. define('THIS_SCRIPT', 'forumdisplay.php');
  13.  
  14. $templatelist = "forumdisplay,forumdisplay_thread,forumbit_depth1_cat,forumbit_depth2_cat,forumbit_depth2_forum,forumdisplay_subforums,forumdisplay_threadlist,forumdisplay_moderatedby,forumdisplay_searchforum,forumdisplay_thread_rating,forumdisplay_threadlist_rating";
  15. $templatelist .= ",forumbit_depth1_forum_lastpost,forumdisplay_thread_multipage_page,forumdisplay_thread_multipage,forumdisplay_thread_multipage_more,forumdisplay_thread_gotounread,forumbit_depth2_forum_lastpost,forumdisplay_rules_link,forumdisplay_orderarrow,forumdisplay_newthread";
  16. $templatelist .= ",multipage,multipage_breadcrumb,multipage_end,multipage_jump_page,multipage_nextpage,multipage_page,multipage_page_current,multipage_page_link_current,multipage_prevpage,multipage_start,forumdisplay_thread_unapproved_posts,forumdisplay_nothreads";
  17. $templatelist .= ",forumjump_advanced,forumjump_special,forumjump_bit,forumdisplay_password_wrongpass,forumdisplay_password,forumdisplay_inlinemoderation_custom_tool,forumbit_subforums,forumbit_moderators,forumbit_depth2_forum_lastpost_never,forumbit_depth2_forum_lastpost_hidden";
  18. $templatelist .= ",forumdisplay_usersbrowsing_user,forumdisplay_usersbrowsing,forumdisplay_inlinemoderation,forumdisplay_thread_modbit,forumdisplay_inlinemoderation_col,forumdisplay_inlinemoderation_selectall,forumdisplay_threadlist_clearpass,forumdisplay_thread_rating_moved";
  19. $templatelist .= ",forumdisplay_announcements_announcement,forumdisplay_announcements,forumdisplay_threads_sep,forumbit_depth3_statusicon,forumbit_depth3,forumdisplay_sticky_sep,forumdisplay_thread_attachment_count,forumdisplay_rssdiscovery,forumbit_moderators_group";
  20. $templatelist .= ",forumdisplay_inlinemoderation_openclose,forumdisplay_inlinemoderation_stickunstick,forumdisplay_inlinemoderation_softdelete,forumdisplay_inlinemoderation_restore,forumdisplay_inlinemoderation_delete,forumdisplay_inlinemoderation_manage,forumdisplay_nopermission";
  21. $templatelist .= ",forumbit_depth2_forum_unapproved_posts,forumbit_depth2_forum_unapproved_threads,forumbit_moderators_user,forumdisplay_inlinemoderation_standard,forumdisplay_threadlist_prefixes_prefix,forumdisplay_threadlist_prefixes,forumdisplay_thread_icon,forumdisplay_rules";
  22. $templatelist .= ",forumdisplay_thread_deleted,forumdisplay_announcements_announcement_modbit,forumbit_depth2_forum_viewers,forumdisplay_threadlist_sortrating,forumdisplay_inlinemoderation_custom,forumdisplay_announcement_rating,forumdisplay_inlinemoderation_approveunapprove";
  23.  
  24. require_once "./global.php";
  25. require_once MYBB_ROOT."inc/functions_post.php";
  26. require_once MYBB_ROOT."inc/functions_forumlist.php";
  27. require_once MYBB_ROOT."inc/class_parser.php";
  28. $parser = new postParser;
  29.  
  30. $orderarrow = $sortsel = array('rating' => '', 'subject' => '', 'starter' => '', 'started' => '', 'replies' => '', 'views' => '', 'lastpost' => '');
  31. $ordersel = array('asc' => '', 'desc' => '');
  32. $datecutsel = array(1 => '', 5 => '', 10 => '', 20 => '', 50 => '', 75 => '', 100 => '', 365 => '', 9999 => '');
  33. $rules = '';
  34.  
  35. // Load global language phrases
  36. $lang->load("forumdisplay");
  37.  
  38. $plugins->run_hooks("forumdisplay_start");
  39.  
  40. $fid = $mybb->get_input('fid', MyBB::INPUT_INT);
  41. if($fid < 0)
  42. {
  43. switch($fid)
  44. {
  45. case "-1":
  46. $location = "index.php";
  47. break;
  48. case "-2":
  49. $location = "search.php";
  50. break;
  51. case "-3":
  52. $location = "usercp.php";
  53. break;
  54. case "-4":
  55. $location = "private.php";
  56. break;
  57. case "-5":
  58. $location = "online.php";
  59. break;
  60. }
  61. if($location)
  62. {
  63. header("Location: ".$location);
  64. exit;
  65. }
  66. }
  67.  
  68. // Get forum info
  69. $foruminfo = get_forum($fid);
  70. if(!$foruminfo)
  71. {
  72. error($lang->error_invalidforum);
  73. }
  74.  
  75. $archive_url = build_archive_link("forum", $fid);
  76.  
  77. $currentitem = $fid;
  78. build_forum_breadcrumb($fid);
  79. $parentlist = $foruminfo['parentlist'];
  80.  
  81. // To validate, turn & to &amp; but support unicode
  82. $foruminfo['name'] = preg_replace("#&(?!\#[0-9]+;)#si", "&amp;", $foruminfo['name']);
  83.  
  84. $forumpermissions = forum_permissions();
  85. $fpermissions = $forumpermissions[$fid];
  86.  
  87. if($fpermissions['canview'] != 1)
  88. {
  89. error_no_permission();
  90. }
  91.  
  92. if($mybb->user['uid'] == 0)
  93. {
  94. // Cookie'd forum read time
  95. $forumsread = array();
  96. if(isset($mybb->cookies['mybb']['forumread']))
  97. {
  98. $forumsread = my_unserialize($mybb->cookies['mybb']['forumread']);
  99. }
  100.  
  101. if(is_array($forumsread) && empty($forumsread))
  102. {
  103. if(isset($mybb->cookies['mybb']['readallforums']))
  104. {
  105. $forumsread[$fid] = $mybb->cookies['mybb']['lastvisit'];
  106. }
  107. else
  108. {
  109. $forumsread = array();
  110. }
  111. }
  112.  
  113. $query = $db->simple_select("forums", "*", "active != 0", array("order_by" => "pid, disporder"));
  114. }
  115. else
  116. {
  117. // Build a forum cache from the database
  118. $query = $db->query("
  119. SELECT f.*, fr.dateline AS lastread
  120. FROM ".TABLE_PREFIX."forums f
  121. LEFT JOIN ".TABLE_PREFIX."forumsread fr ON (fr.fid=f.fid AND fr.uid='{$mybb->user['uid']}')
  122. WHERE f.active != 0
  123. ORDER BY pid, disporder
  124. ");
  125. }
  126.  
  127. while($forum = $db->fetch_array($query))
  128. {
  129. if($mybb->user['uid'] == 0 && isset($forumsread[$forum['fid']]))
  130. {
  131. $forum['lastread'] = $forumsread[$forum['fid']];
  132. }
  133.  
  134. $fcache[$forum['pid']][$forum['disporder']][$forum['fid']] = $forum;
  135. }
  136.  
  137. // Get the forum moderators if the setting is enabled.
  138. if($mybb->settings['modlist'] != 0)
  139. {
  140. $moderatorcache = $cache->read("moderators");
  141. }
  142.  
  143. $bgcolor = "trow1";
  144. if($mybb->settings['subforumsindex'] != 0)
  145. {
  146. $showdepth = 3;
  147. }
  148. else
  149. {
  150. $showdepth = 2;
  151. }
  152.  
  153. $subforums = '';
  154. $child_forums = build_forumbits($fid, 2);
  155. $forums = $child_forums['forum_list'];
  156.  
  157. if($forums)
  158. {
  159. $lang->sub_forums_in = $lang->sprintf($lang->sub_forums_in, $foruminfo['name']);
  160. eval("\$subforums = \"".$templates->get("forumdisplay_subforums")."\";");
  161. }
  162.  
  163. $excols = "forumdisplay";
  164.  
  165. // Password protected forums
  166. check_forum_password($foruminfo['fid']);
  167.  
  168. if($foruminfo['linkto'])
  169. {
  170. header("Location: {$foruminfo['linkto']}");
  171. exit;
  172. }
  173.  
  174. // Make forum jump...
  175. if($mybb->settings['enableforumjump'] != 0)
  176. {
  177. $forumjump = build_forum_jump("", $fid, 1);
  178. }
  179.  
  180. if($foruminfo['type'] == "f" && $foruminfo['open'] != 0 && $fpermissions['canpostthreads'] != 0 && $mybb->user['suspendposting'] == 0)
  181. {
  182. eval("\$newthread = \"".$templates->get("forumdisplay_newthread")."\";");
  183. }
  184.  
  185. if($fpermissions['cansearch'] != 0 && $foruminfo['type'] == "f")
  186. {
  187. eval("\$searchforum = \"".$templates->get("forumdisplay_searchforum")."\";");
  188. }
  189.  
  190. // Gather forum stats
  191. $has_announcements = $has_modtools = false;
  192. $forum_stats = $cache->read("forumsdisplay");
  193.  
  194. if(is_array($forum_stats))
  195. {
  196. if(!empty($forum_stats[-1]['modtools']) || !empty($forum_stats[$fid]['modtools']))
  197. {
  198. // Mod tools are specific to forums, not parents
  199. $has_modtools = true;
  200. }
  201.  
  202. if(!empty($forum_stats[-1]['announcements']) || !empty($forum_stats[$fid]['announcements']))
  203. {
  204. // Global or forum-specific announcements
  205. $has_announcements = true;
  206. }
  207. }
  208.  
  209. $done_moderators = array(
  210. "users" => array(),
  211. "groups" => array()
  212. );
  213.  
  214. $moderators = '';
  215. $parentlistexploded = explode(",", $parentlist);
  216.  
  217. foreach($parentlistexploded as $mfid)
  218. {
  219. // This forum has moderators
  220. if(is_array($moderatorcache[$mfid]))
  221. {
  222. // Fetch each moderator from the cache and format it, appending it to the list
  223. foreach($moderatorcache[$mfid] as $modtype)
  224. {
  225. foreach($modtype as $moderator)
  226. {
  227. if($moderator['isgroup'])
  228. {
  229. if(in_array($moderator['id'], $done_moderators['groups']))
  230. {
  231. continue;
  232. }
  233.  
  234. $moderator['title'] = htmlspecialchars_uni($moderator['title']);
  235.  
  236. eval("\$moderators .= \"".$templates->get("forumbit_moderators_group", 1, 0)."\";");
  237. $done_moderators['groups'][] = $moderator['id'];
  238. }
  239. else
  240. {
  241. if(in_array($moderator['id'], $done_moderators['users']))
  242. {
  243. continue;
  244. }
  245.  
  246. $moderator['profilelink'] = get_profile_link($moderator['id']);
  247. $moderator['username'] = format_name(htmlspecialchars_uni($moderator['username']), $moderator['usergroup'], $moderator['displaygroup']);
  248.  
  249. eval("\$moderators .= \"".$templates->get("forumbit_moderators_user", 1, 0)."\";");
  250. $done_moderators['users'][] = $moderator['id'];
  251. }
  252. $comma = $lang->comma;
  253. }
  254. }
  255. }
  256.  
  257. if(!empty($forum_stats[$mfid]['announcements']))
  258. {
  259. $has_announcements = true;
  260. }
  261. }
  262. $comma = '';
  263.  
  264. // If we have a moderators list, load the template
  265. if($moderators)
  266. {
  267. eval("\$moderatedby = \"".$templates->get("forumdisplay_moderatedby")."\";");
  268. }
  269. else
  270. {
  271. $moderatedby = '';
  272. }
  273.  
  274. // Get the users browsing this forum.
  275. if($mybb->settings['browsingthisforum'] != 0)
  276. {
  277. $timecut = TIME_NOW - $mybb->settings['wolcutoff'];
  278.  
  279. $comma = '';
  280. $guestcount = 0;
  281. $membercount = 0;
  282. $inviscount = 0;
  283. $onlinemembers = '';
  284. $doneusers = array();
  285.  
  286. $query = $db->query("
  287. SELECT s.ip, s.uid, u.username, s.time, u.invisible, u.usergroup, u.usergroup, u.displaygroup
  288. FROM ".TABLE_PREFIX."sessions s
  289. LEFT JOIN ".TABLE_PREFIX."users u ON (s.uid=u.uid)
  290. WHERE s.time > '$timecut' AND location1='$fid' AND nopermission != 1
  291. ORDER BY u.username ASC, s.time DESC
  292. ");
  293.  
  294. while($user = $db->fetch_array($query))
  295. {
  296. if($user['uid'] == 0)
  297. {
  298. ++$guestcount;
  299. }
  300. else
  301. {
  302. if(empty($doneusers[$user['uid']]) || $doneusers[$user['uid']] < $user['time'])
  303. {
  304. $doneusers[$user['uid']] = $user['time'];
  305. ++$membercount;
  306. if($user['invisible'] == 1)
  307. {
  308. $invisiblemark = "*";
  309. ++$inviscount;
  310. }
  311. else
  312. {
  313. $invisiblemark = '';
  314. }
  315.  
  316. if($user['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1 || $user['uid'] == $mybb->user['uid'])
  317. {
  318. $user['username'] = format_name(htmlspecialchars_uni($user['username']), $user['usergroup'], $user['displaygroup']);
  319. $user['profilelink'] = build_profile_link($user['username'], $user['uid']);
  320. eval("\$onlinemembers .= \"".$templates->get("forumdisplay_usersbrowsing_user", 1, 0)."\";");
  321. $comma = $lang->comma;
  322. }
  323. }
  324. }
  325. }
  326.  
  327. $guestsonline = '';
  328. if($guestcount)
  329. {
  330. $guestsonline = $lang->sprintf($lang->users_browsing_forum_guests, $guestcount);
  331. }
  332.  
  333. $invisonline = '';
  334. if($mybb->user['invisible'] == 1)
  335. {
  336. // the user was counted as invisible user --> correct the inviscount
  337. $inviscount -= 1;
  338. }
  339. if($inviscount && $mybb->usergroup['canviewwolinvis'] != 1)
  340. {
  341. $invisonline = $lang->sprintf($lang->users_browsing_forum_invis, $inviscount);
  342. }
  343.  
  344.  
  345. $onlinesep = '';
  346. if($invisonline != '' && $onlinemembers)
  347. {
  348. $onlinesep = $lang->comma;
  349. }
  350.  
  351. $onlinesep2 = '';
  352. if($invisonline != '' && $guestcount || $onlinemembers && $guestcount)
  353. {
  354. $onlinesep2 = $lang->comma;
  355. }
  356.  
  357. eval("\$usersbrowsing = \"".$templates->get("forumdisplay_usersbrowsing")."\";");
  358. }
  359.  
  360. // Do we have any forum rules to show for this forum?
  361. $forumrules = '';
  362. if($foruminfo['rulestype'] != 0 && $foruminfo['rules'])
  363. {
  364. if(!$foruminfo['rulestitle'])
  365. {
  366. $foruminfo['rulestitle'] = $lang->sprintf($lang->forum_rules, $foruminfo['name']);
  367. }
  368.  
  369. $rules_parser = array(
  370. "allow_html" => 1,
  371. "allow_mycode" => 1,
  372. "allow_smilies" => 1,
  373. "allow_imgcode" => 1
  374. );
  375.  
  376. $foruminfo['rules'] = $parser->parse_message($foruminfo['rules'], $rules_parser);
  377. if($foruminfo['rulestype'] == 1 || $foruminfo['rulestype'] == 3)
  378. {
  379. eval("\$rules = \"".$templates->get("forumdisplay_rules")."\";");
  380. }
  381. else if($foruminfo['rulestype'] == 2)
  382. {
  383. eval("\$rules = \"".$templates->get("forumdisplay_rules_link")."\";");
  384. }
  385. }
  386.  
  387. $bgcolor = "trow1";
  388.  
  389. // Set here to fetch only approved/deleted topics (and then below for a moderator we change this).
  390. if($fpermissions['canviewdeletionnotice'] != 0)
  391. {
  392. $visibleonly = "AND visible IN (-1,1)";
  393. $tvisibleonly = "AND t.visible IN (-1,1)";
  394. }
  395. else
  396. {
  397. $visibleonly = "AND visible='1'";
  398. $tvisibleonly = "AND t.visible='1'";
  399. }
  400.  
  401. // Check if the active user is a moderator and get the inline moderation tools.
  402. if(is_moderator($fid))
  403. {
  404. eval("\$inlinemodcol = \"".$templates->get("forumdisplay_inlinemoderation_col")."\";");
  405. $ismod = true;
  406. $inlinecount = "0";
  407. $inlinemod = '';
  408. $inlinecookie = "inlinemod_forum".$fid;
  409.  
  410. if(is_moderator($fid, "canviewdeleted") == true || is_moderator($fid, "canviewunapprove") == true)
  411. {
  412. if(is_moderator($fid, "canviewunapprove") == true && is_moderator($fid, "canviewdeleted") == false)
  413. {
  414. $visibleonly = "AND visible IN (0,1)";
  415. $tvisibleonly = "AND t.visible IN (0,1)";
  416. }
  417. elseif(is_moderator($fid, "canviewdeleted") == true && is_moderator($fid, "canviewunapprove") == false)
  418. {
  419. $visibleonly = "AND visible IN (-1,1)";
  420. $tvisibleonly = "AND t.visible IN (-1,1)";
  421. }
  422. else
  423. {
  424. $visibleonly = " AND visible IN (-1,0,1)";
  425. $tvisibleonly = " AND t.visible IN (-1,0,1)";
  426. }
  427. }
  428. }
  429. else
  430. {
  431. $inlinemod = $inlinemodcol = '';
  432. $ismod = false;
  433. }
  434.  
  435. if(is_moderator($fid, "caneditposts") || $fpermissions['caneditposts'] == 1)
  436. {
  437. $can_edit_titles = 1;
  438. }
  439. else
  440. {
  441. $can_edit_titles = 0;
  442. }
  443.  
  444. unset($rating);
  445.  
  446. // Pick out some sorting options.
  447. // First, the date cut for the threads.
  448. $datecut = 9999;
  449. if(empty($mybb->input['datecut']))
  450. {
  451. // If the user manually set a date cut, use it.
  452. if(!empty($mybb->user['daysprune']))
  453. {
  454. $datecut = $mybb->user['daysprune'];
  455. }
  456. else
  457. {
  458. // If the forum has a non-default date cut, use it.
  459. if(!empty($foruminfo['defaultdatecut']))
  460. {
  461. $datecut = $foruminfo['defaultdatecut'];
  462. }
  463. }
  464. }
  465. // If there was a manual date cut override, use it.
  466. else
  467. {
  468. $datecut = $mybb->get_input('datecut', MyBB::INPUT_INT);
  469. }
  470.  
  471. $datecutsel[(int)$datecut] = ' selected="selected"';
  472. if($datecut > 0 && $datecut != 9999)
  473. {
  474. $checkdate = TIME_NOW - ($datecut * 86400);
  475. $datecutsql = "AND (lastpost >= '$checkdate' OR sticky = '1')";
  476. $datecutsql2 = "AND (t.lastpost >= '$checkdate' OR t.sticky = '1')";
  477. }
  478. else
  479. {
  480. $datecutsql = '';
  481. $datecutsql2 = '';
  482. }
  483.  
  484. // Sort by thread prefix
  485. $tprefix = $mybb->get_input('prefix', MyBB::INPUT_INT);
  486. if($tprefix > 0)
  487. {
  488. $prefixsql = "AND prefix = {$tprefix}";
  489. $prefixsql2 = "AND t.prefix = {$tprefix}";
  490. }
  491. else if($tprefix == -1)
  492. {
  493. $prefixsql = "AND prefix = 0";
  494. $prefixsql2 = "AND t.prefix = 0";
  495. }
  496. else if($tprefix == -2)
  497. {
  498. $prefixsql = "AND prefix != 0";
  499. $prefixsql2 = "AND t.prefix != 0";
  500. }
  501. else
  502. {
  503. $prefixsql = $prefixsql2 = '';
  504. }
  505.  
  506. // Pick the sort order.
  507. if(!isset($mybb->input['order']) && !empty($foruminfo['defaultsortorder']))
  508. {
  509. $mybb->input['order'] = $foruminfo['defaultsortorder'];
  510. }
  511. else
  512. {
  513. $mybb->input['order'] = $mybb->get_input('order');
  514. }
  515.  
  516. $mybb->input['order'] = htmlspecialchars_uni($mybb->get_input('order'));
  517.  
  518. switch(my_strtolower($mybb->input['order']))
  519. {
  520. case "asc":
  521. $sortordernow = "asc";
  522. $ordersel['asc'] = ' selected="selected"';
  523. $oppsort = $lang->desc;
  524. $oppsortnext = "desc";
  525. break;
  526. default:
  527. $sortordernow = "desc";
  528. $ordersel['desc'] = ' selected="selected"';
  529. $oppsort = $lang->asc;
  530. $oppsortnext = "asc";
  531. break;
  532. }
  533.  
  534. // Sort by which field?
  535. if(!isset($mybb->input['sortby']) && !empty($foruminfo['defaultsortby']))
  536. {
  537. $mybb->input['sortby'] = $foruminfo['defaultsortby'];
  538. }
  539. else
  540. {
  541. $mybb->input['sortby'] = $mybb->get_input('sortby');
  542. }
  543.  
  544. $t = 't.';
  545. $sortfield2 = '';
  546.  
  547. $sortby = htmlspecialchars_uni($mybb->input['sortby']);
  548.  
  549. switch($mybb->input['sortby'])
  550. {
  551. case "subject":
  552. $sortfield = "subject";
  553. break;
  554. case "replies":
  555. $sortfield = "replies";
  556. break;
  557. case "views":
  558. $sortfield = "views";
  559. break;
  560. case "starter":
  561. $sortfield = "username";
  562. break;
  563. case "rating":
  564. $t = "";
  565. $sortfield = "averagerating";
  566. $sortfield2 = ", t.totalratings DESC";
  567. break;
  568. case "started":
  569. $sortfield = "dateline";
  570. break;
  571. default:
  572. $sortby = "lastpost";
  573. $sortfield = "lastpost";
  574. $mybb->input['sortby'] = "lastpost";
  575. break;
  576. }
  577.  
  578. $sortsel['rating'] = ''; // Needs to be initialized in order to speed-up things. Fixes #2031
  579. $sortsel[$mybb->input['sortby']] = ' selected="selected"';
  580.  
  581. // Pick the right string to join the sort URL
  582. if($mybb->seo_support == true)
  583. {
  584. $string = "?";
  585. }
  586. else
  587. {
  588. $string = "&amp;";
  589. }
  590.  
  591. // Are we viewing a specific page?
  592. $mybb->input['page'] = $mybb->get_input('page', MyBB::INPUT_INT);
  593. if($mybb->input['page'] > 1)
  594. {
  595. $sorturl = get_forum_link($fid, $mybb->input['page']).$string."datecut=$datecut&amp;prefix=$tprefix";
  596. }
  597. else
  598. {
  599. $sorturl = get_forum_link($fid).$string."datecut=$datecut&amp;prefix=$tprefix";
  600. }
  601.  
  602. eval("\$orderarrow['$sortby'] = \"".$templates->get("forumdisplay_orderarrow")."\";");
  603.  
  604. $threadcount = 0;
  605. $useronly = $tuseronly = "";
  606. if(isset($fpermissions['canonlyviewownthreads']) && $fpermissions['canonlyviewownthreads'] == 1)
  607. {
  608. $useronly = "AND uid={$mybb->user['uid']}";
  609. $tuseronly = "AND t.uid={$mybb->user['uid']}";
  610. }
  611.  
  612. if($fpermissions['canviewthreads'] != 0)
  613. {
  614. // How many threads are there?
  615. $query = $db->simple_select("threads", "COUNT(tid) AS threads", "fid = '$fid' $useronly $visibleonly $datecutsql $prefixsql");
  616. $threadcount = $db->fetch_field($query, "threads");
  617. }
  618.  
  619. // How many pages are there?
  620. if(!$mybb->settings['threadsperpage'] || (int)$mybb->settings['threadsperpage'] < 1)
  621. {
  622. $mybb->settings['threadsperpage'] = 20;
  623. }
  624.  
  625. $perpage = $mybb->settings['threadsperpage'];
  626.  
  627. if($mybb->input['page'] > 0)
  628. {
  629. $page = $mybb->input['page'];
  630. $start = ($page-1) * $perpage;
  631. $pages = $threadcount / $perpage;
  632. $pages = ceil($pages);
  633. if($page > $pages || $page <= 0)
  634. {
  635. $start = 0;
  636. $page = 1;
  637. }
  638. }
  639. else
  640. {
  641. $start = 0;
  642. $page = 1;
  643. }
  644.  
  645. $end = $start + $perpage;
  646. $lower = $start + 1;
  647. $upper = $end;
  648.  
  649. if($upper > $threadcount)
  650. {
  651. $upper = $threadcount;
  652. }
  653.  
  654. // Assemble page URL
  655. if($mybb->input['sortby'] || $mybb->input['order'] || $mybb->input['datecut'] || $mybb->input['prefix']) // Ugly URL
  656. {
  657. $page_url = str_replace("{fid}", $fid, FORUM_URL_PAGED);
  658.  
  659. if($mybb->seo_support == true)
  660. {
  661. $q = "?";
  662. $and = '';
  663. }
  664. else
  665. {
  666. $q = '';
  667. $and = "&";
  668. }
  669.  
  670. if((!empty($foruminfo['defaultsortby']) && $sortby != $foruminfo['defaultsortby']) || (empty($foruminfo['defaultsortby']) && $sortby != "lastpost"))
  671. {
  672. $page_url .= "{$q}{$and}sortby={$sortby}";
  673. $q = '';
  674. $and = "&";
  675. }
  676.  
  677. if($sortordernow != "desc")
  678. {
  679. $page_url .= "{$q}{$and}order={$sortordernow}";
  680. $q = '';
  681. $and = "&";
  682. }
  683.  
  684. if($datecut > 0 && $datecut != 9999)
  685. {
  686. $page_url .= "{$q}{$and}datecut={$datecut}";
  687. $q = '';
  688. $and = "&";
  689. }
  690.  
  691. if($tprefix != 0)
  692. {
  693. $page_url .= "{$q}{$and}prefix={$tprefix}";
  694. }
  695. }
  696. else
  697. {
  698. $page_url = str_replace("{fid}", $fid, FORUM_URL_PAGED);
  699. }
  700. $multipage = multipage($threadcount, $perpage, $page, $page_url);
  701.  
  702. if($mybb->settings['allowthreadratings'] != 0 && $foruminfo['allowtratings'] != 0 && $fpermissions['canviewthreads'] != 0)
  703. {
  704. $lang->load("ratethread");
  705.  
  706. switch($db->type)
  707. {
  708. case "pgsql":
  709. $ratingadd = "CASE WHEN t.numratings=0 THEN 0 ELSE t.totalratings/t.numratings::numeric END AS averagerating, ";
  710. break;
  711. default:
  712. $ratingadd = "(t.totalratings/t.numratings) AS averagerating, ";
  713. }
  714.  
  715. $lpbackground = "trow2";
  716. eval("\$ratingcol = \"".$templates->get("forumdisplay_threadlist_rating")."\";");
  717. eval("\$ratingsort = \"".$templates->get("forumdisplay_threadlist_sortrating")."\";");
  718. $colspan = "7";
  719. }
  720. else
  721. {
  722. if($sortfield == "averagerating")
  723. {
  724. $t = "t.";
  725. $sortfield = "lastpost";
  726. }
  727. $ratingadd = '';
  728. $lpbackground = "trow1";
  729. $colspan = "6";
  730. }
  731.  
  732. if($ismod)
  733. {
  734. ++$colspan;
  735. }
  736.  
  737. // Get Announcements
  738. $announcementlist = '';
  739. if($has_announcements == true)
  740. {
  741. $limit = '';
  742. $announcements = '';
  743. if($mybb->settings['announcementlimit'])
  744. {
  745. $limit = "LIMIT 0, ".$mybb->settings['announcementlimit'];
  746. }
  747.  
  748. $sql = build_parent_list($fid, "fid", "OR", $parentlist);
  749. $time = TIME_NOW;
  750. $query = $db->query("
  751. SELECT a.*, u.username
  752. FROM ".TABLE_PREFIX."announcements a
  753. LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=a.uid)
  754. WHERE a.startdate<='$time' AND (a.enddate>='$time' OR a.enddate='0') AND ($sql OR fid='-1')
  755. ORDER BY a.startdate DESC $limit
  756. ");
  757.  
  758. // See if this announcement has been read in our announcement array
  759. $cookie = array();
  760. if(isset($mybb->cookies['mybb']['announcements']))
  761. {
  762. $cookie = my_unserialize(stripslashes($mybb->cookies['mybb']['announcements']));
  763. }
  764.  
  765. $announcementlist = '';
  766. $bgcolor = alt_trow(true); // Reset the trow colors
  767. while($announcement = $db->fetch_array($query))
  768. {
  769. if($announcement['startdate'] > $mybb->user['lastvisit'] && !$cookie[$announcement['aid']])
  770. {
  771. $new_class = ' class="subject_new"';
  772. $folder = "newfolder";
  773. }
  774. else
  775. {
  776. $new_class = ' class="subject_old"';
  777. $folder = "folder";
  778. }
  779.  
  780. // Mmm, eat those announcement cookies if they're older than our last visit
  781. if(isset($cookie[$announcement['aid']]) && $cookie[$announcement['aid']] < $mybb->user['lastvisit'])
  782. {
  783. unset($cookie[$announcement['aid']]);
  784. }
  785.  
  786. $announcement['announcementlink'] = get_announcement_link($announcement['aid']);
  787. $announcement['subject'] = $parser->parse_badwords($announcement['subject']);
  788. $announcement['subject'] = htmlspecialchars_uni($announcement['subject']);
  789. $postdate = my_date('relative', $announcement['startdate']);
  790.  
  791. $announcement['username'] = htmlspecialchars_uni($announcement['username']);
  792.  
  793. $announcement['profilelink'] = build_profile_link($announcement['username'], $announcement['uid']);
  794.  
  795. if($mybb->settings['allowthreadratings'] != 0 && $foruminfo['allowtratings'] != 0 && $fpermissions['canviewthreads'] != 0)
  796. {
  797. eval("\$rating = \"".$templates->get("forumdisplay_announcement_rating")."\";");
  798. $lpbackground = "trow2";
  799. }
  800. else
  801. {
  802. $rating = '';
  803. $lpbackground = "trow1";
  804. }
  805.  
  806. if($ismod)
  807. {
  808. eval("\$modann = \"".$templates->get("forumdisplay_announcements_announcement_modbit")."\";");
  809. }
  810. else
  811. {
  812. $modann = '';
  813. }
  814.  
  815. $plugins->run_hooks("forumdisplay_announcement");
  816. eval("\$announcements .= \"".$templates->get("forumdisplay_announcements_announcement")."\";");
  817. $bgcolor = alt_trow();
  818. }
  819.  
  820. if($announcements)
  821. {
  822. eval("\$announcementlist = \"".$templates->get("forumdisplay_announcements")."\";");
  823. $shownormalsep = true;
  824. }
  825.  
  826. if(empty($cookie))
  827. {
  828. // Clean up cookie crumbs
  829. my_setcookie('mybb[announcements]', 0, (TIME_NOW - (60*60*24*365)));
  830. }
  831. else if(!empty($cookie))
  832. {
  833. my_setcookie("mybb[announcements]", addslashes(my_serialize($cookie)), -1);
  834. }
  835. }
  836. else
  837. {
  838. $announcementlist = '';
  839. }
  840.  
  841. $tids = $threadcache = array();
  842. $icon_cache = $cache->read("posticons");
  843.  
  844. if($fpermissions['canviewthreads'] != 0)
  845. {
  846. $plugins->run_hooks("forumdisplay_get_threads");
  847.  
  848. // Start Getting Threads
  849. $query = $db->query("
  850. SELECT t.*, {$ratingadd}t.username AS threadusername, u.username
  851. FROM ".TABLE_PREFIX."threads t
  852. LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid)
  853. WHERE t.fid='$fid' $tuseronly $tvisibleonly $datecutsql2 $prefixsql2
  854. ORDER BY t.sticky DESC, {$t}{$sortfield} $sortordernow $sortfield2
  855. LIMIT $start, $perpage
  856. ");
  857.  
  858. $ratings = false;
  859. $moved_threads = array();
  860. while($thread = $db->fetch_array($query))
  861. {
  862. $threadcache[$thread['tid']] = $thread;
  863.  
  864. if($thread['numratings'] > 0 && $ratings == false)
  865. {
  866. $ratings = true; // Looks for ratings in the forum
  867. }
  868.  
  869. // If this is a moved thread - set the tid for participation marking and thread read marking to that of the moved thread
  870. if(substr($thread['closed'], 0, 5) == "moved")
  871. {
  872. $tid = substr($thread['closed'], 6);
  873. if(!isset($tids[$tid]))
  874. {
  875. $moved_threads[$tid] = $thread['tid'];
  876. $tids[$thread['tid']] = $tid;
  877. }
  878. }
  879. // Otherwise - set it to the plain thread ID
  880. else
  881. {
  882. $tids[$thread['tid']] = $thread['tid'];
  883. if(isset($moved_threads[$thread['tid']]))
  884. {
  885. unset($moved_threads[$thread['tid']]);
  886. }
  887. }
  888. }
  889.  
  890. if($mybb->settings['allowthreadratings'] != 0 && $foruminfo['allowtratings'] != 0 && $mybb->user['uid'] && !empty($threadcache) && $ratings == true)
  891. {
  892. // Check if we've rated threads on this page
  893. // Guests get the pleasure of not being ID'd, but will be checked when they try and rate
  894. $imp = implode(",", array_keys($threadcache));
  895. $query = $db->simple_select("threadratings", "tid, uid", "tid IN ({$imp}) AND uid = '{$mybb->user['uid']}'");
  896.  
  897. while($rating = $db->fetch_array($query))
  898. {
  899. $threadcache[$rating['tid']]['rated'] = 1;
  900. }
  901. }
  902. }
  903.  
  904. // If user has moderation tools available, prepare the Select All feature
  905. $selectall = '';
  906. if(is_moderator($fid) && $threadcount > $perpage)
  907. {
  908. $lang->page_selected = $lang->sprintf($lang->page_selected, count($threadcache));
  909. $lang->select_all = $lang->sprintf($lang->select_all, (int)$threadcount);
  910. $lang->all_selected = $lang->sprintf($lang->all_selected, (int)$threadcount);
  911. eval("\$selectall = \"".$templates->get("forumdisplay_inlinemoderation_selectall")."\";");
  912. }
  913.  
  914. if(!empty($tids))
  915. {
  916. $tids = implode(",", $tids);
  917. }
  918.  
  919. // Check participation by the current user in any of these threads - for 'dot' folder icons
  920. if($mybb->settings['dotfolders'] != 0 && $mybb->user['uid'] && !empty($threadcache))
  921. {
  922. $query = $db->simple_select("posts", "DISTINCT tid,uid", "uid='{$mybb->user['uid']}' AND tid IN ({$tids}) {$visibleonly}");
  923. while($post = $db->fetch_array($query))
  924. {
  925. if(!empty($moved_threads[$post['tid']]))
  926. {
  927. $post['tid'] = $moved_threads[$post['tid']];
  928. }
  929. if($threadcache[$post['tid']])
  930. {
  931. $threadcache[$post['tid']]['doticon'] = 1;
  932. }
  933. }
  934. }
  935.  
  936. // Read threads
  937. if($mybb->user['uid'] && $mybb->settings['threadreadcut'] > 0 && !empty($threadcache))
  938. {
  939. $query = $db->simple_select("threadsread", "*", "uid='{$mybb->user['uid']}' AND tid IN ({$tids})");
  940. while($readthread = $db->fetch_array($query))
  941. {
  942. if(!empty($moved_threads[$readthread['tid']]))
  943. {
  944. $readthread['tid'] = $moved_threads[$readthread['tid']];
  945. }
  946. if($threadcache[$readthread['tid']])
  947. {
  948. $threadcache[$readthread['tid']]['lastread'] = $readthread['dateline'];
  949. }
  950. }
  951. }
  952.  
  953. if($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid'])
  954. {
  955. $query = $db->simple_select("forumsread", "dateline", "fid='{$fid}' AND uid='{$mybb->user['uid']}'");
  956. $forum_read = $db->fetch_field($query, "dateline");
  957.  
  958. $read_cutoff = TIME_NOW-$mybb->settings['threadreadcut']*60*60*24;
  959. if($forum_read == 0 || $forum_read < $read_cutoff)
  960. {
  961. $forum_read = $read_cutoff;
  962. }
  963. }
  964. else
  965. {
  966. $forum_read = my_get_array_cookie("forumread", $fid);
  967.  
  968. if(isset($mybb->cookies['mybb']['readallforums']) && !$forum_read)
  969. {
  970. $forum_read = $mybb->cookies['mybb']['lastvisit'];
  971. }
  972. }
  973.  
  974. $unreadpost = 0;
  975. $threads = '';
  976. if(!empty($threadcache) && is_array($threadcache))
  977. {
  978. if(!$mybb->settings['maxmultipagelinks'])
  979. {
  980. $mybb->settings['maxmultipagelinks'] = 5;
  981. }
  982.  
  983. if(!$mybb->settings['postsperpage'] || (int)$mybb->settings['postsperpage'] < 1)
  984. {
  985. $mybb->settings['postsperpage'] = 20;
  986. }
  987.  
  988. foreach($threadcache as $thread)
  989. {
  990. $plugins->run_hooks("forumdisplay_thread");
  991.  
  992. $moved = explode("|", $thread['closed']);
  993.  
  994. if($thread['visible'] == 0)
  995. {
  996. $bgcolor = "trow_shaded";
  997. }
  998. elseif($thread['visible'] == -1 && is_moderator($fid, "canviewdeleted"))
  999. {
  1000. $bgcolor = "trow_shaded trow_deleted";
  1001. }
  1002. else
  1003. {
  1004. $bgcolor = alt_trow();
  1005. }
  1006.  
  1007. if($thread['sticky'] == 1)
  1008. {
  1009. $thread_type_class = " forumdisplay_sticky";
  1010. }
  1011. else
  1012. {
  1013. $thread_type_class = " forumdisplay_regular";
  1014. }
  1015.  
  1016. $folder = '';
  1017. $prefix = '';
  1018.  
  1019. $thread['author'] = $thread['uid'];
  1020. if(!$thread['username'])
  1021. {
  1022. if(!$thread['threadusername'])
  1023. {
  1024. $thread['username'] = $thread['profilelink'] = htmlspecialchars_uni($lang->guest);
  1025. }
  1026. else
  1027. {
  1028. $thread['username'] = $thread['profilelink'] = htmlspecialchars_uni($thread['threadusername']);
  1029. }
  1030. }
  1031. else
  1032. {
  1033. $thread['username'] = htmlspecialchars_uni($thread['username']);
  1034. $thread['profilelink'] = build_profile_link($thread['username'], $thread['uid']);
  1035. }
  1036.  
  1037. // If this thread has a prefix, insert a space between prefix and subject
  1038. $thread['threadprefix'] = $threadprefix = '';
  1039. if($thread['prefix'] != 0)
  1040. {
  1041. $threadprefix = build_prefixes($thread['prefix']);
  1042. if(!empty($threadprefix))
  1043. {
  1044. $thread['threadprefix'] = $threadprefix['displaystyle'].'&nbsp;';
  1045. }
  1046. }
  1047.  
  1048. $thread['subject'] = $parser->parse_badwords($thread['subject']);
  1049. $thread['subject'] = htmlspecialchars_uni($thread['subject']);
  1050.  
  1051. if($thread['icon'] > 0 && $icon_cache[$thread['icon']])
  1052. {
  1053. $icon = $icon_cache[$thread['icon']];
  1054. $icon['path'] = str_replace("{theme}", $theme['imgdir'], $icon['path']);
  1055. $icon['path'] = htmlspecialchars_uni($icon['path']);
  1056. $icon['name'] = htmlspecialchars_uni($icon['name']);
  1057. eval("\$icon = \"".$templates->get("forumdisplay_thread_icon")."\";");
  1058. }
  1059. else
  1060. {
  1061. $icon = "&nbsp;";
  1062. }
  1063.  
  1064. $prefix = '';
  1065. if($thread['poll'])
  1066. {
  1067. $prefix = $lang->poll_prefix;
  1068. }
  1069.  
  1070. if($thread['sticky'] == "1" && !isset($donestickysep))
  1071. {
  1072. eval("\$threads .= \"".$templates->get("forumdisplay_sticky_sep")."\";");
  1073. $shownormalsep = true;
  1074. $donestickysep = true;
  1075. }
  1076. else if($thread['sticky'] == 0 && !empty($shownormalsep))
  1077. {
  1078. eval("\$threads .= \"".$templates->get("forumdisplay_threads_sep")."\";");
  1079. $shownormalsep = false;
  1080. }
  1081.  
  1082. $rating = '';
  1083. if($mybb->settings['allowthreadratings'] != 0 && $foruminfo['allowtratings'] != 0)
  1084. {
  1085. if($moved[0] == "moved" || ($fpermissions['canviewdeletionnotice'] != 0 && $thread['visible'] == -1))
  1086. {
  1087. eval("\$rating = \"".$templates->get("forumdisplay_thread_rating_moved")."\";");
  1088. }
  1089. else
  1090. {
  1091. $thread['averagerating'] = (float)round($thread['averagerating'], 2);
  1092. $thread['width'] = (int)round($thread['averagerating'])*20;
  1093. $thread['numratings'] = (int)$thread['numratings'];
  1094.  
  1095. $not_rated = '';
  1096. if(!isset($thread['rated']) || empty($thread['rated']))
  1097. {
  1098. $not_rated = ' star_rating_notrated';
  1099. }
  1100.  
  1101. $ratingvotesav = $lang->sprintf($lang->rating_votes_average, $thread['numratings'], $thread['averagerating']);
  1102. eval("\$rating = \"".$templates->get("forumdisplay_thread_rating")."\";");
  1103. }
  1104. }
  1105.  
  1106. $thread['pages'] = 0;
  1107. $thread['multipage'] = '';
  1108. $threadpages = '';
  1109. $morelink = '';
  1110. $thread['posts'] = $thread['replies'] + 1;
  1111. if(is_moderator($fid, "canviewdeleted") == true || is_moderator($fid, "canviewunapprove") == true)
  1112. {
  1113. if(is_moderator($fid, "canviewdeleted") == true)
  1114. {
  1115. $thread['posts'] += $thread['deletedposts'];
  1116. }
  1117. if(is_moderator($fid, "canviewunapprove") == true)
  1118. {
  1119. $thread['posts'] += $thread['unapprovedposts'];
  1120. }
  1121. }
  1122. elseif($fpermissions['canviewdeletionnotice'] != 0)
  1123. {
  1124. $thread['posts'] += $thread['deletedposts'];
  1125. }
  1126.  
  1127. if($thread['posts'] > $mybb->settings['postsperpage'])
  1128. {
  1129. $thread['pages'] = $thread['posts'] / $mybb->settings['postsperpage'];
  1130. $thread['pages'] = ceil($thread['pages']);
  1131.  
  1132. if($thread['pages'] > $mybb->settings['maxmultipagelinks'])
  1133. {
  1134. $pagesstop = $mybb->settings['maxmultipagelinks'] - 1;
  1135. $page_link = get_thread_link($thread['tid'], $thread['pages']);
  1136. eval("\$morelink = \"".$templates->get("forumdisplay_thread_multipage_more")."\";");
  1137. }
  1138. else
  1139. {
  1140. $pagesstop = $thread['pages'];
  1141. }
  1142.  
  1143. for($i = 1; $i <= $pagesstop; ++$i)
  1144. {
  1145. $page_link = get_thread_link($thread['tid'], $i);
  1146. eval("\$threadpages .= \"".$templates->get("forumdisplay_thread_multipage_page")."\";");
  1147. }
  1148.  
  1149. eval("\$thread['multipage'] = \"".$templates->get("forumdisplay_thread_multipage")."\";");
  1150. }
  1151. else
  1152. {
  1153. $threadpages = '';
  1154. $morelink = '';
  1155. $thread['multipage'] = '';
  1156. }
  1157.  
  1158. if($ismod)
  1159. {
  1160. if(isset($mybb->cookies[$inlinecookie]) && my_strpos($mybb->cookies[$inlinecookie], "|{$thread['tid']}|") !== false)
  1161. {
  1162. $inlinecheck = "checked=\"checked\"";
  1163. ++$inlinecount;
  1164. }
  1165. else
  1166. {
  1167. $inlinecheck = '';
  1168. }
  1169.  
  1170. $multitid = $thread['tid'];
  1171. eval("\$modbit = \"".$templates->get("forumdisplay_thread_modbit")."\";");
  1172. }
  1173. else
  1174. {
  1175. $modbit = '';
  1176. }
  1177.  
  1178. if($moved[0] == "moved")
  1179. {
  1180. $prefix = $lang->moved_prefix;
  1181. $thread['tid'] = $moved[1];
  1182. $thread['replies'] = "-";
  1183. $thread['views'] = "-";
  1184. }
  1185.  
  1186. $thread['threadlink'] = get_thread_link($thread['tid']);
  1187. $thread['lastpostlink'] = get_thread_link($thread['tid'], 0, "lastpost");
  1188.  
  1189. // Determine the folder
  1190. $folder = '';
  1191. $folder_label = '';
  1192.  
  1193. if(isset($thread['doticon']))
  1194. {
  1195. $folder = "dot_";
  1196. $folder_label .= $lang->icon_dot;
  1197. }
  1198.  
  1199. $gotounread = '';
  1200. $isnew = 0;
  1201. $donenew = 0;
  1202.  
  1203. if($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid'] && $thread['lastpost'] > $forum_read)
  1204. {
  1205. if(!empty($thread['lastread']))
  1206. {
  1207. $last_read = $thread['lastread'];
  1208. }
  1209. else
  1210. {
  1211. $last_read = $read_cutoff;
  1212. }
  1213. }
  1214. else
  1215. {
  1216. $last_read = my_get_array_cookie("threadread", $thread['tid']);
  1217. }
  1218.  
  1219. if($forum_read > $last_read)
  1220. {
  1221. $last_read = $forum_read;
  1222. }
  1223.  
  1224. if($thread['lastpost'] > $last_read && $moved[0] != "moved")
  1225. {
  1226. $folder .= "new";
  1227. $folder_label .= $lang->icon_new;
  1228. $new_class = "subject_new";
  1229. $thread['newpostlink'] = get_thread_link($thread['tid'], 0, "newpost");
  1230. eval("\$gotounread = \"".$templates->get("forumdisplay_thread_gotounread")."\";");
  1231. $unreadpost = 1;
  1232. }
  1233. else
  1234. {
  1235. $folder_label .= $lang->icon_no_new;
  1236. $new_class = "subject_old";
  1237. }
  1238.  
  1239. if($thread['replies'] >= $mybb->settings['hottopic'] || $thread['views'] >= $mybb->settings['hottopicviews'])
  1240. {
  1241. $folder .= "hot";
  1242. $folder_label .= $lang->icon_hot;
  1243. }
  1244.  
  1245. if($thread['closed'] == 1)
  1246. {
  1247. $folder .= "close";
  1248. $folder_label .= $lang->icon_close;
  1249. }
  1250.  
  1251. if($moved[0] == "moved")
  1252. {
  1253. $folder = "move";
  1254. $gotounread = '';
  1255. }
  1256.  
  1257. $folder .= "folder";
  1258.  
  1259. $inline_edit_tid = $thread['tid'];
  1260.  
  1261. // If this user is the author of the thread and it is not closed or they are a moderator, they can edit
  1262. $inline_edit_class = '';
  1263. if(($thread['uid'] == $mybb->user['uid'] && $thread['closed'] != 1 && $mybb->user['uid'] != 0 && $can_edit_titles == 1) || $ismod == true)
  1264. {
  1265. $inline_edit_class = "subject_editable";
  1266. }
  1267.  
  1268.  
  1269. $lastposteruid = $thread['lastposteruid'];
  1270. if(!$lastposteruid && !$thread['lastposter'])
  1271. {
  1272. $lastposter = htmlspecialchars_uni($lang->guest);
  1273. }
  1274. else
  1275. {
  1276. $lastposter = htmlspecialchars_uni($thread['lastposter']);
  1277. }
  1278. $lastpostdate = my_date('relative', $thread['lastpost']);
  1279.  
  1280. // Don't link to guest's profiles (they have no profile).
  1281. if($lastposteruid == 0)
  1282. {
  1283. $lastposterlink = $lastposter;
  1284. }
  1285. else
  1286. {
  1287. $lastposterlink = build_profile_link($lastposter, $lastposteruid);
  1288. }
  1289.  
  1290. $thread['replies'] = my_number_format($thread['replies']);
  1291. $thread['views'] = my_number_format($thread['views']);
  1292.  
  1293. // Threads and posts requiring moderation
  1294. if($thread['unapprovedposts'] > 0 && is_moderator($fid, "canviewunapprove"))
  1295. {
  1296. if($thread['unapprovedposts'] > 1)
  1297. {
  1298. $unapproved_posts_count = $lang->sprintf($lang->thread_unapproved_posts_count, $thread['unapprovedposts']);
  1299. }
  1300. else
  1301. {
  1302. $unapproved_posts_count = $lang->sprintf($lang->thread_unapproved_post_count, 1);
  1303. }
  1304.  
  1305. $thread['unapprovedposts'] = my_number_format($thread['unapprovedposts']);
  1306. eval("\$unapproved_posts = \"".$templates->get("forumdisplay_thread_unapproved_posts")."\";");
  1307. }
  1308. else
  1309. {
  1310. $unapproved_posts = '';
  1311. }
  1312.  
  1313. // If this thread has 1 or more attachments show the papperclip
  1314. if($mybb->settings['enableattachments'] == 1 && $thread['attachmentcount'] > 0)
  1315. {
  1316. if($thread['attachmentcount'] > 1)
  1317. {
  1318. $attachment_count = $lang->sprintf($lang->attachment_count_multiple, $thread['attachmentcount']);
  1319. }
  1320. else
  1321. {
  1322. $attachment_count = $lang->attachment_count;
  1323. }
  1324.  
  1325. eval("\$attachment_count = \"".$templates->get("forumdisplay_thread_attachment_count")."\";");
  1326. }
  1327. else
  1328. {
  1329. $attachment_count = '';
  1330. }
  1331.  
  1332. $plugins->run_hooks("forumdisplay_thread_end");
  1333.  
  1334. if($fpermissions['canviewdeletionnotice'] != 0 && $thread['visible'] == -1 && !is_moderator($fid, "canviewdeleted"))
  1335. {
  1336. eval("\$threads .= \"".$templates->get("forumdisplay_thread_deleted")."\";");
  1337. }
  1338. else
  1339. {
  1340. eval("\$threads .= \"".$templates->get("forumdisplay_thread")."\";");
  1341. }
  1342. }
  1343.  
  1344. $customthreadtools = $standardthreadtools = '';
  1345. if($ismod)
  1346. {
  1347. if(is_moderator($fid, "canusecustomtools") && $has_modtools == true)
  1348. {
  1349. $gids = explode(',', $mybb->user['additionalgroups']);
  1350. $gids[] = $mybb->user['usergroup'];
  1351. $gids = array_filter(array_unique($gids));
  1352.  
  1353. $gidswhere = '';
  1354. switch($db->type)
  1355. {
  1356. case "pgsql":
  1357. case "sqlite":
  1358. foreach($gids as $gid)
  1359. {
  1360. $gid = (int)$gid;
  1361. $gidswhere .= " OR ','||groups||',' LIKE '%,{$gid},%'";
  1362. }
  1363. $query = $db->simple_select("modtools", 'tid, name', "(','||forums||',' LIKE '%,$fid,%' OR ','||forums||',' LIKE '%,-1,%' OR forums='') AND (groups='' OR ','||groups||',' LIKE '%,-1,%'{$gidswhere}) AND type = 't'");
  1364. break;
  1365. default:
  1366. foreach($gids as $gid)
  1367. {
  1368. $gid = (int)$gid;
  1369. $gidswhere .= " OR CONCAT(',',`groups`,',') LIKE '%,{$gid},%'";
  1370. }
  1371. $query = $db->simple_select("modtools", 'tid, name', "(CONCAT(',',forums,',') LIKE '%,$fid,%' OR CONCAT(',',forums,',') LIKE '%,-1,%' OR forums='') AND (`groups`='' OR CONCAT(',',`groups`,',') LIKE '%,-1,%'{$gidswhere}) AND type = 't'");
  1372. break;
  1373. }
  1374.  
  1375. while($tool = $db->fetch_array($query))
  1376. {
  1377. $tool['name'] = htmlspecialchars_uni($tool['name']);
  1378. eval("\$customthreadtools .= \"".$templates->get("forumdisplay_inlinemoderation_custom_tool")."\";");
  1379. }
  1380.  
  1381. if($customthreadtools)
  1382. {
  1383. eval("\$customthreadtools = \"".$templates->get("forumdisplay_inlinemoderation_custom")."\";");
  1384. }
  1385. }
  1386.  
  1387. $inlinemodopenclose = $inlinemodstickunstick = $inlinemodsoftdelete = $inlinemodrestore = $inlinemoddelete = $inlinemodmanage = $inlinemodapproveunapprove = '';
  1388.  
  1389. if(is_moderator($fid, "canopenclosethreads"))
  1390. {
  1391. eval("\$inlinemodopenclose = \"".$templates->get("forumdisplay_inlinemoderation_openclose")."\";");
  1392. }
  1393.  
  1394. if(is_moderator($fid, "canstickunstickthreads"))
  1395. {
  1396. eval("\$inlinemodstickunstick = \"".$templates->get("forumdisplay_inlinemoderation_stickunstick")."\";");
  1397. }
  1398.  
  1399. if(is_moderator($fid, "cansoftdeletethreads"))
  1400. {
  1401. eval("\$inlinemodsoftdelete = \"".$templates->get("forumdisplay_inlinemoderation_softdelete")."\";");
  1402. }
  1403.  
  1404. if(is_moderator($fid, "canrestorethreads"))
  1405. {
  1406. eval("\$inlinemodrestore = \"".$templates->get("forumdisplay_inlinemoderation_restore")."\";");
  1407. }
  1408.  
  1409. if(is_moderator($fid, "candeletethreads"))
  1410. {
  1411. eval("\$inlinemoddelete = \"".$templates->get("forumdisplay_inlinemoderation_delete")."\";");
  1412. }
  1413.  
  1414. if(is_moderator($fid, "canmanagethreads"))
  1415. {
  1416. eval("\$inlinemodmanage = \"".$templates->get("forumdisplay_inlinemoderation_manage")."\";");
  1417. }
  1418.  
  1419. if(is_moderator($fid, "canapproveunapprovethreads"))
  1420. {
  1421. eval("\$inlinemodapproveunapprove = \"".$templates->get("forumdisplay_inlinemoderation_approveunapprove")."\";");
  1422. }
  1423.  
  1424. if(!empty($inlinemodopenclose) || !empty($inlinemodstickunstick) || !empty($inlinemodsoftdelete) || !empty($inlinemodrestore) || !empty($inlinemoddelete) || !empty($inlinemodmanage) || !empty($inlinemodapproveunapprove))
  1425. {
  1426. eval("\$standardthreadtools = \"".$templates->get("forumdisplay_inlinemoderation_standard")."\";");
  1427. }
  1428.  
  1429. // Only show inline mod menu if there's options to show
  1430. if(!empty($standardthreadtools) || !empty($customthreadtools))
  1431. {
  1432. eval("\$inlinemod = \"".$templates->get("forumdisplay_inlinemoderation")."\";");
  1433. }
  1434. }
  1435. }
  1436.  
  1437. // If there are no unread threads in this forum and no unread child forums - mark it as read
  1438. require_once MYBB_ROOT."inc/functions_indicators.php";
  1439.  
  1440. $unread_threads = fetch_unread_count($fid);
  1441. if($unread_threads !== false && $unread_threads == 0 && empty($unread_forums))
  1442. {
  1443. mark_forum_read($fid);
  1444. }
  1445.  
  1446. // Subscription status
  1447. $add_remove_subscription = 'add';
  1448. $add_remove_subscription_text = $lang->subscribe_forum;
  1449.  
  1450. if($mybb->user['uid'])
  1451. {
  1452. $query = $db->simple_select("forumsubscriptions", "fid", "fid='".$fid."' AND uid='{$mybb->user['uid']}'", array('limit' => 1));
  1453.  
  1454. if($db->fetch_field($query, 'fid'))
  1455. {
  1456. $add_remove_subscription = 'remove';
  1457. $add_remove_subscription_text = $lang->unsubscribe_forum;
  1458. }
  1459. }
  1460.  
  1461. $inline_edit_js = $clearstoredpass = '';
  1462.  
  1463. // Is this a real forum with threads?
  1464. if($foruminfo['type'] != "c")
  1465. {
  1466. if($fpermissions['canviewthreads'] != 1)
  1467. {
  1468. eval("\$threads = \"".$templates->get("forumdisplay_nopermission")."\";");
  1469. }
  1470.  
  1471. if(!$threadcount && $fpermissions['canviewthreads'] == 1)
  1472. {
  1473. eval("\$threads = \"".$templates->get("forumdisplay_nothreads")."\";");
  1474. }
  1475.  
  1476. $clearstoredpass = '';
  1477. if($foruminfo['password'] != '')
  1478. {
  1479. eval("\$clearstoredpass = \"".$templates->get("forumdisplay_threadlist_clearpass")."\";");
  1480. }
  1481.  
  1482. $prefixselect = build_forum_prefix_select($fid, $tprefix);
  1483.  
  1484. $lang->rss_discovery_forum = $lang->sprintf($lang->rss_discovery_forum, htmlspecialchars_uni(strip_tags($foruminfo['name'])));
  1485. eval("\$rssdiscovery = \"".$templates->get("forumdisplay_rssdiscovery")."\";");
  1486. eval("\$threadslist = \"".$templates->get("forumdisplay_threadlist")."\";");
  1487. }
  1488. else
  1489. {
  1490. $rssdiscovery = '';
  1491. $threadslist = '';
  1492.  
  1493. if(empty($forums))
  1494. {
  1495. error($lang->error_containsnoforums);
  1496. }
  1497. }
  1498.  
  1499. $plugins->run_hooks("forumdisplay_end");
  1500.  
  1501. $foruminfo['name'] = strip_tags($foruminfo['name']);
  1502.  
  1503. eval("\$forums = \"".$templates->get("forumdisplay")."\";");
  1504. output_page($forums);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement