[ Index ]

PHP Cross Reference of WordPress 3.0 beta 1

[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

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('VHOST') && VHOST == 'yes' )
  20          return true;
  21  
  22      return false;
  23  }
  24  
  25  /**
  26   * Checks status of current blog.
  27   *
  28   * Checks if the blog is deleted, inactive, archived, or spammed.
  29   *
  30   * Dies with a default message if the blog does not pass the check.
  31   *
  32   * To change the default message when a blog does not pass the check,
  33   * use the wp-content/blog-deleted.php, blog-inactive.php and
  34   * blog-suspended.php drop-ins.
  35   *
  36   * @return bool|string Returns true on success, or drop-in file to include.
  37   */
  38  function ms_site_check() {
  39      global $wpdb, $current_blog;
  40  
  41      if ( '1' == $current_blog->deleted ) {
  42          if ( file_exists( WP_CONTENT_DIR . '/blog-deleted.php' ) ) {
  43              return WP_CONTENT_DIR . '/blog-deleted.php';
  44          } else {
  45              header( 'HTTP/1.1 410 Gone' );
  46              wp_die( /*WP_I18N_USER_DELETED_BLOG*/'This user has elected to delete their account and the content is no longer available.'/*/WP_I18N_USER_DELETED_BLOG*/ );
  47          }
  48      }
  49  
  50      if ( '2' == $current_blog->deleted ) {
  51          if ( file_exists( WP_CONTENT_DIR . '/blog-inactive.php' ) )
  52              return WP_CONTENT_DIR . '/blog-inactive.php';
  53          else
  54              wp_die( sprintf( /*WP_I18N_BLOG_NOT_ACTIVATED*/'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>.'/*/WP_I18N_BLOG_NOT_ACTIVATED*/, str_replace( '@', ' AT ', get_site_option( 'admin_email', "support@{$current_site->domain}" ) ) ) );
  55      }
  56  
  57      if ( $current_blog->archived == '1' || $current_blog->spam == '1' ) {
  58          if ( file_exists( WP_CONTENT_DIR . '/blog-suspended.php' ) ) {
  59              return WP_CONTENT_DIR . '/blog-suspended.php';
  60          } else {
  61              header( 'HTTP/1.1 410 Gone' );
  62              wp_die( /*WP_I18N_ARCHIVED*/'This blog has been archived or suspended.'/*/WP_I18N_ARCHIVED*/ );
  63          }
  64      }
  65  
  66      return true;
  67  }
  68  
  69  /**
  70   * Sets current site name.
  71   *
  72   * @access private
  73   * @since 3.0.0
  74   * @return object $current_site object with site_name
  75   */
  76  function get_current_site_name( $current_site ) {
  77      global $wpdb;
  78      $current_site->site_name = wp_cache_get( $current_site->id . ':current_site_name', 'site-options' );
  79      if ( ! $current_site->site_name ) {
  80          $current_site->site_name = wp_cache_get( $current_site->id . ':site_name', 'site-options' );
  81          if ( ! $current_site->site_name ) {
  82              $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 ) );
  83              if ( ! $current_site->site_name )
  84                  $current_site->site_name = ucfirst( $current_site->domain );
  85          }
  86          wp_cache_set( $current_site->id . ':current_site_name', $current_site->site_name, 'site-options' );
  87      }
  88      return $current_site;
  89  }
  90  
  91  /**
  92   * Sets current_site object.
  93   *
  94   * @access private
  95   * @since 3.0.0
  96   * @return object $current_site object
  97   */
  98  function wpmu_current_site() {
  99      global $wpdb, $current_site, $domain, $path, $sites, $cookie_domain;
 100      if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) {
 101          $current_site->id = defined( 'SITE_ID_CURRENT_SITE' ) ? SITE_ID_CURRENT_SITE : 1;
 102          $current_site->domain = DOMAIN_CURRENT_SITE;
 103          $current_site->path   = $path = PATH_CURRENT_SITE;
 104          if ( defined( 'BLOG_ID_CURRENT_SITE' ) )
 105              $current_site->blog_id = BLOG_ID_CURRENT_SITE;
 106          elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) // deprecated.
 107              $current_site->blog_id = BLOGID_CURRENT_SITE;
 108          if ( DOMAIN_CURRENT_SITE == $domain )
 109              $current_site->cookie_domain = $cookie_domain;
 110          elseif ( substr( $current_site->domain, 0, 4 ) == 'www.' )
 111              $current_site->cookie_domain = substr( $current_site->domain, 4 );
 112          else
 113              $current_site->cookie_domain = $current_site->domain;
 114  
 115          wp_load_core_site_options( $current_site->id );
 116  
 117          return $current_site;
 118      }
 119  
 120      $current_site = wp_cache_get( 'current_site', 'site-options' );
 121      if ( $current_site )
 122          return $current_site;
 123  
 124      $sites = $wpdb->get_results( "SELECT * FROM $wpdb->site" ); // usually only one site
 125      if ( 1 == count( $sites ) ) {
 126          $current_site = $sites[0];
 127          wp_load_core_site_options( $current_site->id );
 128          $path = $current_site->path;
 129          $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 ) );
 130          $current_site = get_current_site_name( $current_site );
 131          if ( substr( $current_site->domain, 0, 4 ) == 'www.' )
 132              $current_site->cookie_domain = substr( $current_site->domain, 4 );
 133          wp_cache_set( 'current_site', $current_site, 'site-options' );
 134          return $current_site;
 135      }
 136      $path = substr( $_SERVER[ 'REQUEST_URI' ], 0, 1 + strpos( $_SERVER[ 'REQUEST_URI' ], '/', 1 ) );
 137  
 138      if ( $domain == $cookie_domain )
 139          $current_site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path ) );
 140      else
 141          $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 ) );
 142  
 143      if ( ! $current_site ) {
 144          if ( $domain == $cookie_domain )
 145              $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain ) );
 146          else
 147              $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 ) );
 148      }
 149  
 150      if ( $current_site ) {
 151          $path = $current_site->path;
 152          $current_site->cookie_domain = $cookie_domain;
 153          return $current_site;
 154      }
 155  
 156      if ( is_subdomain_install() ) {
 157          $sitedomain = substr( $domain, 1 + strpos( $domain, '.' ) );
 158          $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path) );
 159          if ( $current_site ) {
 160              $current_site->cookie_domain = $current_site->domain;
 161              return $current_site;
 162          }
 163  
 164          $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $sitedomain) );
 165      }
 166  
 167      if ( $current_site || defined( 'WP_INSTALLING' ) ) {
 168          $path = '/';
 169          return $current_site;
 170      }
 171  
 172      // Still no dice.
 173      // @todo Update or remove WPMU codex link.
 174      if ( 1 == count( $sites ) )
 175          wp_die( sprintf( /*WP_I18N_BLOG_DOESNT_EXIST*/'That blog does not exist. Please try <a href="%s">%s</a>.'/*/WP_I18N_BLOG_DOESNT_EXIST*/, $sites[0]->domain . $sites[0]->path ) );
 176      else
 177          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_WPMU">Debugging WPMU</a> for further assistance.'/*/WP_I18N_NO_SITE_DEFINED*/ );
 178  }
 179  
 180  /**
 181   * Displays a failure message.
 182   *
 183   * Used when blog does not exist. Checks for a missing $wpdb->site table as well.
 184   *
 185   * @todo update for 3.0, pare down, and i18n
 186   *
 187   * @access private
 188   * @since 3.0.0
 189   */
 190  function ms_not_installed() {
 191      global $wpdb, $domain, $path;
 192  
 193      $msg = '<h1>' . /*WP_I18N_FATAL_ERROR*/'Fatal Error'/*/WP_I18N_FATAL_ERROR*/ . '</h1>';
 194      $msg .= '<p>' . /*WP_I18N_CONTACT_OWNER*/'If your site does not display, please contact the owner of this network.'/*/WP_I18N_CONTACT_OWNER*/ . '</p>';
 195      $msg .= '<p>' . /*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>';
 196      if ( !$wpdb->get_var( "SHOW TABLES LIKE '$wpdb->site'" ) )
 197          $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 <em>should</em> look at your database now.'/*/WP_I18N_TABLES_MISSING_LONG*/, $wpdb->site ) . '</p>';
 198      else
 199          $msg .= '<p>' . sprintf( /*WP_I18N_NO_SITE_FOUND*/'<strong>Could Not Find Site!</strong> Searched for table <em>%1$s</em> in <code>%2$s</code>. Is that right?'/*/WP_I18N_NO_SITE_FOUND*/, $domain . $path, DB_NAME, $wpdb->blogs ) . '</p>';
 200      $msg .= '<h1>' . /*WP_I18N_WHAT_DO_I_DO*/'What do I do now?'/*WP_I18N_WHAT_DO_I_DO*/ . '</h1>';
 201      // @todo Update WPMU codex link.
 202      $msg .= '<p>' . /*WP_I18N_RTFM*/'Read the <a target="_blank" href="http://codex.wordpress.org/Debugging_WPMU">bug report</a> page. Some of the guidelines there may help you figure out what went wrong.'/*/WP_I18N_RTFM*/ . '</p>';
 203      $msg .= '<p>' . /*WP_I18N_STUCK*/"If you're still stuck with this message, then check that your database contains the following tables:"/*/WP_I18N_STUCK*/ . '</p><ul>';
 204      foreach ( $wpdb->global_tables as $table ) {
 205          $msg .= '<li>' . $wpdb->prefix . $table . '</li>';
 206      }
 207      $msg .= '</ul>';
 208      // @todo Update WPMU codex link and support instructions.
 209      $msg .= '<p>' . /*WP_I18N_MS_FORUMS*/'If you suspect a problem please report it to the support forums but you must include the information asked for in the <a target="_blank" href="http://codex.wordpress.org/Debugging_WPMU">WPMU bug reporting guidelines</a>!'/*/WP_I18N_MS_FORUMS*/ . '</p>';
 210  
 211      die( $msg );
 212  }


Generated: Mon Apr 5 14:26:09 2010 Cross-referenced by PHPXref 0.7