protected function post_process() { parent::post_process(); $searchId = $this->searchId; $searchData = $this->searchData; if (w_isset_def($searchData['attachment_use_image'], 1) == 1) { foreach ($this->results as $k => $r) { if (strpos($r->post_mime_type, 'image/') !== false && $r->guid != "") { $this->results[$k]->image = $r->guid; } } } return $this->results; }
function ajaxsearchlite_search() { global $wpdb; global $search; /*print "in ajaxsearchlite_search();"; print_r(array()); return; */ $s = $_POST['aslp']; $s = apply_filters('asl_search_phrase_before_cleaning', $s); $s = stripcslashes($s); $s = trim($s); $s = preg_replace('/\\s+/', ' ', $s); $s = apply_filters('asl_search_phrase_after_cleaning', $s); $def_data = get_option('asl_defaults'); $search = array(); $search['data'] = get_option('asl_options'); $search['data'] = array_merge($def_data, $search['data']); $search['data']['image_options'] = array('show_images' => $search['data']['show_images'], 'image_bg_color' => '#FFFFFF', 'image_transparency' => 1, 'image_crop_location' => w_isset_def($search['data']['image_crop_location'], "c"), 'image_width' => $search['data']['image_width'], 'image_height' => $search['data']['image_height'], 'image_source1' => $search['data']['image_source1'], 'image_source2' => $search['data']['image_source2'], 'image_source3' => $search['data']['image_source3'], 'image_source4' => $search['data']['image_source4'], 'image_source5' => $search['data']['image_source5'], 'image_default' => $search['data']['image_default'], 'image_custom_field' => $search['data']['image_custom_field']); // ----------------- Recalculate image width/height --------------- switch ($search['data']['resultstype']) { case "horizontal": /* Same width as height */ $search['data']['image_options']['image_width'] = wpdreams_width_from_px($search['data']['image_options']['hreswidth']); $search['data']['image_options']['image_height'] = wpdreams_width_from_px($search['data']['image_options']['hreswidth']); break; case "polaroid": $search['data']['image_options']['image_width'] = intval($search['data']['preswidth']); $search['data']['image_options']['image_height'] = intval($search['data']['preswidth']); break; case "isotopic": $search['data']['image_options']['image_width'] = intval($search['data']['i_item_width'] * 1.5); $search['data']['image_options']['image_height'] = intval($search['data']['i_item_height'] * 1.5); break; } if (isset($search['data']['selected-imagesettings'])) { $search['data']['settings-imagesettings'] = $search['data']['selected-imagesettings']; } /*if (isset($search) && $search['data']['exactonly']!=1) { $_s = explode(" ", $s); }*/ if (isset($_POST['options'])) { parse_str($_POST['options'], $search['options']); } $blogresults = array(); $allpageposts = array(); $pageposts = array(); do_action('asl_before_search', $s); $params = array('data' => $search['data'], 'options' => $search['options']); $_posts = new wpdreams_searchContent($params); $pageposts = $_posts->search($s); $allpageposts = array_merge($allpageposts, $pageposts); do_action('asl_after_pagepost_results', $s, $pageposts); $allpageposts = apply_filters('asl_pagepost_results', $allpageposts); $results = array_merge($allpageposts); // Keyword suggestions if (count($results) <= 0 && w_isset_def($search['data']['kw_suggestions'], 1) == 1) { $keywords = array(); $types = array(); $sd = $search['data']; if ($sd['searchinposts'] == 1) { $types[] = "post"; } if ($sd['searchinpages'] == 1) { $types[] = "page"; } if (isset($sd['selected-customtypes']) && count($sd['selected-customtypes']) > 0) { $types = array_merge($types, $sd['selected-customtypes']); } $t = new wpd_keywordSuggest("google", array('maxCount' => w_isset_def($sd['kw_count'], 10), 'maxCharsPerWord' => w_isset_def($sd['kw_length'], 60), 'postTypes' => $types, 'lang' => w_isset_def($sd['kw_google_lang'], "en"), 'overrideUrl' => '')); $keywords = $t->getKeywords($s); if ($keywords != false) { $results['keywords'] = $keywords; $results['nores'] = 1; $results = apply_filters('asl_only_keyword_results', $results); } } else { if (count($results > 0)) { $results = apply_filters('asl_only_non_keyword_results', $results); } } $results = apply_filters('asl_results', $results); do_action('asl_after_search', $s, $results); // Generate the results here $html_results = asl_generate_html_results($results, $search['data']); /* Clear output buffer, possible warnings */ print "!!ASLSTART!!"; //var_dump($results);die(); print_r($html_results); print "!!ASLEND!!"; die; }
/** * The search function * * @return array|string */ protected function do_search() { global $wpdb; global $q_config; $options = $this->options; $searchData = $this->searchData; $parts = array(); $relevance_parts = array(); $types = array(); $post_types = ""; $s = $this->s; // full keyword $_s = $this->_s; // array of keywords $_si = implode('|', $_s); // imploded phrase for regexp $_si = $_si != '' ? $_si : $s; //$kw_logic = w_isset_def($searchData['keyword_logic'], 'or'); $q_config['language'] = $options['qtranslate_lang']; if (isset($wpdb->base_prefix)) { $_prefix = $wpdb->base_prefix; } else { $_prefix = $wpdb->prefix; } /*------------------------- Statuses ----------------------------*/ $statuses = array('publish'); if ($searchData['searchinpending']) { $statuses[] = 'pending'; } if ($searchData['searchindrafts']) { $statuses[] = 'draft'; } $words = implode('|', $statuses); $post_statuses = "(lower({$wpdb->posts}.post_status) REGEXP '{$words}')"; /*---------------------------------------------------------------*/ /*----------------------- Gather Types --------------------------*/ if ($options['set_inposts'] == 1) { $types[] = "post"; } if ($options['set_inpages']) { $types[] = "page"; } if (isset($options['customset']) && count($options['customset']) > 0) { $types = array_merge($types, $options['customset']); } if (count($types) < 1) { return ''; } else { $words = implode('[[:>:]]|[[:<:]]', $types); $post_types = "({$wpdb->posts}.post_type REGEXP '[[:<:]]" . $words . "[[:>:]]')"; } /*---------------------------------------------------------------*/ $is_too_short = false; $not_exact_phrase = ''; $fulltext = wpdreamsFulltext::getInstance(); foreach ($_s as $_pp) { if (strlen($_pp) < $fulltext->getMinWordLength() || !$options['set_exactonly']) { $is_too_short = true; $not_exact_phrase .= " *" . $_pp . "*"; } else { $not_exact_phrase .= " " . $_pp; } } $not_exact_phrase = trim($not_exact_phrase); $exact_phrase = '"' . $s . '"'; $ful_options = get_option('asp_fulltexto'); if (w_isset_def($ful_options['dbuseregularwhenshort'], 0) && $is_too_short) { return parent::do_search(); } /** * Construct the INDEX name to search */ $match_against = '1'; $relevance = ''; $fixed_phrase = $options['set_exactonly'] ? $exact_phrase : $not_exact_phrase; $boolean_mode = get_option('asp_fulltext_indexed') == 0 || $is_too_short || !$options['set_exactonly'] ? ' IN BOOLEAN MODE' : ''; $index_name = $options['set_intitle'] ? "{$wpdb->posts}.post_title" : ''; if ($index_name == '') { $index_name .= $options['set_incontent'] ? "{$wpdb->posts}.post_content" : ''; } else { $index_name .= $options['set_incontent'] ? ", {$wpdb->posts}.post_content" : ''; } if ($index_name == '') { $index_name .= $options['set_inexcerpt'] ? "{$wpdb->posts}.post_excerpt" : ''; } else { $index_name .= $options['set_inexcerpt'] ? ", {$wpdb->posts}.post_excerpt" : ''; } if ($index_name != '') { $match_against = " MATCH(" . $index_name . ") AGAINST ('" . $fixed_phrase . "'" . $boolean_mode . ") "; } if ($match_against != '1') { $relevance = "\r\n (\r\n MATCH(" . $index_name . ") AGAINST ('" . $exact_phrase . "'" . $boolean_mode . ") +\r\n MATCH(" . $index_name . ") AGAINST ('" . $not_exact_phrase . "'" . $boolean_mode . ")\r\n )\r\n "; } // ------------------------ Categories/taxonomies ---------------------- if (!isset($options['categoryset']) || $options['categoryset'] == "") { $options['categoryset'] = array(); } if (!isset($options['termset']) || $options['termset'] == "") { $options['termset'] = array(); } $exclude_categories = array(); $searchData['selected-exsearchincategories'] = w_isset_def($searchData['selected-exsearchincategories'], array()); $searchData['selected-excludecategories'] = w_isset_def($searchData['selected-excludecategories'], array()); $_all_cat = get_terms('category', array('fields' => 'ids')); $_needed_cat = array_diff($_all_cat, $searchData['selected-exsearchincategories']); $_needed_cat = !is_array($_needed_cat) ? array() : $_needed_cat; $exclude_categories = array_diff(array_merge($_needed_cat, $searchData['selected-excludecategories']), $options['categoryset']); $exclude_terms = array(); $exclude_showterms = array(); $searchData['selected-showterms'] = w_isset_def($searchData['selected-showterms'], array()); $searchData['selected-excludeterms'] = w_isset_def($searchData['selected-excludeterms'], array()); foreach ($searchData['selected-excludeterms'] as $tax => $terms) { $exclude_terms = array_merge($exclude_terms, $terms); } foreach ($searchData['selected-showterms'] as $tax => $terms) { $exclude_showterms = array_merge($exclude_showterms, $terms); } $exclude_terms = array_diff(array_merge($exclude_terms, $exclude_showterms), $options['termset']); $all_terms = array(); $all_terms = array_merge($exclude_categories, $exclude_terms); if (count($all_terms) > 0) { $words = '--' . implode('--|--', $all_terms) . '--'; $term_query = "HAVING (ttid NOT REGEXP '{$words}')"; } // --------------------------------------------------------------------- /*------------- Custom Fields with Custom selectors -------------*/ if (isset($options['aspf']) && isset($options['aspfdata'])) { $parts = array(); foreach ($options['aspfdata'] as $u_data) { $data = json_decode(base64_decode($u_data)); $posted = $options['aspf'][$data->asp_f_field]; $ll_like = ""; $rr_like = ""; $operator = "="; if (isset($data->asp_f_operator)) { switch ($data->asp_f_operator) { case 'eq': $operator = "="; break; case 'neq': $operator = "<>"; break; case 'lt': $operator = "<"; break; case 'gt': $operator = ">"; break; case 'elike': $operator = "="; $ll_like = "'"; $rr_like = "'"; break; case 'like': $operator = "LIKE"; $ll_like = "'%"; $rr_like = "%'"; break; default: $operator = "="; break; } } //var_dump($data); /*if (w_isset_def($searchData['cf_null_values'], 1) == 1) { $cf_key_is_null .= " OR $wpdb->postmeta.meta_key IS NULL"; $cf_val_is_null .= " OR $wpdb->postmeta.meta_value IS NULL"; }*/ if ($data->asp_f_type == 'range' && isset($posted['lower'])) { $parts[] = " ( ({$wpdb->postmeta}.meta_key='{$data->asp_f_field}') AND\r\n ({$wpdb->postmeta}.meta_value BETWEEN " . $posted['lower'] . " AND " . $posted['upper'] . " ) )"; } else { if ($data->asp_f_type == 'slider' && isset($posted)) { $parts[] = " ( ({$wpdb->postmeta}.meta_key='{$data->asp_f_field}') AND\r\n ({$wpdb->postmeta}.meta_value {$operator} {$posted} ) )"; } else { if ($data->asp_f_type == 'radio' && isset($posted)) { $parts[] = " ( ({$wpdb->postmeta}.meta_key='{$data->asp_f_field}') AND\r\n ({$wpdb->postmeta}.meta_value {$operator} " . $ll_like . $posted . $rr_like . " ) )"; } else { if ($data->asp_f_type == 'dropdown' && isset($posted)) { if (isset($data->asp_f_dropdown_multi) && count($posted) > 0) { // The AND logic doesn't make any sense $logic = 'OR'; $values = ''; foreach ($posted as $v) { if ($values != '') { $values .= " {$logic} {$wpdb->postmeta}.meta_value {$operator} " . $ll_like . $v . $rr_like; } else { $values .= "{$wpdb->postmeta}.meta_value {$operator} " . $ll_like . $v . $rr_like; } } $values = $values == '' ? '0' : $values; $parts[] = "( ({$wpdb->postmeta}.meta_key='{$data->asp_f_field}') AND ({$values}) )"; } else { $parts[] = "( ({$wpdb->postmeta}.meta_key='{$data->asp_f_field}') AND\r\n ({$wpdb->postmeta}.meta_value {$operator} " . $ll_like . $posted . $rr_like . " ) )"; } } else { if ($data->asp_f_type == 'checkboxes' && isset($posted)) { $logic = $data->asp_f_checkboxes_logic; $values = ''; foreach ($posted as $v => $vv) { if ($values != '') { $values .= " {$logic} {$wpdb->postmeta}.meta_value {$operator} " . $ll_like . $v . $rr_like; } else { $values .= "{$wpdb->postmeta}.meta_value {$operator} " . $ll_like . $v . $rr_like; } } $values = $values == '' ? '0' : $values; $parts[] = "( ({$wpdb->postmeta}.meta_key='{$data->asp_f_field}') AND ({$values}) )"; } } } } } } $this->cf_parts = $parts; } $meta_count = count($this->cf_parts); $cf_query = implode(" OR ", $this->cf_parts); if ($cf_query == "") { $cf_select = "0"; $cf_having = ""; } else { $cf_select = "\r\n SELECT COUNT(*) FROM {$wpdb->postmeta} WHERE\r\n {$wpdb->postmeta}.post_id = {$wpdb->posts}.ID\r\n AND\r\n ({$cf_query})"; if (w_isset_def($searchData['cf_logic'], 'AND') == 'AND') { $cf_having = "meta_matches >= " . $meta_count; } else { $cf_having = "meta_matches >= 1"; } if ($term_query != '') { $cf_having = " AND " . $cf_having; } else { $cf_having = "HAVING " . $cf_having; } } /*---------------------------------------------------------------*/ /*---------------------- Custom Fields --------------------------*/ if (isset($searchData['selected-customfields'])) { $selected_customfields = $searchData['selected-customfields']; if (is_array($selected_customfields) && count($selected_customfields) > 0) { $words = $options['set_exactonly'] == 1 ? $s : $_si; foreach ($selected_customfields as $cfield) { $parts[] = "({$wpdb->postmeta}.meta_key='{$cfield}' AND\r\n lower({$wpdb->postmeta}.meta_value) REGEXP '{$words}')"; } } } /*---------------------------------------------------------------*/ /*------------------------ Exclude id's -------------------------*/ if (isset($searchData['excludeposts']) && $searchData['excludeposts'] != "") { $exclude_posts = "{$wpdb->posts}.ID NOT IN (" . $searchData['excludeposts'] . ")"; } else { $exclude_posts = "{$wpdb->posts}.ID NOT IN (-55)"; } /*---------------------------------------------------------------*/ /*------------------------- Build like --------------------------*/ $like_query = implode(' OR ', $parts); if ($like_query == "") { $like_query = "(0)"; } else { $like_query = "({$like_query})"; } /*---------------------------------------------------------------*/ /*------------------------- WPML filter -------------------------*/ $wpml_join = ""; if (defined('ICL_LANGUAGE_CODE') && ICL_LANGUAGE_CODE != '' && w_isset_def($searchData['wpml_compatibility'], 1) == 1) { $wpml_join = "RIGHT JOIN " . $wpdb->base_prefix . "icl_translations ON ({$wpdb->posts}.ID = " . $wpdb->base_prefix . "icl_translations.element_id AND " . $wpdb->base_prefix . "icl_translations.language_code = '" . ICL_LANGUAGE_CODE . "')"; } /*---------------------------------------------------------------*/ $orderby = isset($searchData['selected-orderby']) && $searchData['selected-orderby'] != '' ? $searchData['selected-orderby'] : "post_date DESC"; $querystr = "\r\n \t\tSELECT \r\n {$wpdb->posts}.post_title as title,\r\n {$wpdb->posts}.ID as id,\r\n {$wpdb->posts}.post_date as date, \r\n {$wpdb->posts}.post_content as content,\r\n {$wpdb->posts}.post_excerpt as excerpt,\r\n {$wpdb->users}.user_nicename as author,\r\n 'pagepost' as content_type,\r\n {$wpdb->posts}.post_type as post_type,\r\n ({$cf_select}) as meta_matches,\r\n CASE WHEN " . $_prefix . "ajaxsearchpro_priorities.priority IS NULL\r\n THEN 100\r\n ELSE " . $_prefix . "ajaxsearchpro_priorities.priority\r\n END AS priority,\r\n CONCAT('--', GROUP_CONCAT(DISTINCT {$wpdb->terms}.term_id SEPARATOR '----'), '--') as ttid,\r\n {$wpdb->posts}.post_type as post_type,"; if ($searchData['userelevance'] == 1 && $relevance != '') { $querystr .= $relevance; } else { $querystr .= "1 "; } $querystr .= "\r\n as relevance\r\n \t\tFROM {$wpdb->posts}\r\n LEFT JOIN {$wpdb->postmeta} ON {$wpdb->postmeta}.post_id = {$wpdb->posts}.ID\r\n LEFT JOIN " . $_prefix . "ajaxsearchpro_priorities ON (" . $_prefix . "ajaxsearchpro_priorities.post_id = {$wpdb->posts}.ID AND " . $_prefix . "ajaxsearchpro_priorities.blog_id = " . get_current_blog_id() . ")\r\n LEFT JOIN {$wpdb->users} ON {$wpdb->users}.ID = {$wpdb->posts}.post_author\r\n LEFT JOIN {$wpdb->term_relationships} ON {$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id\r\n LEFT JOIN {$wpdb->term_taxonomy} ON {$wpdb->term_taxonomy}.term_taxonomy_id = {$wpdb->term_relationships}.term_taxonomy_id\r\n LEFT JOIN {$wpdb->terms} ON {$wpdb->term_taxonomy}.term_id = {$wpdb->terms}.term_id\r\n {$wpml_join}\r\n \t\tWHERE\r\n {$post_types}\r\n AND {$post_statuses}\r\n AND (" . $match_against . " OR (" . $like_query . "))\r\n AND (" . $exclude_posts . ")\r\n GROUP BY\r\n {$wpdb->posts}.ID\r\n {$term_query}\r\n {$cf_having}\r\n "; $querystr .= " ORDER BY priority DESC, relevance DESC, " . $wpdb->posts . "." . $orderby . "\r\n LIMIT " . $searchData['maxresults']; $pageposts = $wpdb->get_results($querystr, OBJECT); //var_dump($querystr); var_dump($pageposts);die("!!"); $this->results = $pageposts; return $pageposts; }
protected function do_search() { global $wpdb; global $q_config; if (isset($wpdb->base_prefix)) { $_prefix = $wpdb->base_prefix; } else { $_prefix = $wpdb->prefix; } $options = $this->options; $searchData = $this->searchData; $s = $this->s; $_s = $this->_s; $q_config['language'] = $options['qtranslate_lang']; $rel_title = ""; $rel_content = ""; $rel_excerpt = ""; $rel_terms = ""; $like = ""; $rel_title = ""; /** * Fallback or Boolean when strlen < N */ $is_too_short = false; $not_exact_phrase = ''; $fulltext = wpdreams_fulltext::getInstance(); foreach ($_s as $_pp) { if (strlen($_pp) < $fulltext->getMinWordLength()) { $is_too_short = true; $not_exact_phrase .= " " . $_pp . "*"; } else { $not_exact_phrase .= " " . $_pp; } } $not_exact_phrase = trim($not_exact_phrase); $exact_phrase = '"' . $s . '"'; if (get_option('asp_dbuseregularwhenshort') == 1 && $is_too_short) { return parent::do_search(); } /** * Construct the INDEX name to search */ $match_against = '1'; $relevance = ''; $fixed_phrase = !$options['set_exactonly'] ? $exact_phrase : $not_exact_phrase; $boolean_mode = get_option('asp_fulltext_indexed') == 0 || $is_too_short || !$options['set_exactonly'] ? ' IN BOOLEAN MODE' : ''; $index_name = $options['set_intitle'] ? "{$wpdb->posts}.post_title" : ''; if ($index_name == '') { $index_name .= $options['set_incontent'] ? "{$wpdb->posts}.post_content" : ''; } else { $index_name .= $options['set_incontent'] ? ", {$wpdb->posts}.post_content" : ''; } if ($index_name == '') { $index_name .= $options['set_inexcerpt'] ? "{$wpdb->posts}.post_excerpt" : ''; } else { $index_name .= $options['set_inexcerpt'] ? ", {$wpdb->posts}.post_excerpt" : ''; } if ($index_name != '') { $match_against = " MATCH(" . $index_name . ") AGAINST ('" . $fixed_phrase . "'" . $boolean_mode . ") "; } if ($match_against != '1') { $relevance = "\n (\n MATCH(" . $index_name . ") AGAINST ('" . $exact_phrase . "'" . $boolean_mode . ") + \n MATCH(" . $index_name . ") AGAINST ('" . $not_exact_phrase . "'" . $boolean_mode . ")\n )\n "; } $selected_customs = array(); if (isset($options['customset'])) { $selected_customs = $options['customset']; } if (is_array($selected_customs)) { foreach ($selected_customs as $k => $v) { if ($where != "") { $where .= " OR {$wpdb->posts}.post_type='" . $v . "'"; } else { $where = "{$wpdb->posts}.post_type='" . $v . "'"; } } } $where = $where == '' ? '1' : $where; $_sr = implode("%' OR lower({$wpdb->terms}.name) like '%", $_s); $rel_terms = ""; if ($searchData['searchinterms']) { if ($options['set_exactonly']) { $sr = $_sr; if ($like != "") { $sr = " OR lower({$wpdb->terms}.name) like '%" . $sr . "%'"; } else { $sr = " lower({$wpdb->terms}.name) like '%" . $sr . "%'"; } } else { if ($like != "") { $sr = " OR lower({$wpdb->terms}.name) like '%" . $s . "%'"; } else { $sr = " lower({$wpdb->terms}.name) like '%" . $s . "%'"; } } $like .= $sr; } $selected_customfields = $searchData['selected-customfields']; if (is_array($selected_customfields) && count($selected_customfields) > 0) { if ($options['set_exactonly']) { $sr = implode("%' OR lower({$wpdb->postmeta}.meta_value) like '%", $_s); $sr = "lower({$wpdb->postmeta}.meta_value) like '%" . $sr . "%'"; } else { $sr = "lower({$wpdb->postmeta}.meta_value) like '%" . $s . "%'"; } $ws = ""; foreach ($selected_customfields as $k => $v) { if ($ws != "") { $ws .= " OR {$wpdb->postmeta}.meta_key='" . $v . "'"; } else { $ws .= "{$wpdb->postmeta}.meta_key='" . $v . "'"; } } if ($like != "") { $like .= " OR ((" . $sr . ") AND (" . $ws . "))"; } else { $like .= "((" . $sr . ") AND (" . $ws . "))"; } } if (isset($searchData['excludeposts']) && $searchData['excludeposts'] != "") { $exclude_posts = "{$wpdb->posts}.ID NOT IN (" . $searchData['excludeposts'] . ")"; } else { $exclude_posts = "{$wpdb->posts}.ID NOT IN (-55)"; } $like = $like == '' ? 0 : $like; $orderby = isset($searchData['selected-orderby']) && $searchData['selected-orderby'] != '' ? $searchData['selected-orderby'] : "post_date DESC"; //$s=strtolower(addslashes($_POST['aspp'])); $querystr = "\n \t\tSELECT \n {$wpdb->posts}.post_title as title,\n {$wpdb->posts}.ID as id,\n {$wpdb->posts}.post_date as date, \n {$wpdb->posts}.post_content as content,\n {$wpdb->posts}.post_excerpt as excerpt,\n {$wpdb->users}.user_nicename as author,\n GROUP_CONCAT(DISTINCT {$wpdb->terms}.term_id) as term_id,\n {$wpdb->posts}.post_type as post_type,"; if ($searchData['userelevance'] == 1 && $relevance != '') { $querystr .= $relevance; } else { $querystr .= "1 "; } $querystr .= " \n as relevance\n \t\tFROM {$wpdb->posts}\n LEFT JOIN {$wpdb->postmeta} ON {$wpdb->postmeta}.post_id = {$wpdb->posts}.ID\n LEFT JOIN {$wpdb->users} ON {$wpdb->users}.ID = {$wpdb->posts}.post_author\n LEFT JOIN {$wpdb->term_relationships} ON {$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id\n LEFT JOIN {$wpdb->term_taxonomy} ON {$wpdb->term_taxonomy}.term_taxonomy_id = {$wpdb->term_relationships}.term_taxonomy_id\n LEFT JOIN {$wpdb->terms} ON {$wpdb->term_taxonomy}.term_id = {$wpdb->terms}.term_id\n \t\tWHERE\n ({$wpdb->posts}.post_status='publish' {$searchin}) AND\n (" . $where . ") \n AND (" . $match_against . " OR (" . $like . "))\n AND (" . $exclude_posts . ")\n GROUP BY\n {$wpdb->posts}.ID"; $querystr .= " ORDER BY relevance DESC, " . $wpdb->posts . "." . $orderby . "\n LIMIT " . $searchData['maxresults']; $pageposts = $wpdb->get_results($querystr, OBJECT); //var_dump($querystr); var_dump($pageposts);die("!!"); $this->results = $pageposts; return $pageposts; }
function ajaxsearchpro_search() { global $wpdb; global $switched; global $search; /*print "in ajaxsearchpro_search();"; print_r(array()); return; */ $s = $_POST['aspp']; $s = apply_filters('asp_search_phrase_before_cleaning', $s); $s = strtolower(trim($s)); $s = preg_replace('/\\s+/', ' ', $s); $s = apply_filters('asp_search_phrase_after_cleaning', $s); $stat = get_option("asp_stat"); if (isset($wpdb->base_prefix)) { $_prefix = $wpdb->base_prefix; } else { $_prefix = $wpdb->prefix; } if ($stat == 1) { require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $in = $wpdb->query("UPDATE " . $_prefix . "ajaxsearchpro_statistics SET num=num+1, last_date=" . time() . " WHERE (keyword='" . $s . "' AND search_id=" . $_POST['asid'] . ")"); if ($in == false) { dbDelta("INSERT INTO " . $_prefix . "ajaxsearchpro_statistics (search_id, keyword, num, last_date) VALUES (" . $_POST['asid'] . ", '" . $s . "', 1, " . time() . ")"); } } $search = $wpdb->get_row("SELECT * FROM " . $_prefix . "ajaxsearchpro WHERE id=" . $_POST['asid'], ARRAY_A); $search['data'] = json_decode($search['data'], true); if (isset($search['data']['selected-imagesettings'])) { $search['data']['settings-imagesettings'] = $search['data']['selected-imagesettings']; } /*if (isset($search) && $search['data']['exactonly']!=1) { $_s = explode(" ", $s); }*/ if (isset($_POST['options'])) { parse_str($_POST['options'], $search['options']); } //Advanced title and description fields add_filter('asp_result_title_after_prostproc', 'adv_title', 1, 2); add_filter('asp_result_content_after_prostproc', 'adv_desc', 1, 2); function adv_title($title, $id) { global $search; $titlefield = $search['data']['advtitlefield']; if ($titlefield == '') { return $title; } preg_match_all("/{(.*?)}/", $titlefield, $matches); if (isset($matches[0]) && isset($matches[1]) && is_array($matches[1])) { foreach ($matches[1] as $field) { if ($field == 'titlefield') { $titlefield = str_replace('{titlefield}', $title, $titlefield); } else { $val = get_post_meta($id, $field, true); $titlefield = str_replace('{' . $field . '}', $val, $titlefield); } } } return $titlefield; } function adv_desc($desc, $id) { global $search; $descfield = $search['data']['advdescriptionfield']; if ($descfield == '') { return $desc; } preg_match_all("/{(.*?)}/", $descfield, $matches); if (isset($matches[0]) && isset($matches[1]) && is_array($matches[1])) { foreach ($matches[1] as $field) { if ($field == 'descriptionfield') { $descfield = str_replace('{descriptionfield}', $desc, $descfield); } else { $val = get_post_meta($id, $field, true); $descfield = str_replace('{' . $field . '}', $val, $descfield); } } } return $descfield; } $blogresults = array(); $allbuddypresults = array('repliesresults' => array(), 'groupresults' => array(), 'userresults' => array()); $allpageposts = array(); $pageposts = array(); $repliesresults = array(); $allcommentsresults = array(); $commentsresults = array(); if (!isset($search['data']['selected-blogs']) || $search['data']['selected-blogs'] == null || count($search['data']['selected-blogs']) <= 0) { $search['data']['selected-blogs'] = array(0 => 1); } do_action('asp_before_search', $s); if (get_option('asp_caching') && AJAXSEARCHPRO_DEBUG != 1) { $filename = AJAXSEARCHPRO_PATH . DIRECTORY_SEPARATOR . "cache" . DIRECTORY_SEPARATOR . md5(json_encode($options) . $s) . ".wp"; $textcache = new wpdreamsTextCache($filename, get_option('asp_cachinginterval') * 60); $cache_content = $textcache->getCache(); if ($cache_content != false) { $cache_content = apply_filters('asp_cached_content_json', $cache_content); do_action('asp_after_search', $s, json_decode($cache_content, true)); print_r($cache_content); die; } } foreach ($search['data']['selected-blogs'] as $blog) { if (is_multisite()) { switch_to_blog($blog); } if ($_POST['asid'] == "") { $_dposts = new wpdreams_searchDemo(array()); $dpageposts = $_dposts->search($s); $allpageposts = array_merge($allpageposts, $dpageposts); } else { $params = array('data' => $search['data'], 'options' => $search['options']); if (get_option('asp_dbusefulltext') && get_option('asp_fulltext') == 1) { $_posts = new wpdreams_searchContentFulltext($params); } else { $_posts = new wpdreams_searchContent($params); } $pageposts = $_posts->search($s); $allpageposts = array_merge($allpageposts, $pageposts); do_action('asp_after_pagepost_results', $s, $pageposts); $_comments = new wpdreams_searchComments($params); $commentsresults = $_comments->search($s); $allcommentsresults = array_merge($allcommentsresults, $commentsresults); do_action('asp_after_comments_results', $s, $commentsresults); $_buddyp = new wpdreams_searchBuddyPress($params); $buddypresults = $_buddyp->search($s); // !!! returns array for each result (group, user, reply) !!! foreach ($buddypresults as $k => $v) { $allbuddypresults[$k] = array_merge($allbuddypresults[$k], $v); } do_action('asp_after_buddypress_results', $s, $buddypresults); } } if (is_multisite()) { restore_current_blog(); } $_blogs = new wpdreams_searchBlogs($params); $blogresults = $_blogs->search($s); $allpageposts = apply_filters('asp_pagepost_results', $allpageposts); $allcommentsresults = apply_filters('asp_comment_results', $allcommentsresults); $buddypresults = apply_filters('asp_buddyp_results', $buddypresults); $blogresults = apply_filters('asp_blog_results', $blogresults); /* Remove the results in polaroid mode */ if ($search['data']['resultstype'] == 'polaroid' && $search['data']['pifnoimage'] == 'removeres') { foreach ($allpageposts as $_k => $_v) { if ($_v->image == null || $_v->image == '') { unset($allpageposts[$_k]); } } foreach ($allcommentsresults as $_k => $_v) { if ($_v->image == null || $_v->image == '') { unset($allcommentsresults[$_k]); } } foreach ($buddypresults as $_k => $_v) { if ($_v->image == null || $_v->image == '') { unset($buddypresults[$_k]); } } foreach ($blogresults as $_k => $_v) { if ($_v->image == null || $_v->image == '') { unset($blogresults[$_k]); } } } // Grouping again if ($search['data']['resultstype'] == 'vertical' && ($search['data']['groupby'] == 1 || $search['data']['groupby'] == 2)) { $results = $allpageposts; if (!isset($results['items']) && count($allpageposts) > 0) { $results['items'] = array(); $results['grouped'] = 1; } if (count($blogresults) > 0) { if ($search['data']['showpostnumber'] == 1) { $num = " (" . count($blogresults) . ")"; } else { $num = ""; } $results['items'][90000] = array(); $results['items'][90000]['name'] = $search['data']['blogresultstext'] . $num; $results['items'][90000]['data'] = $blogresults; $results['grouped'] = 1; } $repliesresults = $allbuddypresults['repliesresults']; if (count($repliesresults) > 0) { if ($search['data']['showpostnumber'] == 1) { $num = " (" . count($repliesresults) . ")"; } else { $num = ""; } $results['items'][90001] = array(); $results['items'][90001]['name'] = $search['data']['bbpressreplytext'] . $num; $results['items'][90001]['data'] = $repliesresults; $results['grouped'] = 1; } if (count($allcommentsresults) > 0) { if ($search['data']['showpostnumber'] == 1) { $num = " (" . count($allcommentsresults) . ")"; } else { $num = ""; } $results['items'][90002] = array(); $results['items'][90002]['name'] = $search['data']['commentstext'] . $num; $results['items'][90002]['data'] = $allcommentsresults; $results['grouped'] = 1; } $groupresults = $allbuddypresults['groupresults']; if (count($groupresults) > 0) { if ($search['data']['showpostnumber'] == 1) { $num = " (" . count($groupresults) . ")"; } else { $num = ""; } $results['items'][90003] = array(); $results['items'][90003]['name'] = $search['data']['bbpressgroupstext'] . $num; $results['items'][90003]['data'] = $groupresults; $results['grouped'] = 1; } $userresults = $allbuddypresults['userresults']; if (count($userresults) > 0) { if ($search['data']['showpostnumber'] == 1) { $num = " (" . count($userresults) . ")"; } else { $num = ""; } $results['items'][90004] = array(); $results['items'][90004]['name'] = $search['data']['bbpressuserstext'] . $num; $results['items'][90004]['data'] = $userresults; $results['grouped'] = 1; } } else { $results = array_merge($blogresults, $allbuddypresults['repliesresults'], $allcommentsresults, $allbuddypresults['groupresults'], $allbuddypresults['userresults'], $allpageposts); } if (count($results) <= 0 && $search['data']['keywordsuggestions']) { $t = new keywordSuggest($search['data']['keywordsuggestionslang']); $keywords = $t->getKeywords($s); if ($keywords != false) { $results['keywords'] = $keywords; $results['nores'] = 1; $results = apply_filters('asp_only_keyword_results', $results); } } else { if (count($results > 0)) { $results = apply_filters('asp_only_non_keyword_results', $results); } } $results = apply_filters('asp_results', $results); do_action('asp_after_search', $s, $results); if (get_option('asp_caching') && AJAXSEARCHPRO_DEBUG != 1) { $cache_content = $textcache->setCache('!!ASPSTART!!' . json_encode($results) . "!!ASPEND!!"); } /* Clear output buffer, possible warnings */ print "!!ASPSTART!!"; //var_dump($results);die(); print_r(json_encode($results)); print "!!ASPEND!!"; die; }