Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/29/2010 03:22:44 PM (14 years ago)
Author:
boonebgorges
Message:

Changes bp_create_excerpt() so that excerpts are generated using character counts rather than word counts. Modifies excerpt_length throughout BP to account for the change. Fixes #1222

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-templatetags.php

    r3607 r3610  
    375375
    376376        $defaults = array(
    377             'length' => 15
     377            'length' => 70
    378378        );
    379379
     
    11161116 * @return str The excerpt text
    11171117 */
    1118 function bp_create_excerpt( $text, $excerpt_length = 55, $filter_shortcodes = true ) { // Fakes an excerpt if needed
     1118function bp_create_excerpt( $text, $excerpt_length = 225, $filter_shortcodes = true ) { // Fakes an excerpt if needed
    11191119    $original_text = $text;
    11201120    $text = str_replace(']]>', ']]>', $text);
     
    11231123        $text = preg_replace( '|\[(.+?)\](.+?\[/\\1\])?|s', '', $text );
    11241124
    1125     $words = preg_split(
    1126         "%\s*((?:<[^>]+>)+\S*)\s*|\s+%s",
    1127         $text,
    1128         $excerpt_length + 1,
    1129         PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE
    1130     );
    1131 
    1132     if (count($words) > $excerpt_length) {
    1133         array_pop($words);
    1134         array_push($words, '[...]');
    1135         $text = implode(' ', $words);
    1136     }
    1137 
     1125    preg_match( "%\s*((?:<[^>]+>)+\S*)\s*|\s+%s", $text, $matches, PREG_OFFSET_CAPTURE, $excerpt_length );
     1126   
     1127    if ( !empty( $matches ) ) {
     1128        $pos = array_pop( array_pop( $matches ) ); 
     1129        $text = substr( $text, 0, $pos ) . ' [...]';
     1130    }
     1131   
    11381132    return apply_filters( 'bp_create_excerpt', $text, $original_text );
    11391133}
Note: See TracChangeset for help on using the changeset viewer.