[ Index ]

PHP Cross Reference of MyBB 1.8.21

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,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.*, eu.username AS editusername
 866              FROM ".TABLE_PREFIX."posts p
 867              LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
 868              LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid)
 869              LEFT JOIN ".TABLE_PREFIX."users eu ON (eu.uid=p.edituid)
 870              WHERE p.tid='$tid' $visible $where
 871          ");
 872          $showpost = $db->fetch_array($query);
 873  
 874          // Choose what pid to display.
 875          if(!$mybb->input['pid'])
 876          {
 877              $mybb->input['pid'] = $showpost['pid'];
 878          }
 879  
 880          // Is there actually a pid to display?
 881          if(!$showpost['pid'])
 882          {
 883              error($lang->error_invalidpost);
 884          }
 885  
 886          $attachcache = array();
 887          if($mybb->settings['enableattachments'] == 1 && $thread['attachmentcount'] > 0 || is_moderator($fid, 'caneditposts'))
 888          {
 889              // Get the attachments for this post.
 890              $query = $db->simple_select("attachments", "*", "pid=".$mybb->input['pid']);
 891              while($attachment = $db->fetch_array($query))
 892              {
 893                  $attachcache[$attachment['pid']][$attachment['aid']] = $attachment;
 894              }
 895          }
 896  
 897          // Build the threaded post display tree.
 898          $query = $db->query("
 899              SELECT p.username, p.uid, p.pid, p.replyto, p.subject, p.dateline
 900              FROM ".TABLE_PREFIX."posts p
 901              WHERE p.tid='$tid'
 902              $visible
 903              ORDER BY p.dateline
 904          ");
 905          if(!is_array($postsdone))
 906          {
 907              $postsdone = array();
 908          }
 909          while($post = $db->fetch_array($query))
 910          {
 911              if(!$postsdone[$post['pid']])
 912              {
 913                  if($post['pid'] == $mybb->input['pid'] || ($isfirst && !$mybb->input['pid']))
 914                  {
 915                      $postcounter = count($postsdone);
 916                      $isfirst = 0;
 917                  }
 918                  $tree[$post['replyto']][$post['pid']] = $post;
 919                  $postsdone[$post['pid']] = 1;
 920              }
 921          }
 922  
 923          $threadedbits = buildtree();
 924          $posts = build_postbit($showpost);
 925          eval("\$threadexbox = \"".$templates->get("showthread_threadedbox")."\";");
 926          $plugins->run_hooks("showthread_threaded");
 927      }
 928      else // Linear display
 929      {
 930          $threadexbox = '';
 931          if(!$mybb->settings['postsperpage'] || (int)$mybb->settings['postsperpage'] < 1)
 932          {
 933              $mybb->settings['postsperpage'] = 20;
 934          }
 935  
 936          // Figure out if we need to display multiple pages.
 937          $page = 1;
 938          $perpage = $mybb->settings['postsperpage'];
 939          if($mybb->get_input('page', MyBB::INPUT_INT) && $mybb->get_input('page') != "last")
 940          {
 941              $page = $mybb->get_input('page', MyBB::INPUT_INT);
 942          }
 943  
 944          if(!empty($mybb->input['pid']))
 945          {
 946              $post = get_post($mybb->input['pid']);
 947              if(empty($post) || ($post['visible'] == 0 && !is_moderator($post['fid'], 'canviewunapprove')) || ($post['visible'] == -1 && !is_moderator($post['fid'], 'canviewdeleted') && $forumpermissions['canviewdeletionnotice'] == 0))
 948              {
 949                  $footer .= '<script type="text/javascript">$(function() { $.jGrowl(\''.$lang->error_invalidpost.'\', {theme: \'jgrowl_error\'}); });</script>';
 950              }
 951              else
 952              {
 953                  $query = $db->query("
 954                      SELECT COUNT(p.dateline) AS count FROM ".TABLE_PREFIX."posts p
 955                      WHERE p.tid = '{$tid}'
 956                      AND p.dateline <= '{$post['dateline']}'
 957                      {$visible}
 958                  ");
 959                  $result = $db->fetch_field($query, "count");
 960                  if(($result % $perpage) == 0)
 961                  {
 962                      $page = $result / $perpage;
 963                  }
 964                  else
 965                  {
 966                      $page = (int)($result / $perpage) + 1;
 967                  }
 968              }
 969          }
 970  
 971          // Recount replies if user is a moderator or can see the deletion notice to take into account unapproved/deleted posts.
 972          if($ismod || $forumpermissions['canviewdeletionnotice'] != 0)
 973          {
 974              $query = $db->simple_select("posts p", "COUNT(*) AS replies", "p.tid='$tid' $visible");
 975              $cached_replies = $thread['replies']+$thread['unapprovedposts']+$thread['deletedposts'];
 976              $thread['replies'] = $db->fetch_field($query, 'replies')-1;
 977  
 978              // The counters are wrong? Rebuild them
 979              // This doesn't cover all cases however it is a good addition to the manual rebuild function
 980              if($thread['replies'] != $cached_replies)
 981              {
 982                  require_once  MYBB_ROOT."/inc/functions_rebuild.php";
 983                  rebuild_thread_counters($thread['tid']);
 984              }
 985          }
 986          elseif($forumpermissions['canviewdeletionnotice'] != 0)
 987          {
 988              $thread['replies'] += $thread['deletedposts'];
 989          }
 990  
 991          $postcount = (int)$thread['replies']+1;
 992          $pages = $postcount / $perpage;
 993          $pages = ceil($pages);
 994  
 995          if($mybb->get_input('page') == "last")
 996          {
 997              $page = $pages;
 998          }
 999  
1000          if($page > $pages || $page <= 0)
1001          {
1002              $page = 1;
1003          }
1004  
1005          if($page)
1006          {
1007              $start = ($page-1) * $perpage;
1008          }
1009          else
1010          {
1011              $start = 0;
1012              $page = 1;
1013          }
1014          $upper = $start+$perpage;
1015  
1016          // Work out if we have terms to highlight
1017          $highlight = "";
1018          $threadmode = "";
1019          if($mybb->seo_support == true)
1020          {
1021              if($mybb->get_input('highlight'))
1022              {
1023                  $highlight = "?highlight=".urlencode($mybb->get_input('highlight'));
1024              }
1025  
1026              if($defaultmode != "linear")
1027              {
1028                  if($mybb->get_input('highlight'))
1029                  {
1030                      $threadmode = "&amp;mode=linear";
1031                  }
1032                  else
1033                  {
1034                      $threadmode = "?mode=linear";
1035                  }
1036              }
1037          }
1038          else
1039          {
1040              if(!empty($mybb->input['highlight']))
1041              {
1042                  if(is_array($mybb->input['highlight']))
1043                  {
1044                      foreach($mybb->input['highlight'] as $highlight_word)
1045                      {
1046                          $highlight .= "&amp;highlight[]=".urlencode($highlight_word);
1047                      }
1048                  }
1049                  else
1050                  {
1051                      $highlight = "&amp;highlight=".urlencode($mybb->get_input('highlight'));
1052                  }
1053              }
1054  
1055              if($defaultmode != "linear")
1056              {
1057                  $threadmode = "&amp;mode=linear";
1058              }
1059          }
1060  
1061          $multipage = multipage($postcount, $perpage, $page, str_replace("{tid}", $tid, THREAD_URL_PAGED.$highlight.$threadmode));
1062          
1063          // Allow originator to see own unapproved posts
1064          if($mybb->user['uid'] && $mybb->settings['showownunapproved'])
1065          {
1066              $visible .= " OR (p.tid='$tid' AND p.visible='0' AND p.uid=".$mybb->user['uid'].")";
1067          }
1068  
1069          // Lets get the pids of the posts on this page.
1070          $pids = "";
1071          $comma = '';
1072          $query = $db->simple_select("posts p", "p.pid", "p.tid='$tid' $visible", array('order_by' => 'p.dateline', 'limit_start' => $start, 'limit' => $perpage));
1073          while($getid = $db->fetch_array($query))
1074          {
1075              // Set the ID of the first post on page to $pid if it doesn't hold any value
1076              // to allow this value to be used for Thread Mode/Linear Mode links
1077              // and ensure the user lands on the correct page after changing view mode
1078              if(empty($pid))
1079              {
1080                  $pid = $getid['pid'];
1081              }
1082              // Gather a comma separated list of post IDs
1083              $pids .= "$comma'{$getid['pid']}'";
1084              $comma = ",";
1085          }
1086          if($pids)
1087          {
1088              $pids = "pid IN($pids)";
1089  
1090              $attachcache = array();
1091              if($mybb->settings['enableattachments'] == 1 && $thread['attachmentcount'] > 0 || is_moderator($fid, 'caneditposts'))
1092              {
1093                  // Now lets fetch all of the attachments for these posts.
1094                  $query = $db->simple_select("attachments", "*", $pids);
1095                  while($attachment = $db->fetch_array($query))
1096                  {
1097                      $attachcache[$attachment['pid']][$attachment['aid']] = $attachment;
1098                  }
1099              }
1100          }
1101          else
1102          {
1103              // If there are no pid's the thread is probably awaiting approval.
1104              error($lang->error_invalidthread);
1105          }
1106  
1107          // Get the actual posts from the database here.
1108          $posts = '';
1109          $query = $db->query("
1110              SELECT u.*, u.username AS userusername, p.*, f.*, eu.username AS editusername
1111              FROM ".TABLE_PREFIX."posts p
1112              LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
1113              LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid)
1114              LEFT JOIN ".TABLE_PREFIX."users eu ON (eu.uid=p.edituid)
1115              WHERE $pids
1116              ORDER BY p.dateline
1117          ");
1118          while($post = $db->fetch_array($query))
1119          {
1120              if($thread['firstpost'] == $post['pid'] && $thread['visible'] == 0)
1121              {
1122                  $post['visible'] = 0;
1123              }
1124              $posts .= build_postbit($post);
1125              $post = '';
1126          }
1127          $plugins->run_hooks("showthread_linear");
1128      }
1129  
1130      // Show the similar threads table if wanted.
1131      $similarthreads = '';
1132      if($mybb->settings['showsimilarthreads'] != 0)
1133      {
1134          $own_perm = '';
1135          if($forumpermissions['canonlyviewownthreads'] == 1)
1136          {
1137              $own_perm = " AND t.uid={$mybb->user['uid']}";
1138          }
1139  
1140          switch($db->type)
1141          {
1142              case "pgsql":
1143                  $query = $db->query("
1144                      SELECT t.*, t.username AS threadusername, u.username
1145                      FROM ".TABLE_PREFIX."threads t
1146                      LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid), plainto_tsquery ('".$db->escape_string($thread['subject'])."') AS query
1147                      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}
1148                      ORDER BY t.lastpost DESC
1149                      OFFSET 0 LIMIT {$mybb->settings['similarlimit']}
1150                  ");
1151                  break;
1152              default:
1153                  $query = $db->query("
1154                      SELECT t.*, t.username AS threadusername, u.username, MATCH (t.subject) AGAINST ('".$db->escape_string($thread['subject'])."') AS relevance
1155                      FROM ".TABLE_PREFIX."threads t
1156                      LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid)
1157                      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']}'
1158                      ORDER BY t.lastpost DESC
1159                      LIMIT 0, {$mybb->settings['similarlimit']}
1160                  ");
1161          }
1162  
1163          $count = 0;
1164          $similarthreadbits = '';
1165          $icon_cache = $cache->read("posticons");
1166          while($similar_thread = $db->fetch_array($query))
1167          {
1168              ++$count;
1169              $trow = alt_trow();
1170              if($similar_thread['icon'] > 0 && $icon_cache[$similar_thread['icon']])
1171              {
1172                  $icon = $icon_cache[$similar_thread['icon']];
1173                  $icon['path'] = str_replace("{theme}", $theme['imgdir'], $icon['path']);
1174                  $icon['path'] = htmlspecialchars_uni($icon['path']);
1175                  $icon['name'] = htmlspecialchars_uni($icon['name']);
1176                  eval("\$icon = \"".$templates->get("forumdisplay_thread_icon")."\";");
1177              }
1178              else
1179              {
1180                  $icon = "&nbsp;";
1181              }
1182              if(!$similar_thread['username'])
1183              {
1184                  $similar_thread['username'] = $similar_thread['profilelink'] = htmlspecialchars_uni($similar_thread['threadusername']);
1185              }
1186              else
1187              {
1188                  $similar_thread['username'] = htmlspecialchars_uni($similar_thread['username']);
1189                  $similar_thread['profilelink'] = build_profile_link($similar_thread['username'], $similar_thread['uid']);
1190              }
1191  
1192              // If this thread has a prefix, insert a space between prefix and subject
1193              if($similar_thread['prefix'] != 0)
1194              {
1195                  $prefix = build_prefixes($similar_thread['prefix']);
1196                  if(!empty($prefix))
1197                  {
1198                      $similar_thread['threadprefix'] = $prefix['displaystyle'].'&nbsp;';
1199                  }
1200              }
1201  
1202              $similar_thread['subject'] = $parser->parse_badwords($similar_thread['subject']);
1203              $similar_thread['subject'] = htmlspecialchars_uni($similar_thread['subject']);
1204              $similar_thread['threadlink'] = get_thread_link($similar_thread['tid']);
1205              $similar_thread['lastpostlink'] = get_thread_link($similar_thread['tid'], 0, "lastpost");
1206  
1207              $lastpostdate = my_date('relative', $similar_thread['lastpost']);
1208              $lastposter = $similar_thread['lastposter'];
1209              $lastposteruid = $similar_thread['lastposteruid'];
1210  
1211              // Don't link to guest's profiles (they have no profile).
1212              if($lastposteruid == 0)
1213              {
1214                  $lastposterlink = $lastposter;
1215              }
1216              else
1217              {
1218                  $lastposterlink = build_profile_link($lastposter, $lastposteruid);
1219              }
1220              $similar_thread['replies'] = my_number_format($similar_thread['replies']);
1221              $similar_thread['views'] = my_number_format($similar_thread['views']);
1222              eval("\$similarthreadbits .= \"".$templates->get("showthread_similarthreads_bit")."\";");
1223          }
1224          if($count)
1225          {
1226              eval("\$similarthreads = \"".$templates->get("showthread_similarthreads")."\";");
1227          }
1228      }
1229  
1230      // Decide whether or not to show quick reply.
1231      $quickreply = '';
1232      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))
1233      {
1234          $query = $db->simple_select("posts", "pid", "tid='{$tid}'", array("order_by" => "pid", "order_dir" => "desc", "limit" => 1));
1235          $last_pid = $db->fetch_field($query, "pid");
1236  
1237          // Show captcha image for guests if enabled
1238          $captcha = '';
1239          if($mybb->settings['captchaimage'] && !$mybb->user['uid'])
1240          {
1241              require_once  MYBB_ROOT.'inc/class_captcha.php';
1242              $post_captcha = new captcha(true, "post_captcha");
1243  
1244              if($post_captcha->html)
1245              {
1246                  $captcha = $post_captcha->html;
1247              }
1248          }
1249  
1250          $postoptionschecked = array('signature' => '', 'emailnotify' => '');
1251          if($mybb->user['signature'])
1252          {
1253              $postoptionschecked['signature'] = 'checked="checked"';
1254          }
1255  
1256          // Hide signature option if no permission
1257          $option_signature = '';
1258          if($mybb->usergroup['canusesig'] && !$mybb->user['suspendsignature'])
1259          {
1260              eval("\$option_signature = \"".$templates->get('showthread_quickreply_options_signature')."\";");
1261          }
1262  
1263          if(isset($mybb->user['emailnotify']) && $mybb->user['emailnotify'] == 1)
1264          {
1265              $postoptionschecked['emailnotify'] = 'checked="checked"';
1266          }
1267  
1268          $trow = alt_trow();
1269          if($thread['closed'] == 1)
1270          {
1271              $trow = 'trow_shaded';
1272          }
1273  
1274          $moderation_notice = '';
1275          if(!is_moderator($forum['fid'], "canapproveunapproveposts"))
1276          {
1277              if($forumpermissions['modposts'] == 1)
1278              {
1279                  $moderation_text = $lang->moderation_forum_posts;
1280                  eval('$moderation_notice = "'.$templates->get('global_moderation_notice').'";');
1281              }
1282  
1283              if($mybb->user['moderateposts'] == 1)
1284              {
1285                  $moderation_text = $lang->moderation_user_posts;
1286                  eval('$moderation_notice = "'.$templates->get('global_moderation_notice').'";');
1287              }
1288          }
1289  
1290              $posthash = md5($mybb->user['uid'].random_str());
1291          $expaltext = (in_array("quickreply", $collapse)) ? "[+]" : "[-]";
1292          eval("\$quickreply = \"".$templates->get("showthread_quickreply")."\";");
1293      }
1294  
1295      $moderationoptions = '';
1296  
1297      // If the user is a moderator, show the moderation tools.
1298      if($ismod)
1299      {
1300          $customthreadtools = $customposttools = $standardthreadtools = $standardposttools = '';
1301  
1302          $threadnotesbox = $viewnotes = '';
1303          if(!empty($thread['notes']))
1304          {
1305              $thread['notes'] = nl2br(htmlspecialchars_uni($thread['notes']));
1306  
1307              if(strlen($thread['notes']) > 200)
1308              {
1309                  eval("\$viewnotes = \"".$templates->get("showthread_threadnotes_viewnotes")."\";");
1310                  $thread['notes'] = my_substr($thread['notes'], 0, 200)."... {$viewnotes}";
1311              }
1312  
1313              $expaltext = (in_array("threadnotes", $collapse)) ? "[+]" : "[-]";
1314              eval("\$threadnotesbox = \"".$templates->get("showthread_threadnotes")."\";");
1315          }
1316  
1317          if(is_moderator($forum['fid'], "canusecustomtools") && (!empty($forum_stats[-1]['modtools']) || !empty($forum_stats[$forum['fid']]['modtools'])))
1318          {
1319              $gids = explode(',', $mybb->user['additionalgroups']);
1320              $gids[] = $mybb->user['usergroup'];
1321              $gids = array_filter(array_unique($gids));
1322              switch($db->type)
1323              {
1324                  case "pgsql":
1325                  case "sqlite":
1326                      foreach($gids as $gid)
1327                      {
1328                          $gid = (int)$gid;
1329                          $gidswhere .= " OR ','||groups||',' LIKE '%,{$gid},%'";
1330                      }
1331                      $query = $db->simple_select("modtools", 'tid, name, type', "(','||forums||',' LIKE '%,$fid,%' OR ','||forums||',' LIKE '%,-1,%' OR forums='') AND (groups='' OR ','||groups||',' LIKE '%,-1,%'{$gidswhere})");
1332                      break;
1333                  default:
1334                      foreach($gids as $gid)
1335                      {
1336                          $gid = (int)$gid;
1337                          $gidswhere .= " OR CONCAT(',',`groups`,',') LIKE '%,{$gid},%'";
1338                      }
1339                      $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})");
1340                      break;
1341              }
1342  
1343              while($tool = $db->fetch_array($query))
1344              {
1345                  $tool['name'] = htmlspecialchars_uni($tool['name']);
1346                  if($tool['type'] == 'p')
1347                  {
1348                      eval("\$customposttools .= \"".$templates->get("showthread_inlinemoderation_custom_tool")."\";");
1349                  }
1350                  else
1351                  {
1352                      eval("\$customthreadtools .= \"".$templates->get("showthread_moderationoptions_custom_tool")."\";");
1353                  }
1354              }
1355  
1356              // Build inline moderation dropdown
1357              if(!empty($customposttools))
1358              {
1359                  eval("\$customposttools = \"".$templates->get("showthread_inlinemoderation_custom")."\";");
1360              }
1361          }
1362  
1363          $inlinemodsoftdelete = $inlinemodrestore = $inlinemoddelete = $inlinemodmanage = $inlinemodapprove = '';
1364  
1365          if(is_moderator($forum['fid'], "cansoftdeleteposts"))
1366          {
1367              eval("\$inlinemodsoftdelete = \"".$templates->get("showthread_inlinemoderation_softdelete")."\";");
1368          }
1369  
1370          if(is_moderator($forum['fid'], "canrestoreposts"))
1371          {
1372              eval("\$inlinemodrestore = \"".$templates->get("showthread_inlinemoderation_restore")."\";");
1373          }
1374  
1375          if(is_moderator($forum['fid'], "candeleteposts"))
1376          {
1377              eval("\$inlinemoddelete = \"".$templates->get("showthread_inlinemoderation_delete")."\";");
1378          }
1379  
1380          if(is_moderator($forum['fid'], "canmanagethreads"))
1381          {
1382              eval("\$inlinemodmanage = \"".$templates->get("showthread_inlinemoderation_manage")."\";");
1383          }
1384  
1385          if(is_moderator($forum['fid'], "canapproveunapproveposts"))
1386          {
1387              eval("\$inlinemodapprove = \"".$templates->get("showthread_inlinemoderation_approve")."\";");
1388          }
1389  
1390          if(!empty($inlinemodsoftdelete) || !empty($inlinemodrestore) || !empty($inlinemoddelete) || !empty($inlinemodmanage) || !empty($inlinemodapprove))
1391          {
1392              eval("\$standardposttools = \"".$templates->get("showthread_inlinemoderation_standard")."\";");
1393          }
1394  
1395          // Only show inline mod menu if there's options to show
1396          if(!empty($standardposttools) || !empty($customposttools))
1397          {
1398              eval("\$inlinemod = \"".$templates->get("showthread_inlinemoderation")."\";");
1399          }
1400  
1401          // Build thread moderation dropdown
1402          if(!empty($customthreadtools))
1403          {
1404              eval("\$customthreadtools = \"".$templates->get("showthread_moderationoptions_custom")."\";");
1405          }
1406  
1407          $openclosethread = $stickunstickthread = $deletethread = $threadnotes = $managethread = $adminpolloptions = $approveunapprovethread = $softdeletethread = '';
1408  
1409          if(is_moderator($forum['fid'], "canopenclosethreads"))
1410          {
1411              eval("\$openclosethread = \"".$templates->get("showthread_moderationoptions_openclose")."\";");
1412          }
1413  
1414          if(is_moderator($forum['fid'], "canstickunstickthreads"))
1415          {
1416              eval("\$stickunstickthread = \"".$templates->get("showthread_moderationoptions_stickunstick")."\";");
1417          }
1418  
1419          if(is_moderator($forum['fid'], "candeletethreads"))
1420          {
1421              eval("\$deletethread = \"".$templates->get("showthread_moderationoptions_delete")."\";");
1422          }
1423  
1424          if(is_moderator($forum['fid'], "canmanagethreads"))
1425          {
1426              eval("\$threadnotes = \"".$templates->get("showthread_moderationoptions_threadnotes")."\";");
1427              eval("\$managethread = \"".$templates->get("showthread_moderationoptions_manage")."\";");
1428          }
1429  
1430          if($pollbox && is_moderator($forum['fid'], "canmanagepolls"))
1431          {
1432              eval("\$adminpolloptions = \"".$templates->get("showthread_moderationoptions_deletepoll")."\";");
1433          }
1434  
1435          if(is_moderator($forum['fid'], "canapproveunapprovethreads"))
1436          {
1437              if($thread['visible'] == 0)
1438              {
1439                  eval("\$approveunapprovethread = \"".$templates->get("showthread_moderationoptions_approve")."\";");
1440              }
1441              else
1442              {
1443                  eval("\$approveunapprovethread = \"".$templates->get("showthread_moderationoptions_unapprove")."\";");
1444              }
1445          }
1446  
1447          if(is_moderator($forum['fid'], "cansoftdeletethreads") && $thread['visible'] != -1)
1448          {
1449              eval("\$softdeletethread = \"".$templates->get("showthread_moderationoptions_softdelete")."\";");
1450          }
1451          elseif(is_moderator($forum['fid'], "canrestorethreads") && $thread['visible'] == -1)
1452          {
1453              eval("\$softdeletethread = \"".$templates->get("showthread_moderationoptions_restore")."\";");
1454          }
1455  
1456          if(!empty($openclosethread) || !empty($stickunstickthread) || !empty($deletethread) || !empty($managethread) || !empty($adminpolloptions) || !empty($approveunapprovethread) || !empty($softdeletethread))
1457          {
1458              eval("\$standardthreadtools = \"".$templates->get("showthread_moderationoptions_standard")."\";");
1459          }
1460  
1461          // Only show mod menu if there's any options to show
1462          if(!empty($standardthreadtools) || !empty($customthreadtools))
1463          {
1464              eval("\$moderationoptions = \"".$templates->get("showthread_moderationoptions")."\";");
1465          }
1466      }
1467  
1468      eval("\$printthread = \"".$templates->get("showthread_printthread")."\";");
1469  
1470      // Display 'send thread' link if permissions allow
1471      $sendthread = '';
1472      if($mybb->usergroup['cansendemail'] == 1)
1473      {
1474          eval("\$sendthread = \"".$templates->get("showthread_send_thread")."\";");
1475      }
1476  
1477      // Display 'add poll' link to thread creator (or mods) if thread doesn't have a poll already
1478      $addpoll = '';
1479      $time = TIME_NOW;
1480      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))
1481      {
1482          eval("\$addpoll = \"".$templates->get("showthread_add_poll")."\";");
1483      }
1484  
1485      // Subscription status
1486      $add_remove_subscription = 'add';
1487      $add_remove_subscription_text = $lang->subscribe_thread;
1488  
1489      if($mybb->user['uid'])
1490      {
1491          $query = $db->simple_select("threadsubscriptions", "tid", "tid='".(int)$tid."' AND uid='".(int)$mybb->user['uid']."'", array('limit' => 1));
1492  
1493          if($db->fetch_field($query, 'tid'))
1494          {
1495              $add_remove_subscription = 'remove';
1496              $add_remove_subscription_text = $lang->unsubscribe_thread;
1497          }
1498  
1499          eval("\$addremovesubscription = \"".$templates->get("showthread_subscription")."\";");
1500      }
1501  
1502      $classic_header = '';
1503      if($mybb->settings['postlayout'] == "classic")
1504      {
1505          eval("\$classic_header = \"".$templates->get("showthread_classic_header")."\";");
1506      }
1507  
1508      // Get users viewing this thread
1509      if($mybb->settings['browsingthisthread'] != 0)
1510      {
1511          $timecut = TIME_NOW - $mybb->settings['wolcutoff'];
1512  
1513          $comma = '';
1514          $guestcount = 0;
1515          $membercount = 0;
1516          $inviscount = 0;
1517          $onlinemembers = '';
1518          $doneusers = array();
1519  
1520          $query = $db->query("
1521              SELECT s.ip, s.uid, s.time, u.username, u.invisible, u.usergroup, u.displaygroup
1522              FROM ".TABLE_PREFIX."sessions s
1523              LEFT JOIN ".TABLE_PREFIX."users u ON (s.uid=u.uid)
1524              WHERE s.time > '$timecut' AND location2='$tid' AND nopermission != 1
1525              ORDER BY u.username ASC, s.time DESC
1526          ");
1527  
1528          while($user = $db->fetch_array($query))
1529          {
1530              if($user['uid'] == 0)
1531              {
1532                  ++$guestcount;
1533              }
1534              else if(empty($doneusers[$user['uid']]) || $doneusers[$user['uid']] < $user['time'])
1535              {
1536                  ++$membercount;
1537                  $doneusers[$user['uid']] = $user['time'];
1538  
1539                  $invisiblemark = '';
1540                  if($user['invisible'] == 1)
1541                  {
1542                      $invisiblemark = "*";
1543                      ++$inviscount;
1544                  }
1545  
1546                  if($user['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1 || $user['uid'] == $mybb->user['uid'])
1547                  {
1548                      $user['profilelink'] = get_profile_link($user['uid']);
1549                      $user['username'] = format_name(htmlspecialchars_uni($user['username']), $user['usergroup'], $user['displaygroup']);
1550                      $user['reading'] = my_date($mybb->settings['timeformat'], $user['time']);
1551  
1552                      eval("\$onlinemembers .= \"".$templates->get("showthread_usersbrowsing_user", 1, 0)."\";");
1553                      $comma = $lang->comma;
1554                  }
1555              }
1556          }
1557  
1558          $guestsonline = '';
1559          if($guestcount)
1560          {
1561              $guestsonline = $lang->sprintf($lang->users_browsing_thread_guests, $guestcount);
1562          }
1563  
1564          $invisonline = '';
1565          if($mybb->user['invisible'] == 1)
1566          {
1567              // the user was counted as invisible user --> correct the inviscount
1568              $inviscount -= 1;
1569          }
1570          if($inviscount && $mybb->usergroup['canviewwolinvis'] != 1)
1571          {
1572              $invisonline = $lang->sprintf($lang->users_browsing_forum_invis, $inviscount);
1573          }
1574  
1575          $onlinesep = '';
1576          if($invisonline != '' && $onlinemembers)
1577          {
1578              $onlinesep = $lang->comma;
1579          }
1580  
1581          $onlinesep2 = '';
1582          if($invisonline != '' && $guestcount || $onlinemembers && $guestcount)
1583          {
1584              $onlinesep2 = $lang->comma;
1585          }
1586  
1587          eval("\$usersbrowsing = \"".$templates->get("showthread_usersbrowsing")."\";");
1588      }
1589  
1590      if($thread['visible'] == -1 )
1591      {
1592          $thread_deleted = 1;
1593      }
1594  
1595      $plugins->run_hooks("showthread_end");
1596  
1597      eval("\$showthread = \"".$templates->get("showthread")."\";");
1598      output_page($showthread);
1599  }
1600  
1601  /**
1602   * Build a navigation tree for threaded display.
1603   *
1604   * @param int $replyto
1605   * @param int $indent
1606   * @return string
1607   */
1608  function buildtree($replyto=0, $indent=0)
1609  {
1610      global $tree, $mybb, $theme, $mybb, $pid, $tid, $templates, $parser, $lang;
1611  
1612      $indentsize = 13 * $indent;
1613  
1614      ++$indent;
1615      $posts = '';
1616      if(is_array($tree[$replyto]))
1617      {
1618          foreach($tree[$replyto] as $key => $post)
1619          {
1620              $postdate = my_date('relative', $post['dateline']);
1621              $post['subject'] = htmlspecialchars_uni($parser->parse_badwords($post['subject']));
1622  
1623              if(!$post['subject'])
1624              {
1625                  $post['subject'] = "[".$lang->no_subject."]";
1626              }
1627  
1628              $post['username'] = htmlspecialchars_uni($post['username']);
1629              $post['profilelink'] = build_profile_link($post['username'], $post['uid']);
1630  
1631              if($mybb->input['pid'] == $post['pid'])
1632              {
1633                  eval("\$posts .= \"".$templates->get("showthread_threaded_bitactive")."\";");
1634              }
1635              else
1636              {
1637                  eval("\$posts .= \"".$templates->get("showthread_threaded_bit")."\";");
1638              }
1639  
1640              if($tree[$post['pid']])
1641              {
1642                  $posts .= buildtree($post['pid'], $indent);
1643              }
1644          }
1645          --$indent;
1646      }
1647      return $posts;
1648  }


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