Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/16/2011 11:33:09 AM (15 years ago)
Author:
boonebgorges
Message:

Modifies bp_create_excerpt() to take account of HTML tag length when truncating long texts. Thanks to CakePHP for the function. Refactors BP use of bp_create_excerpt(), where necessary, to account for new function argument structure. Reworks bp_activity_truncate_entry() so that already-truncated activity items (like blog posts) do not get a Read More link when they contain HTML. Introduces fallback functions for some multibyte string functions, to make bp_create_excerpt() work properly. Thanks to MediaWiki for these fallbacks. Fixes #3452. Props DJPaul for all the help with this patch.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-filters.php

    r4961 r4989  
    189189        $append_text    = apply_filters( 'bp_activity_excerpt_append_text', __( '[Read more]', 'buddypress' ) );
    190190        $excerpt_length = apply_filters( 'bp_activity_excerpt_length', 358 );
    191         $excerpt        = $text;
    192 
    193         $id = !empty( $activities_template->activity->current_comment->id ) ? 'acomment-read-more-' . $activities_template->activity->current_comment->id : 'activity-read-more-' . bp_get_activity_id();
    194 
    195         if ( strlen( $excerpt ) > $excerpt_length )
    196                 $excerpt = sprintf( '%1$s<span class="activity-read-more" id="%2$s"><a href="%3$s" rel="nofollow">%4$s</a></span>', bp_create_excerpt( $excerpt, $excerpt_length, true, '&hellip;' ), $id, bp_get_activity_thread_permalink(), $append_text );
     191
     192        // Run the text through the excerpt function. If it's too short, the original text will be
     193        // returned.
     194        $excerpt        = bp_create_excerpt( $text, $excerpt_length, array( 'ending' => __( '&hellip;', 'buddypress' ) ) );
     195
     196        // If the text returned by bp_create_excerpt() is different from the original text (ie it's
     197        // been truncated), add the "Read More" link.
     198        if ( $excerpt != $text ) {
     199                $id = !empty( $activities_template->activity->current_comment->id ) ? 'acomment-read-more-' . $activities_template->activity->current_comment->id : 'activity-read-more-' . bp_get_activity_id();
     200
     201                $excerpt = sprintf( '%1$s<span class="activity-read-more" id="%2$s"><a href="%3$s" rel="nofollow">%4$s</a></span>', $excerpt, $id, bp_get_activity_thread_permalink(), $append_text );
     202        }
    197203
    198204        return apply_filters( 'bp_activity_truncate_entry', $excerpt, $text, $append_text );
Note: See TracChangeset for help on using the changeset viewer.