Beispiel #1
0
<?php

$plugin_info = array('pi_name' => 'Excerpt', 'pi_version' => '1.0', 'pi_author' => 'Hayden Hancock', 'pi_author_url' => 'http://haydenhancock.com', 'pi_description' => 'The excerpt word amount will be 55 words and if the amount is greater than that, then the string "..." will be appended to the excerpt. If the string is less than 55 words, then the content will be returned as is. The 55 word limit can be modified by using the excerpt_length parameter. The "..." string can be modified by using the excerpt_more parameter.', 'pi_usage' => Excerpt::usage());
class Excerpt
{
    var $return_data;
    function excerpt()
    {
        $this->EE =& get_instance();
        $text = $this->EE->TMPL->tagdata;
        // Parameter(s)
        $excerpt_length = $this->EE->TMPL->fetch_param('excerpt_length');
        $excerpt_more = $this->EE->TMPL->fetch_param('excerpt_more');
        // Set defaults
        if (!is_numeric($excerpt_length)) {
            $excerpt_length = 55;
        }
        if ($excerpt_more == '') {
            $excerpt_more = '...';
        }
        $this->return_data = $this->trim_excerpt($text, $excerpt_length, $excerpt_more);
    }
    function trim_excerpt($text, $excerpt_length, $excerpt_more)
    {
        if (strlen($text) < $excerpt_length) {
            return $text;
        }
        $words = explode(' ', preg_replace("/\\s+/", ' ', preg_replace("/(\r\n|\r|\n)/", " ", $text)));
        if (count($words) <= $excerpt_length) {
            return $text;
        }
<?php

if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}
$plugin_info = array('pi_name' => 'Excerpt', 'pi_version' => '1.0.2', 'pi_author' => 'Clayton McIlrath', 'pi_author_url' => 'http://thinkclay.com/', 'pi_description' => 'Limits the number of words in some text, after stripping tags.', 'pi_usage' => Excerpt::usage());
/**
 * Excerpt Class
 *
 * @package			ExpressionEngine
 * @category		Plugin
 * @author			Clayton McIlrath
 * @copyright		Copyright (c) 2010, Chosen, LLC.
 * @link			NA
 */
class Excerpt
{
    var $return_data;
    function __construct()
    {
        $this->EE =& get_instance();
        $this->indicator = $this->EE->TMPL->fetch_param('indicator', '');
        $this->limit = $this->EE->TMPL->fetch_param('limit', 500);
        $this->limit_type = $this->EE->TMPL->fetch_param('limit_type', 'words');
        // cleanup limit parameter
        if (!is_numeric($this->limit)) {
            $this->EE->TMPL->log_item('Excerpt: Error - limit parameter not numeric');
            $this->limit = 500;
        }
        // cleanup limit_type parameter
        if (in_array($this->limit_type, array('words', 'chars')) == FALSE) {