Ticket #35791: 35791i.1.patch
File 35791i.1.patch, 11.8 KB (added by , 9 years ago) |
---|
-
wp-includes/http.php
606 606 * @param string $host 607 607 * @return bool 608 608 */ 609 609 610 function ms_allowed_http_request_hosts( $is_external, $host ) { 610 611 global $wpdb; 611 612 static $queried = array(); … … 615 616 return true; 616 617 if ( isset( $queried[ $host ] ) ) 617 618 return $queried[ $host ]; 618 $queried[ $host ] = (bool) $wpdb->get_var( $wpdb->prepare( "SELECT domain FROM $wpdb->blogs WHERE domain = %s LIMIT 1", $host ) ); 619 620 $result = get_sites( array( 'domain' => $host, 'count' => true ) ); 621 $queried[ $host ] = (bool) $result; 622 619 623 return $queried[ $host ]; 620 624 } 621 625 -
wp-includes/ms-blogs.php
468 468 } 469 469 470 470 /** 471 * 472 * Retrieve list of sites matching criteria. 473 * 474 * The defaults are as follows: 475 * 476 * @since 4.6.0 477 * 478 * @see WP_Site_Query::parse_query() 479 * 480 * @param string|array $args { 481 * Optional. Array or query string of site query parameters. Default empty. 482 * 483 * @type array $site__in Array of site IDs to include. Default empty. 484 * @type array $site__not_in Array of site IDs to exclude. Default empty. 485 * @type bool $count Whether to return a site count (true) or array of 486 * site objects (false). Default false. 487 * @type array $date_query Date query clauses to limit sites by. See WP_Date_Query. 488 * Default null. 489 * @type string $fields Site fields to return. Accepts 'ids' for site IDs 490 * only or empty for all fields. Default empty. 491 * @type int $ID Currently unused. 492 * @type int $number Maximum number of sites to retrieve. 493 * Default null (no limit). 494 * @type int $offset Number of sites to offset the query. Used to build 495 * LIMIT clause. Default 0. 496 * @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. 497 * Default: true. 498 * @type string|array $orderby Site status or array of statuses. To use 'meta_value' 499 * or 'meta_value_num', `$meta_key` must also be defined. 500 * To sort by a specific `$meta_query` clause, use that 501 * clause's array key. Accepts 'site_agent', 502 * 'site_approved', 'site_author', 503 * 'site_author_email', 'site_author_IP', 504 * 'site_author_url', 'site_content', 'site_date', 505 * 'site_date_gmt', 'blog_id', 'site_karma', 506 * 'site_parent', 'site_id', 'site_type', 507 * 'user_id', 'site__in', 'meta_value', 'meta_value_num', 508 * the value of $meta_key, and the array keys of 509 * `$meta_query`. Also accepts false, an empty array, or 510 * 'none' to disable `ORDER BY` clause. 511 * Default: 'site_date_gmt'. 512 * @type string $order How to order retrieved sites. Accepts 'ASC', 'DESC'. 513 * Default: 'DESC'. 514 * @type string $domain Limit results to those affiliated with a given network ID. 515 * Default current network id. 516 * @type array $domain__in Array of domains to include affiliated sites for. 517 * Default empty. 518 * @type array $domain__not_in Array of domains to exclude affiliated sites for. 519 * Default empty. 520 * @type string $path Limit results to those affiliated with a given network ID. 521 * Default current network id. 522 * @type array $path__in Array of paths to include affiliated sites for. 523 * Default empty. 524 * @type array $path__not_in Array of paths to exclude affiliated sites for. 525 * Default empty. 526 * @type int $network_id Limit results to those affiliated with a given network ID. 527 * Default current network id. 528 * @type array $network__in Array of network IDs to include affiliated sites for. 529 * Default empty. 530 * @type array $network__not_in Array of network IDs to exclude affiliated sites for. 531 * Default empty. 532 * @type string $search Search term(s) to retrieve matching sites for. 533 * Default empty. 534 * @type bool $update_site_cache Whether to prime the cache for site networks. 535 * Default false. 536 * 537 * @return array List of sites. 538 * */ 539 function get_sites( $args = array() ) { 540 $query = new WP_Site_Query(); 541 542 return $query->query( $args ); 543 } 544 545 546 /** 471 547 * Retrieve option value for a given blog id based on name of option. 472 548 * 473 549 * If the option does not exist or does not have a value, then the return value -
wp-includes/ms-functions.php
308 308 global $wpdb; 309 309 310 310 $domain = strtolower( $domain ); 311 $path = strtolower( $path );312 $id = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' );311 $path = strtolower( $path ); 312 $id = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' ); 313 313 314 if ( $id == -1 ) // blog does not exist 314 if ( $id == - 1 ) // blog does not exist 315 { 315 316 return 0; 316 elseif ( $id )317 } elseif ( $id ) { 317 318 return (int) $id; 319 } 318 320 319 $id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s and path = %s /* get_blog_id_from_url */", $domain, $path ) ); 321 $args = array( 'domain' => $domain, 'path' => $path, 'fields' => 'ids' ); 322 $result = get_sites( $args ); 323 $id = array_shift( $result ); 324 if ( ! $id ) { 325 wp_cache_set( md5( $domain . $path ), - 1, 'blog-id-cache' ); 320 326 321 if ( ! $id ) {322 wp_cache_set( md5( $domain . $path ), -1, 'blog-id-cache' );323 327 return 0; 324 328 } 325 329 … … 1255 1259 * @return int 1256 1260 */ 1257 1261 function domain_exists($domain, $path, $site_id = 1) { 1258 global $wpdb;1259 1262 $path = trailingslashit( $path ); 1260 $result = $wpdb->get_var( $wpdb->prepare("SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s AND site_id = %d", $domain, $path, $site_id) );1261 1263 1264 $args = array( 'path' => $path, 'domain' => $domain, 'network' => $site_id, 'number' => 1, 'fields' => 'ids' ); 1265 $result = get_sites( $args ); 1266 $site = array_shift( $result ); 1267 1262 1268 /** 1263 1269 * Filter whether a blogname is taken. 1264 1270 * 1265 1271 * @since 3.5.0 1266 1272 * 1267 * @param int|null $ resultThe blog_id if the blogname exists, null otherwise.1273 * @param int|null $site The blog_id if the blogname exists, null otherwise. 1268 1274 * @param string $domain Domain to be checked. 1269 1275 * @param string $path Path to be checked. 1270 1276 * @param int $site_id Site ID. Relevant only on multi-network installs. 1271 1277 */ 1272 return apply_filters( 'domain_exists', $ result, $domain, $path, $site_id );1278 return apply_filters( 'domain_exists', $site, $domain, $path, $site_id ); 1273 1279 } 1274 1280 1275 1281 /** … … 2252 2258 function wp_update_network_site_counts() { 2253 2259 global $wpdb; 2254 2260 2255 $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(blog_id) as c FROM $wpdb->blogs WHERE site_id = %d AND spam = '0' AND deleted = '0' and archived = '0'", $wpdb->siteid) ); 2261 $args = array( 'network_id' => $wpdb->siteid, 'spam' => 0, 'deleted' => 0, 'archived' => 0, 'count' => true ); 2262 $count = get_sites( $args ); 2263 2256 2264 update_site_option( 'blog_count', $count ); 2257 2265 } 2258 2266 … … 2432 2440 function wp_get_sites( $args = array() ) { 2433 2441 global $wpdb; 2434 2442 2435 if ( wp_is_large_network() )2436 return array();2437 2438 2443 $defaults = array( 2439 2444 'network_id' => $wpdb->siteid, 2440 2445 'public' => null, … … 2448 2453 2449 2454 $args = wp_parse_args( $args, $defaults ); 2450 2455 2451 $query = "SELECT * FROM $wpdb->blogs WHERE 1=1 "; 2456 // Make sure count is disabled. 2457 $args['count'] = false; 2452 2458 2453 if ( isset( $args['network_id'] ) && ( is_array( $args['network_id'] ) || is_numeric( $args['network_id'] ) ) ) { 2454 $network_ids = implode( ',', wp_parse_id_list( $args['network_id'] ) ); 2455 $query .= "AND site_id IN ($network_ids) "; 2459 $_sites = get_sites( $args ); 2460 $results = array(); 2461 foreach ( $_sites as $_site ) { 2462 $results[] = get_site( $_site, ARRAY_A ); 2456 2463 } 2457 2464 2458 if ( isset( $args['public'] ) ) 2459 $query .= $wpdb->prepare( "AND public = %d ", $args['public'] ); 2460 2461 if ( isset( $args['archived'] ) ) 2462 $query .= $wpdb->prepare( "AND archived = %d ", $args['archived'] ); 2463 2464 if ( isset( $args['mature'] ) ) 2465 $query .= $wpdb->prepare( "AND mature = %d ", $args['mature'] ); 2466 2467 if ( isset( $args['spam'] ) ) 2468 $query .= $wpdb->prepare( "AND spam = %d ", $args['spam'] ); 2469 2470 if ( isset( $args['deleted'] ) ) 2471 $query .= $wpdb->prepare( "AND deleted = %d ", $args['deleted'] ); 2472 2473 if ( isset( $args['limit'] ) && $args['limit'] ) { 2474 if ( isset( $args['offset'] ) && $args['offset'] ) 2475 $query .= $wpdb->prepare( "LIMIT %d , %d ", $args['offset'], $args['limit'] ); 2476 else 2477 $query .= $wpdb->prepare( "LIMIT %d ", $args['limit'] ); 2478 } 2479 2480 $site_results = $wpdb->get_results( $query, ARRAY_A ); 2481 2482 return $site_results; 2465 return $results; 2483 2466 } 2484 2467 2485 2468 /** -
wp-includes/ms-load.php
231 231 $domains = array( $domain ); 232 232 if ( 'www.' === substr( $domain, 0, 4 ) ) { 233 233 $domains[] = substr( $domain, 4 ); 234 $search_domains = "'" . implode( "', '", $wpdb->_escape( $domains ) ) . "'";235 234 } 236 235 237 if ( count( $paths ) > 1 ) {238 $search_paths = "'" . implode( "', '", $wpdb->_escape( $paths ) ) . "'";239 }240 236 237 $args = array( 'path__in' => $path, 'domain__in' => $domains, 'number' => 1 ); 238 241 239 if ( count( $domains ) > 1 && count( $paths ) > 1 ) { 242 $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" ); 240 $args['orderby'] = 'domain_length path_length'; 241 $args['order'] = 'DESC DESC'; 243 242 } elseif ( count( $domains ) > 1 ) { 244 $sql = $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE path = %s", $paths[0] ); 245 $sql .= " AND domain IN ($search_domains) ORDER BY CHAR_LENGTH(domain) DESC LIMIT 1"; 246 $site = $wpdb->get_row( $sql ); 243 $args['orderby'] = 'domain_length'; 244 $args['order'] = 'DESC'; 247 245 } elseif ( count( $paths ) > 1 ) { 248 $sql = $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $domains[0] ); 249 $sql .= " AND path IN ($search_paths) ORDER BY CHAR_LENGTH(path) DESC LIMIT 1"; 250 $site = $wpdb->get_row( $sql ); 251 } else { 252 $site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $domains[0], $paths[0] ) ); 246 $args['orderby'] = 'path_length'; 247 $args['order'] = 'DESC'; 253 248 } 254 249 250 $result = get_sites( $args ); 251 $site = array_shift( $result ); 255 252 if ( $site ) { 256 253 // @todo get_blog_details() 257 254 return $site;