[ Index ]

PHP Cross Reference of MyBB 1.8.40

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


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