function getResults($q) { global $wpdb; $q = $this->escape($q); $count = $this->maxCount - count($this->res); $words = implode("','", $this->postTypes); $post_types = "({$wpdb->posts}.post_type IN ('" . $words . "') )"; $pre = $this->matchStart ? "" : "%"; if ($count <= 0) { return; } $the_query = "\n SELECT\n ID as id,\n post_title as title\n FROM {$wpdb->posts}\n WHERE\n post_title LIKE '" . $pre . "{$q}%' AND\n {$post_types} AND\n post_status = 'publish'\n LIMIT {$count}\n "; $results = $wpdb->get_results($the_query, OBJECT); // The Loop if (is_array($results)) { foreach ($results as $res) { $t = strtolower(get_the_title($res->id)); if ($q != $t && !in_array($t, $this->res) && '' != ($str = wd_substr_at_word($t, $this->maxCharsPerWord))) { if ($this->matchStart && strpos($t, $q) === 0) { $this->res[] = $str; } elseif (!$this->matchStart) { $this->res[] = $str; } } } } }
/** * The search function * * @return array of results */ protected function do_search() { global $wpdb; $commentsresults = array(); if (isset($wpdb->base_prefix)) { $_prefix = $wpdb->base_prefix; } else { $_prefix = $wpdb->prefix; } $options = $this->options; $searchData = $this->searchData; $s = $this->s; $_s = $this->_s; if ($options['set_incomments'] && count($_s) > 0) { $like = "lower({$wpdb->comments}.comment_content) REGEXP '" . implode('|', $_s) . "'"; $querystr = "\r\n \t\tSELECT \r\n {$wpdb->comments}.comment_ID as id,\r\n {$wpdb->comments}.comment_post_ID as post_id,\r\n {$wpdb->comments}.user_id as user_id,\r\n {$wpdb->comments}.comment_content as content,\r\n 'comment' as content_type,\r\n {$wpdb->comments}.comment_date as date\r\n \t\tFROM {$wpdb->comments}\r\n \t\tWHERE\r\n ({$wpdb->comments}.comment_approved=1)\r\n AND\r\n (" . $like . ")\r\n \t\tORDER BY {$wpdb->comments}.comment_ID DESC\r\n \t\tLIMIT " . $searchData['maxresults']; //var_dump($querystr); $commentsresults = $wpdb->get_results($querystr, OBJECT); if (is_array($commentsresults)) { foreach ($commentsresults as $k => $v) { $commentsresults[$k]->link = get_comment_link($v->id); $commentsresults[$k]->author = get_comment_author($v->id); $commentsresults[$k]->title = wd_substr_at_word($commentsresults[$k]->content, 40) . "..."; } } } $this->results = $commentsresults; return $commentsresults; }
function getKeywords($q) { $q = str_replace(' ', '+', $q); $method = $this->can_get_file(); if ($method == false) { return array('Error: The fopen url wrapper is not enabled on your server!'); } $_content = $this->url_get_contents($this->url . $q, $method); if ($_content == null || $_content == "") { return array(); } if (function_exists('mb_convert_encoding')) { $_content = mb_convert_encoding($_content, "UTF-8"); } try { $xml = simplexml_load_string($_content); if ($xml == null || $xml === '') { return array(); } $json = json_encode($xml); $array = json_decode($json, TRUE); $res = array(); $keywords = array(); if (isset($array['CompleteSuggestion'])) { foreach ($array['CompleteSuggestion'] as $k => $v) { if (isset($v['suggestion'])) { $keywords[] = $v['suggestion']['@attributes']['data']; } elseif (isset($v[0])) { $keywords[] = $v[0]['@attributes']['data']; } } } foreach ($keywords as $keyword) { $t = strtolower($keyword); if ($t != $q && '' != ($str = wd_substr_at_word($t, $this->maxCharsPerWord))) { if ($this->matchStart && strpos($q, $t) === 0) { $res[] = $str; } elseif (!$this->matchStart) { $res[] = $str; } } } $res = array_slice($res, 0, $this->maxCount); if (count($res) > 0) { return $res; } else { return array(); } } catch (Exception $e) { return array(); } }
function getKeywords($q) { $res = array(); $tags = get_terms(array($this->taxonomy), array('search' => $q, 'hide_empty' => false)); foreach ($tags as $tag) { $t = strtolower($tag->name); if ($t != $q && '' != ($str = wd_substr_at_word($t, $this->maxCharsPerWord))) { if ($this->matchStart && strpos($q, $t) === 0) { $res[] = $str; } elseif (!$this->matchStart) { $res[] = $str; } } } return $res; }
function getKeywords($q) { $res = array(); $tags = get_tags(array('search' => $q, 'number' => $this->maxCount)); foreach ($tags as $tag) { $t = strtolower($tag->name); if ($t != $q && '' != ($str = wd_substr_at_word($t, $this->maxCharsPerWord))) { if ($this->matchStart && strpos($t, $q) === 0) { $res[] = $str; } elseif (!$this->matchStart) { $res[] = $str; } } } return $res; }
function getKeywords($q) { global $wpdb; $keywords = array(); $res = array(); $_keywords = $wpdb->get_results("SELECT keyword FROM " . $wpdb->base_prefix . "ajaxsearchpro_statistics WHERE keyword LIKE '" . $q . "%' ORDER BY num desc", ARRAY_A); foreach ($_keywords as $k => $v) { $keywords[] = $v['keyword']; } foreach ($keywords as $keyword) { $t = strtolower($keyword); if ($t != $q && '' != ($str = wd_substr_at_word($t, $this->maxCharsPerWord))) { if ($this->matchStart && strpos($q, $t) === 0) { $res[] = $str; } elseif (!$this->matchStart) { $res[] = $str; } } } return $res; }
/** * The search function * * @return array|string */ protected function do_search() { global $wpdb; if (isset($wpdb->base_prefix)) { $_prefix = $wpdb->base_prefix; } else { $_prefix = $wpdb->prefix; } $options = $this->options; $searchData = $this->searchData; $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 if ($kw_logic == 'orex') { $_si = "[[:<:]]" . implode('[[:>:]]|[[:<:]]', $_s) . "[[:>:]]"; } else { $_si = implode('|', $_s); } // imploded phrase for regexp $_si = $_si != '' ? $_si : $s; $repliesresults = array(); $userresults = array(); $groupresults = array(); $activityresults = array(); $words = $options['set_exactonly'] == 1 ? array($s) : $_s; $regexp_words = count($_s > 0) ? implode('|', $_s) : $s; if (function_exists('bp_core_get_user_domain')) { $parts = array(); $relevance_parts = array(); /*----------------------- User query ---------------------------*/ // User query had been replaced with user results.. /*---------------------------------------------------------------*/ /*----------------------- Groups query --------------------------*/ if ($searchData['search_in_bp_groups'] && bp_is_active('groups')) { $parts = array(); $relevance_parts = array(); /*------------------------- Statuses ----------------------------*/ $statuses = array(); if ($searchData['search_in_bp_groups_public'] == 1) { $statuses[] = 'public'; } if ($searchData['search_in_bp_groups_private'] == 1) { $statuses[] = 'private'; } if ($searchData['search_in_bp_groups_hidden'] == 1) { $statuses[] = 'hidden'; } if (count($statuses) < 1) { return ''; } $swords = implode('|', $statuses); $group_statuses = "(lower(" . $wpdb->prefix . "bp_groups.status) REGEXP '{$swords}')"; /*---------------------------------------------------------------*/ /*------------------------- Title query -------------------------*/ if ($kw_logic == 'or' || $kw_logic == 'and') { $op = strtoupper($kw_logic); if (count($_s) > 0) { $_like = implode("%' " . $op . " lower(" . $wpdb->prefix . "bp_groups.name) LIKE '%", $words); } else { $_like = $s; } $parts[] = "( lower(" . $wpdb->prefix . "bp_groups.name) LIKE '%" . $_like . "%' )"; } else { $_like = array(); $op = $kw_logic == 'andex' ? 'AND' : 'OR'; foreach ($words as $word) { $_like[] = "\r\n (lower(" . $wpdb->prefix . "bp_groups.name) LIKE '% " . $word . " %'\r\n OR lower(" . $wpdb->prefix . "bp_groups.name) LIKE '" . $word . " %'\r\n OR lower(" . $wpdb->prefix . "bp_groups.name) LIKE '% " . $word . "'\r\n OR lower(" . $wpdb->prefix . "bp_groups.name) = '" . $word . "')"; } $parts[] = "(" . implode(' ' . $op . ' ', $_like) . ")"; } /*$words = $options['set_exactonly'] == 1 ? $s : $_si; if ($kw_logic == 'or' || $kw_logic == 'orex') { $parts[] = "(lower(" . $wpdb->prefix . "bp_groups.name) REGEXP '$words')"; } else { if (count($_s) > 0) $and_like = implode("$r_sign' AND lower(" . $wpdb->prefix . "bp_groups.name) RLIKE '$l_sign", $_s); else $and_like = $s; $parts[] = "lower(" . $wpdb->prefix . "bp_groups.name) RLIKE '$l_sign" . $and_like . "$r_sign'"; }*/ $relevance_parts[] = "(case when\r\n (lower(" . $wpdb->prefix . "bp_groups.name) REGEXP '{$regexp_words}')\r\n then {$searchData['titleweight']} else 0 end)"; $relevance_parts[] = "(case when\r\n (lower(" . $wpdb->prefix . "bp_groups.name) = '{$s}')\r\n then {$searchData['etitleweight']} else 0 end)"; // The first word relevance is higher if (count($_s) > 0) { $relevance_parts[] = "(case when\r\n (lower(" . $wpdb->prefix . "bp_groups.name) REGEXP '" . $_s[0] . "')\r\n then {$searchData['etitleweight']} else 0 end)"; } /*---------------------------------------------------------------*/ /*---------------------- Description query ----------------------*/ if ($kw_logic == 'or' || $kw_logic == 'and') { $op = strtoupper($kw_logic); if (count($_s) > 0) { $_like = implode("%' " . $op . " lower(" . $wpdb->prefix . "bp_groups.description) LIKE '%", $words); } else { $_like = $s; } $parts[] = "( lower(" . $wpdb->prefix . "bp_groups.description) LIKE '%" . $_like . "%' )"; } else { $_like = array(); $op = $kw_logic == 'andex' ? 'AND' : 'OR'; foreach ($words as $word) { $_like[] = "\r\n (lower(" . $wpdb->prefix . "bp_groups.description) LIKE '% " . $word . " %'\r\n OR lower(" . $wpdb->prefix . "bp_groups.description) LIKE '" . $word . " %'\r\n OR lower(" . $wpdb->prefix . "bp_groups.description) LIKE '% " . $word . "'\r\n OR lower(" . $wpdb->prefix . "bp_groups.description) = '" . $word . "')"; } $parts[] = "(" . implode(' ' . $op . ' ', $_like) . ")"; } /*if ($kw_logic == 'or' || $kw_logic == 'orex') { $parts[] = "(lower(" . $wpdb->prefix . "bp_groups.description) REGEXP '$words')"; } else { if (count($_s) > 0) $and_like = implode("$r_sign' AND lower(" . $wpdb->prefix . "bp_groups.description) RLIKE '$l_sign", $_s); else $and_like = $s; $parts[] = "lower(" . $wpdb->prefix . "bp_groups.description) RLIKE '$l_sign" . $and_like . "$r_sign'"; }*/ $relevance_parts[] = "(case when\r\n (lower(" . $wpdb->prefix . "bp_groups.description) REGEXP '{$regexp_words}')\r\n then {$searchData['contentweight']} else 0 end)"; $relevance_parts[] = "(case when\r\n (lower(" . $wpdb->prefix . "bp_groups.description) = '{$s}')\r\n then {$searchData['econtentweight']} else 0 end)"; /*---------------------------------------------------------------*/ /*------------------------- Build like --------------------------*/ $like_query = implode(' OR ', $parts); if ($like_query == "") { $like_query = "(1)"; } else { $like_query = "({$like_query})"; } /*---------------------------------------------------------------*/ /*---------------------- Build relevance ------------------------*/ $relevance = implode(' + ', $relevance_parts); if ($searchData['userelevance'] != 1 || $relevance == "") { $relevance = "(1)"; } else { $relevance = "({$relevance})"; } /*---------------------------------------------------------------*/ $querystr = "\r\n SELECT\r\n " . $wpdb->prefix . "bp_groups.id as id,\r\n " . $wpdb->prefix . "bp_groups.name as title,\r\n " . $wpdb->prefix . "bp_groups.description as content,\r\n " . $wpdb->prefix . "bp_groups.date_created as date,\r\n {$wpdb->users}.user_nicename as author,\r\n 'bp_group' as content_type,\r\n {$relevance} as relevance\r\n FROM\r\n " . $wpdb->prefix . "bp_groups\r\n LEFT JOIN {$wpdb->users} ON {$wpdb->users}.ID = " . $wpdb->prefix . "bp_groups.creator_id\r\n WHERE\r\n {$group_statuses}\r\n AND {$like_query}\r\n ORDER BY relevance DESC, title ASC"; $groupresults = $wpdb->get_results($querystr, OBJECT); foreach ($groupresults as $k => $v) { $group = new BP_Groups_Group($v->id); $groupresults[$k]->link = bp_get_group_permalink($group); if ($searchData['image_options']['show_images'] == 1) { $avatar_options = array('item_id' => $v->id, 'object' => 'group', 'type' => 'full', 'html' => false); $im = bp_core_fetch_avatar($avatar_options); if ($im != '') { $groupresults[$k]->image = $im; } } if ($groupresults[$k]->content != '') { $groupresults[$k]->content = wd_substr_at_word(strip_tags($groupresults[$k]->content), $searchData['descriptionlength']) . "..."; } } } /*---------------------------------------------------------------*/ /*----------------------- Activity query ------------------------*/ if ($searchData['search_in_bp_activities'] && bp_is_active('groups')) { $parts = array(); $relevance_parts = array(); /*---------------------- Description query ----------------------*/ if ($kw_logic == 'or' || $kw_logic == 'and') { $op = strtoupper($kw_logic); if (count($_s) > 0) { $_like = implode("%' " . $op . " lower(" . $wpdb->prefix . "bp_activity.content) LIKE '%", $words); } else { $_like = $s; } $parts[] = "( lower(" . $wpdb->prefix . "bp_activity.content) LIKE '%" . $_like . "%' )"; } else { $_like = array(); $op = $kw_logic == 'andex' ? 'AND' : 'OR'; foreach ($words as $word) { $_like[] = "\r\n (lower(" . $wpdb->prefix . "bp_activity.content) LIKE '% " . $word . " %'\r\n OR lower(" . $wpdb->prefix . "bp_activity.content) LIKE '" . $word . " %'\r\n OR lower(" . $wpdb->prefix . "bp_activity.content) LIKE '% " . $word . "'\r\n OR lower(" . $wpdb->prefix . "bp_activity.content) = '" . $word . "')"; } $parts[] = "(" . implode(' ' . $op . ' ', $_like) . ")"; } /*$words = $options['set_exactonly'] == 1 ? $s : $_si; if ($kw_logic == 'or' || $kw_logic == 'orex') { $parts[] = "(lower(" . $wpdb->prefix . "bp_activity.content) REGEXP '$words')"; } else { if (count($_s) > 0) $and_like = implode("$r_sign' AND lower(" . $wpdb->prefix . "bp_activity.content) RLIKE '$l_sign", $_s); else $and_like = $s; $parts[] = "lower(" . $wpdb->prefix . "bp_activity.content) RLIKE '$l_sign" . $and_like . "$r_sign'"; }*/ $relevance_parts[] = "(case when\r\n (lower(" . $wpdb->prefix . "bp_activity.content) REGEXP '{$regexp_words}')\r\n then {$searchData['contentweight']} else 0 end)"; $relevance_parts[] = "(case when\r\n (lower(" . $wpdb->prefix . "bp_activity.content) = '{$s}')\r\n then {$searchData['econtentweight']} else 0 end)"; /*---------------------------------------------------------------*/ /*------------------------- Build like --------------------------*/ $like_query = implode(' OR ', $parts); if ($like_query == "") { $like_query = "(1)"; } else { $like_query = "({$like_query})"; } /*---------------------------------------------------------------*/ /*---------------------- Build relevance ------------------------*/ $relevance = implode(' + ', $relevance_parts); if ($searchData['userelevance'] != 1 || $relevance == "") { $relevance = "(1)"; } else { $relevance = "({$relevance})"; } /*---------------------------------------------------------------*/ $querystr = "\r\n SELECT\r\n " . $wpdb->prefix . "bp_activity.id as id,\r\n " . $wpdb->prefix . "bp_activity.content as title,\r\n " . $wpdb->prefix . "bp_activity.content as content,\r\n " . $wpdb->prefix . "bp_activity.date_recorded as date,\r\n {$wpdb->users}.user_nicename as author,\r\n " . $wpdb->prefix . "bp_activity.user_id as author_id,\r\n 'bp_activity' as content_type,\r\n {$relevance} as relevance\r\n FROM\r\n " . $wpdb->prefix . "bp_activity\r\n LEFT JOIN {$wpdb->users} ON {$wpdb->users}.ID = " . $wpdb->prefix . "bp_activity.user_id\r\n WHERE\r\n (" . $wpdb->prefix . "bp_activity.component = 'activity' AND " . $wpdb->prefix . "bp_activity.is_spam = 0)\r\n AND {$like_query}\r\n ORDER BY relevance DESC, title ASC"; $activityresults = $wpdb->get_results($querystr, OBJECT); foreach ($activityresults as $k => $v) { $activityresults[$k]->link = bp_activity_get_permalink($v->id); $activityresults[$k]->image = bp_core_fetch_avatar(array('item_id' => $v->author_id, 'html' => false)); } } do_action('bbpress_init'); } $this->results = array('repliesresults' => $repliesresults, 'groupresults' => $groupresults, 'activityresults' => $activityresults); return $this->results; }
/** * Returns the context of a phrase within a text. * * @param $str string context * @param $needle string context * @param $context int length of the context * @param $maxlength int maximum length of the string in characters * @return string */ function context_find($str, $needle, $context, $maxlength) { $haystack = ' ' . trim($str) . ' '; $fn_strpos = "strpos"; $fn_substr = "substr"; $fn_strlen = "strlen"; // Use multibyte string functions if available if (function_exists('mb_substr')) { $fn_strpos = "mb_strpos"; $fn_substr = "mb_substr"; $fn_strlen = "mb_strlen"; $haystack = mb_strtolower($haystack); $needle = mb_strtolower($needle); } else { $haystack = strtolower($haystack); $needle = strtolower($needle); } if ($i = $fn_strpos($haystack, $needle)) { $start = $i; $end = $i; $spaces = 0; while ($spaces < (int) $context / 2 && $start > 0) { $start--; if ($fn_substr($haystack, $start, 1) == ' ') { $spaces++; } } while ($spaces < $context + 1 && $end < $fn_strlen($haystack)) { $end++; if ($fn_substr($haystack, $end, 1) == ' ') { $spaces++; } } while ($spaces < $context + 1 && $start > 0) { $start--; if ($fn_substr($haystack, $start, 1) == ' ') { $spaces++; } } $result = trim($fn_substr($haystack, $start, $end - $start)); // Somewhere inbetween.. if ($start != 0 && $end < $fn_strlen($haystack)) { return "..." . $result . "..."; } // Beginning if ($start == 0 && $end < $fn_strlen($haystack)) { return $result . "..."; } // End if ($start != 0 && $end == $fn_strlen($haystack)) { return "..." . $result; } // If it is too long, strip it if ($fn_strlen($result) > $maxlength) { return wd_substr_at_word($result, $maxlength) . "..."; } // Else, it is the whole return $result; } else { // If it is too long, strip it if ($fn_strlen($str) > $maxlength) { return wd_substr_at_word($str, $maxlength) . "..."; } return $str; } }
/** * 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; }
/** * Post processing the user results */ protected function post_process() { $userresults = is_array($this->results) ? $this->results : array(); $options = $this->options; $searchData = $this->searchData; $s = $this->s; $_s = $this->_s; foreach ($userresults as $k => $v) { /*--------------------------- Link ------------------------------*/ switch (w_isset_def($searchData['user_search_url_source'], 'default')) { case "bp_profile": if (function_exists('bp_core_get_user_domain')) { $userresults[$k]->link = bp_core_get_user_domain($v->id); } else { $userresults[$k]->link = get_author_posts_url($v->id); } break; case "custom": $userresults[$k]->link = str_replace(array("{USER_ID}", "{USER_LOGIN}", "{USER_NICENAME}", "{USER_DISPLAYNAME}"), array($v->id, $v->user_login, $v->user_nicename, $v->user_display_name), w_isset_def($searchData['user_search_custom_url'], '?author={USER_ID}')); break; default: $userresults[$k]->link = get_author_posts_url($v->id); } /*---------------------------------------------------------------*/ /*-------------------------- Image ------------------------------*/ if (w_isset_def($searchData['user_search_display_images'], 1)) { if (w_isset_def($searchData['user_search_image_source'], 'default') == 'buddypress' && function_exists('bp_core_fetch_avatar')) { $im = bp_core_fetch_avatar(array('item_id' => $v->id, 'html' => false)); if ($im != '') { $userresults[$k]->image = $im; } } else { $im = $this->get_avatar_url($v->id); if ($im != '') { $userresults[$k]->image = $im; } } } /*---------------------------------------------------------------*/ $userresults[$k]->title = $this->adv_title($v->title, $v->id); /*---------------------- Description ----------------------------*/ switch (w_isset_def($searchData['user_search_description_field'], 'bio')) { case 'buddypress_last_activity': $update = get_user_meta($v->id, 'bp_latest_update', true); if (is_array($update) && isset($update['content'])) { $userresults[$k]->content = $update['content']; } if ($userresults[$k]->content != '') { $userresults[$k]->content = wd_substr_at_word(strip_tags($userresults[$k]->content), $searchData['descriptionlength']) . "..."; } else { $userresults[$k]->content = ""; } break; case 'nothing': $userresults[$k]->content = ""; break; default: $content = get_user_meta($v->id, 'description', true); if ($content != '') { $userresults[$k]->content = $content; } if ($userresults[$k]->content != '') { $userresults[$k]->content = wd_substr_at_word(strip_tags($userresults[$k]->content), $searchData['descriptionlength']) . "..."; } else { $userresults[$k]->content = ""; } } $userresults[$k]->content = $this->adv_desc($v->content, $v->id); /*---------------------------------------------------------------*/ } }
/** * Returns the context of a phrase within a text. * * @param $str string context * @param $needle string context * @param $context int length of the context * @param $maxlength int maximum length of the string in characters * @return string */ function context_find($str, $needle, $context, $maxlength) { $haystack = ' ' . trim($str) . ' '; // Get the multibyte or regular string functions to variables extract($this->mb_f); $haystack = $fn_strtolower($haystack); $needle = $fn_strtolower($needle); if ($i = $fn_strpos($haystack, $needle)) { $start = $i; $end = $i; $spaces = 0; while ($spaces < (int) $context / 2 && $start > 0) { $start--; if ($fn_substr($haystack, $start, 1) == ' ') { $spaces++; } } while ($spaces < $context + 1 && $end < $fn_strlen($haystack)) { $end++; if ($fn_substr($haystack, $end, 1) == ' ') { $spaces++; } } while ($spaces < $context + 1 && $start > 0) { $start--; if ($fn_substr($haystack, $start, 1) == ' ') { $spaces++; } } $str_start = $start - 1 < 0 ? 0 : $start - 1; $str_end = $end - 1 < 0 ? 0 : $end - 1; $result = trim($fn_substr($str, $str_start, $str_end - $str_start)); // Somewhere inbetween.. if ($start != 0 && $end < $fn_strlen($haystack)) { return "..." . $result . "..."; } // Beginning if ($start == 0 && $end < $fn_strlen($haystack)) { return $result . "..."; } // End if ($start != 0 && $end == $fn_strlen($haystack)) { return "..." . $result; } // If it is too long, strip it if ($fn_strlen($result) > $maxlength) { return wd_substr_at_word($result, $maxlength) . "..."; } // Else, it is the whole return $result; } else { // If it is too long, strip it if ($fn_strlen($str) > $maxlength) { return wd_substr_at_word($str, $maxlength) . "..."; } return $str; } }