<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[27869] trunk/src: Cleanup up the display, escaping, and handling of ID3 data for media.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/27869">27869</a></dd>
<dt>Author</dt> <dd>wonderboymusic</dd>
<dt>Date</dt> <dd>2014-03-31 05:15:39 +0000 (Mon, 31 Mar 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>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 <a href="http://core.trac.wordpress.org/ticket/27574">#27574</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminincludesmediaphp">trunk/src/wp-admin/includes/media.php</a></li>
<li><a href="#trunksrcwpadminincludesmetaboxesphp">trunk/src/wp-admin/includes/meta-boxes.php</a></li>
<li><a href="#trunksrcwpadminincludespostphp">trunk/src/wp-admin/includes/post.php</a></li>
<li><a href="#trunksrcwpincludesmediaphp">trunk/src/wp-includes/media.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/includes/media.php (27868 => 27869)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/media.php 2014-03-31 05:12:29 UTC (rev 27868)
+++ trunk/src/wp-admin/includes/media.php 2014-03-31 05:15:39 UTC (rev 27869)
</span><span class="lines">@@ -2661,10 +2661,7 @@
</span><span class="cx"> </div>
</span><span class="cx"> <div class="wp_attachment_details edit-form-section">
</span><span class="cx"> <p>
</span><del>- <label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong><?php
- if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ): ?>: <?php
- _e( "Custom label for item in a playlist. If empty, the file's available data is used." );
- endif ?></label><br />
</del><ins>+ <label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong></label><br />
</ins><span class="cx"> <textarea class="widefat" name="excerpt" id="attachment_caption"><?php echo $post->post_excerpt; ?></textarea>
</span><span class="cx"> </p>
</span><span class="cx">
</span><span class="lines">@@ -2688,9 +2685,9 @@
</span><span class="cx"> ?>
</span><span class="cx">
</span><span class="cx"> <label for="content"><strong><?php _e( 'Description' ); ?></strong><?php
</span><del>- if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ): ?>: <?php
- _e( 'Displayed on attachment pages.' );
- endif ?></label>
</del><ins>+ if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ) {
+ echo ': ' . __( 'Displayed on attachment pages.' );
+ } ?></label>
</ins><span class="cx"> <?php wp_editor( $post->post_content, 'attachment_content', $editor_args ); ?>
</span><span class="cx">
</span><span class="cx"> </div>
</span><span class="lines">@@ -2728,10 +2725,17 @@
</span><span class="cx"> </div>
</span><span class="cx"> <div class="misc-pub-section misc-pub-filetype">
</span><span class="cx"> <?php _e( 'File type:' ); ?> <strong><?php
</span><del>- if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) )
</del><ins>+ if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) ) {
</ins><span class="cx"> echo esc_html( strtoupper( $matches[1] ) );
</span><del>- else
</del><ins>+ 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 {
</ins><span class="cx"> echo strtoupper( str_replace( 'image/', '', $post->post_mime_type ) );
</span><ins>+ }
</ins><span class="cx"> ?></strong>
</span><span class="cx"> </div>
</span><span class="cx">
</span><span class="lines">@@ -2751,7 +2755,7 @@
</span><span class="cx"> <?php
</span><span class="cx"> endif;
</span><span class="cx">
</span><del>- if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ):
</del><ins>+ if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ) {
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Filter the audio and video metadata fields to be shown in the publish meta box.
</span><span class="lines">@@ -2761,41 +2765,35 @@
</span><span class="cx"> *
</span><span class="cx"> * @since 3.7.0
</span><span class="cx"> *
</span><del>- * @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.
- * }
</del><ins>+ * @param array $fields An array of the attachment metadata keys and labels.
</ins><span class="cx"> */
</span><span class="cx"> $fields = apply_filters( 'media_submitbox_misc_sections', array(
</span><del>- 'mime_type' => __( 'Mime-type:' ),
</del><span class="cx"> 'length_formatted' => __( 'Length:' ),
</span><ins>+ 'bitrate' => __( 'Bitrate:' ),
</ins><span class="cx"> ) );
</span><span class="cx">
</span><del>- foreach ( $fields as $key => $label ):
- if ( ! empty( $meta[$key] ) ) : ?>
</del><ins>+ foreach ( $fields as $key => $label ) {
+ if ( empty( $meta[ $key ] ) ) {
+ continue;
+ }
+ ?>
</ins><span class="cx"> <div class="misc-pub-section misc-pub-mime-meta misc-pub-<?php echo sanitize_html_class( $key ); ?>">
</span><del>- <?php echo $label ?> <strong><?php echo esc_html( $meta[$key] ); ?></strong>
- </div>
- <?php
- endif;
- endforeach;
-
- if ( ! empty( $meta['bitrate'] ) ) : ?>
- <div class="misc-pub-section misc-pub-bitrate">
- <?php _e( 'Bitrate:' ); ?> <strong><?php
- echo round( $meta['bitrate'] / 1000 ), 'kb/s';
-
- if ( ! empty( $meta['bitrate_mode'] ) )
- echo ' ', strtoupper( $meta['bitrate_mode'] );
-
</del><ins>+ <?php echo $label ?> <strong><?php
+ switch ( $key ) {
+ case 'bitrate' :
+ echo round( $meta['bitrate'] / 1000 ) . 'kb/s';
+ if ( ! empty( $meta['bitrate_mode'] ) ) {
+ echo ' ' . strtoupper( esc_html( $meta['bitrate_mode'] ) );
+ }
+ break;
+ default:
+ echo esc_html( $meta[ $key ] );
+ break;
+ }
</ins><span class="cx"> ?></strong>
</span><span class="cx"> </div>
</span><span class="cx"> <?php
</span><del>- endif;
</del><ins>+ }
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Filter the audio attachment metadata fields to be shown in the publish meta box.
</span><span class="lines">@@ -2805,28 +2803,25 @@
</span><span class="cx"> *
</span><span class="cx"> * @since 3.7.0
</span><span class="cx"> *
</span><del>- * @param array $fields {
- * An array of the attachment metadata keys and labels.
- *
- * @type string $dataformat Label to be shown before the field dataformat.
- * @type string $codec Label to be shown before the field codec.
- * }
</del><ins>+ * @param array $fields An array of the attachment metadata keys and labels.
</ins><span class="cx"> */
</span><span class="cx"> $audio_fields = apply_filters( 'audio_submitbox_misc_sections', array(
</span><span class="cx"> 'dataformat' => __( 'Audio Format:' ),
</span><span class="cx"> 'codec' => __( 'Audio Codec:' )
</span><span class="cx"> ) );
</span><span class="cx">
</span><del>- foreach ( $audio_fields as $key => $label ):
- if ( ! empty( $meta['audio'][$key] ) ) : ?>
</del><ins>+ foreach ( $audio_fields as $key => $label ) {
+ if ( empty( $meta['audio'][ $key ] ) ) {
+ continue;
+ }
+ ?>
</ins><span class="cx"> <div class="misc-pub-section misc-pub-audio misc-pub-<?php echo sanitize_html_class( $key ); ?>">
</span><span class="cx"> <?php echo $label; ?> <strong><?php echo esc_html( $meta['audio'][$key] ); ?></strong>
</span><span class="cx"> </div>
</span><span class="cx"> <?php
</span><del>- endif;
- endforeach;
</del><ins>+ }
</ins><span class="cx">
</span><del>- endif;
</del><ins>+ }
</ins><span class="cx">
</span><span class="cx"> if ( $media_dims ) : ?>
</span><span class="cx"> <div class="misc-pub-section misc-pub-dimensions">
</span></span></pre></div>
<a id="trunksrcwpadminincludesmetaboxesphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/includes/meta-boxes.php (27868 => 27869)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/meta-boxes.php 2014-03-31 05:12:29 UTC (rev 27868)
+++ trunk/src/wp-admin/includes/meta-boxes.php 2014-03-31 05:15:39 UTC (rev 27869)
</span><span class="lines">@@ -1071,14 +1071,15 @@
</span><span class="cx"> $meta = wp_get_attachment_metadata( $post->ID );
</span><span class="cx"> }
</span><span class="cx">
</span><del>- foreach ( wp_get_relevant_id3_keys( $post ) as $key => $label ): ?>
</del><ins>+ foreach ( wp_get_attachment_id3_keys( $post, 'edit' ) as $key => $label ) : ?>
</ins><span class="cx"> <p>
</span><del>- <label for="title"><?php echo $label ?></label>
- <input type="text" name="id3_<?php echo esc_attr( $key ) ?>" id="id3_<?php echo esc_attr( $key ) ?>" class="widefat" value="<?php
</del><ins>+ <label for="title"><?php echo $label ?></label><br />
+ <input type="text" name="id3_<?php echo esc_attr( $key ) ?>" id="id3_<?php echo esc_attr( $key ) ?>" class="large-text" value="<?php
</ins><span class="cx"> if ( ! empty( $meta[ $key ] ) ) {
</span><span class="cx"> echo esc_attr( $meta[ $key ] );
</span><span class="cx"> }
</span><span class="cx"> ?>" />
</span><span class="cx"> </p>
</span><del>- <?php endforeach;
-}
</del><span class="cx">\ No newline at end of file
</span><ins>+ <?php
+ endforeach;
+}
</ins></span></pre></div>
<a id="trunksrcwpadminincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/includes/post.php (27868 => 27869)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/post.php 2014-03-31 05:12:29 UTC (rev 27868)
+++ trunk/src/wp-admin/includes/post.php 2014-03-31 05:15:39 UTC (rev 27869)
</span><span class="lines">@@ -243,7 +243,7 @@
</span><span class="cx"> $id3data = array();
</span><span class="cx"> }
</span><span class="cx">
</span><del>- foreach ( wp_get_relevant_id3_keys( $post ) as $key => $label ) {
</del><ins>+ foreach ( wp_get_attachment_id3_keys( $post, 'edit' ) as $key => $label ) {
</ins><span class="cx"> if ( isset( $post_data[ 'id3_' . $key ] ) ) {
</span><span class="cx"> $id3data[ $key ] = sanitize_text_field( wp_unslash( $post_data[ 'id3_' . $key ] ) );
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunksrcwpincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/media.php (27868 => 27869)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/media.php 2014-03-31 05:12:29 UTC (rev 27868)
+++ trunk/src/wp-includes/media.php 2014-03-31 05:15:39 UTC (rev 27869)
</span><span class="lines">@@ -1019,7 +1019,7 @@
</span><span class="cx"> <img src="{{ data.thumb.src }}"/>
</span><span class="cx"> <# } #>
</span><span class="cx"> <div class="wp-playlist-caption">
</span><del>- <span class="wp-playlist-item-meta wp-playlist-item-title">“{{{ data.title }}}”</span>
</del><ins>+ <span class="wp-playlist-item-meta wp-playlist-item-title">“{{ data.title }}”</span>
</ins><span class="cx"> <# if ( data.meta.album ) { #><span class="wp-playlist-item-meta wp-playlist-item-album">{{ data.meta.album }}</span><# } #>
</span><span class="cx"> <# if ( data.meta.artist ) { #><span class="wp-playlist-item-meta wp-playlist-item-artist">{{ data.meta.artist }}</span><# } #>
</span><span class="cx"> </div>
</span><span class="lines">@@ -1029,16 +1029,16 @@
</span><span class="cx"> <div class="wp-playlist-caption">
</span><span class="cx"> {{ data.index ? ( data.index + '. ' ) : '' }}
</span><span class="cx"> <# if ( data.caption ) { #>
</span><del>- {{{ data.caption }}}
</del><ins>+ {{ data.caption }}
</ins><span class="cx"> <# } else { #>
</span><del>- <span class="wp-playlist-item-title">“{{{ data.title }}}”</span>
</del><ins>+ <span class="wp-playlist-item-title">“{{ data.title }}”</span>
</ins><span class="cx"> <# if ( data.artists && data.meta.artist ) { #>
</span><span class="cx"> <span class="wp-playlist-item-artist"> — {{ data.meta.artist }}</span>
</span><span class="cx"> <# } #>
</span><span class="cx"> <# } #>
</span><span class="cx"> </div>
</span><span class="cx"> <# if ( data.meta.length_formatted ) { #>
</span><del>- <div class="wp-playlist-item-length">{{{ data.meta.length_formatted }}}</div>
</del><ins>+ <div class="wp-playlist-item-length">{{ data.meta.length_formatted }}</div>
</ins><span class="cx"> <# } #>
</span><span class="cx"> </div>
</span><span class="cx"> </script>
</span><span class="lines">@@ -1202,7 +1202,7 @@
</span><span class="cx"> $meta = wp_get_attachment_metadata( $attachment->ID );
</span><span class="cx"> if ( ! empty( $meta ) ) {
</span><span class="cx">
</span><del>- foreach ( wp_get_relevant_id3_keys( $attachment ) as $key => $label ) {
</del><ins>+ foreach ( wp_get_attachment_id3_keys( $attachment ) as $key => $label ) {
</ins><span class="cx"> if ( ! empty( $meta[ $key ] ) ) {
</span><span class="cx"> $track['meta'][ $key ] = $meta[ $key ];
</span><span class="cx"> }
</span><span class="lines">@@ -1312,31 +1312,35 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Return useful keys to use to lookup data from an attachment's stored metadata
</del><ins>+ * Return useful keys to use to lookup data from an attachment's stored metadata.
</ins><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><span class="cx"> *
</span><del>- * @param WP_Post $post The post in question, provided for context.
</del><ins>+ * @param WP_Post $attachment The attachment in question, provided for context.
+ * @param string $context The context. Accepts 'edit', 'display'. Default 'display'.
</ins><span class="cx"> * @return array
</span><span class="cx"> */
</span><del>-function wp_get_relevant_id3_keys( $post ) {
</del><ins>+function wp_get_attachment_id3_keys( $attachment, $context = 'display' ) {
</ins><span class="cx"> $fields = array(
</span><span class="cx"> 'artist' => __( 'Artist' ),
</span><span class="cx"> 'album' => __( 'Album' ),
</span><del>- 'genre' => __( 'Genre' ),
- 'year' => __( 'Year' ),
- 'length_formatted' => __( 'Formatted Length' )
</del><span class="cx"> );
</span><span class="cx">
</span><ins>+ if ( 'display' === $context ) {
+ $fields['genre'] = __( 'Genre' );
+ $fields['year'] = __( 'Year' );
+ $fields['length_formatted'] = _x( 'Length', 'video or audio' );
+ }
+
</ins><span class="cx"> /**
</span><span class="cx"> * Filter the editable list of keys to lookup data from an attachment's metadata.
</span><span class="cx"> *
</span><span class="cx"> * @since 3.9.0
</span><span class="cx"> *
</span><del>- * @param array $fields Key/value pairs of field keys to labels.
- * @param WP_Post $post Post object.
</del><ins>+ * @param array $fields Key/value pairs of field keys to labels.
+ * @param WP_Post $attachment Attachment object.
</ins><span class="cx"> */
</span><del>- return apply_filters( 'wp_get_relevant_id3_keys', $fields, $post );
</del><ins>+ return apply_filters( 'wp_get_attachment_id3_keys', $fields, $attachment, $context );
</ins><span class="cx"> }
</span><span class="cx"> /**
</span><span class="cx"> * The Audio shortcode.
</span><span class="lines">@@ -2333,7 +2337,7 @@
</span><span class="cx"> $response['fileLength'] = $meta['length_formatted'];
</span><span class="cx">
</span><span class="cx"> $response['meta'] = array();
</span><del>- foreach ( wp_get_relevant_id3_keys( $attachment ) as $key => $label ) {
</del><ins>+ foreach ( wp_get_attachment_id3_keys( $attachment ) as $key => $label ) {
</ins><span class="cx"> if ( ! empty( $meta[ $key ] ) ) {
</span><span class="cx"> $response['meta'][ $key ] = $meta[ $key ];
</span><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>