Make WordPress Core


Ignore:
Timestamp:
01/29/2010 04:26:46 PM (15 years ago)
Author:
ryan
Message:

ms-settings cleanup. Props nacin. see #11644

File:
1 edited

Legend:

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

    r12888 r12896  
    2121
    2222$domain = addslashes( $_SERVER['HTTP_HOST'] );
    23 if ( strpos( $domain, ':' ) ) {
     23if ( false !== strpos( $domain, ':' ) ) {
    2424    if ( substr( $domain, -3 ) == ':80' ) {
    2525        $domain = substr( $domain, 0, -3 );
     
    2929        $_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -4 );
    3030    } else {
    31         die( 'WPMU only works without the port number in the URL.' );
     31        wp_die( 'Multisite only works without the port number in the URL.' );
    3232    }
    3333}
    34 $domain = preg_replace('/:.*$/', '', $domain); // Strip ports
    35 if ( substr( $domain, -1 ) == '.' )
    36     $domain = substr( $domain, 0, -1 );
    3734
    38 if ( substr( $domain, 0, 4 ) == 'www.' )
    39     $cookie_domain = substr( $domain, 4 );
    40 else
    41     $cookie_domain = $domain;
     35$domain = rtrim( $domain, '.' );
     36$cookie_domain = $domain;
     37if ( substr( $cookie_domain, 0, 4 ) == 'www.' )
     38    $cookie_domain = substr( $cookie_domain, 4 );
    4239
    4340$path = preg_replace( '|([a-z0-9-]+.php.*)|', '', $_SERVER['REQUEST_URI'] );
     
    4643
    4744$current_site = wpmu_current_site();
    48 if ( !isset( $current_site->blog_id ) )
    49     $current_site->blog_id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} WHERE domain='{$current_site->domain}' AND path='{$current_site->path}'" );
     45if ( ! isset( $current_site->blog_id ) )
     46    $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 ) );
    5047
    5148if ( is_subdomain_install() ) {
    5249    $current_blog = wp_cache_get( 'current_blog_' . $domain, 'site-options' );
    5350    if ( !$current_blog ) {
    54         $current_blog = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE domain = %s", $domain) );
     51        $current_blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $domain ) );
    5552        if ( $current_blog )
    5653            wp_cache_set( 'current_blog_' . $domain, $current_blog, 'site-options' );
    5754    }
    58     if ( $current_blog != null && $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) );
     55    if ( $current_blog && $current_blog->site_id != $current_site->id )
     56        $current_site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->site WHERE id = %d", $current_blog->site_id ) );
    6057    else
    6158        $blogname = substr( $domain, 0, strpos( $domain, '.' ) );
    6259} else {
    6360    $blogname = htmlspecialchars( substr( $_SERVER[ 'REQUEST_URI' ], strlen( $path ) ) );
    64     if ( strpos( $blogname, '/' ) )
     61    if ( false !== strpos( $blogname, '/' ) )
    6562        $blogname = substr( $blogname, 0, strpos( $blogname, '/' ) );
    66     if ( strpos( " ".$blogname, '?' ) )
     63    if ( false !== strpos( $blogname, '?' ) )
    6764        $blogname = substr( $blogname, 0, strpos( $blogname, '?' ) );
    6865    $reserved_blognames = array( 'page', 'comments', 'blog', 'wp-admin', 'wp-includes', 'wp-content', 'files', 'feed' );
    69     if ( $blogname != '' && !in_array( $blogname, $reserved_blognames ) && !is_file( $blogname ) )
     66    if ( $blogname != '' && ! in_array( $blogname, $reserved_blognames ) && ! is_file( $blogname ) )
    7067        $path = $path . $blogname . '/';
    7168    $current_blog = wp_cache_get( 'current_blog_' . $domain . $path, 'site-options' );
    72     if ( !$current_blog ) {
    73         $current_blog = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $domain, $path) );
     69    if ( ! $current_blog ) {
     70        $current_blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $domain, $path ) );
    7471        if ( $current_blog )
    7572            wp_cache_set( 'current_blog_' . $domain . $path, $current_blog, 'site-options' );
     
    7774}
    7875
    79 if ( ! defined( 'WP_INSTALLING' ) && is_subdomain_install() && !is_object( $current_blog ) ) {
    80 
     76if ( ! defined( 'WP_INSTALLING' ) && is_subdomain_install() && ! is_object( $current_blog ) ) {
    8177    if ( defined( 'NOBLOGREDIRECT' ) ) {
    82         $destination = constant( 'NOBLOGREDIRECT' );
    83         if ( $destination == '%siteurl%' )
     78        $destination = NOBLOGREDIRECT;
     79        if ( '%siteurl%' == $destination )
    8480            $destination = "http://" . $current_site->domain . $current_site->path;
    85         header( "Location: " .  $destination);
    86         die();
    8781    } else {
    88         header( "Location: http://" . $current_site->domain . $current_site->path . "wp-signup.php?new=" . str_replace( '.' . $current_site->domain, '', $domain ) );
    89         die();
     82        $destination = 'http://' . $current_site->domain . $current_site->path . 'wp-signup.php?new=' . str_replace( '.' . $current_site->domain, '', $domain );
    9083    }
    91 
     84    wp_redirect( $destination );
     85    die();
    9286}
    9387
    9488if ( ! defined( 'WP_INSTALLING' ) ) {
    95     if ( $current_site && $current_blog == null ) {
     89    if ( $current_site && ! $current_blog ) {
    9690        if ( $current_site->domain != $_SERVER[ 'HTTP_HOST' ] ) {
    97             header( "Location: http://" . $current_site->domain . $current_site->path );
     91            wp_redirect( 'http://' . $current_site->domain . $current_site->path );
    9892            exit;
    9993        }
    100         $current_blog = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $current_site->domain, $current_site->path) );
     94        $current_blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $current_site->domain, $current_site->path ) );
    10195    }
    102     if ( $current_blog == false || $current_site == false )
     96    if ( ! $current_blog || ! $current_site )
    10397        is_installed();
    10498}
     
    107101$public  = $current_blog->public;
    108102
    109 if ( $current_blog->site_id == 0 || $current_blog->site_id == '' )
     103if ( empty( $current_blog->site_id ) )
    110104    $current_blog->site_id = 1;
    111105$site_id = $current_blog->site_id;
     
    113107$current_site = get_current_site_name( $current_site );
    114108
    115 if ( $blog_id == false ) {
    116     // no blog found, are we installing? Check if the table exists.
    117     if ( defined('WP_INSTALLING') ) {
    118         $blog_id = $wpdb->get_var( "SELECT blog_id FROM $wpdb->blogs LIMIT 0,1" );
    119         if ( $blog_id == false ) {
    120             // table doesn't exist. This is the first blog
    121             $blog_id = 1;
    122         } else {
    123             // table exists
    124             // don't create record at this stage. we're obviously installing so it doesn't matter what the table vars below are like.
    125             // default to using the "main" blog.
    126             $blog_id = 1;
    127         }
    128         $current_blog->blog_id = $blog_id;
     109if ( ! $blog_id ) {
     110    if ( defined('WP_INSTALLING') ) {
     111        $current_blog->blog_id = $blog_id = 1;
    129112    } else {
    130         $check = $wpdb->get_results( "SELECT * FROM $wpdb->site" );
    131         if ( $check == false )
    132             $msg = ': DB Tables Missing';
    133         else
    134             $msg = '';
    135         die( "No Blog by that name on this system." . $msg );
     113        $msg = ! $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->site'" ) ? __( 'Database tables are missing.' ) : '';
     114        wp_die( __( 'No blog by that name on this system.' ) . $msg );
    136115    }
    137116}
     
    139118$wpdb->suppress_errors( false );
    140119
    141 if ( '0' == $current_blog->public ) {
    142     // This just means the blog shouldn't show up in google, etc. Only to registered members
    143 }
    144 
    145120$wpdb->blogid = $current_blog->blog_id;
    146121$wpdb->siteid = $current_blog->site_id;
    147 $wpdb->set_prefix($table_prefix); // set up blog tables
     122$wpdb->set_prefix( $table_prefix ); // set up blog tables
    148123$table_prefix = $wpdb->get_blog_prefix();
    149 
    150 // Fix empty PHP_SELF
    151 $PHP_SELF = $_SERVER['PHP_SELF'];
    152 if ( empty($PHP_SELF) || ( empty($PHP_SELF) && !is_subdomain_install() && $current_blog->path != '/' ) )
    153     $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace("/(\?.*)?$/",'',$_SERVER["REQUEST_URI"]);
    154124
    155125// need to init cache again after blog_id is set
    156126wp_start_object_cache();
    157127
     128// Define upload directory constants
    158129ms_default_constants( 'uploads' );
    159130
Note: See TracChangeset for help on using the changeset viewer.