| [ Index ] |
PHP Cross Reference of MyBB 1.6.7 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.6 4 * Copyright 2010 MyBB Group, All Rights Reserved 5 * 6 * Website: http://mybb.com 7 * License: http://mybb.com/about/license 8 * 9 * $Id: showthread.php 5758 2012-03-09 15:26:44Z Tomm $ 10 */ 11 12 define("IN_MYBB", 1); 13 define('THIS_SCRIPT', 'showthread.php'); 14 15 $templatelist = "showthread,postbit,postbit_author_user,postbit_author_guest,showthread_newthread,showthread_newreply,showthread_newreply_closed,postbit_sig,showthread_newpoll,postbit_avatar,postbit_profile,postbit_find,postbit_pm,postbit_www,postbit_email,postbit_edit,postbit_quote,postbit_report,postbit_signature, postbit_online,postbit_offline,postbit_away,postbit_gotopost,showthread_ratethread,showthread_inline_ratethread,showthread_moderationoptions"; 16 $templatelist .= ",multipage_prevpage,multipage_nextpage,multipage_page_current,multipage_page,multipage_start,multipage_end,multipage"; 17 $templatelist .= ",postbit_editedby,showthread_similarthreads,showthread_similarthreads_bit,postbit_iplogged_show,postbit_iplogged_hiden,showthread_quickreply"; 18 $templatelist .= ",forumjump_advanced,forumjump_special,forumjump_bit,showthread_multipage,postbit_reputation,postbit_quickdelete,postbit_attachments,thumbnails_thumbnail,postbit_attachments_attachment,postbit_attachments_thumbnails,postbit_attachments_images_image,postbit_attachments_images,postbit_posturl,postbit_rep_button"; 19 $templatelist .= ",postbit_inlinecheck,showthread_inlinemoderation,postbit_attachments_thumbnails_thumbnail,postbit_quickquote,postbit_qqmessage,postbit_ignored,postbit_groupimage,postbit_multiquote,showthread_search,postbit_warn,postbit_warninglevel,showthread_moderationoptions_custom_tool,showthread_moderationoptions_custom,showthread_inlinemoderation_custom_tool,showthread_inlinemoderation_custom,postbit_classic,showthread_classic_header,showthread_poll_resultbit,showthread_poll_results"; 20 $templatelist .= ",showthread_usersbrowsing,showthread_usersbrowsing_user,multipage_page_link_current,multipage_breadcrumb"; 21 22 require_once "./global.php"; 23 require_once MYBB_ROOT."inc/functions_post.php"; 24 require_once MYBB_ROOT."/inc/functions_indicators.php"; 25 require_once MYBB_ROOT."inc/class_parser.php"; 26 $parser = new postParser; 27 28 // Load global language phrases 29 $lang->load("showthread"); 30 31 // If there is no tid but a pid, trick the system into thinking there was a tid anyway. 32 if($mybb->input['pid'] && !$mybb->input['tid']) 33 { 34 // see if we already have the post information 35 if(isset($style) && $style['pid'] == $mybb->input['pid'] && $style['tid']) 36 { 37 $mybb->input['tid'] = $style['tid']; 38 unset($style['tid']); // stop the thread caching code from being tricked 39 } 40 else 41 { 42 $options = array( 43 "limit" => 1 44 ); 45 $query = $db->simple_select("posts", "tid", "pid=".$mybb->input['pid'], $options); 46 $post = $db->fetch_array($query); 47 $mybb->input['tid'] = $post['tid']; 48 } 49 } 50 51 // Get the thread details from the database. 52 $thread = get_thread($mybb->input['tid']); 53 54 // Get thread prefix if there is one. 55 $thread['threadprefix'] = ''; 56 $thread['displayprefix'] = ''; 57 if($thread['prefix'] != 0) 58 { 59 $threadprefix = build_prefixes($thread['prefix']); 60 61 if($threadprefix['prefix']) 62 { 63 $thread['threadprefix'] = $threadprefix['prefix'].' '; 64 $thread['displayprefix'] = $threadprefix['displaystyle'].' '; 65 } 66 } 67 68 if(substr($thread['closed'], 0, 6) == "moved|") 69 { 70 $thread['tid'] = 0; 71 } 72 73 $thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject'])); 74 $tid = $thread['tid']; 75 $fid = $thread['fid']; 76 77 if(!$thread['username']) 78 { 79 $thread['username'] = $lang->guest; 80 } 81 82 $visibleonly = "AND visible='1'"; 83 $visibleonly2 = "AND p.visible='1' AND t.visible='1'"; 84 85 // Is the currently logged in user a moderator of this forum? 86 if(is_moderator($fid)) 87 { 88 $visibleonly = " AND (visible='1' OR visible='0')"; 89 $visibleonly2 = "AND (p.visible='1' OR p.visible='0') AND (t.visible='1' OR t.visible='0')"; 90 $ismod = true; 91 } 92 else 93 { 94 $ismod = false; 95 } 96 97 // Make sure we are looking at a real thread here. 98 if(!$thread['tid'] || ($thread['visible'] == 0 && $ismod == false) || ($thread['visible'] > 1 && $ismod == true)) 99 { 100 error($lang->error_invalidthread); 101 } 102 103 $forumpermissions = forum_permissions($thread['fid']); 104 105 // Does the user have permission to view this thread? 106 if($forumpermissions['canview'] != 1 || $forumpermissions['canviewthreads'] != 1) 107 { 108 error_no_permission(); 109 } 110 111 if($forumpermissions['canonlyviewownthreads'] == 1 && $thread['uid'] != $mybb->user['uid']) 112 { 113 error_no_permission(); 114 } 115 116 $archive_url = build_archive_link("thread", $tid); 117 118 // Does the thread belong to a valid forum? 119 $forum = get_forum($fid); 120 if(!$forum || $forum['type'] != "f") 121 { 122 error($lang->error_invalidforum); 123 } 124 125 // Forumdisplay cache 126 $forum_stats = $cache->read("forumsdisplay"); 127 128 $breadcrumb_multipage = array(); 129 if($mybb->settings['showforumpagesbreadcrumb']) 130 { 131 // How many pages are there? 132 if(!$mybb->settings['threadsperpage']) 133 { 134 $mybb->settings['threadsperpage'] = 20; 135 } 136 137 $query = $db->simple_select("forums", "threads, unapprovedthreads", "fid = '{$fid}'", array('limit' => 1)); 138 $forum_threads = $db->fetch_array($query); 139 $threadcount = $forum_threads['threads']; 140 141 if($ismod == true) 142 { 143 $threadcount += $forum_threads['unapprovedthreads']; 144 } 145 146 // Limit to only our own threads 147 $uid_only = ''; 148 if($forumpermissions['canonlyviewownthreads'] == 1) 149 { 150 $uid_only = " AND uid = '".$mybb->user['uid']."'"; 151 152 $query = $db->simple_select("threads", "COUNT(tid) AS threads", "fid = '$fid' $visibleonly $uid_only", array('limit' => 1)); 153 $threadcount = $db->fetch_field($query, "threads"); 154 } 155 156 // If we have 0 threads double check there aren't any "moved" threads 157 if($threadcount == 0) 158 { 159 $query = $db->simple_select("threads", "COUNT(tid) AS threads", "fid = '$fid' $visibleonly $uid_only", array('limit' => 1)); 160 $threadcount = $db->fetch_field($query, "threads"); 161 } 162 163 $stickybit = " OR sticky=1"; 164 if($thread['sticky'] == 1) 165 { 166 $stickybit = " AND sticky=1"; 167 } 168 169 // Figure out what page the thread is actually on 170 switch($db->type) 171 { 172 case "pgsql": 173 $query = $db->query(" 174 SELECT COUNT(tid) as threads 175 FROM ".TABLE_PREFIX."threads 176 WHERE fid = '$fid' AND (lastpost >= '".intval($thread['lastpost'])."'{$stickybit}) {$visibleonly} {$uid_only} 177 GROUP BY lastpost 178 ORDER BY lastpost DESC 179 "); 180 break; 181 default: 182 $query = $db->simple_select("threads", "COUNT(tid) as threads", "fid = '$fid' AND (lastpost >= '".intval($thread['lastpost'])."'{$stickybit}) {$visibleonly} {$uid_only}", array('order_by' => 'lastpost', 'order_dir' => 'desc')); 183 } 184 185 $thread_position = $db->fetch_field($query, "threads"); 186 $thread_page = ceil(($thread_position/$mybb->settings['threadsperpage'])); 187 188 $breadcrumb_multipage = array( 189 "num_threads" => $threadcount, 190 "current_page" => $thread_page 191 ); 192 } 193 194 // Build the navigation. 195 build_forum_breadcrumb($fid, $breadcrumb_multipage); 196 add_breadcrumb($thread['displayprefix'].$thread['subject'], get_thread_link($thread['tid'])); 197 198 // Check if this forum is password protected and we have a valid password 199 check_forum_password($forum['fid']); 200 201 // If there is no specific action, we must be looking at the thread. 202 if(!$mybb->input['action']) 203 { 204 $mybb->input['action'] = "thread"; 205 } 206 207 // Jump to the unread posts. 208 if($mybb->input['action'] == "newpost") 209 { 210 // First, figure out what time the thread or forum were last read 211 $query = $db->simple_select("threadsread", "dateline", "uid='{$mybb->user['uid']}' AND tid='{$thread['tid']}'"); 212 $thread_read = $db->fetch_field($query, "dateline"); 213 214 if($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid']) 215 { 216 $query = $db->simple_select("forumsread", "dateline", "fid='{$fid}' AND uid='{$mybb->user['uid']}'"); 217 $forum_read = $db->fetch_field($query, "dateline"); 218 219 $read_cutoff = TIME_NOW-$mybb->settings['threadreadcut']*60*60*24; 220 if($forum_read == 0 || $forum_read < $read_cutoff) 221 { 222 $forum_read = $read_cutoff; 223 } 224 } 225 else 226 { 227 $forum_read = intval(my_get_array_cookie("forumread", $fid)); 228 } 229 230 if($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid'] && $thread['lastpost'] > $forum_read) 231 { 232 $cutoff = TIME_NOW-$mybb->settings['threadreadcut']*60*60*24; 233 if($thread['lastpost'] > $cutoff) 234 { 235 if($thread_read) 236 { 237 $lastread = $thread_read; 238 } 239 else 240 { 241 // Set $lastread to zero to make sure 'lastpost' is invoked in the last IF 242 $lastread = 0; 243 } 244 } 245 } 246 247 if(!$lastread) 248 { 249 $readcookie = $threadread = intval(my_get_array_cookie("threadread", $thread['tid'])); 250 if($readcookie > $forum_read) 251 { 252 $lastread = $readcookie; 253 } 254 else 255 { 256 $lastread = $forum_read; 257 } 258 } 259 260 if($cutoff && $lastread < $cutoff) 261 { 262 $lastread = $cutoff; 263 } 264 265 // Next, find the proper pid to link to. 266 $options = array( 267 "limit_start" => 0, 268 "limit" => 1, 269 "order_by" => "dateline", 270 "order_dir" => "asc" 271 ); 272 273 $lastread = intval($lastread); 274 $query = $db->simple_select("posts", "pid", "tid='{$tid}' AND dateline > '{$lastread}' {$visibleonly}", $options); 275 $newpost = $db->fetch_array($query); 276 277 if($newpost['pid'] && $lastread) 278 { 279 $highlight = ''; 280 if($mybb->input['highlight']) 281 { 282 $string = "&"; 283 if($mybb->settings['seourls'] == "yes" || ($mybb->settings['seourls'] == "auto" && $_SERVER['SEO_SUPPORT'] == 1)) 284 { 285 $string = "?"; 286 } 287 288 $highlight = $string."highlight=".$mybb->input['highlight']; 289 } 290 291 header("Location: ".htmlspecialchars_decode(get_post_link($newpost['pid'], $tid)).$highlight."#pid{$newpost['pid']}"); 292 } 293 else 294 { 295 // show them to the last post 296 $mybb->input['action'] = "lastpost"; 297 } 298 } 299 300 // Jump to the last post. 301 if($mybb->input['action'] == "lastpost") 302 { 303 if(my_strpos($thread['closed'], "moved|")) 304 { 305 $query = $db->query(" 306 SELECT p.pid 307 FROM ".TABLE_PREFIX."posts p 308 LEFT JOIN ".TABLE_PREFIX."threads t ON(p.tid=t.tid) 309 WHERE t.fid='".$thread['fid']."' AND t.closed NOT LIKE 'moved|%' {$visibleonly2} 310 ORDER BY p.dateline DESC 311 LIMIT 1 312 "); 313 $pid = $db->fetch_field($query, "pid"); 314 } 315 else 316 { 317 $options = array( 318 'order_by' => 'dateline', 319 'order_dir' => 'desc', 320 'limit_start' => 0, 321 'limit' => 1 322 ); 323 $query = $db->simple_select('posts', 'pid', "tid={$tid} {$visibleonly}", $options); 324 $pid = $db->fetch_field($query, "pid"); 325 } 326 header("Location: ".htmlspecialchars_decode(get_post_link($pid, $tid))."#pid{$pid}"); 327 exit; 328 } 329 330 // Jump to the next newest posts. 331 if($mybb->input['action'] == "nextnewest") 332 { 333 $options = array( 334 "limit_start" => 0, 335 "limit" => 1, 336 "order_by" => "lastpost" 337 ); 338 $query = $db->simple_select('threads', '*', "fid={$thread['fid']} AND lastpost > {$thread['lastpost']} AND visible=1 AND closed NOT LIKE 'moved|%'", $options); 339 $nextthread = $db->fetch_array($query); 340 341 // Are there actually next newest posts? 342 if(!$nextthread['tid']) 343 { 344 error($lang->error_nonextnewest); 345 } 346 $options = array( 347 "limit_start" => 0, 348 "limit" => 1, 349 "order_by" => "dateline", 350 "order_dir" => "desc" 351 ); 352 $query = $db->simple_select('posts', 'pid', "tid='{$nextthread['tid']}'", $options); 353 354 // Redirect to the proper page. 355 $pid = $db->fetch_field($query, "pid"); 356 header("Location: ".htmlspecialchars_decode(get_post_link($pid, $nextthread['tid']))."#pid{$pid}"); 357 exit; 358 } 359 360 // Jump to the next oldest posts. 361 if($mybb->input['action'] == "nextoldest") 362 { 363 $options = array( 364 "limit" => 1, 365 "limit_start" => 0, 366 "order_by" => "lastpost", 367 "order_dir" => "desc" 368 ); 369 $query = $db->simple_select("threads", "*", "fid=".$thread['fid']." AND lastpost < ".$thread['lastpost']." AND visible=1 AND closed NOT LIKE 'moved|%'", $options); 370 $nextthread = $db->fetch_array($query); 371 372 // Are there actually next oldest posts? 373 if(!$nextthread['tid']) 374 { 375 error($lang->error_nonextoldest); 376 } 377 $options = array( 378 "limit_start" => 0, 379 "limit" => 1, 380 "order_by" => "dateline", 381 "order_dir" => "desc" 382 ); 383 $query = $db->simple_select("posts", "pid", "tid='".$nextthread['tid']."'", $options); 384 385 // Redirect to the proper page. 386 $pid = $db->fetch_field($query, "pid"); 387 header("Location: ".htmlspecialchars_decode(get_post_link($pid, $nextthread['tid']))."#pid{$pid}"); 388 exit; 389 } 390 391 if($mybb->input['pid']) 392 { 393 $pid = $mybb->input['pid']; 394 } 395 396 $plugins->run_hooks("showthread_start"); 397 398 // Show the entire thread (taking into account pagination). 399 if($mybb->input['action'] == "thread") 400 { 401 if($thread['firstpost'] == 0) 402 { 403 update_first_post($tid); 404 } 405 406 // Does this thread have a poll? 407 if($thread['poll']) 408 { 409 $options = array( 410 "limit" => 1 411 ); 412 $query = $db->simple_select("polls", "*", "pid='".$thread['poll']."'", $options); 413 $poll = $db->fetch_array($query); 414 $poll['timeout'] = $poll['timeout']*60*60*24; 415 $expiretime = $poll['dateline'] + $poll['timeout']; 416 $now = TIME_NOW; 417 418 // If the poll or the thread is closed or if the poll is expired, show the results. 419 if($poll['closed'] == 1 || $thread['closed'] == 1 || ($expiretime < $now && $poll['timeout'] > 0)) 420 { 421 $showresults = 1; 422 } 423 424 // If the user is not a guest, check if he already voted. 425 if($mybb->user['uid'] != 0) 426 { 427 $query = $db->simple_select("pollvotes", "*", "uid='".$mybb->user['uid']."' AND pid='".$poll['pid']."'"); 428 while($votecheck = $db->fetch_array($query)) 429 { 430 $alreadyvoted = 1; 431 $votedfor[$votecheck['voteoption']] = 1; 432 } 433 } 434 else 435 { 436 if(isset($mybb->cookies['pollvotes'][$poll['pid']]) && $mybb->cookies['pollvotes'][$poll['pid']] !== "") 437 { 438 $alreadyvoted = 1; 439 } 440 } 441 $optionsarray = explode("||~|~||", $poll['options']); 442 $votesarray = explode("||~|~||", $poll['votes']); 443 $poll['question'] = htmlspecialchars_uni($poll['question']); 444 $polloptions = ''; 445 $totalvotes = 0; 446 447 for($i = 1; $i <= $poll['numoptions']; ++$i) 448 { 449 $poll['totvotes'] = $poll['totvotes'] + $votesarray[$i-1]; 450 } 451 452 // Loop through the poll options. 453 for($i = 1; $i <= $poll['numoptions']; ++$i) 454 { 455 // Set up the parser options. 456 $parser_options = array( 457 "allow_html" => $forum['allowhtml'], 458 "allow_mycode" => $forum['allowmycode'], 459 "allow_smilies" => $forum['allowsmilies'], 460 "allow_imgcode" => $forum['allowimgcode'], 461 "allow_videocode" => $forum['allowvideocode'], 462 "filter_badwords" => 1 463 ); 464 465 $option = $parser->parse_message($optionsarray[$i-1], $parser_options); 466 $votes = $votesarray[$i-1]; 467 $totalvotes += $votes; 468 $number = $i; 469 470 // Mark the option the user voted for. 471 if($votedfor[$number]) 472 { 473 $optionbg = "trow2"; 474 $votestar = "*"; 475 } 476 else 477 { 478 $optionbg = "trow1"; 479 $votestar = ""; 480 } 481 482 // If the user already voted or if the results need to be shown, do so; else show voting screen. 483 if($alreadyvoted || $showresults) 484 { 485 if(intval($votes) == "0") 486 { 487 $percent = "0"; 488 } 489 else 490 { 491 $percent = number_format($votes / $poll['totvotes'] * 100, 2); 492 } 493 $imagewidth = round(($percent/3) * 5); 494 $imagerowwidth = $imagewidth + 10; 495 eval("\$polloptions .= \"".$templates->get("showthread_poll_resultbit")."\";"); 496 } 497 else 498 { 499 if($poll['multiple'] == 1) 500 { 501 eval("\$polloptions .= \"".$templates->get("showthread_poll_option_multiple")."\";"); 502 } 503 else 504 { 505 eval("\$polloptions .= \"".$templates->get("showthread_poll_option")."\";"); 506 } 507 } 508 } 509 510 // If there are any votes at all, all votes together will be 100%; if there are no votes, all votes together will be 0%. 511 if($poll['totvotes']) 512 { 513 $totpercent = "100%"; 514 } 515 else 516 { 517 $totpercent = "0%"; 518 } 519 520 // Check if user is allowed to edit posts; if so, show "edit poll" link. 521 if(!is_moderator($fid, 'caneditposts')) 522 { 523 $edit_poll = ''; 524 } 525 else 526 { 527 $edit_poll = " | <a href=\"polls.php?action=editpoll&pid={$poll['pid']}\">{$lang->edit_poll}</a>"; 528 } 529 530 // Decide what poll status to show depending on the status of the poll and whether or not the user voted already. 531 if($alreadyvoted || $showresults) 532 { 533 if($alreadyvoted) 534 { 535 $pollstatus = $lang->already_voted; 536 537 if($mybb->usergroup['canundovotes'] == 1) 538 { 539 $pollstatus .= " [<a href=\"polls.php?action=do_undovote&pid={$poll['pid']}&my_post_key={$mybb->post_code}\">{$lang->undo_vote}</a>]"; 540 } 541 } 542 else 543 { 544 $pollstatus = $lang->poll_closed; 545 } 546 $lang->total_votes = $lang->sprintf($lang->total_votes, $totalvotes); 547 eval("\$pollbox = \"".$templates->get("showthread_poll_results")."\";"); 548 $plugins->run_hooks("showthread_poll_results"); 549 } 550 else 551 { 552 $publicnote = ' '; 553 if($poll['public'] == 1) 554 { 555 $publicnote = $lang->public_note; 556 } 557 eval("\$pollbox = \"".$templates->get("showthread_poll")."\";"); 558 $plugins->run_hooks("showthread_poll"); 559 } 560 561 } 562 else 563 { 564 $pollbox = ""; 565 } 566 567 // Create the forum jump dropdown box. 568 if($mybb->settings['enableforumjump'] != 0) 569 { 570 $forumjump = build_forum_jump("", $fid, 1); 571 } 572 573 // Fetch some links 574 $next_oldest_link = get_thread_link($tid, 0, "nextoldest"); 575 $next_newest_link = get_thread_link($tid, 0, "nextnewest"); 576 577 // Mark this thread as read 578 mark_thread_read($tid, $fid); 579 580 // If the forum is not open, show closed newreply button unless the user is a moderator of this forum. 581 if($forum['open'] != 0) 582 { 583 eval("\$newthread = \"".$templates->get("showthread_newthread")."\";"); 584 585 // Show the appropriate reply button if this thread is open or closed 586 if($thread['closed'] == 1) 587 { 588 eval("\$newreply = \"".$templates->get("showthread_newreply_closed")."\";"); 589 } 590 else 591 { 592 eval("\$newreply = \"".$templates->get("showthread_newreply")."\";"); 593 } 594 } 595 596 // Create the admin tools dropdown box. 597 if($ismod == true) 598 { 599 if($pollbox) 600 { 601 $adminpolloptions = "<option value=\"deletepoll\">".$lang->delete_poll."</option>"; 602 } 603 if($thread['visible'] != 1) 604 { 605 $approveunapprovethread = "<option value=\"approvethread\">".$lang->approve_thread."</option>"; 606 } 607 else 608 { 609 $approveunapprovethread = "<option value=\"unapprovethread\">".$lang->unapprove_thread."</option>"; 610 } 611 if($thread['closed'] == 1) 612 { 613 $closelinkch = ' checked="checked"'; 614 } 615 if($thread['sticky']) 616 { 617 $stickch = ' checked="checked"'; 618 } 619 $closeoption = "<br /><label><input type=\"checkbox\" class=\"checkbox\" name=\"modoptions[closethread]\" value=\"1\"{$closelinkch} /> <strong>".$lang->close_thread."</strong></label>"; 620 $closeoption .= "<br /><label><input type=\"checkbox\" class=\"checkbox\" name=\"modoptions[stickthread]\" value=\"1\"{$stickch} /> <strong>".$lang->stick_thread."</strong></label>"; 621 $inlinecount = "0"; 622 $inlinecookie = "inlinemod_thread".$tid; 623 $plugins->run_hooks("showthread_ismod"); 624 } 625 else 626 { 627 $modoptions = " "; 628 $inlinemod = ""; 629 } 630 631 // Increment the thread view. 632 if($mybb->settings['delayedthreadviews'] == 1) 633 { 634 $db->shutdown_query("INSERT INTO ".TABLE_PREFIX."threadviews (tid) VALUES('{$tid}')"); 635 } 636 else 637 { 638 $db->shutdown_query("UPDATE ".TABLE_PREFIX."threads SET views=views+1 WHERE tid='{$tid}'"); 639 } 640 ++$thread['views']; 641 642 // Work out the thread rating for this thread. 643 $rating = ''; 644 if($mybb->settings['allowthreadratings'] != 0 && $forum['allowtratings'] != 0) 645 { 646 $rated = 0; 647 $lang->load("ratethread"); 648 if($thread['numratings'] <= 0) 649 { 650 $thread['width'] = 0; 651 $thread['averagerating'] = 0; 652 $thread['numratings'] = 0; 653 } 654 else 655 { 656 $thread['averagerating'] = floatval(round($thread['totalratings']/$thread['numratings'], 2)); 657 $thread['width'] = intval(round($thread['averagerating']))*20; 658 $thread['numratings'] = intval($thread['numratings']); 659 } 660 661 if($thread['numratings']) 662 { 663 // At least >someone< has rated this thread, was it me? 664 // Check if we have already voted on this thread - it won't show hover effect then. 665 $query = $db->simple_select("threadratings", "uid", "tid='{$tid}' AND uid='{$mybb->user['uid']}'"); 666 $rated = $db->fetch_field($query, 'uid'); 667 } 668 669 $not_rated = ''; 670 if(!$rated) 671 { 672 $not_rated = ' star_rating_notrated'; 673 } 674 675 $ratingvotesav = $lang->sprintf($lang->rating_average, $thread['numratings'], $thread['averagerating']); 676 eval("\$ratethread = \"".$templates->get("showthread_ratethread")."\";"); 677 } 678 // Work out if we are showing unapproved posts as well (if the user is a moderator etc.) 679 if($ismod) 680 { 681 $visible = "AND (p.visible='0' OR p.visible='1')"; 682 } 683 else 684 { 685 $visible = "AND p.visible='1'"; 686 } 687 688 // Can this user perform searches? If so, we can show them the "Search thread" form 689 if($forumpermissions['cansearch'] != 0) 690 { 691 eval("\$search_thread = \"".$templates->get("showthread_search")."\";"); 692 } 693 694 // Fetch the ignore list for the current user if they have one 695 $ignored_users = array(); 696 if($mybb->user['uid'] > 0 && $mybb->user['ignorelist'] != "") 697 { 698 $ignore_list = explode(',', $mybb->user['ignorelist']); 699 foreach($ignore_list as $uid) 700 { 701 $ignored_users[$uid] = 1; 702 } 703 } 704 705 // Which thread mode is our user using by default? 706 if(!empty($mybb->user['threadmode'])) 707 { 708 $defaultmode = $mybb->user['threadmode']; 709 } 710 else if($mybb->settings['threadusenetstyle'] == 1) 711 { 712 $defaultmode = 'threaded'; 713 } 714 else 715 { 716 $defaultmode = 'linear'; 717 } 718 719 // If mode is unset, set the default mode 720 if(!isset($mybb->input['mode'])) 721 { 722 $mybb->input['mode'] = $defaultmode; 723 } 724 725 // Threaded or linear display? 726 if($mybb->input['mode'] == 'threaded') 727 { 728 $isfirst = 1; 729 730 // Are we linked to a specific pid? 731 if($mybb->input['pid']) 732 { 733 $where = "AND p.pid='".$mybb->input['pid']."'"; 734 } 735 else 736 { 737 $where = " ORDER BY dateline LIMIT 0, 1"; 738 } 739 $query = $db->query(" 740 SELECT u.*, u.username AS userusername, p.*, f.*, eu.username AS editusername 741 FROM ".TABLE_PREFIX."posts p 742 LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid) 743 LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid) 744 LEFT JOIN ".TABLE_PREFIX."users eu ON (eu.uid=p.edituid) 745 WHERE p.tid='$tid' $visible $where 746 "); 747 $showpost = $db->fetch_array($query); 748 749 // Choose what pid to display. 750 if(!$mybb->input['pid']) 751 { 752 $mybb->input['pid'] = $showpost['pid']; 753 } 754 755 // Is there actually a pid to display? 756 if(!$showpost['pid']) 757 { 758 error($lang->error_invalidpost); 759 } 760 761 $attachcache = array(); 762 if($thread['attachmentcount'] > 0) 763 { 764 // Get the attachments for this post. 765 $query = $db->simple_select("attachments", "*", "pid=".$mybb->input['pid']); 766 while($attachment = $db->fetch_array($query)) 767 { 768 $attachcache[$attachment['pid']][$attachment['aid']] = $attachment; 769 } 770 } 771 772 // Build the threaded post display tree. 773 $query = $db->query(" 774 SELECT p.username, p.uid, p.pid, p.replyto, p.subject, p.dateline 775 FROM ".TABLE_PREFIX."posts p 776 WHERE p.tid='$tid' 777 $visible 778 ORDER BY p.dateline 779 "); 780 while($post = $db->fetch_array($query)) 781 { 782 if(!$postsdone[$post['pid']]) 783 { 784 if($post['pid'] == $mybb->input['pid'] || ($isfirst && !$mybb->input['pid'])) 785 { 786 $postcounter = count($postsdone); 787 $isfirst = 0; 788 } 789 $tree[$post['replyto']][$post['pid']] = $post; 790 $postsdone[$post['pid']] = 1; 791 } 792 } 793 794 $threadedbits = buildtree(); 795 $posts = build_postbit($showpost); 796 eval("\$threadexbox = \"".$templates->get("showthread_threadedbox")."\";"); 797 $plugins->run_hooks("showthread_threaded"); 798 } 799 else // Linear display 800 { 801 if(!$mybb->settings['postsperpage']) 802 { 803 $mybb->settings['postperpage'] = 20; 804 } 805 806 // Figure out if we need to display multiple pages. 807 $perpage = $mybb->settings['postsperpage']; 808 if($mybb->input['page'] != "last") 809 { 810 $page = intval($mybb->input['page']); 811 } 812 if($mybb->input['pid']) 813 { 814 $post = get_post($mybb->input['pid']); 815 $query = $db->query(" 816 SELECT COUNT(p.dateline) AS count FROM ".TABLE_PREFIX."posts p 817 WHERE p.tid='$tid' 818 AND p.dateline <= '".$post['dateline']."' 819 $visible 820 "); 821 $result = $db->fetch_field($query, "count"); 822 if(($result % $perpage) == 0) 823 { 824 $page = $result / $perpage; 825 } 826 else 827 { 828 $page = intval($result / $perpage) + 1; 829 } 830 } 831 // Recount replies if user is a moderator to take into account unapproved posts. 832 if($ismod) 833 { 834 $query = $db->simple_select("posts p", "COUNT(*) AS replies", "p.tid='$tid' $visible"); 835 $thread['replies'] = $db->fetch_field($query, 'replies')-1; 836 } 837 $postcount = intval($thread['replies'])+1; 838 $pages = $postcount / $perpage; 839 $pages = ceil($pages); 840 841 if($mybb->input['page'] == "last") 842 { 843 $page = $pages; 844 } 845 846 if($page > $pages || $page <= 0) 847 { 848 $page = 1; 849 } 850 851 if($page) 852 { 853 $start = ($page-1) * $perpage; 854 } 855 else 856 { 857 $start = 0; 858 $page = 1; 859 } 860 $upper = $start+$perpage; 861 862 // Work out if we have terms to highlight 863 $highlight = ""; 864 $threadmode = ""; 865 if($mybb->settings['seourls'] == "yes" || ($mybb->settings['seourls'] == "auto" && $_SERVER['SEO_SUPPORT'] == 1)) 866 { 867 if($mybb->input['highlight']) 868 { 869 $highlight = "?highlight=".urlencode($mybb->input['highlight']); 870 } 871 872 if($defaultmode != "linear") 873 { 874 if($mybb->input['highlight']) 875 { 876 $threadmode = "&mode=linear"; 877 } 878 else 879 { 880 $threadmode = "?mode=linear"; 881 } 882 } 883 } 884 else 885 { 886 if($mybb->input['highlight']) 887 { 888 if(is_array($mybb->input['highlight'])) 889 { 890 foreach($mybb->input['highlight'] as $highlight_word) 891 { 892 $highlight .= "&highlight[]=".urlencode($highlight_word); 893 } 894 } 895 else 896 { 897 $highlight = "&highlight=".urlencode($mybb->input['highlight']); 898 } 899 } 900 901 if($defaultmode != "linear") 902 { 903 $threadmode = "&mode=linear"; 904 } 905 } 906 907 $multipage = multipage($postcount, $perpage, $page, str_replace("{tid}", $tid, THREAD_URL_PAGED.$highlight.$threadmode)); 908 if($postcount > $perpage) 909 { 910 eval("\$threadpages = \"".$templates->get("showthread_multipage")."\";"); 911 } 912 913 // Lets get the pids of the posts on this page. 914 $pids = ""; 915 $comma = ''; 916 $query = $db->simple_select("posts p", "p.pid", "p.tid='$tid' $visible", array('order_by' => 'p.dateline', 'limit_start' => $start, 'limit' => $perpage)); 917 while($getid = $db->fetch_array($query)) 918 { 919 // Set the ID of the first post on page to $pid if it doesn't hold any value 920 // to allow this value to be used for Thread Mode/Linear Mode links 921 // and ensure the user lands on the correct page after changing view mode 922 if(!$pid) 923 { 924 $pid = $getid['pid']; 925 } 926 // Gather a comma separated list of post IDs 927 $pids .= "$comma'{$getid['pid']}'"; 928 $comma = ","; 929 } 930 if($pids) 931 { 932 $pids = "pid IN($pids)"; 933 934 $attachcache = array(); 935 if($thread['attachmentcount'] > 0) 936 { 937 // Now lets fetch all of the attachments for these posts. 938 $query = $db->simple_select("attachments", "*", $pids); 939 while($attachment = $db->fetch_array($query)) 940 { 941 $attachcache[$attachment['pid']][$attachment['aid']] = $attachment; 942 } 943 } 944 } 945 else 946 { 947 // If there are no pid's the thread is probably awaiting approval. 948 error($lang->error_invalidthread); 949 } 950 951 // Get the actual posts from the database here. 952 $posts = ''; 953 $query = $db->query(" 954 SELECT u.*, u.username AS userusername, p.*, f.*, eu.username AS editusername 955 FROM ".TABLE_PREFIX."posts p 956 LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid) 957 LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid) 958 LEFT JOIN ".TABLE_PREFIX."users eu ON (eu.uid=p.edituid) 959 WHERE $pids 960 ORDER BY p.dateline 961 "); 962 while($post = $db->fetch_array($query)) 963 { 964 if($thread['firstpost'] == $post['pid'] && $thread['visible'] == 0) 965 { 966 $post['visible'] = 0; 967 } 968 $posts .= build_postbit($post); 969 $post = ''; 970 } 971 $plugins->run_hooks("showthread_linear"); 972 } 973 974 // Show the similar threads table if wanted. 975 if($mybb->settings['showsimilarthreads'] != 0) 976 { 977 switch($db->type) 978 { 979 case "pgsql": 980 $query = $db->query(" 981 SELECT t.*, t.username AS threadusername, u.username 982 FROM ".TABLE_PREFIX."threads t 983 LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid), plainto_tsquery ('".$db->escape_string($thread['subject'])."') AS query 984 WHERE t.fid='{$thread['fid']}' AND t.tid!='{$thread['tid']}' AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND t.subject @@ query 985 ORDER BY t.lastpost DESC 986 OFFSET 0 LIMIT {$mybb->settings['similarlimit']} 987 "); 988 break; 989 default: 990 $query = $db->query(" 991 SELECT t.*, t.username AS threadusername, u.username, MATCH (t.subject) AGAINST ('".$db->escape_string($thread['subject'])."') AS relevance 992 FROM ".TABLE_PREFIX."threads t 993 LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid) 994 WHERE t.fid='{$thread['fid']}' AND t.tid!='{$thread['tid']}' AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND MATCH (t.subject) AGAINST ('".$db->escape_string($thread['subject'])."') >= '{$mybb->settings['similarityrating']}' 995 ORDER BY t.lastpost DESC 996 LIMIT 0, {$mybb->settings['similarlimit']} 997 "); 998 } 999 1000 $count = 0; 1001 $similarthreadbits = ''; 1002 $icon_cache = $cache->read("posticons"); 1003 while($similar_thread = $db->fetch_array($query)) 1004 { 1005 ++$count; 1006 $trow = alt_trow(); 1007 if($similar_thread['icon'] > 0 && $icon_cache[$similar_thread['icon']]) 1008 { 1009 $icon = $icon_cache[$similar_thread['icon']]; 1010 $icon = "<img src=\"{$icon['path']}\" alt=\"{$icon['name']}\" />"; 1011 } 1012 else 1013 { 1014 $icon = " "; 1015 } 1016 if(!$similar_thread['username']) 1017 { 1018 $similar_thread['username'] = $similar_thread['threadusername']; 1019 $similar_thread['profilelink'] = $similar_thread['threadusername']; 1020 } 1021 else 1022 { 1023 $similar_thread['profilelink'] = build_profile_link($similar_thread['username'], $similar_thread['uid']); 1024 } 1025 1026 // If this thread has a prefix, insert a space between prefix and subject 1027 if($similar_thread['prefix'] != 0) 1028 { 1029 $prefix = build_prefixes($similar_thread['prefix']); 1030 $similar_thread['threadprefix'] = $prefix['displaystyle'].' '; 1031 } 1032 1033 $similar_thread['subject'] = $parser->parse_badwords($similar_thread['subject']); 1034 $similar_thread['subject'] = htmlspecialchars_uni($similar_thread['subject']); 1035 $similar_thread['threadlink'] = get_thread_link($similar_thread['tid']); 1036 $similar_thread['lastpostlink'] = get_thread_link($similar_thread['tid'], 0, "lastpost"); 1037 1038 $lastpostdate = my_date($mybb->settings['dateformat'], $similar_thread['lastpost']); 1039 $lastposttime = my_date($mybb->settings['timeformat'], $similar_thread['lastpost']); 1040 $lastposter = $similar_thread['lastposter']; 1041 $lastposteruid = $similar_thread['lastposteruid']; 1042 1043 // Don't link to guest's profiles (they have no profile). 1044 if($lastposteruid == 0) 1045 { 1046 $lastposterlink = $lastposter; 1047 } 1048 else 1049 { 1050 $lastposterlink = build_profile_link($lastposter, $lastposteruid); 1051 } 1052 $similar_thread['replies'] = my_number_format($similar_thread['replies']); 1053 $similar_thread['views'] = my_number_format($similar_thread['views']); 1054 eval("\$similarthreadbits .= \"".$templates->get("showthread_similarthreads_bit")."\";"); 1055 } 1056 if($count) 1057 { 1058 eval("\$similarthreads = \"".$templates->get("showthread_similarthreads")."\";"); 1059 } 1060 } 1061 1062 // Decide whether or not to show quick reply. 1063 if($forumpermissions['canpostreplys'] != 0 && $mybb->user['suspendposting'] != 1 && ($thread['closed'] != 1 || is_moderator($fid)) && $mybb->settings['quickreply'] != 0 && $mybb->user['showquickreply'] != '0' && $forum['open'] != 0) 1064 { 1065 $query = $db->simple_select("posts", "pid", "tid='{$tid}'", array("order_by" => "pid", "order_dir" => "desc", "limit" => 1)); 1066 $last_pid = $db->fetch_field($query, "pid"); 1067 1068 // Show captcha image for guests if enabled 1069 if($mybb->settings['captchaimage'] && !$mybb->user['uid']) 1070 { 1071 require_once MYBB_ROOT.'inc/class_captcha.php'; 1072 $post_captcha = new captcha(true, "post_captcha"); 1073 1074 if($post_captcha->html) 1075 { 1076 $captcha = $post_captcha->html; 1077 } 1078 } 1079 if($mybb->user['signature']) 1080 { 1081 $postoptionschecked['signature'] = 'checked="checked"'; 1082 } 1083 if($mybb->user['emailnotify'] == 1) 1084 { 1085 $postoptionschecked['emailnotify'] = 'checked="checked"'; 1086 } 1087 $posthash = md5($mybb->user['uid'].random_str()); 1088 1089 eval("\$quickreply = \"".$templates->get("showthread_quickreply")."\";"); 1090 } 1091 else 1092 { 1093 $quickreply = ""; 1094 } 1095 1096 // If the user is a moderator, show the moderation tools. 1097 if($ismod) 1098 { 1099 $customthreadtools = $customposttools = ''; 1100 1101 if(is_moderator($forum['fid'], "canusecustomtools") && ($forum_stats[-1]['modtools'] || $forum_stats[$forum['fid']]['modtools'])) 1102 { 1103 switch($db->type) 1104 { 1105 case "pgsql": 1106 case "sqlite": 1107 $query = $db->simple_select("modtools", "tid, name, type", "','||forums||',' LIKE '%,$fid,%' OR ','||forums||',' LIKE '%,-1,%' OR forums=''"); 1108 break; 1109 default: 1110 $query = $db->simple_select("modtools", "tid, name, type", "CONCAT(',',forums,',') LIKE '%,$fid,%' OR CONCAT(',',forums,',') LIKE '%,-1,%' OR forums=''"); 1111 } 1112 1113 while($tool = $db->fetch_array($query)) 1114 { 1115 if($tool['type'] == 'p') 1116 { 1117 eval("\$customposttools .= \"".$templates->get("showthread_inlinemoderation_custom_tool")."\";"); 1118 } 1119 else 1120 { 1121 eval("\$customthreadtools .= \"".$templates->get("showthread_moderationoptions_custom_tool")."\";"); 1122 } 1123 } 1124 1125 // Build inline moderation dropdown 1126 if(!empty($customposttools)) 1127 { 1128 eval("\$customposttools = \"".$templates->get("showthread_inlinemoderation_custom")."\";"); 1129 } 1130 } 1131 1132 eval("\$inlinemod = \"".$templates->get("showthread_inlinemoderation")."\";"); 1133 1134 // Build thread moderation dropdown 1135 if(!empty($customthreadtools)) 1136 { 1137 eval("\$customthreadtools = \"".$templates->get("showthread_moderationoptions_custom")."\";"); 1138 } 1139 1140 eval("\$moderationoptions = \"".$templates->get("showthread_moderationoptions")."\";"); 1141 } 1142 1143 $lang->newthread_in = $lang->sprintf($lang->newthread_in, $forum['name']); 1144 1145 // Subscription status 1146 $add_remove_subscription = 'add'; 1147 $add_remove_subscription_text = $lang->subscribe_thread; 1148 1149 if($mybb->user['uid']) 1150 { 1151 $query = $db->simple_select("threadsubscriptions", "tid", "tid='".intval($tid)."' AND uid='".intval($mybb->user['uid'])."'", array('limit' => 1)); 1152 1153 if($db->fetch_field($query, 'tid')) 1154 { 1155 $add_remove_subscription = 'remove'; 1156 $add_remove_subscription_text = $lang->unsubscribe_thread; 1157 } 1158 } 1159 1160 if($mybb->settings['postlayout'] == "classic") 1161 { 1162 eval("\$classic_header = \"".$templates->get("showthread_classic_header")."\";"); 1163 } 1164 1165 // Get users viewing this thread 1166 if($mybb->settings['browsingthisthread'] != 0) 1167 { 1168 $timecut = TIME_NOW - $mybb->settings['wolcutoff']; 1169 1170 $comma = ''; 1171 $guestcount = 0; 1172 $membercount = 0; 1173 $inviscount = 0; 1174 $onlinemembers = ''; 1175 $doneusers = array(); 1176 1177 $query = $db->query(" 1178 SELECT s.ip, s.uid, s.time, u.username, u.invisible, u.usergroup, u.displaygroup 1179 FROM ".TABLE_PREFIX."sessions s 1180 LEFT JOIN ".TABLE_PREFIX."users u ON (s.uid=u.uid) 1181 WHERE s.time > '$timecut' AND location2='$tid' AND nopermission != 1 1182 ORDER BY u.username ASC, s.time DESC 1183 "); 1184 1185 while($user = $db->fetch_array($query)) 1186 { 1187 if($user['uid'] == 0) 1188 { 1189 ++$guestcount; 1190 } 1191 else if($doneusers[$user['uid']] < $user['time'] || !$doneusers[$user['uid']]) 1192 { 1193 ++$membercount; 1194 $doneusers[$user['uid']] = $user['time']; 1195 1196 $invisiblemark = ''; 1197 if($user['invisible'] == 1) 1198 { 1199 $invisiblemark = "*"; 1200 ++$inviscount; 1201 } 1202 1203 if($user['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1 || $user['uid'] == $mybb->user['uid']) 1204 { 1205 $user['profilelink'] = get_profile_link($user['uid']); 1206 $user['username'] = format_name($user['username'], $user['usergroup'], $user['displaygroup']); 1207 $user['reading'] = my_date($mybb->settings['timeformat'], $user['time']); 1208 1209 eval("\$onlinemembers .= \"".$templates->get("showthread_usersbrowsing_user", 1, 0)."\";"); 1210 $comma = $lang->comma; 1211 } 1212 } 1213 } 1214 1215 if($guestcount) 1216 { 1217 $guestsonline = $lang->sprintf($lang->users_browsing_thread_guests, $guestcount); 1218 } 1219 1220 if($guestcount && $onlinemembers) 1221 { 1222 $onlinesep = $lang->comma; 1223 } 1224 1225 $invisonline = ''; 1226 if($inviscount && $mybb->usergroup['canviewwolinvis'] != 1 && ($inviscount != 1 && $mybb->user['invisible'] != 1)) 1227 { 1228 $invisonline = $lang->sprintf($lang->users_browsing_thread_invis, $inviscount); 1229 } 1230 1231 if($invisonline != '' && $guestcount) 1232 { 1233 $onlinesep2 = $lang->comma; 1234 } 1235 1236 eval("\$usersbrowsing = \"".$templates->get("showthread_usersbrowsing")."\";"); 1237 } 1238 1239 $plugins->run_hooks("showthread_end"); 1240 1241 eval("\$showthread = \"".$templates->get("showthread")."\";"); 1242 output_page($showthread); 1243 } 1244 1245 /** 1246 * Build a navigation tree for threaded display. 1247 * 1248 * @param unknown_type $replyto 1249 * @param unknown_type $indent 1250 * @return unknown 1251 */ 1252 function buildtree($replyto="0", $indent="0") 1253 { 1254 global $tree, $mybb, $theme, $mybb, $pid, $tid, $templates, $parser; 1255 1256 if($indent) 1257 { 1258 $indentsize = 13 * $indent; 1259 } 1260 else 1261 { 1262 $indentsize = 0; 1263 } 1264 1265 ++$indent; 1266 if(is_array($tree[$replyto])) 1267 { 1268 foreach($tree[$replyto] as $key => $post) 1269 { 1270 $postdate = my_date($mybb->settings['dateformat'], $post['dateline']); 1271 $posttime = my_date($mybb->settings['timeformat'], $post['dateline']); 1272 $post['subject'] = htmlspecialchars_uni($parser->parse_badwords($post['subject'])); 1273 1274 if(!$post['subject']) 1275 { 1276 $post['subject'] = "[".$lang->no_subject."]"; 1277 } 1278 1279 $post['profilelink'] = build_profile_link($post['username'], $post['uid']); 1280 1281 if($mybb->input['pid'] == $post['pid']) 1282 { 1283 eval("\$posts .= \"".$templates->get("showthread_threaded_bitactive")."\";"); 1284 } 1285 else 1286 { 1287 eval("\$posts .= \"".$templates->get("showthread_threaded_bit")."\";"); 1288 } 1289 1290 if($tree[$post['pid']]) 1291 { 1292 $posts .= buildtree($post['pid'], $indent); 1293 } 1294 } 1295 --$indent; 1296 } 1297 return $posts; 1298 } 1299 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Mar 31 17:55:03 2012 | Cross-referenced by PHPXref 0.7.1 |