/**
  * 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;
 }
示例#2
0
 protected function post_process()
 {
     $pageposts = is_array($this->results) ? $this->results : array();
     $options = $this->options;
     $searchData = $this->searchData;
     $s = $this->s;
     $_s = $this->_s;
     $performance_options = get_option('asl_performance');
     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);
     }
     /* Images, title, desc */
     foreach ($pageposts as $k => $v) {
         // Let's simplify things
         $r =& $pageposts[$k];
         $r->title = apply_filters('asl_result_title_before_prostproc', $r->title, $r->id);
         $r->content = apply_filters('asl_result_content_before_prostproc', $r->content, $r->id);
         $r->image = apply_filters('asl_result_image_before_prostproc', $r->image, $r->id);
         $r->author = apply_filters('asl_result_author_before_prostproc', $r->author, $r->id);
         $r->date = apply_filters('asl_result_date_before_prostproc', $r->date, $r->id);
         $r->link = get_permalink($v->id);
         $image_settings = $searchData['image_options'];
         if ($image_settings['show_images'] != 0) {
             $im = $this->getBFIimage($r);
             if ($im != '' && strpos($im, "mshots/v1") === false && w_isset_def($performance_options['image_cropping'], 0) == 1) {
                 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);
                 }
             }
         }
         //remove the search shortcodes properly
         add_shortcode('wpdreams_ajaxsearchpro', array($this, 'return_empty_string'));
         add_shortcode('wpdreams_ajaxsearchlite', array($this, 'return_empty_string'));
         if (!isset($searchData['striptagsexclude'])) {
             $searchData['striptagsexclude'] = "<a><span>";
         }
         if (!isset($searchData['descriptionfield']) || $searchData['descriptionfield'] == "0" || is_array($searchData['descriptionfield'])) {
             if (w_isset_def($searchData['strip_shortcodes'], 0) == 1) {
                 $r->content = strip_shortcodes($r->content);
             }
             if (function_exists('qtrans_getLanguage')) {
                 $r->content = apply_filters('the_content', $r->content);
             }
             $_content = strip_tags($r->content);
         } else {
             if ($searchData['descriptionfield'] == "1") {
                 $_content = strip_tags($r->excerpt);
             } else {
                 if ($searchData['descriptionfield'] == "2") {
                     $_content = strip_tags(get_the_title($r->id));
                 } else {
                     $mykey_values = get_post_custom_values($searchData['descriptionfield'], $r->id);
                     if (isset($mykey_values[0])) {
                         $_content = strip_tags($mykey_values[0]);
                     } else {
                         $_content = strip_tags($r->content);
                     }
                 }
             }
         }
         if ($_content == "" && $r->content != '') {
             $_content = $r->content;
         }
         if ($_content != "") {
             $_content = str_replace('[wpdreams_ajaxsearchlite]', "", $_content);
         }
         if ($_content != "") {
             $_content = apply_filters('the_content', $_content);
         }
         // Remove styles and scripts
         $_content = preg_replace(array('#<script(.*?)>(.*?)</script>#is', '#<style(.*?)>(.*?)</style>#is'), '', $_content);
         $_content = strip_tags($_content);
         // 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 != '' && strlen($_content) > $searchData['descriptionlength']) {
                 $_content = wd_substr_at_word($_content, $searchData['descriptionlength']) . "...";
             }
         }
         $_content = wd_closetags($_content);
         $r->content = $_content;
         // -------------------------- 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->title = apply_filters('asl_result_title_after_prostproc', $r->title, $r->id);
         $r->content = apply_filters('asl_result_content_after_prostproc', $r->content, $r->id);
         $r->image = apply_filters('asl_result_image_after_prostproc', $r->image, $r->id);
         $r->author = apply_filters('asl_result_author_after_prostproc', $r->author, $r->id);
         $r->date = apply_filters('asl_result_date_after_prostproc', $r->date, $r->id);
     }
     /* !Images, title, desc */
     //var_dump($pageposts); die();
     $this->results = $pageposts;
     return $pageposts;
 }
示例#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;
     // 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;
 }