[ Index ]

PHP Cross Reference of Wordpress MU 2.7

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 wpmu_current_site() {
  31      global $wpdb, $current_site, $domain, $path, $sites;
  32      if( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) {
  33          $current_site->id = 1;
  34          $current_site->domain = DOMAIN_CURRENT_SITE;
  35          $current_site->path   = $path = PATH_CURRENT_SITE;
  36          if( defined( 'BLOGID_CURRENT_SITE' ) )
  37              $current_site->blog_id = BLOGID_CURRENT_SITE;
  38          return $current_site;
  39      }
  40  
  41      $current_site = wp_cache_get( "current_site", "site-options" );
  42      if( $current_site )
  43          return $current_site;
  44          
  45      $wpdb->suppress_errors();
  46      $sites = $wpdb->get_results( "SELECT * FROM $wpdb->site" ); // usually only one site

  47      if( count( $sites ) == 1 ) {
  48          $current_site = $sites[0];
  49          $path = $current_site->path;
  50          $current_site->blog_id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} WHERE domain='{$current_site->domain}' AND path='{$current_site->path}'" );
  51          wp_cache_set( "current_site", $current_site, "site-options" );
  52          return $current_site;
  53      }
  54      $path = substr( $_SERVER[ 'REQUEST_URI' ], 0, 1 + strpos( $_SERVER[ 'REQUEST_URI' ], '/', 1 ) );
  55      if( constant( 'VHOST' ) == 'yes' ) {
  56          $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path) );
  57          if( $current_site != null )
  58              return $current_site;
  59          $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain) );
  60          if( $current_site != null ) {
  61              $path = '/';
  62              return $current_site;
  63          }
  64  
  65          $sitedomain = substr( $domain, 1 + strpos( $domain, '.' ) );
  66          $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path) );
  67          if( $current_site != null )
  68              return $current_site;
  69          $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $sitedomain) );
  70          if( $current_site == null && defined( "WP_INSTALLING" ) == false ) {
  71              if( count( $sites ) == 1 ) {
  72                  $current_site = $sites[0];
  73                  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>" );
  74              } else {
  75                  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." );
  76              }
  77          } else {
  78              $path = '/';
  79          }
  80      } else {
  81          $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path) );
  82          if( $current_site != null )
  83              return $current_site;
  84          $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain) );
  85          if( $current_site == null && defined( "WP_INSTALLING" ) == false ) {
  86              if( count( $sites ) == 1 ) {
  87                  $current_site = $sites[0];
  88                  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>" );
  89              } else {
  90                  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." );
  91              }
  92          } else {
  93              $path = '/';
  94          }
  95      }
  96      return $current_site;
  97  }
  98  
  99  $current_site = wpmu_current_site();
 100  if( !isset( $current_site->blog_id ) )
 101      $current_site->blog_id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} WHERE domain='{$current_site->domain}' AND path='{$current_site->path}'" );
 102  
 103  if( constant( 'VHOST' ) == 'yes' ) {
 104      $current_blog = wp_cache_get( 'current_blog_' . $domain, 'site-options' );
 105      if( !$current_blog ) {
 106          $current_blog = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE domain = %s", $domain) );
 107          if( $current_blog )
 108              wp_cache_set( 'current_blog_' . $domain, $current_blog, 'site-options' );
 109      }
 110      if( $current_blog != null && $current_blog->site_id != $current_site->id ) {
 111          $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE id = %d", $current_blog->site_id) );
 112      } else {
 113          $blogname = substr( $domain, 0, strpos( $domain, '.' ) );
 114      }
 115  } else {
 116      $blogname = htmlspecialchars( substr( $_SERVER[ 'REQUEST_URI' ], strlen( $path ) ) );
 117      if( strpos( $blogname, '/' ) )
 118          $blogname = substr( $blogname, 0, strpos( $blogname, '/' ) );
 119      if( strpos( " ".$blogname, '?' ) )
 120          $blogname = substr( $blogname, 0, strpos( $blogname, '?' ) );
 121      $blognames = array( 'page', 'comments', 'blog', 'wp-admin', 'wp-includes', 'wp-content', 'files', 'feed' );
 122      if( $blogname == '' || in_array( $blogname, $blognames ) || is_file( $blogname ) || is_blogname_page( $blogname ) ) {
 123          $current_blog = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $domain, $path) );
 124      } else {
 125          $current_blog = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $domain, $path.$blogname.'/') );
 126      }
 127  }
 128  
 129  if( defined( "WP_INSTALLING" ) == false && constant( 'VHOST' ) == 'yes' && !is_object( $current_blog ) ) {
 130      if( defined( 'NOBLOGREDIRECT' ) ) {
 131          header( "Location: " . constant( 'NOBLOGREDIRECT' ) );
 132          die();
 133      } else {
 134          if( constant( 'VHOST' ) == 'yes' ) {
 135              header( "Location: http://" . $current_site->domain . $current_site->path . "wp-signup.php?new=" . str_replace( '.' . $current_site->domain, '', $domain ) );
 136          } else {
 137              header( "Location: http://" . $current_site->domain . $current_site->path . "wp-signup.php?new=" . str_replace( '/', '', $_SERVER[ 'REQUEST_URI' ] ) );
 138          }
 139          die();
 140      }
 141  
 142  }
 143  
 144  if( defined( "WP_INSTALLING" ) == false ) {
 145      if( $current_site && $current_blog == null ) {
 146          $current_blog = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $current_site->domain, $current_site->path) );
 147      }
 148      if( $current_blog == false || $current_site == false )
 149          is_installed();
 150  }
 151  
 152  function is_blogname_page( $blogname ) {
 153      global $wpdb, $table_prefix, $domain, $path;
 154  
 155      $blog_id = $wpdb->get_var( $wpdb->prepare("SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s", $domain, $path) );
 156  
 157      // is the request for a page of the main blog? We need to cache this information somewhere to save a request

 158      $pages = $wpdb->get_col( "SELECT LOWER(post_name) FROM {$table_prefix}{$blog_id}_posts WHERE post_type='page'" ); 
 159  
 160      if( is_array( $pages ) == false ) 
 161          return false;
 162  
 163      if( in_array( strtolower( $blogname ), $pages ) ) {
 164          return true;
 165      } else {
 166          return false;
 167      }
 168  }
 169  
 170  $blog_id = $current_blog->blog_id;
 171  $public  = $current_blog->public;
 172  
 173  if( $current_blog->site_id == 0 || $current_blog->site_id == '' )
 174      $current_blog->site_id = 1;
 175  $site_id = $current_blog->site_id;
 176  
 177  
 178  $current_site->site_name = $wpdb->get_var( $wpdb->prepare("SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = %d AND meta_key = 'site_name'", $site_id) );
 179  if( $current_site->site_name == null )
 180      $current_site->site_name = ucfirst( $current_site->domain );
 181  
 182  if( $blog_id == false ) {
 183      // no blog found, are we installing? Check if the table exists.

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

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

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

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

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

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


Generated: Thu Mar 5 12:05:07 2009 Cross-referenced by PHPXref 0.7