MyBB PHP Cross Reference Discussion Forums

Source: /showthread.php - 1344 lines - 39819 bytes - Summary - Text - Print

Description: MyBB 1.6 Copyright 2010 MyBB Group, All Rights Reserved Website: http://mybb.com License: http://mybb.com/about/license

   1  <?php
   2  /**
   3   * MyBB 1.6
   4   * Copyright 2010 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://mybb.com
   7   * License: http://mybb.com/about/license
   8   *
   9   * $Id$
  10   */
  11  
  12  define("IN_MYBB", 1);
  13  define('THIS_SCRIPT', 'showthread.php');
  14  
  15  $templatelist = "showthread,postbit,postbit_author_user,postbit_author_guest,showthread_newthread,showthread_newreply,showthread_newreply_closed,postbit_avatar,postbit_find,postbit_pm,postbit_www,postbit_email,postbit_edit,postbit_quote,postbit_report,postbit_signature,postbit_online,postbit_offline,postbit_away,postbit_gotopost,showthread_ratethread,showthread_moderationoptions";
  16  $templatelist .= ",multipage_prevpage,multipage_nextpage,multipage_page_current,multipage_page,multipage_start,multipage_end,multipage";
  17  $templatelist .= ",postbit_editedby,showthread_similarthreads,showthread_similarthreads_bit,postbit_iplogged_show,postbit_iplogged_hiden,showthread_quickreply";
  18  $templatelist .= ",forumjump_advanced,forumjump_special,forumjump_bit,showthread_multipage,postbit_reputation,postbit_quickdelete,postbit_attachments,postbit_attachments_attachment,postbit_attachments_thumbnails,postbit_attachments_images_image,postbit_attachments_images,postbit_posturl,postbit_rep_button";
  19  $templatelist .= ",postbit_inlinecheck,showthread_inlinemoderation,postbit_attachments_thumbnails_thumbnail,postbit_ignored,postbit_groupimage,postbit_multiquote,showthread_search,postbit_warn,postbit_warninglevel,showthread_moderationoptions_custom_tool,showthread_moderationoptions_custom,showthread_inlinemoderation_custom_tool,showthread_inlinemoderation_custom,postbit_classic,showthread_classic_header,showthread_poll_resultbit,showthread_poll_results";
  20  $templatelist .= ",showthread_usersbrowsing,showthread_usersbrowsing_user,multipage_page_link_current,multipage_breadcrumb,showthread_poll_option_multiple,showthread_poll_option,showthread_poll,showthread_threadedbox,showthread_quickreply_options_signature,showthread_threaded_bitactive,showthread_threaded_bit,postbit_attachments_attachment_unapproved,forumdisplay_password_wrongpass,forumdisplay_password";
  21  
  22  require_once  "./global.php";
  23  require_once  MYBB_ROOT."inc/functions_post.php";
  24  require_once  MYBB_ROOT."inc/functions_indicators.php";
  25  require_once  MYBB_ROOT."inc/class_parser.php";
  26  $parser = new postParser;
  27  
  28  // Load global language phrases
  29  $lang->load("showthread");
  30  
  31  // If there is no tid but a pid, trick the system into thinking there was a tid anyway.
  32  if(!empty($mybb->input['pid']) && !$mybb->input['tid'])
  33  {
  34      // see if we already have the post information
  35      if(isset($style) && $style['pid'] == $mybb->input['pid'] && $style['tid'])
  36      {
  37          $mybb->input['tid'] = $style['tid'];
  38          unset($style['tid']); // stop the thread caching code from being tricked
  39      }
  40      else
  41      {
  42          $options = array(
  43              "limit" => 1
  44          );
  45          $query = $db->simple_select("posts", "tid", "pid=".$mybb->input['pid'], $options);
  46          $post = $db->fetch_array($query);
  47          $mybb->input['tid'] = $post['tid'];
  48      }
  49  }
  50  
  51  // Get the thread details from the database.
  52  $thread = get_thread($mybb->input['tid']);
  53  
  54  if(!$thread || substr($thread['closed'], 0, 6) == "moved|")
  55  {
  56      error($lang->error_invalidthread);
  57  }
  58  
  59  // Get thread prefix if there is one.
  60  $thread['threadprefix'] = '';
  61  $thread['displayprefix'] = '';
  62  if($thread['prefix'] != 0)
  63  {
  64      $threadprefix = build_prefixes($thread['prefix']);
  65  
  66      if($threadprefix['prefix'])
  67      {
  68          $thread['threadprefix'] = $threadprefix['prefix'].'&nbsp;';
  69          $thread['displayprefix'] = $threadprefix['displaystyle'].'&nbsp;';
  70      }
  71  }
  72  
  73  $reply_subject = $parser->parse_badwords($thread['subject']);
  74  $thread['subject'] = htmlspecialchars_uni($reply_subject);
  75  // Subject too long? Shorten it to avoid error message
  76  if(my_strlen($reply_subject) > 85)
  77  {
  78      $reply_subject = my_substr($reply_subject, 0, 82).'...';
  79  }
  80  $reply_subject = htmlspecialchars_uni($reply_subject);
  81  $tid = $thread['tid'];
  82  $fid = $thread['fid'];
  83  
  84  if(!$thread['username'])
  85  {
  86      $thread['username'] = $lang->guest;
  87  }
  88  
  89  $visibleonly = "AND visible='1'";
  90  $visibleonly2 = "AND p.visible='1' AND t.visible='1'";
  91  
  92  // Is the currently logged in user a moderator of this forum?
  93  if(is_moderator($fid))
  94  {
  95      $visibleonly = " AND (visible='1' OR visible='0')";
  96      $visibleonly2 = "AND (p.visible='1' OR p.visible='0') AND (t.visible='1' OR t.visible='0')";
  97      $ismod = true;
  98  }
  99  else
 100  {
 101      $ismod = false;
 102  }
 103  
 104  // Make sure we are looking at a real thread here.
 105  if(($thread['visible'] != 1 && $ismod == false) || ($thread['visible'] > 1 && $ismod == true))
 106  {
 107      error($lang->error_invalidthread);
 108  }
 109  
 110  $forumpermissions = forum_permissions($thread['fid']);
 111  
 112  // Does the user have permission to view this thread?
 113  if($forumpermissions['canview'] != 1 || $forumpermissions['canviewthreads'] != 1)
 114  {
 115      error_no_permission();
 116  }
 117  
 118  if(isset($forumpermissions['canonlyviewownthreads']) && $forumpermissions['canonlyviewownthreads'] == 1 && $thread['uid'] != $mybb->user['uid'])
 119  {
 120      error_no_permission();
 121  }
 122  
 123  $archive_url = build_archive_link("thread", $tid);
 124  
 125  // Does the thread belong to a valid forum?
 126  $forum = get_forum($fid);
 127  if(!$forum || $forum['type'] != "f")
 128  {
 129      error($lang->error_invalidforum);
 130  }
 131  
 132  // Check if this forum is password protected and we have a valid password
 133  check_forum_password($forum['fid']);
 134  
 135  // If there is no specific action, we must be looking at the thread.
 136  if(empty($mybb->input['action']))
 137  {
 138      $mybb->input['action'] = "thread";
 139  }
 140  
 141  // Jump to the unread posts.
 142  if($mybb->input['action'] == "newpost")
 143  {
 144      // First, figure out what time the thread or forum were last read
 145      $query = $db->simple_select("threadsread", "dateline", "uid='{$mybb->user['uid']}' AND tid='{$thread['tid']}'");
 146      $thread_read = $db->fetch_field($query, "dateline");
 147  
 148      if($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid'])
 149      {
 150          $query = $db->simple_select("forumsread", "dateline", "fid='{$fid}' AND uid='{$mybb->user['uid']}'");
 151          $forum_read = $db->fetch_field($query, "dateline");
 152      
 153          $read_cutoff = TIME_NOW-$mybb->settings['threadreadcut']*60*60*24;
 154          if($forum_read == 0 || $forum_read < $read_cutoff)
 155          {
 156              $forum_read = $read_cutoff;
 157          }
 158      }
 159      else
 160      {
 161          $forum_read = intval(my_get_array_cookie("forumread", $fid));
 162      }
 163      
 164      if($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid'] && $thread['lastpost'] > $forum_read)
 165      {
 166          $cutoff = TIME_NOW-$mybb->settings['threadreadcut']*60*60*24;
 167          if($thread['lastpost'] > $cutoff)
 168          {
 169              if($thread_read)
 170              {
 171                  $lastread = $thread_read;
 172              }
 173              else
 174              {
 175                  // Set $lastread to zero to make sure 'lastpost' is invoked in the last IF
 176                  $lastread = 0;
 177              }
 178          }
 179      }
 180      
 181      if(!$lastread)
 182      {
 183          $readcookie = $threadread = intval(my_get_array_cookie("threadread", $thread['tid']));
 184          if($readcookie > $forum_read)
 185          {
 186              $lastread = $readcookie;
 187          }
 188          else
 189          {
 190              $lastread = $forum_read;
 191          }
 192      }
 193      
 194     if($cutoff && $lastread < $cutoff)
 195     {
 196            $lastread = $cutoff;
 197     }
 198      
 199      // Next, find the proper pid to link to.
 200      $options = array(
 201          "limit_start" => 0,
 202          "limit" => 1,
 203          "order_by" => "dateline",
 204          "order_dir" => "asc"
 205      );
 206  
 207      $lastread = intval($lastread);
 208      $query = $db->simple_select("posts", "pid", "tid='{$tid}' AND dateline > '{$lastread}' {$visibleonly}", $options);
 209      $newpost = $db->fetch_array($query);
 210      
 211      if($newpost['pid'] && $lastread)
 212      {
 213          $highlight = '';
 214          if($mybb->input['highlight'])
 215          {
 216              $string = "&";
 217              if($mybb->settings['seourls'] == "yes" || ($mybb->settings['seourls'] == "auto" && $_SERVER['SEO_SUPPORT'] == 1))
 218              {
 219                  $string = "?";
 220              }
 221  
 222              $highlight = $string."highlight=".$mybb->input['highlight'];
 223          }
 224  
 225          header("Location: ".htmlspecialchars_decode(get_post_link($newpost['pid'], $tid)).$highlight."#pid{$newpost['pid']}");
 226      }
 227      else
 228      {
 229          // show them to the last post
 230          $mybb->input['action'] = "lastpost";
 231      }
 232  }
 233  
 234  // Jump to the last post.
 235  if($mybb->input['action'] == "lastpost")
 236  {
 237      if(my_strpos($thread['closed'], "moved|"))
 238      {
 239          $query = $db->query("
 240              SELECT p.pid
 241              FROM ".TABLE_PREFIX."posts p
 242              LEFT JOIN ".TABLE_PREFIX."threads t ON(p.tid=t.tid)
 243              WHERE t.fid='".$thread['fid']."' AND t.closed NOT LIKE 'moved|%' {$visibleonly2}
 244              ORDER BY p.dateline DESC
 245              LIMIT 1
 246          ");
 247          $pid = $db->fetch_field($query, "pid");
 248      }
 249      else
 250      {
 251          $options = array(
 252              'order_by' => 'dateline',
 253              'order_dir' => 'desc',
 254              'limit_start' => 0,
 255              'limit' => 1
 256          );
 257          $query = $db->simple_select('posts', 'pid', "tid={$tid} {$visibleonly}", $options);
 258          $pid = $db->fetch_field($query, "pid");
 259      }
 260      header("Location: ".htmlspecialchars_decode(get_post_link($pid, $tid))."#pid{$pid}");
 261      exit;
 262  }
 263  
 264  // Jump to the next newest posts.
 265  if($mybb->input['action'] == "nextnewest")
 266  {
 267      $options = array(
 268          "limit_start" => 0,
 269          "limit" => 1,
 270          "order_by" => "lastpost"
 271      );
 272      $query = $db->simple_select('threads', '*', "fid={$thread['fid']} AND lastpost > {$thread['lastpost']} {$visibleonly} AND closed NOT LIKE 'moved|%'", $options);
 273      $nextthread = $db->fetch_array($query);
 274  
 275      // Are there actually next newest posts?
 276      if(!$nextthread['tid'])
 277      {
 278          error($lang->error_nonextnewest);
 279      }
 280      $options = array(
 281          "limit_start" => 0,
 282          "limit" => 1,
 283          "order_by" => "dateline",
 284          "order_dir" => "desc"
 285      );
 286      $query = $db->simple_select('posts', 'pid', "tid='{$nextthread['tid']}'", $options);
 287  
 288      // Redirect to the proper page.
 289      $pid = $db->fetch_field($query, "pid");
 290      header("Location: ".htmlspecialchars_decode(get_post_link($pid, $nextthread['tid']))."#pid{$pid}");
 291      exit;
 292  }
 293  
 294  // Jump to the next oldest posts.
 295  if($mybb->input['action'] == "nextoldest")
 296  {
 297      $options = array(
 298          "limit" => 1,
 299          "limit_start" => 0,
 300          "order_by" => "lastpost",
 301          "order_dir" => "desc"
 302      );
 303      $query = $db->simple_select("threads", "*", "fid=".$thread['fid']." AND lastpost < ".$thread['lastpost']." {$visibleonly} AND closed NOT LIKE 'moved|%'", $options);
 304      $nextthread = $db->fetch_array($query);
 305  
 306      // Are there actually next oldest posts?
 307      if(!$nextthread['tid'])
 308      {
 309          error($lang->error_nonextoldest);
 310      }
 311      $options = array(
 312          "limit_start" => 0,
 313          "limit" => 1,
 314          "order_by" => "dateline",
 315          "order_dir" => "desc"
 316      );
 317      $query = $db->simple_select("posts", "pid", "tid='".$nextthread['tid']."'", $options);
 318  
 319      // Redirect to the proper page.
 320      $pid = $db->fetch_field($query, "pid");
 321      header("Location: ".htmlspecialchars_decode(get_post_link($pid, $nextthread['tid']))."#pid{$pid}");
 322      exit;
 323  }
 324  
 325  if(!empty($mybb->input['pid']))
 326  {
 327      $pid = $mybb->input['pid'];
 328  }
 329  
 330  // Forumdisplay cache
 331  $forum_stats = $cache->read("forumsdisplay");
 332  
 333  $breadcrumb_multipage = array();
 334  if($mybb->settings['showforumpagesbreadcrumb'])
 335  {
 336      // How many pages are there?
 337      if(!$mybb->settings['threadsperpage'])
 338      {
 339          $mybb->settings['threadsperpage'] = 20;
 340      }
 341  
 342      $query = $db->simple_select("forums", "threads, unapprovedthreads", "fid = '{$fid}'", array('limit' => 1));
 343      $forum_threads = $db->fetch_array($query);
 344      $threadcount = $forum_threads['threads'];
 345  
 346      if($ismod == true)
 347      {
 348          $threadcount += $forum_threads['unapprovedthreads'];
 349      }
 350  
 351      // Limit to only our own threads
 352      $uid_only = '';
 353      if(isset($forumpermissions['canonlyviewownthreads']) && $forumpermissions['canonlyviewownthreads'] == 1)
 354      {
 355          $uid_only = " AND uid = '".$mybb->user['uid']."'";
 356  
 357          $query = $db->simple_select("threads", "COUNT(tid) AS threads", "fid = '$fid' $visibleonly $uid_only", array('limit' => 1));
 358          $threadcount = $db->fetch_field($query, "threads");
 359      }
 360  
 361      // If we have 0 threads double check there aren't any "moved" threads
 362      if($threadcount == 0)
 363      {
 364          $query = $db->simple_select("threads", "COUNT(tid) AS threads", "fid = '$fid' $visibleonly $uid_only", array('limit' => 1));
 365          $threadcount = $db->fetch_field($query, "threads");
 366      }
 367  
 368      $stickybit = " OR sticky=1";
 369      if($thread['sticky'] == 1)
 370      {
 371          $stickybit = " AND sticky=1";
 372      }
 373  
 374      // Figure out what page the thread is actually on
 375      switch($db->type)
 376      {
 377          case "pgsql":
 378              $query = $db->query("
 379                  SELECT COUNT(tid) as threads
 380                  FROM ".TABLE_PREFIX."threads
 381                  WHERE fid = '$fid' AND (lastpost >= '".intval($thread['lastpost'])."'{$stickybit}) {$visibleonly} {$uid_only}
 382                  GROUP BY lastpost
 383                  ORDER BY lastpost DESC
 384              ");
 385              break;
 386          default:
 387              $query = $db->simple_select("threads", "COUNT(tid) as threads", "fid = '$fid' AND (lastpost >= '".intval($thread['lastpost'])."'{$stickybit}) {$visibleonly} {$uid_only}", array('order_by' => 'lastpost', 'order_dir' => 'desc'));
 388      }
 389  
 390      $thread_position = $db->fetch_field($query, "threads");
 391      $thread_page = ceil(($thread_position/$mybb->settings['threadsperpage']));
 392  
 393      $breadcrumb_multipage = array(
 394          "num_threads" => $threadcount,
 395          "current_page" => $thread_page
 396      );
 397  }
 398  
 399  // Build the navigation.
 400  build_forum_breadcrumb($fid, $breadcrumb_multipage);
 401  add_breadcrumb($thread['displayprefix'].$thread['subject'], get_thread_link($thread['tid']));
 402  
 403  $plugins->run_hooks("showthread_start");
 404  
 405  // Show the entire thread (taking into account pagination).
 406  if($mybb->input['action'] == "thread")
 407  {
 408      if($thread['firstpost'] == 0)
 409      {
 410          update_first_post($tid);
 411      }
 412      
 413      // Does this thread have a poll?
 414      if($thread['poll'])
 415      {
 416          $options = array(
 417              "limit" => 1
 418          );
 419          $query = $db->simple_select("polls", "*", "pid='".$thread['poll']."'", $options);
 420          $poll = $db->fetch_array($query);
 421          $poll['timeout'] = $poll['timeout']*60*60*24;
 422          $expiretime = $poll['dateline'] + $poll['timeout'];
 423          $now = TIME_NOW;
 424  
 425          // If the poll or the thread is closed or if the poll is expired, show the results.
 426          if($poll['closed'] == 1 || $thread['closed'] == 1 || ($expiretime < $now && $poll['timeout'] > 0))
 427          {
 428              $showresults = 1;
 429          }
 430  
 431          // If the user is not a guest, check if he already voted.
 432          if($mybb->user['uid'] != 0)
 433          {
 434              $query = $db->simple_select("pollvotes", "*", "uid='".$mybb->user['uid']."' AND pid='".$poll['pid']."'");
 435              while($votecheck = $db->fetch_array($query))
 436              {    
 437                  $alreadyvoted = 1;
 438                  $votedfor[$votecheck['voteoption']] = 1;
 439              }
 440          }
 441          else
 442          {
 443              if(isset($mybb->cookies['pollvotes'][$poll['pid']]) && $mybb->cookies['pollvotes'][$poll['pid']] !== "")
 444              {
 445                  $alreadyvoted = 1;
 446              }
 447          }
 448          $optionsarray = explode("||~|~||", $poll['options']);
 449          $votesarray = explode("||~|~||", $poll['votes']);
 450          $poll['question'] = htmlspecialchars_uni($poll['question']);
 451          $polloptions = '';
 452          $totalvotes = 0;
 453  
 454          for($i = 1; $i <= $poll['numoptions']; ++$i)
 455          {
 456              $poll['totvotes'] = $poll['totvotes'] + $votesarray[$i-1];
 457          }
 458  
 459          // Loop through the poll options.
 460          for($i = 1; $i <= $poll['numoptions']; ++$i)
 461          {
 462              // Set up the parser options.
 463              $parser_options = array(
 464                  "allow_html" => $forum['allowhtml'],
 465                  "allow_mycode" => $forum['allowmycode'],
 466                  "allow_smilies" => $forum['allowsmilies'],
 467                  "allow_imgcode" => $forum['allowimgcode'],
 468                  "allow_videocode" => $forum['allowvideocode'],
 469                  "filter_badwords" => 1
 470              );
 471  
 472              $option = $parser->parse_message($optionsarray[$i-1], $parser_options);
 473              $votes = $votesarray[$i-1];
 474              $totalvotes += $votes;
 475              $number = $i;
 476  
 477              // Mark the option the user voted for.
 478              if($votedfor[$number])
 479              {
 480                  $optionbg = "trow2";
 481                  $votestar = "*";
 482              }
 483              else
 484              {
 485                  $optionbg = "trow1";
 486                  $votestar = "";
 487              }
 488  
 489              // If the user already voted or if the results need to be shown, do so; else show voting screen.
 490              if($alreadyvoted || $showresults)
 491              {
 492                  if(intval($votes) == "0")
 493                  {
 494                      $percent = "0";
 495                  }
 496                  else
 497                  {
 498                      $percent = number_format($votes / $poll['totvotes'] * 100, 2);
 499                  }
 500                  $imagewidth = round(($percent/3) * 5);
 501                  $imagerowwidth = $imagewidth + 10;
 502                  eval("\$polloptions .= \"".$templates->get("showthread_poll_resultbit")."\";");
 503              }
 504              else
 505              {
 506                  if($poll['multiple'] == 1)
 507                  {
 508                      eval("\$polloptions .= \"".$templates->get("showthread_poll_option_multiple")."\";");
 509                  }
 510                  else
 511                  {
 512                      eval("\$polloptions .= \"".$templates->get("showthread_poll_option")."\";");
 513                  }
 514              }
 515          }
 516  
 517          // If there are any votes at all, all votes together will be 100%; if there are no votes, all votes together will be 0%.
 518          if($poll['totvotes'])
 519          {
 520              $totpercent = "100%";
 521          }
 522          else
 523          {
 524              $totpercent = "0%";
 525          }
 526  
 527          // Check if user is allowed to edit posts; if so, show "edit poll" link.
 528          if(!is_moderator($fid, 'caneditposts'))
 529          {
 530              $edit_poll = '';
 531          }
 532          else
 533          {
 534              $edit_poll = " | <a href=\"polls.php?action=editpoll&amp;pid={$poll['pid']}\">{$lang->edit_poll}</a>";
 535          }
 536  
 537          // Decide what poll status to show depending on the status of the poll and whether or not the user voted already.
 538          if($alreadyvoted || $showresults)
 539          {
 540              if($alreadyvoted)
 541              {
 542                  $pollstatus = $lang->already_voted;
 543                  
 544                  if($mybb->usergroup['canundovotes'] == 1)
 545                  {
 546                      $pollstatus .= " [<a href=\"polls.php?action=do_undovote&amp;pid={$poll['pid']}&amp;my_post_key={$mybb->post_code}\">{$lang->undo_vote}</a>]";
 547                  }
 548              }
 549              else
 550              {
 551                  $pollstatus = $lang->poll_closed;
 552              }
 553              $lang->total_votes = $lang->sprintf($lang->total_votes, $totalvotes);
 554              eval("\$pollbox = \"".$templates->get("showthread_poll_results")."\";");
 555              $plugins->run_hooks("showthread_poll_results");
 556          }
 557          else
 558          {
 559              $publicnote = '&nbsp;';
 560              if($poll['public'] == 1)
 561              {
 562                  $publicnote = $lang->public_note;
 563              }
 564              eval("\$pollbox = \"".$templates->get("showthread_poll")."\";");
 565              $plugins->run_hooks("showthread_poll");
 566          }
 567  
 568      }
 569      else
 570      {
 571          $pollbox = "";
 572      }
 573  
 574      // Create the forum jump dropdown box.
 575      if($mybb->settings['enableforumjump'] != 0)
 576      {
 577          $forumjump = build_forum_jump("", $fid, 1);
 578      }
 579      
 580      // Fetch some links
 581      $next_oldest_link = get_thread_link($tid, 0, "nextoldest");
 582      $next_newest_link = get_thread_link($tid, 0, "nextnewest");
 583  
 584      // Mark this thread as read
 585      mark_thread_read($tid, $fid);
 586  
 587      // If the forum is not open, show closed newreply button unless the user is a moderator of this forum.
 588      if($forum['open'] != 0)
 589      {
 590          eval("\$newthread = \"".$templates->get("showthread_newthread")."\";");
 591  
 592          // Show the appropriate reply button if this thread is open or closed
 593          if($thread['closed'] == 1)
 594          {
 595              eval("\$newreply = \"".$templates->get("showthread_newreply_closed")."\";");
 596          }
 597          else
 598          {
 599              eval("\$newreply = \"".$templates->get("showthread_newreply")."\";");
 600          }
 601      }
 602  
 603      // Create the admin tools dropdown box.
 604      if($ismod == true)
 605      {
 606          $adminpolloptions = $closelinkch = $stickch = '';
 607  
 608          if($pollbox)
 609          {
 610              $adminpolloptions = "<option value=\"deletepoll\">".$lang->delete_poll."</option>";
 611          }
 612          if($thread['visible'] != 1)
 613          {
 614              $approveunapprovethread = "<option value=\"approvethread\">".$lang->approve_thread."</option>";
 615          }
 616          else
 617          {
 618              $approveunapprovethread = "<option value=\"unapprovethread\">".$lang->unapprove_thread."</option>";
 619          }
 620          if($thread['closed'] == 1)
 621          {
 622              $closelinkch = ' checked="checked"';
 623          }
 624          if($thread['sticky'])
 625          {
 626              $stickch = ' checked="checked"';
 627          }
 628          $closeoption = "<br /><label><input type=\"checkbox\" class=\"checkbox\" name=\"modoptions[closethread]\" value=\"1\"{$closelinkch} />&nbsp;<strong>".$lang->close_thread."</strong></label>";
 629          $closeoption .= "<br /><label><input type=\"checkbox\" class=\"checkbox\" name=\"modoptions[stickthread]\" value=\"1\"{$stickch} />&nbsp;<strong>".$lang->stick_thread."</strong></label>";
 630          $inlinecount = "0";
 631          $inlinecookie = "inlinemod_thread".$tid;
 632          $plugins->run_hooks("showthread_ismod");
 633      }
 634      else
 635      {
 636          $modoptions = "&nbsp;";
 637          $inlinemod = "";
 638      }
 639  
 640      // Increment the thread view.
 641      if($mybb->settings['delayedthreadviews'] == 1)
 642      {
 643          $db->shutdown_query("INSERT INTO ".TABLE_PREFIX."threadviews (tid) VALUES('{$tid}')");
 644      }
 645      else
 646      {
 647          $db->shutdown_query("UPDATE ".TABLE_PREFIX."threads SET views=views+1 WHERE tid='{$tid}'");
 648      }
 649      ++$thread['views'];
 650  
 651      // Work out the thread rating for this thread.
 652      $rating = '';
 653      if($mybb->settings['allowthreadratings'] != 0 && $forum['allowtratings'] != 0)
 654      {
 655          $rated = 0;
 656          $lang->load("ratethread");
 657          if($thread['numratings'] <= 0)
 658          {
 659              $thread['width'] = 0;
 660              $thread['averagerating'] = 0;
 661              $thread['numratings'] = 0;
 662          }
 663          else
 664          {
 665              $thread['averagerating'] = floatval(round($thread['totalratings']/$thread['numratings'], 2));
 666              $thread['width'] = intval(round($thread['averagerating']))*20;
 667              $thread['numratings'] = intval($thread['numratings']);
 668          }
 669  
 670          if($thread['numratings'])
 671          {
 672              // At least >someone< has rated this thread, was it me?
 673              // Check if we have already voted on this thread - it won't show hover effect then.
 674              $query = $db->simple_select("threadratings", "uid", "tid='{$tid}' AND uid='{$mybb->user['uid']}'");
 675              $rated = $db->fetch_field($query, 'uid');
 676          }
 677  
 678          $not_rated = '';
 679          if(!$rated)
 680          {
 681              $not_rated = ' star_rating_notrated';
 682          }
 683  
 684          $ratingvotesav = $lang->sprintf($lang->rating_average, $thread['numratings'], $thread['averagerating']);
 685          eval("\$ratethread = \"".$templates->get("showthread_ratethread")."\";");
 686      }
 687      // Work out if we are showing unapproved posts as well (if the user is a moderator etc.)
 688      if($ismod)
 689      {
 690          $visible = "AND (p.visible='0' OR p.visible='1')";
 691      }
 692      else
 693      {
 694          $visible = "AND p.visible='1'";
 695      }
 696      
 697      // Can this user perform searches? If so, we can show them the "Search thread" form
 698      if($forumpermissions['cansearch'] != 0)
 699      {
 700          eval("\$search_thread = \"".$templates->get("showthread_search")."\";");
 701      }
 702  
 703      // Fetch the ignore list for the current user if they have one
 704      $ignored_users = array();
 705      if($mybb->user['uid'] > 0 && $mybb->user['ignorelist'] != "")
 706      {
 707          $ignore_list = explode(',', $mybb->user['ignorelist']);
 708          foreach($ignore_list as $uid)
 709          {
 710              $ignored_users[$uid] = 1;
 711          }
 712      }
 713      
 714      // Which thread mode is our user using by default?
 715      if(!empty($mybb->user['threadmode']))
 716      {
 717          $defaultmode = $mybb->user['threadmode'];
 718      }
 719      else if($mybb->settings['threadusenetstyle'] == 1)
 720      {
 721          $defaultmode = 'threaded';
 722      }
 723      else
 724      {
 725          $defaultmode = 'linear';
 726      }
 727      
 728      // If mode is unset, set the default mode
 729      if(!isset($mybb->input['mode']))
 730      {
 731          $mybb->input['mode'] = $defaultmode;
 732      }
 733  
 734      // Threaded or linear display?
 735      if($mybb->input['mode'] == 'threaded')
 736      {
 737          $isfirst = 1;
 738  
 739          // Are we linked to a specific pid?
 740          if($mybb->input['pid'])
 741          {
 742              $where = "AND p.pid='".$mybb->input['pid']."'";
 743          }
 744          else
 745          {
 746              $where = " ORDER BY dateline LIMIT 0, 1";
 747          }
 748          $query = $db->query("
 749              SELECT u.*, u.username AS userusername, p.*, f.*, eu.username AS editusername
 750              FROM ".TABLE_PREFIX."posts p
 751              LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
 752              LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid)
 753              LEFT JOIN ".TABLE_PREFIX."users eu ON (eu.uid=p.edituid)
 754              WHERE p.tid='$tid' $visible $where
 755          ");
 756          $showpost = $db->fetch_array($query);
 757  
 758          // Choose what pid to display.
 759          if(!$mybb->input['pid'])
 760          {
 761              $mybb->input['pid'] = $showpost['pid'];
 762          }
 763  
 764          // Is there actually a pid to display?
 765          if(!$showpost['pid'])
 766          {
 767              error($lang->error_invalidpost);
 768          }
 769          
 770          $attachcache = array();
 771          if($thread['attachmentcount'] > 0 || is_moderator($fid, 'caneditposts'))
 772          {
 773              // Get the attachments for this post.
 774              $query = $db->simple_select("attachments", "*", "pid=".$mybb->input['pid']);
 775              while($attachment = $db->fetch_array($query))
 776              {
 777                  $attachcache[$attachment['pid']][$attachment['aid']] = $attachment;
 778              }
 779          }
 780  
 781          // Build the threaded post display tree.
 782          $query = $db->query("
 783              SELECT p.username, p.uid, p.pid, p.replyto, p.subject, p.dateline
 784              FROM ".TABLE_PREFIX."posts p
 785              WHERE p.tid='$tid'
 786              $visible
 787              ORDER BY p.dateline
 788          ");
 789          while($post = $db->fetch_array($query))
 790          {
 791              if(!$postsdone[$post['pid']])
 792              {
 793                  if($post['pid'] == $mybb->input['pid'] || ($isfirst && !$mybb->input['pid']))
 794                  {
 795                      $postcounter = count($postsdone);
 796                      $isfirst = 0;
 797                  }
 798                  $tree[$post['replyto']][$post['pid']] = $post;
 799                  $postsdone[$post['pid']] = 1;
 800              }
 801          }
 802          
 803          $threadedbits = buildtree();
 804          $posts = build_postbit($showpost);
 805          eval("\$threadexbox = \"".$templates->get("showthread_threadedbox")."\";");
 806          $plugins->run_hooks("showthread_threaded");
 807      }
 808      else // Linear display
 809      {
 810          $threadexbox = '';
 811          if(!$mybb->settings['postsperpage'])
 812          {
 813              $mybb->settings['postperpage'] = 20;
 814          }
 815          
 816          // Figure out if we need to display multiple pages.
 817          $page = 1;
 818          $perpage = $mybb->settings['postsperpage'];
 819          if(isset($mybb->input['page']) && $mybb->input['page'] != "last")
 820          {
 821              $page = intval($mybb->input['page']);
 822          }
 823  
 824          if(!empty($mybb->input['pid']))
 825          {
 826              $post = get_post($mybb->input['pid']);
 827              if($post)
 828              {
 829                  $query = $db->query("
 830                      SELECT COUNT(p.dateline) AS count FROM ".TABLE_PREFIX."posts p
 831                      WHERE p.tid = '{$tid}'
 832                      AND p.dateline <= '{$post['dateline']}'
 833                      {$visible}
 834                  ");
 835                  $result = $db->fetch_field($query, "count");
 836                  if(($result % $perpage) == 0)
 837                  {
 838                      $page = $result / $perpage;
 839                  }
 840                  else
 841                  {
 842                      $page = intval($result / $perpage) + 1;
 843                  }
 844              }
 845          }
 846  
 847          // Recount replies if user is a moderator to take into account unapproved posts.
 848          if($ismod)
 849          {
 850              $query = $db->simple_select("posts p", "COUNT(*) AS replies", "p.tid='$tid' $visible");
 851              $cached_replies = $thread['replies']+$thread['unapprovedposts'];
 852              $thread['replies'] = $db->fetch_field($query, 'replies')-1;
 853              
 854              // The counters are wrong? Rebuild them
 855              // This doesn't cover all cases however it is a good addition to the manual rebuild function
 856              if($thread['replies'] != $cached_replies)
 857              {
 858                  require_once  MYBB_ROOT."/inc/functions_rebuild.php";
 859                  rebuild_thread_counters($thread['tid']);
 860              }
 861          }
 862  
 863          $postcount = intval($thread['replies'])+1;
 864          $pages = $postcount / $perpage;
 865          $pages = ceil($pages);
 866  
 867          if(isset($mybb->input['page']) && $mybb->input['page'] == "last")
 868          {
 869              $page = $pages;
 870          }
 871  
 872          if($page > $pages || $page <= 0)
 873          {
 874              $page = 1;
 875          }
 876  
 877          if($page)
 878          {
 879              $start = ($page-1) * $perpage;
 880          }
 881          else
 882          {
 883              $start = 0;
 884              $page = 1;
 885          }
 886          $upper = $start+$perpage;
 887          
 888          // Work out if we have terms to highlight
 889          $highlight = "";
 890          $threadmode = "";
 891          if($mybb->settings['seourls'] == "yes" || ($mybb->settings['seourls'] == "auto" && isset($_SERVER['SEO_SUPPORT']) && $_SERVER['SEO_SUPPORT'] == 1))
 892          {
 893              if($mybb->input['highlight'])
 894              {
 895                  $highlight = "?highlight=".urlencode($mybb->input['highlight']);
 896              }
 897              
 898              if($defaultmode != "linear")
 899              {
 900                  if($mybb->input['highlight'])
 901                  {
 902                      $threadmode = "&amp;mode=linear";
 903                  }
 904                  else 
 905                  {
 906                      $threadmode = "?mode=linear";
 907                  }
 908              }
 909          }
 910          else
 911          {
 912              if(!empty($mybb->input['highlight']))
 913              {
 914                  if(is_array($mybb->input['highlight']))
 915                  {
 916                      foreach($mybb->input['highlight'] as $highlight_word)
 917                      {
 918                          $highlight .= "&amp;highlight[]=".urlencode($highlight_word);
 919                      }
 920                  }
 921                  else
 922                  {
 923                      $highlight = "&amp;highlight=".urlencode($mybb->input['highlight']);
 924                  }
 925              }
 926              
 927              if($defaultmode != "linear")
 928              {
 929                  $threadmode = "&amp;mode=linear";
 930              }
 931          }
 932  
 933          $multipage = multipage($postcount, $perpage, $page, str_replace("{tid}", $tid, THREAD_URL_PAGED.$highlight.$threadmode));
 934          if($postcount > $perpage)
 935          {
 936              eval("\$threadpages = \"".$templates->get("showthread_multipage")."\";");
 937          }
 938  
 939          // Lets get the pids of the posts on this page.
 940          $pids = "";
 941          $comma = '';
 942          $query = $db->simple_select("posts p", "p.pid", "p.tid='$tid' $visible", array('order_by' => 'p.dateline', 'limit_start' => $start, 'limit' => $perpage));
 943          while($getid = $db->fetch_array($query))
 944          {
 945              // Set the ID of the first post on page to $pid if it doesn't hold any value
 946              // to allow this value to be used for Thread Mode/Linear Mode links
 947              // and ensure the user lands on the correct page after changing view mode
 948              if(empty($pid))
 949              {
 950                  $pid = $getid['pid'];
 951              }
 952              // Gather a comma separated list of post IDs
 953              $pids .= "$comma'{$getid['pid']}'";
 954              $comma = ",";
 955          }
 956          if($pids)
 957          {
 958              $pids = "pid IN($pids)";
 959              
 960              $attachcache = array();
 961              if($thread['attachmentcount'] > 0 || is_moderator($fid, 'caneditposts'))
 962              {
 963                  // Now lets fetch all of the attachments for these posts.
 964                  $query = $db->simple_select("attachments", "*", $pids);
 965                  while($attachment = $db->fetch_array($query))
 966                  {
 967                      $attachcache[$attachment['pid']][$attachment['aid']] = $attachment;
 968                  }
 969              }
 970          }
 971          else
 972          {
 973              // If there are no pid's the thread is probably awaiting approval.
 974              error($lang->error_invalidthread);
 975          }
 976  
 977          // Get the actual posts from the database here.
 978          $posts = '';
 979          $query = $db->query("
 980              SELECT u.*, u.username AS userusername, p.*, f.*, eu.username AS editusername
 981              FROM ".TABLE_PREFIX."posts p
 982              LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
 983              LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid)
 984              LEFT JOIN ".TABLE_PREFIX."users eu ON (eu.uid=p.edituid)
 985              WHERE $pids
 986              ORDER BY p.dateline
 987          ");
 988          while($post = $db->fetch_array($query))
 989          {
 990              if($thread['firstpost'] == $post['pid'] && $thread['visible'] == 0)
 991              {
 992                  $post['visible'] = 0;
 993              }
 994              $posts .= build_postbit($post);
 995              $post = '';
 996          }
 997          $plugins->run_hooks("showthread_linear");
 998      }
 999  
1000      // Show the similar threads table if wanted.
1001      $similarthreads = '';
1002      if($mybb->settings['showsimilarthreads'] != 0)
1003      {
1004          switch($db->type)
1005          {
1006              case "pgsql":
1007                  $query = $db->query("
1008                      SELECT t.*, t.username AS threadusername, u.username
1009                      FROM ".TABLE_PREFIX."threads t
1010                      LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid), plainto_tsquery ('".$db->escape_string($thread['subject'])."') AS query
1011                      WHERE t.fid='{$thread['fid']}' AND t.tid!='{$thread['tid']}' AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND t.subject @@ query
1012                      ORDER BY t.lastpost DESC
1013                      OFFSET 0 LIMIT {$mybb->settings['similarlimit']}
1014                  ");
1015                  break;
1016              default:
1017                  $query = $db->query("
1018                      SELECT t.*, t.username AS threadusername, u.username, MATCH (t.subject) AGAINST ('".$db->escape_string($thread['subject'])."') AS relevance
1019                      FROM ".TABLE_PREFIX."threads t
1020                      LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid)
1021                      WHERE t.fid='{$thread['fid']}' AND t.tid!='{$thread['tid']}' AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND MATCH (t.subject) AGAINST ('".$db->escape_string($thread['subject'])."') >= '{$mybb->settings['similarityrating']}'
1022                      ORDER BY t.lastpost DESC
1023                      LIMIT 0, {$mybb->settings['similarlimit']}
1024                  ");
1025          }
1026  
1027          $count = 0;
1028          $similarthreadbits = '';
1029          $icon_cache = $cache->read("posticons");
1030          while($similar_thread = $db->fetch_array($query))
1031          {
1032              ++$count;
1033              $trow = alt_trow();
1034              if($similar_thread['icon'] > 0 && $icon_cache[$similar_thread['icon']])
1035              {
1036                  $icon = $icon_cache[$similar_thread['icon']];
1037                  $icon = "<img src=\"{$icon['path']}\" alt=\"{$icon['name']}\" />";
1038              }
1039              else
1040              {
1041                  $icon = "&nbsp;";
1042              }                
1043              if(!$similar_thread['username'])
1044              {
1045                  $similar_thread['username'] = $similar_thread['threadusername'];
1046                  $similar_thread['profilelink'] = $similar_thread['threadusername'];
1047              }
1048              else
1049              {
1050                  $similar_thread['profilelink'] = build_profile_link($similar_thread['username'], $similar_thread['uid']);
1051              }
1052              
1053              // If this thread has a prefix, insert a space between prefix and subject
1054              if($similar_thread['prefix'] != 0)
1055              {
1056                  $prefix = build_prefixes($similar_thread['prefix']);
1057                  $similar_thread['threadprefix'] = $prefix['displaystyle'].'&nbsp;';
1058              }
1059              
1060              $similar_thread['subject'] = $parser->parse_badwords($similar_thread['subject']);
1061              $similar_thread['subject'] = htmlspecialchars_uni($similar_thread['subject']);
1062              $similar_thread['threadlink'] = get_thread_link($similar_thread['tid']);
1063              $similar_thread['lastpostlink'] = get_thread_link($similar_thread['tid'], 0, "lastpost");
1064  
1065              $lastpostdate = my_date($mybb->settings['dateformat'], $similar_thread['lastpost']);
1066              $lastposttime = my_date($mybb->settings['timeformat'], $similar_thread['lastpost']);
1067              $lastposter = $similar_thread['lastposter'];
1068              $lastposteruid = $similar_thread['lastposteruid'];
1069  
1070              // Don't link to guest's profiles (they have no profile).
1071              if($lastposteruid == 0)
1072              {
1073                  $lastposterlink = $lastposter;
1074              }
1075              else
1076              {
1077                  $lastposterlink = build_profile_link($lastposter, $lastposteruid);
1078              }
1079              $similar_thread['replies'] = my_number_format($similar_thread['replies']);
1080              $similar_thread['views'] = my_number_format($similar_thread['views']);
1081              eval("\$similarthreadbits .= \"".$templates->get("showthread_similarthreads_bit")."\";");
1082          }
1083          if($count)
1084          {
1085              eval("\$similarthreads = \"".$templates->get("showthread_similarthreads")."\";");
1086          }
1087      }
1088  
1089      // Decide whether or not to show quick reply.
1090      $quickreply = '';
1091      if($forumpermissions['canpostreplys'] != 0 && $mybb->user['suspendposting'] != 1 && ($thread['closed'] != 1 || is_moderator($fid)) && $mybb->settings['quickreply'] != 0 && $mybb->user['showquickreply'] != '0' && $forum['open'] != 0)
1092      {
1093          $query = $db->simple_select("posts", "pid", "tid='{$tid}'", array("order_by" => "pid", "order_dir" => "desc", "limit" => 1));
1094          $last_pid = $db->fetch_field($query, "pid");
1095          
1096          // Show captcha image for guests if enabled
1097          $captcha = '';
1098          if($mybb->settings['captchaimage'] && !$mybb->user['uid'])
1099          {
1100              require_once  MYBB_ROOT.'inc/class_captcha.php';
1101              $post_captcha = new captcha(true, "post_captcha");
1102  
1103              if($post_captcha->html)
1104              {
1105                  $captcha = $post_captcha->html;
1106              }
1107          }
1108  
1109          $postoptionschecked = array('signature' => '', 'emailnotify' => '');
1110          if($mybb->user['signature'])
1111          {
1112              $postoptionschecked['signature'] = 'checked="checked"';
1113          }
1114          
1115          // Hide signature option if no permission
1116          $option_signature = '';
1117          if($mybb->usergroup['canusesig'] && !$mybb->user['suspendsignature'])
1118          {
1119              eval("\$option_signature = \"".$templates->get('showthread_quickreply_options_signature')."\";");
1120          }
1121  
1122          if(isset($mybb->user['emailnotify']) && $mybb->user['emailnotify'] == 1)
1123          {
1124              $postoptionschecked['emailnotify'] = 'checked="checked"';
1125          }
1126  
1127          $posthash = md5($mybb->user['uid'].random_str());
1128          eval("\$quickreply = \"".$templates->get("showthread_quickreply")."\";");
1129      }
1130      
1131      // If the user is a moderator, show the moderation tools.
1132      if($ismod)
1133      {
1134          $customthreadtools = $customposttools = '';
1135  
1136          if(is_moderator($forum['fid'], "canusecustomtools") && (!empty($forum_stats[-1]['modtools']) || !empty($forum_stats[$forum['fid']]['modtools'])))
1137          {
1138              switch($db->type)
1139              {
1140                  case "pgsql":
1141                  case "sqlite":
1142                      $query = $db->simple_select("modtools", "tid, name, type", "','||forums||',' LIKE '%,$fid,%' OR ','||forums||',' LIKE '%,-1,%' OR forums=''");
1143                      break;
1144                  default:
1145                      $query = $db->simple_select("modtools", "tid, name, type", "CONCAT(',',forums,',') LIKE '%,$fid,%' OR CONCAT(',',forums,',') LIKE '%,-1,%' OR forums=''");
1146              }
1147      
1148              while($tool = $db->fetch_array($query))
1149              {
1150                  if($tool['type'] == 'p')
1151                  {
1152                      eval("\$customposttools .= \"".$templates->get("showthread_inlinemoderation_custom_tool")."\";");
1153                  }
1154                  else
1155                  {
1156                      eval("\$customthreadtools .= \"".$templates->get("showthread_moderationoptions_custom_tool")."\";");
1157                  }
1158              }
1159  
1160              // Build inline moderation dropdown
1161              if(!empty($customposttools))
1162              {
1163                  eval("\$customposttools = \"".$templates->get("showthread_inlinemoderation_custom")."\";");
1164              }
1165          }
1166  
1167          eval("\$inlinemod = \"".$templates->get("showthread_inlinemoderation")."\";");
1168  
1169          // Build thread moderation dropdown
1170          if(!empty($customthreadtools))
1171          {
1172              eval("\$customthreadtools = \"".$templates->get("showthread_moderationoptions_custom")."\";");
1173          }
1174  
1175          eval("\$moderationoptions = \"".$templates->get("showthread_moderationoptions")."\";");
1176      }
1177  
1178      if(!isset($lang->newthread_in))
1179      {
1180          $lang->newthread_in = '';
1181      }
1182  
1183      $lang->newthread_in = $lang->sprintf($lang->newthread_in, $forum['name']);
1184      
1185      // Subscription status
1186      $add_remove_subscription = 'add';
1187      $add_remove_subscription_text = $lang->subscribe_thread;
1188  
1189      if($mybb->user['uid'])
1190      {
1191          $query = $db->simple_select("threadsubscriptions", "tid", "tid='".intval($tid)."' AND uid='".intval($mybb->user['uid'])."'", array('limit' => 1));
1192  
1193          if($db->fetch_field($query, 'tid'))
1194          {
1195              $add_remove_subscription = 'remove';
1196              $add_remove_subscription_text = $lang->unsubscribe_thread;
1197          }
1198      }
1199  
1200      $classic_header = '';
1201      if($mybb->settings['postlayout'] == "classic")
1202      {
1203          eval("\$classic_header = \"".$templates->get("showthread_classic_header")."\";");        
1204      }
1205      
1206      // Get users viewing this thread
1207      if($mybb->settings['browsingthisthread'] != 0)
1208      {
1209          $timecut = TIME_NOW - $mybb->settings['wolcutoff'];
1210  
1211          $comma = '';
1212          $guestcount = 0;
1213          $membercount = 0;
1214          $inviscount = 0;
1215          $onlinemembers = '';
1216          $doneusers = array();
1217  
1218          $query = $db->query("
1219              SELECT s.ip, s.uid, s.time, u.username, u.invisible, u.usergroup, u.displaygroup
1220              FROM ".TABLE_PREFIX."sessions s
1221              LEFT JOIN ".TABLE_PREFIX."users u ON (s.uid=u.uid)
1222              WHERE s.time > '$timecut' AND location2='$tid' AND nopermission != 1
1223              ORDER BY u.username ASC, s.time DESC
1224          ");
1225  
1226          while($user = $db->fetch_array($query))
1227          {
1228              if($user['uid'] == 0)
1229              {
1230                  ++$guestcount;
1231              }
1232              else if(empty($doneusers[$user['uid']]) || $doneusers[$user['uid']] < $user['time'])
1233              {
1234                  ++$membercount;
1235                  $doneusers[$user['uid']] = $user['time'];
1236  
1237                  $invisiblemark = '';
1238                  if($user['invisible'] == 1)
1239                  {
1240                      $invisiblemark = "*";
1241                      ++$inviscount;
1242                  }
1243  
1244                  if($user['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1 || $user['uid'] == $mybb->user['uid'])
1245                  {
1246                      $user['profilelink'] = get_profile_link($user['uid']);
1247                      $user['username'] = format_name($user['username'], $user['usergroup'], $user['displaygroup']);
1248                      $user['reading'] = my_date($mybb->settings['timeformat'], $user['time']);
1249  
1250                      eval("\$onlinemembers .= \"".$templates->get("showthread_usersbrowsing_user", 1, 0)."\";");
1251                      $comma = $lang->comma;
1252                  }
1253              }
1254          }
1255  
1256          $guestsonline = '';
1257  
1258          if($guestcount)
1259          {
1260              $guestsonline = $lang->sprintf($lang->users_browsing_thread_guests, $guestcount);
1261          }
1262  
1263          $onlinesep = '';
1264          if($guestcount && $onlinemembers)
1265          {
1266              $onlinesep = $lang->comma;
1267          }
1268  
1269          $invisonline = '';
1270          if($inviscount && $mybb->usergroup['canviewwolinvis'] != 1 && ($inviscount != 1 && $mybb->user['invisible'] != 1))
1271          {
1272              $invisonline = $lang->sprintf($lang->users_browsing_thread_invis, $inviscount);
1273          }
1274  
1275          $onlinesep2 = '';
1276          if($invisonline != '' && $guestcount)
1277          {
1278              $onlinesep2 = $lang->comma;
1279          }
1280  
1281          eval("\$usersbrowsing = \"".$templates->get("showthread_usersbrowsing")."\";");
1282      }
1283      
1284      $plugins->run_hooks("showthread_end");
1285      
1286      eval("\$showthread = \"".$templates->get("showthread")."\";");
1287      output_page($showthread);
1288  }
1289  
1290  /**
1291   * Build a navigation tree for threaded display.
1292   *
1293   * @param unknown_type $replyto
1294   * @param unknown_type $indent
1295   * @return unknown
1296   */
1297  function buildtree($replyto="0", $indent="0")
1298  {
1299      global $tree, $mybb, $theme, $mybb, $pid, $tid, $templates, $parser;
1300      
1301      if($indent)
1302      {
1303          $indentsize = 13 * $indent;
1304      }
1305      else
1306      {
1307          $indentsize = 0;
1308      }
1309      
1310      ++$indent;
1311      if(is_array($tree[$replyto]))
1312      {
1313          foreach($tree[$replyto] as $key => $post)
1314          {
1315              $postdate = my_date($mybb->settings['dateformat'], $post['dateline']);
1316              $posttime = my_date($mybb->settings['timeformat'], $post['dateline']);
1317              $post['subject'] = htmlspecialchars_uni($parser->parse_badwords($post['subject']));
1318              
1319              if(!$post['subject'])
1320              {
1321                  $post['subject'] = "[".$lang->no_subject."]";
1322              }
1323              
1324              $post['profilelink'] = build_profile_link($post['username'], $post['uid']);
1325          
1326              if($mybb->input['pid'] == $post['pid'])
1327              {
1328                  eval("\$posts .= \"".$templates->get("showthread_threaded_bitactive")."\";");
1329              }
1330              else
1331              {
1332                  eval("\$posts .= \"".$templates->get("showthread_threaded_bit")."\";");
1333              }
1334              
1335              if($tree[$post['pid']])
1336              {
1337                  $posts .= buildtree($post['pid'], $indent);
1338              }
1339          }
1340          --$indent;
1341      }
1342      return $posts;
1343  }
1344  ?>

title

Description

title

Description

title

Description

title

title

Body