Log in with username/password: lyceum/lyceum

root/trunk/src/lib/wp-settings.php

Revision 616, 8.8 kB (checked in by jjb, 4 years ago)

Subdomains!

Most of the pieces in order to use subdomains. The way that cookies are set needs to be adapted to this system. As it is now, users have to keep re-logging-in when they switch from one domain to another.

Many thanks to coffelius of http://bloggear.net for help and code.

ticket:326

Line 
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 unregister_GLOBALS();
19
20 $HTTP_USER_AGENT = getenv('HTTP_USER_AGENT');
21 unset( $wp_filter, $cache_userdata, $cache_lastcommentmodified, $cache_lastpostdate, $cache_settings, $category_cache, $cache_categories );
22
23 if ( ! isset($blog_id) )
24     $blog_id = 1;
25
26 // Fix for IIS, which doesn't set REQUEST_URI
27 if ( empty( $_SERVER['REQUEST_URI'] ) ) {
28     $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME']; // Does this work under CGI?
29     
30     // Append the query string if it exists and isn't null
31     if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
32         $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
33     }
34 }
35
36 // Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests
37 if ( isset($_SERVER['SCRIPT_FILENAME']) && ( strpos($_SERVER['SCRIPT_FILENAME'], 'php.cgi') == strlen($_SERVER['SCRIPT_FILENAME']) - 7 ) )
38     $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
39
40 // Fix for Dreamhost and other PHP as CGI hosts
41 if ( strstr( $_SERVER['SCRIPT_NAME'], 'php.cgi' ) )
42     unset($_SERVER['PATH_INFO']);
43
44 // Fix empty PHP_SELF
45 $PHP_SELF = $_SERVER['PHP_SELF'];
46 if ( empty($PHP_SELF) )
47     $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace("/(\?.*)?$/",'',$_SERVER["REQUEST_URI"]);
48
49 function timer_start() {
50     global $timestart;
51     $mtime = explode(' ', microtime() );
52     $mtime = $mtime[1] + $mtime[0];
53     $timestart = $mtime;
54     return true;
55 }
56 timer_start();
57
58 // Change to E_ALL for development/debugging
59 //error_reporting(E_ALL ^ E_NOTICE);
60 //error_reporting(E_ALL);
61
62 // For an advanced caching plugin to use, static because you would only want one
63 if ( defined('WP_CACHE') )
64     require (ABSPATH . 'wp-content/advanced-cache.php');
65
66 define('WPINC', PRIVATE_REL_PATH . 'lib/wp-includes');
67 require_once (ABSPATH . WPINC . '/wp-db.php');
68
69 // Table names
70 $wpdb->posts            = $table_prefix . 'posts';
71 $wpdb->users            = $table_prefix . 'users';
72 $wpdb->categories       = $table_prefix . 'categories';
73 $wpdb->post2cat         = $table_prefix . 'post2cat';
74 $wpdb->comments         = $table_prefix . 'comments';
75 $wpdb->links            = $table_prefix . 'links';
76 $wpdb->linkcategories   = $table_prefix . 'linkcategories';
77 $wpdb->options          = $table_prefix . 'options';
78 $wpdb->postmeta         = $table_prefix . 'postmeta';
79 $wpdb->usermeta         = $table_prefix . 'usermeta';
80 $wpdb->blogs            = $table_prefix . 'blogs';
81 $wpdb->postsearch       = $table_prefix . 'postsearch';
82 $wpdb->sessions         = $table_prefix . 'sessions';
83
84 $wpdb->prefix           = $table_prefix;
85
86 if ( defined('CUSTOM_USER_TABLE') )
87     $wpdb->users = CUSTOM_USER_TABLE;
88 if ( defined('CUSTOM_USER_META_TABLE') )
89     $wpdb->usermeta = CUSTOM_USER_META_TABLE;
90
91 $tableposts = $wpdb->posts;
92 $tableusers = $wpdb->users;
93 $tablecategories = $wpdb->categories;
94 $tablepost2cat = $wpdb->post2cat;
95 $tablecomments = $wpdb->comments;
96 $tablelinks = $wpdb->links;
97 $tablelinkcategories = $wpdb->linkcategories;
98 $tableoptions = $wpdb->options;
99 $tablepostmeta = $wpdb->postmeta;
100
101 if ( file_exists(ABSPATH . 'wp-content/object-cache.php') )
102     require (ABSPATH . 'wp-content/object-cache.php');
103 else
104     require (ABSPATH . WPINC . '/cache.php');
105
106 // To disable persistant caching, add the below line to your wp-config.php file, uncommented of course.
107 define('DISABLE_CACHE', true);
108
109 wp_cache_init();
110
111 require (ABSPATH . WPINC . '/functions.php');
112 require (ABSPATH . WPINC . '/default-filters.php');
113 require_once (ABSPATH . WPINC . '/wp-l10n.php');
114
115 /*
116 $wpdb->hide_errors();
117 $db_check = $wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'");
118 if ( !$db_check && (!strstr($_SERVER['PHP_SELF'], 'install.php') && !defined('WP_INSTALLING')) ) {
119     if ( strstr($_SERVER['PHP_SELF'], 'wp-admin') )
120         $link = 'install.php';
121     else
122         $link = 'wp-admin/install.php';
123     die(sprintf(__("It doesn't look like you've installed WP yet. Try running <a href='%s'>install.php</a>."), $link));
124 }
125 $wpdb->show_errors();
126 */
127
128 require (ABSPATH . WPINC . '/functions-formatting.php');
129 require (ABSPATH . WPINC . '/functions-post.php');
130 require (ABSPATH . WPINC . '/capabilities.php');
131 require (ABSPATH . WPINC . '/classes.php');
132 require (ABSPATH . WPINC . '/template-functions-general.php');
133 require (ABSPATH . WPINC . '/template-functions-links.php');
134 require (ABSPATH . WPINC . '/template-functions-author.php');
135 require (ABSPATH . WPINC . '/template-functions-post.php');
136 require (ABSPATH . WPINC . '/template-functions-category.php');
137 require (ABSPATH . WPINC . '/comment-functions.php');
138 require (ABSPATH . WPINC . '/feed-functions.php');
139 require (ABSPATH . WPINC . '/links.php');
140 require (ABSPATH . WPINC . '/kses.php');
141 require (ABSPATH . WPINC . '/version.php');
142 require (PRIVATEROOT . 'lib/functions.php');
143 require (PRIVATEROOT . 'lib/session.php');
144
145 //TODO use cache
146 if (!isset($blogdata)){
147     if(SUBDOMAINS) {
148         $host=$_SERVER['HTTP_HOST'];
149         if(($pos=strpos($host, '.'.MAINDOMAIN))!==false)    {
150             $theslug=substr($host, 0, $pos);
151             $blogdata = $wpdb->get_row("SELECT * FROM `$wpdb->blogs` WHERE `slug`='{$theslug}'");
152             //trace('$blogdata', array_print($blogdata));
153             $blog = $blogdata->id;
154             $blogstatus = $blogdata->status;
155
156         } else {
157             if(!(strpos($_SERVER['REQUEST_URI'], '/system-admin')===0
158             or strpos($_SERVER['REQUEST_URI'], '/wp-')===0))
159             header('Location: '.PORTAL);
160         }
161     } else { // if(SUBDOMAINS)
162         if (!isset($_REQUEST['b']))
163             header('Location: '.PORTAL);//redirect to public portal
164         else {
165             $blogdata = $wpdb->get_row("SELECT * FROM `$wpdb->blogs` WHERE `id`='{$_REQUEST['b']}'");
166             //trace('$blogdata', array_print($blogdata));
167             $blog = $blogdata->id;
168             $blogstatus = $blogdata->status;
169         }
170
171     }   
172
173 }
174 if (!isset($blog))
175     $blog = 'NULL';
176
177 if (!strstr($_SERVER['PHP_SELF'], 'install.php')) :
178     // Used to guarantee unique hash cookies
179     $cookiehash = md5(get_settings('siteurl')); // Remove in 1.4
180     define('COOKIEHASH', $cookiehash);
181 endif;
182
183 if ( !defined('USER_COOKIE') )
184     define('USER_COOKIE', 'wordpressuser_'. COOKIEHASH);
185 if ( !defined('PASS_COOKIE') )
186     define('PASS_COOKIE', 'wordpresspass_'. COOKIEHASH);
187 if ( !defined('COOKIEPATH') )
188     define('COOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_settings('home') . '/' ) );
189 if ( !defined('SITECOOKIEPATH') )
190     define('SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_settings('siteurl') . '/' ) );
191 if ( !defined('COOKIE_DOMAIN') )
192     define('COOKIE_DOMAIN', false);
193
194 require (ABSPATH . WPINC . '/vars.php');
195
196 // Check for hacks file if the option is enabled
197 if (get_settings('hack_file')) {
198     if (file_exists(ABSPATH . '/my-hacks.php'))
199         require(ABSPATH . '/my-hacks.php');
200 }
201
202 if ( get_settings('active_plugins') || get_settings('active_system_plugins')) {
203     $current_plugins = array_merge(get_settings('active_plugins'), get_settings('active_system_plugins'));
204     if ( is_array($current_plugins) ) {
205         foreach ($current_plugins as $plugin) {
206             if ('' != $plugin && file_exists(ABSPATH . 'wp-content/plugins/' . $plugin))
207                 include_once(ABSPATH . 'wp-content/plugins/' . $plugin);
208             else if ('' != $plugin && file_exists(ABSPATH . 'wp-content/systemplugins/' . $plugin))
209                 include_once(ABSPATH . 'wp-content/systemplugins/' . $plugin);
210         }
211     }
212 }
213
214 require (ABSPATH . WPINC . '/pluggable-functions.php');
215
216 if ( defined('WP_CACHE') && function_exists('wp_cache_postload') )
217     wp_cache_postload();
218
219 do_action('plugins_loaded');
220
221 // If already slashed, strip.
222 if ( get_magic_quotes_gpc() ) {
223     $_GET    = stripslashes_deep($_GET   );
224     $_POST   = stripslashes_deep($_POST  );
225     $_COOKIE = stripslashes_deep($_COOKIE);
226     $_SERVER = stripslashes_deep($_SERVER);
227 }
228
229 // Escape with wpdb.
230 $_GET    = add_magic_quotes($_GET   );
231 $_POST   = add_magic_quotes($_POST  );
232 $_COOKIE = add_magic_quotes($_COOKIE);
233 $_SERVER = add_magic_quotes($_SERVER);
234
235 $wp_query   = new WP_Query();
236 $wp_rewrite = new WP_Rewrite();
237 $wp         = new WP();
238
239 define('TEMPLATEPATH', get_template_directory());
240
241 // Load the default text localization domain.
242 load_default_textdomain();
243
244 // Pull in locale data after loading text domain.
245 require_once(ABSPATH . WPINC . '/locale.php');
246
247 // Load functions for active theme.
248 if ( file_exists(TEMPLATEPATH . "/functions.php") )
249     include(TEMPLATEPATH . "/functions.php");
250
251 function shutdown_action_hook() {
252     do_action('shutdown');
253     wp_cache_close();
254 }
255 register_shutdown_function('shutdown_action_hook');
256
257 session_start();
258
259 // Everything is loaded and initialized.
260 do_action('init');
261
262 ?>
Note: See TracBrowser for help on using the browser.
Log in with username/password: lyceum/lyceum