Plugin Directory

Changeset 231542


Ignore:
Timestamp:
04/21/2010 12:14:15 PM (16 years ago)
Author:
flattr
Message:

Excerpt fix

Location:
flattr/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • flattr/trunk/flattr.php

    r227897 r231542  
    44Plugin URI: http://api.flattr.com/plugins/
    55Description: Give your readers the opportunity to Flattr your effort
    6 Version: 0.4
     6Version: 0.5
    77Author: Flattr.com
    88Author URI: http://flattr.com/
     
    1111// Defines
    1212
    13 define(FLATTR_WP_VERSION, '0.4');
     13define(FLATTR_WP_VERSION, '0.5');
    1414define(FLATTR_WP_SCRIPT,  'http://api.flattr.com/button/load.js');
    1515
     
    2525if (get_option('flattr_aut', 'on') == 'on')
    2626{
     27    remove_filter('get_the_excerpt', 'wp_trim_excerpt');
    2728    add_filter('get_the_excerpt', create_function('$content', 'remove_filter("the_content", "flattr_the_content"); return $content;'), 9);
    2829    add_filter('get_the_excerpt', create_function('$content', 'add_filter("the_content", "flattr_the_content"); return $content;'), 11);
     
    110111    if (strlen($uid) && strlen($cat))
    111112    {
    112         return flattr_permalink($uid, $cat, get_the_title(), get_the_excerpt(), strip_tags(get_the_tag_list('', ',', '')), get_permalink());
     113        return flattr_permalink($uid, $cat, get_the_title(), flattr_get_excerpt(), strip_tags(get_the_tag_list('', ',', '')), get_permalink());
    113114    }
    114115}
     116
     117function flattr_get_excerpt( $excerpt_max_length = 1024 )
     118{
     119    global $post;
     120    $excerpt = $post->post_excerpt;
     121    if (! $excerpt)
     122    {
     123        $excerpt = $post->post_content;
     124            $excerpt = strip_shortcodes( $excerpt );
     125            $excerpt = str_replace(']]>', ']]>', $excerpt);
     126            $excerpt = strip_tags($excerpt);
     127        }
     128
     129        // Try to shorten without breaking words
     130        if ( strlen($excerpt) > $excerpt_max_length )
     131        {
     132            $pos = strpos($excerpt, ' ', $excerpt_max_length);
     133            if ($pos !== false)
     134            {
     135                    $excerpt = substr($excerpt, 0, $pos);
     136            }
     137        }
     138
     139        // If excerpt still too long
     140        if ( strlen($excerpt) > $excerpt_max_length )
     141        {
     142            $excerpt = substr($excerpt, 0, $excerpt_max_length);
     143        }
     144        return $excerpt;
     145}
     146
    115147
    116148function the_flattr_permalink()
  • flattr/trunk/readme.txt

    r227897 r231542  
    3232== Changelog ==
    3333
     34= 0.5 =
     35* Fixed a bug that caused blog posts to display incorrectly when no excerpt was entered.
     36
    3437= 0.4 =
    3538* First public version
    3639
    3740== Upgrade Notice ==
     41
     42= 0.5 =
     43Previous version makes your blog posts display incorrectly if you don't enter an excerpt.
    3844
    3945= 0.4 =
Note: See TracChangeset for help on using the changeset viewer.