Make WordPress Core


Ignore:
Timestamp:
01/28/2010 04:09:52 PM (15 years ago)
Author:
wpmuguru
Message:

rearrage multisite initialization, remove deprecated $wpmuBaseTablePrefix, props nacin, see #11881

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/ms-load.php

    r12836 r12885  
    11<?php
    22/**
    3  * Used to setup and fix common variables and include
    4  * the WordPress procedural and class library.
    5  *
    6  * You should not have to change this file and allows
    7  * for some configuration in wp-config.php.
     3 * These functions are needed to load Multisite.
     4 *
     5 * @since 3.0.0
     6 *
     7 * @package WordPress
     8 * @subpackage Multisite
     9 */
     10
     11/**
     12 * Whether a subdomain configuration is enabled
    813 *
    914 * @since 3.0
    1015 *
    11  * @package WordPress
     16 * @return bool True if subdomain configuration is enabled, false otherwise.
    1217 */
    13 if ( defined( 'SUNRISE' ) )
    14     include_once( WP_CONTENT_DIR . '/sunrise.php' );
    15 
    16 require( ABSPATH . WPINC . '/ms-settings.php' );
    17 $wpdb->blogid = $current_blog->blog_id;
    18 $wpdb->siteid = $current_blog->site_id;
    19 $wpdb->set_prefix($table_prefix); // set up blog tables
    20 $table_prefix = $wpdb->get_blog_prefix();
    21 
    22 // Fix empty PHP_SELF
    23 $PHP_SELF = $_SERVER['PHP_SELF'];
    24 if ( empty($PHP_SELF) || ( empty($PHP_SELF) && !is_subdomain_install() && $current_blog->path != '/' ) )
    25     $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace("/(\?.*)?$/",'',$_SERVER["REQUEST_URI"]);
    26 
    27 wp_cache_init(); // need to init cache again after blog_id is set
    28 if ( function_exists('wp_cache_add_global_groups') ) { // need to add these again. Yes, it's an ugly hack
    29     wp_cache_add_global_groups(array ('users', 'userlogins', 'usermeta', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss'));
    30     wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
    31 }
    32 
    33 if ( !defined( 'UPLOADBLOGSDIR' ) )
    34     define( 'UPLOADBLOGSDIR', 'wp-content/blogs.dir' );
    35 
    36 if ( !defined( 'UPLOADS' ) )
    37     define( 'UPLOADS', UPLOADBLOGSDIR . "/{$wpdb->blogid}/files/" );
    38 
    39 if ( !defined( 'BLOGUPLOADDIR' ) )
    40     define( 'BLOGUPLOADDIR', WP_CONTENT_DIR . "/blogs.dir/{$wpdb->blogid}/files/" );
     18function is_subdomain_install() {
     19    if ( defined('VHOST') && VHOST == 'yes' )
     20        return true;
     21
     22    return false;
     23}
    4124
    4225function ms_network_settings() {
     
    11396}
    11497
    115 function ms_network_cookies() {
    116     global $current_site;
    117     /**
    118      * It is possible to define this in wp-config.php
    119      * @since 1.2.0
    120      */
    121     if ( !defined( 'COOKIEPATH' ) )
    122             define( 'COOKIEPATH', $current_site->path );
    123 
    124     /**
    125      * It is possible to define this in wp-config.php
    126      * @since 1.5.0
    127      */
    128     if ( !defined( 'SITECOOKIEPATH' ) )
    129             define( 'SITECOOKIEPATH', $current_site->path );
    130 
    131     /**
    132      * It is possible to define this in wp-config.php
    133      * @since 2.6.0
    134      */
    135     if ( !defined( 'ADMIN_COOKIE_PATH' ) ) {
    136             if( !is_subdomain_install() ) {
    137                     define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH );
     98function get_current_site_name( $current_site ) {
     99    global $wpdb;
     100    $current_site->site_name = wp_cache_get( $current_site->id . ':current_site_name', "site-options" );
     101    if ( !$current_site->site_name ) {
     102        $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 ) );
     103        if ( $current_site->site_name == null )
     104            $current_site->site_name = ucfirst( $current_site->domain );
     105        wp_cache_set( $current_site->id . ':current_site_name', $current_site->site_name, 'site-options');
     106    }
     107    return $current_site;
     108}
     109
     110function wpmu_current_site() {
     111    global $wpdb, $current_site, $domain, $path, $sites, $cookie_domain;
     112    if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) {
     113        $current_site->id = (defined( 'SITE_ID_CURRENT_SITE' ) ? constant('SITE_ID_CURRENT_SITE') : 1);
     114        $current_site->domain = DOMAIN_CURRENT_SITE;
     115        $current_site->path   = $path = PATH_CURRENT_SITE;
     116        if ( defined( 'BLOGID_CURRENT_SITE' ) )
     117            $current_site->blog_id = BLOGID_CURRENT_SITE;
     118        if ( DOMAIN_CURRENT_SITE == $domain )
     119            $current_site->cookie_domain = $cookie_domain;
     120        elseif ( substr( $current_site->domain, 0, 4 ) == 'www.' )
     121            $current_site->cookie_domain = substr( $current_site->domain, 4 );
     122        else
     123            $current_site->cookie_domain = $current_site->domain;
     124
     125        return $current_site;
     126    }
     127
     128    $current_site = wp_cache_get( "current_site", "site-options" );
     129    if ( $current_site )
     130        return $current_site;
     131
     132    $wpdb->suppress_errors();
     133    $sites = $wpdb->get_results( "SELECT * FROM $wpdb->site" ); // usually only one site
     134    if ( count( $sites ) == 1 ) {
     135        $current_site = $sites[0];
     136        $path = $current_site->path;
     137        $current_site->blog_id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} WHERE domain='{$current_site->domain}' AND path='{$current_site->path}'" );
     138        $current_site = get_current_site_name( $current_site );
     139        if ( substr( $current_site->domain, 0, 4 ) == 'www.' )
     140            $current_site->cookie_domain = substr( $current_site->domain, 4 );
     141        wp_cache_set( "current_site", $current_site, "site-options" );
     142        return $current_site;
     143    }
     144    $path = substr( $_SERVER[ 'REQUEST_URI' ], 0, 1 + strpos( $_SERVER[ 'REQUEST_URI' ], '/', 1 ) );
     145
     146    if ( $domain == $cookie_domain )
     147        $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path ) );
     148    else
     149        $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 ) );
     150    if ( $current_site == null ) {
     151        if ( $domain == $cookie_domain )
     152            $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain ) );
     153        else
     154            $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 ) );
     155    }
     156    if ( $current_site != null ) {
     157        $path = $current_site->path;
     158        $current_site->cookie_domain = $cookie_domain;
     159        return $current_site;
     160    } elseif ( is_subdomain_install() ) {
     161        $sitedomain = substr( $domain, 1 + strpos( $domain, '.' ) );
     162        $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path) );
     163        if ( $current_site != null ) {
     164            $current_site->cookie_domain = $current_site->domain;
     165            return $current_site;
     166        }
     167        $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $sitedomain) );
     168        if ( $current_site == null && defined( "WP_INSTALLING" ) == false ) {
     169            if ( count( $sites ) == 1 ) {
     170                $current_site = $sites[0];
     171                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>" );
    138172            } else {
    139                     define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . 'wp-admin' );
     173                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." );
    140174            }
    141     }
    142     /**
    143      * It is possible to define this in wp-config.php
    144      * @since 2.0.0
    145      */
    146     if ( !defined('COOKIE_DOMAIN') )
    147             define('COOKIE_DOMAIN', '.' . $current_site->cookie_domain);
    148 }
     175        } else {
     176            $path = '/';
     177        }
     178    } elseif ( defined( "WP_INSTALLING" ) == false ) {
     179        if ( count( $sites ) == 1 ) {
     180            $current_site = $sites[0];
     181            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>" );
     182        } else {
     183            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." );
     184        }
     185    } else {
     186        $path = '/';
     187    }
     188    return $current_site;
     189}
     190
     191function is_installed() {
     192    global $wpdb, $domain, $path;
     193    $base = stripslashes( $base );
     194    if ( defined( "WP_INSTALLING" ) == false ) {
     195        $check = $wpdb->get_results( "SELECT * FROM $wpdb->site" );
     196        $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 />";
     197        if ( $check == false ) {
     198            $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 />";
     199        } else {
     200            $msg .= '<strong>Could Not Find Blog!</strong><br />';
     201            $msg .= "Searched for <em>" . $domain . $path . "</em> in " . DB_NAME . "::" . $wpdb->blogs . " table. Is that right?<br />";
     202        }
     203        $msg .= "<br />\n<h1>What do I do now?</h1>";
     204        $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 />";
     205        $msg .= "If you're still stuck with this message, then check that your database contains the following tables:<ul>
     206            <li> $wpdb->blogs </li>
     207            <li> $wpdb->users </li>
     208            <li> $wpdb->usermeta </li>
     209            <li> $wpdb->site </li>
     210            <li> $wpdb->sitemeta </li>
     211            <li> $wpdb->sitecategories </li>
     212            </ul>";
     213        $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 />";
     214        if ( is_file( 'release-info.txt' ) ) {
     215            $msg .= 'Your bug report must include the following text: "';
     216            $info = file( 'release-info.txt' );
     217            $msg .= $info[ 4 ] . '"';
     218        }
     219
     220        die( "<h1>Fatal Error</h1> " . $msg );
     221    }
     222}
     223
    149224?>
Note: See TracChangeset for help on using the changeset viewer.