Ticket #3452: 3473.04.patch
File 3473.04.patch, 10.6 KB (added by , 13 years ago) |
---|
-
bp-activity/bp-activity-filters.php
function bp_activity_truncate_entry( $text ) { 193 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 194 195 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, '…'), $id, bp_get_activity_thread_permalink(), $append_text );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, array( 'ending' => '…' ) ), $id, bp_get_activity_thread_permalink(), $append_text ); 197 197 198 198 return apply_filters( 'bp_activity_truncate_entry', $excerpt, $text, $append_text ); 199 199 } -
bp-activity/bp-activity-template.php
function bp_activity_feed_item_title() { 1536 1536 $title = substr( $title, 0, -1 ); 1537 1537 1538 1538 if ( 'activity_update' == $activities_template->activity->type ) 1539 $title .= ': ' . strip_tags( ent2ncr( trim( convert_chars( bp_create_excerpt( $activities_template->activity->content, 70, true, " […]") ) ) ) );1539 $title .= ': ' . strip_tags( ent2ncr( trim( convert_chars( bp_create_excerpt( $activities_template->activity->content, 70, array( 'ending' => " […]" ) ) ) ) ) ); 1540 1540 1541 1541 return apply_filters( 'bp_get_activity_feed_item_title', $title ); 1542 1542 } -
bp-core/bp-core-template.php
function bp_button( $args = '' ) { 346 346 return apply_filters( 'bp_get_button', $button->contents, $args, $button ); 347 347 } 348 348 349 349 350 /** 350 * bp_create_excerpt()351 * Truncates text. 351 352 * 352 * Fakes an excerpt on any content. Will not truncate words. 353 * Cuts a string to the length of $length and replaces the last characters 354 * with the ending if the text is longer than length. 353 355 * 354 * @package BuddyPress Core 355 * @param $text str The text to create the excerpt from 356 * @param $excerpt_length Minimum excerpt length, in characters 357 * @param $filter_shortcodes When true, registered shortcodes (in square brackets) will be stripped 358 * @param $append_text Be sure to include a leading space 359 * @return str The excerpt text 356 * This function is borrowed from CakePHP v2.0, under the MIT license. See 357 * http://book.cakephp.org/view/1469/Text#truncate-1625 358 * 359 * ### Options: 360 * 361 * - `ending` Will be used as Ending and appended to the trimmed string 362 * - `exact` If false, $text will not be cut mid-word 363 * - `html` If true, HTML tags would be handled correctly 364 * - `filter_shortcodes` If true, shortcodes will be stripped before truncating 365 * 366 * @package BuddyPress 367 * 368 * @param string $text String to truncate. 369 * @param integer $length Length of returned string, including ellipsis. 370 * @param array $options An array of html attributes and options. 371 * @return string Trimmed string. 360 372 */ 361 function bp_create_excerpt( $text, $excerpt_length = 225, $filter_shortcodes = true, $append_text = ' […]' ) { // Fakes an excerpt if needed 373 function bp_create_excerpt( $text, $length = 225, $options = array() ) { 374 // Backward compatibility. The third argument used to be a boolean $filter_shortcodes 375 $filter_shortcodes_default = is_bool( $options ) ? $options : true; 376 377 $defaults = array( 378 'ending' => __( ' […]', 'buddypress' ), 379 'exact' => false, 380 'html' => true, 381 'filter_shortcodes' => $filter_shortcodes_default 382 ); 383 $r = wp_parse_args( $options, $defaults ); 384 extract( $r ); 385 386 // Save the original text, to be passed along to the filter 362 387 $original_text = $text; 363 $text = str_replace( ']]>', ']]>', $text );364 388 365 $excerpt_length = apply_filters( 'bp_excerpt_length', $excerpt_length ); 366 $append_text = apply_filters( 'bp_excerpt_append_text', $append_text ); 389 // Allow plugins to modify these values globally 390 $length = apply_filters( 'bp_excerpt_length', $length ); 391 $ending = apply_filters( 'bp_excerpt_append_text', $ending ); 367 392 393 // Remove shortcodes if necessary 368 394 if ( $filter_shortcodes ) 369 395 $text = strip_shortcodes( $text ); 370 396 371 preg_match( "%\s*((?:<[^>]+>)+\S*)\s*|\s+%s", $text, $matches, PREG_OFFSET_CAPTURE, $excerpt_length ); 397 // When $html is true, the excerpt should be created without including HTML tags in the 398 // excerpt length 399 if ( $html ) { 400 // The text is short enough. No need to truncate 401 if ( mb_strlen( preg_replace( '/<.*?>/', '', $text ) ) <= $length ) { 402 return $text; 403 } 372 404 373 if ( !empty( $matches ) ) { 374 $pos = array_pop( array_pop( $matches ) ); 375 $text = substr( $text, 0, $pos ) . $append_text; 405 $totalLength = mb_strlen( strip_tags( $ending ) ); 406 $openTags = array(); 407 $truncate = ''; 408 409 // Find all the tags and put them in a stack for later use 410 preg_match_all( '/(<\/?([\w+]+)[^>]*>)?([^<>]*)/', $text, $tags, PREG_SET_ORDER ); 411 foreach ( $tags as $tag ) { 412 // Process tags that need to be closed 413 if ( !preg_match( '/img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param/s', $tag[2] ) ) { 414 if ( preg_match( '/<[\w]+[^>]*>/s', $tag[0] ) ) { 415 array_unshift( $openTags, $tag[2] ); 416 } else if ( preg_match('/<\/([\w]+)[^>]*>/s', $tag[0], $closeTag ) ) { 417 $pos = array_search( $closeTag[1], $openTags ); 418 if ( $pos !== false ) { 419 array_splice( $openTags, $pos, 1 ); 420 } 421 } 422 } 423 $truncate .= $tag[1]; 424 425 $contentLength = mb_strlen( preg_replace( '/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i', ' ', $tag[3] ) ); 426 if ( $contentLength + $totalLength > $length ) { 427 $left = $length - $totalLength; 428 $entitiesLength = 0; 429 if ( preg_match_all( '/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i', $tag[3], $entities, PREG_OFFSET_CAPTURE ) ) { 430 foreach ( $entities[0] as $entity ) { 431 if ( $entity[1] + 1 - $entitiesLength <= $left ) { 432 $left--; 433 $entitiesLength += mb_strlen( $entity[0] ); 434 } else { 435 break; 436 } 437 } 438 } 439 440 $truncate .= mb_substr( $tag[3], 0 , $left + $entitiesLength ); 441 break; 442 } else { 443 $truncate .= $tag[3]; 444 $totalLength += $contentLength; 445 } 446 if ( $totalLength >= $length ) { 447 break; 448 } 449 } 450 } else { 451 if ( mb_strlen( $text ) <= $length ) { 452 return $text; 453 } else { 454 $truncate = mb_substr( $text, 0, $length - mb_strlen( $ending ) ); 455 } 456 } 457 458 // If $exact is false, we can't break on words 459 if ( !$exact ) { 460 $spacepos = mb_strrpos( $truncate, ' ' ); 461 if ( isset( $spacepos ) ) { 462 if ( $html ) { 463 $bits = mb_substr( $truncate, $spacepos ); 464 preg_match_all( '/<\/([a-z]+)>/', $bits, $droppedTags, PREG_SET_ORDER ); 465 if ( !empty( $droppedTags ) ) { 466 foreach ( $droppedTags as $closingTag ) { 467 if ( !in_array( $closingTag[1], $openTags ) ) { 468 array_unshift( $openTags, $closingTag[1] ); 469 } 470 } 471 } 472 } 473 $truncate = mb_substr( $truncate, 0, $spacepos ); 474 } 475 } 476 $truncate .= $ending; 477 478 if ( $html ) { 479 foreach ( $openTags as $tag ) { 480 $truncate .= '</' . $tag . '>'; 481 } 376 482 } 377 483 378 return apply_filters( 'bp_create_excerpt', $t ext, $original_text, $excerpt_length, $filter_shortcodes, $append_text);484 return apply_filters( 'bp_create_excerpt', $truncate, $original_text, $length, $options ); 379 485 } 380 486 add_filter( 'bp_create_excerpt', 'wp_trim_excerpt' ); 381 487 add_filter( 'bp_create_excerpt', 'stripslashes_deep' ); -
bp-core/bp-core-wpabstraction.php
if ( !is_multisite() ) { 26 26 return get_option( $option_name, $default ); 27 27 } 28 28 } 29 29 30 30 if ( !function_exists( 'update_blog_option' ) ) { 31 31 function update_blog_option( $blog_id, $option_name, $value ) { 32 32 return update_option( $option_name, $value ); … … function bp_core_get_status_sql( $prefix = false ) { 73 73 else 74 74 return "{$prefix}spam = 0 AND {$prefix}deleted = 0 AND {$prefix}user_status = 0"; 75 75 } 76 77 /** 78 * Multibyte encoding fallback functions 79 * 80 * The PHP multibyte encoding extension is not enabled by default. In cases where it is not enabled, 81 * these functions provide a fallback. 82 * 83 * Borrowed from MediaWiki, under the GPLv2. Thanks! 84 */ 85 if ( !function_exists( 'mb_strlen' ) ) { 86 /** 87 * Fallback implementation of mb_strlen, hardcoded to UTF-8. 88 * @param string $str 89 * @param string $enc optional encoding; ignored 90 * @return int 91 */ 92 function mb_strlen( $str, $enc = '' ) { 93 $counts = count_chars( $str ); 94 $total = 0; 95 96 // Count ASCII bytes 97 for( $i = 0; $i < 0x80; $i++ ) { 98 $total += $counts[$i]; 99 } 100 101 // Count multibyte sequence heads 102 for( $i = 0xc0; $i < 0xff; $i++ ) { 103 $total += $counts[$i]; 104 } 105 return $total; 106 } 107 } 108 109 if ( !function_exists( 'mb_strpos' ) ) { 110 /** 111 * Fallback implementation of mb_strpos, hardcoded to UTF-8. 112 * @param $haystack String 113 * @param $needle String 114 * @param $offset String: optional start position 115 * @param $encoding String: optional encoding; ignored 116 * @return int 117 */ 118 function mb_strpos( $haystack, $needle, $offset = 0, $encoding = '' ) { 119 $needle = preg_quote( $needle, '/' ); 120 121 $ar = array(); 122 preg_match( '/' . $needle . '/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset ); 123 124 if( isset( $ar[0][1] ) ) { 125 return $ar[0][1]; 126 } else { 127 return false; 128 } 129 } 130 } 131 132 if ( !function_exists( 'mb_strrpos' ) ) { 133 /** 134 * Fallback implementation of mb_strrpos, hardcoded to UTF-8. 135 * @param $haystack String 136 * @param $needle String 137 * @param $offset String: optional start position 138 * @param $encoding String: optional encoding; ignored 139 * @return int 140 */ 141 function mb_strrpos( $haystack, $needle, $offset = 0, $encoding = '' ) { 142 $needle = preg_quote( $needle, '/' ); 143 144 $ar = array(); 145 preg_match_all( '/' . $needle . '/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset ); 146 147 if( isset( $ar[0] ) && count( $ar[0] ) > 0 && 148 isset( $ar[0][count( $ar[0] ) - 1][1] ) ) { 149 return $ar[0][count( $ar[0] ) - 1][1]; 150 } else { 151 return false; 152 } 153 } 154 } 155 76 156 ?> 157 No newline at end of file