2010-01-06 02:50:12 -05:00
|
|
|
<?php
|
2010-01-08 16:25:01 -05:00
|
|
|
/**
|
2010-01-28 11:09:52 -05:00
|
|
|
* Used to setup and fix common variables and include
|
|
|
|
* the Multisite procedural and class library.
|
2010-01-08 16:25:01 -05:00
|
|
|
*
|
2010-01-28 11:09:52 -05:00
|
|
|
* Allows for some configuration in wp-config.php (see ms-default-constants.php)
|
2010-01-08 16:25:01 -05:00
|
|
|
*
|
2010-01-28 11:09:52 -05:00
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Multisite
|
2010-01-08 16:25:01 -05:00
|
|
|
*/
|
|
|
|
|
2010-01-28 11:09:52 -05:00
|
|
|
/** Include Multisite initialization functions */
|
|
|
|
require( ABSPATH . WPINC . '/ms-load.php' );
|
|
|
|
require( ABSPATH . WPINC . '/ms-default-constants.php' );
|
|
|
|
|
|
|
|
if ( defined( 'SUNRISE' ) )
|
|
|
|
include_once( WP_CONTENT_DIR . '/sunrise.php' );
|
2010-01-08 16:25:01 -05:00
|
|
|
|
2010-01-19 12:01:39 -05:00
|
|
|
if ( isset( $current_site ) && isset( $current_blog ) )
|
2010-01-06 02:50:12 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
$domain = addslashes( $_SERVER['HTTP_HOST'] );
|
2010-01-19 12:01:39 -05:00
|
|
|
if ( strpos( $domain, ':' ) ) {
|
|
|
|
if ( substr( $domain, -3 ) == ':80' ) {
|
2010-01-06 02:50:12 -05:00
|
|
|
$domain = substr( $domain, 0, -3 );
|
|
|
|
$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -3 );
|
2010-01-19 12:01:39 -05:00
|
|
|
} elseif ( substr( $domain, -4 ) == ':443' ) {
|
2010-01-06 02:50:12 -05:00
|
|
|
$domain = substr( $domain, 0, -4 );
|
|
|
|
$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -4 );
|
|
|
|
} else {
|
|
|
|
die( 'WPMU only works without the port number in the URL.' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$domain = preg_replace('/:.*$/', '', $domain); // Strip ports
|
2010-01-19 12:01:39 -05:00
|
|
|
if ( substr( $domain, -1 ) == '.' )
|
2010-01-06 02:50:12 -05:00
|
|
|
$domain = substr( $domain, 0, -1 );
|
|
|
|
|
2010-01-21 12:20:23 -05:00
|
|
|
if ( substr( $domain, 0, 4 ) == 'www.' )
|
|
|
|
$cookie_domain = substr( $domain, 4 );
|
|
|
|
else
|
|
|
|
$cookie_domain = $domain;
|
|
|
|
|
2010-01-06 02:50:12 -05:00
|
|
|
$path = preg_replace( '|([a-z0-9-]+.php.*)|', '', $_SERVER['REQUEST_URI'] );
|
|
|
|
$path = str_replace ( '/wp-admin/', '/', $path );
|
|
|
|
$path = preg_replace( '|(/[a-z0-9-]+?/).*|', '$1', $path );
|
|
|
|
|
|
|
|
$current_site = wpmu_current_site();
|
2010-01-19 12:01:39 -05:00
|
|
|
if ( !isset( $current_site->blog_id ) )
|
2010-01-06 02:50:12 -05:00
|
|
|
$current_site->blog_id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} WHERE domain='{$current_site->domain}' AND path='{$current_site->path}'" );
|
|
|
|
|
2010-01-19 12:01:39 -05:00
|
|
|
if ( is_subdomain_install() ) {
|
2010-01-06 02:50:12 -05:00
|
|
|
$current_blog = wp_cache_get( 'current_blog_' . $domain, 'site-options' );
|
2010-01-19 12:01:39 -05:00
|
|
|
if ( !$current_blog ) {
|
2010-01-06 02:50:12 -05:00
|
|
|
$current_blog = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE domain = %s", $domain) );
|
2010-01-19 12:01:39 -05:00
|
|
|
if ( $current_blog )
|
2010-01-06 02:50:12 -05:00
|
|
|
wp_cache_set( 'current_blog_' . $domain, $current_blog, 'site-options' );
|
|
|
|
}
|
2010-01-19 12:01:39 -05:00
|
|
|
if ( $current_blog != null && $current_blog->site_id != $current_site->id )
|
2010-01-06 02:50:12 -05:00
|
|
|
$current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE id = %d", $current_blog->site_id) );
|
2010-01-19 12:01:39 -05:00
|
|
|
else
|
2010-01-06 02:50:12 -05:00
|
|
|
$blogname = substr( $domain, 0, strpos( $domain, '.' ) );
|
|
|
|
} else {
|
|
|
|
$blogname = htmlspecialchars( substr( $_SERVER[ 'REQUEST_URI' ], strlen( $path ) ) );
|
2010-01-19 12:01:39 -05:00
|
|
|
if ( strpos( $blogname, '/' ) )
|
2010-01-06 02:50:12 -05:00
|
|
|
$blogname = substr( $blogname, 0, strpos( $blogname, '/' ) );
|
2010-01-19 12:01:39 -05:00
|
|
|
if ( strpos( " ".$blogname, '?' ) )
|
2010-01-06 02:50:12 -05:00
|
|
|
$blogname = substr( $blogname, 0, strpos( $blogname, '?' ) );
|
|
|
|
$reserved_blognames = array( 'page', 'comments', 'blog', 'wp-admin', 'wp-includes', 'wp-content', 'files', 'feed' );
|
2010-01-19 12:01:39 -05:00
|
|
|
if ( $blogname != '' && !in_array( $blogname, $reserved_blognames ) && !is_file( $blogname ) )
|
2010-01-06 02:50:12 -05:00
|
|
|
$path = $path . $blogname . '/';
|
|
|
|
$current_blog = wp_cache_get( 'current_blog_' . $domain . $path, 'site-options' );
|
2010-01-19 12:01:39 -05:00
|
|
|
if ( !$current_blog ) {
|
2010-01-06 02:50:12 -05:00
|
|
|
$current_blog = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $domain, $path) );
|
2010-01-19 12:01:39 -05:00
|
|
|
if ( $current_blog )
|
2010-01-06 02:50:12 -05:00
|
|
|
wp_cache_set( 'current_blog_' . $domain . $path, $current_blog, 'site-options' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-28 11:09:52 -05:00
|
|
|
if ( ! defined( 'WP_INSTALLING' ) && is_subdomain_install() && !is_object( $current_blog ) ) {
|
|
|
|
|
2010-01-19 12:01:39 -05:00
|
|
|
if ( defined( 'NOBLOGREDIRECT' ) ) {
|
2010-01-06 02:50:12 -05:00
|
|
|
$destination = constant( 'NOBLOGREDIRECT' );
|
|
|
|
if ( $destination == '%siteurl%' )
|
|
|
|
$destination = "http://" . $current_site->domain . $current_site->path;
|
|
|
|
header( "Location: " . $destination);
|
|
|
|
die();
|
|
|
|
} else {
|
|
|
|
header( "Location: http://" . $current_site->domain . $current_site->path . "wp-signup.php?new=" . str_replace( '.' . $current_site->domain, '', $domain ) );
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-01-28 11:09:52 -05:00
|
|
|
if ( ! defined( 'WP_INSTALLING' ) ) {
|
2010-01-19 12:01:39 -05:00
|
|
|
if ( $current_site && $current_blog == null ) {
|
|
|
|
if ( $current_site->domain != $_SERVER[ 'HTTP_HOST' ] ) {
|
2010-01-06 02:50:12 -05:00
|
|
|
header( "Location: http://" . $current_site->domain . $current_site->path );
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
$current_blog = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $current_site->domain, $current_site->path) );
|
|
|
|
}
|
2010-01-19 12:01:39 -05:00
|
|
|
if ( $current_blog == false || $current_site == false )
|
2010-01-06 02:50:12 -05:00
|
|
|
is_installed();
|
|
|
|
}
|
|
|
|
|
|
|
|
$blog_id = $current_blog->blog_id;
|
|
|
|
$public = $current_blog->public;
|
|
|
|
|
2010-01-19 12:01:39 -05:00
|
|
|
if ( $current_blog->site_id == 0 || $current_blog->site_id == '' )
|
2010-01-06 02:50:12 -05:00
|
|
|
$current_blog->site_id = 1;
|
|
|
|
$site_id = $current_blog->site_id;
|
|
|
|
|
|
|
|
$current_site = get_current_site_name( $current_site );
|
|
|
|
|
2010-01-19 12:01:39 -05:00
|
|
|
if ( $blog_id == false ) {
|
2010-01-06 02:50:12 -05:00
|
|
|
// no blog found, are we installing? Check if the table exists.
|
|
|
|
if ( defined('WP_INSTALLING') ) {
|
2010-01-19 12:01:39 -05:00
|
|
|
$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;
|
2010-01-06 02:50:12 -05:00
|
|
|
} else {
|
2010-01-19 12:01:39 -05:00
|
|
|
$check = $wpdb->get_results( "SELECT * FROM $wpdb->site" );
|
|
|
|
if ( $check == false )
|
|
|
|
$msg = ': DB Tables Missing';
|
|
|
|
else
|
|
|
|
$msg = '';
|
|
|
|
die( "No Blog by that name on this system." . $msg );
|
2010-01-06 02:50:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$wpdb->suppress_errors( false );
|
|
|
|
|
2010-01-19 12:01:39 -05:00
|
|
|
if ( '0' == $current_blog->public ) {
|
2010-01-06 02:50:12 -05:00
|
|
|
// This just means the blog shouldn't show up in google, etc. Only to registered members
|
|
|
|
}
|
|
|
|
|
2010-01-28 11:09:52 -05:00
|
|
|
$wpdb->blogid = $current_blog->blog_id;
|
|
|
|
$wpdb->siteid = $current_blog->site_id;
|
|
|
|
$wpdb->set_prefix($table_prefix); // set up blog tables
|
|
|
|
$table_prefix = $wpdb->get_blog_prefix();
|
2010-01-06 02:50:12 -05:00
|
|
|
|
2010-01-28 11:09:52 -05:00
|
|
|
// 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"]);
|
|
|
|
|
2010-01-28 12:28:44 -05:00
|
|
|
// need to init cache again after blog_id is set
|
|
|
|
wp_start_object_cache();
|
2010-01-06 02:50:12 -05:00
|
|
|
|
2010-01-28 11:09:52 -05:00
|
|
|
ms_default_constants( 'uploads' );
|
|
|
|
|
2010-01-06 02:50:12 -05:00
|
|
|
?>
|