[ 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: index.php 5790 2012-04-19 13:52:50Z Tomm $ 10 */ 11 12 define("IN_MYBB", 1); 13 define("IN_ARCHIVE", 1); 14 15 require_once "./global.php"; 16 require_once MYBB_ROOT."inc/functions_post.php"; 17 // Load global language phrases 18 $lang->load("index"); 19 20 $plugins->run_hooks("archive_start"); 21 22 switch($action) 23 { 24 // Display an announcement. 25 case "announcement": 26 // Fetch the forum this thread is in 27 if($announcement['fid'] != -1) 28 { 29 $forum = get_forum($announcement['fid']); 30 if(!$forum['fid'] || $forum['password'] != '') 31 { 32 archive_error($lang->error_invalidforum); 33 } 34 35 // Check if we have permission to view this thread 36 $forumpermissions = forum_permissions($forum['fid']); 37 if($forumpermissions['canview'] != 1 || $forumpermissions['canviewthreads'] != 1) 38 { 39 archive_error_no_permission(); 40 } 41 42 check_forum_password_archive($forum['fid']); 43 } 44 45 $announcement['subject'] = htmlspecialchars_uni($parser->parse_badwords($announcement['subject'])); 46 47 $parser_options = array( 48 "allow_html" => $announcement['allowhtml'], 49 "allow_mycode" => $announcement['allowmycode'], 50 "allow_smilies" => $announcement['allowsmilies'], 51 "allow_imgcode" => $announcement['allowimgcode'], 52 "allow_videocode" => $announcement['allowvideocode'], 53 "me_username" => $announcement['username'], 54 "filter_badwords" => 1 55 ); 56 57 $announcement['message'] = $parser->parse_message($announcement['message'], $parser_options); 58 59 $profile_link = build_profile_link($announcement['username'], $announcement['uid']); 60 61 // Build the navigation 62 add_breadcrumb($announcement['subject']); 63 archive_header($announcement['subject'], $announcement['subject'], $mybb->settings['bburl']."/announcements.php?aid={$id}"); 64 65 // Format announcement contents. 66 $announcement['startdate'] = my_date($mybb->settings['dateformat'].", ".$mybb->settings['timeformat'], $announcement['startdate']); 67 68 $plugins->run_hooks("archive_announcement_start"); 69 70 echo "<div class=\"post\">\n<div class=\"header\">\n<h2>{$announcement['subject']} - {$profile_link}</h2>"; 71 echo "<div class=\"dateline\">{$announcement['startdate']}</div>\n</div>\n<div class=\"message\">{$announcement['message']}</div>\n</div>\n"; 72 73 $plugins->run_hooks("archive_announcement_end"); 74 75 archive_footer(); 76 break; 77 78 // Display a thread. 79 case "thread": 80 $thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject'])); 81 82 // Fetch the forum this thread is in 83 $forum = get_forum($thread['fid']); 84 if(!$forum['fid'] || $forum['password'] != '') 85 { 86 archive_error($lang->error_invalidforum); 87 } 88 89 // Check if we have permission to view this thread 90 $forumpermissions = forum_permissions($forum['fid']); 91 if($forumpermissions['canview'] != 1 || $forumpermissions['canviewthreads'] != 1) 92 { 93 archive_error_no_permission(); 94 } 95 96 if($thread['visible'] != 1) 97 { 98 if(is_moderator($forum['fid'])) 99 { 100 archive_error($lang->sprintf($lang->error_unapproved_thread, $mybb->settings['bburl']."/".get_thread_link($thread['tid'], $page))); 101 } 102 else 103 { 104 archive_error($lang->error_invalidthread); 105 } 106 } 107 108 if($forumpermissions['canonlyviewownthreads'] == 1 && $thread['uid'] != $mybb->user['uid']) 109 { 110 archive_error_no_permission(); 111 } 112 113 check_forum_password_archive($forum['fid']); 114 115 // Build the navigation 116 build_forum_breadcrumb($forum['fid'], 1); 117 add_breadcrumb($thread['subject']); 118 119 archive_header($thread['subject'], $thread['subject'], $mybb->settings['bburl']."/".get_thread_link($thread['tid'], $page)); 120 121 $plugins->run_hooks("archive_thread_start"); 122 123 // Paginate this thread 124 $perpage = $mybb->settings['postsperpage']; 125 $postcount = intval($thread['replies'])+1; 126 $pages = ceil($postcount/$perpage); 127 128 if($page > $pages) 129 { 130 $page = 1; 131 } 132 if($page) 133 { 134 $start = ($page-1) * $perpage; 135 } 136 else 137 { 138 $start = 0; 139 $page = 1; 140 } 141 142 $pids = array(); 143 // Fetch list of post IDs to be shown 144 $query = $db->simple_select("posts", "pid", "tid='{$id}' AND visible='1'", array('order_by' => 'dateline', 'limit_start' => $start, 'limit' => $perpage)); 145 while($post = $db->fetch_array($query)) 146 { 147 $pids[$post['pid']] = $post['pid']; 148 } 149 150 if(empty($pids)) 151 { 152 archive_error($lang->error_invalidthread); 153 } 154 155 archive_multipage($postcount, $perpage, $page, "{$base_url}thread-$id"); 156 157 $pids = implode(",", $pids); 158 159 if($pids) 160 { 161 // Build attachments cache 162 $query = $db->simple_select("attachments", "*", "pid IN ({$pids})"); 163 while($attachment = $db->fetch_array($query)) 164 { 165 $acache[$attachment['pid']][$attachment['aid']] = $attachment; 166 } 167 } 168 169 // Start fetching the posts 170 $query = $db->query(" 171 SELECT u.*, u.username AS userusername, p.* 172 FROM ".TABLE_PREFIX."posts p 173 LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid) 174 WHERE p.pid IN ({$pids}) 175 ORDER BY p.dateline 176 "); 177 while($post = $db->fetch_array($query)) 178 { 179 $post['date'] = my_date($mybb->settings['dateformat'].", ".$mybb->settings['timeformat'], $post['dateline'], "", 0); 180 if($post['userusername']) 181 { 182 $post['username'] = $post['userusername']; 183 } 184 185 // Parse the message 186 $parser_options = array( 187 "allow_html" => $forum['allowhtml'], 188 "allow_mycode" => $forum['allowmycode'], 189 "allow_smilies" => $forum['allowsmilies'], 190 "allow_imgcode" => $forum['allowimgcode'], 191 "allow_videocode" => $forum['allowvideocode'], 192 "me_username" => $post['username'], 193 "filter_badwords" => 1 194 ); 195 if($post['smilieoff'] == 1) 196 { 197 $parser_options['allow_smilies'] = 0; 198 } 199 200 $post['message'] = $parser->parse_message($post['message'], $parser_options); 201 202 // Is there an attachment in this post? 203 if(is_array($acache[$post['pid']])) 204 { 205 foreach($acache[$post['pid']] as $aid => $attachment) 206 { 207 $post['message'] = str_replace("[attachment={$attachment['aid']}]", "[<a href=\"".$mybb->settings['bburl']."/attachment.php?aid={$attachment['aid']}\">attachment={$attachment['aid']}</a>]", $post['message']); 208 } 209 } 210 211 // Damn thats a lot of parsing, now to determine which username to show.. 212 if($post['userusername']) 213 { 214 $post['username'] = $post['userusername']; 215 } 216 $post['username'] = build_profile_link($post['username'], $post['uid']); 217 218 $plugins->run_hooks("archive_thread_post"); 219 220 // Finally show the post 221 echo "<div class=\"post\">\n<div class=\"header\">\n<div class=\"author\"><h2>{$post['username']}</h2></div>"; 222 echo "<div class=\"dateline\">{$post['date']}</div>\n</div>\n<div class=\"message\">{$post['message']}</div>\n</div>\n"; 223 } 224 archive_multipage($postcount, $perpage, $page, "{$base_url}thread-$id"); 225 226 $plugins->run_hooks("archive_thread_end"); 227 228 archive_footer(); 229 break; 230 231 // Display a category or a forum. 232 case "forum": 233 // Check if we have permission to view this forum 234 $forumpermissions = forum_permissions($forum['fid']); 235 if($forumpermissions['canview'] != 1) 236 { 237 archive_error_no_permission(); 238 } 239 240 check_forum_password_archive($forum['fid']); 241 242 $useronly = ""; 243 if($forumpermissions['canonlyviewownthreads'] == 1) 244 { 245 $useronly = "AND uid={$mybb->user['uid']}"; 246 } 247 248 // Paginate this forum 249 $query = $db->simple_select("threads", "COUNT(tid) AS threads", "fid='{$id}' AND visible='1' {$useronly}"); 250 $threadcount = $db->fetch_field($query, "threads"); 251 252 // Build the navigation 253 build_forum_breadcrumb($forum['fid'], 1); 254 255 // No threads and not a category? Error! 256 if($threadcount < 1 && $forum['type'] != 'c') 257 { 258 archive_header(strip_tags($forum['name']), $forum['name'], $mybb->settings['bburl']."/".get_forum_link($id, $page).""); 259 archive_error($lang->error_nothreads); 260 } 261 262 // Build the archive header. 263 archive_header(strip_tags($forum['name']), $forum['name'], $mybb->settings['bburl']."/".get_forum_link($id, $page), 1); 264 265 $plugins->run_hooks("archive_forum_start"); 266 267 if(!$mybb->settings['threadsperpage']) 268 { 269 $mybb->settings['threadsperpage'] = 20; 270 } 271 272 $perpage = $mybb->settings['threadsperpage']; 273 $pages = ceil($threadcount/$perpage); 274 if($page > $pages) 275 { 276 $page = 1; 277 } 278 279 if($page > 0) 280 { 281 $start = ($page-1) * $perpage; 282 } 283 else 284 { 285 $start = 0; 286 $page = 1; 287 } 288 289 // Decide what type of listing to show. 290 if($forum['type'] == 'f') 291 { 292 echo "<div class=\"listing\">\n<div class=\"header\"><h2>{$forum['name']}</h2></div>\n"; 293 } 294 elseif($forum['type'] == 'c') 295 { 296 echo "<div class=\"listing\">\n<div class=\"header\"><h2>{$forum['name']}</h2></div>\n"; 297 } 298 299 // Show subforums. 300 $query = $db->simple_select("forums", "COUNT(fid) AS subforums", "pid='{$id}' AND status='1'"); 301 $subforumcount = $db->fetch_field($query, "subforums"); 302 if($subforumcount > 0) 303 { 304 echo "<div class=\"forumlist\">\n"; 305 echo "<h3>{$lang->subforums}</h3>\n"; 306 echo "<ol>\n"; 307 $forums = build_archive_forumbits($forum['fid']); 308 echo $forums; 309 echo "</ol>\n</div>\n"; 310 } 311 312 archive_multipage($threadcount, $perpage, $page, "{$base_url}forum-$id"); 313 314 // Get the announcements if the forum is not a category. 315 if($forum['type'] == 'f') 316 { 317 $sql = build_parent_list($forum['fid'], "fid", "OR", $forum['parentlist']); 318 $time = TIME_NOW; 319 $query = $db->simple_select("announcements", "*", "startdate < '{$time}' AND (enddate > '{$time}' OR enddate=0) AND ({$sql} OR fid='-1')"); 320 if($db->num_rows($query) > 0) 321 { 322 echo "<div class=\"announcementlist\">\n"; 323 echo "<h3>{$lang->forumbit_announcements}</h3>"; 324 echo "<ol>\n"; 325 while($announcement = $db->fetch_array($query)) 326 { 327 $announcement['subject'] = $parser->parse_badwords($announcement['subject']); 328 echo "<li><a href=\"{$base_url}announcement-{$announcement['aid']}.html\">".htmlspecialchars_uni($announcement['subject'])."</a></li>"; 329 } 330 echo "</ol>\n</div>\n"; 331 } 332 333 } 334 335 // Get the stickies if the forum is not a category. 336 if($forum['type'] == 'f') 337 { 338 $options = array( 339 'order_by' => 'sticky, lastpost', 340 'order_dir' => 'desc', 341 'limit_start' => $start, 342 'limit' => $perpage 343 ); 344 $query = $db->simple_select("threads", "*", "fid='{$id}' AND visible='1' AND sticky='1' AND closed NOT LIKE 'moved|%' {$useronly}", $options); 345 if($db->num_rows($query) > 0) 346 { 347 echo "<div class=\"threadlist\">\n"; 348 echo "<h3>{$lang->forumbit_stickies}</h3>"; 349 echo "<ol>\n"; 350 while($sticky = $db->fetch_array($query)) 351 { 352 $sticky['subject'] = htmlspecialchars_uni($parser->parse_badwords($sticky['subject'])); 353 if($sticky['replies'] != 1) 354 { 355 $lang_reply_text = $lang->archive_replies; 356 } 357 else 358 { 359 $lang_reply_text = $lang->archive_reply; 360 } 361 362 $plugins->run_hooks("archive_forum_thread"); 363 364 echo "<li><a href=\"{$base_url}thread-{$sticky['tid']}.html\">{$sticky['subject']}</a>"; 365 echo "<span class=\"replycount\"> ({$sticky['replies']} {$lang_reply_text})</span></li>"; 366 } 367 echo "</ol>\n</div>\n"; 368 } 369 } 370 371 // Get the threads if the forum is not a category. 372 if($forum['type'] == 'f') 373 { 374 $options = array( 375 'order_by' => 'sticky, lastpost', 376 'order_dir' => 'desc', 377 'limit_start' => $start, 378 'limit' => $perpage 379 ); 380 $query = $db->simple_select("threads", "*", "fid='{$id}' AND visible='1' AND sticky='0' AND closed NOT LIKE 'moved|%' {$useronly}", $options); 381 if($db->num_rows($query) > 0) 382 { 383 echo "<div class=\"threadlist\">\n"; 384 echo "<h3>{$lang->forumbit_threads}</h3>"; 385 echo "<ol>\n"; 386 while($thread = $db->fetch_array($query)) 387 { 388 $thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject'])); 389 if($thread['replies'] != 1) 390 { 391 $lang_reply_text = $lang->archive_replies; 392 } 393 else 394 { 395 $lang_reply_text = $lang->archive_reply; 396 } 397 398 $plugins->run_hooks("archive_forum_thread"); 399 400 echo "<li><a href=\"{$base_url}thread-{$thread['tid']}.html\">{$thread['subject']}</a>"; 401 echo "<span class=\"replycount\"> ({$thread['replies']} {$lang_reply_text})</span></li>"; 402 } 403 echo "</ol>\n</div>\n"; 404 } 405 } 406 407 echo "</div>\n"; 408 409 archive_multipage($threadcount, $perpage, $page, "{$base_url}forum-$id"); 410 411 $plugins->run_hooks("archive_forum_end"); 412 413 archive_footer(); 414 break; 415 416 // Display the board home. 417 case "index": 418 // Build our forum listing 419 $forums = build_archive_forumbits(0); 420 archive_header("", $mybb->settings['bbname_orig'], $mybb->settings['bburl']."/index.php"); 421 422 $plugins->run_hooks("archive_index_start"); 423 424 echo "<div class=\"listing forumlist\">\n<div class=\"header\">{$mybb->settings['bbname']}</div>\n<div class=\"forums\">\n<ul>\n"; 425 echo $forums; 426 echo "\n</ul>\n</div>\n</div>"; 427 428 $plugins->run_hooks("archive_index_end"); 429 430 archive_footer(); 431 break; 432 default: 433 header("HTTP/1.0 404 Not Found"); 434 switch($action2) 435 { 436 case "announcement": 437 archive_error($lang->error_invalidannouncement); 438 case "thread": 439 archive_error($lang->error_invalidthread); 440 case "forum": 441 archive_error($lang->error_invalidforum); 442 default: 443 archive_error($lang->archive_not_found); 444 } 445 } 446 447 $plugins->run_hooks("archive_end"); 448 449 /** 450 * Gets a list of forums and possibly subforums. 451 * 452 * @param int The parent forum to get the childforums for. 453 * @return array Array of information regarding the child forums of this parent forum 454 */ 455 function build_archive_forumbits($pid=0) 456 { 457 global $db, $forumpermissions, $mybb, $lang, $archiveurl, $base_url; 458 459 // Sort out the forum cache first. 460 static $fcache; 461 if(!is_array($fcache)) 462 { 463 // Fetch forums 464 $query = $db->simple_select("forums", "*", "active!=0 AND password=''", array('order_by' =>'pid, disporder')); 465 while($forum = $db->fetch_array($query)) 466 { 467 $fcache[$forum['pid']][$forum['disporder']][$forum['fid']] = $forum; 468 } 469 $forumpermissions = forum_permissions(); 470 } 471 472 // Start the process. 473 if(is_array($fcache[$pid])) 474 { 475 foreach($fcache[$pid] as $key => $main) 476 { 477 foreach($main as $key => $forum) 478 { 479 $perms = $forumpermissions[$forum['fid']]; 480 if(($perms['canview'] == 1 || $mybb->settings['hideprivateforums'] == 0) && $forum['active'] != 0) 481 { 482 if($forum['linkto']) 483 { 484 $forums .= "<li><a href=\"{$forum['linkto']}\">{$forum['name']}</a>"; 485 } 486 elseif($forum['type'] == "c") 487 { 488 $forums .= "<li><strong><a href=\"{$base_url}forum-{$forum['fid']}.html\">{$forum['name']}</a></strong>"; 489 } 490 else 491 { 492 $forums .= "<li><a href=\"{$base_url}forum-{$forum['fid']}.html\">{$forum['name']}</a>"; 493 } 494 if($fcache[$forum['fid']]) 495 { 496 $forums .= "\n<ol>\n"; 497 $forums .= build_archive_forumbits($forum['fid']); 498 $forums .= "</ol>\n"; 499 } 500 $forums .= "</li>\n"; 501 } 502 } 503 } 504 } 505 return $forums; 506 } 507 ?>
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 |