[ Index ]

PHP Cross Reference of MyBB 1.8.28

title

Body

[close]

/ -> forumdisplay.php (source)

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


2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref