| [ Index ] |
PHP Cross Reference of MyBB 1.4.13 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.4 4 * Copyright © 2008 MyBB Group, All Rights Reserved 5 * 6 * Website: http://www.mybboard.net 7 * License: http://www.mybboard.net/about/license 8 * 9 * $Id: global.php 4430 2009-08-22 23:27:11Z RyanGordon $ 10 */ 11 12 $working_dir = dirname(__FILE__); 13 if(!$working_dir) 14 { 15 $working_dir = '.'; 16 } 17 18 // Load main MyBB core file which begins all of the magic 19 require_once $working_dir."/inc/init.php"; 20 21 $shutdown_queries = array(); 22 23 // Read the usergroups cache as well as the moderators cache 24 $groupscache = $cache->read("usergroups"); 25 26 // If the groups cache doesn't exist, update it and re-read it 27 if(!is_array($groupscache)) 28 { 29 $cache->update_usergroups(); 30 $groupscache = $cache->read("usergroups"); 31 } 32 33 if(!defined('THIS_SCRIPT')) 34 { 35 define('THIS_SCRIPT', ''); 36 } 37 38 $current_page = my_strtolower(basename(THIS_SCRIPT)); 39 40 41 // Send page headers - don't send no-cache headers for attachment.php 42 if($current_page != "attachment.php") 43 { 44 send_page_headers(); 45 } 46 47 // Do not use session system for defined pages 48 if((@isset($mybb->input['action']) && @isset($nosession[$mybb->input['action']])) || (@isset($mybb->input['thumbnail']) && $current_page == 'attachment.php')) 49 { 50 define("NO_ONLINE", 1); 51 } 52 53 // Create session for this user 54 require_once MYBB_ROOT."inc/class_session.php"; 55 $session = new session; 56 $session->init(); 57 $mybb->session = &$session; 58 59 $mybb->user['ismoderator'] = is_moderator("", "", $mybb->user['uid']); 60 61 // Set our POST validation code here 62 $mybb->post_code = generate_post_check(); 63 64 // Set and load the language 65 if($mybb->input['language'] && $lang->language_exists($mybb->input['language'])) 66 { 67 $mybb->settings['bblanguage'] = $mybb->input['language']; 68 // If user is logged in, update their language selection with the new one 69 if($mybb->user['uid']) 70 { 71 $db->update_query("users", array("language" => $db->escape_string($mybb->settings['bblanguage'])), "uid='{$mybb->user['uid']}'"); 72 } 73 // Guest = cookie 74 else 75 { 76 my_setcookie("mybblang", $mybb->settings['bblanguage']); 77 } 78 $mybb->user['language'] = $mybb->settings['bblanguage']; 79 } 80 // Cookied language! 81 else if($mybb->cookies['mybblang'] && $lang->language_exists($mybb->cookies['mybblang'])) 82 { 83 $mybb->settings['bblanguage'] = $mybb->cookies['mybblang']; 84 } 85 else if(!isset($mybb->settings['bblanguage'])) 86 { 87 $mybb->settings['bblanguage'] = "english"; 88 } 89 90 // Load language 91 $lang->set_language($mybb->settings['bblanguage']); 92 $lang->load("global"); 93 $lang->load("messages"); 94 95 // Run global_start plugin hook now that the basics are set up 96 $plugins->run_hooks("global_start"); 97 98 if(function_exists('mb_internal_encoding') && !empty($lang->settings['charset'])) 99 { 100 @mb_internal_encoding($lang->settings['charset']); 101 } 102 103 // Select the board theme to use. 104 $loadstyle = ''; 105 $load_from_forum = 0; 106 $style = array(); 107 108 // This user has a custom theme set in their profile 109 if(isset($mybb->user['style']) && intval($mybb->user['style']) != 0) 110 { 111 $loadstyle = "tid='".$mybb->user['style']."'"; 112 } 113 114 $valid = array( 115 "showthread.php", 116 "forumdisplay.php", 117 "newthread.php", 118 "newreply.php", 119 "ratethread.php", 120 "editpost.php", 121 "polls.php", 122 "sendthread.php", 123 "printthread.php", 124 "moderation.php" 125 ); 126 127 if(in_array($current_page, $valid)) 128 { 129 // If we're accessing a post, fetch the forum theme for it and if we're overriding it 130 if($mybb->input['pid']) 131 { 132 $query = $db->query(" 133 SELECT f.style, f.overridestyle, p.* 134 FROM ".TABLE_PREFIX."forums f 135 LEFT JOIN ".TABLE_PREFIX."posts p ON(f.fid=p.fid) 136 WHERE p.pid='".intval($mybb->input['pid'])."' 137 LIMIT 1 138 "); 139 $style = $db->fetch_array($query); 140 141 $load_from_forum = 1; 142 } 143 144 // We have a thread id and a forum id, we can easily fetch the theme for this forum 145 else if($mybb->input['tid']) 146 { 147 $query = $db->query(" 148 SELECT f.style, f.overridestyle, t.* 149 FROM ".TABLE_PREFIX."forums f 150 LEFT JOIN ".TABLE_PREFIX."threads t ON (f.fid=t.fid) 151 WHERE t.tid='".intval($mybb->input['tid'])."' 152 LIMIT 1 153 "); 154 $style = $db->fetch_array($query); 155 $load_from_forum = 1; 156 } 157 158 // We have a forum id - simply load the theme from it 159 else if($mybb->input['fid']) 160 { 161 cache_forums(); 162 $style = $forum_cache[intval($mybb->input['fid'])]; 163 $load_from_forum = 1; 164 } 165 } 166 unset($valid); 167 168 // From all of the above, a theme was found 169 if(isset($style['style']) && $style['style'] > 0) 170 { 171 // This theme is forced upon the user, overriding their selection 172 if($style['overridestyle'] == 1 || !isset($mybb->user['style'])) 173 { 174 $loadstyle = "tid='".intval($style['style'])."'"; 175 } 176 } 177 178 // After all of that no theme? Load the board default 179 if(empty($loadstyle)) 180 { 181 $loadstyle = "def='1'"; 182 } 183 184 // Fetch the theme to load from the database 185 $query = $db->simple_select("themes", "name, tid, properties, stylesheets", $loadstyle, array('limit' => 1)); 186 $theme = $db->fetch_array($query); 187 188 // No theme was found - we attempt to load the master or any other theme 189 if(!$theme['tid']) 190 { 191 // Missing theme was from a forum, run a query to set any forums using the theme to the default 192 if($load_from_forum == 1) 193 { 194 $db->update_query("forums", array("style" => 0), "style='{$style['style']}'"); 195 } 196 // Missing theme was from a user, run a query to set any users using the theme to the default 197 else if($load_from_user == 1) 198 { 199 $db->update_query("users", array("style" => 0), "style='{$style['style']}'"); 200 } 201 // Attempt to load the master or any other theme if the master is not available 202 $query = $db->simple_select("themes", "name, tid, properties, stylesheets", "", array("order_by" => "tid", "limit" => 1)); 203 $theme = $db->fetch_array($query); 204 } 205 $theme = @array_merge($theme, unserialize($theme['properties'])); 206 207 // Fetch all necessary stylesheets 208 $theme['stylesheets'] = unserialize($theme['stylesheets']); 209 $stylesheet_scripts = array("global", basename($_SERVER['PHP_SELF'])); 210 foreach($stylesheet_scripts as $stylesheet_script) 211 { 212 $stylesheet_actions = array("global"); 213 if($mybb->input['action']) 214 { 215 $stylesheet_actions[] = $mybb->input['action']; 216 } 217 // Load stylesheets for global actions and the current action 218 foreach($stylesheet_actions as $stylesheet_action) 219 { 220 if(!$stylesheet_action) 221 { 222 continue; 223 } 224 225 if($theme['stylesheets'][$stylesheet_script][$stylesheet_action]) 226 { 227 // Actually add the stylesheets to the list 228 foreach($theme['stylesheets'][$stylesheet_script][$stylesheet_action] as $page_stylesheet) 229 { 230 if($already_loaded[$page_stylesheet]) 231 { 232 continue; 233 } 234 $stylesheets .= "<link type=\"text/css\" rel=\"stylesheet\" href=\"{$mybb->settings['bburl']}/{$page_stylesheet}\" />\n"; 235 $already_loaded[$page_stylesheet] = 1; 236 } 237 } 238 } 239 } 240 241 if(!@is_dir($theme['imgdir'])) 242 { 243 $theme['imgdir'] = "images"; 244 } 245 246 // If a language directory for the current language exists within the theme - we use it 247 if(!empty($mybb->user['language']) && is_dir($theme['imgdir'].'/'.$mybb->user['language'])) 248 { 249 $theme['imglangdir'] = $theme['imgdir'].'/'.$mybb->user['language']; 250 } 251 else 252 { 253 // Check if a custom language directory exists for this theme 254 if(is_dir($theme['imgdir'].'/'.$mybb->settings['bblanguage'])) 255 { 256 $theme['imglangdir'] = $theme['imgdir'].'/'.$mybb->settings['bblanguage']; 257 } 258 // Otherwise, the image language directory is the same as the language directory for the theme 259 else 260 { 261 $theme['imglangdir'] = $theme['imgdir']; 262 } 263 } 264 265 // Theme logo - is it a relative URL to the forum root? Append bburl 266 if(!preg_match("#^(\.\.?(/|$)|([a-z0-9]+)://)#i", $theme['logo']) && $theme['logo']{0} != "/") 267 { 268 $theme['logo'] = $mybb->settings['bburl']."/".$theme['logo']; 269 } 270 271 // Load Main Templates and Cached Templates 272 if(isset($templatelist)) 273 { 274 $templatelist .= ','; 275 } 276 $templatelist .= "css,headerinclude,header,footer,gobutton,htmldoctype,header_welcomeblock_member,header_welcomeblock_guest,header_welcomeblock_member_admin,global_pm_alert,global_unreadreports"; 277 $templatelist .= ",nav,nav_sep,nav_bit,nav_sep_active,nav_bit_active,footer_languageselect,header_welcomeblock_member_moderator,redirect,error"; 278 $templates->cache($db->escape_string($templatelist)); 279 280 // Set the current date and time now 281 $datenow = my_date($mybb->settings['dateformat'], TIME_NOW, '', false); 282 $timenow = my_date($mybb->settings['timeformat'], TIME_NOW); 283 $lang->welcome_current_time = $lang->sprintf($lang->welcome_current_time, $datenow.', '.$timenow); 284 285 // Format the last visit date of this user appropriately 286 if(isset($mybb->user['lastvisit'])) 287 { 288 $lastvisit = my_date($mybb->settings['dateformat'], $mybb->user['lastvisit']) . ', ' . my_date($mybb->settings['timeformat'], $mybb->user['lastvisit']); 289 } 290 291 // Otherwise, they've never visited before 292 else 293 { 294 $lastvisit = $lang->lastvisit_never; 295 } 296 297 // If the board is closed and we have an Administrator, show board closed warning 298 $bbclosedwarning = ''; 299 if($mybb->settings['boardclosed'] == 1 && $mybb->usergroup['cancp'] == 1) 300 { 301 eval("\$bbclosedwarning = \"".$templates->get("global_boardclosed_warning")."\";"); 302 } 303 304 // Prepare the main templates for use 305 unset($admincplink); 306 307 // Load appropriate welcome block for the current logged in user 308 if($mybb->user['uid'] != 0) 309 { 310 // User can access the admin cp and we're not hiding admin cp links, fetch it 311 if($mybb->usergroup['cancp'] == 1 && $mybb->config['hide_admin_links'] != 1) 312 { 313 eval("\$admincplink = \"".$templates->get("header_welcomeblock_member_admin")."\";"); 314 } 315 316 if($mybb->usergroup['canmodcp'] == 1) 317 { 318 eval("\$modcplink = \"".$templates->get("header_welcomeblock_member_moderator")."\";"); 319 } 320 321 // Format the welcome back message 322 $lang->welcome_back = $lang->sprintf($lang->welcome_back, $mybb->user['username'], $lastvisit); 323 324 // Tell the user their PM usage 325 $lang->welcome_pms_usage = $lang->sprintf($lang->welcome_pms_usage, my_number_format($mybb->user['pms_unread']), my_number_format($mybb->user['pms_total'])); 326 eval("\$welcomeblock = \"".$templates->get("header_welcomeblock_member")."\";"); 327 } 328 // Otherwise, we have a guest 329 else 330 { 331 eval("\$welcomeblock = \"".$templates->get("header_welcomeblock_guest")."\";"); 332 } 333 334 $unreadreports = ''; 335 // This user is a moderator, super moderator or administrator 336 if($mybb->usergroup['cancp'] == 1 || $mybb->user['ismoderator']) 337 { 338 // Read the reported posts cache 339 $reported = $cache->read("reportedposts"); 340 341 // 0 or more reported posts currently exist 342 if($reported['unread'] > 0) 343 { 344 if($reported['unread'] == 1) 345 { 346 $lang->unread_reports = $lang->unread_report; 347 } 348 else 349 { 350 $lang->unread_reports = $lang->sprintf($lang->unread_reports, $reported['unread']); 351 } 352 eval("\$unreadreports = \"".$templates->get("global_unreadreports")."\";"); 353 } 354 } 355 356 // Got a character set? 357 if($lang->settings['charset']) 358 { 359 $charset = $lang->settings['charset']; 360 } 361 // If not, revert to UTF-8 362 else 363 { 364 $charset = "UTF-8"; 365 } 366 367 // Is this user apart of a banned group? 368 $bannedwarning = ''; 369 if($mybb->usergroup['isbannedgroup'] == 1) 370 { 371 // Fetch details on their ban 372 $query = $db->simple_select("banned", "*", "uid='{$mybb->user['uid']}'", array('limit' => 1)); 373 $ban = $db->fetch_array($query); 374 if($ban['uid']) 375 { 376 // Format their ban lift date and reason appropriately 377 if($ban['lifted'] > 0) 378 { 379 $banlift = my_date($mybb->settings['dateformat'], $ban['lifted']) . ", " . my_date($mybb->settings['timeformat'], $ban['lifted']); 380 } 381 else 382 { 383 $banlift = $lang->banned_lifted_never; 384 } 385 $reason = htmlspecialchars_uni($ban['reason']); 386 } 387 if(empty($reason)) 388 { 389 $reason = $lang->unknown; 390 } 391 if(empty($banlift)) 392 { 393 $banlift = $lang->unknown; 394 } 395 // Display a nice warning to the user 396 eval("\$bannedwarning = \"".$templates->get("global_bannedwarning")."\";"); 397 } 398 399 $lang->ajax_loading = str_replace("'", "\\'", $lang->ajax_loading); 400 401 // Check if this user has a new private message. 402 if($mybb->user['pmnotice'] == 2 && $mybb->user['pms_unread'] > 0 && $mybb->settings['enablepms'] != 0 && $mybb->usergroup['canusepms'] != 0 && $mybb->usergroup['canview'] != 0 && ($current_page != "private.php" || $mybb->input['action'] != "read")) 403 { 404 $query = $db->query(" 405 SELECT pm.subject, pm.pmid, fu.username AS fromusername, fu.uid AS fromuid 406 FROM ".TABLE_PREFIX."privatemessages pm 407 LEFT JOIN ".TABLE_PREFIX."users fu ON (fu.uid=pm.fromid) 408 WHERE pm.folder='1' AND pm.uid='{$mybb->user['uid']}' AND pm.status='0' 409 ORDER BY pm.dateline DESC 410 LIMIT 1 411 "); 412 $pm = $db->fetch_array($query); 413 414 if($pm['fromuid'] == 0) 415 { 416 $pm['fromusername'] = 'MyBB Engine'; 417 $user_text = $pm['fromusername']; 418 } 419 else 420 { 421 $user_text = build_profile_link($pm['fromusername'], $pm['fromuid']); 422 } 423 424 if($mybb->user['pms_unread'] == 1) 425 { 426 $privatemessage_text = $lang->sprintf($lang->newpm_notice_one, $user_text, $pm['pmid'], htmlspecialchars_uni($pm['subject'])); 427 } 428 else 429 { 430 $privatemessage_text = $lang->sprintf($lang->newpm_notice_multiple, $mybb->user['pms_unread'], $user_text, $pm['pmid'], htmlspecialchars_uni($pm['subject'])); 431 } 432 eval("\$pm_notice = \"".$templates->get("global_pm_alert")."\";"); 433 } 434 435 // Set up some of the default templates 436 eval("\$headerinclude = \"".$templates->get("headerinclude")."\";"); 437 eval("\$gobutton = \"".$templates->get("gobutton")."\";"); 438 eval("\$htmldoctype = \"".$templates->get("htmldoctype", 1, 0)."\";"); 439 eval("\$header = \"".$templates->get("header")."\";"); 440 441 $copy_year = my_date("Y", TIME_NOW); 442 443 // Are we showing version numbers in the footer? 444 if($mybb->settings['showvernum'] == 1) 445 { 446 $mybbversion = ' '.$mybb->version; 447 } 448 else 449 { 450 $mybbversion = ''; 451 } 452 453 // Check to see if we have any tasks to run 454 if($mybb->settings['taskscron'] != 1) 455 { 456 $task_cache = $cache->read("tasks"); 457 if(!$task_cache['nextrun']) 458 { 459 $task_cache['nextrun'] = TIME_NOW; 460 } 461 if($task_cache['nextrun'] <= TIME_NOW) 462 { 463 $task_image = "<img src=\"{$mybb->settings['bburl']}/task.php\" border=\"0\" width=\"1\" height=\"1\" alt=\"\" />"; 464 } 465 else 466 { 467 $task_image = ''; 468 } 469 } 470 471 // Are we showing the quick language selection box? 472 $lang_select = ''; 473 if($mybb->settings['showlanguageselect'] != 0) 474 { 475 $languages = $lang->get_languages(); 476 foreach($languages as $key => $language) 477 { 478 $language = htmlspecialchars_uni($language); 479 // Current language matches 480 if($lang->language == $key) 481 { 482 $lang_options .= "<option value=\"{$key}\" selected=\"selected\"> {$language}</option>\n"; 483 } 484 else 485 { 486 $lang_options .= "<option value=\"{$key}\"> {$language}</option>\n"; 487 } 488 } 489 490 $lang_redirect_url = get_current_location(true, 'language'); 491 492 eval("\$lang_select = \"".$templates->get("footer_languageselect")."\";"); 493 } 494 495 // DST Auto detection enabled? 496 if($mybb->user['uid'] > 0 && $mybb->user['dstcorrection'] == 2) 497 { 498 $auto_dst_detection = "<script type=\"text/javascript\">if(MyBB) { Event.observe(window, 'load', function() { MyBB.detectDSTChange('".($mybb->user['timezone']+$mybb->user['dst'])."'); }); }</script>\n"; 499 } 500 501 eval("\$footer = \"".$templates->get("footer")."\";"); 502 503 // Add our main parts to the navigation 504 $navbits = array(); 505 $navbits[0]['name'] = $mybb->settings['bbname_orig']; 506 $navbits[0]['url'] = $mybb->settings['bburl']."/index.php"; 507 508 // Set the link to the archive. 509 $archive_url = $mybb->settings['bburl']."/archive/index.php"; 510 511 // Check banned ip addresses 512 if(is_banned_ip($session->ipaddress, true)) 513 { 514 if ($mybb->user['uid']) 515 { 516 $db->delete_query("sessions", "ip='".$db->escape_string($session->ipaddress)."' OR uid='{$mybb->user['uid']}'"); 517 } 518 else 519 { 520 $db->delete_query("sessions", "ip='".$db->escape_string($session->ipaddress)."'"); 521 } 522 error($lang->error_banned); 523 } 524 525 $closed_bypass = array( 526 "member.php" => array( 527 "login", 528 "do_login", 529 "logout", 530 ), 531 "captcha.php", 532 ); 533 534 // If the board is closed, the user is not an administrator and they're not trying to login, show the board closed message 535 if($mybb->settings['boardclosed'] == 1 && $mybb->usergroup['cancp'] != 1 && !in_array($current_page, $closed_bypass) && (!is_array($closed_bypass[$current_page]) || !in_array($mybb->input['action'], $closed_bypass[$current_page]))) 536 { 537 // Show error 538 $lang->error_boardclosed .= "<blockquote>{$mybb->settings['boardclosed_reason']}</blockquote>"; 539 error($lang->error_boardclosed); 540 exit; 541 } 542 543 // Load Limiting 544 if($mybb->usergroup['cancp'] != 1 && $mybb->settings['load'] > 0 && ($load = get_server_load()) && $load != $lang->unknown && $load > $mybb->settings['load']) 545 { 546 // User is not an administrator and the load limit is higher than the limit, show an error 547 error($lang->error_loadlimit); 548 } 549 550 // If there is a valid referrer in the URL, cookie it 551 if(!$mybb->user['uid'] && $mybb->settings['usereferrals'] == 1 && (isset($mybb->input['referrer']) || isset($mybb->input['referrername']))) 552 { 553 if(isset($mybb->input['referrername'])) 554 { 555 $condition = "username='".$db->escape_string($mybb->input['referrername'])."'"; 556 } 557 else 558 { 559 $condition = "uid='".intval($mybb->input['referrer'])."'"; 560 } 561 $query = $db->simple_select("users", "uid", $condition, array('limit' => 1)); 562 $referrer = $db->fetch_array($query); 563 if($referrer['uid']) 564 { 565 my_setcookie("mybb[referrer]", $referrer['uid']); 566 } 567 } 568 569 if($mybb->usergroup['canview'] != 1) 570 { 571 // Check pages allowable even when not allowed to view board 572 $allowable_actions = array( 573 "member.php" => array( 574 "register", 575 "do_register", 576 "login", 577 "do_login", 578 "logout", 579 "lostpw", 580 "do_lostpw", 581 "activate", 582 "resendactivation", 583 "do_resendactivation", 584 "resetpassword" 585 ), 586 "usercp2.php" => array( 587 "removesubscription", 588 "removesubscriptions" 589 ), 590 ); 591 if(!($current_page == "member.php" && in_array($mybb->input['action'], $allowable_actions['member.php'])) && !($current_page == "usercp2.php" && in_array($mybb->input['action'], $allowable_actions['usercp2.php'])) && $current_page != "captcha.php") 592 { 593 error_no_permission(); 594 } 595 unset($allowable_actions); 596 } 597 598 // work out which items the user has collapsed 599 $colcookie = $mybb->cookies['collapsed']; 600 601 // set up collapsable items (to automatically show them us expanded) 602 if($colcookie) 603 { 604 $col = explode("|", $colcookie); 605 if(!is_array($col)) 606 { 607 $col[0] = $colcookie; // only one item 608 } 609 unset($collapsed); 610 foreach($col as $key => $val) 611 { 612 $ex = $val."_e"; 613 $co = $val."_c"; 614 $collapsed[$co] = "display: show;"; 615 $collapsed[$ex] = "display: none;"; 616 $collapsedimg[$val] = "_collapsed"; 617 } 618 } 619 620 // Run hooks for end of global.php 621 $plugins->run_hooks("global_end"); 622 623 $globaltime = $maintimer->getTime(); 624 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Apr 19 19:52:21 2010 | Cross-referenced by PHPXref 0.7 |