diff options
| author | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2006-11-07 12:37:04 +0000 |
|---|---|---|
| committer | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2006-11-07 12:37:04 +0000 |
| commit | d510632e9f07cec9ac3de3b5dafc56bd58c81b8a (patch) | |
| tree | b4944ea6ceed3a73977f9edeae40f8174a4bab29 /wp-includes/query.php | |
| parent | 74e848ef222ada441de10e1db012988d1904b3ca (diff) | |
| download | wordpress-mu-d510632e9f07cec9ac3de3b5dafc56bd58c81b8a.tar.gz wordpress-mu-d510632e9f07cec9ac3de3b5dafc56bd58c81b8a.tar.xz wordpress-mu-d510632e9f07cec9ac3de3b5dafc56bd58c81b8a.zip | |
WP Merge
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@804 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-includes/query.php')
| -rw-r--r-- | wp-includes/query.php | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/wp-includes/query.php b/wp-includes/query.php index c1b88ec..b2dd69d 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -254,7 +254,7 @@ function the_post() { class WP_Query {
var $query;
- var $query_vars;
+ var $query_vars = array();
var $queried_object;
var $queried_object_id;
var $request;
@@ -315,7 +315,7 @@ class WP_Query { function init () {
unset($this->posts);
unset($this->query);
- unset($this->query_vars);
+ $this->query_vars = array();
unset($this->queried_object);
unset($this->queried_object_id);
$this->post_count = 0;
@@ -743,29 +743,26 @@ class WP_Query { // If a search pattern is specified, load the posts that match
if (!empty($q['s'])) {
- $q['s'] = addslashes_gpc($q['s']);
- $search = ' AND (';
- $q['s'] = preg_replace('/, +/', ' ', $q['s']);
- $q['s'] = str_replace(',', ' ', $q['s']);
- $q['s'] = str_replace('"', ' ', $q['s']);
- $q['s'] = trim($q['s']);
- if ($q['exact']) {
- $n = '';
- } else {
- $n = '%';
+ // added slashes screw with quote grouping when done early, so done later
+ $q['s'] = stripslashes($q['s']);
+ if ($q['sentence']) {
+ $q['search_terms'] = array($q['s']);
}
- if (!$q['sentence']) {
- $s_array = explode(' ',$q['s']);
- $q['search_terms'] = $s_array;
- $search .= '((post_title LIKE \''.$n.$s_array[0].$n.'\') OR (post_content LIKE \''.$n.$s_array[0].$n.'\'))';
- for ( $i = 1; $i < count($s_array); $i = $i + 1) {
- $search .= ' AND ((post_title LIKE \''.$n.$s_array[$i].$n.'\') OR (post_content LIKE \''.$n.$s_array[$i].$n.'\'))';
- }
- $search .= ' OR (post_title LIKE \''.$n.$q['s'].$n.'\') OR (post_content LIKE \''.$n.$q['s'].$n.'\')';
- $search .= ')';
- } else {
- $search = ' AND ((post_title LIKE \''.$n.$q['s'].$n.'\') OR (post_content LIKE \''.$n.$q['s'].$n.'\'))';
+ else {
+ preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $q[s], $matches);
+ $q['search_terms'] = array_map(create_function('$a', 'return trim($a, "\\"\'\\n\\r ");'), $matches[0]);
+ }
+ $n = ($q['exact']) ? '' : '%';
+ $searchand = '';
+ foreach((array)$q['search_terms'] as $term) {
+ $term = addslashes_gpc($term);
+ $search .= "{$searchand}((post_title LIKE '{$n}{$term}{$n}') OR (post_content LIKE '{$n}{$term}{$n}'))";
+ $searchand = ' AND ';
}
+ $term = addslashes_gpc($q['s']);
+ if (!$q['sentence'] && count($q['search_terms']) > 1 && $q['search_terms'][0] != $q['s'] ) $search .= " OR (post_title LIKE '{$n}{$term}{$n}') OR (post_content LIKE '{$n}{$term}{$n}')";
+
+ $search = " AND ({$search}) ";
}
// Category stuff
|
