[ Index ] |
PHP Cross Reference of MyBB 1.8.39 |
[Summary view] [Print] [Text view]
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']).' '; 91 $thread['displayprefix'] = $threadprefix['displaystyle'].' '; 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 $threadcount = 0; 391 if($mybb->settings['showforumpagesbreadcrumb']) 392 { 393 // How many pages are there? 394 if(!$mybb->settings['threadsperpage'] || (int)$mybb->settings['threadsperpage'] < 1) 395 { 396 $mybb->settings['threadsperpage'] = 20; 397 } 398 399 $query = $db->simple_select("forums", "threads, unapprovedthreads, deletedthreads", "fid = '{$fid}'", array('limit' => 1)); 400 $forum_threads = $db->fetch_array($query); 401 $threadcount = $forum_threads['threads']; 402 403 404 if(is_moderator($fid, "canviewdeleted") == true || is_moderator($fid, "canviewunapprove") == true) 405 { 406 if(is_moderator($fid, "canviewdeleted") == true) 407 { 408 $threadcount += $forum_threads['deletedthreads']; 409 } 410 if(is_moderator($fid, "canviewunapprove") == true) 411 { 412 $threadcount += $forum_threads['unapprovedthreads']; 413 } 414 } 415 elseif($forumpermissions['canviewdeletionnotice'] != 0) 416 { 417 $threadcount += $forum_threads['deletedthreads']; 418 } 419 420 // Limit to only our own threads 421 $uid_only = ''; 422 if(isset($forumpermissions['canonlyviewownthreads']) && $forumpermissions['canonlyviewownthreads'] == 1) 423 { 424 $uid_only = " AND uid = '".$mybb->user['uid']."'"; 425 426 $query = $db->simple_select("threads", "COUNT(tid) AS threads", "fid = '$fid' $visibleonly $uid_only", array('limit' => 1)); 427 $threadcount = $db->fetch_field($query, "threads"); 428 } 429 430 // If we have 0 threads double check there aren't any "moved" threads 431 if($threadcount == 0) 432 { 433 $query = $db->simple_select("threads", "COUNT(tid) AS threads", "fid = '$fid' $visibleonly $uid_only", array('limit' => 1)); 434 $threadcount = $db->fetch_field($query, "threads"); 435 } 436 437 $stickybit = " OR sticky=1"; 438 if($thread['sticky'] == 1) 439 { 440 $stickybit = " AND sticky=1"; 441 } 442 443 // Figure out what page the thread is actually on 444 switch($db->type) 445 { 446 case "pgsql": 447 $query = $db->query(" 448 SELECT COUNT(tid) as threads 449 FROM ".TABLE_PREFIX."threads 450 WHERE fid = '$fid' AND (lastpost >= '".(int)$thread['lastpost']."'{$stickybit}) {$visibleonly} {$uid_only} 451 GROUP BY lastpost 452 ORDER BY lastpost DESC 453 "); 454 break; 455 default: 456 $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')); 457 } 458 459 $thread_position = $db->fetch_field($query, "threads"); 460 $thread_page = ceil(($thread_position/$mybb->settings['threadsperpage'])); 461 462 $breadcrumb_multipage = array( 463 "num_threads" => $threadcount, 464 "current_page" => $thread_page 465 ); 466 } 467 468 // Build the navigation. 469 build_forum_breadcrumb($fid, $breadcrumb_multipage); 470 add_breadcrumb($thread['displayprefix'].$thread['subject'], get_thread_link($thread['tid'])); 471 472 $plugins->run_hooks("showthread_start"); 473 474 // Show the entire thread (taking into account pagination). 475 if($mybb->input['action'] == "thread") 476 { 477 // This is a workaround to fix threads which data may get "corrupted" due to lag or other still unknown reasons 478 if($thread['firstpost'] == 0 || $thread['dateline'] == 0) 479 { 480 update_first_post($tid); 481 } 482 483 // Does this thread have a poll? 484 if($thread['poll']) 485 { 486 $options = array( 487 "limit" => 1 488 ); 489 $query = $db->simple_select("polls", "*", "pid='".$thread['poll']."'", $options); 490 $poll = $db->fetch_array($query); 491 $poll['timeout'] = $poll['timeout']*60*60*24; 492 $expiretime = $poll['dateline'] + $poll['timeout']; 493 $now = TIME_NOW; 494 495 // If the poll or the thread is closed or if the poll is expired, show the results. 496 if($poll['closed'] == 1 || $thread['closed'] == 1 || ($expiretime < $now && $poll['timeout'] > 0) || $forumpermissions['canvotepolls'] != 1) 497 { 498 $showresults = 1; 499 } 500 501 if($forumpermissions['canvotepolls'] != 1) 502 { 503 $nopermission = 1; 504 } 505 506 // Check if the user has voted before... 507 if($mybb->user['uid']) 508 { 509 $user_check = "uid='{$mybb->user['uid']}'"; 510 } 511 else 512 { 513 $user_check = "uid='0' AND ipaddress=".$db->escape_binary($session->packedip); 514 } 515 516 $query = $db->simple_select("pollvotes", "*", "{$user_check} AND pid='".$poll['pid']."'"); 517 while($votecheck = $db->fetch_array($query)) 518 { 519 $alreadyvoted = 1; 520 $votedfor[$votecheck['voteoption']] = 1; 521 } 522 523 $optionsarray = explode("||~|~||", $poll['options']); 524 $votesarray = explode("||~|~||", $poll['votes']); 525 $poll['question'] = htmlspecialchars_uni($poll['question']); 526 $polloptions = ''; 527 $totalvotes = 0; 528 $poll['totvotes'] = 0; 529 530 for($i = 1; $i <= $poll['numoptions']; ++$i) 531 { 532 $poll['totvotes'] = $poll['totvotes'] + $votesarray[$i-1]; 533 } 534 535 // Loop through the poll options. 536 for($i = 1; $i <= $poll['numoptions']; ++$i) 537 { 538 // Set up the parser options. 539 $parser_options = array( 540 "allow_html" => $forum['allowhtml'], 541 "allow_mycode" => $forum['allowmycode'], 542 "allow_smilies" => $forum['allowsmilies'], 543 "allow_imgcode" => $forum['allowimgcode'], 544 "allow_videocode" => $forum['allowvideocode'], 545 "filter_badwords" => 1 546 ); 547 548 if($mybb->user['uid'] != 0 && $mybb->user['showimages'] != 1 || $mybb->settings['guestimages'] != 1 && $mybb->user['uid'] == 0) 549 { 550 $parser_options['allow_imgcode'] = 0; 551 } 552 553 if($mybb->user['uid'] != 0 && $mybb->user['showvideos'] != 1 || $mybb->settings['guestvideos'] != 1 && $mybb->user['uid'] == 0) 554 { 555 $parser_options['allow_videocode'] = 0; 556 } 557 558 $option = $parser->parse_message($optionsarray[$i-1], $parser_options); 559 $votes = $votesarray[$i-1]; 560 $totalvotes += $votes; 561 $number = $i; 562 563 // Mark the option the user voted for. 564 if(!empty($votedfor[$number])) 565 { 566 $optionbg = "trow2 poll_votedfor"; 567 $votestar = "*"; 568 } 569 else 570 { 571 $optionbg = "trow1"; 572 $votestar = ""; 573 } 574 575 // If the user already voted or if the results need to be shown, do so; else show voting screen. 576 if(isset($alreadyvoted) || isset($showresults)) 577 { 578 if((int)$votes == "0") 579 { 580 $percent = "0"; 581 } 582 else 583 { 584 $percent = number_format($votes / $poll['totvotes'] * 100, 2); 585 } 586 $imagewidth = round($percent); 587 eval("\$polloptions .= \"".$templates->get("showthread_poll_resultbit")."\";"); 588 } 589 else 590 { 591 if($poll['multiple'] == 1) 592 { 593 eval("\$polloptions .= \"".$templates->get("showthread_poll_option_multiple")."\";"); 594 } 595 else 596 { 597 eval("\$polloptions .= \"".$templates->get("showthread_poll_option")."\";"); 598 } 599 } 600 } 601 602 // If there are any votes at all, all votes together will be 100%; if there are no votes, all votes together will be 0%. 603 if($poll['totvotes']) 604 { 605 $totpercent = "100%"; 606 } 607 else 608 { 609 $totpercent = "0%"; 610 } 611 612 // Check if user is allowed to edit posts; if so, show "edit poll" link. 613 $edit_poll = ''; 614 if(is_moderator($fid, 'canmanagepolls')) 615 { 616 eval("\$edit_poll = \"".$templates->get("showthread_poll_editpoll")."\";"); 617 } 618 619 // Decide what poll status to show depending on the status of the poll and whether or not the user voted already. 620 if(isset($alreadyvoted) || isset($showresults) || isset($nopermission)) 621 { 622 $undovote = ''; 623 624 if(isset($alreadyvoted)) 625 { 626 $pollstatus = $lang->already_voted; 627 628 if($mybb->usergroup['canundovotes'] == 1) 629 { 630 eval("\$undovote = \"".$templates->get("showthread_poll_undovote")."\";"); 631 } 632 } 633 elseif(isset($nopermission)) 634 { 635 $pollstatus = $lang->no_voting_permission; 636 } 637 else 638 { 639 $pollstatus = $lang->poll_closed; 640 } 641 642 $lang->total_votes = $lang->sprintf($lang->total_votes, $totalvotes); 643 eval("\$pollbox = \"".$templates->get("showthread_poll_results")."\";"); 644 $plugins->run_hooks("showthread_poll_results"); 645 } 646 else 647 { 648 $closeon = ' '; 649 if($poll['timeout'] != 0) 650 { 651 $closeon = $lang->sprintf($lang->poll_closes, my_date($mybb->settings['dateformat'], $expiretime)); 652 } 653 654 $publicnote = ' '; 655 if($poll['public'] == 1) 656 { 657 $publicnote = $lang->public_note; 658 } 659 660 eval("\$pollbox = \"".$templates->get("showthread_poll")."\";"); 661 $plugins->run_hooks("showthread_poll"); 662 } 663 664 } 665 else 666 { 667 $pollbox = ""; 668 } 669 670 // Create the forum jump dropdown box. 671 $forumjump = ''; 672 if($mybb->settings['enableforumjump'] != 0) 673 { 674 $forumjump = build_forum_jump("", $fid, 1); 675 } 676 677 // Fetch some links 678 $next_oldest_link = get_thread_link($tid, 0, "nextoldest"); 679 $next_newest_link = get_thread_link($tid, 0, "nextnewest"); 680 681 // Mark this thread as read 682 mark_thread_read($tid, $fid); 683 684 // If the forum is not open, show closed newreply button unless the user is a moderator of this forum. 685 $newthread = $newreply = ''; 686 if($forum['open'] != 0 && $forum['type'] == "f") 687 { 688 if($forumpermissions['canpostthreads'] != 0 && $mybb->user['suspendposting'] != 1) 689 { 690 eval("\$newthread = \"".$templates->get("showthread_newthread")."\";"); 691 } 692 693 // Show the appropriate reply button if this thread is open or closed 694 if($forumpermissions['canpostreplys'] != 0 && $mybb->user['suspendposting'] != 1 && ($thread['closed'] != 1 || is_moderator($fid, "canpostclosedthreads")) && ($thread['uid'] == $mybb->user['uid'] || empty($forumpermissions['canonlyreplyownthreads']))) 695 { 696 eval("\$newreply = \"".$templates->get("showthread_newreply")."\";"); 697 } 698 elseif($thread['closed'] == 1) 699 { 700 eval("\$newreply = \"".$templates->get("showthread_newreply_closed")."\";"); 701 } 702 } 703 704 // Create the admin tools dropdown box. 705 if($ismod == true) 706 { 707 $closeoption = $closelinkch = $stickch = ''; 708 709 if($thread['closed'] == 1) 710 { 711 $closelinkch = ' checked="checked"'; 712 } 713 714 if($thread['sticky']) 715 { 716 $stickch = ' checked="checked"'; 717 } 718 719 if(is_moderator($thread['fid'], "canopenclosethreads")) 720 { 721 eval("\$closeoption .= \"".$templates->get("showthread_quickreply_options_close")."\";"); 722 } 723 724 if(is_moderator($thread['fid'], "canstickunstickthreads")) 725 { 726 eval("\$closeoption .= \"".$templates->get("showthread_quickreply_options_stick")."\";"); 727 } 728 729 $inlinecount = "0"; 730 $inlinecookie = "inlinemod_thread".$tid; 731 732 $plugins->run_hooks("showthread_ismod"); 733 } 734 else 735 { 736 $modoptions = " "; 737 $inlinemod = $closeoption = ''; 738 } 739 740 // Increment the thread view. 741 if( 742 ( 743 $mybb->user['uid'] == 0 && 744 ( 745 ($session->is_spider == true && $mybb->settings['threadviews_countspiders'] == 1) || 746 ($session->is_spider == false && $mybb->settings['threadviews_countguests'] == 1) 747 ) 748 ) || 749 ( 750 $mybb->user['uid'] != 0 && 751 ($mybb->settings['threadviews_countthreadauthor'] == 1 || $mybb->user['uid'] != $thread['uid']) 752 ) 753 ) 754 { 755 if($mybb->settings['delayedthreadviews'] == 1) 756 { 757 $db->shutdown_query("INSERT INTO ".TABLE_PREFIX."threadviews (tid) VALUES('{$tid}')"); 758 } 759 else 760 { 761 $db->shutdown_query("UPDATE ".TABLE_PREFIX."threads SET views=views+1 WHERE tid='{$tid}'"); 762 } 763 ++$thread['views']; 764 } 765 766 // Work out the thread rating for this thread. 767 $rating = $ratethread = ''; 768 if($mybb->settings['allowthreadratings'] != 0 && $forum['allowtratings'] != 0) 769 { 770 $rated = 0; 771 $lang->load("ratethread"); 772 if($thread['numratings'] <= 0) 773 { 774 $thread['width'] = 0; 775 $thread['averagerating'] = 0; 776 $thread['numratings'] = 0; 777 } 778 else 779 { 780 $thread['averagerating'] = (float)round($thread['totalratings']/$thread['numratings'], 2); 781 $thread['width'] = (int)round($thread['averagerating'])*20; 782 $thread['numratings'] = (int)$thread['numratings']; 783 } 784 785 if($thread['numratings']) 786 { 787 // At least >someone< has rated this thread, was it me? 788 // Check if we have already voted on this thread - it won't show hover effect then. 789 $query = $db->simple_select("threadratings", "uid", "tid='{$tid}' AND uid='{$mybb->user['uid']}'"); 790 $rated = $db->fetch_field($query, 'uid'); 791 } 792 793 $not_rated = ''; 794 if(!$rated) 795 { 796 $not_rated = ' star_rating_notrated'; 797 } 798 799 $ratingvotesav = $lang->sprintf($lang->rating_average, $thread['numratings'], $thread['averagerating']); 800 eval("\$ratethread = \"".$templates->get("showthread_ratethread")."\";"); 801 } 802 803 // Can this user perform searches? If so, we can show them the "Search thread" form 804 $search_thread=''; 805 if($forumpermissions['cansearch'] != 0) 806 { 807 eval("\$search_thread = \"".$templates->get("showthread_search")."\";"); 808 } 809 810 // Fetch the ignore list for the current user if they have one 811 $ignored_users = array(); 812 if($mybb->user['uid'] > 0 && $mybb->user['ignorelist'] != "") 813 { 814 $ignore_list = explode(',', $mybb->user['ignorelist']); 815 foreach($ignore_list as $uid) 816 { 817 $ignored_users[$uid] = 1; 818 } 819 } 820 821 // Which thread mode is our user using by default? 822 if(!empty($mybb->user['threadmode'])) 823 { 824 $defaultmode = $mybb->user['threadmode']; 825 } 826 else if($mybb->settings['threadusenetstyle'] == 1) 827 { 828 $defaultmode = 'threaded'; 829 } 830 else 831 { 832 $defaultmode = 'linear'; 833 } 834 835 // If mode is unset, set the default mode 836 if(!isset($mybb->input['mode'])) 837 { 838 $mybb->input['mode'] = $defaultmode; 839 } 840 841 // Threaded or linear display? 842 $threadexbox = ''; 843 if($mybb->get_input('mode') == 'threaded') 844 { 845 $thread_toggle = 'linear'; 846 $isfirst = 1; 847 848 // Are we linked to a specific pid? 849 if($mybb->input['pid']) 850 { 851 $where = "AND p.pid='".$mybb->input['pid']."'"; 852 } 853 else 854 { 855 $where = " ORDER BY dateline, pid LIMIT 0, 1"; 856 } 857 $query = $db->query(" 858 SELECT u.*, u.username AS userusername, p.*, f.*, r.reporters, eu.username AS editusername 859 FROM ".TABLE_PREFIX."posts p 860 LEFT JOIN ".TABLE_PREFIX."reportedcontent r ON (r.id=p.pid AND r.type='post' AND r.reportstatus != 1) 861 LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid) 862 LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid) 863 LEFT JOIN ".TABLE_PREFIX."users eu ON (eu.uid=p.edituid) 864 WHERE p.tid='$tid' $visibleonly_p $where 865 "); 866 $showpost = $db->fetch_array($query); 867 868 // Is there actually a pid to display? 869 if(!$showpost) 870 { 871 error($lang->error_invalidpost); 872 } 873 874 // Choose what pid to display. 875 if(!$mybb->input['pid']) 876 { 877 $mybb->input['pid'] = $showpost['pid']; 878 } 879 880 $attachcache = array(); 881 if($mybb->settings['enableattachments'] == 1 && $thread['attachmentcount'] > 0 || is_moderator($fid, 'caneditposts')) 882 { 883 // Get the attachments for this post. 884 $query = $db->simple_select("attachments", "*", "pid=".$mybb->input['pid']); 885 while($attachment = $db->fetch_array($query)) 886 { 887 $attachcache[$attachment['pid']][$attachment['aid']] = $attachment; 888 } 889 } 890 891 $multipage = ''; 892 893 // Build the threaded post display tree. 894 $query = $db->query(" 895 SELECT p.username, p.uid, p.pid, p.replyto, p.subject, p.dateline 896 FROM ".TABLE_PREFIX."posts p 897 WHERE p.tid='$tid' 898 $visibleonly_p 899 ORDER BY p.dateline, p.pid 900 "); 901 $postsdone = array(); 902 while($post = $db->fetch_array($query)) 903 { 904 if(empty($postsdone[$post['pid']])) 905 { 906 if($post['pid'] == $mybb->input['pid'] || ($isfirst && !$mybb->input['pid'])) 907 { 908 $postcounter = count($postsdone); 909 $isfirst = 0; 910 } 911 $tree[$post['replyto']][$post['pid']] = $post; 912 $postsdone[$post['pid']] = 1; 913 } 914 } 915 916 $threadedbits = buildtree(); 917 $posts = build_postbit($showpost); 918 eval("\$threadexbox = \"".$templates->get("showthread_threadedbox")."\";"); 919 $plugins->run_hooks("showthread_threaded"); 920 } 921 else // Linear display 922 { 923 $thread_toggle = 'threaded'; 924 $threadexbox = ''; 925 if(!$mybb->settings['postsperpage'] || (int)$mybb->settings['postsperpage'] < 1) 926 { 927 $mybb->settings['postsperpage'] = 20; 928 } 929 930 // Figure out if we need to display multiple pages. 931 $page = 1; 932 $perpage = $mybb->settings['postsperpage']; 933 if($mybb->get_input('page', MyBB::INPUT_INT) && $mybb->get_input('page') != "last") 934 { 935 $page = $mybb->get_input('page', MyBB::INPUT_INT); 936 } 937 938 if(!empty($mybb->input['pid'])) 939 { 940 $post = get_post($mybb->input['pid']); 941 if( 942 empty($post) || 943 ( 944 $post['visible'] == 0 && !( 945 is_moderator($post['fid'], 'canviewunapprove') || 946 ($mybb->user['uid'] && $post['uid'] == $mybb->user['uid'] && $mybb->settings['showownunapproved']) 947 ) 948 ) || 949 ($post['visible'] == -1 && !is_moderator($post['fid'], 'canviewdeleted') && $forumpermissions['canviewdeletionnotice'] == 0) 950 ) 951 { 952 $footer .= '<script type="text/javascript">$(function() { $.jGrowl(\''.$lang->error_invalidpost.'\', {theme: \'jgrowl_error\'}); });</script>'; 953 } 954 else 955 { 956 $query = $db->query(" 957 SELECT COUNT(p.dateline) AS count FROM ".TABLE_PREFIX."posts p 958 WHERE p.tid = '{$tid}' 959 AND p.dateline <= '{$post['dateline']}' 960 {$visibleonly_p} 961 "); 962 $result = $db->fetch_field($query, "count"); 963 if(($result % $perpage) == 0) 964 { 965 $page = $result / $perpage; 966 } 967 else 968 { 969 $page = (int)($result / $perpage) + 1; 970 } 971 } 972 } 973 974 // Recount replies if user is a moderator or can see the deletion notice to take into account unapproved/deleted posts. 975 if($visible_states != array("1")) 976 { 977 $cached_replies = $thread['replies']+$thread['unapprovedposts']+$thread['deletedposts']; 978 979 $query = $db->simple_select("posts p", "COUNT(*) AS replies", "p.tid='$tid' $visibleonly_p"); 980 $thread['replies'] = $db->fetch_field($query, 'replies')-1; 981 982 if(in_array('-1', $visible_states) && in_array('0', $visible_states)) 983 { 984 // The counters are wrong? Rebuild them 985 // This doesn't cover all cases however it is a good addition to the manual rebuild function 986 if($thread['replies'] != $cached_replies) 987 { 988 require_once MYBB_ROOT."/inc/functions_rebuild.php"; 989 rebuild_thread_counters($thread['tid']); 990 } 991 } 992 } 993 994 $postcount = (int)$thread['replies']+1; 995 $pages = $postcount / $perpage; 996 $pages = ceil($pages); 997 998 if($mybb->get_input('page') == "last") 999 { 1000 $page = $pages; 1001 } 1002 1003 if($page > $pages || $page <= 0) 1004 { 1005 $page = 1; 1006 } 1007 1008 if($page) 1009 { 1010 $start = ($page-1) * $perpage; 1011 } 1012 else 1013 { 1014 $start = 0; 1015 $page = 1; 1016 } 1017 $upper = $start+$perpage; 1018 1019 // Work out if we have terms to highlight 1020 $highlight = ""; 1021 $threadmode = ""; 1022 if($mybb->seo_support == true) 1023 { 1024 if($mybb->get_input('highlight')) 1025 { 1026 $highlight = "?highlight=".urlencode($mybb->get_input('highlight')); 1027 } 1028 1029 if($defaultmode != "linear") 1030 { 1031 if($mybb->get_input('highlight')) 1032 { 1033 $threadmode = "&mode=linear"; 1034 } 1035 else 1036 { 1037 $threadmode = "?mode=linear"; 1038 } 1039 } 1040 } 1041 else 1042 { 1043 if(!empty($mybb->input['highlight'])) 1044 { 1045 if(is_array($mybb->input['highlight'])) 1046 { 1047 foreach($mybb->input['highlight'] as $highlight_word) 1048 { 1049 $highlight .= "&highlight[]=".urlencode($highlight_word); 1050 } 1051 } 1052 else 1053 { 1054 $highlight = "&highlight=".urlencode($mybb->get_input('highlight')); 1055 } 1056 } 1057 1058 if($defaultmode != "linear") 1059 { 1060 $threadmode = "&mode=linear"; 1061 } 1062 } 1063 1064 $multipage = multipage($postcount, $perpage, $page, str_replace("{tid}", $tid, THREAD_URL_PAGED.$highlight.$threadmode)); 1065 1066 // Lets get the pids of the posts on this page. 1067 $pids = ""; 1068 $comma = ''; 1069 $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)); 1070 while($getid = $db->fetch_array($query)) 1071 { 1072 // Set the ID of the first post on page to $pid if it doesn't hold any value 1073 // to allow this value to be used for Thread Mode/Linear Mode links 1074 // and ensure the user lands on the correct page after changing view mode 1075 if(empty($pid)) 1076 { 1077 $pid = $getid['pid']; 1078 } 1079 // Gather a comma separated list of post IDs 1080 $pids .= "$comma'{$getid['pid']}'"; 1081 $comma = ","; 1082 } 1083 if($pids) 1084 { 1085 $pids = "pid IN($pids)"; 1086 1087 $attachcache = array(); 1088 if($mybb->settings['enableattachments'] == 1 && $thread['attachmentcount'] > 0 || is_moderator($fid, 'caneditposts')) 1089 { 1090 // Now lets fetch all of the attachments for these posts. 1091 $query = $db->simple_select("attachments", "*", $pids); 1092 while($attachment = $db->fetch_array($query)) 1093 { 1094 $attachcache[$attachment['pid']][$attachment['aid']] = $attachment; 1095 } 1096 } 1097 } 1098 else 1099 { 1100 // If there are no pid's the thread is probably awaiting approval. 1101 error($lang->error_invalidthread); 1102 } 1103 1104 // Get the actual posts from the database here. 1105 $posts = ''; 1106 $query = $db->query(" 1107 SELECT u.*, u.username AS userusername, p.*, f.*, r.reporters, eu.username AS editusername 1108 FROM ".TABLE_PREFIX."posts p 1109 LEFT JOIN ".TABLE_PREFIX."reportedcontent r ON (r.id=p.pid AND r.type='post' AND r.reportstatus != 1) 1110 LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid) 1111 LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid) 1112 LEFT JOIN ".TABLE_PREFIX."users eu ON (eu.uid=p.edituid) 1113 WHERE $pids 1114 ORDER BY p.dateline, p.pid 1115 "); 1116 while($post = $db->fetch_array($query)) 1117 { 1118 if($thread['firstpost'] == $post['pid'] && $thread['visible'] == 0) 1119 { 1120 $post['visible'] = 0; 1121 } 1122 $posts .= build_postbit($post); 1123 $post = ''; 1124 } 1125 $plugins->run_hooks("showthread_linear"); 1126 } 1127 $lang->thread_toggle = $lang->{$thread_toggle}; 1128 1129 // Show the similar threads table if wanted. 1130 $similarthreads = ''; 1131 if($mybb->settings['showsimilarthreads'] != 0) 1132 { 1133 $own_perm = ''; 1134 if(isset($forumpermissions['canonlyviewownthreads']) && $forumpermissions['canonlyviewownthreads'] == 1) 1135 { 1136 $own_perm = " AND t.uid={$mybb->user['uid']}"; 1137 } 1138 1139 switch($db->type) 1140 { 1141 case "pgsql": 1142 $query = $db->query(" 1143 SELECT t.*, t.username AS threadusername, u.username 1144 FROM ".TABLE_PREFIX."threads t 1145 LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid), plainto_tsquery ('".$db->escape_string($thread['subject'])."') AS query 1146 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} 1147 ORDER BY t.lastpost DESC 1148 OFFSET 0 LIMIT {$mybb->settings['similarlimit']} 1149 "); 1150 break; 1151 default: 1152 $query = $db->query(" 1153 SELECT t.*, t.username AS threadusername, u.username, MATCH (t.subject) AGAINST ('".$db->escape_string($thread['subject'])."') AS relevance 1154 FROM ".TABLE_PREFIX."threads t 1155 LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid) 1156 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']}' 1157 ORDER BY t.lastpost DESC 1158 LIMIT 0, {$mybb->settings['similarlimit']} 1159 "); 1160 } 1161 1162 $count = 0; 1163 $similarthreadbits = ''; 1164 $icon_cache = $cache->read("posticons"); 1165 while($similar_thread = $db->fetch_array($query)) 1166 { 1167 ++$count; 1168 $trow = alt_trow(); 1169 if($similar_thread['icon'] > 0 && $icon_cache[$similar_thread['icon']]) 1170 { 1171 $icon = $icon_cache[$similar_thread['icon']]; 1172 $icon['path'] = str_replace("{theme}", $theme['imgdir'], $icon['path']); 1173 $icon['path'] = htmlspecialchars_uni($icon['path']); 1174 $icon['name'] = htmlspecialchars_uni($icon['name']); 1175 eval("\$icon = \"".$templates->get("forumdisplay_thread_icon")."\";"); 1176 } 1177 else 1178 { 1179 $icon = " "; 1180 } 1181 if(!$similar_thread['username']) 1182 { 1183 $similar_thread['username'] = $similar_thread['profilelink'] = htmlspecialchars_uni($similar_thread['threadusername']); 1184 } 1185 else 1186 { 1187 $similar_thread['username'] = htmlspecialchars_uni($similar_thread['username']); 1188 $similar_thread['profilelink'] = build_profile_link($similar_thread['username'], $similar_thread['uid']); 1189 } 1190 1191 // If this thread has a prefix, insert a space between prefix and subject 1192 if($similar_thread['prefix'] != 0) 1193 { 1194 $prefix = build_prefixes($similar_thread['prefix']); 1195 if(!empty($prefix)) 1196 { 1197 $similar_thread['threadprefix'] = $prefix['displaystyle'].' '; 1198 } 1199 } 1200 else 1201 { 1202 $similar_thread['threadprefix'] = ''; 1203 } 1204 1205 $similar_thread['subject'] = $parser->parse_badwords($similar_thread['subject']); 1206 $similar_thread['subject'] = htmlspecialchars_uni($similar_thread['subject']); 1207 $similar_thread['threadlink'] = get_thread_link($similar_thread['tid']); 1208 $similar_thread['lastpostlink'] = get_thread_link($similar_thread['tid'], 0, "lastpost"); 1209 1210 $lastpostdate = my_date('relative', $similar_thread['lastpost']); 1211 $lastposter = $similar_thread['lastposter']; 1212 $lastposteruid = $similar_thread['lastposteruid']; 1213 1214 // Don't link to guest's profiles (they have no profile). 1215 if($lastposteruid == 0) 1216 { 1217 $lastposterlink = $lastposter; 1218 } 1219 else 1220 { 1221 $lastposterlink = build_profile_link($lastposter, $lastposteruid); 1222 } 1223 $similar_thread['replies'] = my_number_format($similar_thread['replies']); 1224 $similar_thread['views'] = my_number_format($similar_thread['views']); 1225 eval("\$similarthreadbits .= \"".$templates->get("showthread_similarthreads_bit")."\";"); 1226 } 1227 if($count) 1228 { 1229 eval("\$similarthreads = \"".$templates->get("showthread_similarthreads")."\";"); 1230 } 1231 } 1232 1233 // Decide whether or not to show quick reply. 1234 $quickreply = ''; 1235 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']))) 1236 { 1237 $query = $db->simple_select("posts", "pid", "tid='{$tid}'", array("order_by" => "pid", "order_dir" => "desc", "limit" => 1)); 1238 $last_pid = $db->fetch_field($query, "pid"); 1239 1240 // Show captcha image for guests if enabled 1241 $captcha = ''; 1242 if($mybb->settings['captchaimage'] && !$mybb->user['uid']) 1243 { 1244 require_once MYBB_ROOT.'inc/class_captcha.php'; 1245 $post_captcha = new captcha(true, "post_captcha"); 1246 1247 if($post_captcha->html) 1248 { 1249 $captcha = $post_captcha->html; 1250 } 1251 } 1252 1253 $postoptionschecked = array('signature' => '', 'emailnotify' => ''); 1254 if($mybb->user['signature']) 1255 { 1256 $postoptionschecked['signature'] = 'checked="checked"'; 1257 } 1258 1259 // Hide signature option if no permission 1260 $option_signature = ''; 1261 if($mybb->usergroup['canusesig'] && !$mybb->user['suspendsignature']) 1262 { 1263 eval("\$option_signature = \"".$templates->get('showthread_quickreply_options_signature')."\";"); 1264 } 1265 1266 if(isset($mybb->user['emailnotify']) && $mybb->user['emailnotify'] == 1) 1267 { 1268 $postoptionschecked['emailnotify'] = 'checked="checked"'; 1269 } 1270 1271 $trow = alt_trow(); 1272 if($thread['closed'] == 1) 1273 { 1274 $trow = 'trow_shaded'; 1275 } 1276 1277 $moderation_notice = ''; 1278 if(!is_moderator($forum['fid'], "canapproveunapproveposts")) 1279 { 1280 if($forumpermissions['modposts'] == 1) 1281 { 1282 $moderation_text = $lang->moderation_forum_posts; 1283 eval('$moderation_notice = "'.$templates->get('global_moderation_notice').'";'); 1284 } 1285 1286 if($mybb->user['moderateposts'] == 1) 1287 { 1288 $moderation_text = $lang->moderation_user_posts; 1289 eval('$moderation_notice = "'.$templates->get('global_moderation_notice').'";'); 1290 } 1291 } 1292 1293 $posthash = md5($mybb->user['uid'].random_str()); 1294 1295 if(!isset($collapsedthead['quickreply'])) 1296 { 1297 $collapsedthead['quickreply'] = ''; 1298 } 1299 if(!isset($collapsedimg['quickreply'])) 1300 { 1301 $collapsedimg['quickreply'] = ''; 1302 } 1303 if(!isset($collapsed['quickreply_e'])) 1304 { 1305 $collapsed['quickreply_e'] = ''; 1306 } 1307 1308 $expaltext = (in_array("quickreply", $collapse)) ? $lang->expcol_expand : $lang->expcol_collapse; 1309 eval("\$quickreply = \"".$templates->get("showthread_quickreply")."\";"); 1310 } 1311 1312 $moderationoptions = ''; 1313 $threadnotesbox = $viewnotes = ''; 1314 1315 // If the user is a moderator, show the moderation tools. 1316 if($ismod) 1317 { 1318 $customthreadtools = $customposttools = $standardthreadtools = $standardposttools = ''; 1319 1320 if(!empty($thread['notes'])) 1321 { 1322 $thread['notes'] = nl2br(htmlspecialchars_uni($thread['notes'])); 1323 1324 if(strlen($thread['notes']) > 200) 1325 { 1326 eval("\$viewnotes = \"".$templates->get("showthread_threadnotes_viewnotes")."\";"); 1327 $thread['notes'] = my_substr($thread['notes'], 0, 200)."... {$viewnotes}"; 1328 } 1329 1330 if(!isset($collapsedthead['threadnotes'])) 1331 { 1332 $collapsedthead['threadnotes'] = ''; 1333 } 1334 if(!isset($collapsedimg['threadnotes'])) 1335 { 1336 $collapsedimg['threadnotes'] = ''; 1337 } 1338 if(!isset($collapsed['threadnotes_e'])) 1339 { 1340 $collapsed['threadnotes_e'] = ''; 1341 } 1342 1343 $expaltext = (in_array("threadnotes", $collapse)) ? $lang->expcol_expand : $lang->expcol_collapse; 1344 eval("\$threadnotesbox = \"".$templates->get("showthread_threadnotes")."\";"); 1345 } 1346 1347 if(is_moderator($forum['fid'], "canusecustomtools") && (!empty($forum_stats[-1]['modtools']) || !empty($forum_stats[$forum['fid']]['modtools']))) 1348 { 1349 $gids = explode(',', $mybb->user['additionalgroups']); 1350 $gids[] = $mybb->user['usergroup']; 1351 $gids = array_filter(array_unique($gids)); 1352 $gidswhere = ''; 1353 switch($db->type) 1354 { 1355 case "pgsql": 1356 case "sqlite": 1357 foreach($gids as $gid) 1358 { 1359 $gid = (int)$gid; 1360 $gidswhere .= " OR ','||groups||',' LIKE '%,{$gid},%'"; 1361 } 1362 $query = $db->simple_select("modtools", 'tid, name, type', "(','||forums||',' LIKE '%,$fid,%' OR ','||forums||',' LIKE '%,-1,%' OR forums='') AND (groups='' OR ','||groups||',' LIKE '%,-1,%'{$gidswhere})"); 1363 break; 1364 default: 1365 foreach($gids as $gid) 1366 { 1367 $gid = (int)$gid; 1368 $gidswhere .= " OR CONCAT(',',`groups`,',') LIKE '%,{$gid},%'"; 1369 } 1370 $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})"); 1371 break; 1372 } 1373 1374 while($tool = $db->fetch_array($query)) 1375 { 1376 $tool['name'] = htmlspecialchars_uni($tool['name']); 1377 if($tool['type'] == 'p') 1378 { 1379 eval("\$customposttools .= \"".$templates->get("showthread_inlinemoderation_custom_tool")."\";"); 1380 } 1381 else 1382 { 1383 eval("\$customthreadtools .= \"".$templates->get("showthread_moderationoptions_custom_tool")."\";"); 1384 } 1385 } 1386 1387 // Build inline moderation dropdown 1388 if(!empty($customposttools)) 1389 { 1390 eval("\$customposttools = \"".$templates->get("showthread_inlinemoderation_custom")."\";"); 1391 } 1392 } 1393 1394 $inlinemodsoftdelete = $inlinemodrestore = $inlinemoddelete = $inlinemodmanage = $inlinemodapprove = ''; 1395 1396 if(is_moderator($forum['fid'], "cansoftdeleteposts")) 1397 { 1398 eval("\$inlinemodsoftdelete = \"".$templates->get("showthread_inlinemoderation_softdelete")."\";"); 1399 } 1400 1401 if(is_moderator($forum['fid'], "canrestoreposts")) 1402 { 1403 eval("\$inlinemodrestore = \"".$templates->get("showthread_inlinemoderation_restore")."\";"); 1404 } 1405 1406 if(is_moderator($forum['fid'], "candeleteposts")) 1407 { 1408 eval("\$inlinemoddelete = \"".$templates->get("showthread_inlinemoderation_delete")."\";"); 1409 } 1410 1411 if(is_moderator($forum['fid'], "canmanagethreads")) 1412 { 1413 eval("\$inlinemodmanage = \"".$templates->get("showthread_inlinemoderation_manage")."\";"); 1414 } 1415 1416 if(is_moderator($forum['fid'], "canapproveunapproveposts")) 1417 { 1418 eval("\$inlinemodapprove = \"".$templates->get("showthread_inlinemoderation_approve")."\";"); 1419 } 1420 1421 if(!empty($inlinemodsoftdelete) || !empty($inlinemodrestore) || !empty($inlinemoddelete) || !empty($inlinemodmanage) || !empty($inlinemodapprove)) 1422 { 1423 eval("\$standardposttools = \"".$templates->get("showthread_inlinemoderation_standard")."\";"); 1424 } 1425 1426 // Only show inline mod menu if there's options to show 1427 if(!empty($standardposttools) || !empty($customposttools)) 1428 { 1429 eval("\$inlinemod = \"".$templates->get("showthread_inlinemoderation")."\";"); 1430 } 1431 1432 // Build thread moderation dropdown 1433 if(!empty($customthreadtools)) 1434 { 1435 eval("\$customthreadtools = \"".$templates->get("showthread_moderationoptions_custom")."\";"); 1436 } 1437 1438 $openclosethread = $stickunstickthread = $deletethread = $threadnotes = $managethread = $adminpolloptions = $approveunapprovethread = $softdeletethread = ''; 1439 1440 if(is_moderator($forum['fid'], "canopenclosethreads")) 1441 { 1442 if($thread['closed']) 1443 { 1444 $lang->open_close_thread = $lang->open_thread; 1445 } 1446 else 1447 { 1448 $lang->open_close_thread = $lang->close_thread; 1449 } 1450 eval("\$openclosethread = \"".$templates->get("showthread_moderationoptions_openclose")."\";"); 1451 } 1452 1453 if(is_moderator($forum['fid'], "canstickunstickthreads")) 1454 { 1455 if($thread['sticky']) 1456 { 1457 $lang->stick_unstick_thread = $lang->unstick_thread; 1458 } 1459 else 1460 { 1461 $lang->stick_unstick_thread = $lang->stick_thread; 1462 } 1463 eval("\$stickunstickthread = \"".$templates->get("showthread_moderationoptions_stickunstick")."\";"); 1464 } 1465 1466 if(is_moderator($forum['fid'], "candeletethreads")) 1467 { 1468 eval("\$deletethread = \"".$templates->get("showthread_moderationoptions_delete")."\";"); 1469 } 1470 1471 if(is_moderator($forum['fid'], "canmanagethreads")) 1472 { 1473 eval("\$threadnotes = \"".$templates->get("showthread_moderationoptions_threadnotes")."\";"); 1474 eval("\$managethread = \"".$templates->get("showthread_moderationoptions_manage")."\";"); 1475 } 1476 1477 if($pollbox && is_moderator($forum['fid'], "canmanagepolls")) 1478 { 1479 eval("\$adminpolloptions = \"".$templates->get("showthread_moderationoptions_deletepoll")."\";"); 1480 } 1481 1482 if(is_moderator($forum['fid'], "canapproveunapprovethreads")) 1483 { 1484 if($thread['visible'] == 0) 1485 { 1486 eval("\$approveunapprovethread = \"".$templates->get("showthread_moderationoptions_approve")."\";"); 1487 } 1488 else 1489 { 1490 eval("\$approveunapprovethread = \"".$templates->get("showthread_moderationoptions_unapprove")."\";"); 1491 } 1492 } 1493 1494 if(is_moderator($forum['fid'], "cansoftdeletethreads") && $thread['visible'] != -1) 1495 { 1496 eval("\$softdeletethread = \"".$templates->get("showthread_moderationoptions_softdelete")."\";"); 1497 } 1498 elseif(is_moderator($forum['fid'], "canrestorethreads") && $thread['visible'] == -1) 1499 { 1500 eval("\$softdeletethread = \"".$templates->get("showthread_moderationoptions_restore")."\";"); 1501 } 1502 1503 if(!empty($openclosethread) || !empty($stickunstickthread) || !empty($deletethread) || !empty($managethread) || !empty($adminpolloptions) || !empty($approveunapprovethread) || !empty($softdeletethread)) 1504 { 1505 eval("\$standardthreadtools = \"".$templates->get("showthread_moderationoptions_standard")."\";"); 1506 } 1507 1508 // Only show mod menu if there's any options to show 1509 if(!empty($standardthreadtools) || !empty($customthreadtools)) 1510 { 1511 eval("\$moderationoptions = \"".$templates->get("showthread_moderationoptions")."\";"); 1512 } 1513 } 1514 1515 eval("\$printthread = \"".$templates->get("showthread_printthread")."\";"); 1516 1517 // Display 'send thread' link if permissions allow 1518 $sendthread = ''; 1519 if($mybb->usergroup['cansendemail'] == 1) 1520 { 1521 eval("\$sendthread = \"".$templates->get("showthread_send_thread")."\";"); 1522 } 1523 1524 // Display 'add poll' link to thread creator (or mods) if thread doesn't have a poll already 1525 $addpoll = ''; 1526 $time = TIME_NOW; 1527 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)) 1528 { 1529 eval("\$addpoll = \"".$templates->get("showthread_add_poll")."\";"); 1530 } 1531 1532 // Subscription status 1533 $add_remove_subscription = 'add'; 1534 $add_remove_subscription_text = $lang->subscribe_thread; 1535 1536 if($mybb->user['uid']) 1537 { 1538 $query = $db->simple_select("threadsubscriptions", "tid", "tid='".(int)$tid."' AND uid='".(int)$mybb->user['uid']."'", array('limit' => 1)); 1539 1540 if($db->num_rows($query) > 0) 1541 { 1542 $add_remove_subscription = 'remove'; 1543 $add_remove_subscription_text = $lang->unsubscribe_thread; 1544 } 1545 1546 eval("\$addremovesubscription = \"".$templates->get("showthread_subscription")."\";"); 1547 } 1548 else 1549 { 1550 $addremovesubscription = ''; 1551 } 1552 1553 $classic_header = ''; 1554 if($mybb->settings['postlayout'] == "classic") 1555 { 1556 eval("\$classic_header = \"".$templates->get("showthread_classic_header")."\";"); 1557 } 1558 1559 // Get users viewing this thread 1560 $usersbrowsing=''; 1561 if($mybb->settings['browsingthisthread'] != 0) 1562 { 1563 $timecut = TIME_NOW - $mybb->settings['wolcutoff']; 1564 1565 $comma = ''; 1566 $guestcount = 0; 1567 $membercount = 0; 1568 $inviscount = 0; 1569 $onlinemembers = ''; 1570 $doneusers = array(); 1571 1572 $query = $db->simple_select("sessions", "COUNT(DISTINCT ip) AS guestcount", "uid = 0 AND time > $timecut AND location2 = $tid AND nopermission != 1"); 1573 $guestcount = $db->fetch_field($query, 'guestcount'); 1574 1575 $query = $db->query(" 1576 SELECT 1577 s.ip, s.uid, s.time, u.username, u.invisible, u.usergroup, u.displaygroup 1578 FROM 1579 ".TABLE_PREFIX."sessions s 1580 LEFT JOIN ".TABLE_PREFIX."users u ON (s.uid=u.uid) 1581 WHERE s.uid != 0 AND s.time > '$timecut' AND location2='$tid' AND nopermission != 1 1582 ORDER BY u.username ASC, s.time DESC 1583 "); 1584 1585 while($user = $db->fetch_array($query)) 1586 { 1587 if(empty($doneusers[$user['uid']]) || $doneusers[$user['uid']] < $user['time']) 1588 { 1589 ++$membercount; 1590 $doneusers[$user['uid']] = $user['time']; 1591 1592 $invisiblemark = ''; 1593 if($user['invisible'] == 1) 1594 { 1595 $invisiblemark = "*"; 1596 ++$inviscount; 1597 } 1598 1599 if($user['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1 || $user['uid'] == $mybb->user['uid']) 1600 { 1601 $user['profilelink'] = get_profile_link($user['uid']); 1602 $user['username'] = format_name(htmlspecialchars_uni($user['username']), $user['usergroup'], $user['displaygroup']); 1603 $user['reading'] = my_date($mybb->settings['timeformat'], $user['time']); 1604 1605 eval("\$onlinemembers .= \"".$templates->get("showthread_usersbrowsing_user", 1, 0)."\";"); 1606 $comma = $lang->comma; 1607 } 1608 } 1609 } 1610 1611 $guestsonline = ''; 1612 if($guestcount) 1613 { 1614 $guestsonline = $lang->sprintf($lang->users_browsing_thread_guests, $guestcount); 1615 } 1616 1617 $invisonline = ''; 1618 if($mybb->user['invisible'] == 1) 1619 { 1620 // the user was counted as invisible user --> correct the inviscount 1621 $inviscount -= 1; 1622 } 1623 if($inviscount && $mybb->usergroup['canviewwolinvis'] != 1) 1624 { 1625 $invisonline = $lang->sprintf($lang->users_browsing_thread_invis, $inviscount); 1626 } 1627 1628 $onlinesep = ''; 1629 if($invisonline != '' && $onlinemembers) 1630 { 1631 $onlinesep = $lang->comma; 1632 } 1633 1634 $onlinesep2 = ''; 1635 if($invisonline != '' && $guestcount || $onlinemembers && $guestcount) 1636 { 1637 $onlinesep2 = $lang->comma; 1638 } 1639 1640 eval("\$usersbrowsing = \"".$templates->get("showthread_usersbrowsing")."\";"); 1641 } 1642 1643 $thread_deleted = 0; 1644 if($thread['visible'] == -1) 1645 { 1646 $thread_deleted = 1; 1647 } 1648 1649 $plugins->run_hooks("showthread_end"); 1650 1651 eval("\$showthread = \"".$templates->get("showthread")."\";"); 1652 output_page($showthread); 1653 } 1654 1655 /** 1656 * Build a navigation tree for threaded display. 1657 * 1658 * @param int $replyto 1659 * @param int $indent 1660 * @return string 1661 */ 1662 function buildtree($replyto=0, $indent=0) 1663 { 1664 global $tree, $mybb, $theme, $mybb, $pid, $tid, $templates, $parser, $lang; 1665 1666 $indentsize = 13 * $indent; 1667 1668 ++$indent; 1669 $posts = ''; 1670 if(is_array($tree[$replyto])) 1671 { 1672 foreach($tree[$replyto] as $key => $post) 1673 { 1674 $postdate = my_date('relative', $post['dateline']); 1675 $post['subject'] = htmlspecialchars_uni($parser->parse_badwords($post['subject'])); 1676 1677 if(!$post['subject']) 1678 { 1679 $post['subject'] = "[".$lang->no_subject."]"; 1680 } 1681 1682 $post['username'] = htmlspecialchars_uni($post['username']); 1683 $post['profilelink'] = build_profile_link($post['username'], $post['uid']); 1684 1685 if($mybb->input['pid'] == $post['pid']) 1686 { 1687 eval("\$posts .= \"".$templates->get("showthread_threaded_bitactive")."\";"); 1688 } 1689 else 1690 { 1691 eval("\$posts .= \"".$templates->get("showthread_threaded_bit")."\";"); 1692 } 1693 1694 if(!empty($tree[$post['pid']])) 1695 { 1696 $posts .= buildtree($post['pid'], $indent); 1697 } 1698 } 1699 --$indent; 1700 } 1701 return $posts; 1702 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup | Cross-referenced by PHPXref |