[ Index ]

PHP Cross Reference of MyBB 1.8.26

title

Body

[close]

/ -> showthread.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.8
   4   * Copyright 2014 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://www.mybb.com
   7   * License: http://www.mybb.com/about/license
   8   *
   9   */
  10  
  11  define("IN_MYBB", 1);
  12  define('THIS_SCRIPT', 'showthread.php');
  13  
  14  $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";
  15  $templatelist .= ",multipage,multipage_breadcrumb,multipage_end,multipage_jump_page,multipage_nextpage,multipage_page,multipage_page_current,multipage_page_link_current,multipage_prevpage,multipage_start,showthread_inlinemoderation_softdelete,showthread_poll_editpoll";
  16  $templatelist .= ",postbit_editedby,showthread_similarthreads,showthread_similarthreads_bit,postbit_iplogged_show,postbit_iplogged_hiden,postbit_profilefield,showthread_quickreply,showthread_printthread,showthread_add_poll,showthread_send_thread,showthread_inlinemoderation_restore";
  17  $templatelist .= ",forumjump_advanced,forumjump_special,forumjump_bit,postbit_attachments,postbit_attachments_attachment,postbit_attachments_thumbnails,postbit_attachments_images_image,postbit_attachments_images,showthread_quickreply_options_stick,postbit_status";
  18  $templatelist .= ",postbit_inlinecheck,showthread_inlinemoderation,postbit_attachments_thumbnails_thumbnail,postbit_ignored,postbit_multiquote,showthread_moderationoptions_custom_tool,showthread_moderationoptions_custom,showthread_inlinemoderation_custom_tool";
  19  $templatelist .= ",showthread_usersbrowsing,showthread_usersbrowsing_user,showthread_poll_option,showthread_poll,showthread_quickreply_options_signature,showthread_threaded_bitactive,showthread_threaded_bit,postbit_attachments_attachment_unapproved";
  20  $templatelist .= ",showthread_moderationoptions_openclose,showthread_moderationoptions_stickunstick,showthread_moderationoptions_delete,showthread_moderationoptions_threadnotes,showthread_moderationoptions_manage,showthread_moderationoptions_deletepoll";
  21  $templatelist .= ",postbit_userstar,postbit_reputation_formatted_link,postbit_warninglevel_formatted,postbit_quickrestore,forumdisplay_password,forumdisplay_password_wrongpass,postbit_purgespammer,showthread_inlinemoderation_approve,forumdisplay_thread_icon";
  22  $templatelist .= ",showthread_moderationoptions_softdelete,showthread_moderationoptions_restore,post_captcha,post_captcha_recaptcha_invisible,post_captcha_nocaptcha,post_captcha_hcaptcha_invisible,post_captcha_hcaptcha,showthread_moderationoptions,showthread_inlinemoderation_standard,showthread_inlinemoderation_manage";
  23  $templatelist .= ",showthread_ratethread,postbit_posturl,postbit_icon,postbit_editedby_editreason,attachment_icon,global_moderation_notice,showthread_poll_option_multiple,postbit_gotopost,postbit_rep_button,postbit_warninglevel,showthread_threadnoteslink";
  24  $templatelist .= ",showthread_moderationoptions_approve,showthread_moderationoptions_unapprove,showthread_inlinemoderation_delete,showthread_moderationoptions_standard,showthread_quickreply_options_close,showthread_inlinemoderation_custom,showthread_search";
  25  $templatelist .= ",postbit_profilefield_multiselect_value,postbit_profilefield_multiselect,showthread_subscription,postbit_deleted_member,postbit_away,postbit_warn,postbit_classic,postbit_reputation,postbit_deleted,postbit_offline,postbit_online,postbit_signature";
  26  $templatelist .= ",postbit_editreason,postbit_quickdelete,showthread_threadnotes_viewnotes,showthread_threadedbox,showthread_poll_resultbit,showthread_poll_results,showthread_threadnotes,showthread_classic_header,showthread_poll_undovote,postbit_groupimage";
  27  
  28  require_once  "./global.php";
  29  require_once  MYBB_ROOT."inc/functions_post.php";
  30  require_once  MYBB_ROOT."inc/functions_indicators.php";
  31  require_once  MYBB_ROOT."inc/class_parser.php";
  32  $parser = new postParser;
  33  
  34  // Load global language phrases
  35  $lang->load("showthread");
  36  
  37  // If there is no tid but a pid, trick the system into thinking there was a tid anyway.
  38  if(!empty($mybb->input['pid']) && !isset($mybb->input['tid']))
  39  {
  40      // see if we already have the post information
  41      if(isset($style) && $style['pid'] == $mybb->get_input('pid', MyBB::INPUT_INT) && $style['tid'])
  42      {
  43          $mybb->input['tid'] = $style['tid'];
  44          unset($style['tid']); // stop the thread caching code from being tricked
  45      }
  46      else
  47      {
  48          $options = array(
  49              "limit" => 1
  50          );
  51          $query = $db->simple_select("posts", "fid,tid,visible", "pid=".$mybb->get_input('pid', MyBB::INPUT_INT), $options);
  52          $post = $db->fetch_array($query);
  53  
  54          if(empty($post) || ($post['visible'] == 0 && !is_moderator($post['fid'], 'canviewunapprove')) || ($post['visible'] == -1 && !is_moderator($post['fid'], 'canviewdeleted')))
  55          {
  56              // post does not exist --> show corresponding error
  57              error($lang->error_invalidpost);
  58          }
  59  
  60          $mybb->input['tid'] = $post['tid'];
  61      }
  62  }
  63  
  64  // Get the thread details from the database.
  65  $thread = get_thread($mybb->get_input('tid', MyBB::INPUT_INT));
  66  
  67  if(!$thread || substr($thread['closed'], 0, 6) == "moved|")
  68  {
  69      error($lang->error_invalidthread);
  70  }
  71  
  72  // Get thread prefix if there is one.
  73  $thread['threadprefix'] = '';
  74  $thread['displayprefix'] = '';
  75  if($thread['prefix'] != 0)
  76  {
  77      $threadprefix = build_prefixes($thread['prefix']);
  78  
  79      if(!empty($threadprefix['prefix']))
  80      {
  81          $thread['threadprefix'] = htmlspecialchars_uni($threadprefix['prefix']).'&nbsp;';
  82          $thread['displayprefix'] = $threadprefix['displaystyle'].'&nbsp;';
  83      }
  84  }
  85  
  86  $reply_subject = $parser->parse_badwords($thread['subject']);
  87  $thread['subject'] = htmlspecialchars_uni($reply_subject);
  88  // Subject too long? Shorten it to avoid error message
  89  if(my_strlen($reply_subject) > 85)
  90  {
  91      $reply_subject = my_substr($reply_subject, 0, 82).'...';
  92  }
  93  $reply_subject = htmlspecialchars_uni($reply_subject);
  94  $tid = $thread['tid'];
  95  $fid = $thread['fid'];
  96  
  97  if(!$thread['username'])
  98  {
  99      $thread['username'] = $lang->guest;
 100  }
 101  $thread['username'] = htmlspecialchars_uni($thread['username']);
 102  
 103  $forumpermissions = forum_permissions($thread['fid']);
 104  
 105  // Set here to fetch only approved/deleted posts (and then below for a moderator we change this).
 106  if($forumpermissions['canviewdeletionnotice'] != 0)
 107  {
 108      $visibleonly = " AND visible IN (-1,1)";
 109      $visibleonly2 = "AND p.visible IN (-1,1) AND t.visible IN (-1,1)";
 110  }
 111  else
 112  {
 113      $visibleonly = " AND visible=1";
 114      $visibleonly2 = "AND p.visible=1 AND t.visible=1";
 115  }
 116  
 117  // Is the currently logged in user a moderator of this forum?
 118  if(is_moderator($fid))
 119  {
 120      $ismod = true;
 121      if(is_moderator($fid, "canviewdeleted") == true || is_moderator($fid, "canviewunapprove") == true)
 122      {
 123          if(is_moderator($fid, "canviewunapprove") == true && is_moderator($fid, "canviewdeleted") == false)
 124          {
 125              $visibleonly = " AND visible IN (0,1)";
 126              $visibleonly2 = "AND p.visible IN (0,1) AND t.visible IN (0,1)";
 127          }
 128          elseif(is_moderator($fid, "canviewdeleted") == true && is_moderator($fid, "canviewunapprove") == false)
 129          {
 130              $visibleonly = " AND visible IN (-1,1)";
 131              $visibleonly2 = "AND p.visible IN (-1,1) AND t.visible IN (-1,1)";
 132          }
 133          else
 134          {
 135              $visibleonly = " AND visible IN (-1,0,1)";
 136              $visibleonly2 = "AND p.visible IN (-1,0,1) AND t.visible IN (-1,0,1)";
 137          }
 138      }
 139  }
 140  else
 141  {
 142      $ismod = false;
 143  }
 144  
 145  // Make sure we are looking at a real thread here.
 146  if(($thread['visible'] != 1 && $ismod == false) || ($thread['visible'] == 0 && !is_moderator($fid, "canviewunapprove")) || ($thread['visible'] == -1 && !is_moderator($fid, "canviewdeleted")))
 147  {
 148      // Allow viewing own unapproved thread
 149      if (!($mybb->user['uid'] && $mybb->settings['showownunapproved'] && $thread['visible'] == 0 && ($thread['uid'] == $mybb->user['uid'])))
 150      {
 151          error($lang->error_invalidthread);
 152      }
 153  }
 154  
 155  // Does the user have permission to view this thread?
 156  if($forumpermissions['canview'] != 1 || $forumpermissions['canviewthreads'] != 1)
 157  {
 158      error_no_permission();
 159  }
 160  
 161  if(isset($forumpermissions['canonlyviewownthreads']) && $forumpermissions['canonlyviewownthreads'] == 1 && $thread['uid'] != $mybb->user['uid'])
 162  {
 163      error_no_permission();
 164  }
 165  
 166  $archive_url = build_archive_link("thread", $tid);
 167  
 168  // Does the thread belong to a valid forum?
 169  $forum = get_forum($fid);
 170  if(!$forum || $forum['type'] != "f")
 171  {
 172      error($lang->error_invalidforum);
 173  }
 174  
 175  $threadnoteslink = '';
 176  if(is_moderator($fid, "canmanagethreads") && !empty($thread['notes']))
 177  {
 178      eval('$threadnoteslink = "'.$templates->get('showthread_threadnoteslink').'";');
 179  }
 180  
 181  // Check if this forum is password protected and we have a valid password
 182  check_forum_password($forum['fid']);
 183  
 184  // If there is no specific action, we must be looking at the thread.
 185  if(!$mybb->get_input('action'))
 186  {
 187      $mybb->input['action'] = "thread";
 188  }
 189  
 190  // Jump to the unread posts.
 191  if($mybb->input['action'] == "newpost")
 192  {
 193      // First, figure out what time the thread or forum were last read
 194      $query = $db->simple_select("threadsread", "dateline", "uid='{$mybb->user['uid']}' AND tid='{$thread['tid']}'");
 195      $thread_read = $db->fetch_field($query, "dateline");
 196  
 197      if($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid'])
 198      {
 199          $query = $db->simple_select("forumsread", "dateline", "fid='{$fid}' AND uid='{$mybb->user['uid']}'");
 200          $forum_read = $db->fetch_field($query, "dateline");
 201  
 202          $read_cutoff = TIME_NOW-$mybb->settings['threadreadcut']*60*60*24;
 203          if($forum_read == 0 || $forum_read < $read_cutoff)
 204          {
 205              $forum_read = $read_cutoff;
 206          }
 207      }
 208      else
 209      {
 210          $forum_read = (int)my_get_array_cookie("forumread", $fid);
 211      }
 212  
 213      if($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid'] && $thread['lastpost'] > $forum_read)
 214      {
 215          $cutoff = TIME_NOW-$mybb->settings['threadreadcut']*60*60*24;
 216          if($thread['lastpost'] > $cutoff)
 217          {
 218              if($thread_read)
 219              {
 220                  $lastread = $thread_read;
 221              }
 222              else
 223              {
 224                  // Set $lastread to zero to make sure 'lastpost' is invoked in the last IF
 225                  $lastread = 0;
 226              }
 227          }
 228      }
 229  
 230      if(!$lastread)
 231      {
 232          $readcookie = $threadread = (int)my_get_array_cookie("threadread", $thread['tid']);
 233          if($readcookie > $forum_read)
 234          {
 235              $lastread = $readcookie;
 236          }
 237          else
 238          {
 239              $lastread = $forum_read;
 240          }
 241      }
 242  
 243     if($cutoff && $lastread < $cutoff)
 244     {
 245            $lastread = $cutoff;
 246     }
 247  
 248      // Next, find the proper pid to link to.
 249      $options = array(
 250          "limit_start" => 0,
 251          "limit" => 1,
 252          "order_by" => "dateline",
 253          "order_dir" => "asc"
 254      );
 255  
 256      $lastread = (int)$lastread;
 257      $query = $db->simple_select("posts", "pid", "tid='{$tid}' AND dateline > '{$lastread}' {$visibleonly}", $options);
 258      $newpost = $db->fetch_array($query);
 259  
 260      if($newpost['pid'] && $lastread)
 261      {
 262          $highlight = '';
 263          if($mybb->get_input('highlight'))
 264          {
 265              $string = "&";
 266              if($mybb->seo_support == true)
 267              {
 268                  $string = "?";
 269              }
 270  
 271              $highlight = $string."highlight=".$mybb->get_input('highlight');
 272          }
 273  
 274          header("Location: ".htmlspecialchars_decode(get_post_link($newpost['pid'], $tid)).$highlight."#pid{$newpost['pid']}");
 275      }
 276      else
 277      {
 278          // show them to the last post
 279          $mybb->input['action'] = "lastpost";
 280      }
 281  }
 282  
 283  // Jump to the last post.
 284  if($mybb->input['action'] == "lastpost")
 285  {
 286      if(my_strpos($thread['closed'], "moved|"))
 287      {
 288          $query = $db->query("
 289              SELECT p.pid
 290              FROM ".TABLE_PREFIX."posts p
 291              LEFT JOIN ".TABLE_PREFIX."threads t ON(p.tid=t.tid)
 292              WHERE t.fid='".$thread['fid']."' AND t.closed NOT LIKE 'moved|%' {$visibleonly2}
 293              ORDER BY p.dateline DESC
 294              LIMIT 1
 295          ");
 296          $pid = $db->fetch_field($query, "pid");
 297      }
 298      else
 299      {
 300          $options = array(
 301              'order_by' => 'dateline',
 302              'order_dir' => 'desc',
 303              'limit_start' => 0,
 304              'limit' => 1
 305          );
 306          $query = $db->simple_select('posts', 'pid', "tid={$tid} {$visibleonly}", $options);
 307          $pid = $db->fetch_field($query, "pid");
 308      }
 309      header("Location: ".htmlspecialchars_decode(get_post_link($pid, $tid))."#pid{$pid}");
 310      exit;
 311  }
 312  
 313  // Jump to the next newest posts.
 314  if($mybb->input['action'] == "nextnewest")
 315  {
 316      $options = array(
 317          "limit_start" => 0,
 318          "limit" => 1,
 319          "order_by" => "lastpost"
 320      );
 321      $query = $db->simple_select('threads', '*', "fid={$thread['fid']} AND lastpost > {$thread['lastpost']} {$visibleonly} AND closed NOT LIKE 'moved|%'", $options);
 322      $nextthread = $db->fetch_array($query);
 323  
 324      // Are there actually next newest posts?
 325      if(!$nextthread['tid'])
 326      {
 327          error($lang->error_nonextnewest);
 328      }
 329      $options = array(
 330          "limit_start" => 0,
 331          "limit" => 1,
 332          "order_by" => "dateline",
 333          "order_dir" => "desc"
 334      );
 335      $query = $db->simple_select('posts', 'pid', "tid='{$nextthread['tid']}'", $options);
 336  
 337      // Redirect to the proper page.
 338      $pid = $db->fetch_field($query, "pid");
 339      header("Location: ".htmlspecialchars_decode(get_post_link($pid, $nextthread['tid']))."#pid{$pid}");
 340      exit;
 341  }
 342  
 343  // Jump to the next oldest posts.
 344  if($mybb->input['action'] == "nextoldest")
 345  {
 346      $options = array(
 347          "limit" => 1,
 348          "limit_start" => 0,
 349          "order_by" => "lastpost",
 350          "order_dir" => "desc"
 351      );
 352      $query = $db->simple_select("threads", "*", "fid=".$thread['fid']." AND lastpost < ".$thread['lastpost']." {$visibleonly} AND closed NOT LIKE 'moved|%'", $options);
 353      $nextthread = $db->fetch_array($query);
 354  
 355      // Are there actually next oldest posts?
 356      if(!$nextthread['tid'])
 357      {
 358          error($lang->error_nonextoldest);
 359      }
 360      $options = array(
 361          "limit_start" => 0,
 362          "limit" => 1,
 363          "order_by" => "dateline",
 364          "order_dir" => "desc"
 365      );
 366      $query = $db->simple_select("posts", "pid", "tid='".$nextthread['tid']."'", $options);
 367  
 368      // Redirect to the proper page.
 369      $pid = $db->fetch_field($query, "pid");
 370      header("Location: ".htmlspecialchars_decode(get_post_link($pid, $nextthread['tid']))."#pid{$pid}");
 371      exit;
 372  }
 373  
 374  $pid = $mybb->input['pid'] = $mybb->get_input('pid', MyBB::INPUT_INT);
 375  
 376  // Forumdisplay cache
 377  $forum_stats = $cache->read("forumsdisplay");
 378  
 379  $breadcrumb_multipage = array();
 380  if($mybb->settings['showforumpagesbreadcrumb'])
 381  {
 382      // How many pages are there?
 383      if(!$mybb->settings['threadsperpage'] || (int)$mybb->settings['threadsperpage'] < 1)
 384      {
 385          $mybb->settings['threadsperpage'] = 20;
 386      }
 387  
 388      $query = $db->simple_select("forums", "threads, unapprovedthreads, deletedthreads", "fid = '{$fid}'", array('limit' => 1));
 389      $forum_threads = $db->fetch_array($query);
 390      $threadcount = $forum_threads['threads'];
 391  
 392  
 393      if(is_moderator($fid, "canviewdeleted") == true || is_moderator($fid, "canviewunapprove") == true)
 394      {
 395          if(is_moderator($fid, "canviewdeleted") == true)
 396          {
 397              $threadcount += $forum_threads['deletedthreads'];
 398          }
 399          if(is_moderator($fid, "canviewunapprove") == true)
 400          {
 401              $threadcount += $forum_threads['unapprovedthreads'];
 402          }
 403      }
 404      elseif($forumpermissions['canviewdeletionnotice'] != 0)
 405      {
 406          $threadcount += $forum_threads['deletedthreads'];
 407      }
 408  
 409      // Limit to only our own threads
 410      $uid_only = '';
 411      if(isset($forumpermissions['canonlyviewownthreads']) && $forumpermissions['canonlyviewownthreads'] == 1)
 412      {
 413          $uid_only = " AND uid = '".$mybb->user['uid']."'";
 414  
 415          $query = $db->simple_select("threads", "COUNT(tid) AS threads", "fid = '$fid' $visibleonly $uid_only", array('limit' => 1));
 416          $threadcount = $db->fetch_field($query, "threads");
 417      }
 418  
 419      // If we have 0 threads double check there aren't any "moved" threads
 420      if($threadcount == 0)
 421      {
 422          $query = $db->simple_select("threads", "COUNT(tid) AS threads", "fid = '$fid' $visibleonly $uid_only", array('limit' => 1));
 423          $threadcount = $db->fetch_field($query, "threads");
 424      }
 425  
 426      $stickybit = " OR sticky=1";
 427      if($thread['sticky'] == 1)
 428      {
 429          $stickybit = " AND sticky=1";
 430      }
 431  
 432      // Figure out what page the thread is actually on
 433      switch($db->type)
 434      {
 435          case "pgsql":
 436              $query = $db->query("
 437                  SELECT COUNT(tid) as threads
 438                  FROM ".TABLE_PREFIX."threads
 439                  WHERE fid = '$fid' AND (lastpost >= '".(int)$thread['lastpost']."'{$stickybit}) {$visibleonly} {$uid_only}
 440                  GROUP BY lastpost
 441                  ORDER BY lastpost DESC
 442              ");
 443              break;
 444          default:
 445              $query = $db->simple_select("threads", "COUNT(tid) as threads", "fid = '$fid' AND (lastpost >= '".(int)$thread['lastpost']."'{$stickybit}) {$visibleonly} {$uid_only}", array('order_by' => 'lastpost', 'order_dir' => 'desc'));
 446      }
 447  
 448      $thread_position = $db->fetch_field($query, "threads");
 449      $thread_page = ceil(($thread_position/$mybb->settings['threadsperpage']));
 450  
 451      $breadcrumb_multipage = array(
 452          "num_threads" => $threadcount,
 453          "current_page" => $thread_page
 454      );
 455  }
 456  
 457  // Build the navigation.
 458  build_forum_breadcrumb($fid, $breadcrumb_multipage);
 459  add_breadcrumb($thread['displayprefix'].$thread['subject'], get_thread_link($thread['tid']));
 460  
 461  $plugins->run_hooks("showthread_start");
 462  
 463  // Show the entire thread (taking into account pagination).
 464  if($mybb->input['action'] == "thread")
 465  {
 466      // This is a workaround to fix threads which data may get "corrupted" due to lag or other still unknown reasons
 467      if($thread['firstpost'] == 0 || $thread['dateline'] == 0)
 468      {
 469          update_first_post($tid);
 470      }
 471  
 472      // Does this thread have a poll?
 473      if($thread['poll'])
 474      {
 475          $options = array(
 476              "limit" => 1
 477          );
 478          $query = $db->simple_select("polls", "*", "pid='".$thread['poll']."'", $options);
 479          $poll = $db->fetch_array($query);
 480          $poll['timeout'] = $poll['timeout']*60*60*24;
 481          $expiretime = $poll['dateline'] + $poll['timeout'];
 482          $now = TIME_NOW;
 483  
 484          // If the poll or the thread is closed or if the poll is expired, show the results.
 485          if($poll['closed'] == 1 || $thread['closed'] == 1 || ($expiretime < $now && $poll['timeout'] > 0) || $forumpermissions['canvotepolls'] != 1)
 486          {
 487              $showresults = 1;
 488          }
 489  
 490          if($forumpermissions['canvotepolls'] != 1)
 491          {
 492              $nopermission = 1;
 493          }
 494  
 495          // Check if the user has voted before...
 496          if($mybb->user['uid'])
 497          {
 498              $user_check = "uid='{$mybb->user['uid']}'";
 499          }
 500          else
 501          {
 502              $user_check = "uid='0' AND ipaddress=".$db->escape_binary($session->packedip);
 503          }
 504  
 505          $query = $db->simple_select("pollvotes", "*", "{$user_check} AND pid='".$poll['pid']."'");
 506          while($votecheck = $db->fetch_array($query))
 507          {
 508              $alreadyvoted = 1;
 509              $votedfor[$votecheck['voteoption']] = 1;
 510          }
 511  
 512          $optionsarray = explode("||~|~||", $poll['options']);
 513          $votesarray = explode("||~|~||", $poll['votes']);
 514          $poll['question'] = htmlspecialchars_uni($poll['question']);
 515          $polloptions = '';
 516          $totalvotes = 0;
 517          $poll['totvotes'] = 0;
 518  
 519          for($i = 1; $i <= $poll['numoptions']; ++$i)
 520          {
 521              $poll['totvotes'] = $poll['totvotes'] + $votesarray[$i-1];
 522          }
 523  
 524          // Loop through the poll options.
 525          for($i = 1; $i <= $poll['numoptions']; ++$i)
 526          {
 527              // Set up the parser options.
 528              $parser_options = array(
 529                  "allow_html" => $forum['allowhtml'],
 530                  "allow_mycode" => $forum['allowmycode'],
 531                  "allow_smilies" => $forum['allowsmilies'],
 532                  "allow_imgcode" => $forum['allowimgcode'],
 533                  "allow_videocode" => $forum['allowvideocode'],
 534                  "filter_badwords" => 1
 535              );
 536  
 537              if($mybb->user['showimages'] != 1 && $mybb->user['uid'] != 0 || $mybb->settings['guestimages'] != 1 && $mybb->user['uid'] == 0)
 538              {
 539                  $parser_options['allow_imgcode'] = 0;
 540              }
 541  
 542              if($mybb->user['showvideos'] != 1 && $mybb->user['uid'] != 0 || $mybb->settings['guestvideos'] != 1 && $mybb->user['uid'] == 0)
 543              {
 544                  $parser_options['allow_videocode'] = 0;
 545              }
 546  
 547              $option = $parser->parse_message($optionsarray[$i-1], $parser_options);
 548              $votes = $votesarray[$i-1];
 549              $totalvotes += $votes;
 550              $number = $i;
 551  
 552              // Mark the option the user voted for.
 553              if(!empty($votedfor[$number]))
 554              {
 555                  $optionbg = "trow2";
 556                  $votestar = "*";
 557              }
 558              else
 559              {
 560                  $optionbg = "trow1";
 561                  $votestar = "";
 562              }
 563  
 564              // If the user already voted or if the results need to be shown, do so; else show voting screen.
 565              if(isset($alreadyvoted) || isset($showresults))
 566              {
 567                  if((int)$votes == "0")
 568                  {
 569                      $percent = "0";
 570                  }
 571                  else
 572                  {
 573                      $percent = number_format($votes / $poll['totvotes'] * 100, 2);
 574                  }
 575                  $imagewidth = round($percent);
 576                  eval("\$polloptions .= \"".$templates->get("showthread_poll_resultbit")."\";");
 577              }
 578              else
 579              {
 580                  if($poll['multiple'] == 1)
 581                  {
 582                      eval("\$polloptions .= \"".$templates->get("showthread_poll_option_multiple")."\";");
 583                  }
 584                  else
 585                  {
 586                      eval("\$polloptions .= \"".$templates->get("showthread_poll_option")."\";");
 587                  }
 588              }
 589          }
 590  
 591          // If there are any votes at all, all votes together will be 100%; if there are no votes, all votes together will be 0%.
 592          if($poll['totvotes'])
 593          {
 594              $totpercent = "100%";
 595          }
 596          else
 597          {
 598              $totpercent = "0%";
 599          }
 600  
 601          // Check if user is allowed to edit posts; if so, show "edit poll" link.
 602          $edit_poll = '';
 603          if(is_moderator($fid, 'canmanagepolls'))
 604          {
 605              eval("\$edit_poll = \"".$templates->get("showthread_poll_editpoll")."\";");
 606          }
 607  
 608          // Decide what poll status to show depending on the status of the poll and whether or not the user voted already.
 609          if(isset($alreadyvoted) || isset($showresults) || isset($nopermission))
 610          {
 611              if($alreadyvoted)
 612              {
 613                  $pollstatus = $lang->already_voted;
 614  
 615                  $undovote = '';
 616                  if($mybb->usergroup['canundovotes'] == 1)
 617                  {
 618                      eval("\$undovote = \"".$templates->get("showthread_poll_undovote")."\";");
 619                  }
 620              }
 621              elseif($nopermission)
 622              {
 623                  $pollstatus = $lang->no_voting_permission;
 624              }
 625              else
 626              {
 627                  $pollstatus = $lang->poll_closed;
 628              }
 629  
 630              $lang->total_votes = $lang->sprintf($lang->total_votes, $totalvotes);
 631              eval("\$pollbox = \"".$templates->get("showthread_poll_results")."\";");
 632              $plugins->run_hooks("showthread_poll_results");
 633          }
 634          else
 635          {
 636              $closeon = '&nbsp;';
 637              if($poll['timeout'] != 0)
 638              {
 639                  $closeon = $lang->sprintf($lang->poll_closes, my_date($mybb->settings['dateformat'], $expiretime));
 640              }
 641  
 642              $publicnote = '&nbsp;';
 643              if($poll['public'] == 1)
 644              {
 645                  $publicnote = $lang->public_note;
 646              }
 647  
 648              eval("\$pollbox = \"".$templates->get("showthread_poll")."\";");
 649              $plugins->run_hooks("showthread_poll");
 650          }
 651  
 652      }
 653      else
 654      {
 655          $pollbox = "";
 656      }
 657  
 658      // Create the forum jump dropdown box.
 659      if($mybb->settings['enableforumjump'] != 0)
 660      {
 661          $forumjump = build_forum_jump("", $fid, 1);
 662      }
 663  
 664      // Fetch some links
 665      $next_oldest_link = get_thread_link($tid, 0, "nextoldest");
 666      $next_newest_link = get_thread_link($tid, 0, "nextnewest");
 667  
 668      // Mark this thread as read
 669      mark_thread_read($tid, $fid);
 670  
 671      // If the forum is not open, show closed newreply button unless the user is a moderator of this forum.
 672      $newthread = $newreply = '';
 673      if($forum['open'] != 0 && $forum['type'] == "f")
 674      {
 675          if($forumpermissions['canpostthreads'] != 0 && $mybb->user['suspendposting'] != 1)
 676          {
 677              eval("\$newthread = \"".$templates->get("showthread_newthread")."\";");
 678          }
 679  
 680          // Show the appropriate reply button if this thread is open or closed
 681          if($forumpermissions['canpostreplys'] != 0 && $mybb->user['suspendposting'] != 1 && ($thread['closed'] != 1 || is_moderator($fid, "canpostclosedthreads")) && ($thread['uid'] == $mybb->user['uid'] || $forumpermissions['canonlyreplyownthreads'] != 1))
 682          {
 683              eval("\$newreply = \"".$templates->get("showthread_newreply")."\";");
 684          }
 685          elseif($thread['closed'] == 1)
 686          {
 687              eval("\$newreply = \"".$templates->get("showthread_newreply_closed")."\";");
 688          }
 689      }
 690  
 691      // Create the admin tools dropdown box.
 692      if($ismod == true)
 693      {
 694          $closelinkch = $stickch = '';
 695  
 696          if($thread['closed'] == 1)
 697          {
 698              $closelinkch = ' checked="checked"';
 699          }
 700  
 701          if($thread['sticky'])
 702          {
 703              $stickch = ' checked="checked"';
 704          }
 705  
 706          if(is_moderator($thread['fid'], "canopenclosethreads"))
 707          {
 708              eval("\$closeoption .= \"".$templates->get("showthread_quickreply_options_close")."\";");
 709          }
 710  
 711          if(is_moderator($thread['fid'], "canstickunstickthreads"))
 712          {
 713              eval("\$closeoption .= \"".$templates->get("showthread_quickreply_options_stick")."\";");
 714          }
 715  
 716          $inlinecount = "0";
 717          $inlinecookie = "inlinemod_thread".$tid;
 718  
 719          $plugins->run_hooks("showthread_ismod");
 720      }
 721      else
 722      {
 723          $modoptions = "&nbsp;";
 724          $inlinemod = $closeoption = '';
 725      }
 726  
 727      // Increment the thread view.
 728      if($mybb->settings['delayedthreadviews'] == 1)
 729      {
 730          $db->shutdown_query("INSERT INTO ".TABLE_PREFIX."threadviews (tid) VALUES('{$tid}')");
 731      }
 732      else
 733      {
 734          $db->shutdown_query("UPDATE ".TABLE_PREFIX."threads SET views=views+1 WHERE tid='{$tid}'");
 735      }
 736      ++$thread['views'];
 737  
 738      // Work out the thread rating for this thread.
 739      $rating = '';
 740      if($mybb->settings['allowthreadratings'] != 0 && $forum['allowtratings'] != 0)
 741      {
 742          $rated = 0;
 743          $lang->load("ratethread");
 744          if($thread['numratings'] <= 0)
 745          {
 746              $thread['width'] = 0;
 747              $thread['averagerating'] = 0;
 748              $thread['numratings'] = 0;
 749          }
 750          else
 751          {
 752              $thread['averagerating'] = (float)round($thread['totalratings']/$thread['numratings'], 2);
 753              $thread['width'] = (int)round($thread['averagerating'])*20;
 754              $thread['numratings'] = (int)$thread['numratings'];
 755          }
 756  
 757          if($thread['numratings'])
 758          {
 759              // At least >someone< has rated this thread, was it me?
 760              // Check if we have already voted on this thread - it won't show hover effect then.
 761              $query = $db->simple_select("threadratings", "uid", "tid='{$tid}' AND uid='{$mybb->user['uid']}'");
 762              $rated = $db->fetch_field($query, 'uid');
 763          }
 764  
 765          $not_rated = '';
 766          if(!$rated)
 767          {
 768              $not_rated = ' star_rating_notrated';
 769          }
 770  
 771          $ratingvotesav = $lang->sprintf($lang->rating_average, $thread['numratings'], $thread['averagerating']);
 772          eval("\$ratethread = \"".$templates->get("showthread_ratethread")."\";");
 773      }
 774      // Work out if we are showing unapproved posts as well (if the user is a moderator etc.)
 775      if($ismod && is_moderator($fid, "canviewdeleted") == true && is_moderator($fid, "canviewunapprove") == false)
 776      {
 777          $visible = "AND p.visible IN (-1,1)";
 778      }
 779      elseif($ismod && is_moderator($fid, "canviewdeleted") == false && is_moderator($fid, "canviewunapprove") == true)
 780      {
 781          $visible = "AND p.visible IN (0,1)";
 782      }
 783      elseif($ismod && is_moderator($fid, "canviewdeleted") == true && is_moderator($fid, "canviewunapprove") == true)
 784      {
 785          $visible = "AND p.visible IN (-1,0,1)";
 786      }
 787      elseif($forumpermissions['canviewdeletionnotice'] != 0 && $ismod == false)
 788      {
 789          $visible = "AND p.visible IN (-1,1)";
 790      }
 791      else
 792      {
 793          $visible = "AND p.visible='1'";
 794      }
 795  
 796      // Can this user perform searches? If so, we can show them the "Search thread" form
 797      if($forumpermissions['cansearch'] != 0)
 798      {
 799          eval("\$search_thread = \"".$templates->get("showthread_search")."\";");
 800      }
 801  
 802      // Fetch the ignore list for the current user if they have one
 803      $ignored_users = array();
 804      if($mybb->user['uid'] > 0 && $mybb->user['ignorelist'] != "")
 805      {
 806          $ignore_list = explode(',', $mybb->user['ignorelist']);
 807          foreach($ignore_list as $uid)
 808          {
 809              $ignored_users[$uid] = 1;
 810          }
 811      }
 812  
 813      // Fetch profile fields to display on postbit
 814      $pfcache = $cache->read('profilefields');
 815  
 816      if(is_array($pfcache))
 817      {
 818          foreach($pfcache as $profilefield)
 819          {
 820              if($profilefield['postbit'] != 1)
 821              {
 822                  continue;
 823              }
 824  
 825              $profile_fields[$profilefield['fid']] = $profilefield;
 826          }
 827      }
 828  
 829      // Which thread mode is our user using by default?
 830      if(!empty($mybb->user['threadmode']))
 831      {
 832          $defaultmode = $mybb->user['threadmode'];
 833      }
 834      else if($mybb->settings['threadusenetstyle'] == 1)
 835      {
 836          $defaultmode = 'threaded';
 837      }
 838      else
 839      {
 840          $defaultmode = 'linear';
 841      }
 842  
 843      // If mode is unset, set the default mode
 844      if(!isset($mybb->input['mode']))
 845      {
 846          $mybb->input['mode'] = $defaultmode;
 847      }
 848  
 849      // Threaded or linear display?
 850      $threadexbox = '';
 851      if($mybb->get_input('mode') == 'threaded')
 852      {
 853          $isfirst = 1;
 854  
 855          // Are we linked to a specific pid?
 856          if($mybb->input['pid'])
 857          {
 858              $where = "AND p.pid='".$mybb->input['pid']."'";
 859          }
 860          else
 861          {
 862              $where = " ORDER BY dateline LIMIT 0, 1";
 863          }
 864          $query = $db->query("
 865              SELECT u.*, u.username AS userusername, p.*, f.*, r.reporters, eu.username AS editusername
 866              FROM ".TABLE_PREFIX."posts p
 867              LEFT JOIN ".TABLE_PREFIX."reportedcontent r ON (r.id=p.pid AND r.type='post' AND r.reportstatus != 1)
 868              LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
 869              LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid)
 870              LEFT JOIN ".TABLE_PREFIX."users eu ON (eu.uid=p.edituid)
 871              WHERE p.tid='$tid' $visible $where
 872          ");
 873          $showpost = $db->fetch_array($query);
 874  
 875          // Choose what pid to display.
 876          if(!$mybb->input['pid'])
 877          {
 878              $mybb->input['pid'] = $showpost['pid'];
 879          }
 880  
 881          // Is there actually a pid to display?
 882          if(!$showpost['pid'])
 883          {
 884              error($lang->error_invalidpost);
 885          }
 886  
 887          $attachcache = array();
 888          if($mybb->settings['enableattachments'] == 1 && $thread['attachmentcount'] > 0 || is_moderator($fid, 'caneditposts'))
 889          {
 890              // Get the attachments for this post.
 891              $query = $db->simple_select("attachments", "*", "pid=".$mybb->input['pid']);
 892              while($attachment = $db->fetch_array($query))
 893              {
 894                  $attachcache[$attachment['pid']][$attachment['aid']] = $attachment;
 895              }
 896          }
 897  
 898          // Build the threaded post display tree.
 899          $query = $db->query("
 900              SELECT p.username, p.uid, p.pid, p.replyto, p.subject, p.dateline
 901              FROM ".TABLE_PREFIX."posts p
 902              WHERE p.tid='$tid'
 903              $visible
 904              ORDER BY p.dateline
 905          ");
 906          if(!is_array($postsdone))
 907          {
 908              $postsdone = array();
 909          }
 910          while($post = $db->fetch_array($query))
 911          {
 912              if(!$postsdone[$post['pid']])
 913              {
 914                  if($post['pid'] == $mybb->input['pid'] || ($isfirst && !$mybb->input['pid']))
 915                  {
 916                      $postcounter = count($postsdone);
 917                      $isfirst = 0;
 918                  }
 919                  $tree[$post['replyto']][$post['pid']] = $post;
 920                  $postsdone[$post['pid']] = 1;
 921              }
 922          }
 923  
 924          $threadedbits = buildtree();
 925          $posts = build_postbit($showpost);
 926          eval("\$threadexbox = \"".$templates->get("showthread_threadedbox")."\";");
 927          $plugins->run_hooks("showthread_threaded");
 928      }
 929      else // Linear display
 930      {
 931          $threadexbox = '';
 932          if(!$mybb->settings['postsperpage'] || (int)$mybb->settings['postsperpage'] < 1)
 933          {
 934              $mybb->settings['postsperpage'] = 20;
 935          }
 936  
 937          // Figure out if we need to display multiple pages.
 938          $page = 1;
 939          $perpage = $mybb->settings['postsperpage'];
 940          if($mybb->get_input('page', MyBB::INPUT_INT) && $mybb->get_input('page') != "last")
 941          {
 942              $page = $mybb->get_input('page', MyBB::INPUT_INT);
 943          }
 944  
 945          if(!empty($mybb->input['pid']))
 946          {
 947              $post = get_post($mybb->input['pid']);
 948              if(empty($post) || ($post['visible'] == 0 && !is_moderator($post['fid'], 'canviewunapprove')) || ($post['visible'] == -1 && !is_moderator($post['fid'], 'canviewdeleted') && $forumpermissions['canviewdeletionnotice'] == 0))
 949              {
 950                  $footer .= '<script type="text/javascript">$(function() { $.jGrowl(\''.$lang->error_invalidpost.'\', {theme: \'jgrowl_error\'}); });</script>';
 951              }
 952              else
 953              {
 954                  $query = $db->query("
 955                      SELECT COUNT(p.dateline) AS count FROM ".TABLE_PREFIX."posts p
 956                      WHERE p.tid = '{$tid}'
 957                      AND p.dateline <= '{$post['dateline']}'
 958                      {$visible}
 959                  ");
 960                  $result = $db->fetch_field($query, "count");
 961                  if(($result % $perpage) == 0)
 962                  {
 963                      $page = $result / $perpage;
 964                  }
 965                  else
 966                  {
 967                      $page = (int)($result / $perpage) + 1;
 968                  }
 969              }
 970          }
 971  
 972          // Recount replies if user is a moderator or can see the deletion notice to take into account unapproved/deleted posts.
 973          if($ismod || $forumpermissions['canviewdeletionnotice'] != 0)
 974          {
 975              $query = $db->simple_select("posts p", "COUNT(*) AS replies", "p.tid='$tid' $visible");
 976              $cached_replies = $thread['replies']+$thread['unapprovedposts']+$thread['deletedposts'];
 977              $thread['replies'] = $db->fetch_field($query, 'replies')-1;
 978  
 979              // The counters are wrong? Rebuild them
 980              // This doesn't cover all cases however it is a good addition to the manual rebuild function
 981              if($thread['replies'] != $cached_replies)
 982              {
 983                  require_once  MYBB_ROOT."/inc/functions_rebuild.php";
 984                  rebuild_thread_counters($thread['tid']);
 985              }
 986          }
 987          elseif($forumpermissions['canviewdeletionnotice'] != 0)
 988          {
 989              $thread['replies'] += $thread['deletedposts'];
 990          }
 991  
 992          $postcount = (int)$thread['replies']+1;
 993          $pages = $postcount / $perpage;
 994          $pages = ceil($pages);
 995  
 996          if($mybb->get_input('page') == "last")
 997          {
 998              $page = $pages;
 999          }
1000  
1001          if($page > $pages || $page <= 0)
1002          {
1003              $page = 1;
1004          }
1005  
1006          if($page)
1007          {
1008              $start = ($page-1) * $perpage;
1009          }
1010          else
1011          {
1012              $start = 0;
1013              $page = 1;
1014          }
1015          $upper = $start+$perpage;
1016  
1017          // Work out if we have terms to highlight
1018          $highlight = "";
1019          $threadmode = "";
1020          if($mybb->seo_support == true)
1021          {
1022              if($mybb->get_input('highlight'))
1023              {
1024                  $highlight = "?highlight=".urlencode($mybb->get_input('highlight'));
1025              }
1026  
1027              if($defaultmode != "linear")
1028              {
1029                  if($mybb->get_input('highlight'))
1030                  {
1031                      $threadmode = "&amp;mode=linear";
1032                  }
1033                  else
1034                  {
1035                      $threadmode = "?mode=linear";
1036                  }
1037              }
1038          }
1039          else
1040          {
1041              if(!empty($mybb->input['highlight']))
1042              {
1043                  if(is_array($mybb->input['highlight']))
1044                  {
1045                      foreach($mybb->input['highlight'] as $highlight_word)
1046                      {
1047                          $highlight .= "&amp;highlight[]=".urlencode($highlight_word);
1048                      }
1049                  }
1050                  else
1051                  {
1052                      $highlight = "&amp;highlight=".urlencode($mybb->get_input('highlight'));
1053                  }
1054              }
1055  
1056              if($defaultmode != "linear")
1057              {
1058                  $threadmode = "&amp;mode=linear";
1059              }
1060          }
1061  
1062          $multipage = multipage($postcount, $perpage, $page, str_replace("{tid}", $tid, THREAD_URL_PAGED.$highlight.$threadmode));
1063          
1064          // Allow originator to see own unapproved posts
1065          if($mybb->user['uid'] && $mybb->settings['showownunapproved'])
1066          {
1067              $visible .= " OR (p.tid='$tid' AND p.visible='0' AND p.uid=".$mybb->user['uid'].")";
1068          }
1069  
1070          // Lets get the pids of the posts on this page.
1071          $pids = "";
1072          $comma = '';
1073          $query = $db->simple_select("posts p", "p.pid", "p.tid='$tid' $visible", array('order_by' => 'p.dateline', 'limit_start' => $start, 'limit' => $perpage));
1074          while($getid = $db->fetch_array($query))
1075          {
1076              // Set the ID of the first post on page to $pid if it doesn't hold any value
1077              // to allow this value to be used for Thread Mode/Linear Mode links
1078              // and ensure the user lands on the correct page after changing view mode
1079              if(empty($pid))
1080              {
1081                  $pid = $getid['pid'];
1082              }
1083              // Gather a comma separated list of post IDs
1084              $pids .= "$comma'{$getid['pid']}'";
1085              $comma = ",";
1086          }
1087          if($pids)
1088          {
1089              $pids = "pid IN($pids)";
1090  
1091              $attachcache = array();
1092              if($mybb->settings['enableattachments'] == 1 && $thread['attachmentcount'] > 0 || is_moderator($fid, 'caneditposts'))
1093              {
1094                  // Now lets fetch all of the attachments for these posts.
1095                  $query = $db->simple_select("attachments", "*", $pids);
1096                  while($attachment = $db->fetch_array($query))
1097                  {
1098                      $attachcache[$attachment['pid']][$attachment['aid']] = $attachment;
1099                  }
1100              }
1101          }
1102          else
1103          {
1104              // If there are no pid's the thread is probably awaiting approval.
1105              error($lang->error_invalidthread);
1106          }
1107  
1108          // Get the actual posts from the database here.
1109          $posts = '';
1110          $query = $db->query("
1111              SELECT u.*, u.username AS userusername, p.*, f.*, r.reporters, eu.username AS editusername
1112              FROM ".TABLE_PREFIX."posts p
1113              LEFT JOIN ".TABLE_PREFIX."reportedcontent r ON (r.id=p.pid AND r.type='post' AND r.reportstatus != 1)
1114              LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
1115              LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid)
1116              LEFT JOIN ".TABLE_PREFIX."users eu ON (eu.uid=p.edituid)
1117              WHERE $pids
1118              ORDER BY p.dateline
1119          ");
1120          while($post = $db->fetch_array($query))
1121          {
1122              if($thread['firstpost'] == $post['pid'] && $thread['visible'] == 0)
1123              {
1124                  $post['visible'] = 0;
1125              }
1126              $posts .= build_postbit($post);
1127              $post = '';
1128          }
1129          $plugins->run_hooks("showthread_linear");
1130      }
1131  
1132      // Show the similar threads table if wanted.
1133      $similarthreads = '';
1134      if($mybb->settings['showsimilarthreads'] != 0)
1135      {
1136          $own_perm = '';
1137          if($forumpermissions['canonlyviewownthreads'] == 1)
1138          {
1139              $own_perm = " AND t.uid={$mybb->user['uid']}";
1140          }
1141  
1142          switch($db->type)
1143          {
1144              case "pgsql":
1145                  $query = $db->query("
1146                      SELECT t.*, t.username AS threadusername, u.username
1147                      FROM ".TABLE_PREFIX."threads t
1148                      LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid), plainto_tsquery ('".$db->escape_string($thread['subject'])."') AS query
1149                      WHERE t.fid='{$thread['fid']}' AND t.tid!='{$thread['tid']}' AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND t.subject @@ query{$own_perm}
1150                      ORDER BY t.lastpost DESC
1151                      OFFSET 0 LIMIT {$mybb->settings['similarlimit']}
1152                  ");
1153                  break;
1154              default:
1155                  $query = $db->query("
1156                      SELECT t.*, t.username AS threadusername, u.username, MATCH (t.subject) AGAINST ('".$db->escape_string($thread['subject'])."') AS relevance
1157                      FROM ".TABLE_PREFIX."threads t
1158                      LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid)
1159                      WHERE t.fid='{$thread['fid']}' AND t.tid!='{$thread['tid']}' AND t.visible='1' AND t.closed NOT LIKE 'moved|%'{$own_perm} AND MATCH (t.subject) AGAINST ('".$db->escape_string($thread['subject'])."') >= '{$mybb->settings['similarityrating']}'
1160                      ORDER BY t.lastpost DESC
1161                      LIMIT 0, {$mybb->settings['similarlimit']}
1162                  ");
1163          }
1164  
1165          $count = 0;
1166          $similarthreadbits = '';
1167          $icon_cache = $cache->read("posticons");
1168          while($similar_thread = $db->fetch_array($query))
1169          {
1170              ++$count;
1171              $trow = alt_trow();
1172              if($similar_thread['icon'] > 0 && $icon_cache[$similar_thread['icon']])
1173              {
1174                  $icon = $icon_cache[$similar_thread['icon']];
1175                  $icon['path'] = str_replace("{theme}", $theme['imgdir'], $icon['path']);
1176                  $icon['path'] = htmlspecialchars_uni($icon['path']);
1177                  $icon['name'] = htmlspecialchars_uni($icon['name']);
1178                  eval("\$icon = \"".$templates->get("forumdisplay_thread_icon")."\";");
1179              }
1180              else
1181              {
1182                  $icon = "&nbsp;";
1183              }
1184              if(!$similar_thread['username'])
1185              {
1186                  $similar_thread['username'] = $similar_thread['profilelink'] = htmlspecialchars_uni($similar_thread['threadusername']);
1187              }
1188              else
1189              {
1190                  $similar_thread['username'] = htmlspecialchars_uni($similar_thread['username']);
1191                  $similar_thread['profilelink'] = build_profile_link($similar_thread['username'], $similar_thread['uid']);
1192              }
1193  
1194              // If this thread has a prefix, insert a space between prefix and subject
1195              if($similar_thread['prefix'] != 0)
1196              {
1197                  $prefix = build_prefixes($similar_thread['prefix']);
1198                  if(!empty($prefix))
1199                  {
1200                      $similar_thread['threadprefix'] = $prefix['displaystyle'].'&nbsp;';
1201                  }
1202              }
1203  
1204              $similar_thread['subject'] = $parser->parse_badwords($similar_thread['subject']);
1205              $similar_thread['subject'] = htmlspecialchars_uni($similar_thread['subject']);
1206              $similar_thread['threadlink'] = get_thread_link($similar_thread['tid']);
1207              $similar_thread['lastpostlink'] = get_thread_link($similar_thread['tid'], 0, "lastpost");
1208  
1209              $lastpostdate = my_date('relative', $similar_thread['lastpost']);
1210              $lastposter = $similar_thread['lastposter'];
1211              $lastposteruid = $similar_thread['lastposteruid'];
1212  
1213              // Don't link to guest's profiles (they have no profile).
1214              if($lastposteruid == 0)
1215              {
1216                  $lastposterlink = $lastposter;
1217              }
1218              else
1219              {
1220                  $lastposterlink = build_profile_link($lastposter, $lastposteruid);
1221              }
1222              $similar_thread['replies'] = my_number_format($similar_thread['replies']);
1223              $similar_thread['views'] = my_number_format($similar_thread['views']);
1224              eval("\$similarthreadbits .= \"".$templates->get("showthread_similarthreads_bit")."\";");
1225          }
1226          if($count)
1227          {
1228              eval("\$similarthreads = \"".$templates->get("showthread_similarthreads")."\";");
1229          }
1230      }
1231  
1232      // Decide whether or not to show quick reply.
1233      $quickreply = '';
1234      if($forumpermissions['canpostreplys'] != 0 && $mybb->user['suspendposting'] != 1 && ($thread['closed'] != 1 || is_moderator($fid, "canpostclosedthreads")) && $mybb->settings['quickreply'] != 0 && $mybb->user['showquickreply'] != '0' && $forum['open'] != 0 && ($thread['uid'] == $mybb->user['uid'] || $forumpermissions['canonlyreplyownthreads'] != 1))
1235      {
1236          $query = $db->simple_select("posts", "pid", "tid='{$tid}'", array("order_by" => "pid", "order_dir" => "desc", "limit" => 1));
1237          $last_pid = $db->fetch_field($query, "pid");
1238  
1239          // Show captcha image for guests if enabled
1240          $captcha = '';
1241          if($mybb->settings['captchaimage'] && !$mybb->user['uid'])
1242          {
1243              require_once  MYBB_ROOT.'inc/class_captcha.php';
1244              $post_captcha = new captcha(true, "post_captcha");
1245  
1246              if($post_captcha->html)
1247              {
1248                  $captcha = $post_captcha->html;
1249              }
1250          }
1251  
1252          $postoptionschecked = array('signature' => '', 'emailnotify' => '');
1253          if($mybb->user['signature'])
1254          {
1255              $postoptionschecked['signature'] = 'checked="checked"';
1256          }
1257  
1258          // Hide signature option if no permission
1259          $option_signature = '';
1260          if($mybb->usergroup['canusesig'] && !$mybb->user['suspendsignature'])
1261          {
1262              eval("\$option_signature = \"".$templates->get('showthread_quickreply_options_signature')."\";");
1263          }
1264  
1265          if(isset($mybb->user['emailnotify']) && $mybb->user['emailnotify'] == 1)
1266          {
1267              $postoptionschecked['emailnotify'] = 'checked="checked"';
1268          }
1269  
1270          $trow = alt_trow();
1271          if($thread['closed'] == 1)
1272          {
1273              $trow = 'trow_shaded';
1274          }
1275  
1276          $moderation_notice = '';
1277          if(!is_moderator($forum['fid'], "canapproveunapproveposts"))
1278          {
1279              if($forumpermissions['modposts'] == 1)
1280              {
1281                  $moderation_text = $lang->moderation_forum_posts;
1282                  eval('$moderation_notice = "'.$templates->get('global_moderation_notice').'";');
1283              }
1284  
1285              if($mybb->user['moderateposts'] == 1)
1286              {
1287                  $moderation_text = $lang->moderation_user_posts;
1288                  eval('$moderation_notice = "'.$templates->get('global_moderation_notice').'";');
1289              }
1290          }
1291  
1292              $posthash = md5($mybb->user['uid'].random_str());
1293          $expaltext = (in_array("quickreply", $collapse)) ? "[+]" : "[-]";
1294          eval("\$quickreply = \"".$templates->get("showthread_quickreply")."\";");
1295      }
1296  
1297      $moderationoptions = '';
1298  
1299      // If the user is a moderator, show the moderation tools.
1300      if($ismod)
1301      {
1302          $customthreadtools = $customposttools = $standardthreadtools = $standardposttools = '';
1303  
1304          $threadnotesbox = $viewnotes = '';
1305          if(!empty($thread['notes']))
1306          {
1307              $thread['notes'] = nl2br(htmlspecialchars_uni($thread['notes']));
1308  
1309              if(strlen($thread['notes']) > 200)
1310              {
1311                  eval("\$viewnotes = \"".$templates->get("showthread_threadnotes_viewnotes")."\";");
1312                  $thread['notes'] = my_substr($thread['notes'], 0, 200)."... {$viewnotes}";
1313              }
1314  
1315              $expaltext = (in_array("threadnotes", $collapse)) ? "[+]" : "[-]";
1316              eval("\$threadnotesbox = \"".$templates->get("showthread_threadnotes")."\";");
1317          }
1318  
1319          if(is_moderator($forum['fid'], "canusecustomtools") && (!empty($forum_stats[-1]['modtools']) || !empty($forum_stats[$forum['fid']]['modtools'])))
1320          {
1321              $gids = explode(',', $mybb->user['additionalgroups']);
1322              $gids[] = $mybb->user['usergroup'];
1323              $gids = array_filter(array_unique($gids));
1324              switch($db->type)
1325              {
1326                  case "pgsql":
1327                  case "sqlite":
1328                      foreach($gids as $gid)
1329                      {
1330                          $gid = (int)$gid;
1331                          $gidswhere .= " OR ','||groups||',' LIKE '%,{$gid},%'";
1332                      }
1333                      $query = $db->simple_select("modtools", 'tid, name, type', "(','||forums||',' LIKE '%,$fid,%' OR ','||forums||',' LIKE '%,-1,%' OR forums='') AND (groups='' OR ','||groups||',' LIKE '%,-1,%'{$gidswhere})");
1334                      break;
1335                  default:
1336                      foreach($gids as $gid)
1337                      {
1338                          $gid = (int)$gid;
1339                          $gidswhere .= " OR CONCAT(',',`groups`,',') LIKE '%,{$gid},%'";
1340                      }
1341                      $query = $db->simple_select("modtools", 'tid, name, type', "(CONCAT(',',forums,',') LIKE '%,$fid,%' OR CONCAT(',',forums,',') LIKE '%,-1,%' OR forums='') AND (`groups`='' OR CONCAT(',',`groups`,',') LIKE '%,-1,%'{$gidswhere})");
1342                      break;
1343              }
1344  
1345              while($tool = $db->fetch_array($query))
1346              {
1347                  $tool['name'] = htmlspecialchars_uni($tool['name']);
1348                  if($tool['type'] == 'p')
1349                  {
1350                      eval("\$customposttools .= \"".$templates->get("showthread_inlinemoderation_custom_tool")."\";");
1351                  }
1352                  else
1353                  {
1354                      eval("\$customthreadtools .= \"".$templates->get("showthread_moderationoptions_custom_tool")."\";");
1355                  }
1356              }
1357  
1358              // Build inline moderation dropdown
1359              if(!empty($customposttools))
1360              {
1361                  eval("\$customposttools = \"".$templates->get("showthread_inlinemoderation_custom")."\";");
1362              }
1363          }
1364  
1365          $inlinemodsoftdelete = $inlinemodrestore = $inlinemoddelete = $inlinemodmanage = $inlinemodapprove = '';
1366  
1367          if(is_moderator($forum['fid'], "cansoftdeleteposts"))
1368          {
1369              eval("\$inlinemodsoftdelete = \"".$templates->get("showthread_inlinemoderation_softdelete")."\";");
1370          }
1371  
1372          if(is_moderator($forum['fid'], "canrestoreposts"))
1373          {
1374              eval("\$inlinemodrestore = \"".$templates->get("showthread_inlinemoderation_restore")."\";");
1375          }
1376  
1377          if(is_moderator($forum['fid'], "candeleteposts"))
1378          {
1379              eval("\$inlinemoddelete = \"".$templates->get("showthread_inlinemoderation_delete")."\";");
1380          }
1381  
1382          if(is_moderator($forum['fid'], "canmanagethreads"))
1383          {
1384              eval("\$inlinemodmanage = \"".$templates->get("showthread_inlinemoderation_manage")."\";");
1385          }
1386  
1387          if(is_moderator($forum['fid'], "canapproveunapproveposts"))
1388          {
1389              eval("\$inlinemodapprove = \"".$templates->get("showthread_inlinemoderation_approve")."\";");
1390          }
1391  
1392          if(!empty($inlinemodsoftdelete) || !empty($inlinemodrestore) || !empty($inlinemoddelete) || !empty($inlinemodmanage) || !empty($inlinemodapprove))
1393          {
1394              eval("\$standardposttools = \"".$templates->get("showthread_inlinemoderation_standard")."\";");
1395          }
1396  
1397          // Only show inline mod menu if there's options to show
1398          if(!empty($standardposttools) || !empty($customposttools))
1399          {
1400              eval("\$inlinemod = \"".$templates->get("showthread_inlinemoderation")."\";");
1401          }
1402  
1403          // Build thread moderation dropdown
1404          if(!empty($customthreadtools))
1405          {
1406              eval("\$customthreadtools = \"".$templates->get("showthread_moderationoptions_custom")."\";");
1407          }
1408  
1409          $openclosethread = $stickunstickthread = $deletethread = $threadnotes = $managethread = $adminpolloptions = $approveunapprovethread = $softdeletethread = '';
1410  
1411          if(is_moderator($forum['fid'], "canopenclosethreads"))
1412          {
1413              eval("\$openclosethread = \"".$templates->get("showthread_moderationoptions_openclose")."\";");
1414          }
1415  
1416          if(is_moderator($forum['fid'], "canstickunstickthreads"))
1417          {
1418              eval("\$stickunstickthread = \"".$templates->get("showthread_moderationoptions_stickunstick")."\";");
1419          }
1420  
1421          if(is_moderator($forum['fid'], "candeletethreads"))
1422          {
1423              eval("\$deletethread = \"".$templates->get("showthread_moderationoptions_delete")."\";");
1424          }
1425  
1426          if(is_moderator($forum['fid'], "canmanagethreads"))
1427          {
1428              eval("\$threadnotes = \"".$templates->get("showthread_moderationoptions_threadnotes")."\";");
1429              eval("\$managethread = \"".$templates->get("showthread_moderationoptions_manage")."\";");
1430          }
1431  
1432          if($pollbox && is_moderator($forum['fid'], "canmanagepolls"))
1433          {
1434              eval("\$adminpolloptions = \"".$templates->get("showthread_moderationoptions_deletepoll")."\";");
1435          }
1436  
1437          if(is_moderator($forum['fid'], "canapproveunapprovethreads"))
1438          {
1439              if($thread['visible'] == 0)
1440              {
1441                  eval("\$approveunapprovethread = \"".$templates->get("showthread_moderationoptions_approve")."\";");
1442              }
1443              else
1444              {
1445                  eval("\$approveunapprovethread = \"".$templates->get("showthread_moderationoptions_unapprove")."\";");
1446              }
1447          }
1448  
1449          if(is_moderator($forum['fid'], "cansoftdeletethreads") && $thread['visible'] != -1)
1450          {
1451              eval("\$softdeletethread = \"".$templates->get("showthread_moderationoptions_softdelete")."\";");
1452          }
1453          elseif(is_moderator($forum['fid'], "canrestorethreads") && $thread['visible'] == -1)
1454          {
1455              eval("\$softdeletethread = \"".$templates->get("showthread_moderationoptions_restore")."\";");
1456          }
1457  
1458          if(!empty($openclosethread) || !empty($stickunstickthread) || !empty($deletethread) || !empty($managethread) || !empty($adminpolloptions) || !empty($approveunapprovethread) || !empty($softdeletethread))
1459          {
1460              eval("\$standardthreadtools = \"".$templates->get("showthread_moderationoptions_standard")."\";");
1461          }
1462  
1463          // Only show mod menu if there's any options to show
1464          if(!empty($standardthreadtools) || !empty($customthreadtools))
1465          {
1466              eval("\$moderationoptions = \"".$templates->get("showthread_moderationoptions")."\";");
1467          }
1468      }
1469  
1470      eval("\$printthread = \"".$templates->get("showthread_printthread")."\";");
1471  
1472      // Display 'send thread' link if permissions allow
1473      $sendthread = '';
1474      if($mybb->usergroup['cansendemail'] == 1)
1475      {
1476          eval("\$sendthread = \"".$templates->get("showthread_send_thread")."\";");
1477      }
1478  
1479      // Display 'add poll' link to thread creator (or mods) if thread doesn't have a poll already
1480      $addpoll = '';
1481      $time = TIME_NOW;
1482      if(!$thread['poll'] && ($thread['uid'] == $mybb->user['uid'] || $ismod == true) && $forumpermissions['canpostpolls'] == 1 && $forum['open'] != 0 && $thread['closed'] != 1 && ($ismod == true || $thread['dateline'] > ($time-($mybb->settings['polltimelimit']*60*60)) || $mybb->settings['polltimelimit'] == 0))
1483      {
1484          eval("\$addpoll = \"".$templates->get("showthread_add_poll")."\";");
1485      }
1486  
1487      // Subscription status
1488      $add_remove_subscription = 'add';
1489      $add_remove_subscription_text = $lang->subscribe_thread;
1490  
1491      if($mybb->user['uid'])
1492      {
1493          $query = $db->simple_select("threadsubscriptions", "tid", "tid='".(int)$tid."' AND uid='".(int)$mybb->user['uid']."'", array('limit' => 1));
1494  
1495          if($db->fetch_field($query, 'tid'))
1496          {
1497              $add_remove_subscription = 'remove';
1498              $add_remove_subscription_text = $lang->unsubscribe_thread;
1499          }
1500  
1501          eval("\$addremovesubscription = \"".$templates->get("showthread_subscription")."\";");
1502      }
1503  
1504      $classic_header = '';
1505      if($mybb->settings['postlayout'] == "classic")
1506      {
1507          eval("\$classic_header = \"".$templates->get("showthread_classic_header")."\";");
1508      }
1509  
1510      // Get users viewing this thread
1511      if($mybb->settings['browsingthisthread'] != 0)
1512      {
1513          $timecut = TIME_NOW - $mybb->settings['wolcutoff'];
1514  
1515          $comma = '';
1516          $guestcount = 0;
1517          $membercount = 0;
1518          $inviscount = 0;
1519          $onlinemembers = '';
1520          $doneusers = array();
1521  
1522          $query = $db->simple_select("sessions", "COUNT(DISTINCT ip) AS guestcount", "uid = 0 AND time > $timecut AND location2 = $tid AND nopermission != 1");
1523          $guestcount = $db->fetch_field($query, 'guestcount');
1524  
1525          $query = $db->query("
1526              SELECT
1527                  s.ip, s.uid, s.time, u.username, u.invisible, u.usergroup, u.displaygroup
1528              FROM
1529                  ".TABLE_PREFIX."sessions s
1530                  LEFT JOIN ".TABLE_PREFIX."users u ON (s.uid=u.uid)
1531              WHERE s.uid != 0 AND s.time > '$timecut' AND location2='$tid' AND nopermission != 1
1532              ORDER BY u.username ASC, s.time DESC
1533          ");
1534  
1535          while($user = $db->fetch_array($query))
1536          {
1537              if(empty($doneusers[$user['uid']]) || $doneusers[$user['uid']] < $user['time'])
1538              {
1539                  ++$membercount;
1540                  $doneusers[$user['uid']] = $user['time'];
1541  
1542                  $invisiblemark = '';
1543                  if($user['invisible'] == 1)
1544                  {
1545                      $invisiblemark = "*";
1546                      ++$inviscount;
1547                  }
1548  
1549                  if($user['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1 || $user['uid'] == $mybb->user['uid'])
1550                  {
1551                      $user['profilelink'] = get_profile_link($user['uid']);
1552                      $user['username'] = format_name(htmlspecialchars_uni($user['username']), $user['usergroup'], $user['displaygroup']);
1553                      $user['reading'] = my_date($mybb->settings['timeformat'], $user['time']);
1554  
1555                      eval("\$onlinemembers .= \"".$templates->get("showthread_usersbrowsing_user", 1, 0)."\";");
1556                      $comma = $lang->comma;
1557                  }
1558              }
1559          }
1560  
1561          $guestsonline = '';
1562          if($guestcount)
1563          {
1564              $guestsonline = $lang->sprintf($lang->users_browsing_thread_guests, $guestcount);
1565          }
1566  
1567          $invisonline = '';
1568          if($mybb->user['invisible'] == 1)
1569          {
1570              // the user was counted as invisible user --> correct the inviscount
1571              $inviscount -= 1;
1572          }
1573          if($inviscount && $mybb->usergroup['canviewwolinvis'] != 1)
1574          {
1575              $invisonline = $lang->sprintf($lang->users_browsing_forum_invis, $inviscount);
1576          }
1577  
1578          $onlinesep = '';
1579          if($invisonline != '' && $onlinemembers)
1580          {
1581              $onlinesep = $lang->comma;
1582          }
1583  
1584          $onlinesep2 = '';
1585          if($invisonline != '' && $guestcount || $onlinemembers && $guestcount)
1586          {
1587              $onlinesep2 = $lang->comma;
1588          }
1589  
1590          eval("\$usersbrowsing = \"".$templates->get("showthread_usersbrowsing")."\";");
1591      }
1592  
1593      if($thread['visible'] == -1 )
1594      {
1595          $thread_deleted = 1;
1596      }
1597  
1598      $plugins->run_hooks("showthread_end");
1599  
1600      eval("\$showthread = \"".$templates->get("showthread")."\";");
1601      output_page($showthread);
1602  }
1603  
1604  /**
1605   * Build a navigation tree for threaded display.
1606   *
1607   * @param int $replyto
1608   * @param int $indent
1609   * @return string
1610   */
1611  function buildtree($replyto=0, $indent=0)
1612  {
1613      global $tree, $mybb, $theme, $mybb, $pid, $tid, $templates, $parser, $lang;
1614  
1615      $indentsize = 13 * $indent;
1616  
1617      ++$indent;
1618      $posts = '';
1619      if(is_array($tree[$replyto]))
1620      {
1621          foreach($tree[$replyto] as $key => $post)
1622          {
1623              $postdate = my_date('relative', $post['dateline']);
1624              $post['subject'] = htmlspecialchars_uni($parser->parse_badwords($post['subject']));
1625  
1626              if(!$post['subject'])
1627              {
1628                  $post['subject'] = "[".$lang->no_subject."]";
1629              }
1630  
1631              $post['username'] = htmlspecialchars_uni($post['username']);
1632              $post['profilelink'] = build_profile_link($post['username'], $post['uid']);
1633  
1634              if($mybb->input['pid'] == $post['pid'])
1635              {
1636                  eval("\$posts .= \"".$templates->get("showthread_threaded_bitactive")."\";");
1637              }
1638              else
1639              {
1640                  eval("\$posts .= \"".$templates->get("showthread_threaded_bit")."\";");
1641              }
1642  
1643              if($tree[$post['pid']])
1644              {
1645                  $posts .= buildtree($post['pid'], $indent);
1646              }
1647          }
1648          --$indent;
1649      }
1650      return $posts;
1651  }


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