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