Exemplo n.º 1
0
/**
 * Highlight the search term
 *
 * @since	2.0.0
 *
 * @param	string $content    Post content
 * @return 	string	Post Content
 */
function bsearch_content($content)
{
    global $bsearch_settings, $wp_query;
    if ($wp_query->is_search() && $bsearch_settings['seamless'] && !is_admin() && in_the_loop() && $bsearch_settings['highlight']) {
        $search_query = get_bsearch_query();
        $search_query = preg_quote($search_query, '/');
        $keys = explode(' ', str_replace(array("'", "\"", """), "", $search_query));
        $regEx = '/(?!<[^>]*?>)(' . implode('|', $keys) . ')(?![^<]*?>)/iu';
        $content = preg_replace($regEx, '<span class="bsearch_highlight">$1</span>', $content);
    }
    return apply_filters('bsearch_content', $content);
}
Exemplo n.º 2
0
/**
 * Fetches the search results for the current search query and returns a comma separated string of IDs.
 *
 * @since	1.3.3
 *
 * @return	string	Blank string or comma separated string of search results' IDs
 */
function bsearch_clause_prepare()
{
    global $wp_query, $wpdb;
    $search_ids = '';
    if ($wp_query->is_search) {
        $search_query = get_bsearch_query();
        $matches = get_bsearch_matches($search_query, 0);
        // Fetch the search results for the search term stored in $search_query
        $searches = $matches[0];
        // 0 index contains the search results always
        if ($searches) {
            $search_ids = implode(',', wp_list_pluck($searches, 'ID'));
        }
    }
    /**
     * Filters the string of SEARCH IDs returned
     *
     * @since	2.0.0
     *
     * @return	string	$search_ids	Blank string or comma separated string of search results' IDs
     */
    return apply_filters('bsearch_clause_prepare', $search_ids);
}
Exemplo n.º 3
0
/**
 * Returns an array with the cleaned-up search string at the zero index and possibly a list of terms in the second.
 *
 * @since	1.2
 *
 * @param	mixed $search_query   The search term.
 * @return	array	Cleaned up search string
 */
function get_bsearch_terms($search_query = '')
{
    global $bsearch_settings;
    if ('' == $search_query || empty($search_query)) {
        $search_query = get_bsearch_query();
    }
    $s_array[0] = $search_query;
    $use_fulltext = $bsearch_settings['use_fulltext'];
    /**
    	If use_fulltext is false OR if all the words are shorter than four chars, add the array of search terms.
    	Currently this will disable match ranking and won't be quote-savvy.
    	If we are using fulltext, turn it off unless there's a search word longer than three chars
    	ideally we'd also check against stopwords here
    */
    $search_words = explode(' ', $search_query);
    if ($use_fulltext) {
        $use_fulltext_proxy = false;
        foreach ($search_words as $search_word) {
            if (strlen($search_word) > 3) {
                $use_fulltext_proxy = true;
            }
        }
        $use_fulltext = $use_fulltext_proxy;
    }
    if (!$use_fulltext) {
        // strip out all the fancy characters that fulltext would use
        $search_query = addslashes_gpc($search_query);
        $search_query = preg_replace('/, +/', ' ', $search_query);
        $search_query = str_replace(',', ' ', $search_query);
        $search_query = str_replace('"', ' ', $search_query);
        $search_query = trim($search_query);
        $search_words = explode(' ', $search_query);
        $s_array[0] = $search_query;
        // Save original query at [0]
        $s_array[1] = $search_words;
        // Save array of terms at [1]
    }
    /**
     * Filter array holding the search query and terms
     *
     * @since	1.2
     *
     * @param	array	$s_array	Original query is at [0] and array of terms at [1]
     */
    return apply_filters('get_bsearch_terms', $s_array);
}
/**
 * Change page title. Filters `wp_title`.
 *
 * @since	1.0
 *
 * @param	string $title
 * @return	string	Title of the page
 */
function bsearch_title($title)
{
    if (!is_search()) {
        return $title;
    }
    $search_query = get_bsearch_query();
    if (isset($search_query)) {
        $bsearch_title = sprintf(__('Search Results for "%s" | %s', 'better-search'), $search_query, $title);
    }
    /**
     * Filters the title of the page
     *
     * @since	2.0.0
     *
     * @param	string	$bsearch_title	Title of the page set by Better Search
     * @param	string	$title			Original Title of the page
     * @param	string	$search_query	Search query
     */
    return apply_filters('bsearch_title', $bsearch_title, $title, $search_query);
}
Exemplo n.º 5
0
<?php

/**
 * Default template when there is no template in the theme folder
 *
 * @package Better_Search
 */
/* Set the search query if it is missing */
if (!isset($bsearch_settings)) {
    global $bsearch_settings;
}
$limit = isset($_GET['limit']) ? intval($_GET['limit']) : $bsearch_settings['limit'];
// Read from GET variable
/* Set the search query if it is missing */
if (!isset($search_query)) {
    $search_query = get_bsearch_query();
}
// Get Header
get_header();
?>

	<div id="content" class="bsearch_results_page">

		<?php 
echo get_bsearch_form($search_query);
?>

		<div id="bsearchresults">
			<h1 class="page-title">
				<?php 
echo __('Search Results for: ', 'better-search');
/**
 * Function to fetch search form.
 *
 * @since	1.1
 *
 * @param 	string $search_query   Search query
 * @return 	string	Search form
 */
function get_bsearch_form($search_query)
{
    if ($search_query == '') {
        $search_query = get_bsearch_query();
    }
    $form = '
	<div style="text-align:center"><form method="get" class="bsearchform" action="' . home_url() . '/" >
	<label class="hidden" for="s">' . __('Search for:', 'better-search') . '</label>
	<input type="text" value="' . $search_query . '" name="s" class="s" />
	<input type="submit" class="searchsubmit" value="' . __('Search', 'better-search') . '" />
	</form></div>
	';
    /**
     * Filters the title of the page
     *
     * @since	1.2
     *
     * @param	string	$form	HTML to display the form
     * @param	string	$search_query	Search query
     */
    return apply_filters('get_bsearch_form', $form, $search_query);
}