[ Index ]

PHP Cross Reference of MyBB 1.8.38

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


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