Changeset 28280
- Timestamp:
- 05/06/2014 05:31:12 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/ms-load.php
r28009 r28280 349 349 */ 350 350 351 // Either www or non-www is supported, not both. If a www domain is requested, 352 // query for both to provide the proper redirect. 353 $domains = array( $domain ); 354 if ( 'www.' === substr( $domain, 0, 4 ) ) { 355 $domains[] = substr( $domain, 4 ); 356 $search_domains = "'" . implode( "', '", $wpdb->_escape( $domains ) ) . "'"; 357 } 358 351 359 if ( count( $paths ) > 1 ) { 352 $paths = "'" . implode( "', '", $wpdb->_escape( $paths ) ) . "'"; 353 $sql = $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $domain ); 354 $sql .= " AND path IN ($paths) ORDER BY CHAR_LENGTH(path) DESC LIMIT 1"; 360 $search_paths = "'" . implode( "', '", $wpdb->_escape( $paths ) ) . "'"; 361 } 362 363 if ( count( $domains ) > 1 && count( $paths ) > 1 ) { 364 $site = $wpdb->get_row( "SELECT * FROM $wpdb->blogs WHERE domain IN ($search_domains) AND path IN ($search_paths) ORDER BY CHAR_LENGTH(domain) DESC, CHAR_LENGTH(path) DESC LIMIT 1" ); 365 } elseif ( count( $domains ) > 1 ) { 366 $sql = $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE path = %s", $paths[0] ); 367 $sql .= " AND domain IN ($search_domains) ORDER BY CHAR_LENGTH(domain) DESC LIMIT 1"; 368 $site = $wpdb->get_row( $sql ); 369 } elseif ( count( $paths ) > 1 ) { 370 $sql = $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $domains[0] ); 371 $sql .= " AND path IN ($search_paths) ORDER BY CHAR_LENGTH(path) DESC LIMIT 1"; 355 372 $site = $wpdb->get_row( $sql ); 356 373 } else { 357 $site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s and path = %s", $domain, $paths[0] ) );374 $site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $domains[0], $paths[0] ) ); 358 375 } 359 376 -
trunk/tests/phpunit/tests/ms.php
r27718 r28280 1226 1226 /** 1227 1227 * @ticket 27003 1228 * @ticket 27927 1228 1229 */ 1229 1230 function test_get_site_by_path() { … … 1234 1235 'make.wordpress.org/' => array( 'domain' => 'make.wordpress.org', 'path' => '/' ), 1235 1236 'make.wordpress.org/foo/' => array( 'domain' => 'make.wordpress.org', 'path' => '/foo/' ), 1237 'www.w.org/' => array( 'domain' => 'www.w.org', 'path' => '/' ), 1238 'www.w.org/foo/' => array( 'domain' => 'www.w.org', 'path' => '/foo/' ), 1239 'www.w.org/foo/bar/' => array( 'domain' => 'www.w.org', 'path' => '/foo/bar/' ), 1236 1240 ); 1237 1241 … … 1244 1248 get_site_by_path( 'wordpress.org', '/notapath/' )->blog_id ); 1245 1249 1250 $this->assertEquals( $ids['wordpress.org/'], 1251 get_site_by_path( 'www.wordpress.org', '/notapath/' )->blog_id ); 1252 1246 1253 $this->assertEquals( $ids['wordpress.org/foo/bar/'], 1247 1254 get_site_by_path( 'wordpress.org', '/foo/bar/baz/' )->blog_id ); 1248 1255 1249 1256 $this->assertEquals( $ids['wordpress.org/foo/bar/'], 1257 get_site_by_path( 'www.wordpress.org', '/foo/bar/baz/' )->blog_id ); 1258 1259 $this->assertEquals( $ids['wordpress.org/foo/bar/'], 1250 1260 get_site_by_path( 'wordpress.org', '/foo/bar/baz/', 3 )->blog_id ); 1261 1262 $this->assertEquals( $ids['wordpress.org/foo/bar/'], 1263 get_site_by_path( 'www.wordpress.org', '/foo/bar/baz/', 3 )->blog_id ); 1251 1264 1252 1265 $this->assertEquals( $ids['wordpress.org/foo/bar/'], 1253 1266 get_site_by_path( 'wordpress.org', '/foo/bar/baz/', 2 )->blog_id ); 1254 1267 1268 $this->assertEquals( $ids['wordpress.org/foo/bar/'], 1269 get_site_by_path( 'www.wordpress.org', '/foo/bar/baz/', 2 )->blog_id ); 1270 1255 1271 $this->assertEquals( $ids['wordpress.org/foo/'], 1256 1272 get_site_by_path( 'wordpress.org', '/foo/bar/baz/', 1 )->blog_id ); 1257 1273 1274 $this->assertEquals( $ids['wordpress.org/foo/'], 1275 get_site_by_path( 'www.wordpress.org', '/foo/bar/baz/', 1 )->blog_id ); 1276 1258 1277 $this->assertEquals( $ids['wordpress.org/'], 1259 1278 get_site_by_path( 'wordpress.org', '/', 0 )->blog_id ); 1260 1279 1280 $this->assertEquals( $ids['wordpress.org/'], 1281 get_site_by_path( 'www.wordpress.org', '/', 0 )->blog_id ); 1282 1261 1283 $this->assertEquals( $ids['make.wordpress.org/foo/'], 1262 1284 get_site_by_path( 'make.wordpress.org', '/foo/bar/baz/qux/', 4 )->blog_id ); 1285 1286 $this->assertEquals( $ids['make.wordpress.org/foo/'], 1287 get_site_by_path( 'www.make.wordpress.org', '/foo/bar/baz/qux/', 4 )->blog_id ); 1288 1289 $this->assertEquals( $ids['www.w.org/'], 1290 get_site_by_path( 'www.w.org', '/', 0 )->blog_id ); 1291 1292 $this->assertEquals( $ids['www.w.org/'], 1293 get_site_by_path( 'www.w.org', '/notapath/' )->blog_id ); 1294 1295 $this->assertEquals( $ids['www.w.org/foo/bar/'], 1296 get_site_by_path( 'www.w.org', '/foo/bar/baz/' )->blog_id ); 1297 1298 $this->assertEquals( $ids['www.w.org/foo/'], 1299 get_site_by_path( 'www.w.org', '/foo/bar/baz/', 1 )->blog_id ); 1300 1301 // A site installed with www will not be found by the root domain. 1302 $this->assertFalse( get_site_by_path( 'w.org', '/' ) ); 1303 $this->assertFalse( get_site_by_path( 'w.org', '/notapath/' ) ); 1304 $this->assertFalse( get_site_by_path( 'w.org', '/foo/bar/baz/' ) ); 1305 $this->assertFalse( get_site_by_path( 'w.org', '/foo/bar/baz/', 1 ) ); 1306 1307 // A site will not be found by its root domain when an invalid subdomain is requested. 1308 $this->assertFalse( get_site_by_path( 'invalid.wordpress.org', '/' ) ); 1309 $this->assertFalse( get_site_by_path( 'invalid.wordpress.org', '/foo/bar/' ) ); 1263 1310 } 1264 1311
Note: See TracChangeset
for help on using the changeset viewer.