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