root/tags/2.3.1/wp-settings.php

Revision 6139, 10.5 kB (checked in by markjaquith, 1 year ago)

Make sure number_format_i18n() is available before calling it in timer_stop(). fixes #5016

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php
2 // Turn register globals off
3 function wp_unregister_GLOBALS() {
4     if ( !ini_get('register_globals') )
5         return;
6
7     if ( isset($_REQUEST['GLOBALS']) )
8         die('GLOBALS overwrite attempt detected');
9
10     // Variables that shouldn't be unset
11     $noUnset = array('GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'table_prefix');
12
13     $input = array_merge($_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset($_SESSION) && is_array($_SESSION) ? $_SESSION : array());
14     foreach ( $input as $k => $v )
15         if ( !in_array($k, $noUnset) && isset($GLOBALS[$k]) ) {
16             $GLOBALS[$k] = NULL;
17             unset($GLOBALS[$k]);
18         }
19 }
20
21 wp_unregister_GLOBALS();
22
23 unset( $wp_filter, $cache_userdata, $cache_lastcommentmodified, $cache_lastpostdate, $cache_settings, $category_cache, $cache_categories );
24
25 if ( ! isset($blog_id) )
26     $blog_id = 1;
27
28 // Fix for IIS, which doesn't set REQUEST_URI
29 if ( empty( $_SERVER['REQUEST_URI'] ) ) {
30
31     // IIS Mod-Rewrite
32     if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
33         $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
34     }
35     // IIS Isapi_Rewrite
36     else if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
37         $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
38     }
39     else {
40         // If root then simulate that no script-name was specified
41         if (empty($_SERVER['PATH_INFO']))
42             $_SERVER['REQUEST_URI'] = substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], '/')) . '/';
43         elseif ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] )
44             // Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice)
45             $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
46         else
47             $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
48
49         // Append the query string if it exists and isn't null
50         if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
51             $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
52         }
53     }
54 }
55
56 // Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests
57 if ( isset($_SERVER['SCRIPT_FILENAME']) && ( strpos($_SERVER['SCRIPT_FILENAME'], 'php.cgi') == strlen($_SERVER['SCRIPT_FILENAME']) - 7 ) )
58     $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
59
60 // Fix for Dreamhost and other PHP as CGI hosts
61 if (strpos($_SERVER['SCRIPT_NAME'], 'php.cgi') !== false)
62     unset($_SERVER['PATH_INFO']);
63
64 // Fix empty PHP_SELF
65 $PHP_SELF = $_SERVER['PHP_SELF'];
66 if ( empty($PHP_SELF) )
67     $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace("/(\?.*)?$/",'',$_SERVER["REQUEST_URI"]);
68
69 if ( version_compare( '4.2', phpversion(), '>' ) ) {
70     die( 'Your server is running PHP version ' . phpversion() . ' but WordPress requires at least 4.2.' );
71 }
72
73 if ( !extension_loaded('mysql') && !file_exists(ABSPATH . 'wp-content/db.php') )
74     die( 'Your PHP installation appears to be missing the MySQL which is required for WordPress.' );
75
76 function timer_start() {
77     global $timestart;
78     $mtime = explode(' ', microtime() );
79     $mtime = $mtime[1] + $mtime[0];
80     $timestart = $mtime;
81     return true;
82 }
83
84 function timer_stop($display = 0, $precision = 3) { //if called like timer_stop(1), will echo $timetotal
85     global $timestart, $timeend;
86     $mtime = microtime();
87     $mtime = explode(' ',$mtime);
88     $mtime = $mtime[1] + $mtime[0];
89     $timeend = $mtime;
90     $timetotal = $timeend-$timestart;
91     $r = ( function_exists('number_format_i18n') ) ? number_format_i18n($timetotal, $precision) : number_format($timetotal, $precision);
92     if ( $display )
93         echo $r;
94     return $r;
95 }
96 timer_start();
97
98 // Change to E_ALL for development/debugging
99 error_reporting(E_ALL ^ E_NOTICE);
100
101 // For an advanced caching plugin to use, static because you would only want one
102 if ( defined('WP_CACHE') )
103     @include ABSPATH . 'wp-content/advanced-cache.php';
104
105 define('WPINC', 'wp-includes');
106
107 if ( !defined('LANGDIR') ) {
108     if ( file_exists(ABSPATH . 'wp-content/languages') && @is_dir(ABSPATH . 'wp-content/languages') )
109         define('LANGDIR', 'wp-content/languages'); // no leading slash, no trailing slash
110     else
111         define('LANGDIR', WPINC . '/languages'); // no leading slash, no trailing slash
112 }
113
114 if ( !defined('PLUGINDIR') )
115     define('PLUGINDIR', 'wp-content/plugins'); // no leading slash, no trailing slash
116
117 require (ABSPATH . WPINC . '/compat.php');
118 require (ABSPATH . WPINC . '/functions.php');
119
120 if ( file_exists(ABSPATH . 'wp-content/db.php') )
121     require_once (ABSPATH . 'wp-content/db.php');
122 else
123     require_once (ABSPATH . WPINC . '/wp-db.php');
124
125 // $table_prefix is deprecated as of 2.1
126 $wpdb->prefix = $table_prefix;
127
128 if ( preg_match('|[^a-z0-9_]|i', $wpdb->prefix) && !file_exists(ABSPATH . 'wp-content/db.php') )
129     wp_die("<strong>ERROR</strong>: <code>$table_prefix</code> in <code>wp-config.php</code> can only contain numbers, letters, and underscores.");
130
131 // Table names
132 $wpdb->posts          = $wpdb->prefix . 'posts';
133 $wpdb->users          = $wpdb->prefix . 'users';
134 $wpdb->categories     = $wpdb->prefix . 'categories';
135 $wpdb->post2cat       = $wpdb->prefix . 'post2cat';
136 $wpdb->comments       = $wpdb->prefix . 'comments';
137 $wpdb->link2cat       = $wpdb->prefix . 'link2cat';
138 $wpdb->links          = $wpdb->prefix . 'links';
139 $wpdb->options        = $wpdb->prefix . 'options';
140 $wpdb->postmeta       = $wpdb->prefix . 'postmeta';
141 $wpdb->usermeta       = $wpdb->prefix . 'usermeta';
142 $wpdb->terms          = $wpdb->prefix . 'terms';
143 $wpdb->term_taxonomy  = $wpdb->prefix . 'term_taxonomy';
144 $wpdb->term_relationships = $wpdb->prefix . 'term_relationships';
145
146 if ( defined('CUSTOM_USER_TABLE') )
147     $wpdb->users = CUSTOM_USER_TABLE;
148 if ( defined('CUSTOM_USER_META_TABLE') )
149     $wpdb->usermeta = CUSTOM_USER_META_TABLE;
150
151 if ( file_exists(ABSPATH . 'wp-content/object-cache.php') )
152     require_once (ABSPATH . 'wp-content/object-cache.php');
153 else
154     require_once (ABSPATH . WPINC . '/cache.php');
155
156 wp_cache_init();
157
158 require (ABSPATH . WPINC . '/classes.php');
159 require (ABSPATH . WPINC . '/plugin.php');
160 require (ABSPATH . WPINC . '/default-filters.php');
161 include_once(ABSPATH . WPINC . '/streams.php');
162 include_once(ABSPATH . WPINC . '/gettext.php');
163 require_once (ABSPATH . WPINC . '/l10n.php');
164
165 if ( !is_blog_installed() && (strpos($_SERVER['PHP_SELF'], 'install.php') === false && !defined('WP_INSTALLING')) ) {
166     if ( defined('WP_SITEURL') )
167         $link = WP_SITEURL . '/wp-admin/install.php';
168     elseif (strpos($_SERVER['PHP_SELF'], 'wp-admin') !== false)
169         $link = preg_replace('|/wp-admin/?.*?$|', '/', $_SERVER['PHP_SELF']) . 'wp-admin/install.php';
170     else
171         $link = preg_replace('|/[^/]+?$|', '/', $_SERVER['PHP_SELF']) . 'wp-admin/install.php';
172     require_once(ABSPATH . WPINC . '/kses.php');
173     require_once(ABSPATH . WPINC . '/pluggable.php');
174     wp_redirect($link);
175     die(); // have to die here ~ Mark
176 }
177
178 require (ABSPATH . WPINC . '/formatting.php');
179 require (ABSPATH . WPINC . '/capabilities.php');
180 require (ABSPATH . WPINC . '/query.php');
181 require (ABSPATH . WPINC . '/theme.php');
182 require (ABSPATH . WPINC . '/user.php');
183 require (ABSPATH . WPINC . '/general-template.php');
184 require (ABSPATH . WPINC . '/link-template.php');
185 require (ABSPATH . WPINC . '/author-template.php');
186 require (ABSPATH . WPINC . '/post.php');
187 require (ABSPATH . WPINC . '/post-template.php');
188 require (ABSPATH . WPINC . '/category.php');
189 require (ABSPATH . WPINC . '/category-template.php');
190 require (ABSPATH . WPINC . '/comment.php');
191 require (ABSPATH . WPINC . '/comment-template.php');
192 require (ABSPATH . WPINC . '/rewrite.php');
193 require (ABSPATH . WPINC . '/feed.php');
194 require (ABSPATH . WPINC . '/bookmark.php');
195 require (ABSPATH . WPINC . '/bookmark-template.php');
196 require (ABSPATH . WPINC . '/kses.php');
197 require (ABSPATH . WPINC . '/cron.php');
198 require (ABSPATH . WPINC . '/version.php');
199 require (ABSPATH . WPINC . '/deprecated.php');
200 require (ABSPATH . WPINC . '/script-loader.php');
201 require (ABSPATH . WPINC . '/taxonomy.php');
202 require (ABSPATH . WPINC . '/update.php');
203 require (ABSPATH . WPINC . '/canonical.php');
204
205 if (strpos($_SERVER['PHP_SELF'], 'install.php') === false) {
206     // Used to guarantee unique hash cookies
207     $cookiehash = md5(get_option('siteurl'));
208     define('COOKIEHASH', $cookiehash);
209 }
210
211 if ( !defined('USER_COOKIE') )
212     define('USER_COOKIE', 'wordpressuser_'. COOKIEHASH);
213 if ( !defined('PASS_COOKIE') )
214     define('PASS_COOKIE', 'wordpresspass_'. COOKIEHASH);
215 if ( !defined('TEST_COOKIE') )
216     define('TEST_COOKIE', 'wordpress_test_cookie');
217 if ( !defined('COOKIEPATH') )
218     define('COOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('home') . '/' ) );
219 if ( !defined('SITECOOKIEPATH') )
220     define('SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('siteurl') . '/' ) );
221 if ( !defined('COOKIE_DOMAIN') )
222     define('COOKIE_DOMAIN', false);
223
224 require (ABSPATH . WPINC . '/vars.php');
225
226 // Check for hacks file if the option is enabled
227 if (get_option('hack_file')) {
228     if (file_exists(ABSPATH . 'my-hacks.php'))
229         require(ABSPATH . 'my-hacks.php');
230 }
231
232 if ( get_option('active_plugins') ) {
233     $current_plugins = get_option('active_plugins');
234     if ( is_array($current_plugins) ) {
235         foreach ($current_plugins as $plugin) {
236             if ('' != $plugin && file_exists(ABSPATH . PLUGINDIR . '/' . $plugin))
237                 include_once(ABSPATH . PLUGINDIR . '/' . $plugin);
238         }
239     }
240 }
241
242 require (ABSPATH . WPINC . '/pluggable.php');
243
244 if ( defined('WP_CACHE') && function_exists('wp_cache_postload') )
245     wp_cache_postload();
246
247 do_action('plugins_loaded');
248
249 // If already slashed, strip.
250 if ( get_magic_quotes_gpc() ) {
251     $_GET    = stripslashes_deep($_GET   );
252     $_POST   = stripslashes_deep($_POST  );
253     $_COOKIE = stripslashes_deep($_COOKIE);
254 }
255
256 // Escape with wpdb.
257 $_GET    = add_magic_quotes($_GET   );
258 $_POST   = add_magic_quotes($_POST  );
259 $_COOKIE = add_magic_quotes($_COOKIE);
260 $_SERVER = add_magic_quotes($_SERVER);
261
262 do_action('sanitize_comment_cookies');
263
264 $wp_the_query =& new WP_Query();
265 $wp_query     =& $wp_the_query;
266 $wp_rewrite   =& new WP_Rewrite();
267 $wp           =& new WP();
268
269 validate_current_theme();
270 define('TEMPLATEPATH', get_template_directory());
271 define('STYLESHEETPATH', get_stylesheet_directory());
272
273 // Load the default text localization domain.
274 load_default_textdomain();
275
276 $locale = get_locale();
277 $locale_file = ABSPATH . LANGDIR . "/$locale.php";
278 if ( is_readable($locale_file) )
279     require_once($locale_file);
280
281 // Pull in locale data after loading text domain.
282 require_once(ABSPATH . WPINC . '/locale.php');
283
284 $wp_locale =& new WP_Locale();
285
286 // Load functions for active theme.
287 if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists(STYLESHEETPATH . '/functions.php') )
288     include(STYLESHEETPATH . '/functions.php');
289 if ( file_exists(TEMPLATEPATH . '/functions.php') )
290     include(TEMPLATEPATH . '/functions.php');
291
292 function shutdown_action_hook() {
293     do_action('shutdown');
294     wp_cache_close();
295 }
296 register_shutdown_function('shutdown_action_hook');
297
298 // Everything is loaded and initialized.
299 do_action('init');
300
301 ?>
302
Note: See TracBrowser for help on using the browser.