]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-settings.php
Wordpress 2.0.2
[autoinstalls/wordpress.git] / wp-settings.php
1 <?php
2 // Turn register globals off
3 function 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                         unset($GLOBALS[$k]);
17 }
18
19 unregister_GLOBALS(); 
20
21 $HTTP_USER_AGENT = getenv('HTTP_USER_AGENT');
22 unset( $wp_filter, $cache_userdata, $cache_lastcommentmodified, $cache_lastpostdate, $cache_settings, $category_cache, $cache_categories );
23
24 if ( ! isset($blog_id) )
25         $blog_id = 1;
26
27 // Fix for IIS, which doesn't set REQUEST_URI
28 if ( empty( $_SERVER['REQUEST_URI'] ) ) {
29         $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME']; // Does this work under CGI?
30         
31         // Append the query string if it exists and isn't null
32         if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
33                 $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
34         }
35 }
36
37 // Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests
38 if ( isset($_SERVER['SCRIPT_FILENAME']) && ( strpos($_SERVER['SCRIPT_FILENAME'], 'php.cgi') == strlen($_SERVER['SCRIPT_FILENAME']) - 7 ) )
39         $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
40
41 // Fix for Dreamhost and other PHP as CGI hosts
42 if ( strstr( $_SERVER['SCRIPT_NAME'], 'php.cgi' ) )
43         unset($_SERVER['PATH_INFO']);
44
45 // Fix empty PHP_SELF
46 $PHP_SELF = $_SERVER['PHP_SELF'];
47 if ( empty($PHP_SELF) )
48         $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace("/(\?.*)?$/",'',$_SERVER["REQUEST_URI"]);
49
50 if ( !(phpversion() >= '4.1') )
51         die( 'Your server is running PHP version ' . phpversion() . ' but WordPress requires at least 4.1' );
52
53 if ( !extension_loaded('mysql') )
54         die( 'Your PHP installation appears to be missing the MySQL which is required for WordPress.' );
55
56 function timer_start() {
57         global $timestart;
58         $mtime = explode(' ', microtime() );
59         $mtime = $mtime[1] + $mtime[0];
60         $timestart = $mtime;
61         return true;
62 }
63 timer_start();
64
65 // Change to E_ALL for development/debugging
66 error_reporting(E_ALL ^ E_NOTICE);
67
68 // For an advanced caching plugin to use, static because you would only want one
69 if ( defined('WP_CACHE') )
70         require (ABSPATH . 'wp-content/advanced-cache.php');
71
72 define('WPINC', 'wp-includes');
73 require_once (ABSPATH . WPINC . '/wp-db.php');
74
75 // Table names
76 $wpdb->posts            = $table_prefix . 'posts';
77 $wpdb->users            = $table_prefix . 'users';
78 $wpdb->categories       = $table_prefix . 'categories';
79 $wpdb->post2cat         = $table_prefix . 'post2cat';
80 $wpdb->comments         = $table_prefix . 'comments';
81 $wpdb->links            = $table_prefix . 'links';
82 $wpdb->linkcategories   = $table_prefix . 'linkcategories';
83 $wpdb->options          = $table_prefix . 'options';
84 $wpdb->postmeta         = $table_prefix . 'postmeta';
85 $wpdb->usermeta         = $table_prefix . 'usermeta';
86
87 $wpdb->prefix           = $table_prefix;
88
89 if ( defined('CUSTOM_USER_TABLE') )
90         $wpdb->users = CUSTOM_USER_TABLE;
91 if ( defined('CUSTOM_USER_META_TABLE') )
92         $wpdb->usermeta = CUSTOM_USER_META_TABLE;
93
94 // We're going to need to keep this around for a few months even though we're not using it internally
95
96 $tableposts = $wpdb->posts;
97 $tableusers = $wpdb->users;
98 $tablecategories = $wpdb->categories;
99 $tablepost2cat = $wpdb->post2cat;
100 $tablecomments = $wpdb->comments;
101 $tablelinks = $wpdb->links;
102 $tablelinkcategories = $wpdb->linkcategories;
103 $tableoptions = $wpdb->options;
104 $tablepostmeta = $wpdb->postmeta;
105
106 if ( file_exists(ABSPATH . 'wp-content/object-cache.php') )
107         require (ABSPATH . 'wp-content/object-cache.php');
108 else
109         require (ABSPATH . WPINC . '/cache.php');
110
111 // To disable persistant caching, add the below line to your wp-config.php file, uncommented of course.
112 // define('DISABLE_CACHE', true);
113
114 wp_cache_init();
115
116 require (ABSPATH . WPINC . '/functions.php');
117 require (ABSPATH . WPINC . '/default-filters.php');
118 require_once (ABSPATH . WPINC . '/wp-l10n.php');
119
120 $wpdb->hide_errors();
121 $db_check = $wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'");
122 if ( !$db_check && (!strstr($_SERVER['PHP_SELF'], 'install.php') && !defined('WP_INSTALLING')) ) {
123         if ( strstr($_SERVER['PHP_SELF'], 'wp-admin') )
124                 $link = 'install.php';
125         else
126                 $link = 'wp-admin/install.php';
127         die(sprintf(__("It doesn't look like you've installed WP yet. Try running <a href='%s'>install.php</a>."), $link));
128 }
129 $wpdb->show_errors();
130
131 require (ABSPATH . WPINC . '/functions-formatting.php');
132 require (ABSPATH . WPINC . '/functions-post.php');
133 require (ABSPATH . WPINC . '/capabilities.php');
134 require (ABSPATH . WPINC . '/classes.php');
135 require (ABSPATH . WPINC . '/template-functions-general.php');
136 require (ABSPATH . WPINC . '/template-functions-links.php');
137 require (ABSPATH . WPINC . '/template-functions-author.php');
138 require (ABSPATH . WPINC . '/template-functions-post.php');
139 require (ABSPATH . WPINC . '/template-functions-category.php');
140 require (ABSPATH . WPINC . '/comment-functions.php');
141 require (ABSPATH . WPINC . '/feed-functions.php');
142 require (ABSPATH . WPINC . '/links.php');
143 require (ABSPATH . WPINC . '/kses.php');
144 require (ABSPATH . WPINC . '/version.php');
145
146 if (!strstr($_SERVER['PHP_SELF'], 'install.php')) :
147     // Used to guarantee unique hash cookies
148     $cookiehash = md5(get_settings('siteurl')); // Remove in 1.4
149         define('COOKIEHASH', $cookiehash); 
150 endif;
151
152 if ( !defined('USER_COOKIE') )
153         define('USER_COOKIE', 'wordpressuser_'. COOKIEHASH);
154 if ( !defined('PASS_COOKIE') )
155         define('PASS_COOKIE', 'wordpresspass_'. COOKIEHASH);
156 if ( !defined('COOKIEPATH') )
157         define('COOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_settings('home') . '/' ) );
158 if ( !defined('SITECOOKIEPATH') )
159         define('SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_settings('siteurl') . '/' ) );
160 if ( !defined('COOKIE_DOMAIN') )
161         define('COOKIE_DOMAIN', false);
162
163 require (ABSPATH . WPINC . '/vars.php');
164
165 // Check for hacks file if the option is enabled
166 if (get_settings('hack_file')) {
167         if (file_exists(ABSPATH . '/my-hacks.php'))
168                 require(ABSPATH . '/my-hacks.php');
169 }
170
171 if ( get_settings('active_plugins') ) {
172         $current_plugins = get_settings('active_plugins');
173         if ( is_array($current_plugins) ) {
174                 foreach ($current_plugins as $plugin) {
175                         if ('' != $plugin && file_exists(ABSPATH . 'wp-content/plugins/' . $plugin))
176                                 include_once(ABSPATH . 'wp-content/plugins/' . $plugin);
177                 }
178         }
179 }
180
181 require (ABSPATH . WPINC . '/pluggable-functions.php');
182
183 if ( defined('WP_CACHE') && function_exists('wp_cache_postload') )
184         wp_cache_postload();
185
186 do_action('plugins_loaded');
187
188 // If already slashed, strip.
189 if ( get_magic_quotes_gpc() ) {
190         $_GET    = stripslashes_deep($_GET   );
191         $_POST   = stripslashes_deep($_POST  );
192         $_COOKIE = stripslashes_deep($_COOKIE);
193 }
194
195 // Escape with wpdb.
196 $_GET    = add_magic_quotes($_GET   );
197 $_POST   = add_magic_quotes($_POST  );
198 $_COOKIE = add_magic_quotes($_COOKIE);
199 $_SERVER = add_magic_quotes($_SERVER);
200
201 $wp_query   = new WP_Query();
202 $wp_rewrite = new WP_Rewrite();
203 $wp         = new WP();
204
205 define('TEMPLATEPATH', get_template_directory());
206
207 // Load the default text localization domain.
208 load_default_textdomain();
209
210 // Pull in locale data after loading text domain.
211 require_once(ABSPATH . WPINC . '/locale.php');
212
213 // Load functions for active theme.
214 if ( file_exists(TEMPLATEPATH . "/functions.php") )
215         include(TEMPLATEPATH . "/functions.php");
216
217 function shutdown_action_hook() {
218         do_action('shutdown');
219         wp_cache_close();
220 }
221 register_shutdown_function('shutdown_action_hook');
222
223 // Everything is loaded and initialized.
224 do_action('init');
225
226 ?>