Changeset 12760 for trunk/wp-includes/ms-settings.php
- Timestamp:
- 01/19/2010 05:01:39 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/ms-settings.php
r12674 r12760 15 15 } 16 16 17 if ( isset( $current_site ) && isset( $current_blog ) )17 if ( isset( $current_site ) && isset( $current_blog ) ) 18 18 return; 19 19 … … 22 22 23 23 $domain = addslashes( $_SERVER['HTTP_HOST'] ); 24 if ( substr( $domain, 0, 4 ) == 'www.' )24 if ( substr( $domain, 0, 4 ) == 'www.' ) 25 25 $domain = substr( $domain, 4 ); 26 if ( strpos( $domain, ':' ) ) {27 if ( substr( $domain, -3 ) == ':80' ) {26 if ( strpos( $domain, ':' ) ) { 27 if ( substr( $domain, -3 ) == ':80' ) { 28 28 $domain = substr( $domain, 0, -3 ); 29 29 $_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -3 ); 30 } elseif ( substr( $domain, -4 ) == ':443' ) {30 } elseif ( substr( $domain, -4 ) == ':443' ) { 31 31 $domain = substr( $domain, 0, -4 ); 32 32 $_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -4 ); … … 36 36 } 37 37 $domain = preg_replace('/:.*$/', '', $domain); // Strip ports 38 if ( substr( $domain, -1 ) == '.' )38 if ( substr( $domain, -1 ) == '.' ) 39 39 $domain = substr( $domain, 0, -1 ); 40 40 … … 48 48 if ( !$current_site->site_name ) { 49 49 $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 ) ); 50 if ( $current_site->site_name == null )50 if ( $current_site->site_name == null ) 51 51 $current_site->site_name = ucfirst( $current_site->domain ); 52 52 wp_cache_set( $current_site->id . ':current_site_name', $current_site->site_name, 'site-options'); … … 57 57 function wpmu_current_site() { 58 58 global $wpdb, $current_site, $domain, $path, $sites; 59 if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) {59 if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) { 60 60 $current_site->id = (defined( 'SITE_ID_CURRENT_SITE' ) ? constant('SITE_ID_CURRENT_SITE') : 1); 61 61 $current_site->domain = DOMAIN_CURRENT_SITE; 62 62 $current_site->path = $path = PATH_CURRENT_SITE; 63 if ( defined( 'BLOGID_CURRENT_SITE' ) )63 if ( defined( 'BLOGID_CURRENT_SITE' ) ) 64 64 $current_site->blog_id = BLOGID_CURRENT_SITE; 65 65 return $current_site; … … 67 67 68 68 $current_site = wp_cache_get( "current_site", "site-options" ); 69 if ( $current_site )69 if ( $current_site ) 70 70 return $current_site; 71 71 72 72 $wpdb->suppress_errors(); 73 73 $sites = $wpdb->get_results( "SELECT * FROM $wpdb->site" ); // usually only one site 74 if ( count( $sites ) == 1 ) {74 if ( count( $sites ) == 1 ) { 75 75 $current_site = $sites[0]; 76 76 $path = $current_site->path; … … 81 81 } 82 82 $path = substr( $_SERVER[ 'REQUEST_URI' ], 0, 1 + strpos( $_SERVER[ 'REQUEST_URI' ], '/', 1 ) ); 83 if ( is_subdomain_install() ) {83 if ( is_subdomain_install() ) { 84 84 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path) ); 85 if ( $current_site != null )85 if ( $current_site != null ) 86 86 return $current_site; 87 87 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain) ); 88 if ( $current_site != null ) {88 if ( $current_site != null ) { 89 89 $path = '/'; 90 90 return $current_site; … … 93 93 $sitedomain = substr( $domain, 1 + strpos( $domain, '.' ) ); 94 94 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path) ); 95 if ( $current_site != null )95 if ( $current_site != null ) 96 96 return $current_site; 97 97 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $sitedomain) ); 98 if ( $current_site == null && defined( "WP_INSTALLING" ) == false ) {99 if ( count( $sites ) == 1 ) {98 if ( $current_site == null && defined( "WP_INSTALLING" ) == false ) { 99 if ( count( $sites ) == 1 ) { 100 100 $current_site = $sites[0]; 101 101 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>" ); … … 108 108 } else { 109 109 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path) ); 110 if ( $current_site != null )110 if ( $current_site != null ) 111 111 return $current_site; 112 112 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain) ); 113 if ( $current_site == null && defined( "WP_INSTALLING" ) == false ) {114 if ( count( $sites ) == 1 ) {113 if ( $current_site == null && defined( "WP_INSTALLING" ) == false ) { 114 if ( count( $sites ) == 1 ) { 115 115 $current_site = $sites[0]; 116 116 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>" ); … … 126 126 127 127 $current_site = wpmu_current_site(); 128 if ( !isset( $current_site->blog_id ) )128 if ( !isset( $current_site->blog_id ) ) 129 129 $current_site->blog_id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} WHERE domain='{$current_site->domain}' AND path='{$current_site->path}'" ); 130 130 131 if ( is_subdomain_install() ) {131 if ( is_subdomain_install() ) { 132 132 $current_blog = wp_cache_get( 'current_blog_' . $domain, 'site-options' ); 133 if ( !$current_blog ) {133 if ( !$current_blog ) { 134 134 $current_blog = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE domain = %s", $domain) ); 135 if ( $current_blog )135 if ( $current_blog ) 136 136 wp_cache_set( 'current_blog_' . $domain, $current_blog, 'site-options' ); 137 137 } 138 if ( $current_blog != null && $current_blog->site_id != $current_site->id ) {138 if ( $current_blog != null && $current_blog->site_id != $current_site->id ) 139 139 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE id = %d", $current_blog->site_id) ); 140 } else {140 else 141 141 $blogname = substr( $domain, 0, strpos( $domain, '.' ) ); 142 }143 142 } else { 144 143 $blogname = htmlspecialchars( substr( $_SERVER[ 'REQUEST_URI' ], strlen( $path ) ) ); 145 if ( strpos( $blogname, '/' ) )144 if ( strpos( $blogname, '/' ) ) 146 145 $blogname = substr( $blogname, 0, strpos( $blogname, '/' ) ); 147 if ( strpos( " ".$blogname, '?' ) )146 if ( strpos( " ".$blogname, '?' ) ) 148 147 $blogname = substr( $blogname, 0, strpos( $blogname, '?' ) ); 149 148 $reserved_blognames = array( 'page', 'comments', 'blog', 'wp-admin', 'wp-includes', 'wp-content', 'files', 'feed' ); 150 if ( $blogname != '' && !in_array( $blogname, $reserved_blognames ) && !is_file( $blogname ) ) {149 if ( $blogname != '' && !in_array( $blogname, $reserved_blognames ) && !is_file( $blogname ) ) 151 150 $path = $path . $blogname . '/'; 152 }153 151 $current_blog = wp_cache_get( 'current_blog_' . $domain . $path, 'site-options' ); 154 if ( !$current_blog ) {152 if ( !$current_blog ) { 155 153 $current_blog = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $domain, $path) ); 156 if ( $current_blog )154 if ( $current_blog ) 157 155 wp_cache_set( 'current_blog_' . $domain . $path, $current_blog, 'site-options' ); 158 156 } 159 157 } 160 158 161 if ( defined( "WP_INSTALLING" ) == false && is_subdomain_install() && !is_object( $current_blog ) ) {162 if ( defined( 'NOBLOGREDIRECT' ) ) {159 if ( defined( "WP_INSTALLING" ) == false && is_subdomain_install() && !is_object( $current_blog ) ) { 160 if ( defined( 'NOBLOGREDIRECT' ) ) { 163 161 $destination = constant( 'NOBLOGREDIRECT' ); 164 162 if ( $destination == '%siteurl%' ) … … 173 171 } 174 172 175 if ( defined( "WP_INSTALLING" ) == false ) {176 if ( $current_site && $current_blog == null ) {177 if ( $current_site->domain != $_SERVER[ 'HTTP_HOST' ] ) {173 if ( defined( "WP_INSTALLING" ) == false ) { 174 if ( $current_site && $current_blog == null ) { 175 if ( $current_site->domain != $_SERVER[ 'HTTP_HOST' ] ) { 178 176 header( "Location: http://" . $current_site->domain . $current_site->path ); 179 177 exit; … … 181 179 $current_blog = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $current_site->domain, $current_site->path) ); 182 180 } 183 if ( $current_blog == false || $current_site == false )181 if ( $current_blog == false || $current_site == false ) 184 182 is_installed(); 185 183 } … … 188 186 $public = $current_blog->public; 189 187 190 if ( $current_blog->site_id == 0 || $current_blog->site_id == '' )188 if ( $current_blog->site_id == 0 || $current_blog->site_id == '' ) 191 189 $current_blog->site_id = 1; 192 190 $site_id = $current_blog->site_id; … … 194 192 $current_site = get_current_site_name( $current_site ); 195 193 196 if ( $blog_id == false ) {194 if ( $blog_id == false ) { 197 195 // no blog found, are we installing? Check if the table exists. 198 196 if ( defined('WP_INSTALLING') ) { 199 $blog_id = $wpdb->get_var( "SELECT blog_id FROM $wpdb->blogs LIMIT 0,1" );200 if( $blog_id == false ) {201 // table doesn't exist. This is the first blog202 $blog_id = 1;203 } else {204 // table exists205 // don't create record at this stage. we're obviously installing so it doesn't matter what the table vars below are like.206 // default to using the "main" blog.207 $blog_id = 1;208 }209 $current_blog->blog_id = $blog_id;197 $blog_id = $wpdb->get_var( "SELECT blog_id FROM $wpdb->blogs LIMIT 0,1" ); 198 if ( $blog_id == false ) { 199 // table doesn't exist. This is the first blog 200 $blog_id = 1; 201 } else { 202 // table exists 203 // don't create record at this stage. we're obviously installing so it doesn't matter what the table vars below are like. 204 // default to using the "main" blog. 205 $blog_id = 1; 206 } 207 $current_blog->blog_id = $blog_id; 210 208 } else { 211 $check = $wpdb->get_results( "SELECT * FROM $wpdb->site" ); 212 if( $check == false ) { 213 $msg = ': DB Tables Missing'; 214 } else { 215 $msg = ''; 216 } 217 die( "No Blog by that name on this system." . $msg ); 209 $check = $wpdb->get_results( "SELECT * FROM $wpdb->site" ); 210 if ( $check == false ) 211 $msg = ': DB Tables Missing'; 212 else 213 $msg = ''; 214 die( "No Blog by that name on this system." . $msg ); 218 215 } 219 216 } … … 221 218 $wpdb->suppress_errors( false ); 222 219 223 if ( '0' == $current_blog->public ) {220 if ( '0' == $current_blog->public ) { 224 221 // This just means the blog shouldn't show up in google, etc. Only to registered members 225 222 } … … 228 225 global $wpdb, $domain, $path; 229 226 $base = stripslashes( $base ); 230 if ( defined( "WP_INSTALLING" ) == false ) {227 if ( defined( "WP_INSTALLING" ) == false ) { 231 228 $check = $wpdb->get_results( "SELECT * FROM $wpdb->site" ); 232 229 $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 />"; 233 if ( $check == false ) {230 if ( $check == false ) { 234 231 $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 />"; 235 232 } else { … … 248 245 </ul>"; 249 246 $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 />"; 250 if ( is_file( 'release-info.txt' ) ) {247 if ( is_file( 'release-info.txt' ) ) { 251 248 $msg .= 'Your bug report must include the following text: "'; 252 249 $info = file( 'release-info.txt' );
Note: See TracChangeset
for help on using the changeset viewer.