* Pass ellipsis as a parameter to wp_html_excerpt() instead of appending it manually.

* Consolidate the logic to avoid appending ellipsis if the entire string is shown.
* Show ellipsis after truncated filenames and post titles.

props solarissmoke, bpetty, SergeyBiryukov. fixes #11446.

git-svn-id: http://core.svn.wordpress.org/trunk@24214 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2013-05-09 00:22:02 +00:00
parent 633a6fb400
commit 415a5c60da
11 changed files with 27 additions and 34 deletions

View File

@ -57,7 +57,7 @@ if ( isset($_REQUEST['attachment_id']) && ($id = intval($_REQUEST['attachment_id
echo '<img class="pinkynail" src="' . esc_url( $thumb_url[0] ) . '" alt="" />'; echo '<img class="pinkynail" src="' . esc_url( $thumb_url[0] ) . '" alt="" />';
echo '<a class="edit-attachment" href="' . esc_url( get_edit_post_link( $id ) ) . '" target="_blank">' . _x( 'Edit', 'media item' ) . '</a>'; echo '<a class="edit-attachment" href="' . esc_url( get_edit_post_link( $id ) ) . '" target="_blank">' . _x( 'Edit', 'media item' ) . '</a>';
$title = $post->post_title ? $post->post_title : wp_basename( $post->guid ); // title shouldn't ever be empty, but use filename just in cas.e $title = $post->post_title ? $post->post_title : wp_basename( $post->guid ); // title shouldn't ever be empty, but use filename just in cas.e
echo '<div class="filename new"><span class="title">' . esc_html( wp_html_excerpt( $title, 60 ) ) . '</span></div>'; echo '<div class="filename new"><span class="title">' . esc_html( wp_html_excerpt( $title, 60, '&hellip;' ) ) . '</span></div>';
break; break;
case 2 : case 2 :
add_filter('attachment_fields_to_edit', 'media_single_attachment_fields_to_edit', 10, 2); add_filter('attachment_fields_to_edit', 'media_single_attachment_fields_to_edit', 10, 2);

View File

@ -105,7 +105,7 @@ wp_enqueue_script('admin-comments');
enqueue_comment_hotkeys_js(); enqueue_comment_hotkeys_js();
if ( $post_id ) if ( $post_id )
$title = sprintf(__('Comments on &#8220;%s&#8221;'), wp_html_excerpt(_draft_or_post_title($post_id), 50)); $title = sprintf( __( 'Comments on &#8220;%s&#8221;' ), wp_html_excerpt( _draft_or_post_title( $post_id ), 50, '&hellip;' ) );
else else
$title = __('Comments'); $title = __('Comments');
@ -143,17 +143,17 @@ require_once('./admin-header.php');
<?php screen_icon(); ?> <?php screen_icon(); ?>
<h2><?php <h2><?php
if ( $post_id ) if ( $post_id )
echo sprintf(__('Comments on &#8220;%s&#8221;'), echo sprintf( __( 'Comments on &#8220;%s&#8221;' ),
sprintf('<a href="%s">%s</a>', sprintf( '<a href="%s">%s</a>',
get_edit_post_link($post_id), get_edit_post_link( $post_id ),
wp_html_excerpt(_draft_or_post_title($post_id), 50) wp_html_excerpt( _draft_or_post_title( $post_id ), 50, '&hellip;' )
) )
); );
else else
echo __('Comments'); echo __('Comments');
if ( isset($_REQUEST['s']) && $_REQUEST['s'] ) if ( isset($_REQUEST['s']) && $_REQUEST['s'] )
printf( '<span class="subtitle">' . sprintf( __( 'Search results for &#8220;%s&#8221;' ), wp_html_excerpt( esc_html( wp_unslash( $_REQUEST['s'] ) ), 50 ) ) . '</span>' ); ?> printf( '<span class="subtitle">' . sprintf( __( 'Search results for &#8220;%s&#8221;' ), wp_html_excerpt( esc_html( wp_unslash( $_REQUEST['s'] ) ), 50, '&hellip;' ) ) . '</span>' ); ?>
</h2> </h2>
<?php <?php

View File

@ -827,7 +827,7 @@ function wp_dashboard_incoming_links_output() {
$publisher = "<strong>$publisher</strong>"; $publisher = "<strong>$publisher</strong>";
$content = $item->get_content(); $content = $item->get_content();
$content = wp_html_excerpt($content, 50) . ' &hellip;'; $content = wp_html_excerpt( $content, 50, ' &hellip;' );
if ( $link ) if ( $link )
/* translators: incoming links feed, %1$s is other person, %3$s is content */ /* translators: incoming links feed, %1$s is other person, %3$s is content */

View File

@ -1159,7 +1159,7 @@ function get_media_item( $attachment_id, $args = null ) {
} }
$display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case $display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case
$display_title = $show_title ? "<div class='filename new'><span class='title'>" . wp_html_excerpt( $display_title, 60 ) . "</span></div>" : ''; $display_title = $show_title ? "<div class='filename new'><span class='title'>" . wp_html_excerpt( $display_title, 60, '&hellip;' ) . "</span></div>" : '';
$gallery = ( ( isset( $_REQUEST['tab'] ) && 'gallery' == $_REQUEST['tab'] ) || ( isset( $redir_tab ) && 'gallery' == $redir_tab ) ); $gallery = ( ( isset( $_REQUEST['tab'] ) && 'gallery' == $_REQUEST['tab'] ) || ( isset( $redir_tab ) && 'gallery' == $redir_tab ) );
$order = ''; $order = '';

View File

@ -515,10 +515,7 @@ function wp_nav_menu_locations_meta_box() {
<option value="0"></option> <option value="0"></option>
<?php foreach ( $menus as $menu ) : ?> <?php foreach ( $menus as $menu ) : ?>
<option<?php selected( isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $menu->term_id ); ?> <option<?php selected( isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $menu->term_id ); ?>
value="<?php echo $menu->term_id; ?>"><?php value="<?php echo $menu->term_id; ?>"><?php echo wp_html_excerpt( $menu->name, 40, '&hellip;' ); ?></option>
$truncated_name = wp_html_excerpt( $menu->name, 40 );
echo $truncated_name == $menu->name ? $menu->name : trim( $truncated_name ) . '&hellip;';
?></option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
</label> </label>

View File

@ -436,11 +436,7 @@ if ( ! $nav_menu_selected_title && is_nav_menu( $nav_menu_selected_id ) ) {
// Generate truncated menu names // Generate truncated menu names
foreach( (array) $nav_menus as $key => $_nav_menu ) { foreach( (array) $nav_menus as $key => $_nav_menu ) {
$_nav_menu->truncated_name = trim( wp_html_excerpt( $_nav_menu->name, 40 ) ); $nav_menus[$key]->truncated_name = wp_html_excerpt( $_nav_menu->name, 40, '&hellip;' );
if ( $_nav_menu->truncated_name != $_nav_menu->name )
$_nav_menu->truncated_name .= '&hellip;';
$nav_menus[$key]->truncated_name = $_nav_menu->truncated_name;
} }
// Retrieve menu locations // Retrieve menu locations
@ -572,8 +568,7 @@ require_once( './admin-header.php' );
<?php foreach ( $nav_menus as $menu ) : ?> <?php foreach ( $nav_menus as $menu ) : ?>
<?php $selected = isset( $menu_locations[$_location] ) && $menu_locations[$_location] == $menu->term_id; ?> <?php $selected = isset( $menu_locations[$_location] ) && $menu_locations[$_location] == $menu->term_id; ?>
<option <?php if ( $selected ) echo 'data-orig="true"'; ?> <?php selected( $selected ); ?> value="<?php echo $menu->term_id; ?>"> <option <?php if ( $selected ) echo 'data-orig="true"'; ?> <?php selected( $selected ); ?> value="<?php echo $menu->term_id; ?>">
<?php $truncated_name = wp_html_excerpt( $menu->name, 40 ); <?php echo wp_html_excerpt( $menu->name, 40, '&hellip;' ); ?>
echo $truncated_name == $menu->name ? $menu->name : trim( $truncated_name ) . '&hellip;'; ?>
</option> </option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>

View File

@ -229,9 +229,7 @@ function wp_admin_bar_site_menu( $wp_admin_bar ) {
$blogname = sprintf( __('Global Dashboard: %s'), esc_html( $current_site->site_name ) ); $blogname = sprintf( __('Global Dashboard: %s'), esc_html( $current_site->site_name ) );
} }
$title = wp_html_excerpt( $blogname, 40 ); $title = wp_html_excerpt( $blogname, 40, '&hellip;' );
if ( $title != $blogname )
$title = trim( $title ) . '&hellip;';
$wp_admin_bar->add_menu( array( $wp_admin_bar->add_menu( array(
'id' => 'site-name', 'id' => 'site-name',

View File

@ -897,9 +897,7 @@ final class WP_Customize_Manager {
if ( $menus ) { if ( $menus ) {
$choices = array( 0 => __( '&mdash; Select &mdash;' ) ); $choices = array( 0 => __( '&mdash; Select &mdash;' ) );
foreach ( $menus as $menu ) { foreach ( $menus as $menu ) {
$truncated_name = wp_html_excerpt( $menu->name, 40 ); $choices[ $menu->term_id ] = wp_html_excerpt( $menu->name, 40, '&hellip;' );
$truncated_name = ( $truncated_name == $menu->name ) ? $menu->name : trim( $truncated_name ) . '&hellip;';
$choices[ $menu->term_id ] = $truncated_name;
} }
foreach ( $locations as $location => $description ) { foreach ( $locations as $location => $description ) {

View File

@ -1753,7 +1753,7 @@ function do_trackbacks($post_id) {
else else
$excerpt = apply_filters('the_excerpt', $post->post_excerpt); $excerpt = apply_filters('the_excerpt', $post->post_excerpt);
$excerpt = str_replace(']]>', ']]&gt;', $excerpt); $excerpt = str_replace(']]>', ']]&gt;', $excerpt);
$excerpt = wp_html_excerpt($excerpt, 252) . '&#8230;'; $excerpt = wp_html_excerpt($excerpt, 252, '&#8230;');
$post_title = apply_filters('the_title', $post->post_title, $post->ID); $post_title = apply_filters('the_title', $post->post_title, $post->ID);
$post_title = strip_tags($post_title); $post_title = strip_tags($post_title);

View File

@ -2199,7 +2199,7 @@ function wp_trim_excerpt($text = '') {
* *
* @param string $text Text to trim. * @param string $text Text to trim.
* @param int $num_words Number of words. Default 55. * @param int $num_words Number of words. Default 55.
* @param string $more What to append if $text needs to be trimmed. Default '&hellip;'. * @param string $more Optional. What to append if $text needs to be trimmed. Default '&hellip;'.
* @return string Trimmed text. * @return string Trimmed text.
*/ */
function wp_trim_words( $text, $num_words = 55, $more = null ) { function wp_trim_words( $text, $num_words = 55, $more = null ) {
@ -3118,14 +3118,19 @@ function wp_sprintf_l($pattern, $args) {
* *
* @param integer $str String to get the excerpt from. * @param integer $str String to get the excerpt from.
* @param integer $count Maximum number of characters to take. * @param integer $count Maximum number of characters to take.
* @param string $more Optional. What to append if $str needs to be trimmed. Defaults to empty string.
* @return string The excerpt. * @return string The excerpt.
*/ */
function wp_html_excerpt( $str, $count ) { function wp_html_excerpt( $str, $count, $more = null ) {
if ( null === $more )
$more = '';
$str = wp_strip_all_tags( $str, true ); $str = wp_strip_all_tags( $str, true );
$str = mb_substr( $str, 0, $count ); $excerpt = mb_substr( $str, 0, $count );
// remove part of an entity at the end // remove part of an entity at the end
$str = preg_replace( '/&[^;\s]{0,6}$/', '', $str ); $excerpt = preg_replace( '/&[^;\s]{0,6}$/', '', $excerpt );
return $str; if ( $str != $excerpt )
$excerpt = trim( $excerpt ) . $more;
return $excerpt;
} }
/** /**

View File

@ -87,8 +87,8 @@ if ( !empty($tb_url) && !empty($title) ) {
if ( !pings_open($tb_id) ) if ( !pings_open($tb_id) )
trackback_response(1, 'Sorry, trackbacks are closed for this item.'); trackback_response(1, 'Sorry, trackbacks are closed for this item.');
$title = wp_html_excerpt( $title, 250 ) . '&#8230;'; $title = wp_html_excerpt( $title, 250, '&#8230;' );
$excerpt = wp_html_excerpt( $excerpt, 252 ) . '&#8230;'; $excerpt = wp_html_excerpt( $excerpt, 252, '&#8230;' );
$comment_post_ID = (int) $tb_id; $comment_post_ID = (int) $tb_id;
$comment_author = $blog_name; $comment_author = $blog_name;