[ Root ] [ Search ] [ Index ]

PHP Cross Reference of WordPress MU 2.9.2

Provided by Yoast

title

Body

[close]

/ -> wpmu-settings.php (source)

   1  <?php
   2  if( isset( $current_site ) && isset( $current_blog ) )
   3      return;
   4  
   5  // depreciated

   6  $wpmuBaseTablePrefix = $table_prefix;
   7  
   8  $domain = addslashes( $_SERVER['HTTP_HOST'] );
   9  if( substr( $domain, 0, 4 ) == 'www.' )
  10      $domain = substr( $domain, 4 );
  11  if( strpos( $domain, ':' ) ) {
  12      if( substr( $domain, -3 ) == ':80' ) {
  13          $domain = substr( $domain, 0, -3 );
  14          $_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -3 );
  15      } elseif( substr( $domain, -4 ) == ':443' ) {
  16          $domain = substr( $domain, 0, -4 );
  17          $_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -4 );
  18      } else {
  19          die( 'WPMU only works without the port number in the URL.' );
  20      }
  21  }
  22  $domain = preg_replace('/:.*$/', '', $domain); // Strip ports

  23  if( substr( $domain, -1 ) == '.' )
  24      $domain = substr( $domain, 0, -1 );
  25  
  26  $path = preg_replace( '|([a-z0-9-]+.php.*)|', '', $_SERVER['REQUEST_URI'] );
  27  $path = str_replace ( '/wp-admin/', '/', $path );
  28  $path = preg_replace( '|(/[a-z0-9-]+?/).*|', '$1', $path );
  29  
  30  function get_current_site_name( $current_site ) {
  31      global $wpdb;
  32      $current_site->site_name = wp_cache_get( $current_site->id . ':current_site_name', "site-options" );
  33      if ( !$current_site->site_name ) {
  34          $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 ) );
  35          if( $current_site->site_name == null )
  36              $current_site->site_name = ucfirst( $current_site->domain );
  37          wp_cache_set( $current_site->id . ':current_site_name', $current_site->site_name, 'site-options');
  38      }
  39      return $current_site;
  40  }
  41  
  42  function wpmu_current_site() {
  43      global $wpdb, $current_site, $domain, $path, $sites;
  44      if( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) {
  45          $current_site->id = (defined( 'SITE_ID_CURRENT_SITE' ) ? constant('SITE_ID_CURRENT_SITE') : 1);
  46          $current_site->domain = DOMAIN_CURRENT_SITE;
  47          $current_site->path   = $path = PATH_CURRENT_SITE;
  48          if( defined( 'BLOGID_CURRENT_SITE' ) )
  49              $current_site->blog_id = BLOGID_CURRENT_SITE;
  50          return $current_site;
  51      }
  52  
  53      $current_site = wp_cache_get( "current_site", "site-options" );
  54      if( $current_site )
  55          return $current_site;
  56          
  57      $wpdb->suppress_errors();
  58      $sites = $wpdb->get_results( "SELECT * FROM $wpdb->site" ); // usually only one site

  59      if( count( $sites ) == 1 ) {
  60          $current_site = $sites[0];
  61          $path = $current_site->path;
  62          $current_site->blog_id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} WHERE domain='{$current_site->domain}' AND path='{$current_site->path}'" );
  63          $current_site = get_current_site_name( $current_site );
  64          wp_cache_set( "current_site", $current_site, "site-options" );
  65          return $current_site;
  66      }
  67      $path = substr( $_SERVER[ 'REQUEST_URI' ], 0, 1 + strpos( $_SERVER[ 'REQUEST_URI' ], '/', 1 ) );
  68      if( constant( 'VHOST' ) == 'yes' ) {
  69          $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path) );
  70          if( $current_site != null )
  71              return $current_site;
  72          $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain) );
  73          if( $current_site != null ) {
  74              $path = '/';
  75              return $current_site;
  76          }
  77  
  78          $sitedomain = substr( $domain, 1 + strpos( $domain, '.' ) );
  79          $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path) );
  80          if( $current_site != null )
  81              return $current_site;
  82          $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $sitedomain) );
  83          if( $current_site == null && defined( "WP_INSTALLING" ) == false ) {
  84              if( count( $sites ) == 1 ) {
  85                  $current_site = $sites[0];
  86                  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>" );
  87              } else {
  88                  die( "No WPMU 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." );
  89              }
  90          } else {
  91              $path = '/';
  92          }
  93      } else {
  94          $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path) );
  95          if( $current_site != null )
  96              return $current_site;
  97          $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain) );
  98          if( $current_site == null && defined( "WP_INSTALLING" ) == false ) {
  99              if( count( $sites ) == 1 ) {
 100                  $current_site = $sites[0];
 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>" );
 102              } else {
 103                  die( "No WPMU 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." );
 104              }
 105          } else {
 106              $path = '/';
 107          }
 108      }
 109      return $current_site;
 110  }
 111  
 112  $current_site = wpmu_current_site();
 113  if( !isset( $current_site->blog_id ) )
 114      $current_site->blog_id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} WHERE domain='{$current_site->domain}' AND path='{$current_site->path}'" );
 115  
 116  if( constant( 'VHOST' ) == 'yes' ) {
 117      $current_blog = wp_cache_get( 'current_blog_' . $domain, 'site-options' );
 118      if( !$current_blog ) {
 119          $current_blog = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE domain = %s", $domain) );
 120          if( $current_blog )
 121              wp_cache_set( 'current_blog_' . $domain, $current_blog, 'site-options' );
 122      }
 123      if( $current_blog != null && $current_blog->site_id != $current_site->id ) {
 124          $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE id = %d", $current_blog->site_id) );
 125      } else {
 126          $blogname = substr( $domain, 0, strpos( $domain, '.' ) );
 127      }
 128  } else {
 129      $blogname = htmlspecialchars( substr( $_SERVER[ 'REQUEST_URI' ], strlen( $path ) ) );
 130      if( strpos( $blogname, '/' ) )
 131          $blogname = substr( $blogname, 0, strpos( $blogname, '/' ) );
 132      if( strpos( " ".$blogname, '?' ) )
 133          $blogname = substr( $blogname, 0, strpos( $blogname, '?' ) );
 134      $reserved_blognames = array( 'page', 'comments', 'blog', 'wp-admin', 'wp-includes', 'wp-content', 'files', 'feed' );
 135      if ( $blogname != '' && !in_array( $blogname, $reserved_blognames ) && !is_file( $blogname ) ) {
 136          $path = $path . $blogname . '/';
 137      }
 138      $current_blog = wp_cache_get( 'current_blog_' . $domain . $path, 'site-options' );
 139      if( !$current_blog ) {
 140          $current_blog = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $domain, $path) );
 141          if( $current_blog )
 142              wp_cache_set( 'current_blog_' . $domain . $path, $current_blog, 'site-options' );
 143      }
 144  }
 145  
 146  if( defined( "WP_INSTALLING" ) == false && constant( 'VHOST' ) == 'yes' && !is_object( $current_blog ) ) {
 147      if( defined( 'NOBLOGREDIRECT' ) ) {
 148          $destination = constant( 'NOBLOGREDIRECT' );
 149          if ( $destination == '%siteurl%' )
 150              $destination = "http://" . $current_site->domain . $current_site->path;
 151          header( "Location: " .  $destination);
 152          die();
 153      } else {
 154          header( "Location: http://" . $current_site->domain . $current_site->path . "wp-signup.php?new=" . str_replace( '.' . $current_site->domain, '', $domain ) );
 155          die();
 156      }
 157  
 158  }
 159  
 160  if( defined( "WP_INSTALLING" ) == false ) {
 161      if( $current_site && $current_blog == null ) {
 162          if( $current_site->domain != $_SERVER[ 'HTTP_HOST' ] ) {
 163              header( "Location: http://" . $current_site->domain . $current_site->path );
 164              exit;
 165          }
 166          $current_blog = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $current_site->domain, $current_site->path) );
 167      }
 168      if( $current_blog == false || $current_site == false )
 169          is_installed();
 170  }
 171  
 172  $blog_id = $current_blog->blog_id;
 173  $public  = $current_blog->public;
 174  
 175  if( $current_blog->site_id == 0 || $current_blog->site_id == '' )
 176      $current_blog->site_id = 1;
 177  $site_id = $current_blog->site_id;
 178  
 179  $current_site = get_current_site_name( $current_site );
 180  
 181  if( $blog_id == false ) {
 182      // no blog found, are we installing? Check if the table exists.

 183      if ( defined('WP_INSTALLING') ) {
 184      $blog_id = $wpdb->get_var( "SELECT blog_id FROM $wpdb->blogs LIMIT 0,1" );
 185      if( $blog_id == false ) {
 186          // table doesn't exist. This is the first blog

 187          $blog_id = 1;
 188      } else {
 189          // table exists

 190          // don't create record at this stage. we're obviously installing so it doesn't matter what the table vars below are like.

 191          // default to using the "main" blog.

 192          $blog_id = 1;
 193      }
 194      $current_blog->blog_id = $blog_id;
 195      } else {
 196      $check = $wpdb->get_results( "SELECT * FROM $wpdb->site" );
 197      if( $check == false ) {
 198          $msg = ': DB Tables Missing';
 199      } else {
 200          $msg = '';
 201      }
 202      die( "No Blog by that name on this system." . $msg );
 203      }
 204  }
 205  
 206  $wpdb->suppress_errors( false );
 207  
 208  if( '0' == $current_blog->public ) {
 209      // This just means the blog shouldn't show up in google, etc. Only to registered members

 210  }
 211  
 212  function is_installed() {
 213      global $wpdb, $domain, $path;
 214      $base = stripslashes( $base );
 215      if( defined( "WP_INSTALLING" ) == false ) {
 216          $check = $wpdb->get_results( "SELECT * FROM $wpdb->site" );
 217          $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 />";
 218          if( $check == false ) {
 219              $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 />";
 220          } else {
 221              $msg .= '<strong>Could Not Find Blog!</strong><br />';
 222              $msg .= "Searched for <em>" . $domain . $path . "</em> in " . DB_NAME . "::" . $wpdb->blogs . " table. Is that right?<br />";
 223          }
 224          $msg .= "<br />\n<h1>What do I do now?</h1>";
 225          $msg .= "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.<br />";
 226          $msg .= "If you're still stuck with this message, then check that your database contains the following tables:<ul>
 227              <li> $wpdb->blogs </li>
 228              <li> $wpdb->users </li>
 229              <li> $wpdb->usermeta </li>
 230              <li> $wpdb->site </li>
 231              <li> $wpdb->sitemeta </li>
 232              <li> $wpdb->sitecategories </li>
 233              </ul>";
 234          $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 />";
 235          if( is_file( 'release-info.txt' ) ) {
 236              $msg .= 'Your bug report must include the following text: "';
 237              $info = file( 'release-info.txt' );
 238              $msg .= $info[ 4 ] . '"';
 239          }
 240  
 241          die( "<h1>Fatal Error</h1> " . $msg );
 242      }
 243  }
 244  
 245  ?>


Generated: Mon May 3 12:25:32 2010 Cross-referenced by PHPXref 0.7