root/tags/release-1.0/wpmu-settings.php

Revision 782, 8.3 kB (checked in by donncha, 2 years ago)

Strip "." at the end of hostname. (fixes #156)

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