| 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 ( substr( $domain, 0, 4 ) == 'www.' ) { |
| 355 | $domains[] = substr( $domain, 4 ); |
| 356 | $search_domains = "'" . implode( "', '", $wpdb->_escape( $domains ) ) . "'"; |
| 357 | } |
| 358 | |
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"; |