]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/ms-settings.php
Wordpress 3.0.1-scripts
[autoinstalls/wordpress.git] / wp-includes / ms-settings.php
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         if ( ! defined( 'WP_INSTALLING' ) && is_subdomain_install() && ! is_object( $current_blog ) ) {
84                 if ( defined( 'NOBLOGREDIRECT' ) ) {
85                         $destination = NOBLOGREDIRECT;
86                         if ( '%siteurl%' == $destination )
87                                 $destination = "http://" . $current_site->domain . $current_site->path;
88                 } else {
89                         $destination = 'http://' . $current_site->domain . $current_site->path . 'wp-signup.php?new=' . str_replace( '.' . $current_site->domain, '', $domain );
90                 }
91                 header( 'Location: ' . $destination );
92                 die();
93         }
94
95         if ( ! defined( 'WP_INSTALLING' ) ) {
96                 if ( $current_site && ! $current_blog ) {
97                         if ( $current_site->domain != $_SERVER[ 'HTTP_HOST' ] ) {
98                                 header( 'Location: http://' . $current_site->domain . $current_site->path );
99                                 exit;
100                         }
101                         $current_blog = get_blog_details( array( 'domain' => $current_site->domain, 'path' => $current_site->path ), false );
102                 }
103                 if ( ! $current_blog || ! $current_site )
104                         ms_not_installed();
105         }
106
107         $blog_id = $current_blog->blog_id;
108         $public  = $current_blog->public;
109
110         if ( empty( $current_blog->site_id ) )
111                 $current_blog->site_id = 1;
112         $site_id = $current_blog->site_id;
113
114         $current_site = get_current_site_name( $current_site );
115
116         if ( ! $blog_id ) {
117                 if ( defined( 'WP_INSTALLING' ) ) {
118                         $current_blog->blog_id = $blog_id = 1;
119                 } else {
120                         $msg = ! $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->site'" ) ? ' ' . /*WP_I18N_TABLES_MISSING*/'Database tables are missing.'/*/WP_I18N_TABLES_MISSING*/ : '';
121                         wp_die( /*WP_I18N_NO_BLOG*/'No site by that name on this system.'/*/WP_I18N_NO_BLOG*/ . $msg );
122                 }
123         }
124 }
125 $wpdb->set_prefix( $table_prefix, false ); // $table_prefix can be set in sunrise.php
126 $wpdb->set_blog_id( $current_blog->blog_id, $current_blog->site_id );
127 $table_prefix = $wpdb->get_blog_prefix();
128
129 // need to init cache again after blog_id is set
130 wp_start_object_cache();
131
132 // Define upload directory constants
133 ms_upload_constants();