root/branches/0.8/bb-settings.php

Revision 1362, 12.9 kB (checked in by mdawaffe, 5 months ago)

don't include l10n stuff if WP is already loaded. Fixes #837 for branches/0.8

  • Property svn:eol-style set to native
Line 
1 <?php
2
3 if ( version_compare(PHP_VERSION, '4.3', '<') )
4     die(sprintf('Your server is running PHP version %s but bbPress requires at least 4.3', PHP_VERSION) );
5
6 if ( !$bb_table_prefix )
7     die('You must specify a table prefix in your <code>bb-config.php</code> file.');
8
9 if ( !defined('BB_PATH') )
10     die('This file cannot be called directly.');
11
12 // Turn register globals off
13 function bb_unregister_GLOBALS() {
14     if ( !ini_get('register_globals') )
15         return;
16
17     if ( isset($_REQUEST['GLOBALS']) )
18         die('GLOBALS overwrite attempt detected');
19
20     // Variables that shouldn't be unset
21     $noUnset = array('GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'bb_table_prefix', 'bb');
22
23     $input = array_merge($_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset($_SESSION) && is_array($_SESSION) ? $_SESSION : array());
24     foreach ( $input as $k => $v )
25         if ( !in_array($k, $noUnset) && isset($GLOBALS[$k]) ) {
26             $GLOBALS[$k] = NULL;
27             unset($GLOBALS[$k]);
28         }
29 }
30
31 bb_unregister_GLOBALS();
32
33 function bb_timer_start() {
34     global $bb_timestart;
35     $mtime = explode(' ', microtime() );
36     $bb_timestart = $mtime[1] + $mtime[0];
37     return true;
38 }
39 bb_timer_start();
40
41 $is_IIS = strstr($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') ? 1 : 0;
42 // Fix for IIS, which doesn't set REQUEST_URI
43 if ( empty( $_SERVER['REQUEST_URI'] ) ) {
44     $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME']; // Does this work under CGI?
45
46     // Append the query string if it exists and isn't null
47     if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING']))
48         $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
49 }
50
51 // Modify error reporting levels
52 error_reporting(E_ALL ^ E_NOTICE);
53
54 if ( !defined( 'BB_IS_ADMIN' ) )
55     define( 'BB_IS_ADMIN', false );
56
57 // Define the include path
58 define('BB_INC', 'bb-includes/');
59
60 // Load the database class
61 require( BB_PATH . BB_INC . 'db.php' );
62
63 // Define the language file directory
64 if ( !defined('BB_LANG_DIR') )
65     if ( defined('BBLANGDIR') ) // User has set old constant
66         define('BB_LANG_DIR', BBLANGDIR);
67     else
68         define('BB_LANG_DIR', BB_PATH . BB_INC . 'languages/'); // absolute path with trailing slash
69
70 // Include functions
71 require( BB_PATH . BB_INC . 'compat.php');
72 require( BB_PATH . BB_INC . 'wp-functions.php');
73 require( BB_PATH . BB_INC . 'functions.php');
74 require( BB_PATH . BB_INC . 'wp-classes.php');
75 require( BB_PATH . BB_INC . 'classes.php');
76 if ( !defined('BB_LANG') && defined('BBLANG') && '' != BBLANG ) // User has set old constant
77     define('BB_LANG', BBLANG);
78 if ( !( defined('DB_NAME') || defined('WP_BB') && WP_BB ) ) {  // Don't include these when WP is running.
79     if ( defined('BB_LANG') && '' != BB_LANG ) {
80         include_once(BB_PATH . BB_INC . 'streams.php');
81         include_once(BB_PATH . BB_INC . 'gettext.php');
82     }
83     require( BB_PATH . BB_INC . 'kses.php');
84     require( BB_PATH . BB_INC . 'l10n.php');
85 }
86
87 if ( is_wp_error( $bbdb->set_prefix( $bb_table_prefix ) ) )
88     die(__('Your table prefix may only contain letters, numbers and underscores.'));
89
90 if ( !bb_is_installed() && ( !defined('BB_INSTALLING') || !BB_INSTALLING ) ) {
91     $link = preg_replace('|(/bb-admin)?/[^/]+?$|', '/', $_SERVER['PHP_SELF']) . 'bb-admin/install.php';
92     require( BB_PATH . BB_INC . 'pluggable.php');
93     wp_redirect($link);
94     die();
95 }
96
97 foreach ( array('use_cache', 'debug', 'static_title', 'load_options') as $o )
98     if ( !isset($bb->$o) )
99         $bb->$o = false;
100 unset($o);
101
102 if ( defined('BB_INSTALLING') && BB_INSTALLING )
103 foreach ( array('active_plugins') as $i )
104     $bb->$i = false;
105 unset($i);
106
107 require( BB_PATH . BB_INC . 'formatting-functions.php');
108 require( BB_PATH . BB_INC . 'template-functions.php');
109 require( BB_PATH . BB_INC . 'capabilities.php');
110 require( BB_PATH . BB_INC . 'cache.php');
111 require( BB_PATH . BB_INC . 'deprecated.php');
112
113 $bb_cache = new BB_Cache();
114
115 if ( $bb->load_options ) {
116     $bbdb->hide_errors();
117     bb_cache_all_options();
118     $bbdb->show_errors();
119 }
120
121 require( BB_PATH . BB_INC . 'default-filters.php');
122 require( BB_PATH . BB_INC . 'script-loader.php');
123
124 $_GET    = bb_global_sanitize($_GET   );
125 $_POST   = bb_global_sanitize($_POST  );
126 $_COOKIE = bb_global_sanitize($_COOKIE, false);
127 $_SERVER = bb_global_sanitize($_SERVER);
128
129 // Set the URI and derivitaves
130 if ( $bb->uri = bb_get_option('uri') ) {
131     $bb->uri = rtrim($bb->uri, '/') . '/';
132     
133     // Not used in core anymore, only set here for plugin compatibility
134     if ( preg_match( '@^(https?://[^/]+)((?:/.*)*/{1,1})$@i', $bb->uri, $matches ) ) {
135         $bb->domain = $matches[1];
136         $bb->path = $matches[2];
137     }
138     unset($matches);
139 } else {
140     // Backwards compatibility
141     // These were never set in the database
142     if ( isset($bb->domain) ) {
143         $bb->domain = rtrim( trim( $bb->domain ), '/' );
144     }
145     if ( isset($bb->path) ) {
146         $bb->path = trim($bb->path);
147         if ( $bb->path != '/' ) $bb->path = '/' . trim($bb->path, '/') . '/';
148     }
149     // We need both to build a uri
150     if ( $bb->domain && $bb->path ) {
151         $bb->uri = $bb->domain . $bb->path;
152     }
153 }
154 // Die if no URI
155 if ( !$bb->uri && ( !defined('BB_INSTALLING') || !BB_INSTALLING ) ) {
156     bb_die( __('Could not determine site URI') );
157 }
158
159 define('BB_CORE_PLUGIN_DIR', BB_PATH . 'bb-plugins/');
160 define('BB_CORE_PLUGIN_URL', $bb->uri . 'bb-plugins/');
161 define('BB_CORE_THEME_DIR', BB_PATH . 'bb-templates/');
162 define('BB_CORE_THEME_URL', $bb->uri . 'bb-templates/');
163 define('BB_DEFAULT_THEME', 'core#kakumei');
164 define('BB_DEFAULT_THEME_DIR', BB_CORE_THEME_DIR . 'kakumei/');
165 define('BB_DEFAULT_THEME_URL', BB_CORE_THEME_URL . 'kakumei/');
166
167 if ( !defined('BB_PLUGIN_DIR') )
168     if ( defined('BBPLUGINDIR') ) // User has set old constant
169         define('BB_PLUGIN_DIR', BBPLUGINDIR);
170     else
171         define('BB_PLUGIN_DIR', BB_PATH . 'my-plugins/');
172
173 if ( !defined('BB_PLUGIN_URL') )
174     if ( defined('BBPLUGINURL') ) // User has set old constant
175         define('BB_PLUGIN_URL', BBPLUGINURL);
176     else
177         define('BB_PLUGIN_URL', $bb->uri . 'my-plugins/');
178
179 if ( !defined('BB_THEME_DIR') )
180     if ( defined('BBTHEMEDIR') ) // User has set old constant
181         define('BB_THEME_DIR', BBTHEMEDIR);
182     else
183         define('BB_THEME_DIR', BB_PATH . 'my-templates/');
184
185 if ( !defined('BB_THEME_URL') )
186     if ( defined('BBTHEMEURL') ) // User has set old constant
187         define('BB_THEME_URL', BBTHEMEURL);
188     else
189         define('BB_THEME_URL', $bb->uri . 'my-templates/');
190
191 // Check for defined custom user tables
192 // Constants are taken before $bb before database settings
193 $bb->wp_table_prefix = bb_get_option('wp_table_prefix');
194
195 if ( !$bb->user_bbdb_name = bb_get_option('user_bbdb_name') )
196     if ( defined('USER_BBDB_NAME') ) // User has set old constant
197         $bb->user_bbdb_name = USER_BBDB_NAME;
198
199 if ( !$bb->user_bbdb_user = bb_get_option('user_bbdb_user') )
200     if ( defined('USER_BBDB_USER') ) // User has set old constant
201         $bb->user_bbdb_user = USER_BBDB_USER;
202
203 if ( !$bb->user_bbdb_password = bb_get_option('user_bbdb_password') )
204     if ( defined('USER_BBDB_PASSWORD') ) // User has set old constant
205         $bb->user_bbdb_password = USER_BBDB_PASSWORD;
206
207 if ( !$bb->user_bbdb_host = bb_get_option('user_bbdb_host') )
208     if ( defined('USER_BBDB_HOST') ) // User has set old constant
209         $bb->user_bbdb_host = USER_BBDB_HOST;
210
211 if ( !$bb->user_bbdb_charset = bb_get_option('user_bbdb_charset') )
212     if ( defined('USER_BBDB_CHARSET') ) // User has set old constant
213         $bb->user_bbdb_charset = USER_BBDB_CHARSET;
214
215 if ( !$bb->custom_user_table = bb_get_option('custom_user_table') )
216     if ( defined('CUSTOM_USER_TABLE') ) // User has set old constant
217         $bb->custom_user_table = CUSTOM_USER_TABLE;
218
219 if ( !$bb->custom_user_meta_table = bb_get_option('custom_user_meta_table') )
220     if ( defined('CUSTOM_USER_META_TABLE') ) // User has set old constant
221         $bb->custom_user_meta_table = CUSTOM_USER_META_TABLE;
222
223 if ( is_wp_error( $bbdb->set_prefix( $bb->wp_table_prefix, array('users', 'usermeta') ) ) )
224     die(__('Your user table prefix may only contain letters, numbers and underscores.'));
225
226 // Set the user table's character set if defined
227 if ( isset($bb->user_bbdb_charset) && $bb->user_bbdb_charset )
228     $bbdb->user_charset = $bb->user_bbdb_charset;
229
230 // Set the user table's custom name if defined
231 if ( isset($bb->custom_user_table) && $bb->custom_user_table )
232     $bbdb->users = $bb->custom_user_table;
233
234 // Set the usermeta table's custom name if defined
235 if ( isset($bb->custom_user_meta_table) && $bb->custom_user_meta_table )
236     $bbdb->usermeta = $bb->custom_user_meta_table;
237
238 // Sort out cookies so they work with WordPress (if required)
239 // Note that database integration is no longer a pre-requisite for cookie integration
240 $bb->wp_siteurl = bb_get_option('wp_siteurl');
241 if ( $bb->wp_siteurl ) {
242     $bb->wp_siteurl = rtrim($bb->wp_siteurl, '/') . '/';
243 }
244
245 $bb->wp_home = bb_get_option('wp_home');
246 if ( $bb->wp_home ) {
247     $bb->wp_home = rtrim($bb->wp_home, '/') . '/';
248 }
249
250 $bb->wp_cookies_integrated = false;
251 $bb->cookiedomain = bb_get_option('cookiedomain');
252 if ( $bb->wp_siteurl && $bb->wp_home ) {
253     if ( $bb->cookiedomain ) {
254         $bb->wp_cookies_integrated = true;
255     } else {
256         $cookiedomain = bb_get_common_domains($bb->uri, $bb->wp_home);
257         if ( bb_match_domains($bb->uri, $bb->wp_home) ) {
258             $bb->cookiepath = bb_get_common_paths($bb->uri, $bb->wp_home);
259             $bb->wp_cookies_integrated = true;
260         } elseif ($cookiedomain && strpos($cookiedomain, '.') !== false) {
261             $bb->cookiedomain = '.' . $cookiedomain;
262             $bb->cookiepath = bb_get_common_paths($bb->uri, $bb->wp_home);
263             $bb->wp_cookies_integrated = true;
264         }
265         unset($cookiedomain);
266     }
267 }
268
269 define('BB_HASH', $bb->wp_cookies_integrated ? md5(rtrim($bb->wp_siteurl, '/')) : md5(rtrim($bb->uri, '/')) );
270 // Deprecated setting
271 $bb->usercookie = bb_get_option('usercookie');
272 if ( !$bb->usercookie ) {
273     $bb->usercookie = ( $bb->wp_cookies_integrated ? 'wordpressuser_' : 'bb_user_' ) . BB_HASH;
274 }
275
276 // Deprecated setting
277 $bb->passcookie = bb_get_option('passcookie');
278 if ( !$bb->passcookie ) {
279     $bb->passcookie = ( $bb->wp_cookies_integrated ? 'wordpresspass_' : 'bb_pass_' ) . BB_HASH;
280 }
281
282 $bb->authcookie = bb_get_option('authcookie');
283 if ( !$bb->authcookie ) {
284     $bb->authcookie = ($bb->wp_cookies_integrated ? 'wordpress_' : 'bbpress_') . BB_HASH;
285 }
286
287 $bb->cookiepath = bb_get_option('cookiepath');
288 if ( !isset( $bb->cookiepath ) ) {
289     $bb->cookiepath = $bb->wp_cookies_integrated ? preg_replace('|https?://[^/]+|i', '', $bb->wp_home ) : $bb->path;
290 }
291
292 $bb->sitecookiepath = bb_get_option('sitecookiepath');
293 if ( !isset( $bb->sitecookiepath ) ) {
294     $bb->sitecookiepath = $bb->wp_cookies_integrated ? preg_replace('|https?://[^/]+|i', '', $bb->wp_siteurl ) : $bb->path;
295 }
296
297
298 // Set the path to the tag pages
299 if ( !isset( $bb->tagpath ) )
300     $bb->tagpath = $bb->path;
301
302 do_action( 'bb_options_loaded' );
303
304 /*
305 Define deprecated constants for plugin compatibility
306 TODO: Completely remove old constants on version 1.0
307 $deprecated_constants below is a complete array of old constants and their replacements
308 */
309 $deprecated_constants = array(
310     'BBPATH'                 => 'BB_PATH',
311     'BBINC'                  => 'BB_INC',
312     'BBLANG'                 => 'BB_LANG',
313     'BBLANGDIR'              => 'BB_LANG_DIR',
314     'BBPLUGINDIR'            => 'BB_PLUGIN_DIR',
315     'BBPLUGINURL'            => 'BB_PLUGIN_URL',
316     'BBTHEMEDIR'             => 'BB_THEME_DIR',
317     'BBTHEMEURL'             => 'BB_THEME_URL',
318     'BBHASH'                 => 'BB_HASH'
319 );
320 foreach ( $deprecated_constants as $old => $new )
321     if ( !defined($old) && defined($new)) // only define if new one is defined
322         define($old, constant($new));
323
324 $deprecated_constants = array(
325     'USER_BBDB_NAME'         => $bb->user_bbdb_name,
326     'USER_BBDB_USER'         => $bb->user_bbdb_user,
327     'USER_BBDB_PASSWORD'     => $bb->user_bbdb_password,
328     'USER_BBDB_HOST'         => $bb->user_bbdb_host,
329     'USER_BBDB_CHARSET'      => $bb->user_bbdb_charset,
330     'CUSTOM_USER_TABLE'      => $bb->custom_user_table,
331     'CUSTOM_USER_META_TABLE' => $bb->custom_user_meta_table,
332 );
333 foreach ( $deprecated_constants as $old => $new )
334     if ( !defined($old) )
335         define($old, $new);
336 unset($deprecated_constants, $old, $new);
337
338 // Load Plugins
339
340 // Autoloaded "underscore" plugins
341 // First BB_CORE_PLUGIN_DIR
342 foreach ( bb_glob(BB_CORE_PLUGIN_DIR . '_*.php') as $_plugin )
343     require( $_plugin );
344 unset( $_plugin );
345 // Second BB_PLUGIN_DIR, with no name clash testing
346 foreach ( bb_glob(BB_PLUGIN_DIR . '_*.php') as $_plugin )
347     require( $_plugin );
348 unset( $_plugin );
349 do_action( 'bb_underscore_plugins_loaded' );
350
351 // Normal plugins
352 if ( $plugins = bb_get_option( 'active_plugins' ) ) {
353     foreach ( (array) $plugins as $plugin ) {
354         $plugin = str_replace(
355             array('core#', 'user#'),
356             array(BB_CORE_PLUGIN_DIR, BB_PLUGIN_DIR),
357             $plugin
358         );
359         if ( file_exists( $plugin ) ) {
360             require( $plugin );
361         }
362     }
363 }
364 do_action( 'bb_plugins_loaded' );
365 unset($plugins, $plugin);
366
367 require( BB_PATH . BB_INC . 'pluggable.php');
368
369 // Load the default text localization domain.
370 load_default_textdomain();
371
372 // Pull in locale data after loading text domain.
373 require_once(BB_PATH . BB_INC . 'locale.php');
374 $bb_locale = new BB_Locale();
375
376 $bb_roles  = new BB_Roles();
377 do_action('bb_got_roles', '');
378
379 function bb_shutdown_action_hook() {
380     do_action('bb_shutdown', '');
381 }
382 register_shutdown_function('bb_shutdown_action_hook');
383
384 bb_current_user();
385
386 do_action('bb_init', '');
387
388 if ( bb_is_user_logged_in() && bb_has_broken_pass() )
389     bb_block_current_user();
390
391 $page = bb_get_uri_page();
392
393 bb_send_headers();
394
395 ?>
396
Note: See TracBrowser for help on using the browser.