Changeset 10565
- Timestamp:
- 01/11/2021 02:34:51 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-parser.php
r10430 r10565 470 470 */ 471 471 protected function trim_length( $desc, $length = 150 ) { 472 if ( mb_strlen( $desc ) > $length ) { 473 $desc = mb_substr( $desc, 0, $length ) . ' …'; 474 475 // If not a full sentence, and one ends within 20% of the end, trim it to that. 476 if ( '.' !== mb_substr( $desc, -1 ) && ( $pos = mb_strrpos( $desc, '.' ) ) > ( 0.8 * $length ) ) { 477 $desc = mb_substr( $desc, 0, $pos + 1 ); 472 // Apply the length restriction without counting html entities. 473 $str_length = mb_strlen( html_entity_decode( $desc ) ?: $desc ); 474 475 if ( $str_length > $length ) { 476 $desc = mb_substr( $desc, 0, $length ); 477 478 // If not a full sentence... 479 if ( '.' !== mb_substr( $desc, -1 ) ) { 480 // ..and one ends within 20% of the end, trim it to that. 481 if ( ( $pos = mb_strrpos( $desc, '.' ) ) > ( 0.8 * $length ) ) { 482 $desc = mb_substr( $desc, 0, $pos + 1 ); 483 } else { 484 // ..else mark it as being trimmed. 485 $desc .= ' …'; 486 } 478 487 } 479 488 }
Note: See TracChangeset
for help on using the changeset viewer.