root/tags/1.5-rc1/wp-settings.php

Revision 1240, 16.7 kB (checked in by donncha, 8 months ago)

Replace glob(), it may be disabled on some hosts. fixes #594

  • Property svn:eol-style set to native
Line 
1 <?php
2 /**
3  * Used to setup and fix common variables and include
4  * the WordPress procedural and class library.
5  *
6  * You should not have to change this file and allows
7  * for some configuration in wp-config.php.
8  *
9  * @package WordPress
10  */
11
12 if ( !defined('WP_MEMORY_LIMIT') )
13     define('WP_MEMORY_LIMIT', '32M');
14
15 if ( function_exists('memory_get_usage') && ( (int) @ini_get('memory_limit') < abs(intval(WP_MEMORY_LIMIT)) ) )
16     @ini_set('memory_limit', WP_MEMORY_LIMIT);
17
18
19 /**
20  * wp_unregister_GLOBALS() - Turn register globals off
21  *
22  * @access private
23  * @since 2.1.0
24  * @return null Will return null if register_globals PHP directive was disabled
25  */
26 function wp_unregister_GLOBALS() {
27     if ( !ini_get('register_globals') )
28         return;
29
30     if ( isset($_REQUEST['GLOBALS']) )
31         die('GLOBALS overwrite attempt detected');
32
33     // Variables that shouldn't be unset
34     $noUnset = array('GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'table_prefix');
35
36     $input = array_merge($_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset($_SESSION) && is_array($_SESSION) ? $_SESSION : array());
37     foreach ( $input as $k => $v )
38         if ( !in_array($k, $noUnset) && isset($GLOBALS[$k]) ) {
39             $GLOBALS[$k] = NULL;
40             unset($GLOBALS[$k]);
41         }
42 }
43
44 wp_unregister_GLOBALS();
45
46 unset( $wp_filter, $cache_lastcommentmodified, $cache_lastpostdate );
47
48 /**
49  * The $blog_id global, which you can change in the config allows you to create a simple
50  * multiple blog installation using just one WordPress and changing $blog_id around.
51  *
52  * @global int $blog_id
53  * @since 2.0.0
54  */
55 if ( ! isset($blog_id) )
56     $blog_id = 0;
57
58 // Fix for IIS, which doesn't set REQUEST_URI
59 if ( empty( $_SERVER['REQUEST_URI'] ) ) {
60
61     // IIS Mod-Rewrite
62     if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
63         $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
64     }
65     // IIS Isapi_Rewrite
66     else if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
67         $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
68     }
69     else
70     {
71         // Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice)
72         if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] )
73             $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
74         else
75             $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
76
77         // Append the query string if it exists and isn't null
78         if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
79             $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
80         }
81     }
82 }
83
84 // Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests
85 if ( isset($_SERVER['SCRIPT_FILENAME']) && ( strpos($_SERVER['SCRIPT_FILENAME'], 'php.cgi') == strlen($_SERVER['SCRIPT_FILENAME']) - 7 ) )
86     $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
87
88 // Fix for Dreamhost and other PHP as CGI hosts
89 if (strpos($_SERVER['SCRIPT_NAME'], 'php.cgi') !== false)
90     unset($_SERVER['PATH_INFO']);
91
92 // Fix empty PHP_SELF
93 $PHP_SELF = $_SERVER['PHP_SELF'];
94 if ( empty($PHP_SELF) )
95     $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace("/(\?.*)?$/",'',$_SERVER["REQUEST_URI"]);
96
97 if ( version_compare( '4.3', phpversion(), '>' ) ) {
98     die( 'Your server is running PHP version ' . phpversion() . ' but WordPress requires at least 4.3.' );
99 }
100
101 if ( !extension_loaded('mysql') && !file_exists(ABSPATH . 'wp-content/db.php') )
102     die( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' );
103
104 /**
105  * timer_start() - PHP 4 standard microtime start capture
106  *
107  * @access private
108  * @since 0.71
109  * @global int $timestart Seconds and Microseconds added together from when function is called
110  * @return bool Always returns true
111  */
112 function timer_start() {
113     global $timestart;
114     $mtime = explode(' ', microtime() );
115     $mtime = $mtime[1] + $mtime[0];
116     $timestart = $mtime;
117     return true;
118 }
119
120 /**
121  * timer_stop() - Return and/or display the time from the page start to when function is called.
122  *
123  * You can get the results and print them by doing:
124  * <code>
125  * $nTimePageTookToExecute = timer_stop();
126  * echo $nTimePageTookToExecute;
127  * </code>
128  *
129  * Or instead, you can do:
130  * <code>
131  * timer_stop(1);
132  * </code>
133  * which will do what the above does. If you need the result, you can assign it to a variable, but
134  * most cases, you only need to echo it.
135  *
136  * @since 0.71
137  * @global int $timestart Seconds and Microseconds added together from when timer_start() is called
138  * @global int $timeend  Seconds and Microseconds added together from when function is called
139  *
140  * @param int $display Use '0' or null to not echo anything and 1 to echo the total time
141  * @param int $precision The amount of digits from the right of the decimal to display. Default is 3.
142  * @return float The "second.microsecond" finished time calculation
143  */
144 function timer_stop($display = 0, $precision = 3) { //if called like timer_stop(1), will echo $timetotal
145     global $timestart, $timeend;
146     $mtime = microtime();
147     $mtime = explode(' ',$mtime);
148     $mtime = $mtime[1] + $mtime[0];
149     $timeend = $mtime;
150     $timetotal = $timeend-$timestart;
151     $r = ( function_exists('number_format_i18n') ) ? number_format_i18n($timetotal, $precision) : number_format($timetotal, $precision);
152     if ( $display )
153         echo $r;
154     return $r;
155 }
156 timer_start();
157
158 // Add define('WP_DEBUG',true); to wp-config.php to enable display of notices during development.
159 if (defined('WP_DEBUG') and WP_DEBUG == true) {
160     error_reporting(E_ALL);
161 } else {
162     error_reporting(E_ALL ^ E_NOTICE ^ E_USER_NOTICE);
163 }
164
165 // For an advanced caching plugin to use, static because you would only want one
166 if ( defined('WP_CACHE') )
167     @include ABSPATH . 'wp-content/advanced-cache.php';
168
169 /**
170  * Stores the location of the WordPress directory of functions, classes, and core content.
171  *
172  * @since 1.0.0
173  */
174 define('WPINC', 'wp-includes');
175
176 if ( !defined('LANGDIR') ) {
177     /**
178      * Stores the location of the language directory. First looks for language folder in wp-content
179      * and uses that folder if it exists. Or it uses the "languages" folder in WPINC.
180      *
181      * @since 2.1.0
182      */
183     if ( file_exists(ABSPATH . 'wp-content/languages') && @is_dir(ABSPATH . 'wp-content/languages') )
184         define('LANGDIR', 'wp-content/languages'); // no leading slash, no trailing slash
185     else
186         define('LANGDIR', WPINC . '/languages'); // no leading slash, no trailing slash
187 }
188
189 /**
190  * Allows for the plugins directory to be moved from the default location.
191  *
192  * This isn't used everywhere. Constant is not used in plugin_basename()
193  * which might cause conflicts with changing this.
194  *
195  * @since 2.1
196  */
197 if ( !defined('PLUGINDIR') )
198     define('PLUGINDIR', 'wp-content/plugins'); // no leading slash, no trailing slash
199
200 require (ABSPATH . WPINC . '/compat.php');
201 require (ABSPATH . WPINC . '/functions.php');
202 require (ABSPATH . WPINC . '/classes.php');
203
204 require_wp_db();
205
206 if ( !empty($wpdb->error) )
207     dead_db();
208
209 $prefix = $wpdb->set_prefix($table_prefix);
210
211 if ( is_wp_error($prefix) )
212     wp_die('<strong>ERROR</strong>: <code>$table_prefix</code> in <code>wp-config.php</code> can only contain numbers, letters, and underscores.');
213 // Table names. prefix is bare "wp_"
214 $wpdb->blogs        = $wpdb->prefix . 'blogs';
215 $wpdb->site        = $wpdb->prefix . 'site';
216 $wpdb->sitemeta        = $wpdb->prefix . 'sitemeta';
217 $wpdb->sitecategories    = $wpdb->prefix . 'sitecategories';
218 $wpdb->signups        = $wpdb->prefix . 'signups';
219 $wpdb->registration_log    = $wpdb->prefix . 'registration_log';
220 $wpdb->blog_versions    = $wpdb->prefix . 'blog_versions';
221
222 if( defined( 'SUNRISE' ) )
223     include_once( ABSPATH . 'wp-content/sunrise.php' );
224
225 require_once ( ABSPATH . 'wpmu-settings.php' );
226 $prefix = $table_prefix;
227 $wpdb->prefix           = $table_prefix; // prefix now includes a blog_id
228 $wpdb->posts            = $wpdb->prefix . 'posts';
229 $wpdb->categories       = $wpdb->prefix . 'categories';
230 $wpdb->post2cat         = $wpdb->prefix . 'post2cat';
231 $wpdb->comments         = $wpdb->prefix . 'comments';
232 $wpdb->link2cat         = $wpdb->prefix . 'link2cat';
233 $wpdb->links            = $wpdb->prefix . 'links';
234 $wpdb->linkcategories   = $wpdb->prefix . 'linkcategories';
235 $wpdb->options          = $wpdb->prefix . 'options';
236 $wpdb->postmeta         = $wpdb->prefix . 'postmeta';
237 $wpdb->terms            = $wpdb->prefix . 'terms';
238 $wpdb->term_taxonomy    = $wpdb->prefix . 'term_taxonomy';
239 $wpdb->term_relationships = $wpdb->prefix . 'term_relationships';
240 $wpdb->siteid           = $current_blog->site_id;
241 $wpdb->blogid           = $current_blog->blog_id;
242
243 if ( defined('CUSTOM_USER_TABLE') )
244     $wpdb->users = CUSTOM_USER_TABLE;
245 if ( defined('CUSTOM_USER_META_TABLE') )
246     $wpdb->usermeta = CUSTOM_USER_META_TABLE;
247
248 if ( file_exists(ABSPATH . 'wp-content/object-cache.php') )
249     require_once (ABSPATH . 'wp-content/object-cache.php');
250 else
251     require_once (ABSPATH . WPINC . '/cache.php');
252
253 wp_cache_init();
254
255 if( !defined( "UPLOADS" ) )
256     define( "UPLOADS", "wp-content/blogs.dir/{$wpdb->blogid}/files/" );
257
258 require (ABSPATH . WPINC . '/plugin.php');
259 require (ABSPATH . WPINC . '/default-filters.php');
260
261 if( defined( "SHORTINIT" ) && constant( "SHORTINIT" ) == true ) // stop most of WP being loaded, we just want the basics
262     return;
263
264 include_once(ABSPATH . WPINC . '/streams.php');
265 include_once(ABSPATH . WPINC . '/gettext.php');
266 require_once (ABSPATH . WPINC . '/l10n.php');
267
268 if ( !is_blog_installed() && (strpos($_SERVER['PHP_SELF'], 'install.php') === false && !defined('WP_INSTALLING')) ) {
269     if ( defined('WP_SITEURL') )
270         $link = WP_SITEURL . '/wp-admin/install.php';
271     elseif (strpos($_SERVER['PHP_SELF'], 'wp-admin') !== false)
272         $link = preg_replace('|/wp-admin/?.*?$|', '/', $_SERVER['PHP_SELF']) . 'wp-admin/install.php';
273     else
274         $link = preg_replace('|/[^/]+?$|', '/', $_SERVER['PHP_SELF']) . 'wp-admin/install.php';
275     require_once(ABSPATH . WPINC . '/kses.php');
276     require_once(ABSPATH . WPINC . '/pluggable.php');
277     wp_redirect($link);
278     die(); // have to die here ~ Mark
279 }
280
281 require (ABSPATH . WPINC . '/formatting.php');
282 require (ABSPATH . WPINC . '/capabilities.php');
283 require (ABSPATH . WPINC . '/query.php');
284 require (ABSPATH . WPINC . '/theme.php');
285 require (ABSPATH . WPINC . '/user.php');
286 require (ABSPATH . WPINC . '/general-template.php');
287 require (ABSPATH . WPINC . '/link-template.php');
288 require (ABSPATH . WPINC . '/author-template.php');
289 require (ABSPATH . WPINC . '/post.php');
290 require (ABSPATH . WPINC . '/post-template.php');
291 require (ABSPATH . WPINC . '/category.php');
292 require (ABSPATH . WPINC . '/category-template.php');
293 require (ABSPATH . WPINC . '/comment.php');
294 require (ABSPATH . WPINC . '/comment-template.php');
295 require (ABSPATH . WPINC . '/rewrite.php');
296 require (ABSPATH . WPINC . '/feed.php');
297 require (ABSPATH . WPINC . '/bookmark.php');
298 require (ABSPATH . WPINC . '/bookmark-template.php');
299 require (ABSPATH . WPINC . '/kses.php');
300 require (ABSPATH . WPINC . '/cron.php');
301 require (ABSPATH . WPINC . '/version.php');
302 require (ABSPATH . WPINC . '/deprecated.php');
303 require (ABSPATH . WPINC . '/script-loader.php');
304 require (ABSPATH . WPINC . '/taxonomy.php');
305 require (ABSPATH . WPINC . '/update.php');
306 require (ABSPATH . WPINC . '/canonical.php');
307 require (ABSPATH . WPINC . '/shortcodes.php');
308 require (ABSPATH . WPINC . '/media.php');
309
310 require_once( ABSPATH . WPINC . '/wpmu-functions.php' );
311
312 if( defined( "WP_INSTALLING" ) == false )
313     $current_site->site_name = get_site_option('site_name');
314
315 if( $current_site->site_name == false ) {
316     $current_site->site_name = ucfirst( $current_site->domain );
317 }
318
319 if( defined('WP_INSTALLING') == false ) {
320     $locale = get_option('WPLANG');
321     if( $locale === false )
322         $locale = get_site_option('WPLANG');
323 }
324
325 $wpdb->hide_errors();
326 if( defined( 'MUPLUGINDIR' ) == false )
327     define( 'MUPLUGINDIR', 'wp-content/mu-plugins' );
328
329 if( is_dir( ABSPATH . MUPLUGINDIR ) ) {
330     if( $dh = opendir( ABSPATH . MUPLUGINDIR ) ) {
331         while( ( $plugin = readdir( $dh ) ) !== false ) {
332             if( substr( $plugin, -4 ) == '.php' ) {
333                 include_once( ABSPATH . MUPLUGINDIR . '/' . $plugin );
334             }
335         }
336     }
337 }
338 $wpdb->show_errors();
339
340 if ( '1' == $current_blog->deleted )
341     graceful_fail(__('This user has elected to delete their account and the content is no longer available.'));
342
343 if ( '2' == $current_blog->deleted )
344         graceful_fail(sprintf(__('This blog has not been activated yet. If you are having problems activating your blog, please contact <a href="mailto:%1$s">%1$s</a>.'), get_site_option( 'admin_email', "support@{$current_site->domain}" )));
345
346 if( $current_blog->archived == '1' )
347     graceful_fail(__('This blog has been archived or suspended.'));
348
349 if( $current_blog->spam == '1' )
350     graceful_fail(__('This blog has been archived or suspended.'));
351
352 define('COOKIEHASH', '');
353
354 /**
355  * Should be exactly the same as the default value of SECRET_KEY in wp-config-sample.php
356  * @since 2.5
357  */
358 $wp_default_secret_key = 'put your unique phrase here';
359
360 /**
361  * It is possible to define this in wp-config.php
362  * @since 2.0.0
363  */
364 if ( !defined('USER_COOKIE') )
365     define('USER_COOKIE', 'wordpressuser');
366
367 /**
368  * It is possible to define this in wp-config.php
369  * @since 2.0.0
370  */
371 if ( !defined('PASS_COOKIE') )
372     define('PASS_COOKIE', 'wordpresspass');
373
374 /**
375  * It is possible to define this in wp-config.php
376  * @since 2.5
377  */
378 if ( !defined('AUTH_COOKIE') )
379     define('AUTH_COOKIE', 'wordpress');
380
381 /**
382  * It is possible to define this in wp-config.php
383  * @since 2.3.0
384  */
385 if ( !defined('TEST_COOKIE') )
386     define('TEST_COOKIE', 'wordpress_test_cookie');
387
388 /**
389  * It is possible to define this in wp-config.php
390  * @since 1.2.0
391  */
392 if ( !defined('COOKIEPATH') )
393     define('COOKIEPATH', $current_site->path );
394
395 /**
396  * It is possible to define this in wp-config.php
397  * @since 1.5.0
398  */
399 if ( !defined('SITECOOKIEPATH') )
400     define('SITECOOKIEPATH', $current_site->path );
401
402 /**
403  * It is possible to define this in wp-config.php
404  * @since 2.0.0
405  */
406 if ( !defined('COOKIE_DOMAIN') )
407     define('COOKIE_DOMAIN', '.' . $current_site->domain);
408
409 require (ABSPATH . WPINC . '/vars.php');
410
411 if ( !defined('PLUGINDIR') )
412     define('PLUGINDIR', 'wp-content/plugins'); // no leading slash, no trailing slash
413
414 if ( get_option('active_plugins') ) {
415     $current_plugins = get_option('active_plugins');
416     if ( is_array($current_plugins) ) {
417         foreach ($current_plugins as $plugin) {
418             if ('' != $plugin && file_exists(ABSPATH . PLUGINDIR . '/' . $plugin))
419                 include_once(ABSPATH . PLUGINDIR . '/' . $plugin);
420         }
421     }
422 }
423
424 require (ABSPATH . WPINC . '/pluggable.php');
425
426 /*
427  * In most cases the default internal encoding is latin1, which is of no use,
428  * since we want to use the mb_ functions for utf-8 strings
429  */
430 if (function_exists('mb_internal_encoding')) {
431     if (!@mb_internal_encoding(get_option('blog_charset')))
432         mb_internal_encoding('UTF-8');
433 }
434
435
436 if ( defined('WP_CACHE') && function_exists('wp_cache_postload') )
437     wp_cache_postload();
438
439 do_action('plugins_loaded');
440
441 // If already slashed, strip.
442 if ( get_magic_quotes_gpc() ) {
443     $_GET    = stripslashes_deep($_GET   );
444     $_POST   = stripslashes_deep($_POST  );
445     $_COOKIE = stripslashes_deep($_COOKIE);
446 }
447
448 // Escape with wpdb.
449 $_GET    = add_magic_quotes($_GET   );
450 $_POST   = add_magic_quotes($_POST  );
451 $_COOKIE = add_magic_quotes($_COOKIE);
452 $_SERVER = add_magic_quotes($_SERVER);
453
454 do_action('sanitize_comment_cookies');
455
456 /**
457  * WordPress Query object
458  * @global object $wp_the_query
459  * @since 2.0.0
460  */
461 $wp_the_query =& new WP_Query();
462
463 /**
464  * Holds the reference to @see $wp_the_query
465  * Use this global for WordPress queries
466  * @global object $wp_query
467  * @since 1.5.0
468  */
469 $wp_query     =& $wp_the_query;
470
471 /**
472  * Holds the WordPress Rewrite object for creating pretty URLs
473  * @global object $wp_rewrite
474  * @since 1.5.0
475  */
476 $wp_rewrite   =& new WP_Rewrite();
477
478 /**
479  * WordPress Object
480  * @global object $wp
481  * @since 2.0.0
482  */
483 $wp           =& new WP();
484
485
486 /**
487  * Web Path to the current active template directory
488  * @since 1.5
489  */
490 define('TEMPLATEPATH', get_template_directory());
491
492 /**
493  * Web Path to the current active template stylesheet directory
494  * @since 2.1
495  */
496 define('STYLESHEETPATH', get_stylesheet_directory());
497
498 // Load the default text localization domain.
499 load_default_textdomain();
500
501 /**
502  * The locale of the blog
503  * @since 1.5.0
504  */
505 $locale = get_locale();
506 $locale_file = ABSPATH . LANGDIR . "/$locale.php";
507 if ( is_readable($locale_file) )
508     require_once($locale_file);
509
510 // Pull in locale data after loading text domain.
511 require_once(ABSPATH . WPINC . '/locale.php');
512
513 /**
514  * WordPress Locale object for loading locale domain date and various strings.
515  * @global object $wp_locale
516  * @since 2.1.0
517  */
518 $wp_locale =& new WP_Locale();
519
520 // Load functions for active theme.
521 if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists(STYLESHEETPATH . '/functions.php') )
522     include(STYLESHEETPATH . '/functions.php');
523 if ( file_exists(TEMPLATEPATH . '/functions.php') )
524     include(TEMPLATEPATH . '/functions.php');
525
526 /**
527  * shutdown_action_hook() - Runs just before PHP shuts down execution.
528  *
529  * @access private
530  * @since 1.2
531  */
532 function shutdown_action_hook() {
533     do_action('shutdown');
534     wp_cache_close();
535 }
536 register_shutdown_function('shutdown_action_hook');
537
538 $wp->init();  // Sets up current user.
539
540 // Everything is loaded and initialized.
541 do_action('init');
542
543 ?>
544
Note: See TracBrowser for help on using the browser.