[ Index ]

PHP Cross Reference of MyBB 1.8.27

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


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