Exemplo n.º 1
0
 /**
  * Content search function
  *
  * @return array|string
  */
 protected function do_search()
 {
     global $wpdb;
     global $q_config;
     $options = $this->options;
     $comp_options = get_option('asp_compatibility');
     $searchId = $this->searchId;
     $searchData = $this->searchData;
     $current_blog_id = get_current_blog_id();
     // General variables
     $parts = array();
     $relevance_parts = array();
     $types = array();
     $post_types = "(1)";
     $term_query = "(1)";
     $post_statuses = "(1)";
     $kw_logic = w_isset_def($searchData['keyword_logic'], 'or');
     $q_config['language'] = $options['qtranslate_lang'];
     $s = $this->s;
     // full keyword
     $_s = $this->_s;
     // array of keywords
     $sr = $this->sr;
     // full reversed keyword
     $_sr = $this->_sr;
     // array of reversed keywords
     if (isset($wpdb->base_prefix)) {
         $_prefix = $wpdb->base_prefix;
     } else {
         $_prefix = $wpdb->prefix;
     }
     /**
      * Determine if the priorities table should be used or not.
      */
     $priority_rows = (int) $wpdb->get_var("SELECT COUNT(*) FROM " . $_prefix . "ajaxsearchpro_priorities");
     $priority_select = $priority_rows > 0 ? "\r\n\t        IFNULL((\r\n            \tSELECT\r\n\t            aspp.priority\r\n\t            FROM " . $_prefix . "ajaxsearchpro_priorities as aspp\r\n\t            WHERE aspp.post_id = asp_index.doc AND aspp.blog_id = " . get_current_blog_id() . "\r\n            ), 100)\r\n\t        " : 100;
     /*------------------------- Statuses ----------------------------*/
     // Removed - it is already considered at index generation
     /*---------------------------------------------------------------*/
     /*----------------------- Gather Types --------------------------*/
     $page_q = "";
     if ($options['set_inposts'] == 1) {
         $types[] = "post";
     }
     if ($options['set_inpages']) {
         if (w_isset_def($searchData['exclude_page_parent_child'], '') != '') {
             // .. page exists thats parent isnt on the list
             $page_q = " OR (asp_index.post_type = 'page' AND\r\n\t\t\t\t\t\tEXISTS (SELECT ID FROM {$wpdb->posts} xxp WHERE\r\n\t\t\t\t\t\t\txxp.ID = asp_index.doc AND\r\n\t\t\t\t\t\t\txxp.post_parent NOT IN (" . str_replace('|', ',', $searchData['exclude_page_parent_child']) . ") AND\r\n\t\t\t\t\t\t\txxp.ID NOT IN (" . str_replace('|', ',', $searchData['exclude_page_parent_child']) . ")\r\n\t\t\t\t\t\t)\r\n\t\t\t\t\t)";
         } else {
             $types[] = "page";
         }
     }
     if (isset($options['customset']) && count($options['customset']) > 0) {
         $types = array_merge($types, $options['customset']);
     }
     // If no post types selected, well then return
     if (count($types) < 1 && $page_q == "") {
         return '';
     } else {
         $words = implode("','", $types);
         $post_types = "(asp_index.post_type IN ('{$words}') {$page_q})";
     }
     /*---------------------------------------------------------------*/
     // ------------------------ Categories/taxonomies ----------------------
     if (!isset($options['categoryset']) || $options['categoryset'] == "") {
         $options['categoryset'] = array();
     }
     if (!isset($options['termset']) || $options['termset'] == "") {
         $options['termset'] = array();
     }
     /*
     	By default it's 'AND', so all the categories must fit in order to show
     	that result.
     */
     $term_logic = w_isset_def($searchData['term_logic'], 'and');
     $exclude_categories = array();
     $searchData['selected-exsearchincategories'] = w_isset_def($searchData['selected-exsearchincategories'], array());
     $searchData['selected-excludecategories'] = w_isset_def($searchData['selected-excludecategories'], array());
     if (count($searchData['selected-exsearchincategories']) > 0 || count($searchData['selected-excludecategories']) > 0 || count($options['categoryset']) > 0 || $searchData['showsearchincategories'] == 1) {
         aspDebug::start('--searchContent-categories');
         // If the category settings are invisible, ignore the excluded frontend categories, reset to empty array
         if ($searchData['showsearchincategories'] == 0) {
             $searchData['selected-exsearchincategories'] = 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;
         // I am pretty sure this is where the devil is born
         /*
         					AND -> Posts NOT in an array of term ids
         					OR  -> Posts in an array of term ids
         */
         if ($term_logic == 'and') {
             if ($searchData['showsearchincategories'] == 1) {
                 // If the settings is visible, count for the options
                 $exclude_categories = array_diff(array_merge($_needed_cat, $searchData['selected-excludecategories']), $options['categoryset']);
             } else {
                 // ..if the settings is not visible, then only the excluded categories count
                 $exclude_categories = $searchData['selected-excludecategories'];
             }
         } else {
             if ($searchData['showsearchincategories'] == 1) {
                 // If the settings is visible, check which is selected
                 $exclude_categories = count($options['categoryset']) == 0 ? array(-10) : $options['categoryset'];
             } else {
                 // .. otherwise this thing here
                 $exclude_categories = array_diff($_needed_cat, $searchData['selected-excludecategories']);
                 $exclude_categories = count($exclude_categories) == 0 ? array(-10) : $exclude_categories;
             }
         }
         // If every category is selected, then we don't need to filter anything out.
         /*if (count($exclude_categories) == count($_all_cat))
         		$exclude_categories = array();  */
         aspDebug::stop('--searchContent-categories');
     }
     $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());
     if (count($searchData['selected-showterms']) > 0 || count($searchData['selected-excludeterms']) > 0 || count($options['termset']) > 0) {
         aspDebug::start('--searchContent-terms');
         foreach ($searchData['selected-excludeterms'] as $tax => $terms) {
             $exclude_terms = array_merge($exclude_terms, $terms);
         }
         // If the term settings are invisible, ignore the excluded frontend terms, reset to empty array
         if ($searchData['showsearchintaxonomies'] == 0) {
             $searchData['selected-showterms'] = array();
         }
         foreach ($searchData['selected-showterms'] as $tax => $terms) {
             $exclude_showterms = array_merge($exclude_showterms, $terms);
         }
         /*if ($term_logic == 'and')
         			$exclude_terms = array_diff(array_merge($exclude_terms, $exclude_showterms), $options['termset']);
         		else
         			$exclude_terms = count($options['termset']) == 0 ? array(-10) : $options['termset'];  */
         aspDebug::stop('--searchContent-terms');
         /*
         					AND -> Posts NOT in an array of term ids
         					OR  -> Posts in an array of term ids
         */
         if ($term_logic == 'and') {
             if ($searchData['showsearchintaxonomies'] == 1) {
                 // If the settings is visible, count for the options
                 $exclude_terms = array_diff(array_merge($exclude_terms, $exclude_showterms), $options['termset']);
             } else {
                 // ..if the settings is not visible, then only the excluded categories count
                 $exclude_terms = $exclude_terms;
             }
         } else {
             if ($searchData['showsearchintaxonomies'] == 1) {
                 // If the settings is visible, check which is selected
                 $exclude_terms = count($options['termset']) == 0 ? array(-10) : $options['termset'];
             } else {
                 // .. otherwise we bail out, and exclude everything. NOT SOLVED!
                 // But here we would need all term IDs, which is not an option
                 $exclude_terms = array(-15);
             }
         }
     }
     $all_terms = array();
     $all_terms = array_merge($exclude_categories, $exclude_terms);
     //var_dump($all_terms);
     /**
      *  New method since ASP 4.1
      *
      *  This is way more efficient, despite it looks more complicated.
      *  Multiple sub-select is not an issue, since the query can use PRIMARY keys as indexes
      */
     if (count($all_terms) > 0) {
         $words = implode(',', $all_terms);
         // Quick explanation for the AND
         // .. MAIN SELECT: selects all object_ids that are not in the array
         // .. SUBSELECT:   excludes all the object_ids that are part of the array
         // This is used because of multiple object_ids (posts in more than 1 category)
         if ($term_logic == 'and') {
             $term_query = "(\r\n              NOT EXISTS (SELECT * FROM {$wpdb->term_relationships} as xt WHERE xt.object_id = asp_index.doc)\r\n              OR\r\n\t\t\t\t\t\tasp_index.doc IN (\r\n\t\t\t\t\t\t\tSELECT DISTINCT(tr.object_id)\r\n\t\t\t\t\t\t\t\tFROM {$wpdb->term_relationships} AS tr\r\n\t\t\t\t                LEFT JOIN {$wpdb->term_taxonomy} as tt ON tr.term_taxonomy_id = tt.term_taxonomy_id\r\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\t\t\t\t\t\t\ttt.term_id NOT IN ({$words})\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND tr.object_id NOT IN (\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tSELECT DISTINCT(trs.object_id)\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM {$wpdb->term_relationships} AS trs\r\n\t\t\t\t                    LEFT JOIN {$wpdb->term_taxonomy} as tts ON trs.term_taxonomy_id = tts.term_taxonomy_id\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE tts.term_id IN ({$words})\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t\t\t\t)";
         } else {
             $term_query = "(\r\n                NOT EXISTS (SELECT * FROM {$wpdb->term_relationships} as xt WHERE xt.object_id = asp_index.doc)\r\n                OR\r\n                asp_index.doc IN ( SELECT DISTINCT(tr.object_id)\r\n\t\t\t            FROM {$wpdb->term_relationships} AS tr\r\n\t\t\t            LEFT JOIN {$wpdb->term_taxonomy} as tt ON tr.term_taxonomy_id = tt.term_taxonomy_id\r\n\t\t\t            WHERE tt.term_id IN ({$words})\r\n\t\t\t          ) )";
         }
     }
     // ---------------------------------------------------------------------
     /*------------ ttids in the main SELECT, we might not need it ---------*/
     // ttid is only used if grouping by category or filtering by category is active
     $term_select = '""';
     if ($searchData['groupby'] == 1 || count($all_terms) > 0) {
         $term_select = "(SELECT DISTINCT CONCAT('--', GROUP_CONCAT( {$wpdb->term_relationships}.term_taxonomy_id SEPARATOR '----' ), '--')\r\n                FROM {$wpdb->term_relationships}\r\n                WHERE ({$wpdb->term_relationships}.object_id = asp_index.doc) )";
     }
     // ---------------------------------------------------------------------
     /*------------- Custom Fields with Custom selectors -------------*/
     if (isset($options['aspf']) && isset($options['aspfdata'])) {
         aspDebug::start('--searchContent-cf');
         $parts = array();
         foreach ($options['aspfdata'] as $u_data) {
             $data = json_decode(base64_decode($u_data));
             $posted = $this->escape($options['aspf'][$data->asp_f_field]);
             $ll_like = "";
             $rr_like = "";
             if (isset($data->asp_f_operator)) {
                 switch ($data->asp_f_operator) {
                     case 'eq':
                         $operator = "=";
                         $posted = $this->force_numeric($posted);
                         break;
                     case 'neq':
                         $operator = "<>";
                         $posted = $this->force_numeric($posted);
                         break;
                     case 'lt':
                         $operator = "<";
                         $posted = $this->force_numeric($posted);
                         break;
                     case 'gt':
                         $operator = ">";
                         $posted = $this->force_numeric($posted);
                         break;
                     case 'elike':
                         $operator = "=";
                         $ll_like = "'";
                         $rr_like = "'";
                         break;
                     case 'like':
                         $operator = "LIKE";
                         $ll_like = "'%";
                         $rr_like = "%'";
                         break;
                     default:
                         $operator = "=";
                         $posted = $this->force_numeric($posted);
                         break;
                 }
             }
             if ($data->asp_f_type == 'range' && isset($posted['lower'])) {
                 $posted = $this->force_numeric($posted);
                 $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' || $data->asp_f_type == 'hidden' || $data->asp_f_type == 'text') && 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 (w_isset_def($data->asp_f_dropdown_multi, 'asp_unchecked') == 'asp_checked' && 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;
         aspDebug::stop('--searchContent-cf');
     }
     $meta_count = count($this->cf_parts);
     $cf_query = implode(" OR ", $this->cf_parts);
     if ($cf_query == "") {
         $cf_select = "(1)";
         //$cf_having = "";
     } else {
         if (w_isset_def($searchData['cf_logic'], 'AND') == 'AND') {
             $cf_count = $meta_count;
         } else {
             $cf_count = 1;
         }
         /**
          * Far effective method for custom fields, bypassing the HAVING
          */
         $cf_select = "\r\n\t\t\t\t( (\r\n\t                SELECT COUNT(*) FROM {$wpdb->postmeta} WHERE\r\n\t                    {$wpdb->postmeta}.post_id = asp_index.doc\r\n\t                AND\r\n\t                    ({$cf_query})\r\n                ) >= {$cf_count} )";
     }
     /*---------------------------------------------------------------*/
     /*------------------------ Exclude id's -------------------------*/
     if (isset($searchData['excludeposts']) && $searchData['excludeposts'] != "") {
         $exclude_posts = "(asp_index.doc NOT IN (" . $searchData['excludeposts'] . "))";
     } else {
         $exclude_posts = "(1)";
     }
     /*---------------------------------------------------------------*/
     /*------------------------ Term JOIN -------------------------*/
     // No need, this should be indexed...
     /*---------------------------------------------------------------*/
     /*------------------------- WPML filter -------------------------*/
     $wpml_query = "(1)";
     if (isset($options['wpml_lang']) && $options['wpml_lang'] != "" && w_isset_def($searchData['wpml_compatibility'], 1) == 1) {
         global $sitepress;
         $site_lang_selected = false;
         if (is_object($sitepress) && method_exists($sitepress, 'get_default_language')) {
             $site_lang_selected = $sitepress->get_default_language() == $options['wpml_lang'] ? true : false;
         }
         $wpml_query = "asp_index.lang = '" . $this->escape($options['wpml_lang']) . "'";
         /**
          * Imported or some custom post types might have missing translations for the site default language.
          * If the user currently searches on the default language, empty translation string is allowed.
          */
         if ($site_lang_selected) {
             $wpml_query .= " OR asp_index.lang = ''";
         }
     }
     /*---------------------------------------------------------------*/
     /*----------------------- Optimal LIMIT -------------------------*/
     // If custom field filtering is enabled, we need to be careful with the limiting
     if (count($this->cf_parts) > 0) {
         $limit = floor($searchData['maxresults']);
     } else {
         /*$limit = count(get_option('asp_posts_indexed')) / 2;
           $limit = $limit < 200 ? 200 : $limit;
           $limit = $limit > 2000 ? 2000 : $limit;
           $limit = ($limit * 5) < $searchData['maxresults'] ? ($limit * 5) : $limit;
           $limit = floor( $limit );*/
         /**
          * Instead of the flippy-floppy calculations, just set this to 5k
          * This is the pool size for each result set. It is important when using
          * AND and similar logics.
          * DO NOT set it too high, as PHP might run out of memory.
          */
         $limit = 5000;
     }
     /*---------------------------------------------------------------*/
     /*---------------------- Blog switching? ------------------------*/
     if (isset($options['switch_on_preprocess'])) {
         $blog_query = "asp_index.blogid IN (" . implode(',', $searchData['selected-blogs']) . ")";
     } else {
         $blog_query = "asp_index.blogid = " . $current_blog_id;
     }
     /*---------------------------------------------------------------*/
     /*---------------------- Relevance Values -----------------------*/
     $rel_val_title = w_isset_def($searchData["it_title_weight"], 100);
     $rel_val_content = w_isset_def($searchData["it_content_weight"], 20);
     $rel_val_excerpt = w_isset_def($searchData["it_excerpt_weight"], 10);
     $rel_val_terms = w_isset_def($searchData["it_terms_weight"], 10);
     $rel_val_cf = w_isset_def($searchData["it_cf_weight"], 8);
     $rel_val_author = w_isset_def($searchData["it_author_weight"], 8);
     /*---------------------------------------------------------------*/
     /**
      * This is the main query.
      *
      * The ttid field is a bit tricky as the term_taxonomy_id doesn't always equal term_id,
      * so we need the LEFT JOINS :(
      */
     $this->ordering['primary'] = w_isset_def($searchData['orderby_primary'], "relevance DESC");
     $this->ordering['secondary'] = w_isset_def($searchData['orderby'], "post_date DESC");
     $_primary_field = explode(" ", $this->ordering['primary']);
     $this->ordering['primary_field'] = $_primary_field[0];
     $this->query = "\r\n    \t\tSELECT \r\n            asp_index.doc as id,\r\n            asp_index.blogid as blogid,\r\n            'pagepost' as content_type,\r\n            {$term_select} as ttid,\r\n            {$priority_select} AS priority,\r\n            asp_index.post_type AS post_type,\r\n            (\r\n\t             asp_index.title * {$rel_val_title} * {rmod} +\r\n\t             asp_index.content * {$rel_val_content} * {rmod}  +\r\n\t             asp_index.excerpt * {$rel_val_excerpt} * {rmod}  +\r\n\t             asp_index.comment * {$rel_val_terms} * {rmod}  +\r\n\t             asp_index.tag * {$rel_val_terms} * {rmod}  +\r\n\t             asp_index.customfield * {$rel_val_cf} * {rmod}  +\r\n\t             asp_index.author * {$rel_val_author} * {rmod}\r\n            )as relevance\r\n            FROM " . $_prefix . "asp_index as asp_index\r\n            WHERE\r\n                    {like_query}\r\n                AND {$post_types}\r\n                AND {$blog_query}\r\n\t\t\t\tAND ( {$wpml_query} )\r\n                AND {$term_query}\r\n                AND {$cf_select}\r\n                AND {$post_statuses}\r\n                AND {$exclude_posts}\r\n            LIMIT {$limit}";
     $queries = array();
     $results_arr = array();
     //$words = $options['set_exactonly'] == 1 ? array($s) : $_s;
     $words = $_s;
     if ($kw_logic == "orex") {
         $rmod = 1;
         $like_query = "asp_index.term = '" . implode("' OR asp_index.term = '", $words) . "'";
         $queries[] = str_replace(array('{like_query}', '{rmod}'), array($like_query, $rmod), $this->query);
     } else {
         if ($kw_logic == "andex") {
             foreach ($words as $wk => $word) {
                 $rmod = 10 - $wk * 8 < 1 ? 1 : 10 - $wk * 8;
                 $like_query = "asp_index.term = '{$word}'";
                 $queries[] = str_replace(array('{like_query}', '{rmod}'), array($like_query, $rmod), $this->query);
             }
         } else {
             foreach ($words as $wk => $word) {
                 $rmod = 10 - $wk * 8 < 1 ? 1 : 10 - $wk * 8;
                 $like_query = "asp_index.term LIKE '" . $word . "%'";
                 $queries[] = str_replace(array('{like_query}', '{rmod}'), array($like_query, $rmod), $this->query);
                 $like_query = "asp_index.term_reverse LIKE '" . (isset($_sr[$wk]) ? $_sr[$wk] : $sr) . "%'";
                 $queries[] = str_replace(array('{like_query}', '{rmod}'), array($like_query, $rmod), $this->query);
             }
         }
     }
     if (count($queries) > 0) {
         foreach ($queries as $query) {
             $results_arr[] = $wpdb->get_results($query);
         }
     }
     // Merge results depending on the logic
     $results_arr = $this->merge_raw_results($results_arr, $kw_logic);
     // We need to save this array with keys, will need the values later.
     $this->raw_results = $results_arr;
     // Sort results by priority > relevance
     usort($results_arr, array($this, 'compare_by_pr'));
     // Leave only the the LIMIT amount, 500 for non-ajax cases
     if (isset($options['non_ajax_search'])) {
         $results_arr = array_slice($results_arr, 0, 500, true);
     } else {
         $results_arr = array_slice($results_arr, 0, $searchData['maxresults'], true);
     }
     $this->results = $results_arr;
     // Do some pre-processing
     $this->pre_process_results();
     return $this->results;
 }
Exemplo n.º 2
0
 /**
  * Post-processes the results
  *
  * @return array of results
  */
 protected function post_process()
 {
     $pageposts = is_array($this->results) ? $this->results : array();
     $options = $this->options;
     $searchId = $this->searchId;
     $searchData = $this->searchData;
     $s = $this->s;
     $_s = $this->_s;
     // Get multibite or regular functions to variables
     extract($this->mb_f);
     // No post processing is needed on non-ajax search
     if (isset($options['non_ajax_search'])) {
         $this->results = $pageposts;
         return $pageposts;
     }
     if (is_multisite()) {
         $home_url = network_home_url();
     } else {
         $home_url = home_url();
     }
     foreach ($pageposts as $k => $v) {
         $r =& $pageposts[$k];
         $r->title = w_isset_def($r->title, null);
         $r->content = w_isset_def($r->content, null);
         $r->image = w_isset_def($r->image, null);
         $r->author = w_isset_def($r->author, null);
         $r->date = w_isset_def($r->date, null);
     }
     /*--------------------- For Image Parser -----------------------*/
     // Do not select the content field, if it is not used at all
     $get_content = $searchData['showdescription'] == 1 || $searchData['resultstype'] == "isotopic" && $searchData['i_ifnoimage'] == 'description' || $searchData['resultstype'] == "polaroid" && ($searchData['pifnoimage'] == 'descinstead' || $searchData['pshowdesc'] == 1) ? false : true;
     // Do not select excerpt if its not used at all
     $get_excerpt = w_isset_def($searchData['titlefield'], 0) == 1 || w_isset_def($searchData['descriptionfield'], 0) == 1 ? false : true;
     /*---------------------------------------------------------------*/
     aspDebug::start('--searchContent-posptrocess');
     /* Images, title, desc */
     foreach ($pageposts as $k => $v) {
         // Let's simplify things
         $r =& $pageposts[$k];
         if (isset($options['switch_on_preprocess']) && is_multisite()) {
             switch_to_blog($r->blogid);
         }
         $r = apply_filters('asp_result_before_prostproc', $r, $searchId);
         $r->title = apply_filters('asp_result_title_before_prostproc', $r->title, $r->id, $searchId);
         $r->content = apply_filters('asp_result_content_before_prostproc', $r->content, $r->id, $searchId);
         $r->image = apply_filters('asp_result_image_before_prostproc', $r->image, $r->id, $searchId);
         $r->author = apply_filters('asp_result_author_before_prostproc', $r->author, $r->id, $searchId);
         $r->date = apply_filters('asp_result_date_before_prostproc', $r->date, $r->id, $searchId);
         $r->link = get_permalink($v->id);
         // ---- URL FIX for WooCommerce product variations
         if ($r->post_type == 'product_variation' && class_exists('WC_Product_Variation')) {
             $wc_prod_var_o = new WC_Product_Variation($r->id);
             $r->link = $wc_prod_var_o->get_permalink();
         }
         $caching_options = w_false_def(get_option('asp_caching'), get_option('asp_caching_def'));
         $use_bfi = w_isset_def($caching_options['use_bfi_thumb'], 1);
         $image_settings = $searchData['image_options'];
         if ($image_settings['show_images'] != 0) {
             if ($image_settings['image_cropping'] == 0) {
                 // Use the BFI parser, but no caching
                 $im = $this->getBFIimage($r, $get_content, $get_excerpt);
                 if ($im != '') {
                     $r->image = $im;
                 }
             } else {
                 if ($use_bfi == 0) {
                     $im = $this->getCachedImage($r, $get_content, $get_excerpt);
                     if ($im != '') {
                         $r->image = $im;
                     }
                 } else {
                     $im = $this->getBFIimage($r, $get_content, $get_excerpt);
                     if ($im != '' && strpos($im, "mshots/v1") === false) {
                         if (w_isset_def($image_settings['image_transparency'], 1) == 1) {
                             $bfi_params = array('width' => $image_settings['image_width'], 'height' => $image_settings['image_height'], 'crop' => true);
                         } else {
                             $bfi_params = array('width' => $image_settings['image_width'], 'height' => $image_settings['image_height'], 'crop' => true, 'color' => wpdreams_rgb2hex($image_settings['image_bg_color']));
                         }
                         $r->image = bfi_thumb($im, $bfi_params);
                     } else {
                         $r->image = $im;
                     }
                 }
             }
         }
         // If no image and defined, remove the result here, to perevent JS confusions
         if (empty($r->image) && $searchData['resultstype'] == "isotopic" && $searchData['i_ifnoimage'] == 'removeres') {
             unset($pageposts[$k]);
             continue;
         }
         if (!isset($searchData['titlefield']) || $searchData['titlefield'] == "0" || is_array($searchData['titlefield'])) {
             $r->title = get_the_title($r->id);
         } else {
             if ($searchData['titlefield'] == "1") {
                 if ($fn_strlen($r->excerpt) >= 200) {
                     $r->title = wd_substr_at_word($r->excerpt, 200);
                 } else {
                     $r->title = $r->excerpt;
                 }
             } else {
                 $mykey_values = get_post_custom_values($searchData['titlefield'], $r->id);
                 if (isset($mykey_values[0])) {
                     $r->title = $mykey_values[0];
                 } else {
                     $r->title = get_the_title($r->id);
                 }
             }
         }
         $r->title = $this->adv_title($r->title, $r->id);
         if (!isset($searchData['striptagsexclude'])) {
             $searchData['striptagsexclude'] = "<a><span>";
         }
         //remove the search shortcode properly
         add_shortcode('wpdreams_ajaxsearchpro', array($this, 'return_empty_string'));
         if (!isset($searchData['descriptionfield']) || $searchData['descriptionfield'] == "0" || is_array($searchData['descriptionfield'])) {
             if (function_exists('qtrans_getLanguage')) {
                 $r->content = apply_filters('the_content', $r->content, $searchId);
             }
             $_content = strip_tags($r->content, $searchData['striptagsexclude']);
         } else {
             if ($searchData['descriptionfield'] == "1") {
                 $_content = strip_tags($r->excerpt, $searchData['striptagsexclude']);
             } else {
                 if ($searchData['descriptionfield'] == "2") {
                     $_content = strip_tags(get_the_title($r->id), $searchData['striptagsexclude']);
                 } else {
                     $mykey_values = get_post_custom_values($searchData['descriptionfield'], $r->id);
                     if (isset($mykey_values[0])) {
                         $_content = strip_tags($mykey_values[0], $searchData['striptagsexclude']);
                     } else {
                         $_content = strip_tags($r->content, $searchData['striptagsexclude']);
                     }
                 }
             }
         }
         if ($_content == "") {
             $_content = $r->content;
         }
         if (isset($searchData['runshortcode']) && $searchData['runshortcode'] == 1) {
             if ($_content != "") {
                 $_content = apply_filters('the_content', $_content, $searchId);
             }
         }
         if (isset($searchData['stripshortcode']) && $searchData['stripshortcode'] == 1) {
             if ($_content != "") {
                 $_content = strip_shortcodes($_content);
             }
         }
         // Remove styles and scripts
         $_content = preg_replace(array('#<script(.*?)>(.*?)</script>#is', '#<style(.*?)>(.*?)</style>#is'), '', $_content);
         $_content = strip_tags($_content, $searchData['striptagsexclude']);
         // Get the words from around the search phrase, or just the description
         if (w_isset_def($searchData['description_context'], 1) == 1 && count($_s) > 0) {
             $_content = $this->context_find($_content, $_s[0], floor($searchData['descriptionlength'] / 6), $searchData['descriptionlength']);
         } else {
             if ($_content != '' && $fn_strlen($_content) > $searchData['descriptionlength']) {
                 $_content = wd_substr_at_word($_content, $searchData['descriptionlength']) . "...";
             }
         }
         $_content = wd_closetags($_content);
         $r->content = $this->adv_desc($_content, $r->id);
         // -------------------------- Woocommerce Fixes -----------------------------
         // A trick to fix the url
         if ($r->post_type == 'product_variation' && class_exists('WC_Product_Variation')) {
             $r->title = preg_replace("/(Variation) \\#(\\d+) (of)/si", '', $r->title);
             $wc_prod_var_o = new WC_Product_Variation($r->id);
             $r->link = $wc_prod_var_o->get_permalink();
         }
         // --------------------------------------------------------------------------
         // --------------------------------- DATE -----------------------------------
         if ($searchData["showdate"] == 1) {
             $post_time = strtotime($r->date);
             if (w_isset_def($searchData['custom_date'], 0)) {
                 $date_format = w_isset_def($searchData['custom_date_format'], "Y-m-d H:i:s");
             } else {
                 $date_format = get_option('date_format', "Y-m-d") . " " . get_option('time_format', "H:i:s");
             }
             $r->date = @date($date_format, $post_time);
         }
         // --------------------------------------------------------------------------
         $r = apply_filters('asp_result_after_prostproc', $r, $searchId);
         $r->title = apply_filters('asp_result_title_after_prostproc', $r->title, $r->id, $searchId);
         $r->content = apply_filters('asp_result_content_after_prostproc', $r->content, $r->id, $searchId);
         $r->image = apply_filters('asp_result_image_after_prostproc', $r->image, $r->id, $searchId);
         $r->author = apply_filters('asp_result_author_after_prostproc', $r->author, $r->id, $searchId);
         $r->date = apply_filters('asp_result_date_after_prostproc', $r->date, $r->id, $searchId);
     }
     aspDebug::stop('--searchContent-posptrocess');
     if (isset($options['switch_on_preprocess']) && is_multisite()) {
         restore_current_blog();
     }
     /* !Images, title, desc */
     //var_dump($pageposts); die();
     $this->results = $pageposts;
     return $pageposts;
 }
Exemplo n.º 3
0
 /**
  * Post-processes the results
  *
  * @return array of results
  */
 protected function post_process()
 {
     $pageposts = is_array($this->results) ? $this->results : array();
     $options = $this->options;
     $searchId = $this->searchId;
     $searchData = $this->searchData;
     $s = $this->s;
     $_s = $this->_s;
     // No post processing is needed on non-ajax search
     if (isset($options['non_ajax_search'])) {
         $this->results = $pageposts;
         return $pageposts;
     }
     if (is_multisite()) {
         $home_url = network_home_url();
     } else {
         $home_url = home_url();
     }
     foreach ($pageposts as $k => $v) {
         $r =& $pageposts[$k];
         $r->title = w_isset_def($r->title, null);
         $r->content = w_isset_def($r->content, null);
         $r->image = w_isset_def($r->image, null);
         $r->author = w_isset_def($r->author, null);
         $r->date = w_isset_def($r->date, null);
     }
     aspDebug::start('--searchContent-posptrocess');
     /* Images, title, desc */
     foreach ($pageposts as $k => $v) {
         // Let's simplify things
         $r =& $pageposts[$k];
         if (isset($options['switch_on_preprocess']) && is_multisite()) {
             switch_to_blog($r->blogid);
         }
         $r = apply_filters('asp_result_before_prostproc', $r, $searchId);
         $r->title = apply_filters('asp_result_title_before_prostproc', $r->title, $r->id, $searchId);
         $r->content = apply_filters('asp_result_content_before_prostproc', $r->content, $r->id, $searchId);
         $r->image = apply_filters('asp_result_image_before_prostproc', $r->image, $r->id, $searchId);
         $r->author = apply_filters('asp_result_author_before_prostproc', $r->author, $r->id, $searchId);
         $r->date = apply_filters('asp_result_date_before_prostproc', $r->date, $r->id, $searchId);
         $r->link = get_permalink($v->id);
         // ---- URL FIX for WooCommerce product variations
         if ($r->post_type == 'product_variation' && class_exists('WC_Product_Variation')) {
             $wc_prod_var_o = new WC_Product_Variation($r->id);
             $r->link = $wc_prod_var_o->get_permalink();
         }
         $caching_options = w_false_def(get_option('asp_caching'), get_option('asp_caching_def'));
         $use_bfi = w_isset_def($caching_options['use_bfi_thumb'], 1);
         $image_settings = $searchData['image_options'];
         if ($image_settings['show_images'] != 0) {
             if ($image_settings['image_cropping'] == 0) {
                 // Use the BFI parser, but no caching
                 $im = $this->getBFIimage($r);
                 if ($im != '') {
                     $r->image = $im;
                 }
             } else {
                 if ($use_bfi == 0) {
                     $im = $this->getCachedImage($r);
                     if ($im != '') {
                         $r->image = $im;
                     }
                 } else {
                     $im = $this->getBFIimage($r);
                     if ($im != '' && strpos($im, "mshots/v1") === false) {
                         if (w_isset_def($image_settings['image_transparency'], 1) == 1) {
                             $bfi_params = array('width' => $image_settings['image_width'], 'height' => $image_settings['image_height'], 'crop' => true);
                         } else {
                             $bfi_params = array('width' => $image_settings['image_width'], 'height' => $image_settings['image_height'], 'crop' => true, 'color' => wpdreams_rgb2hex($image_settings['image_bg_color']));
                         }
                         $r->image = bfi_thumb($im, $bfi_params);
                     } else {
                         $r->image = $im;
                     }
                 }
             }
         }
         if (!isset($searchData['titlefield']) || $searchData['titlefield'] == "0" || is_array($searchData['titlefield'])) {
             $r->title = get_the_title($r->id);
         } else {
             if ($searchData['titlefield'] == "1") {
                 if (strlen($r->excerpt) >= 200) {
                     $r->title = wd_substr_at_word($r->excerpt, 200);
                 } else {
                     $r->title = $r->excerpt;
                 }
             } else {
                 $mykey_values = get_post_custom_values($searchData['titlefield'], $r->id);
                 if (isset($mykey_values[0])) {
                     $r->title = $mykey_values[0];
                 } else {
                     $r->title = get_the_title($r->id);
                 }
             }
         }
         $r->title = $this->adv_title($r->title, $r->id);
         if (!isset($searchData['striptagsexclude'])) {
             $searchData['striptagsexclude'] = "<a><span>";
         }
         //remove the search shortcode properly
         add_shortcode('wpdreams_ajaxsearchpro', array($this, 'return_empty_string'));
         if (!isset($searchData['descriptionfield']) || $searchData['descriptionfield'] == "0" || is_array($searchData['descriptionfield'])) {
             if (function_exists('qtrans_getLanguage')) {
                 $r->content = apply_filters('the_content', $r->content, $searchId);
             }
             $_content = strip_tags($r->content, $searchData['striptagsexclude']);
         } else {
             if ($searchData['descriptionfield'] == "1") {
                 $_content = strip_tags($r->excerpt, $searchData['striptagsexclude']);
             } else {
                 if ($searchData['descriptionfield'] == "2") {
                     $_content = strip_tags(get_the_title($r->id), $searchData['striptagsexclude']);
                 } else {
                     $mykey_values = get_post_custom_values($searchData['descriptionfield'], $r->id);
                     if (isset($mykey_values[0])) {
                         $_content = strip_tags($mykey_values[0], $searchData['striptagsexclude']);
                     } else {
                         $_content = strip_tags($r->content, $searchData['striptagsexclude']);
                     }
                 }
             }
         }
         if ($_content == "") {
             $_content = $r->content;
         }
         if (isset($searchData['runshortcode']) && $searchData['runshortcode'] == 1) {
             if ($_content != "") {
                 $_content = apply_filters('the_content', $_content, $searchId);
             }
         }
         if (isset($searchData['stripshortcode']) && $searchData['stripshortcode'] == 1) {
             if ($_content != "") {
                 $_content = strip_shortcodes($_content);
             }
         }
         // Remove styles and scripts
         $_content = preg_replace(array('#<script(.*?)>(.*?)</script>#is', '#<style(.*?)>(.*?)</style>#is'), '', $_content);
         $_content = strip_tags($_content, $searchData['striptagsexclude']);
         if ($_content != '' && strlen($_content) > $searchData['descriptionlength']) {
             $_content = wd_substr_at_word($_content, $searchData['descriptionlength']) . "...";
         }
         $_content = wd_closetags($_content);
         $r->content = $this->adv_desc($_content, $r->id);
         // -------------------------- Woocommerce Fixes -----------------------------
         // A trick to fix the url
         if ($r->post_type == 'product_variation' && class_exists('WC_Product_Variation')) {
             $r->title = preg_replace("/(Variation) \\#(\\d+) (of)/si", '', $r->title);
             $wc_prod_var_o = new WC_Product_Variation($r->id);
             $r->link = $wc_prod_var_o->get_permalink();
         }
         // --------------------------------------------------------------------------
         $r = apply_filters('asp_result_after_prostproc', $r, $searchId);
         $r->title = apply_filters('asp_result_title_after_prostproc', $r->title, $r->id, $searchId);
         $r->content = apply_filters('asp_result_content_after_prostproc', $r->content, $r->id, $searchId);
         $r->image = apply_filters('asp_result_image_after_prostproc', $r->image, $r->id, $searchId);
         $r->author = apply_filters('asp_result_author_after_prostproc', $r->author, $r->id, $searchId);
         $r->date = apply_filters('asp_result_date_after_prostproc', $r->date, $r->id, $searchId);
     }
     aspDebug::stop('--searchContent-posptrocess');
     if (isset($options['switch_on_preprocess']) && is_multisite()) {
         restore_current_blog();
     }
     /* !Images, title, desc */
     //var_dump($pageposts); die();
     $this->results = $pageposts;
     return $pageposts;
 }
Exemplo n.º 4
0
 function ajaxsearchpro_search($forceMulti = false, $dontGroup = false)
 {
     global $wpdb;
     global $switched;
     global $search;
     $multi_posts = array();
     // Posts/Custom Posts arranged by Multisite id
     $perf_options = get_option('asp_performance');
     $caching_options = w_boolean_def(get_option('asp_caching'), get_option('asp_caching_def'));
     if (w_isset_def($perf_options['enabled'], 1)) {
         $performance = new wpd_Performance('asp_performance_stats');
         $performance->start_measuring();
     }
     /*print "in ajaxsearchpro_search();";
       print_r(array()); return;  */
     $s = $_POST['aspp'];
     $s = apply_filters('asp_search_phrase_before_cleaning', $s);
     $s = stripcslashes($s);
     $s = trim($s);
     $s = preg_replace('/\\s+/', ' ', $s);
     $s = apply_filters('asp_search_phrase_after_cleaning', $s);
     $id = (int) $_POST['asid'];
     $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($wpdb->prepare("UPDATE " . $_prefix . "ajaxsearchpro_statistics SET num=num+1, last_date=%d WHERE (keyword='%s' AND search_id=%d)", time(), strip_tags($s), $id));
         if ($in == false) {
             $wpdb->query($wpdb->prepare("INSERT INTO " . $_prefix . "ajaxsearchpro_statistics (search_id, keyword, num, last_date) VALUES (%d, '%s', 1, %d)", $id, strip_tags($s), time()));
         }
     }
     $def_data = get_option('asp_defaults');
     $search = $wpdb->get_row("SELECT * FROM " . $_prefix . "ajaxsearchpro WHERE id=" . $id, ARRAY_A);
     $search['data'] = json_decode($search['data'], true);
     $search['data'] = array_merge($def_data, $search['data']);
     //var_dump(current_user_can("manage_options")); die();
     // See if we post the preview data through
     if (!empty($_POST['asp_preview_options']) && current_user_can("manage_options")) {
         //$search['data'] = array_merge($search['data'], unserialize(base64_decode($_POST['asp_preview_options'])));
         $search['data'] = array_merge($search['data'], unserialize(base64_decode($_POST['asp_preview_options'])));
     }
     $sd = $search['data'];
     $search['data']['image_options'] = array('image_cropping' => w_isset_def($caching_options['image_cropping'], 1), 'show_images' => $search['data']['show_images'], 'image_bg_color' => $search['data']['image_bg_color'], 'image_transparency' => $search['data']['image_transparency'], 'image_crop_location' => w_isset_def($search['data']['image_crop_location'], "c"), 'apply_content_filter' => w_isset_def($search['data']['image_apply_content_filter'], 0), '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']);
     if (isset($_POST['asp_get_as_array'])) {
         $search['data']['image_options']['show_images'] = 0;
     }
     // ----------------- 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']['hreswidth']);
             $search['data']['image_options']['image_height'] = wpdreams_width_from_px($search['data']['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'])) {
         if (is_array($_POST['options'])) {
             $search['options'] = $_POST['options'];
         } else {
             parse_str($_POST['options'], $search['options']);
         }
     }
     $blogresults = array();
     $allbuddypresults = array('repliesresults' => array(), 'groupresults' => array(), 'userresults' => array(), 'activityresults' => array());
     $alltermsresults = array();
     $allpageposts = array();
     $pageposts = array();
     $repliesresults = array();
     $allcommentsresults = array();
     $commentsresults = array();
     $userresults = array();
     $attachment_results = array();
     $search['data']['selected-blogs'] = w_isset_def($search['data']['selected-blogs'], array(0 => get_current_blog_id()));
     if ($search['data']['selected-blogs'] === "all") {
         if (is_multisite()) {
             $search['data']['selected-blogs'] = wpdreams_get_blog_list(0, "all", true);
         } else {
             $search['data']['selected-blogs'] = array(0 => get_current_blog_id());
         }
     }
     if (count($search['data']['selected-blogs']) <= 0) {
         $search['data']['selected-blogs'] = array(0 => get_current_blog_id());
     }
     do_action('asp_before_search', $s);
     if (is_array($caching_options) && w_isset_def($caching_options['caching'], 0) && ASP_DEBUG != 1) {
         $filename = ASP_PATH . DIRECTORY_SEPARATOR . "cache" . DIRECTORY_SEPARATOR . md5(json_encode($search['options']) . $s . $_POST['asp_inst_id']) . ".wp";
         $textcache = new wpdreamsTextCache($filename, w_isset_def($caching_options['cachinginterval'], 3600) * 60);
         $cache_content = $textcache->getCache();
         if ($cache_content != false) {
             $cache_content = apply_filters('asp_cached_content', $cache_content);
             do_action('asp_after_search', $s, json_decode($cache_content, true));
             print "cached(" . date("F d Y H:i:s.", filemtime($filename)) . ")";
             print_r($cache_content);
             die;
         }
     }
     // True if only CPT search in the index table is active
     $search_only_it_posts = w_isset_def($search['data']['search_engine'], 'regular') != 'regular' && w_isset_def($search['data']['return_categories'], 0) == 0 && w_isset_def($search['data']['return_terms'], '') == '' && w_isset_def($search['data']['return_attachments'], 0) == 0;
     if (is_multisite() && $search_only_it_posts) {
         // Save huge amounts of server resources by not swapping all the blogs around
         if ($_POST['asid'] == "") {
             $_dposts = new wpdreams_searchDemo(array());
             $dpageposts = $_dposts->search($s);
             $allpageposts = array_merge($allpageposts, $dpageposts);
         } else {
             $search['options']['switch_on_preprocess'] = 1;
             $search['options']['dont_group'] = $dontGroup;
             $params = array('id' => $id, 'data' => $search['data'], 'options' => $search['options']);
             $_posts = new asp_searchIndexTable($params);
             $pageposts = $_posts->search($s);
             do_action('asp_after_pagepost_results', $s, $pageposts);
             $allpageposts = array_merge($allpageposts, $pageposts);
         }
     } else {
         // Regularly swap through blogs
         foreach ($search['data']['selected-blogs'] as $blog) {
             if (is_multisite()) {
                 switch_to_blog($blog);
             }
             aspDebug::start('search-blog-' . $blog);
             if ($_POST['asid'] == "") {
                 $_dposts = new wpdreams_searchDemo(array());
                 $dpageposts = $_dposts->search($s);
                 $allpageposts = array_merge($allpageposts, $dpageposts);
             } else {
                 $search['options']['dont_group'] = $dontGroup;
                 $params = array('id' => $id, 'data' => $search['data'], 'options' => $search['options']);
                 $_terms = new wpdreams_searchTerms($params);
                 $termsresults = $_terms->search($s);
                 $alltermsresults = array_merge($alltermsresults, $termsresults);
                 // For exact matches the regular engine is used
                 if (w_isset_def($search['data']['search_engine'], 'regular') == 'regular' || isset($params['options']['set_exactonly'])) {
                     $_posts = new wpdreams_searchContent($params);
                 } else {
                     $_posts = new asp_searchIndexTable($params);
                 }
                 $pageposts = $_posts->search($s);
                 //var_dump($pageposts);die();
                 $allpageposts = array_merge($allpageposts, $pageposts);
                 if ($forceMulti) {
                     foreach ($pageposts as $kk => $vv) {
                         $pageposts[$kk]->blogid = $blog;
                     }
                     $multi_posts[$blog] = $pageposts;
                 }
                 do_action('asp_after_pagepost_results', $s, $pageposts);
                 $_comments = new wpdreams_searchComments($params);
                 $commentsresults = $_comments->search($s);
                 $allcommentsresults = array_merge($allcommentsresults, $commentsresults);
                 if (w_isset_def($search['data']['return_attachments'], 0)) {
                     $_attachments = new wpdreams_searchAttachments($params);
                     $attachment_results = array_merge($attachment_results, $_attachments->search($s));
                 }
                 do_action('asp_after_attachment_results', $s, $attachment_results);
             }
         }
     }
     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 (w_isset_def($search['data']['user_search'], 0)) {
         $_users = new wpdreams_searchUsers($params);
         $userresults = $_users->search($s);
     }
     do_action('asp_after_user_results', $s, $userresults);
     aspDebug::stop('search-blog-' . $blog);
     if (is_multisite()) {
         restore_current_blog();
     }
     $_blogs = new wpdreams_searchBlogs($params);
     $blogresults = $_blogs->search($s);
     $alltermsresults = apply_filters('asp_terms_results', $alltermsresults, $id);
     $allpageposts = apply_filters('asp_pagepost_results', $allpageposts, $id);
     $allcommentsresults = apply_filters('asp_comment_results', $allcommentsresults, $id);
     $buddypresults = apply_filters('asp_buddyp_results', $buddypresults, $id);
     $blogresults = apply_filters('asp_blog_results', $blogresults, $id);
     $userresults = apply_filters('asp_user_results', $userresults, $id);
     $attachment_results = apply_filters('asp_attachment_results', $attachment_results, $id);
     /* 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]);
             }
         }
     }
     // Results as array, unordered
     $results_arr = array('terms' => $alltermsresults, 'blogs' => $blogresults, 'bp_activities' => $allbuddypresults['activityresults'], 'comments' => $allcommentsresults, 'bp_groups' => $allbuddypresults['groupresults'], 'bp_users' => $userresults, 'post_page_cpt' => $allpageposts, 'attachments' => $attachment_results);
     $results_order = w_isset_def($search['data']['results_order'], 'terms|blogs|bp_activities|comments|bp_groups|bp_users|post_page_cpt|attachments');
     if (strpos($results_order, 'attachments') === false) {
         $results_order .= "|attachments";
     }
     // These keys are in the right order
     $results_order_arr = explode('|', $results_order);
     // Grouping again, respecting ordering
     if ($search['data']['resultstype'] == 'vertical' && ($search['data']['groupby'] == 1 || $search['data']['groupby'] == 2) && !$forceMulti) {
         $results = $allpageposts;
         $results['items'] = array();
         $results['grouped'] = 1;
         // CPM
         if (count($allpageposts) > 0) {
             $i = 9000 + strpos($results_order, 'post_page_cpt');
             $results['items'][$i] = array();
             $results['items'][$i]['data'] = $allpageposts;
             $results['items'][$i]['digdeeper'] = 1;
         }
         // Term results
         if (count($alltermsresults) > 0) {
             $num = $search['data']['showpostnumber'] == 1 ? " (" . count($alltermsresults) . ")" : "";
             $i = 9000 + strpos($results_order, 'terms');
             $results['items'][$i] = array();
             $results['items'][$i]['name'] = asp_icl_t("Term group header", w_isset_def($search['data']['term_group_text'], 'Terms')) . $num;
             $results['items'][$i]['data'] = $alltermsresults;
             $results['items'][$i]['digdeeper'] = 0;
             $results['grouped'] = 1;
         }
         // Blog results
         if (count($blogresults) > 0) {
             $num = $search['data']['showpostnumber'] == 1 ? " (" . count($blogresults) . ")" : "";
             $i = 9000 + strpos($results_order, 'blogs');
             $results['items'][$i] = array();
             $results['items'][$i]['name'] = asp_icl_t("Blog results group header", $search['data']['blogresultstext']) . $num;
             $results['items'][$i]['data'] = $blogresults;
             $results['items'][$i]['digdeeper'] = 0;
             $results['grouped'] = 1;
         }
         // Activity results
         if (count($allbuddypresults['activityresults']) > 0) {
             $num = $search['data']['showpostnumber'] == 1 ? " (" . count($allbuddypresults['activityresults']) . ")" : "";
             $i = 9000 + strpos($results_order, 'bp_activities');
             $results['items'][$i] = array();
             $results['items'][$i]['name'] = asp_icl_t("BuddyPress activity group header", $search['data']['bbpressreplytext']) . $num;
             $results['items'][$i]['data'] = $allbuddypresults['activityresults'];
             $results['items'][$i]['digdeeper'] = 0;
             $results['grouped'] = 1;
         }
         // Comments results
         if (count($allcommentsresults) > 0) {
             $num = $search['data']['showpostnumber'] == 1 ? " (" . count($allcommentsresults) . ")" : "";
             $i = 9000 + strpos($results_order, 'comments');
             $results['items'][$i] = array();
             $results['items'][$i]['name'] = asp_icl_t("Group by comments header", $search['data']['commentstext']) . $num;
             $results['items'][$i]['data'] = $allcommentsresults;
             $results['items'][$i]['digdeeper'] = 0;
             $results['grouped'] = 1;
         }
         // Buddypress groups
         if (count($allbuddypresults['groupresults']) > 0) {
             $num = $search['data']['showpostnumber'] == 1 ? " (" . count($allbuddypresults['groupresults']) . ")" : "";
             $i = 9000 + strpos($results_order, 'bp_groups');
             $results['items'][$i] = array();
             $results['items'][$i]['name'] = asp_icl_t("BuddyPress group header", $search['data']['bbpressgroupstext']) . $num;
             $results['items'][$i]['data'] = $allbuddypresults['groupresults'];
             $results['items'][$i]['digdeeper'] = 0;
             $results['grouped'] = 1;
         }
         // Users
         if (count($userresults) > 0) {
             $num = $search['data']['showpostnumber'] == 1 ? " (" . count($userresults) . ")" : "";
             $i = 9000 + strpos($results_order, 'bp_users');
             $results['items'][$i] = array();
             $results['items'][$i]['name'] = asp_icl_t("User group header", $search['data']['bbpressuserstext']) . $num;
             $results['items'][$i]['data'] = $userresults;
             $results['items'][$i]['digdeeper'] = 0;
             $results['grouped'] = 1;
         }
         // Attachments
         if (count($attachment_results) > 0) {
             $num = $search['data']['showpostnumber'] == 1 ? " (" . count($attachment_results) . ")" : "";
             $i = 9000 + strpos($results_order, 'attachments');
             $results['items'][$i] = array();
             $results['items'][$i]['name'] = asp_icl_t("Attachment group header", w_isset_def($search['data']['attachment_group_text'], 'Attachments')) . $num;
             $results['items'][$i]['data'] = $attachment_results;
             $results['items'][$i]['digdeeper'] = 0;
             $results['grouped'] = 1;
         }
         if (isset($results['items']) && count($results['items']) > 0) {
             ksort($results['items']);
         } else {
             $results = array();
         }
     } else {
         $results = array();
         foreach ($results_order_arr as $rk => $rv) {
             $results = array_merge($results, $results_arr[$rv]);
         }
     }
     if (count($results) <= 0 && $search['data']['keywordsuggestions']) {
         $keywords = array();
         $types = array();
         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']);
         }
         foreach (w_isset_def($search['data']['selected-keyword_suggestion_source'], array('google')) as $source) {
             $remaining_count = w_isset_def($sd['keyword_suggestion_count'], 10) - count($keywords);
             if ($remaining_count <= 0) {
                 break;
             }
             $taxonomy = "";
             // Check if this is a taxonomy
             if (strpos($source, 'xtax_') !== false) {
                 $taxonomy = str_replace('xtax_', '', $source);
                 $source = "terms";
             }
             //$class_name = "wpd_" . $source . "KeywordSuggest";
             $t = new wpd_keywordSuggest($source, array('maxCount' => $remaining_count, 'maxCharsPerWord' => w_isset_def($sd['keyword_suggestion_length'], 50), 'postTypes' => $types, 'lang' => $sd['keywordsuggestionslang'], 'overrideUrl' => '', 'taxonomy' => $taxonomy));
             $keywords = array_merge($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, $id);
     do_action('asp_after_search', $s, $results, $id);
     //
     if (w_isset_def($perf_options['enabled'], 1)) {
         $performance->stop_measuring();
         //$performance->dump_data();
     }
     // If preview, we need the details
     if (isset($_POST['action']) && $_POST['action'] == "ajaxsearchpro_preview") {
         print "wassup!";
         require_once ASP_PATH . "backend" . DIRECTORY_SEPARATOR . "settings" . DIRECTORY_SEPARATOR . "types.inc.php";
         parse_str($_POST['formdata'], $preview_params);
         $preview_params = wpdreams_parse_params($preview_params);
         $preview_params = wp_parse_args($preview_params, $search['data']);
         $html_results = asp_generate_html_results($results, $preview_params, $search['data']['resultstype']);
     } else {
         $html_results = asp_generate_html_results($results, $search['data'], $search['data']['resultstype']);
     }
     if (is_array($caching_options) && w_isset_def($caching_options['caching'], 0) && ASP_DEBUG != 1) {
         $cache_content = $textcache->setCache('!!ASPSTART!!' . $html_results . "!!ASPEND!!");
     }
     // Override from hooks.php
     if (isset($_POST['asp_get_as_array'])) {
         if ($forceMulti) {
             $results['_multi'] = $results;
         }
         return $results;
     }
     /* Clear output buffer, possible warnings */
     print "!!ASPSTART!!";
     //var_dump($results);die();
     //print_r(json_encode($results));
     print_r($html_results);
     print "!!ASPEND!!";
     die;
 }