1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * Copyright (C) 2008-2011 FluxBB |
---|
5 | * based on code by Rickard Andersson copyright (C) 2002-2008 PunBB |
---|
6 | * License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher |
---|
7 | */ |
---|
8 | |
---|
9 | if (!defined('PUN_ROOT')) |
---|
10 | exit('The constant PUN_ROOT must be defined and point to a valid FluxBB installation root directory.'); |
---|
11 | |
---|
12 | // Define the version and database revision that this code was written for |
---|
13 | define('FORUM_VERSION', '1.4.7'); |
---|
14 | |
---|
15 | define('FORUM_DB_REVISION', 15); |
---|
16 | define('FORUM_SI_REVISION', 2); |
---|
17 | define('FORUM_PARSER_REVISION', 2); |
---|
18 | |
---|
19 | // Block prefetch requests |
---|
20 | if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') |
---|
21 | { |
---|
22 | header('HTTP/1.1 403 Prefetching Forbidden'); |
---|
23 | |
---|
24 | // Send no-cache headers |
---|
25 | header('Expires: Thu, 21 Jul 1977 07:30:00 GMT'); // When yours truly first set eyes on this world! :) |
---|
26 | header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); |
---|
27 | header('Cache-Control: post-check=0, pre-check=0', false); |
---|
28 | header('Pragma: no-cache'); // For HTTP/1.0 compatibility |
---|
29 | |
---|
30 | exit; |
---|
31 | } |
---|
32 | |
---|
33 | // Attempt to load the configuration file config.php |
---|
34 | if (file_exists(PUN_ROOT.'config.php')) |
---|
35 | require PUN_ROOT.'config.php'; |
---|
36 | |
---|
37 | // If we have the 1.3-legacy constant defined, define the proper 1.4 constant so we don't get an incorrect "need to install" message |
---|
38 | if (defined('FORUM')) |
---|
39 | define('PUN', FORUM); |
---|
40 | |
---|
41 | // Load the functions script |
---|
42 | require PUN_ROOT.'include/functions.php'; |
---|
43 | |
---|
44 | // Load UTF-8 functions |
---|
45 | require PUN_ROOT.'include/utf8/utf8.php'; |
---|
46 | |
---|
47 | // Strip out "bad" UTF-8 characters |
---|
48 | forum_remove_bad_characters(); |
---|
49 | |
---|
50 | // Reverse the effect of register_globals |
---|
51 | forum_unregister_globals(); |
---|
52 | |
---|
53 | // If PUN isn't defined, config.php is missing or corrupt |
---|
54 | if (!defined('PUN')) |
---|
55 | { |
---|
56 | header('Location: install.php'); |
---|
57 | exit; |
---|
58 | } |
---|
59 | |
---|
60 | // Record the start time (will be used to calculate the generation time for the page) |
---|
61 | $pun_start = get_microtime(); |
---|
62 | |
---|
63 | // Make sure PHP reports all errors except E_NOTICE. FluxBB supports E_ALL, but a lot of scripts it may interact with, do not |
---|
64 | error_reporting(E_ALL ^ E_NOTICE); |
---|
65 | |
---|
66 | // Force POSIX locale (to prevent functions such as strtolower() from messing up UTF-8 strings) |
---|
67 | setlocale(LC_CTYPE, 'C'); |
---|
68 | |
---|
69 | // Turn off magic_quotes_runtime |
---|
70 | if (get_magic_quotes_runtime()) |
---|
71 | set_magic_quotes_runtime(0); |
---|
72 | |
---|
73 | // Strip slashes from GET/POST/COOKIE/REQUEST/FILES (if magic_quotes_gpc is enabled) |
---|
74 | if (get_magic_quotes_gpc()) |
---|
75 | { |
---|
76 | function stripslashes_array($array) |
---|
77 | { |
---|
78 | return is_array($array) ? array_map('stripslashes_array', $array) : stripslashes($array); |
---|
79 | } |
---|
80 | |
---|
81 | $_GET = stripslashes_array($_GET); |
---|
82 | $_POST = stripslashes_array($_POST); |
---|
83 | $_COOKIE = stripslashes_array($_COOKIE); |
---|
84 | $_REQUEST = stripslashes_array($_REQUEST); |
---|
85 | $_FILES = stripslashes_array($_FILES); |
---|
86 | } |
---|
87 | |
---|
88 | // If a cookie name is not specified in config.php, we use the default (pun_cookie) |
---|
89 | if (empty($cookie_name)) |
---|
90 | $cookie_name = 'pun_cookie'; |
---|
91 | |
---|
92 | // If the cache directory is not specified, we use the default setting |
---|
93 | if (!defined('FORUM_CACHE_DIR')) |
---|
94 | define('FORUM_CACHE_DIR', PUN_ROOT.'cache/'); |
---|
95 | |
---|
96 | // Define a few commonly used constants |
---|
97 | define('PUN_UNVERIFIED', 0); |
---|
98 | define('PUN_ADMIN', 1); |
---|
99 | define('PUN_MOD', 2); |
---|
100 | define('PUN_GUEST', 3); |
---|
101 | define('PUN_MEMBER', 4); |
---|
102 | |
---|
103 | // Load DB abstraction layer and connect |
---|
104 | require PUN_ROOT.'include/dblayer/common_db.php'; |
---|
105 | |
---|
106 | // Start a transaction |
---|
107 | $db->start_transaction(); |
---|
108 | |
---|
109 | // Load cached config |
---|
110 | if (file_exists(FORUM_CACHE_DIR.'cache_config.php')) |
---|
111 | include FORUM_CACHE_DIR.'cache_config.php'; |
---|
112 | |
---|
113 | if (!defined('PUN_CONFIG_LOADED')) |
---|
114 | { |
---|
115 | if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) |
---|
116 | require PUN_ROOT.'include/cache.php'; |
---|
117 | |
---|
118 | generate_config_cache(); |
---|
119 | require FORUM_CACHE_DIR.'cache_config.php'; |
---|
120 | } |
---|
121 | |
---|
122 | // Verify that we are running the proper database schema revision |
---|
123 | if (!isset($pun_config['o_database_revision']) || $pun_config['o_database_revision'] < FORUM_DB_REVISION || |
---|
124 | !isset($pun_config['o_searchindex_revision']) || $pun_config['o_searchindex_revision'] < FORUM_SI_REVISION || |
---|
125 | !isset($pun_config['o_parser_revision']) || $pun_config['o_parser_revision'] < FORUM_PARSER_REVISION || |
---|
126 | version_compare($pun_config['o_cur_version'], FORUM_VERSION, '<')) |
---|
127 | { |
---|
128 | header('Location: db_update.php'); |
---|
129 | exit; |
---|
130 | } |
---|
131 | |
---|
132 | // Enable output buffering |
---|
133 | if (!defined('PUN_DISABLE_BUFFERING')) |
---|
134 | { |
---|
135 | // Should we use gzip output compression? |
---|
136 | if ($pun_config['o_gzip'] && extension_loaded('zlib')) |
---|
137 | ob_start('ob_gzhandler'); |
---|
138 | else |
---|
139 | ob_start(); |
---|
140 | } |
---|
141 | |
---|
142 | // Define standard date/time formats |
---|
143 | $forum_time_formats = array($pun_config['o_time_format'], 'H:i:s', 'H:i', 'g:i:s a', 'g:i a'); |
---|
144 | $forum_date_formats = array($pun_config['o_date_format'], 'Y-m-d', 'Y-d-m', 'd-m-Y', 'm-d-Y', 'M j Y', 'jS M Y'); |
---|
145 | |
---|
146 | // Check/update/set cookie and fetch user info |
---|
147 | $pun_user = array(); |
---|
148 | check_cookie($pun_user); |
---|
149 | |
---|
150 | // Attempt to load the common language file |
---|
151 | if (file_exists(PUN_ROOT.'lang/'.$pun_user['language'].'/common.php')) |
---|
152 | include PUN_ROOT.'lang/'.$pun_user['language'].'/common.php'; |
---|
153 | else |
---|
154 | error('There is no valid language pack \''.pun_htmlspecialchars($pun_user['language']).'\' installed. Please reinstall a language of that name'); |
---|
155 | |
---|
156 | // Check if we are to display a maintenance message |
---|
157 | if ($pun_config['o_maintenance'] && $pun_user['g_id'] > PUN_ADMIN && !defined('PUN_TURN_OFF_MAINT')) |
---|
158 | maintenance_message(); |
---|
159 | |
---|
160 | // Load cached bans |
---|
161 | if (file_exists(FORUM_CACHE_DIR.'cache_bans.php')) |
---|
162 | include FORUM_CACHE_DIR.'cache_bans.php'; |
---|
163 | |
---|
164 | if (!defined('PUN_BANS_LOADED')) |
---|
165 | { |
---|
166 | if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) |
---|
167 | require PUN_ROOT.'include/cache.php'; |
---|
168 | |
---|
169 | generate_bans_cache(); |
---|
170 | require FORUM_CACHE_DIR.'cache_bans.php'; |
---|
171 | } |
---|
172 | |
---|
173 | // Check if current user is banned |
---|
174 | check_bans(); |
---|
175 | |
---|
176 | // Update online list |
---|
177 | update_users_online(); |
---|
178 | |
---|
179 | // Check to see if we logged in without a cookie being set |
---|
180 | if ($pun_user['is_guest'] && isset($_GET['login'])) |
---|
181 | message($lang_common['No cookie']); |
---|
182 | |
---|
183 | // The maximum size of a post, in bytes, since the field is now MEDIUMTEXT this allows ~16MB but lets cap at 1MB... |
---|
184 | if (!defined('PUN_MAX_POSTSIZE')) |
---|
185 | define('PUN_MAX_POSTSIZE', 1048576); |
---|
186 | |
---|
187 | if (!defined('PUN_SEARCH_MIN_WORD')) |
---|
188 | define('PUN_SEARCH_MIN_WORD', 3); |
---|
189 | if (!defined('PUN_SEARCH_MAX_WORD')) |
---|
190 | define('PUN_SEARCH_MAX_WORD', 20); |
---|
191 | |
---|
192 | if (!defined('FORUM_MAX_COOKIE_SIZE')) |
---|
193 | define('FORUM_MAX_COOKIE_SIZE', 4048); |
---|