From d7f99f31e6835b2826c309a264e48b6f4c659d39 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov <sergeybiryukov@git.wordpress.org> Date: Wed, 26 May 2021 14:23:11 +0000 Subject: [PATCH] Media: Replace `basename()` usage on media upload screen with `wp_basename()` for better multibyte filenames support. Includes minor code layout fixes for better readability. Follow-up to [44785], [51023]. See #51754. git-svn-id: https://develop.svn.wordpress.org/trunk@51030 602fd350-edb4-49c9-b593-d223f7449a82 --- src/js/_enqueues/vendor/plupload/handlers.js | 4 ++- src/wp-admin/async-upload.php | 31 ++++++++++++-------- src/wp-admin/css/media.css | 4 +-- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/js/_enqueues/vendor/plupload/handlers.js b/src/js/_enqueues/vendor/plupload/handlers.js index aaf1519aff..7958e7231d 100644 --- a/src/js/_enqueues/vendor/plupload/handlers.js +++ b/src/js/_enqueues/vendor/plupload/handlers.js @@ -372,10 +372,12 @@ function wpFileExtensionError( up, file, message ) { */ function copyAttachmentUploadURLClipboard() { var clipboard = new ClipboardJS( '.copy-attachment-url' ), - successTimeout; + successTimeout; + clipboard.on( 'success', function( event ) { var triggerElement = jQuery( event.trigger ), successElement = jQuery( '.success', triggerElement.closest( '.copy-to-clipboard-container' ) ); + // Clear the selection and move focus back to the trigger. event.clearSelection(); // Handle ClipboardJS focus bug, see https://github.com/zenorocha/clipboard.js/issues/680 diff --git a/src/wp-admin/async-upload.php b/src/wp-admin/async-upload.php index 9c0190a198..6e04e0a19a 100644 --- a/src/wp-admin/async-upload.php +++ b/src/wp-admin/async-upload.php @@ -48,22 +48,27 @@ if ( isset( $_REQUEST['attachment_id'] ) && (int) $_REQUEST['attachment_id'] && switch ( $_REQUEST['fetch'] ) { case 3: - echo '<div class="attachment-details">'; - $thumb_url = wp_get_attachment_image_src( $id, 'thumbnail', true ); - if ( $thumb_url ) { - echo '<img class="pinkynail" src="' . esc_url( $thumb_url[0] ) . '" alt="" />'; - } - // Title shouldn't ever be empty, but use filename just in case. - $file = get_attached_file( $post->ID ); - $fileurl = wp_get_attachment_url( $post->ID ); - $title = $post->post_title ? $post->post_title : wp_basename( $file ); - - echo '<div class="filename new"><span class="media-list-title"><strong>' . esc_html( wp_html_excerpt( $title, 60, '…' ) ) . '</strong></span> <span class="media-list-subtitle">' . basename( $file ) . '</span></div>'; - echo '</div>'; ?> + <div class="attachment-details"> + <?php + $thumb_url = wp_get_attachment_image_src( $id, 'thumbnail', true ); + if ( $thumb_url ) { + echo '<img class="pinkynail" src="' . esc_url( $thumb_url[0] ) . '" alt="" />'; + } + + // Title shouldn't ever be empty, but use filename just in case. + $file = get_attached_file( $post->ID ); + $file_url = wp_get_attachment_url( $post->ID ); + $title = $post->post_title ? $post->post_title : wp_basename( $file ); + ?> + <div class="filename new"> + <span class="media-list-title"><strong><?php echo esc_html( wp_html_excerpt( $title, 60, '…' ) ); ?></strong></span> + <span class="media-list-subtitle"><?php echo wp_basename( $file ); ?></span> + </div> + </div> <div class="attachment-tools"> <span class="media-item-copy-container copy-to-clipboard-container edit-attachment"> - <button type="button" class="button button-small copy-attachment-url" data-clipboard-text="<?php echo $fileurl; ?>"><?php _e( 'Copy URL to clipboard' ); ?></button> + <button type="button" class="button button-small copy-attachment-url" data-clipboard-text="<?php echo $file_url; ?>"><?php _e( 'Copy URL to clipboard' ); ?></button> <span class="success hidden" aria-hidden="true"><?php _e( 'Copied!' ); ?></span> </span> <?php diff --git a/src/wp-admin/css/media.css b/src/wp-admin/css/media.css index aaaf8ba13b..f534a5335a 100644 --- a/src/wp-admin/css/media.css +++ b/src/wp-admin/css/media.css @@ -138,11 +138,11 @@ } .media-item button .copy-attachment-url { - margin-top:14px; + margin-top: 14px; } .media-item .copy-to-clipboard-container { - margin-top:7px; + margin-top: 7px; } .media-item .describe-toggle-off,