Make WordPress Core

Changeset 24777


Ignore:
Timestamp:
07/23/2013 05:39:08 AM (13 years ago)
Author:
nacin
Message:

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 #24449.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/media.php

    r24696 r24777  
    24712471        <div class="misc-pub-section">
    24722472            <?php _e( 'Bitrate:' ); ?> <strong><?php
    2473                 echo $meta['bitrate'] / 1000, 'kb/s';
     2473                echo round( $meta['bitrate'] / 1000 ), 'kb/s';
    24742474
    24752475                if ( ! empty( $meta['bitrate_mode'] ) )
  • trunk/wp-includes/js/media-editor.js

    r24519 r24777  
    4646
    4747            link = props.link || defaultProps.link || getUserSetting( 'urlbutton', 'file' );
    48             if ( 'file' === link )
     48            if ( 'file' === link || 'embed' === link )
    4949                linkUrl = attachment.url;
    5050            else if ( 'post' === link )
     
    9898
    9999        audio: function( props, attachment ) {
    100             var shortcode, html;
     100            return wp.media.string._audioVideo( 'audio', props, attachment );
     101        },
     102
     103        video: function( props, attachment ) {
     104            return wp.media.string._audioVideo( 'video', props, attachment );
     105        },
     106
     107        _audioVideo: function( type, props, attachment ) {
     108            var shortcode, html, extension;
    101109
    102110            props = wp.media.string.props( props, attachment );
     111            if ( props.link !== 'embed' )
     112                return wp.media.string.link( props );
     113
    103114            shortcode = {};
    104115
    105             if ( props.mime ) {
    106                 switch ( props.mime ) {
    107                 case 'audio/mpeg':
    108                     if ( attachment.url.indexOf( 'mp3' ) )
    109                         shortcode.mp3 = attachment.url;
    110                     else if ( attachment.url.indexOf( 'm4a' ) )
    111                         shortcode.m4a = attachment.url;
    112                     break;
    113                 case 'audio/mp3':
    114                     shortcode.mp3 = attachment.url;
    115                     break;
    116                 case 'audio/m4a':
    117                     shortcode.m4a = attachment.url;
    118                     break;
    119                 case 'audio/wav':
    120                     shortcode.wav = attachment.url;
    121                     break;
    122                 case 'audio/ogg':
    123                     shortcode.ogg = attachment.url;
    124                     break;
    125                 case 'audio/x-ms-wma':
    126                 case 'audio/wma':
    127                     shortcode.wma = attachment.url;
    128                     break;
    129                 default:
    130                     // Render unsupported audio files as links.
    131                     return wp.media.string.link( props );
    132                 }
     116            if ( 'video' === type ) {
     117                if ( attachment.width )
     118                    shortcode.width = attachment.width;
     119
     120                if ( attachment.height )
     121                    shortcode.height = attachment.height;
     122            }
     123
     124            extension = attachment.filename.split('.').pop();
     125
     126            if ( _.contains( wp.media.view.settings.embedExts, extension ) ) {
     127                shortcode[extension] = attachment.url;
     128            } else {
     129                // Render unsupported audio and video files as links.
     130                return wp.media.string.link( props );
    133131            }
    134132
    135133            html = wp.shortcode.string({
    136                 tag:     'audio',
    137                 attrs:   shortcode
    138             });
    139 
    140             return html;
    141         },
    142 
    143         video: function( props, attachment ) {
    144             var shortcode, html;
    145 
    146             props = wp.media.string.props( props, attachment );
    147 
    148             shortcode = {};
    149 
    150             if ( attachment.width )
    151                 shortcode.width = attachment.width;
    152 
    153             if ( attachment.height )
    154                 shortcode.height = attachment.height;
    155 
    156             if ( props.mime ) {
    157                 switch ( props.mime ) {
    158                 case 'video/mp4':
    159                     shortcode.mp4 = attachment.url;
    160                     break;
    161                 case 'video/m4v':
    162                     shortcode.m4v = attachment.url;
    163                     break;
    164                 case 'video/webm':
    165                     shortcode.webm = attachment.url;
    166                     break;
    167                 case 'video/ogg':
    168                     shortcode.ogv = attachment.url;
    169                     break;
    170                 case 'video/x-ms-wmv':
    171                 case 'video/wmv':
    172                 case 'video/asf':
    173                     shortcode.wmv = attachment.url;
    174                     break;
    175                 case 'video/flv':
    176                 case 'video/x-flv':
    177                     shortcode.flv = attachment.url;
    178                     break;
    179                 }
    180             }
    181 
    182             html = wp.shortcode.string({
    183                 tag:     'video',
     134                tag:     type,
    184135                attrs:   shortcode
    185136            });
  • trunk/wp-includes/js/media-views.js

    r24367 r24777  
    450450
    451451            if ( ! displays[ attachment.cid ] )
    452                 displays[ attachment.cid ] = new Backbone.Model( this._defaultDisplaySettings );
     452                displays[ attachment.cid ] = new Backbone.Model( this.defaultDisplaySettings( attachment ) );
    453453
    454454            return displays[ attachment.cid ];
     455        },
     456
     457        defaultDisplaySettings: function( attachment ) {
     458            settings = this._defaultDisplaySettings;
     459            if ( settings.canEmbed = this.canEmbed( attachment ) )
     460                settings.link = 'embed';
     461            return settings;
     462        },
     463
     464        canEmbed: function( attachment ) {
     465            var type = attachment.get('type');
     466            if ( type !== 'audio' && type !== 'video' )
     467                return false;
     468
     469            return _.contains( media.view.settings.embedExts, attachment.get('filename').split('.').pop() );
    455470        },
    456471
     
    36673682                attachment = this.options.attachment;
    36683683
    3669             if ( 'none' === linkTo || ( ! attachment && 'custom' !== linkTo ) ) {
     3684            if ( 'none' === linkTo || 'embed' === linkTo || ( ! attachment && 'custom' !== linkTo ) ) {
    36703685                $input.hide();
    36713686                return;
  • trunk/wp-includes/media-template.php

    r24550 r24777  
    206206                <# } #>
    207207
     208                <# if ( data.fileLength ) { #>
     209                    <div class="file-length"><?php _e( 'Length:' ); ?> {{ data.fileLength }}</div>
     210                <# } #>
     211
    208212                <# if ( ! data.uploading && data.can.remove ) { #>
    209213                    <a class="delete-attachment" href="#"><?php _e( 'Delete Permanently' ); ?></a>
     
    282286        <div class="setting">
    283287            <label>
    284                 <span><?php _e('Link To'); ?></span>
     288                <# if ( data.model.canEmbed ) { #>
     289                    <span><?php _e('Embed or Link'); ?></span>
     290                <# } else { #>
     291                    <span><?php _e('Link To'); ?></span>
     292                <# } #>
     293
    285294                <select class="link-to"
    286295                    data-setting="link"
    287                     <# if ( data.userSettings ) { #>
     296                    <# if ( data.userSettings && ! data.model.canEmbed ) { #>
    288297                        data-user-setting="urlbutton"
    289298                    <# } #>>
    290299
     300                <# if ( data.model.canEmbed && 'audio' === data.type ) { #>
     301                    <option value="embed" selected>
     302                        <?php esc_attr_e('Embed Audio Player'); ?>
     303                    </option>
     304                    <option value="file">
     305                <# } else if ( data.model.canEmbed && 'video' === data.type ) { #>
     306                    <option value="embed" selected>
     307                        <?php esc_attr_e('Embed Video Player'); ?>
     308                    </option>
     309                    <option value="file">
     310                <# } else { #>
     311                    <option value="file" selected>
     312                <# } #>
     313                    <# if ( data.model.canEmbed ) { #>
     314                        <?php esc_attr_e('Link to Media File'); ?>
     315                    <# } else { #>
     316                        <?php esc_attr_e('Media File'); ?>
     317                    <# } #>
     318                    </option>
     319                    <option value="post">
     320                    <# if ( data.model.canEmbed ) { #>
     321                        <?php esc_attr_e('Link to Attachment Page'); ?>
     322                    <# } else { #>
     323                        <?php esc_attr_e('Attachment Page'); ?>
     324                    <# } #>
     325                    </option>
     326                <# if ( 'image' === data.type ) { #>
    291327                    <option value="custom">
    292328                        <?php esc_attr_e('Custom URL'); ?>
    293329                    </option>
    294                     <option value="file" selected>
    295                         <?php esc_attr_e('Media File'); ?>
    296                     </option>
    297                     <option value="post">
    298                         <?php esc_attr_e('Attachment Page'); ?>
    299                     </option>
    300330                    <option value="none">
    301331                        <?php esc_attr_e('None'); ?>
    302332                    </option>
     333                <# } #>
    303334                </select>
    304335            </label>
  • trunk/wp-includes/media.php

    r24685 r24777  
    17001700    }
    17011701
     1702    if ( $meta && ( 'audio' === $type || 'video' === $type ) ) {
     1703        if ( isset( $meta['length_formatted'] ) )
     1704            $response['fileLength'] = $meta['length_formatted'];
     1705    }
     1706
    17021707    if ( function_exists('get_compat_media_markup') )
    17031708        $response['compat'] = get_compat_media_markup( $attachment->ID, array( 'in_modal' => true ) );
     
    17541759        ),
    17551760        'defaultProps' => $props,
     1761        'embedExts'    => array_merge( wp_get_audio_extensions(), wp_get_video_extensions() ),
    17561762    );
    17571763
Note: See TracChangeset for help on using the changeset viewer.