- $domain = rtrim( $domain, '.' );
- $cookie_domain = $domain;
- if ( substr( $cookie_domain, 0, 4 ) == 'www.' )
- $cookie_domain = substr( $cookie_domain, 4 );
-
- $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();
- if ( ! isset( $current_site->blog_id ) )
- $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() ) {
- $current_blog = wp_cache_get( 'current_blog_' . $domain, 'site-options' );
- if ( !$current_blog ) {
- $current_blog = get_blog_details( array( 'domain' => $domain ), false );
- if ( $current_blog )
- wp_cache_set( 'current_blog_' . $domain, $current_blog, 'site-options' );
- }
- 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 ) );
- if ( ! isset( $current_site->blog_id ) )
- $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 ) );
- } else
- $blogname = substr( $domain, 0, strpos( $domain, '.' ) );
- } else {
- $blogname = htmlspecialchars( substr( $_SERVER[ 'REQUEST_URI' ], strlen( $path ) ) );
- if ( false !== strpos( $blogname, '/' ) )
- $blogname = substr( $blogname, 0, strpos( $blogname, '/' ) );
- if ( false !== strpos( $blogname, '?' ) )
- $blogname = substr( $blogname, 0, strpos( $blogname, '?' ) );
- $reserved_blognames = array( 'page', 'comments', 'blog', 'wp-admin', 'wp-includes', 'wp-content', 'files', 'feed' );
- if ( $blogname != '' && ! in_array( $blogname, $reserved_blognames ) && ! is_file( $blogname ) )
- $path .= $blogname . '/';
- $current_blog = wp_cache_get( 'current_blog_' . $domain . $path, 'site-options' );
- if ( ! $current_blog ) {
- $current_blog = get_blog_details( array( 'domain' => $domain, 'path' => $path ), false );
- if ( $current_blog )
- wp_cache_set( 'current_blog_' . $domain . $path, $current_blog, 'site-options' );
- }
- unset($reserved_blognames);