ms-settings cleanup. Props nacin. see #11644
git-svn-id: https://develop.svn.wordpress.org/trunk@12896 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
ea82d93624
commit
bdbf075914
@ -20,7 +20,7 @@ if ( isset( $current_site ) && isset( $current_blog ) )
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
$domain = addslashes( $_SERVER['HTTP_HOST'] );
|
$domain = addslashes( $_SERVER['HTTP_HOST'] );
|
||||||
if ( strpos( $domain, ':' ) ) {
|
if ( false !== strpos( $domain, ':' ) ) {
|
||||||
if ( substr( $domain, -3 ) == ':80' ) {
|
if ( substr( $domain, -3 ) == ':80' ) {
|
||||||
$domain = substr( $domain, 0, -3 );
|
$domain = substr( $domain, 0, -3 );
|
||||||
$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -3 );
|
$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -3 );
|
||||||
@ -28,133 +28,104 @@ if ( strpos( $domain, ':' ) ) {
|
|||||||
$domain = substr( $domain, 0, -4 );
|
$domain = substr( $domain, 0, -4 );
|
||||||
$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -4 );
|
$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -4 );
|
||||||
} else {
|
} else {
|
||||||
die( 'WPMU only works without the port number in the URL.' );
|
wp_die( 'Multisite only works without the port number in the URL.' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$domain = preg_replace('/:.*$/', '', $domain); // Strip ports
|
|
||||||
if ( substr( $domain, -1 ) == '.' )
|
|
||||||
$domain = substr( $domain, 0, -1 );
|
|
||||||
|
|
||||||
if ( substr( $domain, 0, 4 ) == 'www.' )
|
$domain = rtrim( $domain, '.' );
|
||||||
$cookie_domain = substr( $domain, 4 );
|
$cookie_domain = $domain;
|
||||||
else
|
if ( substr( $cookie_domain, 0, 4 ) == 'www.' )
|
||||||
$cookie_domain = $domain;
|
$cookie_domain = substr( $cookie_domain, 4 );
|
||||||
|
|
||||||
$path = preg_replace( '|([a-z0-9-]+.php.*)|', '', $_SERVER['REQUEST_URI'] );
|
$path = preg_replace( '|([a-z0-9-]+.php.*)|', '', $_SERVER['REQUEST_URI'] );
|
||||||
$path = str_replace ( '/wp-admin/', '/', $path );
|
$path = str_replace ( '/wp-admin/', '/', $path );
|
||||||
$path = preg_replace( '|(/[a-z0-9-]+?/).*|', '$1', $path );
|
$path = preg_replace( '|(/[a-z0-9-]+?/).*|', '$1', $path );
|
||||||
|
|
||||||
$current_site = wpmu_current_site();
|
$current_site = wpmu_current_site();
|
||||||
if ( !isset( $current_site->blog_id ) )
|
if ( ! isset( $current_site->blog_id ) )
|
||||||
$current_site->blog_id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} WHERE domain='{$current_site->domain}' AND path='{$current_site->path}'" );
|
$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 ) );
|
||||||
|
|
||||||
if ( is_subdomain_install() ) {
|
if ( is_subdomain_install() ) {
|
||||||
$current_blog = wp_cache_get( 'current_blog_' . $domain, 'site-options' );
|
$current_blog = wp_cache_get( 'current_blog_' . $domain, 'site-options' );
|
||||||
if ( !$current_blog ) {
|
if ( !$current_blog ) {
|
||||||
$current_blog = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE domain = %s", $domain) );
|
$current_blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $domain ) );
|
||||||
if ( $current_blog )
|
if ( $current_blog )
|
||||||
wp_cache_set( 'current_blog_' . $domain, $current_blog, 'site-options' );
|
wp_cache_set( 'current_blog_' . $domain, $current_blog, 'site-options' );
|
||||||
}
|
}
|
||||||
if ( $current_blog != null && $current_blog->site_id != $current_site->id )
|
if ( $current_blog && $current_blog->site_id != $current_site->id )
|
||||||
$current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE id = %d", $current_blog->site_id) );
|
$current_site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->site WHERE id = %d", $current_blog->site_id ) );
|
||||||
else
|
else
|
||||||
$blogname = substr( $domain, 0, strpos( $domain, '.' ) );
|
$blogname = substr( $domain, 0, strpos( $domain, '.' ) );
|
||||||
} else {
|
} else {
|
||||||
$blogname = htmlspecialchars( substr( $_SERVER[ 'REQUEST_URI' ], strlen( $path ) ) );
|
$blogname = htmlspecialchars( substr( $_SERVER[ 'REQUEST_URI' ], strlen( $path ) ) );
|
||||||
if ( strpos( $blogname, '/' ) )
|
if ( false !== strpos( $blogname, '/' ) )
|
||||||
$blogname = substr( $blogname, 0, strpos( $blogname, '/' ) );
|
$blogname = substr( $blogname, 0, strpos( $blogname, '/' ) );
|
||||||
if ( strpos( " ".$blogname, '?' ) )
|
if ( false !== strpos( $blogname, '?' ) )
|
||||||
$blogname = substr( $blogname, 0, strpos( $blogname, '?' ) );
|
$blogname = substr( $blogname, 0, strpos( $blogname, '?' ) );
|
||||||
$reserved_blognames = array( 'page', 'comments', 'blog', 'wp-admin', 'wp-includes', 'wp-content', 'files', 'feed' );
|
$reserved_blognames = array( 'page', 'comments', 'blog', 'wp-admin', 'wp-includes', 'wp-content', 'files', 'feed' );
|
||||||
if ( $blogname != '' && !in_array( $blogname, $reserved_blognames ) && !is_file( $blogname ) )
|
if ( $blogname != '' && ! in_array( $blogname, $reserved_blognames ) && ! is_file( $blogname ) )
|
||||||
$path = $path . $blogname . '/';
|
$path = $path . $blogname . '/';
|
||||||
$current_blog = wp_cache_get( 'current_blog_' . $domain . $path, 'site-options' );
|
$current_blog = wp_cache_get( 'current_blog_' . $domain . $path, 'site-options' );
|
||||||
if ( !$current_blog ) {
|
if ( ! $current_blog ) {
|
||||||
$current_blog = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $domain, $path) );
|
$current_blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $domain, $path ) );
|
||||||
if ( $current_blog )
|
if ( $current_blog )
|
||||||
wp_cache_set( 'current_blog_' . $domain . $path, $current_blog, 'site-options' );
|
wp_cache_set( 'current_blog_' . $domain . $path, $current_blog, 'site-options' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! defined( 'WP_INSTALLING' ) && is_subdomain_install() && !is_object( $current_blog ) ) {
|
if ( ! defined( 'WP_INSTALLING' ) && is_subdomain_install() && ! is_object( $current_blog ) ) {
|
||||||
|
|
||||||
if ( defined( 'NOBLOGREDIRECT' ) ) {
|
if ( defined( 'NOBLOGREDIRECT' ) ) {
|
||||||
$destination = constant( 'NOBLOGREDIRECT' );
|
$destination = NOBLOGREDIRECT;
|
||||||
if ( $destination == '%siteurl%' )
|
if ( '%siteurl%' == $destination )
|
||||||
$destination = "http://" . $current_site->domain . $current_site->path;
|
$destination = "http://" . $current_site->domain . $current_site->path;
|
||||||
header( "Location: " . $destination);
|
|
||||||
die();
|
|
||||||
} else {
|
} else {
|
||||||
header( "Location: http://" . $current_site->domain . $current_site->path . "wp-signup.php?new=" . str_replace( '.' . $current_site->domain, '', $domain ) );
|
$destination = 'http://' . $current_site->domain . $current_site->path . 'wp-signup.php?new=' . str_replace( '.' . $current_site->domain, '', $domain );
|
||||||
die();
|
|
||||||
}
|
}
|
||||||
|
wp_redirect( $destination );
|
||||||
|
die();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! defined( 'WP_INSTALLING' ) ) {
|
if ( ! defined( 'WP_INSTALLING' ) ) {
|
||||||
if ( $current_site && $current_blog == null ) {
|
if ( $current_site && ! $current_blog ) {
|
||||||
if ( $current_site->domain != $_SERVER[ 'HTTP_HOST' ] ) {
|
if ( $current_site->domain != $_SERVER[ 'HTTP_HOST' ] ) {
|
||||||
header( "Location: http://" . $current_site->domain . $current_site->path );
|
wp_redirect( 'http://' . $current_site->domain . $current_site->path );
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
$current_blog = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $current_site->domain, $current_site->path) );
|
$current_blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $current_site->domain, $current_site->path ) );
|
||||||
}
|
}
|
||||||
if ( $current_blog == false || $current_site == false )
|
if ( ! $current_blog || ! $current_site )
|
||||||
is_installed();
|
is_installed();
|
||||||
}
|
}
|
||||||
|
|
||||||
$blog_id = $current_blog->blog_id;
|
$blog_id = $current_blog->blog_id;
|
||||||
$public = $current_blog->public;
|
$public = $current_blog->public;
|
||||||
|
|
||||||
if ( $current_blog->site_id == 0 || $current_blog->site_id == '' )
|
if ( empty( $current_blog->site_id ) )
|
||||||
$current_blog->site_id = 1;
|
$current_blog->site_id = 1;
|
||||||
$site_id = $current_blog->site_id;
|
$site_id = $current_blog->site_id;
|
||||||
|
|
||||||
$current_site = get_current_site_name( $current_site );
|
$current_site = get_current_site_name( $current_site );
|
||||||
|
|
||||||
if ( $blog_id == false ) {
|
if ( ! $blog_id ) {
|
||||||
// no blog found, are we installing? Check if the table exists.
|
if ( defined('WP_INSTALLING') ) {
|
||||||
if ( defined('WP_INSTALLING') ) {
|
$current_blog->blog_id = $blog_id = 1;
|
||||||
$blog_id = $wpdb->get_var( "SELECT blog_id FROM $wpdb->blogs LIMIT 0,1" );
|
|
||||||
if ( $blog_id == false ) {
|
|
||||||
// table doesn't exist. This is the first blog
|
|
||||||
$blog_id = 1;
|
|
||||||
} else {
|
|
||||||
// table exists
|
|
||||||
// don't create record at this stage. we're obviously installing so it doesn't matter what the table vars below are like.
|
|
||||||
// default to using the "main" blog.
|
|
||||||
$blog_id = 1;
|
|
||||||
}
|
|
||||||
$current_blog->blog_id = $blog_id;
|
|
||||||
} else {
|
} else {
|
||||||
$check = $wpdb->get_results( "SELECT * FROM $wpdb->site" );
|
$msg = ! $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->site'" ) ? __( 'Database tables are missing.' ) : '';
|
||||||
if ( $check == false )
|
wp_die( __( 'No blog by that name on this system.' ) . $msg );
|
||||||
$msg = ': DB Tables Missing';
|
|
||||||
else
|
|
||||||
$msg = '';
|
|
||||||
die( "No Blog by that name on this system." . $msg );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$wpdb->suppress_errors( false );
|
$wpdb->suppress_errors( false );
|
||||||
|
|
||||||
if ( '0' == $current_blog->public ) {
|
|
||||||
// This just means the blog shouldn't show up in google, etc. Only to registered members
|
|
||||||
}
|
|
||||||
|
|
||||||
$wpdb->blogid = $current_blog->blog_id;
|
$wpdb->blogid = $current_blog->blog_id;
|
||||||
$wpdb->siteid = $current_blog->site_id;
|
$wpdb->siteid = $current_blog->site_id;
|
||||||
$wpdb->set_prefix($table_prefix); // set up blog tables
|
$wpdb->set_prefix( $table_prefix ); // set up blog tables
|
||||||
$table_prefix = $wpdb->get_blog_prefix();
|
$table_prefix = $wpdb->get_blog_prefix();
|
||||||
|
|
||||||
// Fix empty PHP_SELF
|
|
||||||
$PHP_SELF = $_SERVER['PHP_SELF'];
|
|
||||||
if ( empty($PHP_SELF) || ( empty($PHP_SELF) && !is_subdomain_install() && $current_blog->path != '/' ) )
|
|
||||||
$_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace("/(\?.*)?$/",'',$_SERVER["REQUEST_URI"]);
|
|
||||||
|
|
||||||
// need to init cache again after blog_id is set
|
// need to init cache again after blog_id is set
|
||||||
wp_start_object_cache();
|
wp_start_object_cache();
|
||||||
|
|
||||||
|
// Define upload directory constants
|
||||||
ms_default_constants( 'uploads' );
|
ms_default_constants( 'uploads' );
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
Loading…
Reference in New Issue
Block a user