From d8d26a4f79802aab3e44ebfad13506402b504701 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Mon, 31 Mar 2014 05:15:39 +0000 Subject: [PATCH] Cleanup up the display, escaping, and handling of ID3 data for media. Rename `wp_get_relevant_id3_keys()` to `wp_get_attachment_id3_keys()`. Props nacin. See #27574. git-svn-id: https://develop.svn.wordpress.org/trunk@27869 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/media.php | 89 +++++++++++++--------------- src/wp-admin/includes/meta-boxes.php | 11 ++-- src/wp-admin/includes/post.php | 2 +- src/wp-includes/media.php | 34 ++++++----- 4 files changed, 68 insertions(+), 68 deletions(-) diff --git a/src/wp-admin/includes/media.php b/src/wp-admin/includes/media.php index 91d558618a..dd5b53a83c 100644 --- a/src/wp-admin/includes/media.php +++ b/src/wp-admin/includes/media.php @@ -2661,10 +2661,7 @@ function edit_form_image_editor( $post ) {

-
+

@@ -2688,9 +2685,9 @@ function edit_form_image_editor( $post ) { ?> + if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ) { + echo ': ' . __( 'Displayed on attachment pages.' ); + } ?> post_content, 'attachment_content', $editor_args ); ?>
@@ -2728,10 +2725,17 @@ function attachment_submitbox_metadata() {
ID ), $matches ) ) + if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) ) { echo esc_html( strtoupper( $matches[1] ) ); - else + list( $mime_type ) = explode( '/', $post->post_mime_type ); + if ( $mime_type !== 'image' && ! empty( $meta['mime_type'] ) ) { + if ( $meta['mime_type'] !== "$mime_type/" . strtolower( $matches[1] ) ) { + echo ' (' . $meta['mime_type'] . ')'; + } + } + } else { echo strtoupper( str_replace( 'image/', '', $post->post_mime_type ) ); + } ?>
@@ -2751,7 +2755,7 @@ function attachment_submitbox_metadata() { post_mime_type ) ): + if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ) { /** * Filter the audio and video metadata fields to be shown in the publish meta box. @@ -2761,41 +2765,35 @@ function attachment_submitbox_metadata() { * * @since 3.7.0 * - * @param array $fields { - * An array of the attachment metadata keys and labels. - * - * @type string $mime_type Label to be shown before the field mime_type. - * @type string $year Label to be shown before the field year. - * @type string $genre Label to be shown before the field genre. - * @type string $length_formatted Label to be shown before the field length_formatted. - * } + * @param array $fields An array of the attachment metadata keys and labels. */ $fields = apply_filters( 'media_submitbox_misc_sections', array( - 'mime_type' => __( 'Mime-type:' ), 'length_formatted' => __( 'Length:' ), + 'bitrate' => __( 'Bitrate:' ), ) ); - foreach ( $fields as $key => $label ): - if ( ! empty( $meta[$key] ) ) : ?> + foreach ( $fields as $key => $label ) { + if ( empty( $meta[ $key ] ) ) { + continue; + } + ?>
- -
- -
-
__( 'Audio Format:' ), 'codec' => __( 'Audio Codec:' ) ) ); - foreach ( $audio_fields as $key => $label ): - if ( ! empty( $meta['audio'][$key] ) ) : ?> + foreach ( $audio_fields as $key => $label ) { + if ( empty( $meta['audio'][ $key ] ) ) { + continue; + } + ?>
diff --git a/src/wp-admin/includes/meta-boxes.php b/src/wp-admin/includes/meta-boxes.php index f690f8b7e7..9f7f469a42 100644 --- a/src/wp-admin/includes/meta-boxes.php +++ b/src/wp-admin/includes/meta-boxes.php @@ -1071,14 +1071,15 @@ function attachment_id3_data_meta_box( $post ) { $meta = wp_get_attachment_metadata( $post->ID ); } - foreach ( wp_get_relevant_id3_keys( $post ) as $key => $label ): ?> + foreach ( wp_get_attachment_id3_keys( $post, 'edit' ) as $key => $label ) : ?>

- -
+

- $label ) { + foreach ( wp_get_attachment_id3_keys( $post, 'edit' ) as $key => $label ) { if ( isset( $post_data[ 'id3_' . $key ] ) ) { $id3data[ $key ] = sanitize_text_field( wp_unslash( $post_data[ 'id3_' . $key ] ) ); } diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 47c64312ad..488c16eba2 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -1019,7 +1019,7 @@ function wp_underscore_playlist_templates() { <# } #>
- “{{{ data.title }}}” + “{{ data.title }}” <# if ( data.meta.album ) { #>{{ data.meta.album }}<# } #> <# if ( data.meta.artist ) { #>{{ data.meta.artist }}<# } #>
@@ -1029,16 +1029,16 @@ function wp_underscore_playlist_templates() {
{{ data.index ? ( data.index + '. ' ) : '' }} <# if ( data.caption ) { #> - {{{ data.caption }}} + {{ data.caption }} <# } else { #> - “{{{ data.title }}}” + “{{ data.title }}” <# if ( data.artists && data.meta.artist ) { #> — {{ data.meta.artist }} <# } #> <# } #>
<# if ( data.meta.length_formatted ) { #> -
{{{ data.meta.length_formatted }}}
+
{{ data.meta.length_formatted }}
<# } #>
@@ -1202,7 +1202,7 @@ function wp_playlist_shortcode( $attr ) { $meta = wp_get_attachment_metadata( $attachment->ID ); if ( ! empty( $meta ) ) { - foreach ( wp_get_relevant_id3_keys( $attachment ) as $key => $label ) { + foreach ( wp_get_attachment_id3_keys( $attachment ) as $key => $label ) { if ( ! empty( $meta[ $key ] ) ) { $track['meta'][ $key ] = $meta[ $key ]; } @@ -1312,31 +1312,35 @@ function wp_get_audio_extensions() { } /** - * Return useful keys to use to lookup data from an attachment's stored metadata + * Return useful keys to use to lookup data from an attachment's stored metadata. * * @since 3.9.0 * - * @param WP_Post $post The post in question, provided for context. + * @param WP_Post $attachment The attachment in question, provided for context. + * @param string $context The context. Accepts 'edit', 'display'. Default 'display'. * @return array */ -function wp_get_relevant_id3_keys( $post ) { +function wp_get_attachment_id3_keys( $attachment, $context = 'display' ) { $fields = array( 'artist' => __( 'Artist' ), 'album' => __( 'Album' ), - 'genre' => __( 'Genre' ), - 'year' => __( 'Year' ), - 'length_formatted' => __( 'Formatted Length' ) ); + if ( 'display' === $context ) { + $fields['genre'] = __( 'Genre' ); + $fields['year'] = __( 'Year' ); + $fields['length_formatted'] = _x( 'Length', 'video or audio' ); + } + /** * Filter the editable list of keys to lookup data from an attachment's metadata. * * @since 3.9.0 * - * @param array $fields Key/value pairs of field keys to labels. - * @param WP_Post $post Post object. + * @param array $fields Key/value pairs of field keys to labels. + * @param WP_Post $attachment Attachment object. */ - return apply_filters( 'wp_get_relevant_id3_keys', $fields, $post ); + return apply_filters( 'wp_get_attachment_id3_keys', $fields, $attachment, $context ); } /** * The Audio shortcode. @@ -2333,7 +2337,7 @@ function wp_prepare_attachment_for_js( $attachment ) { $response['fileLength'] = $meta['length_formatted']; $response['meta'] = array(); - foreach ( wp_get_relevant_id3_keys( $attachment ) as $key => $label ) { + foreach ( wp_get_attachment_id3_keys( $attachment ) as $key => $label ) { if ( ! empty( $meta[ $key ] ) ) { $response['meta'][ $key ] = $meta[ $key ]; }