root/tags/1.3/wpmu-settings.php

Revision 1134, 8.6 kB (checked in by donncha, 1 year ago)

Don't use $wpmuBaseTablePrefix any more, use $wpdb->base_prefix, props lunabyte, fixes #479

Line 
1 <?php
2 if( $current_site && $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     } else {
16         die( 'WPMU only works without the port number in the URL.' );
17     }
18 }
19 $domain = preg_replace('/:.*$/', '', $domain); // Strip ports
20 if( substr( $domain, -1 ) == '.' )
21     $domain = substr( $domain, 0, -1 );
22
23 $path = preg_replace( '|([a-z0-9-]+.php.*)|', '', $_SERVER['REQUEST_URI'] );
24 $path = str_replace ( '/wp-admin/', '/', $path );
25 $path = preg_replace( '|(/[a-z0-9-]+?/).*|', '$1', $path );
26
27 function wpmu_current_site() {
28     global $wpdb, $current_site, $domain, $path, $sites;
29     $path = substr( $_SERVER[ 'REQUEST_URI' ], 0, 1 + strpos( $_SERVER[ 'REQUEST_URI' ], '/', 1 ) );
30     if( constant( 'VHOST' ) == 'yes' ) {
31         $current_site = $wpdb->get_row( "SELECT * FROM $wpdb->site WHERE domain = '$domain' AND path='$path'" );
32         if( $current_site != null )
33             return $current_site;
34         $current_site = $wpdb->get_row( "SELECT * FROM $wpdb->site WHERE domain = '$domain' AND path='/'" );
35         if( $current_site != null ) {
36             $path = '/';
37             return $current_site;
38         }
39         $sitedomain = substr( $domain, 1 + strpos( $domain, '.' ) );
40         $current_site = $wpdb->get_row( "SELECT * FROM $wpdb->site WHERE domain = '$sitedomain' AND path='$path'" );
41         if( $current_site != null )
42             return $current_site;
43         $current_site = $wpdb->get_row( "SELECT * FROM $wpdb->site WHERE domain = '$sitedomain' AND path='/'" );
44         if( $current_site == null && defined( "WP_INSTALLING" ) == false ) {
45             if( count( $sites ) == 1 ) {
46                 $current_site = $sites[0];
47                 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>" );
48             } else {
49                 die( "No WPMU site defined on this host. If you are the owner of this site, please check <a href='http://trac.mu.wordpress.org/wiki/DebuggingWpmu'>Debugging WPMU</a> for further assistance." );
50             }
51         } else {
52             $path = '/';
53         }
54     } else {
55         $current_site = $wpdb->get_row( "SELECT * FROM $wpdb->site WHERE domain = '$domain' AND path='$path'" );
56         if( $current_site != null )
57             return $current_site;
58         $current_site = $wpdb->get_row( "SELECT * FROM $wpdb->site WHERE domain = '$domain' AND path='/'" );
59         if( $current_site == null && defined( "WP_INSTALLING" ) == false ) {
60             if( count( $sites ) == 1 ) {
61                 $current_site = $sites[0];
62                 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>" );
63             } else {
64                 die( "No WPMU site defined on this host. If you are the owner of this site, please check <a href='http://trac.mu.wordpress.org/wiki/DebuggingWpmu'>Debugging WPMU</a> for further assistance." );
65             }
66         } else {
67             $path = '/';
68         }
69     }
70     return $current_site;
71 }
72
73 $wpdb->hide_errors();
74 $sites = $wpdb->get_results( "SELECT * FROM $wpdb->site" ); // usually only one site
75 if( count( $sites ) == 1 ) {
76     $current_site = $sites[0];
77     $path = $current_site->path;
78 } else {
79     $current_site = wpmu_current_site();
80 }
81
82
83 if( constant( 'VHOST' ) == 'yes' ) {
84     $current_blog = $wpdb->get_row("SELECT * FROM $wpdb->blogs WHERE domain = '$domain'");
85     if( $current_blog != null ) {
86         $current_site = $wpdb->get_row("SELECT * FROM $wpdb->site WHERE id='{$current_blog->site_id}'");
87     } else {
88         $blogname = substr( $domain, 0, strpos( $domain, '.' ) );
89     }
90 } else {
91     $blogname = htmlspecialchars( substr( $_SERVER[ 'REQUEST_URI' ], strlen( $path ) ) );
92     if( strpos( $blogname, '/' ) )
93         $blogname = substr( $blogname, 0, strpos( $blogname, '/' ) );
94     if( strpos( " ".$blogname, '?' ) )
95         $blogname = substr( $blogname, 0, strpos( $blogname, '?' ) );
96     $blognames = array( 'page', 'comments', 'blog', 'wp-admin', 'wp-includes', 'wp-content', 'files', 'feed' );
97     if( $blogname == '' || in_array( $blogname, $blognames ) || is_file( $blogname ) || is_blogname_page( $blogname ) ) {
98         $current_blog = $wpdb->get_row("SELECT * FROM $wpdb->blogs WHERE domain = '$domain' AND path = '$path'");
99     } else {
100         $current_blog = $wpdb->get_row("SELECT * FROM $wpdb->blogs WHERE domain = '$domain' AND path = '{$path}{$blogname}/'");
101     }
102 }
103
104 if( defined( "WP_INSTALLING" ) == false ) {
105     if( $current_site && $current_blog == null ) {
106         header( "Location: http://{$current_site->domain}{$current_site->path}wp-signup.php?new=" . urlencode( $blogname ) );
107         die();
108     }
109     if( $current_blog == false || $current_site == false )
110         is_installed();
111 }
112
113 function is_blogname_page( $blogname ) {
114     global $wpdb, $table_prefix, $domain, $path;
115
116     $blog_id = $wpdb->get_var("SELECT blog_id FROM $wpdb->blogs WHERE domain = '$domain' AND path = '$path'");
117
118     // is the request for a page of the main blog? We need to cache this information somewhere to save a request
119     $pages = $wpdb->get_col( "SELECT LOWER(post_name) FROM {$table_prefix}{$blog_id}_posts WHERE post_type='page'" );
120
121     if( is_array( $pages ) == false )
122         return false;
123
124     if( in_array( strtolower( $blogname ), $pages ) ) {
125         return true;
126     } else {
127         return false;
128     }
129 }
130
131 $blog_id = $current_blog->blog_id;
132 $public  = $current_blog->public;
133 $site_id = $current_blog->site_id;
134
135 if( $site_id == 0 )
136     $site_id = 1;
137
138 $current_site->site_name = $wpdb->get_var( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = '$site_id' AND meta_key = 'site_name'" );
139 if( $current_site->site_name == null )
140     $current_site->site_name = ucfirst( $current_site->domain );
141
142 if( $blog_id == false ) {
143     // no blog found, are we installing? Check if the table exists.
144     if ( defined('WP_INSTALLING') ) {
145     $query = "SELECT blog_id FROM ".$wpdb->blogs." limit 0,1";
146     $blog_id = $wpdb->get_var( $query );
147     if( $blog_id == false ) {
148         // table doesn't exist. This is the first blog
149         $blog_id = 1;
150     } else {
151         // table exists
152         // don't create record at this stage. we're obviously installing so it doesn't matter what the table vars below are like.
153         // default to using the "main" blog.
154         $blog_id = 1;
155     }
156     } else {
157     $check = $wpdb->get_results( "SELECT * FROM $wpdb->site" );
158     if( $check == false ) {
159         $msg = ': DB Tables Missing';
160     } else {
161         $msg = '';
162     }
163     die( "No Blog by that name on this system." . $msg );
164     }
165 }
166
167 $wpdb->show_errors();
168
169 if( '0' == $current_blog->public ) {
170     // This just means the blog shouldn't show up in google, etc. Only to registered members
171 }
172
173 function is_installed() {
174     global $wpdb, $domain, $path;
175     $base = stripslashes( $base );
176     if( defined( "WP_INSTALLING" ) == false ) {
177         $check = $wpdb->get_results( "SELECT * FROM $wpdb->site" );
178         $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 />";
179         if( $check == false ) {
180             $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 />";
181         } else {
182             $msg .= '<strong>Could Not Find Blog!</strong><br />';
183             $msg .= "Searched for <em>" . $domain . $path . "</em> in " . DB_NAME . "::" . $wpdb->blogs . " table. Is that right?<br />";
184         }
185         $msg .= "<br />\n<h1>What do I do now?</h1>";
186         $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 />";
187         $msg .= "If you're still stuck with this message, then check that your database contains the following tables:<ul>
188             <li> $wpdb->blogs </li>
189             <li> $wpdb->users </li>
190             <li> $wpdb->usermeta </li>
191             <li> $wpdb->site </li>
192             <li> $wpdb->sitemeta </li>
193             <li> $wpdb->sitecategories </li>
194             </ul>";
195         $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://trac.mu.wordpress.org/wiki/DebuggingWpmu'>WPMU bug reporting guidelines</a>!<br /><br />";
196         if( is_file( 'release-info.txt' ) ) {
197             $msg .= 'Your bug report must include the following text: "';
198             $info = file( 'release-info.txt' );
199             $msg .= $info[ 4 ] . '"';
200         }
201
202         die( "<h1>Fatal Error</h1> " . $msg );
203     }
204 }
205
206 $table_prefix = $table_prefix . $blog_id . '_';
207
208 ?>
209
Note: See TracBrowser for help on using the browser.