[ Index ]

PHP Cross Reference of MyBB 1.6.5

title

Body

[close]

/ -> forumdisplay.php (source)

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


Generated: Sun Dec 11 14:16:27 2011 Cross-referenced by PHPXref 0.7.1