web/wp-includes/ms-settings.php
changeset 194 32102edaa81b
child 204 09a1c134465b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
       
     1 <?php
       
     2 /**
       
     3  * Used to set up 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  * @since 3.0.0
       
    11  */
       
    12 
       
    13 /** Include Multisite initialization functions */
       
    14 require( ABSPATH . WPINC . '/ms-load.php' );
       
    15 require( ABSPATH . WPINC . '/ms-default-constants.php' );
       
    16 
       
    17 if ( defined( 'SUNRISE' ) )
       
    18 	include_once( WP_CONTENT_DIR . '/sunrise.php' );
       
    19 
       
    20 /** Check for and define SUBDOMAIN_INSTALL and the deprecated VHOST constant. */
       
    21 ms_subdomain_constants();
       
    22 
       
    23 if ( !isset( $current_site ) || !isset( $current_blog ) ) {
       
    24 
       
    25 	$domain = addslashes( $_SERVER['HTTP_HOST'] );
       
    26 	if ( false !== strpos( $domain, ':' ) ) {
       
    27 		if ( substr( $domain, -3 ) == ':80' ) {
       
    28 			$domain = substr( $domain, 0, -3 );
       
    29 			$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -3 );
       
    30 		} elseif ( substr( $domain, -4 ) == ':443' ) {
       
    31 			$domain = substr( $domain, 0, -4 );
       
    32 			$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -4 );
       
    33 		} else {
       
    34 			wp_load_translations_early();
       
    35 			wp_die( __( 'Multisite only works without the port number in the URL.' ) );
       
    36 		}
       
    37 	}
       
    38 
       
    39 	$domain = rtrim( $domain, '.' );
       
    40 	$cookie_domain = $domain;
       
    41 	if ( substr( $cookie_domain, 0, 4 ) == 'www.' )
       
    42 		$cookie_domain = substr( $cookie_domain, 4 );
       
    43 
       
    44 	$path = preg_replace( '|([a-z0-9-]+.php.*)|', '', $_SERVER['REQUEST_URI'] );
       
    45 	$path = str_replace ( '/wp-admin/', '/', $path );
       
    46 	$path = preg_replace( '|(/[a-z0-9-]+?/).*|', '$1', $path );
       
    47 
       
    48 	$current_site = wpmu_current_site();
       
    49 	if ( ! isset( $current_site->blog_id ) )
       
    50 		$current_site->blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s", $current_site->domain, $current_site->path ) );
       
    51 
       
    52 	if ( is_subdomain_install() ) {
       
    53 		$current_blog = wp_cache_get( 'current_blog_' . $domain, 'site-options' );
       
    54 		if ( !$current_blog ) {
       
    55 			$current_blog = get_blog_details( array( 'domain' => $domain ), false );
       
    56 			if ( $current_blog )
       
    57 				wp_cache_set( 'current_blog_' . $domain, $current_blog, 'site-options' );
       
    58 		}
       
    59 		if ( $current_blog && $current_blog->site_id != $current_site->id ) {
       
    60 			$current_site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->site WHERE id = %d", $current_blog->site_id ) );
       
    61 			if ( ! isset( $current_site->blog_id ) )
       
    62 				$current_site->blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s", $current_site->domain, $current_site->path ) );
       
    63 		} else
       
    64 			$blogname = substr( $domain, 0, strpos( $domain, '.' ) );
       
    65 	} else {
       
    66 		$blogname = htmlspecialchars( substr( $_SERVER[ 'REQUEST_URI' ], strlen( $path ) ) );
       
    67 		if ( false !== strpos( $blogname, '/' ) )
       
    68 			$blogname = substr( $blogname, 0, strpos( $blogname, '/' ) );
       
    69 		if ( false !== strpos( $blogname, '?' ) )
       
    70 			$blogname = substr( $blogname, 0, strpos( $blogname, '?' ) );
       
    71 		$reserved_blognames = array( 'page', 'comments', 'blog', 'wp-admin', 'wp-includes', 'wp-content', 'files', 'feed' );
       
    72 		if ( $blogname != '' && ! in_array( $blogname, $reserved_blognames ) && ! is_file( $blogname ) )
       
    73 			$path .= $blogname . '/';
       
    74 		$current_blog = wp_cache_get( 'current_blog_' . $domain . $path, 'site-options' );
       
    75 		if ( ! $current_blog ) {
       
    76 			$current_blog = get_blog_details( array( 'domain' => $domain, 'path' => $path ), false );
       
    77 			if ( $current_blog )
       
    78 				wp_cache_set( 'current_blog_' . $domain . $path, $current_blog, 'site-options' );
       
    79 		}
       
    80 		unset($reserved_blognames);
       
    81 	}
       
    82 
       
    83 	if ( ! defined( 'WP_INSTALLING' ) && is_subdomain_install() && ! is_object( $current_blog ) ) {
       
    84 		if ( defined( 'NOBLOGREDIRECT' ) ) {
       
    85 			$destination = NOBLOGREDIRECT;
       
    86 			if ( '%siteurl%' == $destination )
       
    87 				$destination = "http://" . $current_site->domain . $current_site->path;
       
    88 		} else {
       
    89 			$destination = 'http://' . $current_site->domain . $current_site->path . 'wp-signup.php?new=' . str_replace( '.' . $current_site->domain, '', $domain );
       
    90 		}
       
    91 		header( 'Location: ' . $destination );
       
    92 		die();
       
    93 	}
       
    94 
       
    95 	if ( ! defined( 'WP_INSTALLING' ) ) {
       
    96 		if ( $current_site && ! $current_blog ) {
       
    97 			if ( $current_site->domain != $_SERVER[ 'HTTP_HOST' ] ) {
       
    98 				header( 'Location: http://' . $current_site->domain . $current_site->path );
       
    99 				exit;
       
   100 			}
       
   101 			$current_blog = get_blog_details( array( 'domain' => $current_site->domain, 'path' => $current_site->path ), false );
       
   102 		}
       
   103 		if ( ! $current_blog || ! $current_site )
       
   104 			ms_not_installed();
       
   105 	}
       
   106 
       
   107 	$blog_id = $current_blog->blog_id;
       
   108 	$public  = $current_blog->public;
       
   109 
       
   110 	if ( empty( $current_blog->site_id ) )
       
   111 		$current_blog->site_id = 1;
       
   112 	$site_id = $current_blog->site_id;
       
   113 
       
   114 	$current_site = get_current_site_name( $current_site );
       
   115 
       
   116 	if ( ! $blog_id ) {
       
   117 		if ( defined( 'WP_INSTALLING' ) ) {
       
   118 			$current_blog->blog_id = $blog_id = 1;
       
   119 		} else {
       
   120 			wp_load_translations_early();
       
   121 			$msg = ! $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->site'" ) ? ' ' . __( 'Database tables are missing.' ) : '';
       
   122 			wp_die( __( 'No site by that name on this system.' ) . $msg );
       
   123 		}
       
   124 	}
       
   125 }
       
   126 $wpdb->set_prefix( $table_prefix, false ); // $table_prefix can be set in sunrise.php
       
   127 $wpdb->set_blog_id( $current_blog->blog_id, $current_blog->site_id );
       
   128 $table_prefix = $wpdb->get_blog_prefix();
       
   129 
       
   130 // need to init cache again after blog_id is set
       
   131 wp_start_object_cache();
       
   132 
       
   133 // Define upload directory constants
       
   134 ms_upload_constants();