[ XREF Home ] [ Index ]

PHP Cross Reference of WordPress Trunk

Provided by Yoast

title

Body

[close]

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

   1  <?php
   2  /**
   3   * These functions are needed to load Multisite.
   4   *
   5   * @since 3.0.0
   6   *
   7   * @package WordPress
   8   * @subpackage Multisite
   9   */
  10  
  11  /**
  12   * Whether a subdomain configuration is enabled.
  13   *
  14   * @since 3.0.0
  15   *
  16   * @return bool True if subdomain configuration is enabled, false otherwise.
  17   */
  18  function is_subdomain_install() {
  19      if ( defined('SUBDOMAIN_INSTALL') )
  20          return SUBDOMAIN_INSTALL;
  21  
  22      if ( defined('VHOST') && VHOST == 'yes' )
  23          return true;
  24  
  25      return false;
  26  }
  27  
  28  /**
  29   * Returns array of network plugin files to be included in global scope.
  30   *
  31   * The default directory is wp-content/plugins. To change the default directory
  32   * manually, define <code>WP_PLUGIN_DIR</code> and <code>WP_PLUGIN_URL</code>
  33   * in wp-config.php.
  34   *
  35   * @access private
  36   * @since 3.1.0
  37   * @return array Files to include
  38   */
  39  function wp_get_active_network_plugins() {
  40      $active_plugins = (array) get_site_option( 'active_sitewide_plugins', array() );
  41      if ( empty( $active_plugins ) )
  42          return array();
  43  
  44      $plugins = array();
  45      $active_plugins = array_keys( $active_plugins );
  46      sort( $active_plugins );
  47  
  48      foreach ( $active_plugins as $plugin ) {
  49          if ( ! validate_file( $plugin ) // $plugin must validate as file
  50              && '.php' == substr( $plugin, -4 ) // $plugin must end with '.php'
  51              && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist
  52              )
  53          $plugins[] = WP_PLUGIN_DIR . '/' . $plugin;
  54      }
  55      return $plugins;
  56  }
  57  
  58  /**
  59   * Checks status of current blog.
  60   *
  61   * Checks if the blog is deleted, inactive, archived, or spammed.
  62   *
  63   * Dies with a default message if the blog does not pass the check.
  64   *
  65   * To change the default message when a blog does not pass the check,
  66   * use the wp-content/blog-deleted.php, blog-inactive.php and
  67   * blog-suspended.php drop-ins.
  68   *
  69   * @return bool|string Returns true on success, or drop-in file to include.
  70   */
  71  function ms_site_check() {
  72      global $wpdb, $current_blog;
  73  
  74      // Allow short-circuiting
  75      $check = apply_filters('ms_site_check', null);
  76      if ( null !== $check )
  77          return true;
  78  
  79      // Allow super admins to see blocked sites
  80      if ( is_super_admin() )
  81          return true;
  82  
  83      if ( '1' == $current_blog->deleted ) {
  84          if ( file_exists( WP_CONTENT_DIR . '/blog-deleted.php' ) )
  85              return WP_CONTENT_DIR . '/blog-deleted.php';
  86          else
  87              wp_die( __( 'This user has elected to delete their account and the content is no longer available.' ), '', array( 'response' => 410 ) );
  88      }
  89  
  90      if ( '2' == $current_blog->deleted ) {
  91          if ( file_exists( WP_CONTENT_DIR . '/blog-inactive.php' ) )
  92              return WP_CONTENT_DIR . '/blog-inactive.php';
  93          else
  94              wp_die( sprintf( __( 'This site has not been activated yet. If you are having problems activating your site, please contact <a href="mailto:%1$s">%1$s</a>.' ), str_replace( '@', ' AT ', get_site_option( 'admin_email', "support@{$current_site->domain}" ) ) ) );
  95      }
  96  
  97      if ( $current_blog->archived == '1' || $current_blog->spam == '1' ) {
  98          if ( file_exists( WP_CONTENT_DIR . '/blog-suspended.php' ) )
  99              return WP_CONTENT_DIR . '/blog-suspended.php';
 100          else
 101              wp_die( __( 'This site has been archived or suspended.' ), '', array( 'response' => 410 ) );
 102      }
 103  
 104      return true;
 105  }
 106  
 107  /**
 108   * Sets current site name.
 109   *
 110   * @access private
 111   * @since 3.0.0
 112   * @return object $current_site object with site_name
 113   */
 114  function get_current_site_name( $current_site ) {
 115      global $wpdb;
 116  
 117      $current_site->site_name = wp_cache_get( $current_site->id . ':site_name', 'site-options' );
 118      if ( ! $current_site->site_name ) {
 119          $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 ) );
 120          if ( ! $current_site->site_name )
 121              $current_site->site_name = ucfirst( $current_site->domain );
 122      }
 123      wp_cache_set( $current_site->id . ':site_name', $current_site->site_name, 'site-options' );
 124  
 125      return $current_site;
 126  }
 127  
 128  /**
 129   * Sets current_site object.
 130   *
 131   * @access private
 132   * @since 3.0.0
 133   * @return object $current_site object
 134   */
 135  function wpmu_current_site() {
 136      global $wpdb, $current_site, $domain, $path, $sites, $cookie_domain;
 137      if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) {
 138          $current_site->id = defined( 'SITE_ID_CURRENT_SITE' ) ? SITE_ID_CURRENT_SITE : 1;
 139          $current_site->domain = DOMAIN_CURRENT_SITE;
 140          $current_site->path   = $path = PATH_CURRENT_SITE;
 141          if ( defined( 'BLOG_ID_CURRENT_SITE' ) )
 142              $current_site->blog_id = BLOG_ID_CURRENT_SITE;
 143          elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) // deprecated.
 144              $current_site->blog_id = BLOGID_CURRENT_SITE;
 145          if ( DOMAIN_CURRENT_SITE == $domain )
 146              $current_site->cookie_domain = $cookie_domain;
 147          elseif ( substr( $current_site->domain, 0, 4 ) == 'www.' )
 148              $current_site->cookie_domain = substr( $current_site->domain, 4 );
 149          else
 150              $current_site->cookie_domain = $current_site->domain;
 151  
 152          wp_load_core_site_options( $current_site->id );
 153  
 154          return $current_site;
 155      }
 156  
 157      $current_site = wp_cache_get( 'current_site', 'site-options' );
 158      if ( $current_site )
 159          return $current_site;
 160  
 161      $sites = $wpdb->get_results( "SELECT * FROM $wpdb->site" ); // usually only one site
 162      if ( 1 == count( $sites ) ) {
 163          $current_site = $sites[0];
 164          wp_load_core_site_options( $current_site->id );
 165          $path = $current_site->path;
 166          $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 ) );
 167          $current_site = get_current_site_name( $current_site );
 168          if ( substr( $current_site->domain, 0, 4 ) == 'www.' )
 169              $current_site->cookie_domain = substr( $current_site->domain, 4 );
 170          wp_cache_set( 'current_site', $current_site, 'site-options' );
 171          return $current_site;
 172      }
 173      $path = substr( $_SERVER[ 'REQUEST_URI' ], 0, 1 + strpos( $_SERVER[ 'REQUEST_URI' ], '/', 1 ) );
 174  
 175      if ( $domain == $cookie_domain )
 176          $current_site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path ) );
 177      else
 178          $current_site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->site WHERE domain IN ( %s, %s ) AND path = %s ORDER BY CHAR_LENGTH( domain ) DESC LIMIT 1", $domain, $cookie_domain, $path ) );
 179  
 180      if ( ! $current_site ) {
 181          if ( $domain == $cookie_domain )
 182              $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain ) );
 183          else
 184              $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain IN ( %s, %s ) AND path = '/' ORDER BY CHAR_LENGTH( domain ) DESC LIMIT 1", $domain, $cookie_domain, $path ) );
 185      }
 186  
 187      if ( $current_site ) {
 188          $path = $current_site->path;
 189          $current_site->cookie_domain = $cookie_domain;
 190          return $current_site;
 191      }
 192  
 193      if ( is_subdomain_install() ) {
 194          $sitedomain = substr( $domain, 1 + strpos( $domain, '.' ) );
 195          $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path) );
 196          if ( $current_site ) {
 197              $current_site->cookie_domain = $current_site->domain;
 198              return $current_site;
 199          }
 200  
 201          $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $sitedomain) );
 202      }
 203  
 204      if ( $current_site || defined( 'WP_INSTALLING' ) ) {
 205          $path = '/';
 206          return $current_site;
 207      }
 208  
 209      // Still no dice.
 210      if ( 1 == count( $sites ) )
 211          wp_die( sprintf( /*WP_I18N_BLOG_DOESNT_EXIST*/'That site does not exist. Please try <a href="%s">%s</a>.'/*/WP_I18N_BLOG_DOESNT_EXIST*/, $sites[0]->domain . $sites[0]->path ) );
 212      else
 213          wp_die( /*WP_I18N_NO_SITE_DEFINED*/'No site defined on this host. If you are the owner of this site, please check <a href="http://codex.wordpress.org/Debugging_a_WordPress_Network">Debugging a WordPress Network</a> for help.'/*/WP_I18N_NO_SITE_DEFINED*/ );
 214  }
 215  
 216  /**
 217   * Displays a failure message.
 218   *
 219   * Used when a blog's tables do not exist. Checks for a missing $wpdb->site table as well.
 220   *
 221   * @access private
 222   * @since 3.0.0
 223   */
 224  function ms_not_installed() {
 225      global $wpdb, $domain, $path;
 226  
 227      $title = /*WP_I18N_FATAL_ERROR*/'Error establishing database connection'/*/WP_I18N_FATAL_ERROR*/;
 228      $msg  = '<h1>' . $title . '</h1>';
 229      if ( ! is_admin() )
 230          die( $msg );
 231      $msg .= '<p>' . /*WP_I18N_CONTACT_OWNER*/'If your site does not display, please contact the owner of this network.'/*/WP_I18N_CONTACT_OWNER*/ . '';
 232      $msg .= ' ' . /*WP_I18N_CHECK_MYSQL*/'If you are the owner of this network please check that MySQL is running properly and all tables are error free.'/*/WP_I18N_CHECK_MYSQL*/ . '</p>';
 233      if ( false && !$wpdb->get_var( "SHOW TABLES LIKE '$wpdb->site'" ) )
 234          $msg .= '<p>' . sprintf( /*WP_I18N_TABLES_MISSING_LONG*/'<strong>Database tables are missing.</strong> This means that MySQL is not running, WordPress was not installed properly, or someone deleted <code>%s</code>. You really should look at your database now.'/*/WP_I18N_TABLES_MISSING_LONG*/, $wpdb->site ) . '</p>';
 235      else
 236          $msg .= '<p>' . sprintf( /*WP_I18N_NO_SITE_FOUND*/'<strong>Could not find site <code>%1$s</code>.</strong> Searched for table <code>%2$s</code> in database <code>%3$s</code>. Is that right?'/*/WP_I18N_NO_SITE_FOUND*/, rtrim( $domain . $path, '/' ), $wpdb->blogs, DB_NAME ) . '</p>';
 237      $msg .= '<p><strong>' . /*WP_I18N_WHAT_DO_I_DO*/'What do I do now?'/*WP_I18N_WHAT_DO_I_DO*/ . '</strong> ';
 238      $msg .= /*WP_I18N_RTFM*/'Read the <a target="_blank" href="http://codex.wordpress.org/Debugging_a_WordPress_Network">bug report</a> page. Some of the guidelines there may help you figure out what went wrong.'/*/WP_I18N_RTFM*/;
 239      $msg .= ' ' . /*WP_I18N_STUCK*/'If you&#8217;re still stuck with this message, then check that your database contains the following tables:'/*/WP_I18N_STUCK*/ . '</p><ul>';
 240      foreach ( $wpdb->tables('global') as $t => $table ) {
 241          if ( 'sitecategories' == $t )
 242              continue;
 243          $msg .= '<li>' . $table . '</li>';
 244      }
 245      $msg .= '</ul>';
 246  
 247      wp_die( $msg, $title );
 248  }
 249  
 250  ?>


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