root/tags/1.3/wp-settings.php

Revision 1139, 13.0 kB (checked in by donncha, 10 months ago)

Merge with WordPress? 2.3.1

  • Property svn:eol-style set to native
Line 
1 <?php
2 if( defined( 'ABSPATH' ) == false )
3     die();
4
5 // Turn register globals off
6 function wp_unregister_GLOBALS() {
7     if ( !ini_get('register_globals') )
8         return;
9
10     if ( isset($_REQUEST['GLOBALS']) )
11         die('GLOBALS overwrite attempt detected');
12
13     // Variables that shouldn't be unset
14     $noUnset = array('GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'table_prefix');
15
16     $input = array_merge($_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset($_SESSION) && is_array($_SESSION) ? $_SESSION : array());
17     foreach ( $input as $k => $v )
18         if ( !in_array($k, $noUnset) && isset($GLOBALS[$k]) ) {
19             $GLOBALS[$k] = NULL;
20             unset($GLOBALS[$k]);
21         }
22 }
23
24 wp_unregister_GLOBALS();
25
26 if( isset( $_SERVER[ 'HTTP_USER_AGENT' ] ) ) {
27     $HTTP_USER_AGENT = $_SERVER[ 'HTTP_USER_AGENT' ];
28 } else {
29     $HTTP_USER_AGENT = '';
30 }
31 unset( $wp_filter, $cache_userdata, $cache_lastcommentmodified, $cache_lastpostdate, $cache_settings, $category_cache, $cache_categories );
32
33 if ( ! isset($blog_id) )
34     $blog_id = 0;
35
36 // Fix for IIS, which doesn't set REQUEST_URI
37 if ( empty( $_SERVER['REQUEST_URI'] ) ) {
38
39     // IIS Mod-Rewrite
40     if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
41         $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
42     }
43     // IIS Isapi_Rewrite
44     else if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
45         $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
46     }
47     else {
48         // If root then simulate that no script-name was specified
49         if (empty($_SERVER['PATH_INFO']))
50             $_SERVER['REQUEST_URI'] = substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], '/')) . '/';
51         elseif ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] )
52             // Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice)
53             $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
54         else
55             $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
56
57         // Append the query string if it exists and isn't null
58         if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
59             $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
60         }
61     }
62 }
63
64 // Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests
65 if ( isset($_SERVER['SCRIPT_FILENAME']) && ( strpos($_SERVER['SCRIPT_FILENAME'], 'php.cgi') == strlen($_SERVER['SCRIPT_FILENAME']) - 7 ) )
66     $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
67
68 // Fix for Dreamhost and other PHP as CGI hosts
69 if (strpos($_SERVER['SCRIPT_NAME'], 'php.cgi') !== false)
70     unset($_SERVER['PATH_INFO']);
71
72 // Fix empty PHP_SELF
73 $PHP_SELF = $_SERVER['PHP_SELF'];
74 if ( empty($PHP_SELF) )
75     $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace("/(\?.*)?$/",'',$_SERVER["REQUEST_URI"]);
76
77 if ( version_compare( '4.2', phpversion(), '>' ) ) {
78     die( 'Your server is running PHP version ' . phpversion() . ' but WordPress requires at least 4.2.' );
79 }
80
81 if ( !extension_loaded('mysql') && !file_exists(ABSPATH . 'wp-content/db.php') )
82     die( 'Your PHP installation appears to be missing the MySQL which is required for WordPress.' );
83
84 function timer_start() {
85     global $timestart;
86     $mtime = explode(' ', microtime() );
87     $mtime = $mtime[1] + $mtime[0];
88     $timestart = $mtime;
89     return true;
90 }
91
92 function timer_stop($display = 0, $precision = 3) { //if called like timer_stop(1), will echo $timetotal
93     global $timestart, $timeend;
94     $mtime = microtime();
95     $mtime = explode(' ',$mtime);
96     $mtime = $mtime[1] + $mtime[0];
97     $timeend = $mtime;
98     $timetotal = $timeend-$timestart;
99     $r = ( function_exists('number_format_i18n') ) ? number_format_i18n($timetotal, $precision) : number_format($timetotal, $precision);
100     if ( $display )
101         echo $r;
102     return $r;
103 }
104 timer_start();
105
106 // Change to E_ALL for development/debugging
107 error_reporting(E_ALL ^ E_NOTICE);
108
109 // For an advanced caching plugin to use, static because you would only want one
110 if ( defined('WP_CACHE') )
111     @include ABSPATH . 'wp-content/advanced-cache.php';
112
113 define('WPINC', 'wp-includes');
114
115 if ( !defined('LANGDIR') ) {
116     if ( file_exists(ABSPATH . 'wp-content/languages') && @is_dir(ABSPATH . 'wp-content/languages') )
117         define('LANGDIR', 'wp-content/languages'); // no leading slash, no trailing slash
118     else
119         define('LANGDIR', WPINC . '/languages'); // no leading slash, no trailing slash
120 }
121
122 if ( !defined('PLUGINDIR') )
123     define('PLUGINDIR', 'wp-content/plugins'); // no leading slash, no trailing slash
124
125 require (ABSPATH . WPINC . '/compat.php');
126 require (ABSPATH . WPINC . '/functions.php');
127
128 if ( file_exists(ABSPATH . 'wp-content/db.php') )
129     require_once (ABSPATH . 'wp-content/db.php');
130 else
131     require_once (ABSPATH . WPINC . '/wp-db.php');
132
133 // $table_prefix is deprecated as of 2.1
134 $wpdb->prefix = $wpdb->base_prefix = $table_prefix;
135
136 if ( preg_match('|[^a-z0-9_]|i', $wpdb->prefix) && !file_exists(ABSPATH . 'wp-content/db.php') )
137     wp_die("<strong>ERROR</strong>: <code>$table_prefix</code> in <code>wp-config.php</code> can only contain numbers, letters, and underscores.");
138
139 // Table names
140 $wpdb->blogs        = $wpdb->prefix . 'blogs';
141 $wpdb->site        = $wpdb->prefix . 'site';
142 $wpdb->sitemeta        = $wpdb->prefix . 'sitemeta';
143 $wpdb->sitecategories    = $wpdb->prefix . 'sitecategories';
144 $wpdb->signups        = $wpdb->prefix . 'signups';
145 $wpdb->registration_log    = $wpdb->prefix . 'registration_log';
146 $wpdb->blog_versions    = $wpdb->prefix . 'blog_versions';
147 $wpdb->users        = $wpdb->prefix . 'users';
148 $wpdb->usermeta        = $wpdb->prefix . 'usermeta';
149
150 if( defined( 'SUNRISE' ) )
151     include_once( ABSPATH . 'wp-content/sunrise.php' );
152
153 require_once ( ABSPATH . 'wpmu-settings.php' );
154 $wpdb->prefix           = $table_prefix;
155 $wpdb->posts            = $wpdb->prefix . 'posts';
156 $wpdb->categories       = $wpdb->prefix . 'categories';
157 $wpdb->post2cat         = $wpdb->prefix . 'post2cat';
158 $wpdb->comments         = $wpdb->prefix . 'comments';
159 $wpdb->link2cat         = $wpdb->prefix . 'link2cat';
160 $wpdb->links            = $wpdb->prefix . 'links';
161 $wpdb->linkcategories   = $wpdb->prefix . 'linkcategories';
162 $wpdb->options          = $wpdb->prefix . 'options';
163 $wpdb->postmeta         = $wpdb->prefix . 'postmeta';
164 $wpdb->terms          = $wpdb->prefix . 'terms';
165 $wpdb->term_taxonomy  = $wpdb->prefix . 'term_taxonomy';
166 $wpdb->term_relationships = $wpdb->prefix . 'term_relationships';
167 $wpdb->siteid           = $current_blog->site_id;
168 $wpdb->blogid           = $current_blog->blog_id;
169
170 if ( defined('CUSTOM_USER_TABLE') )
171     $wpdb->users = CUSTOM_USER_TABLE;
172 if ( defined('CUSTOM_USER_META_TABLE') )
173     $wpdb->usermeta = CUSTOM_USER_META_TABLE;
174
175 // To be removed in 2.2
176 $tableposts = $tableusers = $tablecategories = $tablepost2cat = $tablecomments = $tablelink2cat = $tablelinks = $tablelinkcategories = $tableoptions = $tablepostmeta = '';
177
178 if ( file_exists(ABSPATH . 'wp-content/object-cache.php') )
179     require_once (ABSPATH . 'wp-content/object-cache.php');
180 else
181     require_once (ABSPATH . WPINC . '/cache.php');
182
183 wp_cache_init();
184
185 if( !defined( "UPLOADS" ) )
186     define( "UPLOADS", "wp-content/blogs.dir/{$wpdb->blogid}/files/" );
187
188 require (ABSPATH . WPINC . '/classes.php');
189 require (ABSPATH . WPINC . '/plugin.php');
190 require (ABSPATH . WPINC . '/default-filters.php');
191
192 if( defined( "SHORTINIT" ) && constant( "SHORTINIT" ) == true ) // stop most of WP being loaded, we just want the basics
193     return;
194
195 include_once(ABSPATH . WPINC . '/streams.php');
196 include_once(ABSPATH . WPINC . '/gettext.php');
197 require_once (ABSPATH . WPINC . '/l10n.php');
198
199 if ( !is_blog_installed() && (strpos($_SERVER['PHP_SELF'], 'install.php') === false && !defined('WP_INSTALLING')) ) {
200     if ( defined('WP_SITEURL') )
201         $link = WP_SITEURL . '/wp-admin/install.php';
202     elseif (strpos($_SERVER['PHP_SELF'], 'wp-admin') !== false)
203         $link = preg_replace('|/wp-admin/?.*?$|', '/', $_SERVER['PHP_SELF']) . 'wp-admin/install.php';
204     else
205         $link = preg_replace('|/[^/]+?$|', '/', $_SERVER['PHP_SELF']) . 'wp-admin/install.php';
206     require_once(ABSPATH . WPINC . '/kses.php');
207     require_once(ABSPATH . WPINC . '/pluggable.php');
208     wp_redirect($link);
209     die(); // have to die here ~ Mark
210 }
211
212 require (ABSPATH . WPINC . '/formatting.php');
213 require (ABSPATH . WPINC . '/capabilities.php');
214 require (ABSPATH . WPINC . '/query.php');
215 require (ABSPATH . WPINC . '/theme.php');
216 require (ABSPATH . WPINC . '/user.php');
217 require (ABSPATH . WPINC . '/general-template.php');
218 require (ABSPATH . WPINC . '/link-template.php');
219 require (ABSPATH . WPINC . '/author-template.php');
220 require (ABSPATH . WPINC . '/post.php');
221 require (ABSPATH . WPINC . '/post-template.php');
222 require (ABSPATH . WPINC . '/category.php');
223 require (ABSPATH . WPINC . '/category-template.php');
224 require (ABSPATH . WPINC . '/comment.php');
225 require (ABSPATH . WPINC . '/comment-template.php');
226 require (ABSPATH . WPINC . '/rewrite.php');
227 require (ABSPATH . WPINC . '/feed.php');
228 require (ABSPATH . WPINC . '/bookmark.php');
229 require (ABSPATH . WPINC . '/bookmark-template.php');
230 require (ABSPATH . WPINC . '/kses.php');
231 require (ABSPATH . WPINC . '/cron.php');
232 require (ABSPATH . WPINC . '/version.php');
233 require (ABSPATH . WPINC . '/deprecated.php');
234 require (ABSPATH . WPINC . '/script-loader.php');
235 require (ABSPATH . WPINC . '/taxonomy.php');
236 require (ABSPATH . WPINC . '/update.php');
237 require (ABSPATH . WPINC . '/canonical.php');
238
239 require_once( ABSPATH . WPINC . '/wpmu-functions.php' );
240
241 if( defined( "WP_INSTALLING" ) == false ) {
242     $current_site->site_name = get_site_option('site_name');
243 }
244
245 if( $current_site->site_name == false ) {
246     $current_site->site_name = ucfirst( $current_site->domain );
247 }
248
249 if( defined('WP_INSTALLING') == false ) {
250     $locale = get_option('WPLANG');
251     if( $locale === false )
252         $locale = get_site_option('WPLANG');
253 }
254
255 $wpdb->hide_errors();
256 if( defined( 'MUPLUGINDIR' ) == false )
257     define( 'MUPLUGINDIR', 'wp-content/mu-plugins' );
258
259 $plugins = glob( ABSPATH . MUPLUGINDIR . '/*.php' );
260 if( is_array( $plugins ) ) {
261     foreach ( $plugins as $plugin ) {
262         if( is_file( $plugin ) )
263             include_once( $plugin );
264     }
265 }
266 $wpdb->show_errors();
267
268 if ( '1' == $current_blog->deleted )
269     graceful_fail(__('This user has elected to delete their account and the content is no longer available.'));
270
271 if ( '2' == $current_blog->deleted )
272         graceful_fail(sprintf(__('This blog has not been activated yet. If you are having problems activating your blog, please contact <a href="mailto:support@{%1$s}">support@{%1$s}</a>.'), $current_site->domain));
273
274 if( $current_blog->archived == '1' )
275     graceful_fail(__('This blog has been archived or suspended.'));
276
277 if( $current_blog->spam == '1' )
278     graceful_fail(__('This blog has been archived or suspended.'));
279
280 if (!strstr($_SERVER['PHP_SELF'], 'install.php') && !strstr($_SERVER['PHP_SELF'], 'wp-admin/import')) :
281     // Used to guarantee unique hash cookies
282     $cookiehash = ''; // Remove in 1.4
283     define('COOKIEHASH', '');
284 endif;
285
286 if ( !defined('USER_COOKIE') )
287     define('USER_COOKIE', 'wordpressuser');
288 if ( !defined('PASS_COOKIE') )
289     define('PASS_COOKIE', 'wordpresspass');
290 if ( !defined('COOKIEPATH') )
291     define('COOKIEPATH', $current_site->path );
292 if ( !defined('SITECOOKIEPATH') )
293     define('SITECOOKIEPATH', $current_site->path );
294 if ( !defined('COOKIE_DOMAIN') )
295     define('COOKIE_DOMAIN', '.' . $current_site->domain);
296
297 require (ABSPATH . WPINC . '/vars.php');
298
299 if ( !defined('PLUGINDIR') )
300     define('PLUGINDIR', 'wp-content/plugins'); // no leading slash, no trailing slash
301 if ( get_option('active_plugins') ) {
302     $current_plugins = get_option('active_plugins');
303     if ( is_array($current_plugins) ) {
304         foreach ($current_plugins as $plugin) {
305             if ('' != $plugin && file_exists(ABSPATH . PLUGINDIR . '/' . $plugin))
306                 include_once(ABSPATH . PLUGINDIR . '/' . $plugin);
307         }
308     }
309 }
310
311 require (ABSPATH . WPINC . '/pluggable.php');
312
313 if ( defined('WP_CACHE') && function_exists('wp_cache_postload') )
314     wp_cache_postload();
315
316 do_action('plugins_loaded');
317
318 // If already slashed, strip.
319 if ( get_magic_quotes_gpc() ) {
320     $_GET    = stripslashes_deep($_GET   );
321     $_POST   = stripslashes_deep($_POST  );
322     $_COOKIE = stripslashes_deep($_COOKIE);
323 }
324
325 // Escape with wpdb.
326 $_GET    = add_magic_quotes($_GET   );
327 $_POST   = add_magic_quotes($_POST  );
328 $_COOKIE = add_magic_quotes($_COOKIE);
329 $_SERVER = add_magic_quotes($_SERVER);
330
331 do_action('sanitize_comment_cookies');
332
333 $wp_the_query =& new WP_Query();
334 $wp_query     =& $wp_the_query;
335 $wp_rewrite   =& new WP_Rewrite();
336 $wp           =& new WP();
337
338 if( defined( "WP_INSTALLING" ) == false )
339     validate_current_theme();
340 define('TEMPLATEPATH', get_template_directory());
341 define('STYLESHEETPATH', get_stylesheet_directory());
342
343 // Load the default text localization domain.
344 load_default_textdomain();
345
346 $locale = get_locale();
347 $locale_file = ABSPATH . LANGDIR . "/$locale.php";
348 if ( is_readable($locale_file) )
349     require_once($locale_file);
350
351 // Pull in locale data after loading text domain.
352 require_once(ABSPATH . WPINC . '/locale.php');
353
354 $wp_locale =& new WP_Locale();
355
356 // Load functions for active theme.
357 if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists(STYLESHEETPATH . '/functions.php') )
358     include(STYLESHEETPATH . '/functions.php');
359 if ( file_exists(TEMPLATEPATH . '/functions.php') )
360     include(TEMPLATEPATH . '/functions.php');
361
362 function shutdown_action_hook() {
363     do_action('shutdown');
364     wp_cache_close();
365 }
366 register_shutdown_function('shutdown_action_hook');
367
368 // Everything is loaded and initialized.
369 do_action('init');
370
371 ?>
372
Note: See TracBrowser for help on using the browser.