Changeset 12885 for trunk/wp-includes/ms-settings.php
- Timestamp:
- 01/28/2010 04:09:52 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/ms-settings.php
r12858 r12885 1 1 <?php 2 /** 3 * Used to setup and fix common variables and include 4 * the Multisite procedural and class library. 5 * 6 * Allows for some configuration in wp-config.php (see ms-default-constants.php) 7 * 8 * @package WordPress 9 * @subpackage Multisite 10 */ 2 11 3 /** 4 * Whether a subdomain configuration is enabled 5 * 6 * @since 3.0 7 * 8 * @return bool True if subdomain configuration is enabled, false otherwise. 9 */ 10 function is_subdomain_install() { 11 if ( defined('VHOST') && VHOST == 'yes' ) 12 return true; 12 /** Include Multisite initialization functions */ 13 require( ABSPATH . WPINC . '/ms-load.php' ); 14 require( ABSPATH . WPINC . '/ms-default-constants.php' ); 13 15 14 return false; 15 } 16 if ( defined( 'SUNRISE' ) ) 17 include_once( WP_CONTENT_DIR . '/sunrise.php' ); 16 18 17 19 if ( isset( $current_site ) && isset( $current_blog ) ) 18 20 return; 19 20 // deprecated21 $wpmuBaseTablePrefix = $table_prefix;22 21 23 22 $domain = addslashes( $_SERVER['HTTP_HOST'] ); … … 45 44 $path = str_replace ( '/wp-admin/', '/', $path ); 46 45 $path = preg_replace( '|(/[a-z0-9-]+?/).*|', '$1', $path ); 47 48 function get_current_site_name( $current_site ) {49 global $wpdb;50 $current_site->site_name = wp_cache_get( $current_site->id . ':current_site_name', "site-options" );51 if ( !$current_site->site_name ) {52 $current_site->site_name = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = %d AND meta_key = 'site_name'", $current_site->id ) );53 if ( $current_site->site_name == null )54 $current_site->site_name = ucfirst( $current_site->domain );55 wp_cache_set( $current_site->id . ':current_site_name', $current_site->site_name, 'site-options');56 }57 return $current_site;58 }59 60 function wpmu_current_site() {61 global $wpdb, $current_site, $domain, $path, $sites, $cookie_domain;62 if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) {63 $current_site->id = (defined( 'SITE_ID_CURRENT_SITE' ) ? constant('SITE_ID_CURRENT_SITE') : 1);64 $current_site->domain = DOMAIN_CURRENT_SITE;65 $current_site->path = $path = PATH_CURRENT_SITE;66 if ( defined( 'BLOGID_CURRENT_SITE' ) )67 $current_site->blog_id = BLOGID_CURRENT_SITE;68 if ( DOMAIN_CURRENT_SITE == $domain )69 $current_site->cookie_domain = $cookie_domain;70 elseif ( substr( $current_site->domain, 0, 4 ) == 'www.' )71 $current_site->cookie_domain = substr( $current_site->domain, 4 );72 else73 $current_site->cookie_domain = $current_site->domain;74 75 return $current_site;76 }77 78 $current_site = wp_cache_get( "current_site", "site-options" );79 if ( $current_site )80 return $current_site;81 82 $wpdb->suppress_errors();83 $sites = $wpdb->get_results( "SELECT * FROM $wpdb->site" ); // usually only one site84 if ( count( $sites ) == 1 ) {85 $current_site = $sites[0];86 $path = $current_site->path;87 $current_site->blog_id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} WHERE domain='{$current_site->domain}' AND path='{$current_site->path}'" );88 $current_site = get_current_site_name( $current_site );89 if ( substr( $current_site->domain, 0, 4 ) == 'www.' )90 $current_site->cookie_domain = substr( $current_site->domain, 4 );91 wp_cache_set( "current_site", $current_site, "site-options" );92 return $current_site;93 }94 $path = substr( $_SERVER[ 'REQUEST_URI' ], 0, 1 + strpos( $_SERVER[ 'REQUEST_URI' ], '/', 1 ) );95 96 if ( $domain == $cookie_domain )97 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path ) );98 else99 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain IN ( %s, %s ) AND path = %s ORDER BY CHAR_LENGTH( domain ) DESC LIMIT 1", $domain, $cookie_domain, $path ) );100 if ( $current_site == null ) {101 if ( $domain == $cookie_domain )102 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain ) );103 else104 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain IN ( %s, %s ) AND path = '/' ORDER BY CHAR_LENGTH( domain ) DESC LIMIT 1", $domain, $cookie_domain, $path ) );105 }106 if ( $current_site != null ) {107 $path = $current_site->path;108 $current_site->cookie_domain = $cookie_domain;109 return $current_site;110 } elseif ( is_subdomain_install() ) {111 $sitedomain = substr( $domain, 1 + strpos( $domain, '.' ) );112 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path) );113 if ( $current_site != null ) {114 $current_site->cookie_domain = $current_site->domain;115 return $current_site;116 }117 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $sitedomain) );118 if ( $current_site == null && defined( "WP_INSTALLING" ) == false ) {119 if ( count( $sites ) == 1 ) {120 $current_site = $sites[0];121 die( "That blog does not exist. Please try <a href='http://{$current_site->domain}{$current_site->path}'>http://{$current_site->domain}{$current_site->path}</a>" );122 } else {123 die( "No WPMU site defined on this host. If you are the owner of this site, please check <a href='http://codex.wordpress.org/Debugging_WPMU'>Debugging WPMU</a> for further assistance." );124 }125 } else {126 $path = '/';127 }128 } elseif ( defined( "WP_INSTALLING" ) == false ) {129 if ( count( $sites ) == 1 ) {130 $current_site = $sites[0];131 die( "That blog does not exist. Please try <a href='http://{$current_site->domain}{$current_site->path}'>http://{$current_site->domain}{$current_site->path}</a>" );132 } else {133 die( "No WPMU site defined on this host. If you are the owner of this site, please check <a href='http://codex.wordpress.org/Debugging_WPMU'>Debugging WPMU</a> for further assistance." );134 }135 } else {136 $path = '/';137 }138 return $current_site;139 }140 46 141 47 $current_site = wpmu_current_site(); … … 171 77 } 172 78 173 if ( defined( "WP_INSTALLING" ) == false && is_subdomain_install() && !is_object( $current_blog ) ) { 79 if ( ! defined( 'WP_INSTALLING' ) && is_subdomain_install() && !is_object( $current_blog ) ) { 80 174 81 if ( defined( 'NOBLOGREDIRECT' ) ) { 175 82 $destination = constant( 'NOBLOGREDIRECT' ); … … 185 92 } 186 93 187 if ( defined( "WP_INSTALLING" ) == false) {94 if ( ! defined( 'WP_INSTALLING' ) ) { 188 95 if ( $current_site && $current_blog == null ) { 189 96 if ( $current_site->domain != $_SERVER[ 'HTTP_HOST' ] ) { … … 236 143 } 237 144 238 function is_installed() { 239 global $wpdb, $domain, $path; 240 $base = stripslashes( $base ); 241 if ( defined( "WP_INSTALLING" ) == false ) { 242 $check = $wpdb->get_results( "SELECT * FROM $wpdb->site" ); 243 $msg = "If your blog does not display, please contact the owner of this site.<br /><br />If you are the owner of this site please check that MySQL is running properly and all tables are error free.<br /><br />"; 244 if ( $check == false ) { 245 $msg .= "<strong>Database Tables Missing.</strong><br />Database tables are missing. This means that MySQL is either not running, WPMU was not installed properly, or someone deleted {$wpdb->site}. You really <em>should</em> look at your database now.<br />"; 246 } else { 247 $msg .= '<strong>Could Not Find Blog!</strong><br />'; 248 $msg .= "Searched for <em>" . $domain . $path . "</em> in " . DB_NAME . "::" . $wpdb->blogs . " table. Is that right?<br />"; 249 } 250 $msg .= "<br />\n<h1>What do I do now?</h1>"; 251 $msg .= "Read the <a target='_blank' href='http://codex.wordpress.org/Debugging_WPMU'>bug report</a> page. Some of the guidelines there may help you figure out what went wrong.<br />"; 252 $msg .= "If you're still stuck with this message, then check that your database contains the following tables:<ul> 253 <li> $wpdb->blogs </li> 254 <li> $wpdb->users </li> 255 <li> $wpdb->usermeta </li> 256 <li> $wpdb->site </li> 257 <li> $wpdb->sitemeta </li> 258 <li> $wpdb->sitecategories </li> 259 </ul>"; 260 $msg .= "If you suspect a problem please report it to the support forums but you must include the information asked for in the <a href='http://codex.wordpress.org/Debugging_WPMU'>WPMU bug reporting guidelines</a>!<br /><br />"; 261 if ( is_file( 'release-info.txt' ) ) { 262 $msg .= 'Your bug report must include the following text: "'; 263 $info = file( 'release-info.txt' ); 264 $msg .= $info[ 4 ] . '"'; 265 } 145 $wpdb->blogid = $current_blog->blog_id; 146 $wpdb->siteid = $current_blog->site_id; 147 $wpdb->set_prefix($table_prefix); // set up blog tables 148 $table_prefix = $wpdb->get_blog_prefix(); 266 149 267 die( "<h1>Fatal Error</h1> " . $msg ); 268 } 150 // Fix empty PHP_SELF 151 $PHP_SELF = $_SERVER['PHP_SELF']; 152 if ( empty($PHP_SELF) || ( empty($PHP_SELF) && !is_subdomain_install() && $current_blog->path != '/' ) ) 153 $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace("/(\?.*)?$/",'',$_SERVER["REQUEST_URI"]); 154 155 wp_cache_init(); // need to init cache again after blog_id is set 156 if ( function_exists('wp_cache_add_global_groups') ) { // need to add these again. Yes, it's an ugly hack 157 wp_cache_add_global_groups(array ('users', 'userlogins', 'usermeta', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss')); 158 wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' )); 269 159 } 270 160 161 ms_default_constants( 'uploads' ); 162 271 163 ?>
Note: See TracChangeset
for help on using the changeset viewer.