Make WordPress Core

Ticket #20835: 20835.diff

File 20835.diff, 7.8 KB (added by nacin, 14 years ago)
  • wp-admin/includes/class-wp-ms-sites-list-table.php

     
    2929                $pagenum = $this->get_pagenum();
    3030
    3131                $s = isset( $_REQUEST['s'] ) ? stripslashes( trim( $_REQUEST[ 's' ] ) ) : '';
    32                 $wild = '';
    33                 if ( false !== strpos($s, '*') ) {
    34                         $wild = '%';
    35                         $s = trim($s, '*');
    36                 }
    3732
    38                 $like_s = esc_sql( like_escape( $s ) );
    39 
    4033                // If the network is large and a search is not being performed, show only the latest blogs with no paging in order
    4134                // to avoid expensive count queries.
    4235                if ( !$s && wp_is_large_network() ) {
     
    4639                                $_GET['order'] = $_REQUEST['order'] = 'DESC';
    4740                }
    4841
    49                 $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' ";
     42                if ( $s )
     43                        $query = self::get_search_sql( $s );
     44                else
     45                        $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' ";
    5046
    51                 if ( empty($s) ) {
    52                         // Nothing to do.
    53                 } elseif ( preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $s ) ||
    54                                         preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) ||
    55                                         preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) ||
    56                                         preg_match( '/^[0-9]{1,3}\.$/', $s ) ) {
    57                         // IPv4 address
    58                         $reg_blog_ids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE ( '{$like_s}$wild' )" );
    59 
    60                         if ( !$reg_blog_ids )
    61                                 $reg_blog_ids = array( 0 );
    62 
    63                         $query = "SELECT *
    64                                 FROM {$wpdb->blogs}
    65                                 WHERE site_id = '{$wpdb->siteid}'
    66                                 AND {$wpdb->blogs}.blog_id IN (" . implode( ', ', $reg_blog_ids ) . ")";
    67                 } else {
    68                         if ( is_numeric($s) && empty( $wild ) ) {
    69                                 $query .= " AND ( {$wpdb->blogs}.blog_id = '{$like_s}' )";
    70                         } elseif ( is_subdomain_install() ) {
    71                                 $blog_s = str_replace( '.' . $current_site->domain, '', $like_s );
    72                                 $blog_s .= $wild . '.' . $current_site->domain;
    73                                 $query .= " AND ( {$wpdb->blogs}.domain LIKE '$blog_s' ) ";
    74                         } else {
    75                                 if ( $like_s != trim('/', $current_site->path) )
    76                                         $blog_s = $current_site->path . $like_s . $wild . '/';
    77                                 else
    78                                         $blog_s = $like_s;
    79                                 $query .= " AND  ( {$wpdb->blogs}.path LIKE '$blog_s' )";
    80                         }
    81                 }
    82 
    8347                $order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : '';
    8448                if ( $order_by == 'registered' ) {
    8549                        $query .= ' ORDER BY registered ';
     
    201165                        }
    202166                        echo "<tr class='$class'>";
    203167
    204                         $blogname = ( is_subdomain_install() ) ? str_replace( '.'.$current_site->domain, '', $blog['domain'] ) : $blog['path'];
     168                        $blogname = is_subdomain_install() ? str_replace( '.' . $current_site->domain, '', $blog['domain'] ) : $blog['path'];
    205169
    206170                        list( $columns, $hidden ) = $this->get_column_info();
    207171
     
    336300                        <?php
    337301                }
    338302        }
     303
     304        static function get_search_sql( $s ) {
     305                global $wpdb, $current_site;
     306
     307                $wild = '';
     308                if ( false !== strpos($s, '*') ) {
     309                        $wild = '%';
     310                        $s = trim($s, '*');
     311                }
     312
     313                $like_s = esc_sql( like_escape( $s ) );
     314
     315                if ( preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $s ) ||
     316                                        preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) ||
     317                                        preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) ||
     318                                        preg_match( '/^[0-9]{1,3}\.$/', $s ) ) {
     319                        // IPv4 address
     320                        $reg_blog_ids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE ( '{$like_s}$wild' )" );
     321
     322                        if ( !$reg_blog_ids )
     323                                $reg_blog_ids = array( 0 );
     324
     325                        return "SELECT *
     326                                FROM {$wpdb->blogs}
     327                                WHERE site_id = '{$wpdb->siteid}'
     328                                AND {$wpdb->blogs}.blog_id IN (" . implode( ', ', $reg_blog_ids ) . ")";
     329                }
     330       
     331                $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' ";
     332
     333                if ( is_numeric($s) && empty( $wild ) ) {
     334                        $query .= " AND ( {$wpdb->blogs}.blog_id = '{$like_s}' )";
     335                } elseif ( is_subdomain_install() ) {
     336                        $blog_s = str_replace( '.' . $current_site->domain, '', $like_s );
     337                        $blog_s .= $wild . '.' . $current_site->domain;
     338                        $query .= " AND ( {$wpdb->blogs}.domain LIKE '$blog_s' ) ";
     339                } else {
     340                        // In a subdirectory install, trim off http://example.com and example.com from the start.
     341                        if ( 0 === strpos( $like_s, 'http://' ) || 0 === strpos( $like_s, 'https://' ) )
     342                                $like_s = str_replace( array( 'http://' . $current_site->domain, 'https://' . $current_site->domain ), '', $like_s );
     343                        elseif ( 0 === strpos( $like_s, $current_site->domain ) )
     344                                $like_s = substr( $like_s, strlen( $current_site->domain ) );
     345
     346                        // If we're missing the network's path, we'll need to add it.
     347                        if ( 0 !== strpos( ltrim( $like_s . '/', '/' ), ltrim( $current_site->path, '/' ) ) )
     348                                $blog_s = $current_site->path . $like_s . $wild;
     349                        // And this allows for search strings that already include the network path.
     350                        else
     351                                $blog_s = $like_s . $wild;
     352                        $query .= " AND  ( {$wpdb->blogs}.path LIKE '$blog_s' )";
     353                }
     354
     355                return $query;
     356        }
    339357}
  • wp-admin/includes/ajax-actions.php

     
    213213}
    214214
    215215function wp_ajax_autocomplete_site() {
     216        global $wp_list_table, $current_site, $wpdb;
     217
    216218        if ( ! is_multisite() || ! current_user_can( 'manage_sites' ) || wp_is_large_network( 'sites' ) )
    217219                wp_die( -1 );
    218220
    219         $return = array();
     221        require ABSPATH . '/wp-admin/includes/class-wp-ms-sites-list-table.php';
    220222
    221         global $wpdb;
    222         $like_escaped_term = '%' . like_escape( stripslashes( $_REQUEST['term'] ) ) . '%';
    223         $sites = $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, domain, path FROM $wpdb->blogs WHERE ( domain LIKE %s OR path LIKE %s ) AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' ORDER BY registered DESC", $like_escaped_term, $like_escaped_term ), ARRAY_A );
     223        $query = WP_MS_Sites_List_Table::get_search_sql( trim( $_REQUEST['term'] ) . '*' );
     224        error_log( $query );
     225        $sites = $wpdb->get_results( $query );
    224226
    225227        if ( empty( $sites ) )
    226228                wp_die( -1 );
    227229
    228         foreach ( (array) $sites as $details ) {
    229                 $blogname = get_blog_option( $details['blog_id'], 'blogname' );
     230        $return = array();
     231
     232        foreach ( $sites as $site ) {
     233                $value = is_subdomain_install() ? str_replace( '.' . $current_site->domain, '', $site->domain ) : $site->path;
    230234                $return[] = array(
    231                         'label' => sprintf( '%1$s (%2$s)', $blogname, $details['domain'] . $details['path'] ),
    232                         'value' => $details['domain']
     235                        'label' => $value,
     236                        'value' => $value,
    233237                );
    234238        }
    235239
  • wp-admin/includes/dashboard.php

     
    442442        <p class="youhave"><?php echo $sentence; ?></p>
    443443        <?php do_action( 'wpmuadminresult', '' ); ?>
    444444
    445         <form name="searchform" action="<?php echo network_admin_url('users.php'); ?>" method="get">
     445        <form action="<?php echo network_admin_url('users.php'); ?>" method="get">
    446446                <p>
    447                         <input type="search" name="s" value="" size="30" id="all-user-search-input" />
     447                        <input type="search" name="s" value="" size="30" id="all-user-search-input" autocomplete="off" />
    448448                        <?php submit_button( __( 'Search Users' ), 'button', 'submit', false, array( 'id' => 'submit_users' ) ); ?>
    449449                </p>
    450450        </form>
    451451
    452         <form name="searchform" action="<?php echo network_admin_url('sites.php'); ?>" method="get">
     452        <form action="<?php echo network_admin_url('sites.php'); ?>" method="get">
    453453                <p>
    454                         <input type="search" name="s" value="" size="30" id="site-search-input" />
     454                        <input type="search" name="s" value="" size="30" id="site-search-input" autocomplete="off" />
    455455                        <?php submit_button( __( 'Search Sites' ), 'button', 'submit', false, array( 'id' => 'submit_sites' ) ); ?>
    456456                </p>
    457457        </form>