Example #1
0
 /**
  * Fetches an image for bfi class
  */
 protected function getBFIimage($post, $get_content = false, $get_excerpt = false)
 {
     if (!isset($post->image) || $post->image == null) {
         $home_url = network_home_url();
         $home_url = home_url();
         if (!isset($post->id)) {
             return "";
         }
         $i = 1;
         $im = "";
         for ($i == 1; $i < 6; $i++) {
             switch ($this->imageSettings['image_source' . $i]) {
                 case "featured":
                     $im = wp_get_attachment_url(get_post_thumbnail_id($post->id));
                     if (is_multisite()) {
                         $im = str_replace(home_url(), network_home_url(), $im);
                     }
                     break;
                 case "content":
                     $content = $get_content ? get_post_field('post_content', $post->id) : $post->content;
                     if ($this->imageSettings['apply_content_filter'] == 1) {
                         $content = apply_filters('the_content', $content);
                     }
                     $im = wpdreams_get_image_from_content($content, 1);
                     if (is_multisite()) {
                         $im = str_replace(home_url(), network_home_url(), $im);
                     }
                     break;
                 case "excerpt":
                     $excerpt = $get_excerpt ? get_post_field('post_excerpt', $post->id) : $post->excerpt;
                     $im = wpdreams_get_image_from_content($excerpt, 1);
                     if (is_multisite()) {
                         $im = str_replace(home_url(), network_home_url(), $im);
                     }
                     break;
                 case "screenshot":
                     $im = 'http://s.wordpress.com/mshots/v1/' . urlencode(get_permalink($post->id)) . '?w=' . $this->imageSettings['image_width'] . '&h=' . $this->imageSettings['image_height'];
                     break;
                 case "post_format":
                     $format = get_post_format($post->id);
                     switch ($format) {
                         case "audio":
                             $im = ASP_URL . "img/post_format/audio.png";
                             break;
                         case "video":
                             $im = ASP_URL . "img/post_format/video.png";
                             break;
                         case "quote":
                             $im = ASP_URL . "img/post_format/quote.png";
                             break;
                         case "image":
                             $im = ASP_URL . "img/post_format/image.png";
                             break;
                         case "gallery":
                             $im = ASP_URL . "img/post_format/gallery.png";
                             break;
                         case "link":
                             $im = ASP_URL . "img/post_format/link.png";
                             break;
                         default:
                             $im = ASP_URL . "img/post_format/default.png";
                             break;
                     }
                     break;
                 case "custom":
                     if ($this->imageSettings['image_custom_field'] != "") {
                         $val = get_post_meta($post->id, $this->imageSettings['image_custom_field'], true);
                         if ($val != null && $val != "") {
                             $im = $val;
                         }
                     }
                     break;
                 case "default":
                     if ($this->imageSettings['image_default'] != "") {
                         $im = $this->imageSettings['image_default'];
                     }
                     break;
                 default:
                     $im = "";
                     break;
             }
             if ($im != null && $im != '') {
                 break;
             }
         }
         return $im;
     } else {
         return $post->image;
     }
 }
Example #2
0
 /**
  * Fetches an image for BFI class
  */
 function getBFIimage($post)
 {
     $searchData = $this->searchData;
     if (!isset($post->image) || $post->image == null) {
         $home_url = network_home_url();
         $home_url = home_url();
         if (!isset($post->id)) {
             return "";
         }
         $i = 1;
         $im = "";
         for ($i == 1; $i < 6; $i++) {
             switch ($this->imageSettings['image_source' . $i]) {
                 case "featured":
                     $im = wp_get_attachment_url(get_post_thumbnail_id($post->id));
                     if (is_multisite()) {
                         $im = str_replace(home_url(), network_home_url(), $im);
                     }
                     break;
                 case "content":
                     if ($searchData['showdescription'] == 0) {
                         $content = get_post_field('post_content', $post->id);
                     } else {
                         $content = $post->content;
                     }
                     $content = apply_filters('the_content', $content);
                     $im = wpdreams_get_image_from_content($content, 1);
                     if (is_multisite()) {
                         $im = str_replace(home_url(), network_home_url(), $im);
                     }
                     break;
                 case "excerpt":
                     $im = wpdreams_get_image_from_content($post->excerpt, 1);
                     if (is_multisite()) {
                         $im = str_replace(home_url(), network_home_url(), $im);
                     }
                     break;
                 case "screenshot":
                     $im = 'http://s.wordpress.com/mshots/v1/' . urlencode(get_permalink($post->id)) . '?w=' . $this->imageSettings['image_width'] . '&h=' . $this->imageSettings['image_height'];
                     break;
                 case "custom":
                     if ($this->imageSettings['image_custom_field'] != "") {
                         $val = get_post_meta($post->id, $this->imageSettings['image_custom_field'], true);
                         if ($val != null && $val != "") {
                             $im = $val;
                         }
                     }
                     break;
                 case "default":
                     if ($this->imageSettings['image_default'] != "") {
                         $im = $this->imageSettings['image_default'];
                     }
                     break;
                 default:
                     $im = "";
                     break;
             }
             if ($im != null && $im != '') {
                 break;
             }
         }
         return $im;
     } else {
         return $post->image;
     }
 }
 protected function post_process()
 {
     $pageposts = $this->results;
     $options = $this->options;
     $searchData = $this->searchData;
     $s = $this->s;
     $_s = $this->_s;
     /* Category filtering */
     $_selected_categories = array();
     if (isset($options['categoryset'])) {
         $_selected_categories = $options['categoryset'];
     }
     $_all_categories = get_all_category_ids();
     if (count($_selected_categories) > 0 && count($_all_categories) != count($_selected_categories)) {
         foreach ($pageposts as $k => $v) {
             if ($v->term_id == null) {
                 $v->term_id = "";
                 continue;
             }
             if ($v->post_type != 'post' && $searchData['pageswithcategories'] != 1) {
                 continue;
             }
             $_term_ids = explode(',', $v->term_id);
             if (count($_term_ids) <= 0) {
                 $_term_ids = array($v->term_id);
             }
             $match = false;
             $_new_terms = array();
             foreach ($_term_ids as $_term_id) {
                 if (in_array($_term_id, $_selected_categories)) {
                     $match = true;
                     $_new_terms[] = $_term_id;
                 }
             }
             if (!$match) {
                 unset($pageposts[$k]);
             } else {
                 $v->term_id = implode(",", $_new_terms);
             }
         }
     }
     /* !Category filtering */
     /* TERM filtering */
     if (isset($options['termset'])) {
         $terms = array();
         $o_terms = array();
         foreach ($options['termset'] as $term => $tax) {
             if ($tax != "0") {
                 $o_terms[$tax][] = $term;
             }
         }
         //var_dump($o_terms);
         foreach ($pageposts as $k => $v) {
             $terms = $o_terms;
             foreach ($terms as $ex_taxonomy => $ex_terms) {
                 $_post_terms = wp_get_post_terms($v->id, $ex_taxonomy);
                 $post_terms = array();
                 if (is_array($_post_terms) && isset($_post_terms[0])) {
                     foreach ($_post_terms as $_term) {
                         $post_terms[] = (int) $_term->term_id;
                     }
                     foreach ($ex_terms as $_term) {
                         /* Get all child terms of the current term */
                         $args = array('child_of' => $_term);
                         $termchildren = get_terms($ex_taxonomy, $args);
                         if (isset($termchildren) && count($termchildren) > 0) {
                             foreach ($termchildren as $child_term) {
                                 if (!in_array((int) $child_term->term_id, $ex_terms)) {
                                     $ex_terms[] = (int) $child_term->term_id;
                                 }
                             }
                         }
                         /* Get the parent term of the current term */
                         $parent = get_term_by('id', $_term, $ex_taxonomy);
                         if (isset($parent) && isset($parent->term_id) && $parent->term_id != 0) {
                             $ex_terms[] = $parent->term_id;
                         }
                     }
                     $diff = array_unique(array_diff($post_terms, $ex_terms));
                     //var_dump($post_terms);
                     //var_dump($ex_terms);
                     //var_dump($diff);
                     //exit;
                     if (!is_array($diff) || count($diff) < 1) {
                         unset($pageposts[$k]);
                         break;
                     }
                 }
             }
         }
     }
     /* !TERM  filtering */
     /* Images, title, desc */
     foreach ($pageposts as $k => $v) {
         // Let's simplify things
         $r =& $pageposts[$k];
         $r->title = apply_filters('asp_result_title_before_prostproc', $r->title, $r->id);
         $r->content = apply_filters('asp_result_content_before_prostproc', $r->content, $r->id);
         $r->image = apply_filters('asp_result_image_before_prostproc', $r->image, $r->id);
         $r->author = apply_filters('asp_result_author_before_prostproc', $r->author, $r->id);
         $r->date = apply_filters('asp_result_date_before_prostproc', $r->date, $r->id);
         $r->link = get_permalink($v->id);
         $use_timthumb = get_option('asp_usetimbthumb');
         if ($use_timthumb) {
             if ($searchData['settings-imagesettings']['show'] == 1) {
                 $imgs = $searchData['settings-imagesettings'];
                 ksort($imgs['from']);
                 if ($searchData['resultstype'] == 'vertical') {
                     $_width = $imgs['width'];
                     $_height = $imgs['height'];
                 } else {
                     $_width = wpdreams_width_from_px($searchData['hreswidth']);
                     $_vimageratio = $_width / $searchData['selected-imagesettings']['width'];
                     $_height = $_vimageratio * $searchData['selected-imagesettings']['height'];
                 }
                 foreach ($imgs['from'] as $kk => $source) {
                     if ($kk == -11) {
                         continue;
                     }
                     if (isset($r->image) || $r->image != '') {
                         continue;
                     }
                     if ($source == 'featured') {
                         $im = wp_get_attachment_url(get_post_thumbnail_id($v->id));
                     } else {
                         if ($source == 'content') {
                             $im = wpdreams_get_image_from_content($v->content, $imgs['imagenum']);
                         } else {
                             if ($source == 'excerpt') {
                                 $im = wpdreams_get_image_from_content($v->excerpt, $imgs['imagenum']);
                             } else {
                                 if ($source == 'usecustom') {
                                     if (isset($imgs['customname']) && $imgs['customname'] != '') {
                                         $im = get_post_meta($v->id, $imgs['customname'], true);
                                         if ($im != '' && $im != false) {
                                         } else {
                                             continue;
                                         }
                                     } else {
                                         continue;
                                     }
                                 }
                             }
                         }
                     }
                     if ($im !== false && $im != '') {
                         $r->image = plugins_url('/ajax-search-pro/includes/timthumb.php') . '?cc=' . str_replace('#', '', wpdreams_rgb2hex($searchData['imagebg'])) . '&ct=0&q=95&w=' . $_width . '&h=' . $_height . '&src=' . rawurlencode($im);
                         break;
                     }
                 }
             }
         } else {
             if ($searchData['settings-imagesettings']['show'] == 1) {
                 $imgs = $searchData['settings-imagesettings'];
                 ksort($imgs['from']);
                 if ($searchData['resultstype'] == 'vertical') {
                     $_width = $imgs['width'];
                     $_height = $imgs['height'];
                 } else {
                     if ($searchData['resultstype'] == 'horizontal') {
                         $_width = wpdreams_width_from_px($searchData['hreswidth']);
                         $_vimageratio = $_width / $searchData['selected-imagesettings']['width'];
                         $_height = $_vimageratio * $searchData['selected-imagesettings']['height'];
                     } else {
                         $_width = wpdreams_width_from_px($searchData['preswidth']) - 2 * wpdreams_width_from_px($searchData['prespadding']);
                         $_height = $_width;
                     }
                 }
                 foreach ($imgs['from'] as $kk => $source) {
                     if ($kk == -11) {
                         continue;
                     }
                     if (isset($r->image) || $r->image != '') {
                         continue;
                     }
                     // Calculate the image size
                     if ($source == 'featured') {
                         //$im = get_the_post_thumbnail($v->id);
                         $im = wp_get_attachment_url(get_post_thumbnail_id($v->id));
                         //var_dump($im);
                         $img = new wpdreamsImageCache($im, "post" . $v->id, AJAXSEARCHPRO_PATH . DIRECTORY_SEPARATOR . "cache" . DIRECTORY_SEPARATOR, $_width, $_height, -1, $searchData['imagebg']);
                     } else {
                         if ($source == 'content') {
                             $img = new wpdreamsImageCache($v->content, "post" . $v->id, AJAXSEARCHPRO_PATH . DIRECTORY_SEPARATOR . "cache" . DIRECTORY_SEPARATOR, $_width, $_height, $imgs['imagenum'], $searchData['imagebg']);
                         } else {
                             if ($source == 'excerpt') {
                                 $img = new wpdreamsImageCache($v->excerpt, "post" . $v->id, AJAXSEARCHPRO_PATH . DIRECTORY_SEPARATOR . "cache" . DIRECTORY_SEPARATOR, $_width, $_height, $imgs['imagenum'], $searchData['imagebg']);
                             } else {
                                 if ($source == 'usecustom') {
                                     if (isset($imgs['customname']) && $imgs['customname'] != '') {
                                         $im = get_post_meta($v->id, $imgs['customname'], true);
                                         if ($im != '' && $im != false) {
                                             $img = new wpdreamsImageCache($im, "post" . $v->id, AJAXSEARCHPRO_PATH . DIRECTORY_SEPARATOR . "cache" . DIRECTORY_SEPARATOR, $_width, $_height, -1, $searchData['imagebg']);
                                         } else {
                                             continue;
                                         }
                                     } else {
                                         continue;
                                     }
                                 }
                             }
                         }
                     }
                     $res = $img->get_image();
                     if ($res != '') {
                         $r->image = plugins_url('/ajax-search-pro/cache/' . $res);
                         break;
                     }
                 }
             }
         }
         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 = substr($r->excerpt, 0, 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);
                 }
             }
         }
         if (!isset($searchData['striptagsexclude'])) {
             $searchData['striptagsexclude'] = "<a><span>";
         }
         if (!isset($searchData['descriptionfield']) || $searchData['descriptionfield'] == "0" || is_array($searchData['descriptionfield'])) {
             if (function_exists('qtrans_getLanguage')) {
                 $r->content = apply_filters('the_content', $r->content);
             }
             $_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(get_content_w($r->content), $searchData['striptagsexclude']);
                     }
                 }
             }
         }
         if ($_content == "") {
             $_content = $r->content;
         }
         if (isset($searchData['runshortcode']) && $searchData['runshortcode'] == 1) {
             if ($_content != "") {
                 $_content = apply_filters('the_content', $_content);
             }
             if ($_content != "") {
                 $_content = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $_content);
             }
         }
         if (isset($searchData['stripshortcode']) && $searchData['stripshortcode'] == 1) {
             if ($_content != "") {
                 $_content = strip_shortcodes($_content);
             }
         }
         $_content = strip_tags($_content, $searchData['striptagsexclude']);
         if ($_content != '' && strlen($_content) > $searchData['descriptionlength']) {
             $r->content = substr($_content, 0, $searchData['descriptionlength']) . "...";
         } else {
             $r->content = $_content . "...";
         }
         $r->title = apply_filters('asp_result_title_after_prostproc', $r->title, $r->id);
         $r->content = apply_filters('asp_result_content_after_prostproc', $r->content, $r->id);
         $r->image = apply_filters('asp_result_image_after_prostproc', $r->image, $r->id);
         $r->author = apply_filters('asp_result_author_after_prostproc', $r->author, $r->id);
         $r->date = apply_filters('asp_result_date_after_prostproc', $r->date, $r->id);
     }
     /* !Images, title, desc */
     //var_dump($pageposts); die();
     $this->results = $pageposts;
     return $pageposts;
 }