| [ 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: forumdisplay.php 5765 2012-03-27 09:52:45Z Tomm $ 10 */ 11 12 define("IN_MYBB", 1); 13 define('THIS_SCRIPT', 'forumdisplay.php'); 14 15 $templatelist = "forumdisplay,forumdisplay_thread,breadcrumb_bit,forumbit_depth1_cat,forumbit_depth1_forum,forumbit_depth2_cat,forumbit_depth2_forum,forumdisplay_subforums,forumdisplay_threadlist,forumdisplay_moderatedby_moderator,forumdisplay_moderatedby,forumdisplay_newthread,forumdisplay_searchforum,forumdisplay_orderarrow,forumdisplay_thread_rating,forumdisplay_announcement,forumdisplay_threadlist_rating,forumdisplay_threadlist_sortrating,forumdisplay_subforums_modcolumn,forumbit_moderators,forumbit_subforums,forumbit_depth2_forum_lastpost"; 16 $templatelist .= ",forumbit_depth1_forum_lastpost,forumdisplay_thread_multipage_page,forumdisplay_thread_multipage,forumdisplay_thread_multipage_more"; 17 $templatelist .= ",multipage_prevpage,multipage_nextpage,multipage_page_current,multipage_page,multipage_start,multipage_end,multipage"; 18 $templatelist .= ",forumjump_advanced,forumjump_special,forumjump_bit"; 19 $templatelist .= ",forumdisplay_usersbrowsing_guests,forumdisplay_usersbrowsing_user,forumdisplay_usersbrowsing,forumdisplay_inlinemoderation,forumdisplay_thread_modbit,forumdisplay_inlinemoderation_col,forumdisplay_inlinemoderation_selectall"; 20 $templatelist .= ",forumdisplay_announcements_announcement,forumdisplay_announcements,forumdisplay_threads_sep,forumbit_depth3_statusicon,forumbit_depth3,forumdisplay_sticky_sep,forumdisplay_thread_attachment_count,forumdisplay_threadlist_inlineedit_js,forumdisplay_rssdiscovery,forumdisplay_announcement_rating,forumdisplay_announcements_announcement_modbit,forumdisplay_rules,forumdisplay_rules_link,forumdisplay_thread_gotounread,forumdisplay_nothreads,forumdisplay_inlinemoderation_custom_tool,forumdisplay_inlinemoderation_custom"; 21 require_once "./global.php"; 22 require_once MYBB_ROOT."inc/functions_post.php"; 23 require_once MYBB_ROOT."inc/functions_forumlist.php"; 24 require_once MYBB_ROOT."inc/class_parser.php"; 25 $parser = new postParser; 26 27 // Load global language phrases 28 $lang->load("forumdisplay"); 29 30 $plugins->run_hooks("forumdisplay_start"); 31 32 $fid = intval($mybb->input['fid']); 33 if($fid < 0) 34 { 35 switch($fid) 36 { 37 case "-1": 38 $location = "index.php"; 39 break; 40 case "-2": 41 $location = "search.php"; 42 break; 43 case "-3": 44 $location = "usercp.php"; 45 break; 46 case "-4": 47 $location = "private.php"; 48 break; 49 case "-5": 50 $location = "online.php"; 51 break; 52 } 53 if($location) 54 { 55 header("Location: ".$location); 56 exit; 57 } 58 } 59 60 // Get forum info 61 $foruminfo = get_forum($fid); 62 if(!$foruminfo) 63 { 64 error($lang->error_invalidforum); 65 } 66 67 $archive_url = build_archive_link("forum", $fid); 68 69 $currentitem = $fid; 70 build_forum_breadcrumb($fid); 71 $parentlist = $foruminfo['parentlist']; 72 73 // To validate, turn & to & but support unicode 74 $foruminfo['name'] = preg_replace("#&(?!\#[0-9]+;)#si", "&", $foruminfo['name']); 75 76 $forumpermissions = forum_permissions(); 77 $fpermissions = $forumpermissions[$fid]; 78 79 if($fpermissions['canview'] != 1) 80 { 81 error_no_permission(); 82 } 83 84 if($mybb->user['uid'] == 0) 85 { 86 // Cookie'd forum read time 87 $forumsread = my_unserialize($mybb->cookies['mybb']['forumread']); 88 89 if(is_array($forumsread) && empty($forumsread)) 90 { 91 if($mybb->cookies['mybb']['readallforums']) 92 { 93 $forumsread[$fid] = $mybb->cookies['mybb']['lastvisit']; 94 } 95 else 96 { 97 $forumsread = array(); 98 } 99 } 100 101 $query = $db->simple_select("forums", "*", "active != 0", array("order_by" => "pid, disporder")); 102 } 103 else 104 { 105 // Build a forum cache from the database 106 $query = $db->query(" 107 SELECT f.*, fr.dateline AS lastread 108 FROM ".TABLE_PREFIX."forums f 109 LEFT JOIN ".TABLE_PREFIX."forumsread fr ON (fr.fid=f.fid AND fr.uid='{$mybb->user['uid']}') 110 WHERE f.active != 0 111 ORDER BY pid, disporder 112 "); 113 } 114 115 while($forum = $db->fetch_array($query)) 116 { 117 if($mybb->user['uid'] == 0 && $forumsread[$forum['fid']]) 118 { 119 $forum['lastread'] = $forumsread[$forum['fid']]; 120 } 121 122 $fcache[$forum['pid']][$forum['disporder']][$forum['fid']] = $forum; 123 } 124 125 // Get the forum moderators if the setting is enabled. 126 if($mybb->settings['modlist'] != 0) 127 { 128 $moderatorcache = $cache->read("moderators"); 129 } 130 131 $bgcolor = "trow1"; 132 if($mybb->settings['subforumsindex'] != 0) 133 { 134 $showdepth = 3; 135 } 136 else 137 { 138 $showdepth = 2; 139 } 140 $child_forums = build_forumbits($fid, 2); 141 $forums = $child_forums['forum_list']; 142 if($forums) 143 { 144 $lang->sub_forums_in = $lang->sprintf($lang->sub_forums_in, $foruminfo['name']); 145 eval("\$subforums = \"".$templates->get("forumdisplay_subforums")."\";"); 146 } 147 148 $excols = "forumdisplay"; 149 150 // Password protected forums 151 check_forum_password($foruminfo['fid']); 152 153 if($foruminfo['linkto']) 154 { 155 header("Location: {$foruminfo['linkto']}"); 156 exit; 157 } 158 159 // Make forum jump... 160 if($mybb->settings['enableforumjump'] != 0) 161 { 162 $forumjump = build_forum_jump("", $fid, 1); 163 } 164 165 if($foruminfo['type'] == "f" && $foruminfo['open'] != 0) 166 { 167 eval("\$newthread = \"".$templates->get("forumdisplay_newthread")."\";"); 168 } 169 170 if($fpermissions['cansearch'] != 0 && $foruminfo['type'] == "f") 171 { 172 eval("\$searchforum = \"".$templates->get("forumdisplay_searchforum")."\";"); 173 } 174 175 // Gather forum stats 176 $has_announcements = $has_modtools = false; 177 $forum_stats = $cache->read("forumsdisplay"); 178 179 if(is_array($forum_stats)) 180 { 181 if($forum_stats[-1]['modtools'] || $forum_stats[$fid]['modtools']) 182 { 183 // Mod tools are specific to forums, not parents 184 $has_modtools = true; 185 } 186 187 if($forum_stats[-1]['announcements'] || $forum_stats[$fid]['announcements']) 188 { 189 // Global or forum-specific announcements 190 $has_announcements = true; 191 } 192 } 193 194 $done_moderators = array( 195 "users" => array(), 196 "groups" => array() 197 ); 198 199 $moderators = ''; 200 $parentlistexploded = explode(",", $parentlist); 201 202 foreach($parentlistexploded as $mfid) 203 { 204 // This forum has moderators 205 if(is_array($moderatorcache[$mfid])) 206 { 207 // Fetch each moderator from the cache and format it, appending it to the list 208 foreach($moderatorcache[$mfid] as $modtype) 209 { 210 foreach($modtype as $moderator) 211 { 212 if($moderator['isgroup']) 213 { 214 if(in_array($moderator['id'], $done_moderators['groups'])) 215 { 216 continue; 217 } 218 $moderators .= $comma.htmlspecialchars_uni($moderator['title']); 219 $done_moderators['groups'][] = $moderator['id']; 220 } 221 else 222 { 223 if(in_array($moderator['id'], $done_moderators['users'])) 224 { 225 continue; 226 } 227 $moderators .= "{$comma}<a href=\"".get_profile_link($moderator['id'])."\">".format_name(htmlspecialchars_uni($moderator['username']), $moderator['usergroup'], $moderator['displaygroup'])."</a>"; 228 $done_moderators['users'][] = $moderator['id']; 229 } 230 $comma = $lang->comma; 231 } 232 } 233 } 234 235 if($forum_stats[$mfid]['announcements']) 236 { 237 $has_announcements = true; 238 } 239 } 240 $comma = ''; 241 242 // If we have a moderators list, load the template 243 if($moderators) 244 { 245 eval("\$moderatedby = \"".$templates->get("forumdisplay_moderatedby")."\";"); 246 } 247 else 248 { 249 $moderatedby = ''; 250 } 251 252 // Get the users browsing this forum. 253 if($mybb->settings['browsingthisforum'] != 0) 254 { 255 $timecut = TIME_NOW - $mybb->settings['wolcutoff']; 256 257 $comma = ''; 258 $guestcount = 0; 259 $membercount = 0; 260 $inviscount = 0; 261 $onlinemembers = ''; 262 $query = $db->query(" 263 SELECT s.ip, s.uid, u.username, s.time, u.invisible, u.usergroup, u.usergroup, u.displaygroup 264 FROM ".TABLE_PREFIX."sessions s 265 LEFT JOIN ".TABLE_PREFIX."users u ON (s.uid=u.uid) 266 WHERE s.time > '$timecut' AND location1='$fid' AND nopermission != 1 267 ORDER BY u.username ASC, s.time DESC 268 "); 269 while($user = $db->fetch_array($query)) 270 { 271 if($user['uid'] == 0) 272 { 273 ++$guestcount; 274 } 275 else 276 { 277 if($doneusers[$user['uid']] < $user['time'] || !$doneusers[$user['uid']]) 278 { 279 $doneusers[$user['uid']] = $user['time']; 280 ++$membercount; 281 if($user['invisible'] == 1) 282 { 283 $invisiblemark = "*"; 284 ++$inviscount; 285 } 286 else 287 { 288 $invisiblemark = ''; 289 } 290 291 if($user['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1 || $user['uid'] == $mybb->user['uid']) 292 { 293 $user['username'] = format_name($user['username'], $user['usergroup'], $user['displaygroup']); 294 $user['profilelink'] = build_profile_link($user['username'], $user['uid']); 295 eval("\$onlinemembers .= \"".$templates->get("forumdisplay_usersbrowsing_user", 1, 0)."\";"); 296 $comma = $lang->comma; 297 } 298 } 299 } 300 } 301 302 if($guestcount) 303 { 304 $guestsonline = $lang->sprintf($lang->users_browsing_forum_guests, $guestcount); 305 } 306 307 if($guestcount && $onlinemembers) 308 { 309 $onlinesep = $lang->comma; 310 } 311 312 $invisonline = ''; 313 if($inviscount && $mybb->usergroup['canviewwolinvis'] != 1 && ($inviscount != 1 && $mybb->user['invisible'] != 1)) 314 { 315 $invisonline = $lang->sprintf($lang->users_browsing_forum_invis, $inviscount); 316 } 317 318 if($invisonline != '' && $guestcount) 319 { 320 $onlinesep2 = $lang->comma; 321 } 322 eval("\$usersbrowsing = \"".$templates->get("forumdisplay_usersbrowsing")."\";"); 323 } 324 325 // Do we have any forum rules to show for this forum? 326 $forumrules = ''; 327 if($foruminfo['rulestype'] != 0 && $foruminfo['rules']) 328 { 329 if(!$foruminfo['rulestitle']) 330 { 331 $foruminfo['rulestitle'] = $lang->sprintf($lang->forum_rules, $foruminfo['name']); 332 } 333 334 $rules_parser = array( 335 "allow_html" => 1, 336 "allow_mycode" => 1, 337 "allow_smilies" => 1, 338 "allow_imgcode" => 1 339 ); 340 341 $foruminfo['rules'] = $parser->parse_message($foruminfo['rules'], $rules_parser); 342 if($foruminfo['rulestype'] == 1 || $foruminfo['rulestype'] == 3) 343 { 344 eval("\$rules = \"".$templates->get("forumdisplay_rules")."\";"); 345 } 346 else if($foruminfo['rulestype'] == 2) 347 { 348 eval("\$rules = \"".$templates->get("forumdisplay_rules_link")."\";"); 349 } 350 } 351 352 $bgcolor = "trow1"; 353 354 // Set here to fetch only approved topics (and then below for a moderator we change this). 355 $visibleonly = "AND visible='1'"; 356 $tvisibleonly = "AND t.visible='1'"; 357 358 // Check if the active user is a moderator and get the inline moderation tools. 359 if(is_moderator($fid)) 360 { 361 eval("\$inlinemodcol = \"".$templates->get("forumdisplay_inlinemoderation_col")."\";"); 362 $ismod = true; 363 $inlinecount = "0"; 364 $inlinecookie = "inlinemod_forum".$fid; 365 $visibleonly = " AND (visible='1' OR visible='0')"; 366 $tvisibleonly = " AND (t.visible='1' OR t.visible='0')"; 367 } 368 else 369 { 370 $inlinemod = ''; 371 $ismod = false; 372 } 373 374 if(is_moderator($fid, "caneditposts") || $fpermissions['caneditposts'] == 1) 375 { 376 $can_edit_titles = 1; 377 } 378 else 379 { 380 $can_edit_titles = 0; 381 } 382 383 unset($rating); 384 385 // Pick out some sorting options. 386 // First, the date cut for the threads. 387 $datecut = 0; 388 if(!$mybb->input['datecut']) 389 { 390 // If the user manually set a date cut, use it. 391 if($mybb->user['daysprune']) 392 { 393 $datecut = $mybb->user['daysprune']; 394 } 395 else 396 { 397 // If the forum has a non-default date cut, use it. 398 if(!empty($foruminfo['defaultdatecut'])) 399 { 400 $datecut = $foruminfo['defaultdatecut']; 401 } 402 } 403 } 404 // If there was a manual date cut override, use it. 405 else 406 { 407 $datecut = intval($mybb->input['datecut']); 408 } 409 410 $datecut = intval($datecut); 411 $datecutsel[$datecut] = "selected=\"selected\""; 412 if($datecut > 0 && $datecut != 9999) 413 { 414 $checkdate = TIME_NOW - ($datecut * 86400); 415 $datecutsql = "AND (lastpost >= '$checkdate' OR sticky = '1')"; 416 $datecutsql2 = "AND (t.lastpost >= '$checkdate' OR t.sticky = '1')"; 417 } 418 else 419 { 420 $datecutsql = ''; 421 $datecutsql2 = ''; 422 } 423 424 // Pick the sort order. 425 if(!isset($mybb->input['order']) && !empty($foruminfo['defaultsortorder'])) 426 { 427 $mybb->input['order'] = $foruminfo['defaultsortorder']; 428 } 429 430 $mybb->input['order'] = htmlspecialchars($mybb->input['order']); 431 432 switch(my_strtolower($mybb->input['order'])) 433 { 434 case "asc": 435 $sortordernow = "asc"; 436 $ordersel['asc'] = "selected=\"selected\""; 437 $oppsort = $lang->desc; 438 $oppsortnext = "desc"; 439 break; 440 default: 441 $sortordernow = "desc"; 442 $ordersel['desc'] = "selected=\"selected\""; 443 $oppsort = $lang->asc; 444 $oppsortnext = "asc"; 445 break; 446 } 447 448 // Sort by which field? 449 if(!isset($mybb->input['sortby']) && !empty($foruminfo['defaultsortby'])) 450 { 451 $mybb->input['sortby'] = $foruminfo['defaultsortby']; 452 } 453 454 $t = "t."; 455 456 $sortby = htmlspecialchars($mybb->input['sortby']); 457 switch($mybb->input['sortby']) 458 { 459 case "subject": 460 $sortfield = "subject"; 461 break; 462 case "replies": 463 $sortfield = "replies"; 464 break; 465 case "views": 466 $sortfield = "views"; 467 break; 468 case "starter": 469 $sortfield = "username"; 470 break; 471 case "rating": 472 $t = ""; 473 $sortfield = "averagerating"; 474 $sortfield2 = ", t.totalratings DESC"; 475 break; 476 case "started": 477 $sortfield = "dateline"; 478 break; 479 default: 480 $sortby = "lastpost"; 481 $sortfield = "lastpost"; 482 $mybb->input['sortby'] = "lastpost"; 483 break; 484 } 485 486 $sortsel[$mybb->input['sortby']] = "selected=\"selected\""; 487 488 // Pick the right string to join the sort URL 489 if($mybb->settings['seourls'] == "yes" || ($mybb->settings['seourls'] == "auto" && $_SERVER['SEO_SUPPORT'] == 1)) 490 { 491 $string = "?"; 492 } 493 else 494 { 495 $string = "&"; 496 } 497 498 // Are we viewing a specific page? 499 if(isset($mybb->input['page']) && is_numeric($mybb->input['page'])) 500 { 501 $sorturl = get_forum_link($fid, $mybb->input['page']).$string."datecut=$datecut"; 502 } 503 else 504 { 505 $sorturl = get_forum_link($fid).$string."datecut=$datecut"; 506 } 507 eval("\$orderarrow['$sortby'] = \"".$templates->get("forumdisplay_orderarrow")."\";"); 508 509 $threadcount = 0; 510 $useronly = $tuseronly = ""; 511 if($fpermissions['canonlyviewownthreads'] == 1) 512 { 513 $useronly = "AND uid={$mybb->user['uid']}"; 514 $tuseronly = "AND t.uid={$mybb->user['uid']}"; 515 } 516 517 if($fpermissions['canviewthreads'] != 0) 518 { 519 520 // How many posts are there? 521 if($datecut > 0 || $fpermissions['canonlyviewownthreads'] == 1) 522 { 523 $query = $db->simple_select("threads", "COUNT(tid) AS threads", "fid = '$fid' $useronly $visibleonly $datecutsql"); 524 $threadcount = $db->fetch_field($query, "threads"); 525 } 526 else 527 { 528 $query = $db->simple_select("forums", "threads, unapprovedthreads", "fid = '{$fid}'", array('limit' => 1)); 529 $forum_threads = $db->fetch_array($query); 530 $threadcount = $forum_threads['threads']; 531 if($ismod == true) 532 { 533 $threadcount += $forum_threads['unapprovedthreads']; 534 } 535 536 // If we have 0 threads double check there aren't any "moved" threads 537 if($threadcount == 0) 538 { 539 $query = $db->simple_select("threads", "COUNT(tid) AS threads", "fid = '$fid' $useronly $visibleonly", array('limit' => 1)); 540 $threadcount = $db->fetch_field($query, "threads"); 541 } 542 } 543 } 544 545 // How many pages are there? 546 if(!$mybb->settings['threadsperpage']) 547 { 548 $mybb->settings['threadsperpage'] = 20; 549 } 550 551 $perpage = $mybb->settings['threadsperpage']; 552 553 if(intval($mybb->input['page']) > 0) 554 { 555 $page = intval($mybb->input['page']); 556 $start = ($page-1) * $perpage; 557 $pages = $threadcount / $perpage; 558 $pages = ceil($pages); 559 if($page > $pages || $page <= 0) 560 { 561 $start = 0; 562 $page = 1; 563 } 564 } 565 else 566 { 567 $start = 0; 568 $page = 1; 569 } 570 571 $end = $start + $perpage; 572 $lower = $start + 1; 573 $upper = $end; 574 575 if($upper > $threadcount) 576 { 577 $upper = $threadcount; 578 } 579 580 // Assemble page URL 581 if($mybb->input['sortby'] || $mybb->input['order'] || $mybb->input['datecut']) // Ugly URL 582 { 583 $page_url = str_replace("{fid}", $fid, FORUM_URL_PAGED); 584 585 if($mybb->settings['seourls'] == "yes" || ($mybb->settings['seourls'] == "auto" && $_SERVER['SEO_SUPPORT'] == 1)) 586 { 587 $q = "?"; 588 $and = ''; 589 } 590 else 591 { 592 $q = ''; 593 $and = "&"; 594 } 595 596 if($sortby != "lastpost") 597 { 598 $page_url .= "{$q}{$and}sortby={$sortby}"; 599 $q = ''; 600 $and = "&"; 601 } 602 603 if($sortordernow != "desc") 604 { 605 $page_url .= "{$q}{$and}order={$sortordernow}"; 606 $q = ''; 607 $and = "&"; 608 } 609 610 if($datecut > 0) 611 { 612 $page_url .= "{$q}{$and}datecut={$datecut}"; 613 } 614 } 615 else 616 { 617 $page_url = str_replace("{fid}", $fid, FORUM_URL_PAGED); 618 } 619 $multipage = multipage($threadcount, $perpage, $page, $page_url); 620 621 if($mybb->settings['allowthreadratings'] != 0 && $foruminfo['allowtratings'] != 0 && $fpermissions['canviewthreads'] != 0) 622 { 623 $lang->load("ratethread"); 624 625 switch($db->type) 626 { 627 case "pgsql": 628 $ratingadd = "CASE WHEN t.numratings=0 THEN 0 ELSE t.totalratings/t.numratings::numeric END AS averagerating, "; 629 break; 630 default: 631 $ratingadd = "(t.totalratings/t.numratings) AS averagerating, "; 632 } 633 634 $lpbackground = "trow2"; 635 eval("\$ratingcol = \"".$templates->get("forumdisplay_threadlist_rating")."\";"); 636 eval("\$ratingsort = \"".$templates->get("forumdisplay_threadlist_sortrating")."\";"); 637 $colspan = "7"; 638 } 639 else 640 { 641 if($sortfield == "averagerating") 642 { 643 $t = "t."; 644 $sortfield = "lastpost"; 645 } 646 $ratingadd = ''; 647 $lpbackground = "trow1"; 648 $colspan = "6"; 649 } 650 651 if($ismod) 652 { 653 ++$colspan; 654 } 655 656 // Get Announcements 657 if($has_announcements == true) 658 { 659 $limit = ''; 660 $announcements = ''; 661 if($mybb->settings['announcementlimit']) 662 { 663 $limit = "LIMIT 0, ".$mybb->settings['announcementlimit']; 664 } 665 666 $sql = build_parent_list($fid, "fid", "OR", $parentlist); 667 $time = TIME_NOW; 668 $query = $db->query(" 669 SELECT a.*, u.username 670 FROM ".TABLE_PREFIX."announcements a 671 LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=a.uid) 672 WHERE a.startdate<='$time' AND (a.enddate>='$time' OR a.enddate='0') AND ($sql OR fid='-1') 673 ORDER BY a.startdate DESC $limit 674 "); 675 676 // See if this announcement has been read in our announcement array 677 $cookie = array(); 678 if(isset($mybb->cookies['mybb']['announcements'])) 679 { 680 $cookie = my_unserialize(stripslashes($mybb->cookies['mybb']['announcements'])); 681 } 682 683 $bgcolor = alt_trow(true); // Reset the trow colors 684 while($announcement = $db->fetch_array($query)) 685 { 686 if($announcement['startdate'] > $mybb->user['lastvisit'] && !$cookie[$announcement['aid']]) 687 { 688 $new_class = ' class="subject_new"'; 689 $folder = "newfolder"; 690 } 691 else 692 { 693 $new_class = ' class="subject_old"'; 694 $folder = "folder"; 695 } 696 697 // Mmm, eat those announcement cookies if they're older than our last visit 698 if($cookie[$announcement['aid']] < $mybb->user['lastvisit']) 699 { 700 unset($cookie[$announcement['aid']]); 701 } 702 703 $announcement['announcementlink'] = get_announcement_link($announcement['aid']); 704 $announcement['subject'] = $parser->parse_badwords($announcement['subject']); 705 $announcement['subject'] = htmlspecialchars_uni($announcement['subject']); 706 $postdate = my_date($mybb->settings['dateformat'], $announcement['startdate']); 707 $posttime = my_date($mybb->settings['timeformat'], $announcement['startdate']); 708 $announcement['profilelink'] = build_profile_link($announcement['username'], $announcement['uid']); 709 710 if($mybb->settings['allowthreadratings'] != 0 && $foruminfo['allowtratings'] != 0 && $fpermissions['canviewthreads'] != 0) 711 { 712 eval("\$rating = \"".$templates->get("forumdisplay_announcement_rating")."\";"); 713 $lpbackground = "trow2"; 714 } 715 else 716 { 717 $rating = ''; 718 $lpbackground = "trow1"; 719 } 720 721 if($ismod) 722 { 723 eval("\$modann = \"".$templates->get("forumdisplay_announcements_announcement_modbit")."\";"); 724 } 725 else 726 { 727 $modann = ''; 728 } 729 730 $plugins->run_hooks("forumdisplay_announcement"); 731 eval("\$announcements .= \"".$templates->get("forumdisplay_announcements_announcement")."\";"); 732 $bgcolor = alt_trow(); 733 } 734 735 if($announcements) 736 { 737 eval("\$announcementlist = \"".$templates->get("forumdisplay_announcements")."\";"); 738 $shownormalsep = true; 739 } 740 741 if(empty($cookie)) 742 { 743 // Clean up cookie crumbs 744 my_setcookie('mybb[announcements]', 0, (TIME_NOW - (60*60*24*365))); 745 } 746 else if(!empty($cookie)) 747 { 748 my_setcookie("mybb[announcements]", addslashes(serialize($cookie)), -1); 749 } 750 } 751 752 $icon_cache = $cache->read("posticons"); 753 754 if($fpermissions['canviewthreads'] != 0) 755 { 756 // Start Getting Threads 757 $query = $db->query(" 758 SELECT t.*, {$ratingadd}t.username AS threadusername, u.username 759 FROM ".TABLE_PREFIX."threads t 760 LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid) 761 WHERE t.fid='$fid' $tuseronly $tvisibleonly $datecutsql2 762 ORDER BY t.sticky DESC, {$t}{$sortfield} $sortordernow $sortfield2 763 LIMIT $start, $perpage 764 "); 765 766 $ratings = false; 767 while($thread = $db->fetch_array($query)) 768 { 769 $threadcache[$thread['tid']] = $thread; 770 771 if($thread['numratings'] > 0 && $ratings == false) 772 { 773 $ratings = true; // Looks for ratings in the forum 774 } 775 776 // If this is a moved thread - set the tid for participation marking and thread read marking to that of the moved thread 777 if(substr($thread['closed'], 0, 5) == "moved") 778 { 779 $tid = substr($thread['closed'], 6); 780 if(!$tids[$tid]) 781 { 782 $moved_threads[$tid] = $thread['tid']; 783 $tids[$thread['tid']] = $tid; 784 } 785 } 786 // Otherwise - set it to the plain thread ID 787 else 788 { 789 $tids[$thread['tid']] = $thread['tid']; 790 if($moved_threads[$tid]) 791 { 792 unset($moved_threads[$tid]); 793 } 794 } 795 } 796 797 if($mybb->settings['allowthreadratings'] != 0 && $foruminfo['allowtratings'] != 0 && $mybb->user['uid'] && $tids && $ratings == true) 798 { 799 // Check if we've rated threads on this page 800 // Guests get the pleasure of not being ID'd, but will be checked when they try and rate 801 $imp = implode(",", $tids); 802 $query = $db->simple_select("threadratings", "tid, uid", "tid IN ({$imp}) AND uid = '{$mybb->user['uid']}'"); 803 804 while($rating = $db->fetch_array($query)) 805 { 806 $threadcache[$rating['tid']]['rated'] = 1; 807 } 808 } 809 } 810 else 811 { 812 $threadcache = $tids = null; 813 } 814 815 // If user has moderation tools available, prepare the Select All feature 816 $num_results = $db->num_rows($query); 817 if(is_moderator($fid) && $num_results > 0) 818 { 819 $lang->page_selected = $lang->sprintf($lang->page_selected, intval($num_results)); 820 $lang->select_all = $lang->sprintf($lang->select_all, intval($threadcount)); 821 $lang->all_selected = $lang->sprintf($lang->all_selected, intval($threadcount)); 822 eval("\$selectall = \"".$templates->get("forumdisplay_inlinemoderation_selectall")."\";"); 823 } 824 825 if($tids) 826 { 827 $tids = implode(",", $tids); 828 } 829 830 // Check participation by the current user in any of these threads - for 'dot' folder icons 831 if($mybb->settings['dotfolders'] != 0 && $mybb->user['uid'] && $threadcache) 832 { 833 $query = $db->simple_select("posts", "tid,uid", "uid='{$mybb->user['uid']}' AND tid IN ({$tids}) {$visibleonly}"); 834 while($post = $db->fetch_array($query)) 835 { 836 if($moved_threads[$post['tid']]) 837 { 838 $post['tid'] = $moved_threads[$post['tid']]; 839 } 840 if($threadcache[$post['tid']]) 841 { 842 $threadcache[$post['tid']]['doticon'] = 1; 843 } 844 } 845 } 846 847 // Read threads 848 if($mybb->user['uid'] && $mybb->settings['threadreadcut'] > 0 && $threadcache) 849 { 850 $query = $db->simple_select("threadsread", "*", "uid='{$mybb->user['uid']}' AND tid IN ({$tids})"); 851 while($readthread = $db->fetch_array($query)) 852 { 853 if($moved_threads[$readthread['tid']]) 854 { 855 $readthread['tid'] = $moved_threads[$readthread['tid']]; 856 } 857 if($threadcache[$readthread['tid']]) 858 { 859 $threadcache[$readthread['tid']]['lastread'] = $readthread['dateline']; 860 } 861 } 862 } 863 864 if($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid']) 865 { 866 $query = $db->simple_select("forumsread", "dateline", "fid='{$fid}' AND uid='{$mybb->user['uid']}'"); 867 $forum_read = $db->fetch_field($query, "dateline"); 868 869 $read_cutoff = TIME_NOW-$mybb->settings['threadreadcut']*60*60*24; 870 if($forum_read == 0 || $forum_read < $read_cutoff) 871 { 872 $forum_read = $read_cutoff; 873 } 874 } 875 else 876 { 877 $forum_read = my_get_array_cookie("forumread", $fid); 878 879 if($mybb->cookies['mybb']['readallforums'] && !$forum_read) 880 { 881 $forum_read = $mybb->cookies['mybb']['lastvisit']; 882 } 883 } 884 885 $unreadpost = 0; 886 $threads = ''; 887 $load_inline_edit_js = 0; 888 if(is_array($threadcache)) 889 { 890 foreach($threadcache as $thread) 891 { 892 $plugins->run_hooks("forumdisplay_thread"); 893 894 $moved = explode("|", $thread['closed']); 895 896 if($thread['visible'] == 0) 897 { 898 $bgcolor = "trow_shaded"; 899 } 900 else 901 { 902 $bgcolor = alt_trow(); 903 } 904 905 if($thread['sticky'] == 1) 906 { 907 $thread_type_class = " forumdisplay_sticky"; 908 } 909 else 910 { 911 $thread_type_class = " forumdisplay_regular"; 912 } 913 914 $folder = ''; 915 $prefix = ''; 916 917 $thread['author'] = $thread['uid']; 918 if(!$thread['username']) 919 { 920 $thread['username'] = $thread['threadusername']; 921 $thread['profilelink'] = $thread['threadusername']; 922 } 923 else 924 { 925 $thread['profilelink'] = build_profile_link($thread['username'], $thread['uid']); 926 } 927 928 // If this thread has a prefix, insert a space between prefix and subject 929 $threadprefix = ''; 930 if($thread['prefix'] != 0) 931 { 932 $threadprefix = build_prefixes($thread['prefix']); 933 $thread['threadprefix'] = $threadprefix['displaystyle'].' '; 934 } 935 936 $thread['subject'] = $parser->parse_badwords($thread['subject']); 937 $thread['subject'] = htmlspecialchars_uni($thread['subject']); 938 939 if($thread['icon'] > 0 && $icon_cache[$thread['icon']]) 940 { 941 $icon = $icon_cache[$thread['icon']]; 942 $icon = "<img src=\"{$icon['path']}\" alt=\"{$icon['name']}\" />"; 943 } 944 else 945 { 946 $icon = " "; 947 } 948 949 $prefix = ''; 950 if($thread['poll']) 951 { 952 $prefix = $lang->poll_prefix; 953 } 954 955 if($thread['sticky'] == "1" && !$donestickysep) 956 { 957 eval("\$threads .= \"".$templates->get("forumdisplay_sticky_sep")."\";"); 958 $shownormalsep = true; 959 $donestickysep = true; 960 } 961 else if($thread['sticky'] == 0 && $shownormalsep) 962 { 963 eval("\$threads .= \"".$templates->get("forumdisplay_threads_sep")."\";"); 964 $shownormalsep = false; 965 } 966 967 $rating = ''; 968 if($mybb->settings['allowthreadratings'] != 0 && $foruminfo['allowtratings'] != 0) 969 { 970 if($moved[0] == "moved") 971 { 972 $rating = "<td class=\"{$bgcolor}\" style=\"text-align: center;\">-</td>"; 973 } 974 else 975 { 976 $thread['averagerating'] = floatval(round($thread['averagerating'], 2)); 977 $thread['width'] = intval(round($thread['averagerating']))*20; 978 $thread['numratings'] = intval($thread['numratings']); 979 980 $not_rated = ''; 981 if(!$thread['rated']) 982 { 983 $not_rated = ' star_rating_notrated'; 984 } 985 986 $ratingvotesav = $lang->sprintf($lang->rating_votes_average, $thread['numratings'], $thread['averagerating']); 987 eval("\$rating = \"".$templates->get("forumdisplay_thread_rating")."\";"); 988 } 989 } 990 991 $thread['pages'] = 0; 992 $thread['multipage'] = ''; 993 $threadpages = ''; 994 $morelink = ''; 995 $thread['posts'] = $thread['replies'] + 1; 996 997 if(!$mybb->settings['postsperpage']) 998 { 999 $mybb->settings['postperpage'] = 20; 1000 } 1001 1002 if($thread['unapprovedposts'] > 0 && $ismod) 1003 { 1004 $thread['posts'] += $thread['unapprovedposts']; 1005 } 1006 1007 if($thread['posts'] > $mybb->settings['postsperpage']) 1008 { 1009 $thread['pages'] = $thread['posts'] / $mybb->settings['postsperpage']; 1010 $thread['pages'] = ceil($thread['pages']); 1011 1012 if($thread['pages'] > 5) 1013 { 1014 $pagesstop = 4; 1015 $page_link = get_thread_link($thread['tid'], $thread['pages']); 1016 eval("\$morelink = \"".$templates->get("forumdisplay_thread_multipage_more")."\";"); 1017 } 1018 else 1019 { 1020 $pagesstop = $thread['pages']; 1021 } 1022 1023 for($i = 1; $i <= $pagesstop; ++$i) 1024 { 1025 $page_link = get_thread_link($thread['tid'], $i); 1026 eval("\$threadpages .= \"".$templates->get("forumdisplay_thread_multipage_page")."\";"); 1027 } 1028 1029 eval("\$thread['multipage'] = \"".$templates->get("forumdisplay_thread_multipage")."\";"); 1030 } 1031 else 1032 { 1033 $threadpages = ''; 1034 $morelink = ''; 1035 $thread['multipage'] = ''; 1036 } 1037 1038 if($ismod) 1039 { 1040 if(my_strpos($mybb->cookies[$inlinecookie], "|{$thread['tid']}|")) 1041 { 1042 $inlinecheck = "checked=\"checked\""; 1043 ++$inlinecount; 1044 } 1045 else 1046 { 1047 $inlinecheck = ''; 1048 } 1049 1050 $multitid = $thread['tid']; 1051 eval("\$modbit = \"".$templates->get("forumdisplay_thread_modbit")."\";"); 1052 } 1053 else 1054 { 1055 $modbit = ''; 1056 } 1057 1058 if($moved[0] == "moved") 1059 { 1060 $prefix = $lang->moved_prefix; 1061 $thread['tid'] = $moved[1]; 1062 $thread['replies'] = "-"; 1063 $thread['views'] = "-"; 1064 } 1065 1066 $thread['threadlink'] = get_thread_link($thread['tid']); 1067 $thread['lastpostlink'] = get_thread_link($thread['tid'], 0, "lastpost"); 1068 1069 // Determine the folder 1070 $folder = ''; 1071 $folder_label = ''; 1072 1073 if($thread['doticon']) 1074 { 1075 $folder = "dot_"; 1076 $folder_label .= $lang->icon_dot; 1077 } 1078 1079 $gotounread = ''; 1080 $isnew = 0; 1081 $donenew = 0; 1082 1083 if($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid'] && $thread['lastpost'] > $forum_read) 1084 { 1085 if($thread['lastread']) 1086 { 1087 $last_read = $thread['lastread']; 1088 } 1089 else 1090 { 1091 $last_read = $read_cutoff; 1092 } 1093 } 1094 else 1095 { 1096 $last_read = my_get_array_cookie("threadread", $thread['tid']); 1097 } 1098 1099 if($forum_read > $last_read) 1100 { 1101 $last_read = $forum_read; 1102 } 1103 1104 if($thread['lastpost'] > $last_read && $moved[0] != "moved") 1105 { 1106 $folder .= "new"; 1107 $folder_label .= $lang->icon_new; 1108 $new_class = "subject_new"; 1109 $thread['newpostlink'] = get_thread_link($thread['tid'], 0, "newpost"); 1110 eval("\$gotounread = \"".$templates->get("forumdisplay_thread_gotounread")."\";"); 1111 $unreadpost = 1; 1112 } 1113 else 1114 { 1115 $folder_label .= $lang->icon_no_new; 1116 $new_class = "subject_old"; 1117 } 1118 1119 if($thread['replies'] >= $mybb->settings['hottopic'] || $thread['views'] >= $mybb->settings['hottopicviews']) 1120 { 1121 $folder .= "hot"; 1122 $folder_label .= $lang->icon_hot; 1123 } 1124 1125 if($thread['closed'] == 1) 1126 { 1127 $folder .= "lock"; 1128 $folder_label .= $lang->icon_lock; 1129 } 1130 1131 if($moved[0] == "moved") 1132 { 1133 $folder = "move"; 1134 $gotounread = ''; 1135 } 1136 1137 $folder .= "folder"; 1138 1139 $inline_edit_tid = $thread['tid']; 1140 1141 // If this user is the author of the thread and it is not closed or they are a moderator, they can edit 1142 if(($thread['uid'] == $mybb->user['uid'] && $thread['closed'] != 1 && $mybb->user['uid'] != 0 && $can_edit_titles == 1) || $ismod == true) 1143 { 1144 $inline_edit_class = "subject_editable"; 1145 } 1146 else 1147 { 1148 $inline_edit_class = ""; 1149 } 1150 $load_inline_edit_js = 1; 1151 1152 $lastpostdate = my_date($mybb->settings['dateformat'], $thread['lastpost']); 1153 $lastposttime = my_date($mybb->settings['timeformat'], $thread['lastpost']); 1154 $lastposter = $thread['lastposter']; 1155 $lastposteruid = $thread['lastposteruid']; 1156 1157 // Don't link to guest's profiles (they have no profile). 1158 if($lastposteruid == 0) 1159 { 1160 $lastposterlink = $lastposter; 1161 } 1162 else 1163 { 1164 $lastposterlink = build_profile_link($lastposter, $lastposteruid); 1165 } 1166 1167 $thread['replies'] = my_number_format($thread['replies']); 1168 $thread['views'] = my_number_format($thread['views']); 1169 1170 // Threads and posts requiring moderation 1171 if($thread['unapprovedposts'] > 0 && $ismod) 1172 { 1173 if($thread['unapprovedposts'] > 1) 1174 { 1175 $unapproved_posts_count = $lang->sprintf($lang->thread_unapproved_posts_count, $thread['unapprovedposts']); 1176 } 1177 else 1178 { 1179 $unapproved_posts_count = $lang->sprintf($lang->thread_unapproved_post_count, 1); 1180 } 1181 1182 $unapproved_posts = " <span title=\"{$unapproved_posts_count}\">(".my_number_format($thread['unapprovedposts']).")</span>"; 1183 } 1184 else 1185 { 1186 $unapproved_posts = ''; 1187 } 1188 1189 // If this thread has 1 or more attachments show the papperclip 1190 if($thread['attachmentcount'] > 0) 1191 { 1192 if($thread['attachmentcount'] > 1) 1193 { 1194 $attachment_count = $lang->sprintf($lang->attachment_count_multiple, $thread['attachmentcount']); 1195 } 1196 else 1197 { 1198 $attachment_count = $lang->attachment_count; 1199 } 1200 1201 eval("\$attachment_count = \"".$templates->get("forumdisplay_thread_attachment_count")."\";"); 1202 } 1203 else 1204 { 1205 $attachment_count = ''; 1206 } 1207 1208 eval("\$threads .= \"".$templates->get("forumdisplay_thread")."\";"); 1209 } 1210 1211 $customthreadtools = ''; 1212 if($ismod) 1213 { 1214 if(is_moderator($fid, "canusecustomtools") && $has_modtools == true) 1215 { 1216 switch($db->type) 1217 { 1218 case "pgsql": 1219 case "sqlite": 1220 $query = $db->simple_select("modtools", 'tid, name', "(','||forums||',' LIKE '%,$fid,%' OR ','||forums||',' LIKE '%,-1,%' OR forums='') AND type = 't'"); 1221 break; 1222 default: 1223 $query = $db->simple_select("modtools", 'tid, name', "(CONCAT(',',forums,',') LIKE '%,$fid,%' OR CONCAT(',',forums,',') LIKE '%,-1,%' OR forums='') AND type = 't'"); 1224 } 1225 1226 while($tool = $db->fetch_array($query)) 1227 { 1228 eval("\$customthreadtools .= \"".$templates->get("forumdisplay_inlinemoderation_custom_tool")."\";"); 1229 } 1230 1231 if($customthreadtools) 1232 { 1233 eval("\$customthreadtools = \"".$templates->get("forumdisplay_inlinemoderation_custom")."\";"); 1234 } 1235 } 1236 1237 eval("\$inlinemod = \"".$templates->get("forumdisplay_inlinemoderation")."\";"); 1238 } 1239 } 1240 1241 // If there are no unread threads in this forum and no unread child forums - mark it as read 1242 require_once MYBB_ROOT."inc/functions_indicators.php"; 1243 1244 $unread_threads = fetch_unread_count($fid); 1245 if($unread_threads !== false && $unread_threads == 0 && $unread_forums == 0) 1246 { 1247 mark_forum_read($fid); 1248 } 1249 1250 // Subscription status 1251 $add_remove_subscription = 'add'; 1252 $add_remove_subscription_text = $lang->subscribe_forum; 1253 1254 if($mybb->user['uid']) 1255 { 1256 $query = $db->simple_select("forumsubscriptions", "fid", "fid='".$fid."' AND uid='{$mybb->user['uid']}'", array('limit' => 1)); 1257 1258 if($db->fetch_field($query, 'fid')) 1259 { 1260 $add_remove_subscription = 'remove'; 1261 $add_remove_subscription_text = $lang->unsubscribe_forum; 1262 } 1263 } 1264 1265 // Is this a real forum with threads? 1266 if($foruminfo['type'] != "c") 1267 { 1268 if(!$threadcount) 1269 { 1270 eval("\$threads = \"".$templates->get("forumdisplay_nothreads")."\";"); 1271 } 1272 1273 if($foruminfo['password'] != '') 1274 { 1275 eval("\$clearstoredpass = \"".$templates->get("forumdisplay_threadlist_clearpass")."\";"); 1276 } 1277 1278 if($load_inline_edit_js == 1) 1279 { 1280 eval("\$inline_edit_js = \"".$templates->get("forumdisplay_threadlist_inlineedit_js")."\";"); 1281 } 1282 1283 $post_code_string = ''; 1284 if($mybb->user['uid']) 1285 { 1286 $post_code_string = "&my_post_key=".$mybb->post_code; 1287 } 1288 1289 $lang->rss_discovery_forum = $lang->sprintf($lang->rss_discovery_forum, htmlspecialchars_uni(strip_tags($foruminfo['name']))); 1290 eval("\$rssdiscovery = \"".$templates->get("forumdisplay_rssdiscovery")."\";"); 1291 eval("\$threadslist = \"".$templates->get("forumdisplay_threadlist")."\";"); 1292 } 1293 else 1294 { 1295 $rssdiscovery = ''; 1296 $threadslist = ''; 1297 1298 if(empty($forums)) 1299 { 1300 error($lang->error_containsnoforums); 1301 } 1302 } 1303 1304 $plugins->run_hooks("forumdisplay_end"); 1305 1306 $foruminfo['name'] = strip_tags($foruminfo['name']); 1307 1308 eval("\$forums = \"".$templates->get("forumdisplay")."\";"); 1309 output_page($forums); 1310 ?>
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 |