Ticket #21688: 21688-5.patch
File 21688-5.patch, 4.6 KB (added by , 11 years ago) |
---|
-
wp-includes/default-filters.php
192 192 add_filter( 'editable_slug', 'urldecode' ); 193 193 add_filter( 'editable_slug', 'esc_textarea' ); 194 194 add_filter( 'nav_menu_meta_box_object', '_wp_nav_menu_meta_box_object' ); 195 add_filter( 'wp_search_stopwords', 'wp_search_stopwords' ); 195 196 196 197 // Actions 197 198 add_action( 'wp_head', 'wp_enqueue_scripts', 1 ); -
wp-includes/functions.php
3637 3637 return true; 3638 3638 } 3639 3639 3640 /** 3641 * Common stopwords (terms) that are excluded from the separate term matching when searching for posts. 3642 * The list of English stopwords is the approximate search engines list. MySQL has a much longer default list of full-text stopwords. 3643 * 3644 * @since 3.5.0 3645 * 3646 * @param array optional Terms to exclude when searching 3647 * @return array 3648 */ 3649 function wp_search_stopwords( $in = array() ) { 3650 $_words = explode( ',', _x('about,are,com,for,from,how,that,the,this,was,what,when,where,who,will,with,www', 'Comma separated list of common words to exclude when searching.') ); 3651 $words = array(); 3652 3653 foreach( $_words as $word ) { 3654 $word = trim($word, "\r\n\t "); 3655 if ( !$word ) 3656 continue; 3657 $words[] = $word; 3658 } 3659 3660 return array_merge( $in, $words ); 3661 } 3662 3663 /** 3664 * Check if the term is suitable for searching. 3665 * 3666 * @access private 3667 * @since 3.5.0 3668 * 3669 * @param string Term to check 3670 * @return string 3671 */ 3672 function _check_search_term($term) { 3673 static $strtolower_func, $stopwords; 3674 3675 if ( empty( $term ) ) 3676 return ''; 3677 3678 // keep spaces when term is for exact match 3679 if ( preg_match('/^".+"$/', $term) ) 3680 $term = trim($term, "\"'"); 3681 else 3682 $term = trim($term, "\"' "); 3683 3684 if ( !$strtolower_func ) { 3685 $strtolower_func = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower'; 3686 $stopwords = apply_filters( 'wp_search_stopwords', array() ); 3687 } 3688 3689 if ( empty( $term{2} ) ) { 3690 // $term is too short, remove it if it doesn't contain numbers and is lower case 3691 if ( !preg_match( '/[0-9]/', $term ) && $strtolower_func($term) == $term ) 3692 $term = ''; 3693 } 3694 3695 if ( $term && in_array( $strtolower_func($term), $stopwords, true ) ) 3696 $term = ''; 3697 3698 return $term; 3699 } 3700 -
wp-includes/query.php
2173 2173 } 2174 2174 } 2175 2175 2176 // If a search pattern is specified, load the posts that match 2177 if ( !empty($q['s']) ) { 2176 // If a search pattern is specified, load the posts that match. 2177 // Sanity check: search string shouldn't be more than 1600 characters. 2178 // See ticket #21688 for more info. 2179 if ( !empty($q['s']) && strlen($q['s']) < 1600 ) { 2178 2180 // added slashes screw with quote grouping when done early, so done later 2179 2181 $q['s'] = stripslashes($q['s']); 2180 2182 if ( empty( $_GET['s'] ) && $this->is_main_query() ) 2181 2183 $q['s'] = urldecode($q['s']); 2184 // there are no line breaks in <input /> fields 2185 $q['s'] = str_replace( array("\r", "\n"), '', $q['s'] ); 2182 2186 if ( !empty($q['sentence']) ) { 2183 2187 $q['search_terms'] = array($q['s']); 2184 2188 } else { 2185 preg_match_all('/".*?("|$)|((?<=[\r\n\t ",+])|^)[^\r\n\t ",+]+/', $q['s'], $matches); 2186 $q['search_terms'] = array_map('_search_terms_tidy', $matches[0]); 2189 if ( preg_match_all('/".*?("|$)|((?<=[\t ",+])|^)[^\t ",+]+/', $q['s'], $matches) ) { 2190 $q['search_terms'] = array(); 2191 2192 if ( !empty($matches[0]) ) { 2193 foreach ( $matches[0] as $term ) { 2194 $term = _check_search_term($term); 2195 if ( $term ) 2196 $q['search_terms'][] = $term; 2197 } 2198 } 2199 2200 // if the search string has only short terms or stopwords, or is more than 10 terms long, match it as sentence 2201 if ( empty($q['search_terms']) || count($q['search_terms']) > 10 ) 2202 $q['search_terms'] = array($q['s']); 2203 } else { 2204 $q['search_terms'] = array($q['s']); 2205 } 2187 2206 } 2207 2188 2208 $n = !empty($q['exact']) ? '' : '%'; 2189 2209 $searchand = ''; 2190 foreach( (array)$q['search_terms'] as $term ) {2210 foreach( $q['search_terms'] as $term ) { 2191 2211 $term = esc_sql( like_escape( $term ) ); 2192 2212 $search .= "{$searchand}(($wpdb->posts.post_title LIKE '{$n}{$term}{$n}') OR ($wpdb->posts.post_content LIKE '{$n}{$term}{$n}'))"; 2193 2213 $searchand = ' AND ';