[ XREF Home ] [ Index ]

PHP Cross Reference of WordPress Trunk

Provided by Yoast

title

Body

[close]

/wp-includes/ -> ms-settings.php (source)

   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              if ( ! isset( $current_site->blog_id ) )
  65                  $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 ) );
  66          } else
  67              $blogname = substr( $domain, 0, strpos( $domain, '.' ) );
  68      } else {
  69          $blogname = htmlspecialchars( substr( $_SERVER[ 'REQUEST_URI' ], strlen( $path ) ) );
  70          if ( false !== strpos( $blogname, '/' ) )
  71              $blogname = substr( $blogname, 0, strpos( $blogname, '/' ) );
  72          if ( false !== strpos( $blogname, '?' ) )
  73              $blogname = substr( $blogname, 0, strpos( $blogname, '?' ) );
  74          $reserved_blognames = array( 'page', 'comments', 'blog', 'wp-admin', 'wp-includes', 'wp-content', 'files', 'feed' );
  75          if ( $blogname != '' && ! in_array( $blogname, $reserved_blognames ) && ! is_file( $blogname ) )
  76              $path .= $blogname . '/';
  77          $current_blog = wp_cache_get( 'current_blog_' . $domain . $path, 'site-options' );
  78          if ( ! $current_blog ) {
  79              $current_blog = get_blog_details( array( 'domain' => $domain, 'path' => $path ), false );
  80              if ( $current_blog )
  81                  wp_cache_set( 'current_blog_' . $domain . $path, $current_blog, 'site-options' );
  82          }
  83          unset($reserved_blognames);
  84      }
  85  
  86      if ( ! defined( 'WP_INSTALLING' ) && is_subdomain_install() && ! is_object( $current_blog ) ) {
  87          if ( defined( 'NOBLOGREDIRECT' ) ) {
  88              $destination = NOBLOGREDIRECT;
  89              if ( '%siteurl%' == $destination )
  90                  $destination = "http://" . $current_site->domain . $current_site->path;
  91          } else {
  92              $destination = 'http://' . $current_site->domain . $current_site->path . 'wp-signup.php?new=' . str_replace( '.' . $current_site->domain, '', $domain );
  93          }
  94          header( 'Location: ' . $destination );
  95          die();
  96      }
  97  
  98      if ( ! defined( 'WP_INSTALLING' ) ) {
  99          if ( $current_site && ! $current_blog ) {
 100              if ( $current_site->domain != $_SERVER[ 'HTTP_HOST' ] ) {
 101                  header( 'Location: http://' . $current_site->domain . $current_site->path );
 102                  exit;
 103              }
 104              $current_blog = get_blog_details( array( 'domain' => $current_site->domain, 'path' => $current_site->path ), false );
 105          }
 106          if ( ! $current_blog || ! $current_site )
 107              ms_not_installed();
 108      }
 109  
 110      $blog_id = $current_blog->blog_id;
 111      $public  = $current_blog->public;
 112  
 113      if ( empty( $current_blog->site_id ) )
 114          $current_blog->site_id = 1;
 115      $site_id = $current_blog->site_id;
 116  
 117      $current_site = get_current_site_name( $current_site );
 118  
 119      if ( ! $blog_id ) {
 120          if ( defined( 'WP_INSTALLING' ) ) {
 121              $current_blog->blog_id = $blog_id = 1;
 122          } else {
 123              $msg = ! $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->site'" ) ? ' ' . /*WP_I18N_TABLES_MISSING*/'Database tables are missing.'/*/WP_I18N_TABLES_MISSING*/ : '';
 124              wp_die( /*WP_I18N_NO_BLOG*/'No site by that name on this system.'/*/WP_I18N_NO_BLOG*/ . $msg );
 125          }
 126      }
 127  }
 128  $wpdb->set_prefix( $table_prefix, false ); // $table_prefix can be set in sunrise.php
 129  $wpdb->set_blog_id( $current_blog->blog_id, $current_blog->site_id );
 130  $table_prefix = $wpdb->get_blog_prefix();
 131  
 132  // need to init cache again after blog_id is set
 133  wp_start_object_cache();
 134  
 135  // Define upload directory constants
 136  ms_upload_constants();


Generated: Wed Jun 1 08:30:02 2011 Cross-referenced by PHPXref 0.7
Provided by Yoast and awesome WordPress Hosting