<!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>[24777] trunk: Media: Add awareness to Attachment Display Settings that audio and video can be embedded.</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/24777">24777</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2013-07-23 05:39:08 +0000 (Tue, 23 Jul 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Media: Add awareness to Attachment Display Settings that audio and video can be embedded.

Also:
 * Add file length metadata to Attachment Details.
 * Round the kb/s bitrate on post.php.

fixes <a href="http://core.trac.wordpress.org/ticket/24449">#24449</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesmediaphp">trunk/wp-admin/includes/media.php</a></li>
<li><a href="#trunkwpincludesjsmediaeditorjs">trunk/wp-includes/js/media-editor.js</a></li>
<li><a href="#trunkwpincludesjsmediaviewsjs">trunk/wp-includes/js/media-views.js</a></li>
<li><a href="#trunkwpincludesmediatemplatephp">trunk/wp-includes/media-template.php</a></li>
<li><a href="#trunkwpincludesmediaphp">trunk/wp-includes/media.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/media.php (24776 => 24777)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/media.php        2013-07-23 04:58:52 UTC (rev 24776)
+++ trunk/wp-admin/includes/media.php   2013-07-23 05:39:08 UTC (rev 24777)
</span><span class="lines">@@ -2470,7 +2470,7 @@
</span><span class="cx">          if ( ! empty( $meta['bitrate'] ) ) : ?>
</span><span class="cx">          <div class="misc-pub-section">
</span><span class="cx">                  <?php _e( 'Bitrate:' ); ?> <strong><?php
</span><del>-                               echo $meta['bitrate'] / 1000, 'kb/s';
</del><ins>+                                echo round( $meta['bitrate'] / 1000 ), 'kb/s';
</ins><span class="cx"> 
</span><span class="cx">                          if ( ! empty( $meta['bitrate_mode'] ) )
</span><span class="cx">                                  echo ' ', strtoupper( $meta['bitrate_mode'] );
</span></span></pre></div>
<a id="trunkwpincludesjsmediaeditorjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/media-editor.js (24776 => 24777)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/media-editor.js     2013-07-23 04:58:52 UTC (rev 24776)
+++ trunk/wp-includes/js/media-editor.js        2013-07-23 05:39:08 UTC (rev 24777)
</span><span class="lines">@@ -45,7 +45,7 @@
</span><span class="cx">                  props.title = props.title || attachment.title;
</span><span class="cx"> 
</span><span class="cx">                  link = props.link || defaultProps.link || getUserSetting( 'urlbutton', 'file' );
</span><del>-                       if ( 'file' === link )
</del><ins>+                        if ( 'file' === link || 'embed' === link )
</ins><span class="cx">                           linkUrl = attachment.url;
</span><span class="cx">                  else if ( 'post' === link )
</span><span class="cx">                          linkUrl = attachment.link;
</span><span class="lines">@@ -97,90 +97,41 @@
</span><span class="cx">          },
</span><span class="cx"> 
</span><span class="cx">          audio: function( props, attachment ) {
</span><del>-                       var shortcode, html;
-
-                       props = wp.media.string.props( props, attachment );
-                       shortcode = {};
-
-                       if ( props.mime ) {
-                               switch ( props.mime ) {
-                               case 'audio/mpeg':
-                                       if ( attachment.url.indexOf( 'mp3' ) )
-                                               shortcode.mp3 = attachment.url;
-                                       else if ( attachment.url.indexOf( 'm4a' ) )
-                                               shortcode.m4a = attachment.url;
-                                       break;
-                               case 'audio/mp3':
-                                       shortcode.mp3 = attachment.url;
-                                       break;
-                               case 'audio/m4a':
-                                       shortcode.m4a = attachment.url;
-                                       break;
-                               case 'audio/wav':
-                                       shortcode.wav = attachment.url;
-                                       break;
-                               case 'audio/ogg':
-                                       shortcode.ogg = attachment.url;
-                                       break;
-                               case 'audio/x-ms-wma':
-                               case 'audio/wma':
-                                       shortcode.wma = attachment.url;
-                                       break;
-                               default:
-                                       // Render unsupported audio files as links.
-                                       return wp.media.string.link( props );
-                               }
-                       }
-
-                       html = wp.shortcode.string({
-                               tag:     'audio',
-                               attrs:   shortcode
-                       });
-
-                       return html;
</del><ins>+                        return wp.media.string._audioVideo( 'audio', props, attachment );
</ins><span class="cx">           },
</span><span class="cx"> 
</span><span class="cx">          video: function( props, attachment ) {
</span><del>-                       var shortcode, html;
</del><ins>+                        return wp.media.string._audioVideo( 'video', props, attachment );
+               },
</ins><span class="cx"> 
</span><ins>+               _audioVideo: function( type, props, attachment ) {
+                       var shortcode, html, extension;
+
</ins><span class="cx">                   props = wp.media.string.props( props, attachment );
</span><ins>+                       if ( props.link !== 'embed' )
+                               return wp.media.string.link( props );
</ins><span class="cx"> 
</span><span class="cx">                  shortcode = {};
</span><span class="cx"> 
</span><del>-                       if ( attachment.width )
-                               shortcode.width = attachment.width;
</del><ins>+                        if ( 'video' === type ) {
+                               if ( attachment.width )
+                                       shortcode.width = attachment.width;
</ins><span class="cx"> 
</span><del>-                       if ( attachment.height )
-                               shortcode.height = attachment.height;
</del><ins>+                                if ( attachment.height )
+                                       shortcode.height = attachment.height;
+                       }
</ins><span class="cx"> 
</span><del>-                       if ( props.mime ) {
-                               switch ( props.mime ) {
-                               case 'video/mp4':
-                                       shortcode.mp4 = attachment.url;
-                                       break;
-                               case 'video/m4v':
-                                       shortcode.m4v = attachment.url;
-                                       break;
-                               case 'video/webm':
-                                       shortcode.webm = attachment.url;
-                                       break;
-                               case 'video/ogg':
-                                       shortcode.ogv = attachment.url;
-                                       break;
-                               case 'video/x-ms-wmv':
-                               case 'video/wmv':
-                               case 'video/asf':
-                                       shortcode.wmv = attachment.url;
-                                       break;
-                               case 'video/flv':
-                               case 'video/x-flv':
-                                       shortcode.flv = attachment.url;
-                                       break;
-                               }
</del><ins>+                        extension = attachment.filename.split('.').pop();
+
+                       if ( _.contains( wp.media.view.settings.embedExts, extension ) ) {
+                               shortcode[extension] = attachment.url;
+                       } else {
+                               // Render unsupported audio and video files as links.
+                               return wp.media.string.link( props );
</ins><span class="cx">                   }
</span><span class="cx"> 
</span><span class="cx">                  html = wp.shortcode.string({
</span><del>-                               tag:     'video',
</del><ins>+                                tag:     type,
</ins><span class="cx">                           attrs:   shortcode
</span><span class="cx">                  });
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpincludesjsmediaviewsjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/media-views.js (24776 => 24777)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/media-views.js      2013-07-23 04:58:52 UTC (rev 24776)
+++ trunk/wp-includes/js/media-views.js 2013-07-23 05:39:08 UTC (rev 24777)
</span><span class="lines">@@ -449,11 +449,26 @@
</span><span class="cx">                  var displays = this._displays;
</span><span class="cx"> 
</span><span class="cx">                  if ( ! displays[ attachment.cid ] )
</span><del>-                               displays[ attachment.cid ] = new Backbone.Model( this._defaultDisplaySettings );
</del><ins>+                                displays[ attachment.cid ] = new Backbone.Model( this.defaultDisplaySettings( attachment ) );
</ins><span class="cx"> 
</span><span class="cx">                  return displays[ attachment.cid ];
</span><span class="cx">          },
</span><span class="cx"> 
</span><ins>+               defaultDisplaySettings: function( attachment ) {
+                       settings = this._defaultDisplaySettings;
+                       if ( settings.canEmbed = this.canEmbed( attachment ) )
+                               settings.link = 'embed';
+                       return settings;
+               },
+
+               canEmbed: function( attachment ) {
+                       var type = attachment.get('type');
+                       if ( type !== 'audio' && type !== 'video' )
+                               return false;
+
+                       return _.contains( media.view.settings.embedExts, attachment.get('filename').split('.').pop() );
+               },
+
</ins><span class="cx">           syncSelection: function() {
</span><span class="cx">                  var selection = this.get('selection'),
</span><span class="cx">                          manager = this.frame._selection;
</span><span class="lines">@@ -3666,7 +3681,7 @@
</span><span class="cx">                          $input = this.$('.link-to-custom'),
</span><span class="cx">                          attachment = this.options.attachment;
</span><span class="cx"> 
</span><del>-                       if ( 'none' === linkTo || ( ! attachment && 'custom' !== linkTo ) ) {
</del><ins>+                        if ( 'none' === linkTo || 'embed' === linkTo || ( ! attachment && 'custom' !== linkTo ) ) {
</ins><span class="cx">                           $input.hide();
</span><span class="cx">                          return;
</span><span class="cx">                  }
</span></span></pre></div>
<a id="trunkwpincludesmediatemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/media-template.php (24776 => 24777)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/media-template.php     2013-07-23 04:58:52 UTC (rev 24776)
+++ trunk/wp-includes/media-template.php        2013-07-23 05:39:08 UTC (rev 24777)
</span><span class="lines">@@ -205,6 +205,10 @@
</span><span class="cx">                                  <# } #>
</span><span class="cx">                          <# } #>
</span><span class="cx"> 
</span><ins>+                               <# if ( data.fileLength ) { #>
+                                       <div class="file-length"><?php _e( 'Length:' ); ?> {{ data.fileLength }}</div>
+                               <# } #>
+
</ins><span class="cx">                           <# if ( ! data.uploading && data.can.remove ) { #>
</span><span class="cx">                                  <a class="delete-attachment" href="#"><?php _e( 'Delete Permanently' ); ?></a>
</span><span class="cx">                          <# } #>
</span><span class="lines">@@ -281,25 +285,52 @@
</span><span class="cx"> 
</span><span class="cx">          <div class="setting">
</span><span class="cx">                  <label>
</span><del>-                               <span><?php _e('Link To'); ?></span>
</del><ins>+                                <# if ( data.model.canEmbed ) { #>
+                                       <span><?php _e('Embed or Link'); ?></span>
+                               <# } else { #>
+                                       <span><?php _e('Link To'); ?></span>
+                               <# } #>
+
</ins><span class="cx">                           <select class="link-to"
</span><span class="cx">                                  data-setting="link"
</span><del>-                                       <# if ( data.userSettings ) { #>
</del><ins>+                                        <# if ( data.userSettings && ! data.model.canEmbed ) { #>
</ins><span class="cx">                                           data-user-setting="urlbutton"
</span><span class="cx">                                  <# } #>>
</span><span class="cx"> 
</span><del>-                                       <option value="custom">
-                                               <?php esc_attr_e('Custom URL'); ?>
</del><ins>+                                <# if ( data.model.canEmbed && 'audio' === data.type ) { #>
+                                       <option value="embed" selected>
+                                               <?php esc_attr_e('Embed Audio Player'); ?>
</ins><span class="cx">                                   </option>
</span><ins>+                                       <option value="file">
+                               <# } else if ( data.model.canEmbed && 'video' === data.type ) { #>
+                                       <option value="embed" selected>
+                                               <?php esc_attr_e('Embed Video Player'); ?>
+                                       </option>
+                                       <option value="file">
+                               <# } else { #>
</ins><span class="cx">                                   <option value="file" selected>
</span><ins>+                               <# } #>
+                                       <# if ( data.model.canEmbed ) { #>
+                                               <?php esc_attr_e('Link to Media File'); ?>
+                                       <# } else { #>
</ins><span class="cx">                                           <?php esc_attr_e('Media File'); ?>
</span><ins>+                                       <# } #>
</ins><span class="cx">                                   </option>
</span><span class="cx">                                  <option value="post">
</span><ins>+                                       <# if ( data.model.canEmbed ) { #>
+                                               <?php esc_attr_e('Link to Attachment Page'); ?>
+                                       <# } else { #>
</ins><span class="cx">                                           <?php esc_attr_e('Attachment Page'); ?>
</span><ins>+                                       <# } #>
</ins><span class="cx">                                   </option>
</span><ins>+                               <# if ( 'image' === data.type ) { #>
+                                       <option value="custom">
+                                               <?php esc_attr_e('Custom URL'); ?>
+                                       </option>
</ins><span class="cx">                                   <option value="none">
</span><span class="cx">                                          <?php esc_attr_e('None'); ?>
</span><span class="cx">                                  </option>
</span><ins>+                               <# } #>
</ins><span class="cx">                           </select>
</span><span class="cx">                  </label>
</span><span class="cx">                  <input type="text" class="link-to-custom" data-setting="linkUrl" />
</span></span></pre></div>
<a id="trunkwpincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/media.php (24776 => 24777)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/media.php      2013-07-23 04:58:52 UTC (rev 24776)
+++ trunk/wp-includes/media.php 2013-07-23 05:39:08 UTC (rev 24777)
</span><span class="lines">@@ -1699,6 +1699,11 @@
</span><span class="cx">                  $response['height'] = (int) $meta['height'];
</span><span class="cx">  }
</span><span class="cx"> 
</span><ins>+       if ( $meta && ( 'audio' === $type || 'video' === $type ) ) {
+               if ( isset( $meta['length_formatted'] ) )
+                       $response['fileLength'] = $meta['length_formatted'];
+       }
+
</ins><span class="cx">   if ( function_exists('get_compat_media_markup') )
</span><span class="cx">          $response['compat'] = get_compat_media_markup( $attachment->ID, array( 'in_modal' => true ) );
</span><span class="cx"> 
</span><span class="lines">@@ -1753,6 +1758,7 @@
</span><span class="cx">                  'id' => 0,
</span><span class="cx">          ),
</span><span class="cx">          'defaultProps' => $props,
</span><ins>+               'embedExts'    => array_merge( wp_get_audio_extensions(), wp_get_video_extensions() ),
</ins><span class="cx">   );
</span><span class="cx"> 
</span><span class="cx">  $post = null;
</span></span></pre>
</div>
</div>

</body>
</html>