root/tags/1_0-rc2/wpmu-settings.php

Revision 625, 6.5 kB (checked in by donncha, 2 years ago)

Added "wp-content" to the ignore list. Should allow php scripts in the plugins dir to be called directly

Line 
1 <?php
2 if( defined( 'ABSPATH' ) == false )
3     die();
4
5 $wpmuBaseTablePrefix = $table_prefix;
6
7 $domain = addslashes( $_SERVER['HTTP_HOST'] );
8 if( substr( $domain, 0, 4 ) == 'www.' )
9     $domain = substr( $domain, 4 );
10 $domain = preg_replace('/:.*$/', '', $domain); // Strip ports
11
12 $path = preg_replace( '|([a-z0-9-]+.php.*)|', '', $_SERVER['REQUEST_URI'] );
13 $path = str_replace ( '/wp-admin/', '/', $path );
14 $path = preg_replace( '|(/[a-z0-9-]+?/).*|', '$1', $path );
15
16 $wpdb->hide_errors();
17
18 #$sites = $wpdb->get_results( "SELECT * FROM $wpdb->site" );
19 #if( count( $sites ) == 1 ) {
20     #$current_site = $sites[0];
21 #}
22     
23 if( isset( $current_site ) == false ) {
24     $path = substr( $_SERVER[ 'REQUEST_URI' ], 0, 1 + strpos( $_SERVER[ 'REQUEST_URI' ], '/', 1 ) );
25     if( constant( 'VHOST' ) == 'yes' ) {
26         $current_site = $wpdb->get_row( "SELECT * FROM $wpdb->site WHERE domain = '$domain' AND path='$path'" );
27         if( $current_site == null ) {
28             $current_site = $wpdb->get_row( "SELECT * FROM $wpdb->site WHERE domain = '$domain' AND path='/'" );
29             if( $current_site == null ) {
30                 $sitedomain = substr( $domain, 1 + strpos( $domain, '.' ) );
31                 $current_site = $wpdb->get_row( "SELECT * FROM $wpdb->site WHERE domain = '$sitedomain' AND path='$path'" );
32                 if( $current_site == null ) {
33                     $path = '/';
34                     $current_site = $wpdb->get_row( "SELECT * FROM $wpdb->site WHERE domain = '$sitedomain' AND path='$path'" );
35                     if( $current_site == null && defined( "WP_INSTALLING" ) == false )
36                         die( "No WPMU site defined on this host." );
37                 }
38             } else {
39                 $path = '/';
40             }
41         }
42     } else {
43         $current_site = $wpdb->get_row( "SELECT * FROM $wpdb->site WHERE domain = '$domain' AND path='$path'" );
44         if( $current_site == null ) {
45             $path = '/';
46             $current_site = $wpdb->get_row( "SELECT * FROM $wpdb->site WHERE domain = '$domain' AND path='$path'" );
47             if( $current_site == null && defined( "WP_INSTALLING" ) == false )
48                 die( "No WPMU site defined on this host." );
49         }
50     }
51 }
52
53
54 if( constant( 'VHOST' ) == 'yes' ) {
55     $current_blog = $wpdb->get_row("SELECT * FROM $wpdb->blogs WHERE domain = '$domain'");
56     if( $current_blog != null ) {
57         $current_site = $wpdb->get_row("SELECT * FROM $wpdb->site WHERE id='{$current_blog->site_id}'");
58     } else {
59         $blogname = substr( $domain, 0, strpos( $domain, '.' ) );
60     }
61 } else {
62     $blogname = htmlspecialchars( substr( $_SERVER[ 'REQUEST_URI' ], strlen( $path ) ) );
63     if( strpos( $blogname, '/' ) )
64         $blogname = substr( $blogname, 0, strpos( $blogname, '/' ) );
65     if( strpos( $blogname, '?' ) )
66         $blogname = substr( $blogname, 0, strpos( $blogname, '?' ) );
67     $blognames = array( 'blog', 'wp-admin', 'wp-includes', 'wp-content', 'files', 'feed' );
68     if( $blogname == '' || in_array( $blogname, $blognames ) || is_file( $blogname ) ) {
69         $current_blog = $wpdb->get_row("SELECT * FROM $wpdb->blogs WHERE domain = '$domain' AND path = '$path'");
70     } else {
71         $current_blog = $wpdb->get_row("SELECT * FROM $wpdb->blogs WHERE domain = '$domain' AND path = '{$path}{$blogname}/'");
72     }
73 }
74
75 if( defined( "WP_INSTALLING" ) == false ) {
76     if( $current_site && $current_blog == null ) {
77         header( "Location: http://{$current_site->domain}{$current_site->path}wp-signup.php?new=" . urlencode( $blogname ) );
78         die();
79     }
80     if( $current_blog == false || $current_site == false )
81         is_installed();
82 }
83
84 $blog_id = $current_blog->blog_id;
85 $public  = $current_blog->public;
86 $site_id = $current_blog->site_id;
87
88 if( $site_id == 0 )
89     $site_id = 1;
90
91 $current_site->site_name = $wpdb->get_var( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = '$site_id' AND meta_key = 'site_name'" );
92 if( $current_site->site_name == null )
93     $current_site->site_name = ucfirst( $current_site->domain );
94
95 if( $blog_id == false ) {
96     // no blog found, are we installing? Check if the table exists.
97     if ( defined('WP_INSTALLING') ) {
98     $query = "SELECT blog_id FROM ".$wpdb->blogs." limit 0,1";
99     $blog_id = $wpdb->get_var( $query );
100     if( $blog_id == false ) {
101         // table doesn't exist. This is the first blog
102         $blog_id = 1;
103     } else {
104         // table exists
105         // don't create record at this stage. we're obviously installing so it doesn't matter what the table vars below are like.
106         // default to using the "main" blog.
107         $blog_id = 1;
108     }
109     } else {
110     $check = $wpdb->get_results( "SELECT * FROM $wpdb->site" );
111     if( $check == false ) {
112         $msg = ': DB Tables Missing';
113     } else {
114         $msg = '';
115     }
116     die( "No Blog by that name on this system." . $msg );
117     }
118 }
119
120 $wpdb->show_errors();
121
122 if( '0' == $current_blog->public ) {
123     // This just means the blog shouldn't show up in google, etc. Only to registered members
124 }
125
126 if( $current_blog->archived == '1' ) {
127     die( 'This blog has been archived or suspended.' );
128 }
129
130 if( $current_blog->spam == '1' ) {
131     die( 'This blog has been archived or suspended.' );
132 }
133
134 function is_installed() {
135     global $wpdb, $domain, $path;
136     $base = stripslashes( $base );
137     if( defined( "WP_INSTALLING" ) == false ) {
138         $check = $wpdb->get_results( "SELECT * FROM $wpdb->site" );
139         if( $check == false ) {
140             $msg = '<strong>Database Tables Missing.</strong><br /> The table <em>' . DB_NAME . '::' . $wpdb->site . '</em> is missing. Delete the .htaccess file and run the installer again!<br />';
141         } else {
142             $msg = '<strong>Could Not Find Blog!</strong><br />';
143             $msg .= "Searched for <em>" . $domain . $path . "</em> in " . DB_NAME . "::" . $wpdb->blogs . " table. Is that right?<br />";
144         }
145         $msg .= "<br />\n<h1>What do I do now?</h1>";
146         $msg .= "Read the <a target='_blank' href='http://trac.mu.wordpress.org/wiki/DebuggingWpmu'>bug report</a> page. Some of the guidelines there may help you figure out what went wrong.<br />";
147         $msg .= "If you're still stuck with this message, then check that your database contains the following tables:<ul>
148             <li> $wpdb->blogs </li>
149             <li> $wpdb->users </li>
150             <li> $wpdb->usermeta </li>
151             <li> $wpdb->site </li>
152             <li> $wpdb->sitemeta </li>
153             <li> $wpdb->sitecategories </li>
154             </ul>";
155         $msg .= "If you suspect a problem please report it to <a href='http://mu.wordpress.org/forums/'>support forums</a> but follow the <a href='http://trac.mu.wordpress.org/wiki/DebuggingWpmu'>guidelines</a>!<br /><br />";
156         if( is_file( 'release-info.txt' ) ) {
157             $msg .= 'Your bug report must include the following text: "';
158             $info = file( 'release-info.txt' );
159             $msg .= $info[ 4 ] . '"';
160         }
161
162         die( "<h1>Fatal Error</h1> " . $msg );
163     }
164 }
165
166 $table_prefix = $table_prefix . $blog_id . '_';
167
168 ?>
169
Note: See TracBrowser for help on using the browser.