<?php
/* @(#)$KimmoSuominen: formatexcerpt.php,v 1.6 2005/02/20 20:10:48 kim Exp $
 *
 * Copyright (c) 2005 Kimmo Suominen
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer
 *    in the documentation and/or other materials provided with the
 *    distribution.
 * 3. The name of the author may not be used to endorse or promote
 *    products derived from this software without specific prior
 *    written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

/*
Plugin Name: Format Excerpt <br /> (1.5 Bug Fix)
Plugin URI: http://kimmo.suominen.com/sw/wp-1.5-bugs/
Description: Call formatting filters for generated excerpts and RSS excerpts.  You probably want to enable this if you are using Markdown, Textile or other markup filters.
Author: Kimmo Suominen
Version: 1.5.1
Author URI: http://kimmo.suominen.com/
*/

class FormatExcerpt
{
    function FormatExcerpt()
    {
	remove_filter('get_the_excerpt', 'wp_trim_excerpt');
	add_filter('get_the_excerpt', array(&$this, 'fake_excerpt'));

	add_filter('the_excerpt_rss', array(&$this, 'format_rss_excerpt'), 6);
    }

    function fake_excerpt($text)
    {
	global $post;
	if ( '' == $text ) {
	    $text = $post->post_content;
	    $text = apply_filters('the_content', $text);
	    $text = str_replace(']]>', ']]&gt;', $text);
	    $text = strip_tags($text);
	    $excerpt_length = 55;
	    $words = explode(' ', $text, $excerpt_length + 1);
	    if (count($words) > $excerpt_length) {
		array_pop($words);
		array_push($words, '[...]');
		$text = implode(' ', $words);
	    }
	}
	return $text;
    }

    function format_rss_excerpt($text)
    {
	return apply_filters('the_excerpt', $text);
    }
}

$wppFormatExcerpt = new FormatExcerpt;

?>