[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/ -> showthread.php (source)

   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: showthread.php 5639 2011-10-26 09:16:47Z Tomm $
  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_sig,showthread_newpoll,postbit_avatar,postbit_profile,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_inline_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,thumbnails_thumbnail,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_quickquote,postbit_qqmessage,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";
  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($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  // Get thread prefix if there is one.
  55  $thread['threadprefix'] = '';
  56  $thread['displayprefix'] = '';
  57  if($thread['prefix'] != 0)
  58  {
  59      $threadprefix = build_prefixes($thread['prefix']);
  60  
  61      if($threadprefix['prefix'])
  62      {
  63          $thread['threadprefix'] = $threadprefix['prefix'].'&nbsp;';
  64          $thread['displayprefix'] = $threadprefix['displaystyle'].'&nbsp;';
  65      }
  66  }
  67  
  68  if(substr($thread['closed'], 0, 6) == "moved|")
  69  {
  70      $thread['tid'] = 0;
  71  }
  72  
  73  $thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject']));
  74  $tid = $thread['tid'];
  75  $fid = $thread['fid'];
  76  
  77  if(!$thread['username'])
  78  {
  79      $thread['username'] = $lang->guest;
  80  }
  81  
  82  $visibleonly = "AND visible='1'";
  83  
  84  // Is the currently logged in user a moderator of this forum?
  85  if(is_moderator($fid))
  86  {
  87      $visibleonly = " AND (visible='1' OR visible='0')";
  88      $ismod = true;
  89  }
  90  else
  91  {
  92      $ismod = false;
  93  }
  94  
  95  // Make sure we are looking at a real thread here.
  96  if(!$thread['tid'] || ($thread['visible'] == 0 && $ismod == false) || ($thread['visible'] > 1 && $ismod == true))
  97  {
  98      error($lang->error_invalidthread);
  99  }
 100  
 101  $forumpermissions = forum_permissions($thread['fid']);
 102  
 103  // Does the user have permission to view this thread?
 104  if($forumpermissions['canview'] != 1 || $forumpermissions['canviewthreads'] != 1)
 105  {
 106      error_no_permission();
 107  }
 108  
 109  if($forumpermissions['canonlyviewownthreads'] == 1 && $thread['uid'] != $mybb->user['uid'])
 110  {
 111      error_no_permission();
 112  }
 113  
 114  $archive_url = build_archive_link("thread", $tid);
 115  
 116  // Does the thread belong to a valid forum?
 117  $forum = get_forum($fid);
 118  if(!$forum || $forum['type'] != "f")
 119  {
 120      error($lang->error_invalidforum);
 121  }
 122  
 123  // Forumdisplay cache
 124  $forum_stats = $cache->read("forumsdisplay");
 125  
 126  if(!is_array($forum_stats))
 127  {
 128      // Attempt to rebuild it?
 129      $forum_stats = $cache->read("forumdisplay", true);
 130  
 131      if(!is_array($forum_stats))
 132      {
 133          $forum_stats = array();
 134      }
 135  }
 136  
 137  $breadcrumb_multipage = array();
 138  if($mybb->settings['showforumpagesbreadcrumb'])
 139  {
 140      // How many pages are there?
 141      if(!$mybb->settings['threadsperpage'])
 142      {
 143          $mybb->settings['threadsperpage'] = 20;
 144      }
 145  
 146      $query = $db->simple_select("forums", "threads, unapprovedthreads", "fid = '{$fid}'", array('limit' => 1));
 147      $forum_threads = $db->fetch_array($query);
 148      $threadcount = $forum_threads['threads'];
 149  
 150      if($ismod == true)
 151      {
 152          $threadcount += $forum_threads['unapprovedthreads'];
 153      }
 154  
 155      // Limit to only our own threads
 156      $uid_only = '';
 157      if($forumpermissions['canonlyviewownthreads'] == 1)
 158      {
 159          $uid_only = " AND uid = '".$mybb->user['uid']."'";
 160  
 161          $query = $db->simple_select("threads", "COUNT(tid) AS threads", "fid = '$fid' $visibleonly $uid_only", array('limit' => 1));
 162          $threadcount = $db->fetch_field($query, "threads");
 163      }
 164  
 165      // If we have 0 threads double check there aren't any "moved" threads
 166      if($threadcount == 0)
 167      {
 168          $query = $db->simple_select("threads", "COUNT(tid) AS threads", "fid = '$fid' $visibleonly $uid_only", array('limit' => 1));
 169          $threadcount = $db->fetch_field($query, "threads");
 170      }
 171  
 172      $stickybit = " OR sticky=1";
 173      if($thread['sticky'] == 1)
 174      {
 175          $stickybit = " AND sticky=1";
 176      }
 177  
 178      // Figure out what page the thread is actually on
 179      switch($db->type)
 180      {
 181          case "pgsql":
 182              $query = $db->query("
 183                  SELECT COUNT(tid) as threads
 184                  FROM ".TABLE_PREFIX."threads
 185                  WHERE fid = '$fid' AND (lastpost >= '".intval($thread['lastpost'])."'{$stickybit}) {$visibleonly} {$uid_only}
 186                  GROUP BY lastpost
 187                  ORDER BY lastpost DESC
 188              ");
 189              break;
 190          default:
 191              $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'));
 192      }
 193  
 194      $thread_position = $db->fetch_field($query, "threads");
 195      $thread_page = ceil(($thread_position/$mybb->settings['threadsperpage']));
 196  
 197      $breadcrumb_multipage = array(
 198          "num_threads" => $threadcount,
 199          "current_page" => $thread_page
 200      );
 201  }
 202  
 203  // Build the navigation.
 204  build_forum_breadcrumb($fid, $breadcrumb_multipage);
 205  add_breadcrumb($thread['displayprefix'].$thread['subject'], get_thread_link($thread['tid']));
 206  
 207  // Check if this forum is password protected and we have a valid password
 208  check_forum_password($forum['fid']);
 209  
 210  // If there is no specific action, we must be looking at the thread.
 211  if(!$mybb->input['action'])
 212  {
 213      $mybb->input['action'] = "thread";
 214  }
 215  
 216  // Jump to the unread posts.
 217  if($mybb->input['action'] == "newpost")
 218  {
 219      // First, figure out what time the thread or forum were last read
 220      $query = $db->simple_select("threadsread", "dateline", "uid='{$mybb->user['uid']}' AND tid='{$thread['tid']}'");
 221      $thread_read = $db->fetch_field($query, "dateline");
 222  
 223      if($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid'])
 224      {
 225          $query = $db->simple_select("forumsread", "dateline", "fid='{$fid}' AND uid='{$mybb->user['uid']}'");
 226          $forum_read = $db->fetch_field($query, "dateline");
 227      
 228          $read_cutoff = TIME_NOW-$mybb->settings['threadreadcut']*60*60*24;
 229          if($forum_read == 0 || $forum_read < $read_cutoff)
 230          {
 231              $forum_read = $read_cutoff;
 232          }
 233      }
 234      else
 235      {
 236          $forum_read = intval(my_get_array_cookie("forumread", $fid));
 237      }
 238      
 239      if($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid'] && $thread['lastpost'] > $forum_read)
 240      {
 241          $cutoff = TIME_NOW-$mybb->settings['threadreadcut']*60*60*24;
 242          if($thread['lastpost'] > $cutoff)
 243          {
 244              if($thread_read)
 245              {
 246                  $lastread = $thread_read;
 247              }
 248              else
 249              {
 250                  // Set $lastread to zero to make sure 'lastpost' is invoked in the last IF
 251                  $lastread = 0;
 252              }
 253          }
 254      }
 255      
 256      if(!$lastread)
 257      {
 258          $readcookie = $threadread = intval(my_get_array_cookie("threadread", $thread['tid']));
 259          if($readcookie > $forum_read)
 260          {
 261              $lastread = $readcookie;
 262          }
 263          else
 264          {
 265              $lastread = $forum_read;
 266          }
 267      }
 268      
 269     if($cutoff && $lastread < $cutoff)
 270     {
 271            $lastread = $cutoff;
 272     }
 273      
 274      // Next, find the proper pid to link to.
 275      $options = array(
 276          "limit_start" => 0,
 277          "limit" => 1,
 278          "order_by" => "dateline",
 279          "order_dir" => "asc"
 280      );
 281  
 282      $lastread = intval($lastread);
 283      $query = $db->simple_select("posts", "pid", "tid='{$tid}' AND dateline > '{$lastread}'", $options);
 284      $newpost = $db->fetch_array($query);
 285      
 286      if($newpost['pid'] && $lastread)
 287      {
 288          $highlight = '';
 289          if($mybb->input['highlight'])
 290          {
 291              $string = "&";
 292              if($mybb->settings['seourls'] == "yes" || ($mybb->settings['seourls'] == "auto" && $_SERVER['SEO_SUPPORT'] == 1))
 293              {
 294                  $string = "?";
 295              }
 296  
 297              $highlight = $string."highlight=".$mybb->input['highlight'];
 298          }
 299  
 300          header("Location: ".htmlspecialchars_decode(get_post_link($newpost['pid'], $tid)).$highlight."#pid{$newpost['pid']}");
 301      }
 302      else
 303      {
 304          // show them to the last post
 305          $mybb->input['action'] = "lastpost";
 306      }
 307  }
 308  
 309  // Jump to the last post.
 310  if($mybb->input['action'] == "lastpost")
 311  {
 312      if(my_strpos($thread['closed'], "moved|"))
 313      {
 314          $query = $db->query("
 315              SELECT p.pid
 316              FROM ".TABLE_PREFIX."posts p
 317              LEFT JOIN ".TABLE_PREFIX."threads t ON(p.tid=t.tid)
 318              WHERE t.fid='".$thread['fid']."' AND t.closed NOT LIKE 'moved|%'
 319              ORDER BY p.dateline DESC
 320              LIMIT 1
 321          ");
 322          $pid = $db->fetch_field($query, "pid");
 323      }
 324      else
 325      {
 326          $options = array(
 327              'order_by' => 'dateline',
 328              'order_dir' => 'desc',
 329              'limit_start' => 0,
 330              'limit' => 1
 331          );
 332          $query = $db->simple_select('posts', 'pid', "tid={$tid}", $options);
 333          $pid = $db->fetch_field($query, "pid");
 334      }
 335      header("Location: ".htmlspecialchars_decode(get_post_link($pid, $tid))."#pid{$pid}");
 336      exit;
 337  }
 338  
 339  // Jump to the next newest posts.
 340  if($mybb->input['action'] == "nextnewest")
 341  {
 342      $options = array(
 343          "limit_start" => 0,
 344          "limit" => 1,
 345          "order_by" => "lastpost"
 346      );
 347      $query = $db->simple_select('threads', '*', "fid={$thread['fid']} AND lastpost > {$thread['lastpost']} AND visible=1 AND closed NOT LIKE 'moved|%'", $options);
 348      $nextthread = $db->fetch_array($query);
 349  
 350      // Are there actually next newest posts?
 351      if(!$nextthread['tid'])
 352      {
 353          error($lang->error_nonextnewest);
 354      }
 355      $options = array(
 356          "limit_start" => 0,
 357          "limit" => 1,
 358          "order_by" => "dateline",
 359          "order_dir" => "desc"
 360      );
 361      $query = $db->simple_select('posts', 'pid', "tid='{$nextthread['tid']}'", $options);
 362  
 363      // Redirect to the proper page.
 364      $pid = $db->fetch_field($query, "pid");
 365      header("Location: ".htmlspecialchars_decode(get_post_link($pid, $nextthread['tid']))."#pid{$pid}");
 366      exit;
 367  }
 368  
 369  // Jump to the next oldest posts.
 370  if($mybb->input['action'] == "nextoldest")
 371  {
 372      $options = array(
 373          "limit" => 1,
 374          "limit_start" => 0,
 375          "order_by" => "lastpost",
 376          "order_dir" => "desc"
 377      );
 378      $query = $db->simple_select("threads", "*", "fid=".$thread['fid']." AND lastpost < ".$thread['lastpost']." AND visible=1 AND closed NOT LIKE 'moved|%'", $options);
 379      $nextthread = $db->fetch_array($query);
 380  
 381      // Are there actually next oldest posts?
 382      if(!$nextthread['tid'])
 383      {
 384          error($lang->error_nonextoldest);
 385      }
 386      $options = array(
 387          "limit_start" => 0,
 388          "limit" => 1,
 389          "order_by" => "dateline",
 390          "order_dir" => "desc"
 391      );
 392      $query = $db->simple_select("posts", "pid", "tid='".$nextthread['tid']."'", $options);
 393  
 394      // Redirect to the proper page.
 395      $pid = $db->fetch_field($query, "pid");
 396      header("Location: ".htmlspecialchars_decode(get_post_link($pid, $nextthread['tid']))."#pid{$pid}");
 397      exit;
 398  }
 399  
 400  if($mybb->input['pid'])
 401  {
 402      $pid = $mybb->input['pid'];
 403  }
 404  
 405  $plugins->run_hooks("showthread_start");
 406  
 407  // Show the entire thread (taking into account pagination).
 408  if($mybb->input['action'] == "thread")
 409  {
 410      if($thread['firstpost'] == 0)
 411      {
 412          update_first_post($tid);
 413      }
 414      
 415      // Does this thread have a poll?
 416      if($thread['poll'])
 417      {
 418          $options = array(
 419              "limit" => 1
 420          );
 421          $query = $db->simple_select("polls", "*", "pid='".$thread['poll']."'", $options);
 422          $poll = $db->fetch_array($query);
 423          $poll['timeout'] = $poll['timeout']*60*60*24;
 424          $expiretime = $poll['dateline'] + $poll['timeout'];
 425          $now = TIME_NOW;
 426  
 427          // If the poll or the thread is closed or if the poll is expired, show the results.
 428          if($poll['closed'] == 1 || $thread['closed'] == 1 || ($expiretime < $now && $poll['timeout'] > 0))
 429          {
 430              $showresults = 1;
 431          }
 432  
 433          // If the user is not a guest, check if he already voted.
 434          if($mybb->user['uid'] != 0)
 435          {
 436              $query = $db->simple_select("pollvotes", "*", "uid='".$mybb->user['uid']."' AND pid='".$poll['pid']."'");
 437              while($votecheck = $db->fetch_array($query))
 438              {    
 439                  $alreadyvoted = 1;
 440                  $votedfor[$votecheck['voteoption']] = 1;
 441              }
 442          }
 443          else
 444          {
 445              if(isset($mybb->cookies['pollvotes'][$poll['pid']]) && $mybb->cookies['pollvotes'][$poll['pid']] !== "")
 446              {
 447                  $alreadyvoted = 1;
 448              }
 449          }
 450          $optionsarray = explode("||~|~||", $poll['options']);
 451          $votesarray = explode("||~|~||", $poll['votes']);
 452          $poll['question'] = htmlspecialchars_uni($poll['question']);
 453          $polloptions = '';
 454          $totalvotes = 0;
 455  
 456          for($i = 1; $i <= $poll['numoptions']; ++$i)
 457          {
 458              $poll['totvotes'] = $poll['totvotes'] + $votesarray[$i-1];
 459          }
 460  
 461          // Loop through the poll options.
 462          for($i = 1; $i <= $poll['numoptions']; ++$i)
 463          {
 464              // Set up the parser options.
 465              $parser_options = array(
 466                  "allow_html" => $forum['allowhtml'],
 467                  "allow_mycode" => $forum['allowmycode'],
 468                  "allow_smilies" => $forum['allowsmilies'],
 469                  "allow_imgcode" => $forum['allowimgcode'],
 470                  "allow_videocode" => $forum['allowvideocode'],
 471                  "filter_badwords" => 1
 472              );
 473  
 474              $option = $parser->parse_message($optionsarray[$i-1], $parser_options);
 475              $votes = $votesarray[$i-1];
 476              $totalvotes += $votes;
 477              $number = $i;
 478  
 479              // Mark the option the user voted for.
 480              if($votedfor[$number])
 481              {
 482                  $optionbg = "trow2";
 483                  $votestar = "*";
 484              }
 485              else
 486              {
 487                  $optionbg = "trow1";
 488                  $votestar = "";
 489              }
 490  
 491              // If the user already voted or if the results need to be shown, do so; else show voting screen.
 492              if($alreadyvoted || $showresults)
 493              {
 494                  if(intval($votes) == "0")
 495                  {
 496                      $percent = "0";
 497                  }
 498                  else
 499                  {
 500                      $percent = number_format($votes / $poll['totvotes'] * 100, 2);
 501                  }
 502                  $imagewidth = round(($percent/3) * 5);
 503                  $imagerowwidth = $imagewidth + 10;
 504                  eval("\$polloptions .= \"".$templates->get("showthread_poll_resultbit")."\";");
 505              }
 506              else
 507              {
 508                  if($poll['multiple'] == 1)
 509                  {
 510                      eval("\$polloptions .= \"".$templates->get("showthread_poll_option_multiple")."\";");
 511                  }
 512                  else
 513                  {
 514                      eval("\$polloptions .= \"".$templates->get("showthread_poll_option")."\";");
 515                  }
 516              }
 517          }
 518  
 519          // If there are any votes at all, all votes together will be 100%; if there are no votes, all votes together will be 0%.
 520          if($poll['totvotes'])
 521          {
 522              $totpercent = "100%";
 523          }
 524          else
 525          {
 526              $totpercent = "0%";
 527          }
 528  
 529          // Check if user is allowed to edit posts; if so, show "edit poll" link.
 530          if(!is_moderator($fid, 'caneditposts'))
 531          {
 532              $edit_poll = '';
 533          }
 534          else
 535          {
 536              $edit_poll = " | <a href=\"polls.php?action=editpoll&amp;pid={$poll['pid']}\">{$lang->edit_poll}</a>";
 537          }
 538  
 539          // Decide what poll status to show depending on the status of the poll and whether or not the user voted already.
 540          if($alreadyvoted || $showresults)
 541          {
 542              if($alreadyvoted)
 543              {
 544                  $pollstatus = $lang->already_voted;
 545                  
 546                  if($mybb->usergroup['canundovotes'] == 1)
 547                  {
 548                      $pollstatus .= " [<a href=\"polls.php?action=do_undovote&amp;pid={$poll['pid']}&amp;my_post_key={$mybb->post_code}\">{$lang->undo_vote}</a>]";
 549                  }
 550              }
 551              else
 552              {
 553                  $pollstatus = $lang->poll_closed;
 554              }
 555              $lang->total_votes = $lang->sprintf($lang->total_votes, $totalvotes);
 556              eval("\$pollbox = \"".$templates->get("showthread_poll_results")."\";");
 557              $plugins->run_hooks("showthread_poll_results");
 558          }
 559          else
 560          {
 561              $publicnote = '&nbsp;';
 562              if($poll['public'] == 1)
 563              {
 564                  $publicnote = $lang->public_note;
 565              }
 566              eval("\$pollbox = \"".$templates->get("showthread_poll")."\";");
 567              $plugins->run_hooks("showthread_poll");
 568          }
 569  
 570      }
 571      else
 572      {
 573          $pollbox = "";
 574      }
 575  
 576      // Create the forum jump dropdown box.
 577      if($mybb->settings['enableforumjump'] != 0)
 578      {
 579          $forumjump = build_forum_jump("", $fid, 1);
 580      }
 581      
 582      // Fetch some links
 583      $next_oldest_link = get_thread_link($tid, 0, "nextoldest");
 584      $next_newest_link = get_thread_link($tid, 0, "nextnewest");
 585  
 586      // Mark this thread as read
 587      mark_thread_read($tid, $fid);
 588  
 589      // If the forum is not open, show closed newreply button unless the user is a moderator of this forum.
 590      if($forum['open'] != 0)
 591      {
 592          eval("\$newthread = \"".$templates->get("showthread_newthread")."\";");
 593  
 594          // Show the appropriate reply button if this thread is open or closed
 595          if($thread['closed'] == 1)
 596          {
 597              eval("\$newreply = \"".$templates->get("showthread_newreply_closed")."\";");
 598          }
 599          else
 600          {
 601              eval("\$newreply = \"".$templates->get("showthread_newreply")."\";");
 602          }
 603      }
 604  
 605      // Create the admin tools dropdown box.
 606      if($ismod == true)
 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($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)
 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          if(!$mybb->settings['postsperpage'])
 811          {
 812              $mybb->settings['postperpage'] = 20;
 813          }
 814          
 815          // Figure out if we need to display multiple pages.
 816          $perpage = $mybb->settings['postsperpage'];
 817          if($mybb->input['page'] != "last")
 818          {
 819              $page = intval($mybb->input['page']);
 820          }
 821          if($mybb->input['pid'])
 822          {
 823              $post = get_post($mybb->input['pid']);
 824              $query = $db->query("
 825                  SELECT COUNT(p.dateline) AS count FROM ".TABLE_PREFIX."posts p
 826                  WHERE p.tid='$tid'
 827                  AND p.dateline <= '".$post['dateline']."'
 828                  $visible
 829              ");
 830              $result = $db->fetch_field($query, "count");
 831              if(($result % $perpage) == 0)
 832              {
 833                  $page = $result / $perpage;
 834              }
 835              else
 836              {
 837                  $page = intval($result / $perpage) + 1;
 838              }
 839          }
 840          // Recount replies if user is a moderator to take into account unapproved posts.
 841          if($ismod)
 842          {
 843              $query = $db->simple_select("posts p", "COUNT(*) AS replies", "p.tid='$tid' $visible");
 844              $thread['replies'] = $db->fetch_field($query, 'replies')-1;
 845          }
 846          $postcount = intval($thread['replies'])+1;
 847          $pages = $postcount / $perpage;
 848          $pages = ceil($pages);
 849  
 850          if($mybb->input['page'] == "last")
 851          {
 852              $page = $pages;
 853          }
 854  
 855          if($page > $pages || $page <= 0)
 856          {
 857              $page = 1;
 858          }
 859  
 860          if($page)
 861          {
 862              $start = ($page-1) * $perpage;
 863          }
 864          else
 865          {
 866              $start = 0;
 867              $page = 1;
 868          }
 869          $upper = $start+$perpage;
 870          
 871          // Work out if we have terms to highlight
 872          $highlight = "";
 873          $threadmode = "";
 874          if($mybb->settings['seourls'] == "yes" || ($mybb->settings['seourls'] == "auto" && $_SERVER['SEO_SUPPORT'] == 1))
 875          {
 876              if($mybb->input['highlight'])
 877              {
 878                  $highlight = "?highlight=".urlencode($mybb->input['highlight']);
 879              }
 880              
 881              if($defaultmode != "linear")
 882              {
 883                  if($mybb->input['highlight'])
 884                  {
 885                      $threadmode = "&amp;mode=linear";
 886                  }
 887                  else 
 888                  {
 889                      $threadmode = "?mode=linear";
 890                  }
 891              }
 892          }
 893          else
 894          {
 895              if($mybb->input['highlight'])
 896              {
 897                  if(is_array($mybb->input['highlight']))
 898                  {
 899                      foreach($mybb->input['highlight'] as $highlight_word)
 900                      {
 901                          $highlight .= "&amp;highlight[]=".urlencode($highlight_word);
 902                      }
 903                  }
 904                  else
 905                  {
 906                      $highlight = "&amp;highlight=".urlencode($mybb->input['highlight']);
 907                  }
 908              }
 909              
 910              if($defaultmode != "linear")
 911              {
 912                  $threadmode = "&amp;mode=linear";
 913              }
 914          }
 915  
 916          $multipage = multipage($postcount, $perpage, $page, str_replace("{tid}", $tid, THREAD_URL_PAGED.$highlight.$threadmode));
 917          if($postcount > $perpage)
 918          {
 919              eval("\$threadpages = \"".$templates->get("showthread_multipage")."\";");
 920          }
 921  
 922          // Lets get the pids of the posts on this page.
 923          $pids = "";
 924          $comma = '';
 925          $query = $db->simple_select("posts p", "p.pid", "p.tid='$tid' $visible", array('order_by' => 'p.dateline', 'limit_start' => $start, 'limit' => $perpage));
 926          while($getid = $db->fetch_array($query))
 927          {
 928              // Set the ID of the first post on page to $pid if it doesn't hold any value
 929              // to allow this value to be used for Thread Mode/Linear Mode links
 930              // and ensure the user lands on the correct page after changing view mode
 931              if(!$pid)
 932              {
 933                  $pid = $getid['pid'];
 934              }
 935              // Gather a comma separated list of post IDs
 936              $pids .= "$comma'{$getid['pid']}'";
 937              $comma = ",";
 938          }
 939          if($pids)
 940          {
 941              $pids = "pid IN($pids)";
 942              
 943              $attachcache = array();
 944              if($thread['attachmentcount'] > 0)
 945              {
 946                  // Now lets fetch all of the attachments for these posts.
 947                  $query = $db->simple_select("attachments", "*", $pids);
 948                  while($attachment = $db->fetch_array($query))
 949                  {
 950                      $attachcache[$attachment['pid']][$attachment['aid']] = $attachment;
 951                  }
 952              }
 953          }
 954          else
 955          {
 956              // If there are no pid's the thread is probably awaiting approval.
 957              error($lang->error_invalidthread);
 958          }
 959  
 960          // Get the actual posts from the database here.
 961          $posts = '';
 962          $query = $db->query("
 963              SELECT u.*, u.username AS userusername, p.*, f.*, eu.username AS editusername
 964              FROM ".TABLE_PREFIX."posts p
 965              LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
 966              LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid)
 967              LEFT JOIN ".TABLE_PREFIX."users eu ON (eu.uid=p.edituid)
 968              WHERE $pids
 969              ORDER BY p.dateline
 970          ");
 971          while($post = $db->fetch_array($query))
 972          {
 973              if($thread['firstpost'] == $post['pid'] && $thread['visible'] == 0)
 974              {
 975                  $post['visible'] = 0;
 976              }
 977              $posts .= build_postbit($post);
 978              $post = '';
 979          }
 980          $plugins->run_hooks("showthread_linear");
 981      }
 982  
 983      // Show the similar threads table if wanted.
 984      if($mybb->settings['showsimilarthreads'] != 0)
 985      {
 986          switch($db->type)
 987          {
 988              case "pgsql":
 989                  $query = $db->query("
 990                      SELECT t.*, t.username AS threadusername, u.username
 991                      FROM ".TABLE_PREFIX."threads t
 992                      LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid), plainto_tsquery ('".$db->escape_string($thread['subject'])."') AS query
 993                      WHERE t.fid='{$thread['fid']}' AND t.tid!='{$thread['tid']}' AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND t.subject @@ query AND ts_rank_cd(to_tsvector('english',t.subject), query ) >= '{$mybb->settings['similarityrating']}'
 994                      ORDER BY t.lastpost DESC
 995                      OFFSET 0 LIMIT {$mybb->settings['similarlimit']}
 996                  ");
 997                  break;
 998              default:
 999                  $query = $db->query("
1000                      SELECT t.*, t.username AS threadusername, u.username, MATCH (t.subject) AGAINST ('".$db->escape_string($thread['subject'])."') AS relevance
1001                      FROM ".TABLE_PREFIX."threads t
1002                      LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid)
1003                      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']}'
1004                      ORDER BY t.lastpost DESC
1005                      LIMIT 0, {$mybb->settings['similarlimit']}
1006                  ");
1007          }
1008  
1009          $count = 0;
1010          $similarthreadbits = '';
1011          $icon_cache = $cache->read("posticons");
1012          while($similar_thread = $db->fetch_array($query))
1013          {
1014              ++$count;
1015              $trow = alt_trow();
1016              if($similar_thread['icon'] > 0 && $icon_cache[$similar_thread['icon']])
1017              {
1018                  $icon = $icon_cache[$similar_thread['icon']];
1019                  $icon = "<img src=\"{$icon['path']}\" alt=\"{$icon['name']}\" />";
1020              }
1021              else
1022              {
1023                  $icon = "&nbsp;";
1024              }                
1025              if(!$similar_thread['username'])
1026              {
1027                  $similar_thread['username'] = $similar_thread['threadusername'];
1028                  $similar_thread['profilelink'] = $similar_thread['threadusername'];
1029              }
1030              else
1031              {
1032                  $similar_thread['profilelink'] = build_profile_link($similar_thread['username'], $similar_thread['uid']);
1033              }
1034              
1035              // If this thread has a prefix, insert a space between prefix and subject
1036              if($similar_thread['prefix'] != 0)
1037              {
1038                  $prefix = build_prefixes($similar_thread['prefix']);
1039                  $similar_thread['threadprefix'] = $prefix['displaystyle'].'&nbsp;';
1040              }
1041              
1042              $similar_thread['subject'] = $parser->parse_badwords($similar_thread['subject']);
1043              $similar_thread['subject'] = htmlspecialchars_uni($similar_thread['subject']);
1044              $similar_thread['threadlink'] = get_thread_link($similar_thread['tid']);
1045              $similar_thread['lastpostlink'] = get_thread_link($similar_thread['tid'], 0, "lastpost");
1046  
1047              $lastpostdate = my_date($mybb->settings['dateformat'], $similar_thread['lastpost']);
1048              $lastposttime = my_date($mybb->settings['timeformat'], $similar_thread['lastpost']);
1049              $lastposter = $similar_thread['lastposter'];
1050              $lastposteruid = $similar_thread['lastposteruid'];
1051  
1052              // Don't link to guest's profiles (they have no profile).
1053              if($lastposteruid == 0)
1054              {
1055                  $lastposterlink = $lastposter;
1056              }
1057              else
1058              {
1059                  $lastposterlink = build_profile_link($lastposter, $lastposteruid);
1060              }
1061              $similar_thread['replies'] = my_number_format($similar_thread['replies']);
1062              $similar_thread['views'] = my_number_format($similar_thread['views']);
1063              eval("\$similarthreadbits .= \"".$templates->get("showthread_similarthreads_bit")."\";");
1064          }
1065          if($count)
1066          {
1067              eval("\$similarthreads = \"".$templates->get("showthread_similarthreads")."\";");
1068          }
1069      }
1070  
1071      // Decide whether or not to show quick reply.
1072      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)
1073      {
1074          $query = $db->simple_select("posts", "pid", "tid='{$tid}'", array("order_by" => "pid", "order_dir" => "desc", "limit" => 1));
1075          $last_pid = $db->fetch_field($query, "pid");
1076          
1077          // Show captcha image for guests if enabled
1078          if($mybb->settings['captchaimage'] && !$mybb->user['uid'])
1079          {
1080              require_once  MYBB_ROOT.'inc/class_captcha.php';
1081              $post_captcha = new captcha(true, "post_captcha");
1082  
1083              if($post_captcha->html)
1084              {
1085                  $captcha = $post_captcha->html;
1086              }
1087          }
1088          if($mybb->user['signature'])
1089          {
1090              $postoptionschecked['signature'] = 'checked="checked"';
1091          }
1092          if($mybb->user['emailnotify'] == 1)
1093          {
1094              $postoptionschecked['emailnotify'] = 'checked="checked"';
1095          }
1096          $posthash = md5($mybb->user['uid'].random_str());
1097          
1098          eval("\$quickreply = \"".$templates->get("showthread_quickreply")."\";");
1099      }
1100      else
1101      {
1102          $quickreply = "";
1103      }
1104      
1105      // If the user is a moderator, show the moderation tools.
1106      if($ismod)
1107      {
1108          if($forum_stats[-1]['modtools'] || $forum_stats[$forum['fid']]['modtools'])
1109          {
1110              $customthreadtools = $customposttools = '';
1111      
1112              switch($db->type)
1113              {
1114                  case "pgsql":
1115                  case "sqlite":
1116                      $query = $db->simple_select("modtools", "tid, name, type", "','||forums||',' LIKE '%,$fid,%' OR ','||forums||',' LIKE '%,-1,%' OR forums=''");
1117                      break;
1118                  default:
1119                      $query = $db->simple_select("modtools", "tid, name, type", "CONCAT(',',forums,',') LIKE '%,$fid,%' OR CONCAT(',',forums,',') LIKE '%,-1,%' OR forums=''");
1120              }
1121          
1122              while($tool = $db->fetch_array($query))
1123              {
1124                  if($tool['type'] == 'p')
1125                  {
1126                      eval("\$customposttools .= \"".$templates->get("showthread_inlinemoderation_custom_tool")."\";");
1127                  }
1128                  else
1129                  {
1130                      eval("\$customthreadtools .= \"".$templates->get("showthread_moderationoptions_custom_tool")."\";");
1131                  }
1132              }
1133  
1134              // Build inline moderation dropdown
1135              if(!empty($customposttools))
1136              {
1137                  eval("\$customposttools = \"".$templates->get("showthread_inlinemoderation_custom")."\";");
1138              }
1139          }
1140  
1141          eval("\$inlinemod = \"".$templates->get("showthread_inlinemoderation")."\";");
1142  
1143          // Build thread moderation dropdown
1144          if(!empty($customthreadtools))
1145          {
1146              eval("\$customthreadtools = \"".$templates->get("showthread_moderationoptions_custom")."\";");
1147          }
1148          eval("\$moderationoptions = \"".$templates->get("showthread_moderationoptions")."\";");
1149      }
1150      $lang->newthread_in = $lang->sprintf($lang->newthread_in, $forum['name']);
1151      
1152      // Subscription status
1153      $add_remove_subscription = 'add';
1154      $add_remove_subscription_text = $lang->subscribe_thread;
1155  
1156      if($mybb->user['uid'])
1157      {
1158          $query = $db->simple_select("threadsubscriptions", "tid", "tid='".intval($tid)."' AND uid='".intval($mybb->user['uid'])."'", array('limit' => 1));
1159  
1160          if($db->fetch_field($query, 'tid'))
1161          {
1162              $add_remove_subscription = 'remove';
1163              $add_remove_subscription_text = $lang->unsubscribe_thread;
1164          }
1165      }
1166  
1167      if($mybb->settings['postlayout'] == "classic")
1168      {
1169          eval("\$classic_header = \"".$templates->get("showthread_classic_header")."\";");        
1170      }
1171      
1172      // Get users viewing this thread
1173      if($mybb->settings['browsingthisthread'] != 0)
1174      {
1175          $timecut = TIME_NOW - $mybb->settings['wolcutoff'];
1176  
1177          $comma = '';
1178          $guestcount = 0;
1179          $membercount = 0;
1180          $inviscount = 0;
1181          $onlinemembers = '';
1182          $doneusers = array();
1183  
1184          $query = $db->query("
1185              SELECT s.ip, s.uid, s.time, u.username, u.invisible, u.usergroup, u.displaygroup
1186              FROM ".TABLE_PREFIX."sessions s
1187              LEFT JOIN ".TABLE_PREFIX."users u ON (s.uid=u.uid)
1188              WHERE s.time > '$timecut' AND location2='$tid' AND nopermission != 1
1189              ORDER BY u.username ASC, s.time DESC
1190          ");
1191  
1192          while($user = $db->fetch_array($query))
1193          {
1194              if($user['uid'] == 0)
1195              {
1196                  ++$guestcount;
1197              }
1198              else if($doneusers[$user['uid']] < $user['time'] || !$doneusers[$user['uid']])
1199              {
1200                  ++$membercount;
1201                  $doneusers[$user['uid']] = $user['time'];
1202  
1203                  $invisiblemark = '';
1204                  if($user['invisible'] == 1)
1205                  {
1206                      $invisiblemark = "*";
1207                      ++$inviscount;
1208                  }
1209  
1210                  if($user['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1 || $user['uid'] == $mybb->user['uid'])
1211                  {
1212                      $user['profilelink'] = get_profile_link($user['uid']);
1213                      $user['username'] = format_name($user['username'], $user['usergroup'], $user['displaygroup']);
1214                      $user['reading'] = my_date($mybb->settings['timeformat'], $user['time']);
1215  
1216                      eval("\$onlinemembers .= \"".$templates->get("showthread_usersbrowsing_user", 1, 0)."\";");
1217                      $comma = $lang->comma;
1218                  }
1219              }
1220          }
1221  
1222          if($guestcount)
1223          {
1224              $guestsonline = $lang->sprintf($lang->users_browsing_thread_guests, $guestcount);
1225          }
1226  
1227          if($guestcount && $onlinemembers)
1228          {
1229              $onlinesep = $lang->comma;
1230          }
1231  
1232          $invisonline = '';
1233          if($inviscount && $mybb->usergroup['canviewwolinvis'] != 1 && ($inviscount != 1 && $mybb->user['invisible'] != 1))
1234          {
1235              $invisonline = $lang->sprintf($lang->users_browsing_thread_invis, $inviscount);
1236          }
1237  
1238          if($invisonline != '' && $guestcount)
1239          {
1240              $onlinesep2 = $lang->comma;
1241          }
1242  
1243          eval("\$usersbrowsing = \"".$templates->get("showthread_usersbrowsing")."\";");
1244      }
1245      
1246      $plugins->run_hooks("showthread_end");
1247      
1248      eval("\$showthread = \"".$templates->get("showthread")."\";");
1249      output_page($showthread);
1250  }
1251  
1252  /**
1253   * Build a navigation tree for threaded display.
1254   *
1255   * @param unknown_type $replyto
1256   * @param unknown_type $indent
1257   * @return unknown
1258   */
1259  function buildtree($replyto="0", $indent="0")
1260  {
1261      global $tree, $mybb, $theme, $mybb, $pid, $tid, $templates, $parser;
1262      
1263      if($indent)
1264      {
1265          $indentsize = 13 * $indent;
1266      }
1267      else
1268      {
1269          $indentsize = 0;
1270      }
1271      
1272      ++$indent;
1273      if(is_array($tree[$replyto]))
1274      {
1275          foreach($tree[$replyto] as $key => $post)
1276          {
1277              $postdate = my_date($mybb->settings['dateformat'], $post['dateline']);
1278              $posttime = my_date($mybb->settings['timeformat'], $post['dateline']);
1279              $post['subject'] = htmlspecialchars_uni($parser->parse_badwords($post['subject']));
1280              
1281              if(!$post['subject'])
1282              {
1283                  $post['subject'] = "[".$lang->no_subject."]";
1284              }
1285              
1286              $post['profilelink'] = build_profile_link($post['username'], $post['uid']);
1287          
1288              if($mybb->input['pid'] == $post['pid'])
1289              {
1290                  eval("\$posts .= \"".$templates->get("showthread_threaded_bitactive")."\";");
1291              }
1292              else
1293              {
1294                  eval("\$posts .= \"".$templates->get("showthread_threaded_bit")."\";");
1295              }
1296              
1297              if($tree[$post['pid']])
1298              {
1299                  $posts .= buildtree($post['pid'], $indent);
1300              }
1301          }
1302          --$indent;
1303      }
1304      return $posts;
1305  }
1306  ?>


Generated: Sun Jan 1 10:49:49 2012 Cross-referenced by PHPXref 0.7.1