1<?php 2/** 3 * Loads the minimum amount of data (eg: functions, database connection, config data, etc) necessary to integrate the site. 4 * 5 * @copyright (C) 2008-2012 PunBB, partially based on code (C) 2008-2009 FluxBB.org 6 * @license http://www.gnu.org/licenses/gpl.html GPL version 2 or higher 7 * @package PunBB 8 */ 9 10if (!defined('FORUM_ROOT')) 11 exit('The constant FORUM_ROOT must be defined and point to a valid PunBB installation root directory.'); 12 13if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') 14{ 15 define('FORUM_REQUEST_AJAX', 1); 16} 17 18require FORUM_ROOT.'include/constants.php'; 19 20// Record the start time (will be used to calculate the generation time for the page) 21list($usec, $sec) = explode(' ', microtime()); 22$forum_start = ((float)$usec + (float)$sec); 23 24// Load the functions script 25require FORUM_ROOT.'include/functions.php'; 26// Load the Loader class 27require FORUM_ROOT.'include/loader.php'; 28 29// Load UTF-8 functions 30require FORUM_ROOT.'include/utf8/utf8.php'; 31require FORUM_ROOT.'include/utf8/ucwords.php'; 32require FORUM_ROOT.'include/utf8/trim.php'; 33 34// Reverse the effect of register_globals 35forum_unregister_globals(); 36 37// Ignore any user abort requests 38ignore_user_abort(true); 39 40// Attempt to load the configuration file config.php 41if (file_exists(FORUM_ROOT.'config.php')) 42 include FORUM_ROOT.'config.php'; 43 44// If we have the 1.2 constant defined, define the proper 1.3 constant so we don't get 45// an incorrect "need to install" message 46if (defined('PUN')) 47 define('FORUM', 1); 48 49if (!defined('FORUM')) 50 error('The file \'config.php\' doesn\'t exist or is corrupt.<br />Please run <a href="'.FORUM_ROOT.'admin/install.php">install.php</a> to install PunBB first.'); 51 52// Block prefetch requests 53if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') 54{ 55 header('HTTP/1.1 403 Prefetching Forbidden'); 56 57 // Send no-cache headers 58 header('Expires: Thu, 21 Jul 1977 07:30:00 GMT'); // When yours truly first set eyes on this world! :) 59 header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); 60 header('Cache-Control: post-check=0, pre-check=0', false); 61 header('Pragma: no-cache'); // For HTTP/1.0 compability 62 63 exit; 64} 65 66// Make sure PHP reports all errors except E_NOTICE. PunBB supports E_ALL, but a lot of scripts it may interact with, do not. 67if (defined('FORUM_DEBUG')) 68 error_reporting(E_ALL); 69else 70 error_reporting(E_ALL ^ E_NOTICE); 71 72// Detect UTF-8 support in PCRE 73if ((version_compare(PHP_VERSION, '5.1.0', '>=') || (version_compare(PHP_VERSION, '5.0.0-dev', '<=') && version_compare(PHP_VERSION, '4.4.0', '>='))) && @/**/preg_match('/\p{L}/u', 'a') !== FALSE) 74{ 75 define('FORUM_SUPPORT_PCRE_UNICODE', 1); 76} 77 78// Force POSIX locale (to prevent functions such as strtolower() from messing up UTF-8 strings) 79setlocale(LC_CTYPE, 'C'); 80 81// If the cache directory is not specified, we use the default setting 82if (!defined('FORUM_CACHE_DIR')) 83 define('FORUM_CACHE_DIR', FORUM_ROOT.'cache/'); 84 85// Load DB abstraction layer and connect 86require FORUM_ROOT.'include/dblayer/common_db.php'; 87 88// Start a transaction 89$forum_db->start_transaction(); 90 91// Load cached config 92if (file_exists(FORUM_CACHE_DIR.'cache_config.php')) 93 include FORUM_CACHE_DIR.'cache_config.php'; 94 95if (!defined('FORUM_CONFIG_LOADED')) 96{ 97 if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) 98 require FORUM_ROOT.'include/cache.php'; 99 100 generate_config_cache(); 101 require FORUM_CACHE_DIR.'cache_config.php'; 102} 103 104// If the request_uri is invalid try fix it 105forum_fix_request_uri(); 106 107if (!isset($base_url)) 108{ 109 // Make an educated guess regarding base_url 110 $base_url_guess = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://').preg_replace('/:80$/', '', $_SERVER['HTTP_HOST']).str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME'])); 111 if (substr($base_url_guess, -1) == '/') 112 $base_url_guess = substr($base_url_guess, 0, -1); 113 114 $base_url = $base_url_guess; 115} 116 117// Verify that we are running the proper database schema revision 118if (defined('PUN') || !isset($forum_config['o_database_revision']) || $forum_config['o_database_revision'] < FORUM_DB_REVISION || version_compare($forum_config['o_cur_version'], FORUM_VERSION, '<')) 119 error('Your PunBB database is out-of-date and must be upgraded in order to continue.<br />Please run <a href="'.$base_url.'/admin/db_update.php">db_update.php</a> in order to complete the upgrade process.'); 120 121 122// Load hooks 123if (file_exists(FORUM_CACHE_DIR.'cache_hooks.php')) 124 include FORUM_CACHE_DIR.'cache_hooks.php'; 125 126if (!defined('FORUM_HOOKS_LOADED')) 127{ 128 if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) 129 require FORUM_ROOT.'include/cache.php'; 130 131 generate_hooks_cache(); 132 require FORUM_CACHE_DIR.'cache_hooks.php'; 133} 134 135require FORUM_ROOT.'include/flash_messenger.php'; 136$forum_flash = new FlashMessenger(); 137 138// A good place to add common functions for your extension 139($hook = get_hook('es_essentials')) ? eval($hook) : null; 140 141if (!defined('FORUM_MAX_POSTSIZE_BYTES')) 142 define('FORUM_MAX_POSTSIZE_BYTES', 65535); 143 144define('FORUM_ESSENTIALS_LOADED', 1); 145