Make WordPress Core

Ticket #27927: 27927.2.diff

File 27927.2.diff, 1.9 KB (added by jeremyfelt, 11 years ago)
  • src/wp-includes/ms-load.php

     
    348348         * then cache whether we can just always ignore paths.
    349349         */
    350350
     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
    351359        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";
    355368                $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";
     372                $site = $wpdb->get_row( $sql );
    356373        } 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] ) );
    358375        }
    359376
    360377        if ( $site ) {