function relevanssi_do_excerpt($t_post, $query)
{
    global $post;
    $old_global_post = NULL;
    if ($post != NULL) {
        $old_global_post = $post;
    }
    $post = $t_post;
    $remove_stopwords = false;
    $terms = relevanssi_tokenize($query, $remove_stopwords, -1, false);
    // These shortcodes cause problems with Relevanssi excerpts
    remove_shortcode('layerslider');
    $content = apply_filters('relevanssi_pre_excerpt_content', $post->post_content, $post, $query);
    $content = apply_filters('the_content', $content);
    $content = apply_filters('relevanssi_excerpt_content', $content, $post, $query);
    $content = relevanssi_strip_invisibles($content);
    // removes <script>, <embed> &c with content
    $content = preg_replace('/(<\\/[^>]+?>)(<[^>\\/][^>]*?>)/', '$1 $2', $content);
    // add spaces between tags to avoid getting words stuck together
    $content = strip_tags($content, get_option('relevanssi_excerpt_allowable_tags', ''));
    // this removes the tags, but leaves the content
    $content = preg_replace("/\n\r|\r\n|\n|\r/", " ", $content);
    //	$content = trim(preg_replace("/\s\s+/", " ", $content));
    $excerpt_data = relevanssi_create_excerpt($content, $terms, $query);
    if (get_option("relevanssi_index_comments") != 'none') {
        $comment_content = relevanssi_get_comments($post->ID);
        $comment_excerpts = relevanssi_create_excerpt($comment_content, $terms, $query);
        if ($comment_excerpts[1] > $excerpt_data[1]) {
            $excerpt_data = $comment_excerpts;
        }
    }
    if (get_option("relevanssi_index_excerpt") != 'none') {
        $excerpt_content = $post->post_excerpt;
        $excerpt_excerpts = relevanssi_create_excerpt($excerpt_content, $terms, $query);
        if ($excerpt_excerpts[1] > $excerpt_data[1]) {
            $excerpt_data = $excerpt_excerpts;
        }
    }
    $start = $excerpt_data[2];
    $excerpt = $excerpt_data[0];
    $excerpt = trim($excerpt);
    $excerpt = apply_filters('relevanssi_excerpt', $excerpt);
    $ellipsis = apply_filters('relevanssi_ellipsis', '...');
    $highlight = get_option('relevanssi_highlight');
    if ("none" != $highlight) {
        if (!is_admin()) {
            $excerpt = relevanssi_highlight_terms($excerpt, $query);
        }
    }
    if (!$start && !empty($excerpt)) {
        $excerpt = $ellipsis . $excerpt;
        // do not add three dots to the beginning of the post
    }
    if (!empty($excerpt)) {
        $excerpt = $excerpt . $ellipsis;
    }
    if (relevanssi_s2member_level($post->ID) == 1) {
        $excerpt = $post->post_excerpt;
    }
    if ($old_global_post != NULL) {
        $post = $old_global_post;
    }
    return $excerpt;
}
Exemplo n.º 2
0
function relevanssi_do_excerpt($post, $query) {
	$remove_stopwords = false;
	$terms = relevanssi_tokenize($query, $remove_stopwords);

	$content = apply_filters('the_content', $post->post_content);
	
	$content = relevanssi_strip_invisibles($content); // removes <script>, <embed> &c with content
	if ('on' == get_option('relevanssi_expand_shortcodes')) {
		if (function_exists("do_shortcode")) {
			$content = do_shortcode($content);
		}
	}
	else {
		if (function_exists("strip_shortcodes")) {
			$content = strip_shortcodes($content);
		}
	}
	$content = strip_tags($content); // this removes the tags, but leaves the content
	
	$content = ereg_replace("/\n\r|\r\n|\n|\r/", " ", $content);
	
	$excerpt_data = relevanssi_create_excerpt($content, $terms);
	
	if (get_option("relevanssi_index_comments") != 'none') {
		$comment_content = relevanssi_get_comments($post->ID);
		$comment_excerpts = relevanssi_create_excerpt($comment_content, $terms);
		if ($comment_excerpts[1] > $excerpt_data[1]) {
			$excerpt_data = $comment_excerpts;
		}
	}

	if (get_option("relevanssi_index_excerpt") != 'none') {
		$excerpt_content = $post->post_excerpt;
		$excerpt_excerpts = relevanssi_create_excerpt($excerpt_content, $terms);
		if ($excerpt_excerpts[1] > $excerpt_data[1]) {
			$excerpt_data = $excerpt_excerpts;
		}
	}
	
	$excerpt = $excerpt_data[0];
	$start = $excerpt_data[2];
	
	$content = apply_filters('get_the_excerpt', $content);
	$content = apply_filters('the_excerpt', $content);	

	$highlight = get_option('relevanssi_highlight');
	if ("none" != $highlight) {
		if (!is_admin()) {
			$excerpt = relevanssi_highlight_terms($excerpt, $query);
		}
	}
	
	if (!$start) {
		$excerpt = "..." . $excerpt;
		// do not add three dots to the beginning of the post
	}
	
	$excerpt = $excerpt . "...";

	return $excerpt;
}