[ Index ]

PHP Cross Reference of MyBB 1.8.26

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


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