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

Revision 600, 5.6 kB (checked in by donncha, 2 years ago)

Check if final part of $path is a filename.
This fixes problems with logging in using subdirs

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 = htmlspecialchars( substr( $_SERVER[ 'REQUEST_URI' ], strlen( $path ) ) );
60     if( strpos( $blogname, '/' ) )
61         $blogname = substr( $blogname, 0, strpos( $blogname, '/' ) );
62     if( $blogname == '' || $blogname == 'blog' || $blogname == 'wp-admin' || $blogname == 'files' || $blogname == 'feed' || is_file( $blogname ) ) {
63         $current_blog = $wpdb->get_row("SELECT * FROM $wpdb->blogs WHERE domain = '$domain' AND path = '$path'");
64     } else {
65         $current_blog = $wpdb->get_row("SELECT * FROM $wpdb->blogs WHERE domain = '$domain' AND path = '{$path}{$blogname}/'");
66     }
67 }
68
69 if( defined( "WP_INSTALLING" ) == false ) {
70     if( $current_blog == false || $current_site == false )
71         is_installed();
72 }
73
74 $blog_id = $current_blog->blog_id;
75 $public  = $current_blog->public;
76 $site_id = $current_blog->site_id;
77
78 if( $site_id == 0 )
79     $site_id = 1;
80
81 $current_site->site_name = $wpdb->get_var( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = '$site_id' AND meta_key = 'site_name'" );
82 if( $current_site->site_name == null )
83     $current_site->site_name = ucfirst( $current_site->domain );
84
85 if( $blog_id == false ) {
86     // no blog found, are we installing? Check if the table exists.
87     if ( defined('WP_INSTALLING') ) {
88     $query = "SELECT blog_id FROM ".$wpdb->blogs." limit 0,1";
89     $blog_id = $wpdb->get_var( $query );
90     if( $blog_id == false ) {
91         // table doesn't exist. This is the first blog
92         $blog_id = 1;
93     } else {
94         // table exists
95         // don't create record at this stage. we're obviously installing so it doesn't matter what the table vars below are like.
96         // default to using the "main" blog.
97         $blog_id = 1;
98     }
99     } else {
100     $check = $wpdb->get_results( "SELECT * FROM $wpdb->site" );
101     if( $check == false ) {
102         $msg = ': DB Tables Missing';
103     } else {
104         $msg = '';
105     }
106     die( "No Blog by that name on this system." . $msg );
107     }
108 }
109
110 $wpdb->show_errors();
111
112 if( '0' == $current_blog->public ) {
113     // This just means the blog shouldn't show up in google, etc. Only to registered members
114 }
115
116 if( $current_blog->archived == '1' ) {
117     die( 'This blog has been archived or suspended.' );
118 }
119
120 if( $current_blog->spam == '1' ) {
121     die( 'This blog has been archived or suspended.' );
122 }
123
124 function is_installed() {
125     global $wpdb, $domain, $path;
126     $base = stripslashes( $base );
127     if( defined( "WP_INSTALLING" ) == false ) {
128         $check = $wpdb->get_results( "SELECT * FROM $wpdb->site" );
129         if( $check == false ) {
130             $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 />';
131         } else {
132             $msg = '<strong>Could Not Find Blog!</strong><br />';
133             $msg .= "Searched for <em>" . $domain . $path . "</em> in " . DB_NAME . "::" . $wpdb->blogs . " table. Is that right?<br />";
134         }
135         $msg .= "Please check that your database contains the following tables:<ul>
136             <li> $wpdb->blogs </li>
137             <li> $wpdb->users </li>
138             <li> $wpdb->usermeta </li>
139             <li> $wpdb->site </li>
140             <li> $wpdb->sitemeta </li>
141             <li> $wpdb->sitecategories </li>
142             </ul>";
143         $msg .= "If you suspect a problem please report it to <a href='http://mu.wordpress.org/forums/'>support forums</a>!";
144         die( "<h1>Fatal Error</h1> " . $msg );
145     }
146 }
147
148 $table_prefix = $table_prefix . $blog_id . '_';
149
150 ?>
151
Note: See TracBrowser for help on using the browser.