Advertisement
Guest User

Untitled

a guest
Feb 17th, 2011
521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.82 KB | None | 0 0
  1. <?php
  2. /**
  3. * MyBB 1.6
  4. * Copyright 2010 MyBB Group, All Rights Reserved
  5. *
  6. * Website: http://mybb.com
  7. * License: http://mybb.com/about/license
  8. *
  9. * $Id: forumdisplay.php 5016 2010-06-12 00:24:02Z RyanGordon $
  10. */
  11.  
  12. define("IN_MYBB", 1);
  13. define('THIS_SCRIPT', 'forumdisplay.php');
  14.  
  15. $templatelist = "forumdisplay,forumdisplay_thread,breadcrumb_bit,forumbit_depth1_cat,forumbit_depth1_forum,forumbit_depth2_cat,forumbit_depth2_forum,forumdisplay_subforums,forumdisplay_threadlist,forumdisplay_moderatedby_moderator,forumdisplay_moderatedby,forumdisplay_newthread,forumdisplay_searchforum,forumdisplay_orderarrow,forumdisplay_thread_rating,forumdisplay_announcement,forumdisplay_threadlist_rating,forumdisplay_threadlist_sortrating,forumdisplay_subforums_modcolumn,forumbit_moderators,forumbit_subforums,forumbit_depth2_forum_lastpost";
  16. $templatelist .= ",forumbit_depth1_forum_lastpost,forumdisplay_thread_multipage_page,forumdisplay_thread_multipage,forumdisplay_thread_multipage_more";
  17. $templatelist .= ",multipage_prevpage,multipage_nextpage,multipage_page_current,multipage_page,multipage_start,multipage_end,multipage";
  18. $templatelist .= ",forumjump_advanced,forumjump_special,forumjump_bit";
  19. $templatelist .= ",forumdisplay_usersbrowsing_guests,forumdisplay_usersbrowsing_user,forumdisplay_usersbrowsing,forumdisplay_inlinemoderation,forumdisplay_thread_modbit,forumdisplay_inlinemoderation_col";
  20. $templatelist .= ",forumdisplay_announcements_announcement,forumdisplay_announcements,forumdisplay_threads_sep,forumbit_depth3_statusicon,forumbit_depth3,forumdisplay_sticky_sep,forumdisplay_thread_attachment_count,forumdisplay_threadlist_inlineedit_js,forumdisplay_rssdiscovery,forumdisplay_announcement_rating,forumdisplay_announcements_announcement_modbit,forumdisplay_rules,forumdisplay_rules_link,forumdisplay_thread_gotounread,forumdisplay_nothreads,forumdisplay_inlinemoderation_custom_tool,forumdisplay_inlinemoderation_custom";
  21. require_once "./global.php";
  22. require_once MYBB_ROOT."inc/functions_post.php";
  23. require_once MYBB_ROOT."inc/functions_forumlist.php";
  24. require_once MYBB_ROOT."inc/class_parser.php";
  25. $parser = new postParser;
  26.  
  27. // Load global language phrases
  28. $lang->load("forumdisplay");
  29.  
  30. $plugins->run_hooks("forumdisplay_start");
  31.  
  32. $fid = intval($mybb->input['fid']);
  33. if($fid < 0)
  34. {
  35. switch($fid)
  36. {
  37. case "-1":
  38. $location = "index.php";
  39. break;
  40. case "-2":
  41. $location = "search.php";
  42. break;
  43. case "-3":
  44. $location = "usercp.php";
  45. break;
  46. case "-4":
  47. $location = "private.php";
  48. break;
  49. case "-5":
  50. $location = "online.php";
  51. break;
  52. }
  53. if($location)
  54. {
  55. header("Location: ".$location);
  56. exit;
  57. }
  58. }
  59.  
  60. // Get forum info
  61. $foruminfo = get_forum($fid);
  62. if(!$foruminfo)
  63. {
  64. error($lang->error_invalidforum);
  65. }
  66.  
  67. $archive_url = build_archive_link("forum", $fid);
  68.  
  69. $currentitem = $fid;
  70. build_forum_breadcrumb($fid);
  71. $parentlist = $foruminfo['parentlist'];
  72.  
  73. // To validate, turn & to &amp; but support unicode
  74. $foruminfo['name'] = preg_replace("#&(?!\#[0-9]+;)#si", "&amp;", $foruminfo['name']);
  75.  
  76. $forumpermissions = forum_permissions();
  77. $fpermissions = $forumpermissions[$fid];
  78.  
  79. if($fpermissions['canview'] != 1)
  80. {
  81. error_no_permission();
  82. }
  83.  
  84. if($mybb->user['uid'] == 0)
  85. {
  86. // Build a forum cache.
  87. $query = $db->query("
  88. SELECT *
  89. FROM ".TABLE_PREFIX."forums
  90. WHERE active != 0
  91. ORDER BY pid, disporder
  92. ");
  93.  
  94. $forumsread = unserialize($mybb->cookies['mybb']['forumread']);
  95. }
  96. else
  97. {
  98. // Build a forum cache.
  99. $query = $db->query("
  100. SELECT f.*, fr.dateline AS lastread
  101. FROM ".TABLE_PREFIX."forums f
  102. LEFT JOIN ".TABLE_PREFIX."forumsread fr ON (fr.fid=f.fid AND fr.uid='{$mybb->user['uid']}')
  103. WHERE f.active != 0
  104. ORDER BY pid, disporder
  105. ");
  106. }
  107. while($forum = $db->fetch_array($query))
  108. {
  109. if($mybb->user['uid'] == 0)
  110. {
  111. if($forumsread[$forum['fid']])
  112. {
  113. $forum['lastread'] = $forumsread[$forum['fid']];
  114. }
  115. }
  116. $fcache[$forum['pid']][$forum['disporder']][$forum['fid']] = $forum;
  117. }
  118.  
  119. // Get the forum moderators if the setting is enabled.
  120. if($mybb->settings['modlist'] != 0)
  121. {
  122. $moderatorcache = $cache->read("moderators");
  123. }
  124.  
  125. $bgcolor = "trow1";
  126. if($mybb->settings['subforumsindex'] != 0)
  127. {
  128. $showdepth = 3;
  129. }
  130. else
  131. {
  132. $showdepth = 2;
  133. }
  134. $child_forums = build_forumbits($fid, 2);
  135. $forums = $child_forums['forum_list'];
  136. if($forums)
  137. {
  138. $lang->sub_forums_in = $lang->sprintf($lang->sub_forums_in, $foruminfo['name']);
  139. eval("\$subforums = \"".$templates->get("forumdisplay_subforums")."\";");
  140. }
  141.  
  142. $excols = "forumdisplay";
  143.  
  144. // Password protected forums
  145. check_forum_password($foruminfo['fid']);
  146.  
  147. if($foruminfo['linkto'])
  148. {
  149. header("Location: {$foruminfo['linkto']}");
  150. exit;
  151. }
  152.  
  153. // Make forum jump...
  154. if($mybb->settings['enableforumjump'] != 0)
  155. {
  156. $forumjump = build_forum_jump("", $fid, 1);
  157. }
  158.  
  159. if($foruminfo['type'] == "f" && $foruminfo['open'] != 0)
  160. {
  161. eval("\$newthread = \"".$templates->get("forumdisplay_newthread")."\";");
  162. }
  163.  
  164. if($fpermissions['cansearch'] != 0 && $foruminfo['type'] == "f")
  165. {
  166. eval("\$searchforum = \"".$templates->get("forumdisplay_searchforum")."\";");
  167. }
  168.  
  169. $done_moderators = array(
  170. "users" => array(),
  171. "groups" => array()
  172. );
  173. $moderators = '';
  174. $parentlistexploded = explode(",", $parentlist);
  175. foreach($parentlistexploded as $mfid)
  176. {
  177. // This forum has moderators
  178. if(is_array($moderatorcache[$mfid]))
  179. {
  180. // Fetch each moderator from the cache and format it, appending it to the list
  181. foreach($moderatorcache[$mfid] as $modtype)
  182. {
  183. foreach($modtype as $moderator)
  184. {
  185. if($moderator['isgroup'])
  186. {
  187. if(in_array($moderator['id'], $done_moderators['groups']))
  188. {
  189. continue;
  190. }
  191. $moderators .= $comma.htmlspecialchars_uni($moderator['title']);
  192. $done_moderators['groups'][] = $moderator['id'];
  193. }
  194. else
  195. {
  196. if(in_array($moderator['id'], $done_moderators['users']))
  197. {
  198. continue;
  199. }
  200. $moderators .= "{$comma}<a href=\"".get_profile_link($moderator['id'])."\">".format_name(htmlspecialchars_uni($moderator['username']), $moderator['usergroup'], $moderator['displaygroup'])."</a>";
  201. $done_moderators['users'][] = $moderator['id'];
  202. }
  203. $comma = $lang->comma;
  204. }
  205. }
  206. }
  207. }
  208. $comma = '';
  209.  
  210. // If we have a moderators list, load the template
  211. if($moderators)
  212. {
  213. eval("\$moderatedby = \"".$templates->get("forumdisplay_moderatedby")."\";");
  214. }
  215. else
  216. {
  217. $moderatedby = '';
  218. }
  219.  
  220. // Get the users browsing this forum.
  221. if($mybb->settings['browsingthisforum'] != 0)
  222. {
  223. $timecut = TIME_NOW - $mybb->settings['wolcutoff'];
  224.  
  225. $comma = '';
  226. $guestcount = 0;
  227. $membercount = 0;
  228. $inviscount = 0;
  229. $onlinemembers = '';
  230. $query = $db->query("
  231. SELECT s.ip, s.uid, u.username, s.time, u.invisible, u.usergroup, u.usergroup, u.displaygroup
  232. FROM ".TABLE_PREFIX."sessions s
  233. LEFT JOIN ".TABLE_PREFIX."users u ON (s.uid=u.uid)
  234. WHERE s.time > '$timecut' AND location1='$fid' AND nopermission != 1
  235. ORDER BY u.username ASC, s.time DESC
  236. ");
  237. while($user = $db->fetch_array($query))
  238. {
  239. if($user['uid'] == 0)
  240. {
  241. ++$guestcount;
  242. }
  243. else
  244. {
  245. if($doneusers[$user['uid']] < $user['time'] || !$doneusers[$user['uid']])
  246. {
  247. $doneusers[$user['uid']] = $user['time'];
  248. ++$membercount;
  249. if($user['invisible'] == 1)
  250. {
  251. $invisiblemark = "*";
  252. ++$inviscount;
  253. }
  254. else
  255. {
  256. $invisiblemark = '';
  257. }
  258.  
  259. if($user['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1 || $user['uid'] == $mybb->user['uid'])
  260. {
  261. $user['username'] = format_name($user['username'], $user['usergroup'], $user['displaygroup']);
  262. $user['profilelink'] = build_profile_link($user['username'], $user['uid']);
  263. eval("\$onlinemembers .= \"".$templates->get("forumdisplay_usersbrowsing_user", 1, 0)."\";");
  264. $comma = $lang->comma;
  265. }
  266. }
  267. }
  268. }
  269.  
  270. if($guestcount)
  271. {
  272. $guestsonline = $lang->sprintf($lang->users_browsing_forum_guests, $guestcount);
  273. }
  274.  
  275. if($guestcount && $onlinemembers)
  276. {
  277. $onlinesep = $lang->comma;
  278. }
  279.  
  280. $invisonline = '';
  281. if($inviscount && $mybb->usergroup['canviewwolinvis'] != 1 && ($inviscount != 1 && $mybb->user['invisible'] != 1))
  282. {
  283. $invisonline = $lang->sprintf($lang->users_browsing_forum_invis, $inviscount);
  284. }
  285.  
  286. if($invisonline != '' && $guestcount)
  287. {
  288. $onlinesep2 = $lang->comma;
  289. }
  290. eval("\$usersbrowsing = \"".$templates->get("forumdisplay_usersbrowsing")."\";");
  291. }
  292.  
  293. // Do we have any forum rules to show for this forum?
  294. $forumrules = '';
  295. if($foruminfo['rulestype'] != 0 && $foruminfo['rules'])
  296. {
  297. if(!$foruminfo['rulestitle'])
  298. {
  299. $foruminfo['rulestitle'] = $lang->sprintf($lang->forum_rules, $foruminfo['name']);
  300. }
  301.  
  302. $rules_parser = array(
  303. "allow_html" => 1,
  304. "allow_mycode" => 1,
  305. "allow_smilies" => 1,
  306. "allow_imgcode" => 1
  307. );
  308.  
  309. $foruminfo['rules'] = $parser->parse_message($foruminfo['rules'], $rules_parser);
  310. if($foruminfo['rulestype'] == 1)
  311. {
  312. eval("\$rules = \"".$templates->get("forumdisplay_rules")."\";");
  313. }
  314. else if($foruminfo['rulestype'] == 2)
  315. {
  316. eval("\$rules = \"".$templates->get("forumdisplay_rules_link")."\";");
  317. }
  318. }
  319.  
  320. $bgcolor = "trow1";
  321.  
  322. // Set here to fetch only approved topics (and then below for a moderator we change this).
  323. if ($mybb->user['uid'] == $thread['uid'])
  324. {
  325. $visibleonly = "AND visible='1'";
  326. $tvisibleonly = "AND t.visible='1'";
  327. }
  328.  
  329. // Check if the active user is a moderator and get the inline moderation tools.
  330. if(is_moderator($fid))
  331. {
  332. eval("\$inlinemodcol = \"".$templates->get("forumdisplay_inlinemoderation_col")."\";");
  333. $ismod = true;
  334. $inlinecount = "0";
  335. $inlinecookie = "inlinemod_forum".$fid;
  336. $visibleonly = " AND (visible='1' OR visible='0')";
  337. $tvisibleonly = " AND (t.visible='1' OR t.visible='0')";
  338. }
  339. else
  340. {
  341. $inlinemod = '';
  342. $ismod = false;
  343. }
  344.  
  345. if(is_moderator($fid, "caneditposts") || $fpermissions['caneditposts'] == 1)
  346. {
  347. $can_edit_titles = 1;
  348. }
  349. else
  350. {
  351. $can_edit_titles = 0;
  352. }
  353.  
  354. unset($rating);
  355.  
  356. // Pick out some sorting options.
  357. // First, the date cut for the threads.
  358. $datecut = 0;
  359. if(!$mybb->input['datecut'])
  360. {
  361. // If the user manually set a date cut, use it.
  362. if($mybb->user['daysprune'])
  363. {
  364. $datecut = $mybb->user['daysprune'];
  365. }
  366. else
  367. {
  368. // If the forum has a non-default date cut, use it.
  369. if(!empty($foruminfo['defaultdatecut']))
  370. {
  371. $datecut = $foruminfo['defaultdatecut'];
  372. }
  373. }
  374. }
  375. // If there was a manual date cut override, use it.
  376. else
  377. {
  378. $datecut = intval($mybb->input['datecut']);
  379. }
  380.  
  381. $datecut = intval($datecut);
  382. $datecutsel[$datecut] = "selected=\"selected\"";
  383. if($datecut > 0 && $datecut != 9999)
  384. {
  385. $checkdate = TIME_NOW - ($datecut * 86400);
  386. $datecutsql = "AND (lastpost >= '$checkdate' OR sticky = '1')";
  387. $datecutsql2 = "AND (t.lastpost >= '$checkdate' OR t.sticky = '1')";
  388. }
  389. else
  390. {
  391. $datecutsql = '';
  392. $datecutsql2 = '';
  393. }
  394.  
  395. // Pick the sort order.
  396. if(!isset($mybb->input['order']) && !empty($foruminfo['defaultsortorder']))
  397. {
  398. $mybb->input['order'] = $foruminfo['defaultsortorder'];
  399. }
  400.  
  401. $mybb->input['order'] = htmlspecialchars($mybb->input['order']);
  402.  
  403. switch(my_strtolower($mybb->input['order']))
  404. {
  405. case "asc":
  406. $sortordernow = "asc";
  407. $ordersel['asc'] = "selected=\"selected\"";
  408. $oppsort = $lang->desc;
  409. $oppsortnext = "desc";
  410. break;
  411. default:
  412. $sortordernow = "desc";
  413. $ordersel['desc'] = "selected=\"selected\"";
  414. $oppsort = $lang->asc;
  415. $oppsortnext = "asc";
  416. break;
  417. }
  418.  
  419. // Sort by which field?
  420. if(!isset($mybb->input['sortby']) && !empty($foruminfo['defaultsortby']))
  421. {
  422. $mybb->input['sortby'] = $foruminfo['defaultsortby'];
  423. }
  424.  
  425. $t = "t.";
  426.  
  427. $sortby = htmlspecialchars($mybb->input['sortby']);
  428. switch($mybb->input['sortby'])
  429. {
  430. case "subject":
  431. $sortfield = "subject";
  432. break;
  433. case "replies":
  434. $sortfield = "replies";
  435. break;
  436. case "views":
  437. $sortfield = "views";
  438. break;
  439. case "starter":
  440. $sortfield = "username";
  441. break;
  442. case "rating":
  443. $t = "";
  444. $sortfield = "averagerating";
  445. $sortfield2 = ", t.totalratings DESC";
  446. break;
  447. case "started":
  448. $sortfield = "dateline";
  449. break;
  450. default:
  451. $sortby = "lastpost";
  452. $sortfield = "lastpost";
  453. $mybb->input['sortby'] = "lastpost";
  454. break;
  455. }
  456.  
  457. $sortsel[$mybb->input['sortby']] = "selected=\"selected\"";
  458.  
  459. // Pick the right string to join the sort URL
  460. if($mybb->settings['seourls'] == "yes" || ($mybb->settings['seourls'] == "auto" && $_SERVER['SEO_SUPPORT'] == 1))
  461. {
  462. $string = "?";
  463. }
  464. else
  465. {
  466. $string = "&amp;";
  467. }
  468.  
  469. // Are we viewing a specific page?
  470. if(isset($mybb->input['page']) && is_numeric($mybb->input['page']))
  471. {
  472. $sorturl = get_forum_link($fid, $mybb->input['page']).$string."datecut=$datecut";
  473. }
  474. else
  475. {
  476. $sorturl = get_forum_link($fid).$string."datecut=$datecut";
  477. }
  478. eval("\$orderarrow['$sortby'] = \"".$templates->get("forumdisplay_orderarrow")."\";");
  479.  
  480. $threadcount = 0;
  481. $useronly = $tuseronly = "";
  482. if($fpermissions['canonlyviewownthreads'] == 1)
  483. {
  484. $useronly = "AND uid={$mybb->user['uid']}";
  485. $tuseronly = "AND t.uid={$mybb->user['uid']}";
  486. }
  487.  
  488. if($fpermissions['canviewthreads'] != 0)
  489. {
  490.  
  491. // How many posts are there?
  492. if($datecut > 0 || $fpermissions['canonlyviewownthreads'] == 1)
  493. {
  494. $query = $db->simple_select("threads", "COUNT(tid) AS threads", "fid = '$fid' $useronly $visibleonly $datecutsql");
  495. $threadcount = $db->fetch_field($query, "threads");
  496. }
  497. else
  498. {
  499. $query = $db->simple_select("forums", "threads, unapprovedthreads", "fid = '{$fid}'", array('limit' => 1));
  500. $forum_threads = $db->fetch_array($query);
  501. $threadcount = $forum_threads['threads'];
  502. if($ismod == true)
  503. {
  504. $threadcount += $forum_threads['unapprovedthreads'];
  505. }
  506.  
  507. // If we have 0 threads double check there aren't any "moved" threads
  508. if($threadcount == 0)
  509. {
  510. $query = $db->simple_select("threads", "COUNT(tid) AS threads", "fid = '$fid' $useronly $visibleonly", array('limit' => 1));
  511. $threadcount = $db->fetch_field($query, "threads");
  512. }
  513. }
  514. }
  515.  
  516. // How many pages are there?
  517. if(!$mybb->settings['threadsperpage'])
  518. {
  519. $mybb->settings['threadsperpage'] = 20;
  520. }
  521.  
  522. $perpage = $mybb->settings['threadsperpage'];
  523.  
  524. if(intval($mybb->input['page']) > 0)
  525. {
  526. $page = intval($mybb->input['page']);
  527. $start = ($page-1) * $perpage;
  528. $pages = $threadcount / $perpage;
  529. $pages = ceil($pages);
  530. if($page > $pages || $page <= 0)
  531. {
  532. $start = 0;
  533. $page = 1;
  534. }
  535. }
  536. else
  537. {
  538. $start = 0;
  539. $page = 1;
  540. }
  541.  
  542. $end = $start + $perpage;
  543. $lower = $start + 1;
  544. $upper = $end;
  545.  
  546. if($upper > $threadcount)
  547. {
  548. $upper = $threadcount;
  549. }
  550.  
  551. // Assemble page URL
  552. if($mybb->input['sortby'] || $mybb->input['order'] || $mybb->input['datecut']) // Ugly URL
  553. {
  554. $page_url = str_replace("{fid}", $fid, FORUM_URL_PAGED);
  555.  
  556. if($mybb->settings['seourls'] == "yes" || ($mybb->settings['seourls'] == "auto" && $_SERVER['SEO_SUPPORT'] == 1))
  557. {
  558. $q = "?";
  559. $and = '';
  560. }
  561. else
  562. {
  563. $q = '';
  564. $and = "&";
  565. }
  566.  
  567. if($sortby != "lastpost")
  568. {
  569. $page_url .= "{$q}{$and}sortby={$sortby}";
  570. $q = '';
  571. $and = "&";
  572. }
  573.  
  574. if($sortordernow != "desc")
  575. {
  576. $page_url .= "{$q}{$and}order={$sortordernow}";
  577. $q = '';
  578. $and = "&";
  579. }
  580.  
  581. if($datecut > 0 && $datecut != 9999)
  582. {
  583. $page_url .= "{$q}{$and}datecut={$datecut}";
  584. }
  585. }
  586. else
  587. {
  588. $page_url = str_replace("{fid}", $fid, FORUM_URL_PAGED);
  589. }
  590. $multipage = multipage($threadcount, $perpage, $page, $page_url);
  591.  
  592. if($foruminfo['allowtratings'] != 0 && $fpermissions['canviewthreads'] != 0)
  593. {
  594. $lang->load("ratethread");
  595. switch($db->type)
  596. {
  597. case "pgsql":
  598. $ratingadd = "CASE WHEN t.numratings=0 THEN 0 ELSE t.totalratings/t.numratings::numeric END AS averagerating, ";
  599. break;
  600. default:
  601. $ratingadd = "(t.totalratings/t.numratings) AS averagerating, ";
  602. }
  603. $lpbackground = "trow2";
  604. eval("\$ratingcol = \"".$templates->get("forumdisplay_threadlist_rating")."\";");
  605. eval("\$ratingsort = \"".$templates->get("forumdisplay_threadlist_sortrating")."\";");
  606. $colspan = "7";
  607. $select_voting = "\nLEFT JOIN ".TABLE_PREFIX."threadratings r ON(r.tid=t.tid AND r.uid='{$mybb->user['uid']}')";
  608. $select_rating_user = "r.uid AS rated, ";
  609. }
  610. else
  611. {
  612. if($sortfield == "averagerating")
  613. {
  614. $t = "t.";
  615. $sortfield = "lastpost";
  616. }
  617. $ratingadd = '';
  618. $lpbackground = "trow1";
  619. $colspan = "6";
  620. }
  621.  
  622. if($ismod)
  623. {
  624. ++$colspan;
  625. }
  626.  
  627. // Get Announcements
  628. $limit = '';
  629. $announcements = '';
  630. if($mybb->settings['announcementlimit'])
  631. {
  632. $limit = "LIMIT 0, ".$mybb->settings['announcementlimit'];
  633. }
  634.  
  635. $sql = build_parent_list($fid, "fid", "OR", $parentlist);
  636. $time = TIME_NOW;
  637. $query = $db->query("
  638. SELECT a.*, u.username
  639. FROM ".TABLE_PREFIX."announcements a
  640. LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=a.uid)
  641. WHERE a.startdate<='$time' AND (a.enddate>='$time' OR a.enddate='0') AND ($sql OR fid='-1')
  642. ORDER BY a.startdate DESC $limit
  643. ");
  644. $bgcolor = alt_trow(true); // Reset the trow colors
  645. while($announcement = $db->fetch_array($query))
  646. {
  647. if($announcement['startdate'] > $mybb->user['lastvisit'])
  648. {
  649. $new_class = ' class="subject_new"';
  650. $folder = "newfolder";
  651. }
  652. else
  653. {
  654. $new_class = ' class="subject_old"';
  655. $folder = "folder";
  656. }
  657.  
  658. $announcement['announcementlink'] = get_announcement_link($announcement['aid']);
  659. $announcement['subject'] = $parser->parse_badwords($announcement['subject']);
  660. $announcement['subject'] = htmlspecialchars_uni($announcement['subject']);
  661. $postdate = my_date($mybb->settings['dateformat'], $announcement['startdate']);
  662. $posttime = my_date($mybb->settings['timeformat'], $announcement['startdate']);
  663. $announcement['profilelink'] = build_profile_link($announcement['username'], $announcement['uid']);
  664.  
  665. if($foruminfo['allowtratings'] != 0 && $fpermissions['canviewthreads'] != 0)
  666. {
  667. eval("\$rating = \"".$templates->get("forumdisplay_announcement_rating")."\";");
  668. $lpbackground = "trow2";
  669. }
  670. else
  671. {
  672. $rating = '';
  673. $lpbackground = "trow1";
  674. }
  675.  
  676. if($ismod)
  677. {
  678. eval("\$modann = \"".$templates->get("forumdisplay_announcements_announcement_modbit")."\";");
  679. }
  680. else
  681. {
  682. $modann = '';
  683. }
  684.  
  685. $plugins->run_hooks("forumdisplay_announcement");
  686. eval("\$announcements .= \"".$templates->get("forumdisplay_announcements_announcement")."\";");
  687. $bgcolor = alt_trow();
  688. }
  689.  
  690. if($announcements)
  691. {
  692. eval("\$announcementlist = \"".$templates->get("forumdisplay_announcements")."\";");
  693. $shownormalsep = true;
  694. }
  695.  
  696. $icon_cache = $cache->read("posticons");
  697.  
  698. if($fpermissions['canviewthreads'] != 0)
  699. {
  700. // Start Getting Threads
  701. $query = $db->query("
  702. SELECT t.*, p.displaystyle AS threadprefix, {$ratingadd}{$select_rating_user}t.username AS threadusername, u.username
  703. FROM ".TABLE_PREFIX."threads t
  704. LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid){$select_voting}
  705. LEFT JOIN ".TABLE_PREFIX."threadprefixes p ON (p.pid = t.prefix)
  706. WHERE t.fid='$fid' $tuseronly $tvisibleonly $datecutsql2
  707. GROUP BY t.tid
  708. ORDER BY t.sticky DESC, {$t}{$sortfield} $sortordernow $sortfield2
  709. LIMIT $start, $perpage
  710. ");
  711. while($thread = $db->fetch_array($query))
  712. {
  713. $threadcache[$thread['tid']] = $thread;
  714.  
  715. // If this is a moved thread - set the tid for participation marking and thread read marking to that of the moved thread
  716. if(substr($thread['closed'], 0, 5) == "moved")
  717. {
  718. $tid = substr($thread['closed'], 6);
  719. if(!$tids[$tid])
  720. {
  721. $moved_threads[$tid] = $thread['tid'];
  722. $tids[$thread['tid']] = $tid;
  723. }
  724. }
  725. // Otherwise - set it to the plain thread ID
  726. else
  727. {
  728. $tids[$thread['tid']] = $thread['tid'];
  729. if($moved_threads[$tid])
  730. {
  731. unset($moved_threads[$tid]);
  732. }
  733. }
  734. }
  735. }
  736. else
  737. {
  738. $threadcache = $tids = null;
  739. }
  740.  
  741. // If user has moderation tools available, prepare the Select All feature
  742. $num_results = $db->num_rows($query);
  743. if(is_moderator($fid) && $num_results > 0)
  744. {
  745. $lang->page_selected = $lang->sprintf($lang->page_selected, intval($num_results));
  746. $lang->select_all = $lang->sprintf($lang->select_all, intval($threadcount));
  747. $lang->all_selected = $lang->sprintf($lang->all_selected, intval($threadcount));
  748. eval("\$selectall = \"".$templates->get("forumdisplay_inlinemoderation_selectall")."\";");
  749. }
  750.  
  751. if($tids)
  752. {
  753. $tids = implode(",", $tids);
  754. }
  755.  
  756. // Check participation by the current user in any of these threads - for 'dot' folder icons
  757. if($mybb->settings['dotfolders'] != 0 && $mybb->user['uid'] && $threadcache)
  758. {
  759. $query = $db->simple_select("posts", "tid,uid", "uid='{$mybb->user['uid']}' AND tid IN ({$tids})");
  760. while($post = $db->fetch_array($query))
  761. {
  762. if($moved_threads[$post['tid']])
  763. {
  764. $post['tid'] = $moved_threads[$post['tid']];
  765. }
  766. if($threadcache[$post['tid']])
  767. {
  768. $threadcache[$post['tid']]['doticon'] = 1;
  769. }
  770. }
  771. }
  772.  
  773. // Read threads
  774. if($mybb->user['uid'] && $mybb->settings['threadreadcut'] > 0 && $threadcache)
  775. {
  776. $query = $db->simple_select("threadsread", "*", "uid='{$mybb->user['uid']}' AND tid IN ({$tids})");
  777. while($readthread = $db->fetch_array($query))
  778. {
  779. if($moved_threads[$readthread['tid']])
  780. {
  781. $readthread['tid'] = $moved_threads[$readthread['tid']];
  782. }
  783. if($threadcache[$readthread['tid']])
  784. {
  785. $threadcache[$readthread['tid']]['lastread'] = $readthread['dateline'];
  786. }
  787. }
  788. }
  789.  
  790. if($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid'])
  791. {
  792. $query = $db->simple_select("forumsread", "dateline", "fid='{$fid}' AND uid='{$mybb->user['uid']}'");
  793. $forum_read = $db->fetch_field($query, "dateline");
  794.  
  795. $read_cutoff = TIME_NOW-$mybb->settings['threadreadcut']*60*60*24;
  796. if($forum_read == 0 || $forum_read < $read_cutoff)
  797. {
  798. $forum_read = $read_cutoff;
  799. }
  800. }
  801. else
  802. {
  803. $forum_read = my_get_array_cookie("forumread", $fid);
  804. }
  805.  
  806. $unreadpost = 0;
  807. $threads = '';
  808. $load_inline_edit_js = 0;
  809. if(is_array($threadcache))
  810. {
  811. foreach($threadcache as $thread)
  812. {
  813. $plugins->run_hooks("forumdisplay_thread");
  814.  
  815. $moved = explode("|", $thread['closed']);
  816.  
  817. if($thread['visible'] == 0)
  818. {
  819. $bgcolor = "trow_shaded";
  820. }
  821. else
  822. {
  823. $bgcolor = alt_trow();
  824. }
  825.  
  826. if($thread['sticky'] == 1)
  827. {
  828. $thread_type_class = " forumdisplay_sticky";
  829. }
  830. else
  831. {
  832. $thread_type_class = " forumdisplay_regular";
  833. }
  834.  
  835. $folder = '';
  836. $prefix = '';
  837.  
  838. $thread['author'] = $thread['uid'];
  839. if(!$thread['username'])
  840. {
  841. $thread['username'] = $thread['threadusername'];
  842. $thread['profilelink'] = $thread['threadusername'];
  843. }
  844. else
  845. {
  846. $thread['profilelink'] = build_profile_link($thread['username'], $thread['uid']);
  847. }
  848.  
  849. // If this thread has a prefix, insert a space between prefix and subject
  850. if($thread['prefix'] != 0)
  851. {
  852. $thread['threadprefix'] .= '&nbsp;';
  853. }
  854.  
  855. $thread['subject'] = $parser->parse_badwords($thread['subject']);
  856. $thread['subject'] = htmlspecialchars_uni($thread['subject']);
  857.  
  858. if($thread['icon'] > 0 && $icon_cache[$thread['icon']])
  859. {
  860. $icon = $icon_cache[$thread['icon']];
  861. $icon = "<img src=\"{$icon['path']}\" alt=\"{$icon['name']}\" />";
  862. }
  863. else
  864. {
  865. $icon = "&nbsp;";
  866. }
  867.  
  868. $prefix = '';
  869. if($thread['poll'])
  870. {
  871. $prefix = $lang->poll_prefix;
  872. }
  873.  
  874. if($thread['sticky'] == "1" && !$donestickysep)
  875. {
  876. eval("\$threads .= \"".$templates->get("forumdisplay_sticky_sep")."\";");
  877. $shownormalsep = true;
  878. $donestickysep = true;
  879. }
  880. else if($thread['sticky'] == 0 && $shownormalsep)
  881. {
  882. eval("\$threads .= \"".$templates->get("forumdisplay_threads_sep")."\";");
  883. $shownormalsep = false;
  884. }
  885.  
  886. $rating = '';
  887. if($foruminfo['allowtratings'] != 0)
  888. {
  889. if($moved[0] == "moved")
  890. {
  891. $rating = "<td class=\"{$bgcolor}\" style=\"text-align: center;\">-</td>";
  892. }
  893. else
  894. {
  895. $thread['averagerating'] = floatval(round($thread['averagerating'], 2));
  896. $thread['width'] = intval(round($thread['averagerating']))*20;
  897. $thread['numratings'] = intval($thread['numratings']);
  898.  
  899. $not_rated = '';
  900. if(!$thread['rated'])
  901. {
  902. $not_rated = ' star_rating_notrated';
  903. }
  904.  
  905. $ratingvotesav = $lang->sprintf($lang->rating_votes_average, $thread['numratings'], $thread['averagerating']);
  906. eval("\$rating = \"".$templates->get("forumdisplay_thread_rating")."\";");
  907. }
  908. }
  909.  
  910. $thread['pages'] = 0;
  911. $thread['multipage'] = '';
  912. $threadpages = '';
  913. $morelink = '';
  914. $thread['posts'] = $thread['replies'] + 1;
  915.  
  916. if(!$mybb->settings['postsperpage'])
  917. {
  918. $mybb->settings['postperpage'] = 20;
  919. }
  920.  
  921. if($thread['unapprovedposts'] > 0 && $ismod)
  922. {
  923. $thread['posts'] += $thread['unapprovedposts'];
  924. }
  925.  
  926. if($thread['posts'] > $mybb->settings['postsperpage'])
  927. {
  928. $thread['pages'] = $thread['posts'] / $mybb->settings['postsperpage'];
  929. $thread['pages'] = ceil($thread['pages']);
  930.  
  931. if($thread['pages'] > 5)
  932. {
  933. $pagesstop = 4;
  934. $page_link = get_thread_link($thread['tid'], $thread['pages']);
  935. eval("\$morelink = \"".$templates->get("forumdisplay_thread_multipage_more")."\";");
  936. }
  937. else
  938. {
  939. $pagesstop = $thread['pages'];
  940. }
  941.  
  942. for($i = 1; $i <= $pagesstop; ++$i)
  943. {
  944. $page_link = get_thread_link($thread['tid'], $i);
  945. eval("\$threadpages .= \"".$templates->get("forumdisplay_thread_multipage_page")."\";");
  946. }
  947.  
  948. eval("\$thread['multipage'] = \"".$templates->get("forumdisplay_thread_multipage")."\";");
  949. }
  950. else
  951. {
  952. $threadpages = '';
  953. $morelink = '';
  954. $thread['multipage'] = '';
  955. }
  956.  
  957. if($ismod)
  958. {
  959. if(my_strpos($mybb->cookies[$inlinecookie], "|{$thread['tid']}|"))
  960. {
  961. $inlinecheck = "checked=\"checked\"";
  962. ++$inlinecount;
  963. }
  964. else
  965. {
  966. $inlinecheck = '';
  967. }
  968.  
  969. $multitid = $thread['tid'];
  970. eval("\$modbit = \"".$templates->get("forumdisplay_thread_modbit")."\";");
  971. }
  972. else
  973. {
  974. $modbit = '';
  975. }
  976.  
  977. if($moved[0] == "moved")
  978. {
  979. $prefix = $lang->moved_prefix;
  980. $thread['tid'] = $moved[1];
  981. $thread['replies'] = "-";
  982. $thread['views'] = "-";
  983. }
  984.  
  985. $thread['threadlink'] = get_thread_link($thread['tid']);
  986. $thread['lastpostlink'] = get_thread_link($thread['tid'], 0, "lastpost");
  987.  
  988. // Determine the folder
  989. $folder = '';
  990. $folder_label = '';
  991.  
  992. if($thread['doticon'])
  993. {
  994. $folder = "dot_";
  995. $folder_label .= $lang->icon_dot;
  996. }
  997.  
  998. $gotounread = '';
  999. $isnew = 0;
  1000. $donenew = 0;
  1001.  
  1002. if($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid'] && $thread['lastpost'] > $forum_read)
  1003. {
  1004. if($thread['lastread'])
  1005. {
  1006. $last_read = $thread['lastread'];
  1007. }
  1008. else
  1009. {
  1010. $last_read = $read_cutoff;
  1011. }
  1012. }
  1013. else
  1014. {
  1015. $last_read = my_get_array_cookie("threadread", $thread['tid']);
  1016. }
  1017.  
  1018. if($forum_read > $last_read)
  1019. {
  1020. $last_read = $forum_read;
  1021. }
  1022.  
  1023. if($thread['lastpost'] > $last_read && $moved[0] != "moved")
  1024. {
  1025. $folder .= "new";
  1026. $folder_label .= $lang->icon_new;
  1027. $new_class = "subject_new";
  1028. $thread['newpostlink'] = get_thread_link($thread['tid'], 0, "newpost");
  1029. eval("\$gotounread = \"".$templates->get("forumdisplay_thread_gotounread")."\";");
  1030. $unreadpost = 1;
  1031. }
  1032. else
  1033. {
  1034. $folder_label .= $lang->icon_no_new;
  1035. $new_class = "subject_old";
  1036. }
  1037.  
  1038. if($thread['replies'] >= $mybb->settings['hottopic'] || $thread['views'] >= $mybb->settings['hottopicviews'])
  1039. {
  1040. $folder .= "hot";
  1041. $folder_label .= $lang->icon_hot;
  1042. }
  1043.  
  1044. if($thread['closed'] == 1)
  1045. {
  1046. $folder .= "lock";
  1047. $folder_label .= $lang->icon_lock;
  1048. }
  1049.  
  1050. if($moved[0] == "moved")
  1051. {
  1052. $folder = "move";
  1053. $gotounread = '';
  1054. }
  1055.  
  1056. $folder .= "folder";
  1057.  
  1058. $inline_edit_tid = $thread['tid'];
  1059.  
  1060. // If this user is the author of the thread and it is not closed or they are a moderator, they can edit
  1061. if(($thread['uid'] == $mybb->user['uid'] && $thread['closed'] != 1 && $mybb->user['uid'] != 0 && $can_edit_titles == 1) || $ismod == true)
  1062. {
  1063. $inline_edit_class = "subject_editable";
  1064. }
  1065. else
  1066. {
  1067. $inline_edit_class = "";
  1068. }
  1069. $load_inline_edit_js = 1;
  1070.  
  1071. $lastpostdate = my_date($mybb->settings['dateformat'], $thread['lastpost']);
  1072. $lastposttime = my_date($mybb->settings['timeformat'], $thread['lastpost']);
  1073. $lastposter = $thread['lastposter'];
  1074. $lastposteruid = $thread['lastposteruid'];
  1075.  
  1076. // Don't link to guest's profiles (they have no profile).
  1077. if($lastposteruid == 0)
  1078. {
  1079. $lastposterlink = $lastposter;
  1080. }
  1081. else
  1082. {
  1083. $lastposterlink = build_profile_link($lastposter, $lastposteruid);
  1084. }
  1085.  
  1086. $thread['replies'] = my_number_format($thread['replies']);
  1087. $thread['views'] = my_number_format($thread['views']);
  1088.  
  1089. // Threads and posts requiring moderation
  1090. if($thread['unapprovedposts'] > 0 && $ismod)
  1091. {
  1092. if($thread['unapprovedposts'] > 1)
  1093. {
  1094. $unapproved_posts_count = $lang->sprintf($lang->thread_unapproved_posts_count, $thread['unapprovedposts']);
  1095. }
  1096. else
  1097. {
  1098. $unapproved_posts_count = $lang->sprintf($lang->thread_unapproved_post_count, 1);
  1099. }
  1100.  
  1101. $unapproved_posts = " <span title=\"{$unapproved_posts_count}\">(".my_number_format($thread['unapprovedposts']).")</span>";
  1102. }
  1103. else
  1104. {
  1105. $unapproved_posts = '';
  1106. }
  1107.  
  1108. // If this thread has 1 or more attachments show the papperclip
  1109. if($thread['attachmentcount'] > 0)
  1110. {
  1111. if($thread['attachmentcount'] > 1)
  1112. {
  1113. $attachment_count = $lang->sprintf($lang->attachment_count_multiple, $thread['attachmentcount']);
  1114. }
  1115. else
  1116. {
  1117. $attachment_count = $lang->attachment_count;
  1118. }
  1119.  
  1120. eval("\$attachment_count = \"".$templates->get("forumdisplay_thread_attachment_count")."\";");
  1121. }
  1122. else
  1123. {
  1124. $attachment_count = '';
  1125. }
  1126.  
  1127. eval("\$threads .= \"".$templates->get("forumdisplay_thread")."\";");
  1128. }
  1129.  
  1130. $customthreadtools = '';
  1131. if($ismod)
  1132. {
  1133. switch($db->type)
  1134. {
  1135. case "pgsql":
  1136. case "sqlite":
  1137. $query = $db->simple_select("modtools", 'tid, name', "(','||forums||',' LIKE '%,$fid,%' OR ','||forums||',' LIKE '%,-1,%' OR forums='') AND type = 't'");
  1138. break;
  1139. default:
  1140. $query = $db->simple_select("modtools", 'tid, name', "(CONCAT(',',forums,',') LIKE '%,$fid,%' OR CONCAT(',',forums,',') LIKE '%,-1,%' OR forums='') AND type = 't'");
  1141. }
  1142. while($tool = $db->fetch_array($query))
  1143. {
  1144. eval("\$customthreadtools .= \"".$templates->get("forumdisplay_inlinemoderation_custom_tool")."\";");
  1145. }
  1146.  
  1147. if(!empty($customthreadtools))
  1148. {
  1149. eval("\$customthreadtools = \"".$templates->get("forumdisplay_inlinemoderation_custom")."\";");
  1150. }
  1151. eval("\$inlinemod = \"".$templates->get("forumdisplay_inlinemoderation")."\";");
  1152. }
  1153. }
  1154.  
  1155. // If there are no unread threads in this forum and no unread child forums - mark it as read
  1156. require_once MYBB_ROOT."inc/functions_indicators.php";
  1157. if(fetch_unread_count($fid) == 0 && $unread_forums == 0)
  1158. {
  1159. mark_forum_read($fid);
  1160. }
  1161.  
  1162.  
  1163. // Subscription status
  1164. $query = $db->simple_select("forumsubscriptions", "fid", "fid='".$fid."' AND uid='{$mybb->user['uid']}'", array('limit' => 1));
  1165. if($db->fetch_field($query, 'fid'))
  1166. {
  1167. $add_remove_subscription = 'remove';
  1168. $add_remove_subscription_text = $lang->unsubscribe_forum;
  1169. }
  1170. else
  1171. {
  1172. $add_remove_subscription = 'add';
  1173. $add_remove_subscription_text = $lang->subscribe_forum;
  1174. }
  1175.  
  1176.  
  1177. // Is this a real forum with threads?
  1178. if($foruminfo['type'] != "c")
  1179. {
  1180. if(!$threadcount)
  1181. {
  1182. eval("\$threads = \"".$templates->get("forumdisplay_nothreads")."\";");
  1183. }
  1184.  
  1185. if($foruminfo['password'] != '')
  1186. {
  1187. eval("\$clearstoredpass = \"".$templates->get("forumdisplay_threadlist_clearpass")."\";");
  1188. }
  1189.  
  1190. if($load_inline_edit_js == 1)
  1191. {
  1192. eval("\$inline_edit_js = \"".$templates->get("forumdisplay_threadlist_inlineedit_js")."\";");
  1193. }
  1194.  
  1195. $lang->rss_discovery_forum = $lang->sprintf($lang->rss_discovery_forum, htmlspecialchars_uni(strip_tags($foruminfo['name'])));
  1196. eval("\$rssdiscovery = \"".$templates->get("forumdisplay_rssdiscovery")."\";");
  1197. eval("\$threadslist = \"".$templates->get("forumdisplay_threadlist")."\";");
  1198. }
  1199. else
  1200. {
  1201. $rssdiscovery = '';
  1202. $threadslist = '';
  1203.  
  1204. if(empty($forums))
  1205. {
  1206. error($lang->error_containsnoforums);
  1207. }
  1208. }
  1209.  
  1210. $plugins->run_hooks("forumdisplay_end");
  1211.  
  1212. $foruminfo['name'] = strip_tags($foruminfo['name']);
  1213.  
  1214. eval("\$forums = \"".$templates->get("forumdisplay")."\";");
  1215. output_page($forums);
  1216. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement