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