Ticket #27891: 27891.diff
File 27891.diff, 15.5 KB (added by , 10 years ago) |
---|
-
src/wp-includes/js/mce-view.js
428 428 this.players = []; 429 429 this.shortcode = options.shortcode; 430 430 _.bindAll( this, 'setPlayer' ); 431 this.fetch(); 431 432 $(this).on( 'ready', this.setPlayer ); 432 433 }, 433 434 435 fetch: function () { 436 var ids = [], allowed = this.allowedExts( this.shortcode.tag ); 437 438 _.each( this.shortcode.attrs.named, function (value, name) { 439 if ( -1 !== $.inArray( name, allowed ) && value.match(/^[0-9]+$/) ) { 440 ids.push( parseInt( value, 10 ) ); 441 } 442 } ); 443 444 if ( ids.length ) { 445 if ( 'video' === this.shortcode.tag 446 && this.shortcode.attrs.named.poster.match(/^[0-9]+$/) ) { 447 ids.push( this.shortcode.attrs.named.poster ); 448 } 449 this.attachments = wp.media.query( { post__in: ids } ); 450 this.dfd = this.attachments.more().done( _.bind( this.render, this ) ); 451 } else { 452 this.dfd = false; 453 } 454 }, 455 434 456 /** 435 457 * Creates the player instance for the current node 436 458 * … … 446 468 return; 447 469 } 448 470 471 if ( this.dfd && 'pending' === this.dfd.state() && ! this.attachments.length ) { 472 return; 473 } 474 449 475 var self = this, 450 476 media, 451 477 firefox = this.ua.is( 'ff' ), … … 487 513 * @returns {string} 488 514 */ 489 515 getHtml: function() { 490 var attrs = _.defaults( 516 if ( this.dfd && 'pending' === this.dfd.state() && ! this.attachments.length ) { 517 return; 518 } 519 520 var options, attrs = _.defaults( 491 521 this.shortcode.attrs.named, 492 522 wp.media[ this.shortcode.tag ].defaults 493 523 ); 494 return this.template({ model: attrs }); 524 525 options = { 526 model: attrs, 527 attachments: this.attachments.toJSON() 528 }; 529 530 return this.template( options ); 495 531 }, 496 532 497 533 unbind: function() { -
src/wp-includes/js/media-audiovideo.js
26 26 } 27 27 }, 28 28 29 allowedExts: function( type ) { 30 return _.filter( _.keys( wp.media.view.settings.embedMimes ), function (key) { 31 return 0 === wp.media.view.settings.embedMimes[ key ].indexOf( type ); 32 } ); 33 }, 34 29 35 /** 30 36 * Utility to identify the user's browser 31 37 */ … … 309 315 * @augments Backbone.Model 310 316 */ 311 317 media.model.PostMedia = Backbone.Model.extend({ 312 initialize: function() { 313 this.attachment = false; 318 initialize: function( attributes ) { 319 this.attachments = false; 320 this.params = attributes; 321 this.type = this.params.context; 322 323 this.getIds( attributes ); 324 this.on( 'change', this.reQuery, this ); 314 325 }, 315 326 327 reQuery: function () { 328 this.params = this.attributes; 329 this.getIds( this.params ); 330 }, 331 332 getIds: function (attributes) { 333 var ids = [], allowed = media.mixin.allowedExts( this.type ); 334 335 _.each( attributes, function (value, name) { 336 if ( -1 !== $.inArray( name, allowed ) && value.match(/^[0-9]+$/) ) { 337 ids.push( parseInt( value, 10 ) ); 338 } 339 } ); 340 341 if ( ids.length ) { 342 if ( 'video' === this.type 343 && attributes.poster.toString().match(/^[0-9]+$/) ) { 344 ids.push( attributes.poster ); 345 } 346 this.attachments = wp.media.query( { post__in: ids } ); 347 this.dfd = this.attachments.more(); 348 } 349 }, 350 316 351 setSource: function( attachment ) { 317 352 this.attachment = attachment; 318 353 this.extension = attachment.get( 'filename' ).split('.').pop(); … … 322 357 } 323 358 324 359 if ( _.contains( wp.media.view.settings.embedExts, this.extension ) ) { 325 this.set( this.extension, this.attachment.get( ' url' ) );360 this.set( this.extension, this.attachment.get( 'id' ) ); 326 361 } else { 327 362 this.unset( this.extension ); 328 363 } … … 416 451 this.cancelText = options.cancelText; 417 452 this.addText = options.addText; 418 453 454 options.metadata.context = this.defaults.id; 455 419 456 this.media = new media.model.PostMedia( options.metadata ); 420 457 this.options.selection = new media.model.Selection( this.media.attachment, { multiple: false } ); 421 458 media.view.MediaFrame.Select.prototype.initialize.apply( this, arguments ); … … 436 473 var view = new this.DetailsView({ 437 474 controller: this, 438 475 model: this.state().media, 439 attachment : this.state().media.attachment476 attachments: this.state().media.attachments.toJSON() 440 477 }).render(); 441 478 442 479 this.content.set( view ); … … 668 705 this.setPrimaryButton( l10n.videoSelectPosterImageTitle, function( controller, state ) { 669 706 var attachment = state.get( 'selection' ).single(); 670 707 671 controller.media.set( 'poster', attachment.get( ' url' ) );708 controller.media.set( 'poster', attachment.get( 'id' ) ); 672 709 state.trigger( 'set-poster-image', controller.media.toJSON() ); 673 710 } ); 674 711 }, -
src/wp-includes/js/media-editor.js
190 190 191 191 if ( 'video' === type ) { 192 192 if ( attachment.image && -1 === attachment.image.src.indexOf( attachment.icon ) ) { 193 shortcode.poster = attachment.image. src;193 shortcode.poster = attachment.image.id; 194 194 } 195 195 196 196 if ( attachment.width ) { … … 205 205 extension = attachment.filename.split('.').pop(); 206 206 207 207 if ( _.contains( wp.media.view.settings.embedExts, extension ) ) { 208 shortcode[extension] = attachment. url;208 shortcode[extension] = attachment.id; 209 209 } else { 210 210 // Render unsupported audio and video files as links. 211 211 return wp.media.string.link( props ); -
src/wp-includes/media-template.php
16 16 function wp_underscore_audio_template() { 17 17 $audio_types = wp_get_audio_extensions(); 18 18 ?> 19 <# var resolvedSrc; #> 19 20 <audio controls 20 21 class="wp-audio-shortcode" 21 22 width="{{ _.isUndefined( data.model.width ) ? 400 : data.model.width }}" … … 27 28 } 28 29 <?php endforeach ?>#> 29 30 > 30 <# if ( ! _.isEmpty( data.model.src ) ) { #> 31 <source src="{{ data.model.src }}" type="{{ wp.media.view.settings.embedMimes[ data.model.src.split('.').pop() ] }}" /> 31 <# if ( ! _.isEmpty( data.model.src ) ) { 32 resolvedSrc = data.model.src.match(/^[0-9]+$/) ? _.findWhere( data.attachments, { id: parseInt( data.model.src, 10 ) } ).url : data.model.src; 33 #> 34 <source src="{{ resolvedSrc }}" type="{{ wp.media.view.settings.embedMimes[ data.model.src.split('.').pop() ] }}" /> 32 35 <# } #> 33 36 34 37 <?php foreach ( $audio_types as $type ): 35 ?><# if ( ! _.isEmpty( data.model.<?php echo $type ?> ) ) { #> 36 <source src="{{ data.model.<?php echo $type ?> }}" type="{{ wp.media.view.settings.embedMimes[ '<?php echo $type ?>' ] }}" /> 38 ?><# if ( ! _.isEmpty( data.model.<?php echo $type ?> ) ) { 39 resolvedSrc = data.model.<?php echo $type ?>.match(/^[0-9]+$/) ? _.findWhere( data.attachments, { id: parseInt( data.model.<?php echo $type ?>, 10 ) } ).url : data.model.<?php echo $type ?>; 40 #> 41 <source src="{{ resolvedSrc }}" type="{{ wp.media.view.settings.embedMimes[ '<?php echo $type ?>' ] }}" /> 37 42 <# } #> 38 43 <?php endforeach; 39 44 ?></audio> … … 49 54 function wp_underscore_video_template() { 50 55 $video_types = wp_get_video_extensions(); 51 56 ?> 52 <# var w, h, settings = wp.media.view.settings, 57 <# var w, h, settings = wp.media.view.settings, resolvedSrc, 53 58 isYouTube = ! _.isEmpty( data.model.src ) && data.model.src.match(/youtube|youtu\.be/); 54 59 60 console.log( data ); 61 55 62 if ( settings.contentWidth && data.model.width >= settings.contentWidth ) { 56 63 w = settings.contentWidth; 57 64 } else { … … 69 76 class="wp-video-shortcode{{ isYouTube ? ' youtube-video' : '' }}" 70 77 width="{{ w }}" 71 78 height="{{ h }}" 72 <?php 73 $props = array( 'poster' => '', 'preload' => 'metadata' ); 74 foreach ( $props as $key => $value ): 75 if ( empty( $value ) ) { 76 ?><# 77 if ( ! _.isUndefined( data.model.<?php echo $key ?> ) && data.model.<?php echo $key ?> ) { 78 #> <?php echo $key ?>="{{ data.model.<?php echo $key ?> }}"<# 79 } #> 80 <?php } else { 81 echo $key ?>="{{ _.isUndefined( data.model.<?php echo $key ?> ) ? '<?php echo $value ?>' : data.model.<?php echo $key ?> }}"<?php 82 } 83 endforeach; 84 ?><# 79 <# if ( ! _.isUndefined( data.model.poster ) && data.model.poster ) { 80 resolvedSrc = data.model.poster.match(/^[0-9]+$/) ? _.findWhere( data.attachments, { id: parseInt( data.model.poster, 10 ) } ).url : data.model.poster; 81 #> poster="{{ resolvedSrc }}"<# 82 } #> 83 metadata="{{ _.isUndefined( data.model.preload ) ? 'metadata' : data.model.preload }}" 84 <# 85 85 <?php foreach ( array( 'autoplay', 'loop' ) as $attr ): 86 86 ?> if ( ! _.isUndefined( data.model.<?php echo $attr ?> ) && data.model.<?php echo $attr ?> ) { 87 87 #> <?php echo $attr ?><# … … 91 91 <# if ( ! _.isEmpty( data.model.src ) ) { 92 92 if ( isYouTube ) { #> 93 93 <source src="{{ data.model.src }}" type="video/youtube" /> 94 <# } else { #> 95 <source src="{{ data.model.src }}" type="{{ settings.embedMimes[ data.model.src.split('.').pop() ] }}" /> 94 <# } else { 95 resolvedSrc = data.model.src.match(/^[0-9]+$/) ? _.findWhere( data.attachments, { id: parseInt( data.model.src, 10 ) } ).url : data.model.src; 96 #> 97 <source src="{{ resolvedSrc }}" type="{{ settings.embedMimes[ data.model.src.split('.').pop() ] }}" /> 96 98 <# } 97 99 } #> 98 100 99 101 <?php foreach ( $video_types as $type ): 100 ?><# if ( data.model.<?php echo $type ?> ) { #> 101 <source src="{{ data.model.<?php echo $type ?> }}" type="{{ settings.embedMimes[ '<?php echo $type ?>' ] }}" /> 102 ?><# if ( data.model.<?php echo $type ?> ) { 103 resolvedSrc = data.model.<?php echo $type ?>.match(/^[0-9]+$/) ? _.findWhere( data.attachments, { id: parseInt( data.model.<?php echo $type ?>, 10 ) } ).url : data.model.<?php echo $type ?>; 104 #> 105 <source src="{{ resolvedSrc }}" type="{{ settings.embedMimes[ '<?php echo $type ?>' ] }}" /> 102 106 <# } #> 103 107 <?php endforeach; ?> 104 108 {{{ data.model.content }}} … … 812 816 #> 813 817 <label class="setting"> 814 818 <span>SRC</span> 819 <# if ( data.model.src.match(/^[0-9]+$/) ) { 820 resolvedSrc = _.findWhere( data.attachments, {id: parseInt( data.model.src, 10 )} ).url; 821 #> 822 <input type="text" disabled="disabled" value="{{ resolvedSrc }}" /> 823 <input type="hidden" data-setting="src" value="{{ data.model.src }}" /> 824 <# } else { #> 815 825 <input type="text" disabled="disabled" data-setting="src" value="{{ data.model.src }}" /> 826 <# } #> 816 827 <a class="remove-setting"><?php _e( 'Remove' ); ?></a> 817 828 </label> 818 829 <# } #> … … 826 837 #> 827 838 <label class="setting"> 828 839 <span><?php echo strtoupper( $type ) ?></span> 840 <# if ( data.model.<?php echo $type ?>.match(/^[0-9]+$/) ) { 841 resolvedSrc = _.findWhere( data.attachments, {id: parseInt( data.model.<?php echo $type ?>, 10 )} ).url; 842 #> 843 <input type="text" disabled="disabled" value="{{ resolvedSrc }}" /> 844 <input type="hidden" data-setting="<?php echo $type ?>" value="{{ data.model.<?php echo $type ?> }}" /> 845 <# } else { #> 829 846 <input type="text" disabled="disabled" data-setting="<?php echo $type ?>" value="{{ data.model.<?php echo $type ?> }}" /> 830 < a class="remove-setting"><?php _e( 'Remove' ); ?></a>847 <# } #><a class="remove-setting"><?php _e( 'Remove' ); ?></a> 831 848 </label> 832 849 <# } #> 833 850 <?php endforeach ?> … … 867 884 </script> 868 885 869 886 <script type="text/html" id="tmpl-video-details"> 870 <# var ext, html5types = {887 <# var resolvedSrc, ext, html5types = { 871 888 mp4: wp.media.view.settings.embedMimes.mp4, 872 889 ogv: wp.media.view.settings.embedMimes.ogv, 873 890 webm: wp.media.view.settings.embedMimes.webm … … 897 914 #> 898 915 <label class="setting"> 899 916 <span>SRC</span> 917 <# if ( data.model.src.match(/^[0-9]+$/) ) { 918 resolvedSrc = _.findWhere( data.attachments, {id: parseInt( data.model.src, 10 )} ).url; 919 #> 920 <input type="text" disabled="disabled" value="{{ resolvedSrc }}" /> 921 <input type="hidden" data-setting="src" value="{{ data.model.src }}" /> 922 <# } else { #> 900 923 <input type="text" disabled="disabled" data-setting="src" value="{{ data.model.src }}" /> 924 <# } #> 901 925 <a class="remove-setting"><?php _e( 'Remove' ); ?></a> 902 926 </label> 903 927 <# } #> … … 909 933 #> 910 934 <label class="setting"> 911 935 <span><?php echo strtoupper( $type ) ?></span> 936 <# if ( data.model.<?php echo $type ?>.match(/^[0-9]+$/) ) { 937 resolvedSrc = _.findWhere( data.attachments, {id: parseInt( data.model.<?php echo $type ?>, 10 )} ).url; 938 #> 939 <input type="text" disabled="disabled" value="{{ resolvedSrc }}" /> 940 <input type="hidden" data-setting="<?php echo $type ?>" value="{{ data.model.<?php echo $type ?> }}" /> 941 <# } else { #> 912 942 <input type="text" disabled="disabled" data-setting="<?php echo $type ?>" value="{{ data.model.<?php echo $type ?> }}" /> 943 <# } #> 913 944 <a class="remove-setting"><?php _e( 'Remove' ); ?></a> 914 945 </label> 915 946 <# } #> … … 930 961 <# if ( ! _.isEmpty( data.model.poster ) ) { #> 931 962 <label class="setting"> 932 963 <span><?php _e( 'Poster Image' ); ?></span> 964 <# if ( data.model.poster.match(/^[0-9]+$/) ) { 965 resolvedSrc = _.findWhere( data.attachments, {id: parseInt( data.model.poster, 10 )} ).url; 966 #> 967 <input type="text" disabled="disabled" value="{{ resolvedSrc }}" /> 968 <input type="hidden" data-setting="poster" value="{{ data.model.poster }}" /> 969 <# } else { #> 933 970 <input type="text" disabled="disabled" data-setting="poster" value="{{ data.model.poster }}" /> 971 <# } #> 934 972 <a class="remove-setting"><?php _e( 'Remove' ); ?></a> 935 973 </label> 936 974 <# } #> -
src/wp-includes/media.php
1713 1713 1714 1714 $primary = false; 1715 1715 if ( ! empty( $src ) ) { 1716 if ( is_numeric( $src ) ) { 1717 $src = get_attached_file( $src ); 1718 } 1719 1716 1720 if ( ! preg_match( $yt_pattern, $src ) ) { 1717 1721 $type = wp_check_filetype( $src, wp_get_mime_types() ); 1718 1722 if ( ! in_array( strtolower( $type['ext'] ), $default_types ) ) { … … 1724 1728 } else { 1725 1729 foreach ( $default_types as $ext ) { 1726 1730 if ( ! empty( $$ext ) ) { 1731 if ( is_numeric( $$ext ) ) { 1732 $$ext = get_attached_file( $$ext ); 1733 if ( empty( $$ext ) ) { 1734 continue; 1735 } 1736 } 1737 1727 1738 $type = wp_check_filetype( $$ext, wp_get_mime_types() ); 1728 1739 if ( strtolower( $type['ext'] ) === $ext ) 1729 1740 $primary = true; … … 2615 2626 $id = get_post_thumbnail_id( $attachment->ID ); 2616 2627 if ( ! empty( $id ) ) { 2617 2628 list( $src, $width, $height ) = wp_get_attachment_image_src( $id, 'full' ); 2618 $response['image'] = compact( ' src', 'width', 'height' );2629 $response['image'] = compact( 'id', 'src', 'width', 'height' ); 2619 2630 list( $src, $width, $height ) = wp_get_attachment_image_src( $id, 'thumbnail' ); 2620 $response['thumb'] = compact( ' src', 'width', 'height' );2631 $response['thumb'] = compact( 'id', 'src', 'width', 'height' ); 2621 2632 } else { 2633 $id = 0; 2622 2634 $src = wp_mime_type_icon( $attachment->ID ); 2623 2635 $width = 48; 2624 2636 $height = 64; 2625 $response['image'] = compact( ' src', 'width', 'height' );2626 $response['thumb'] = compact( ' src', 'width', 'height' );2637 $response['image'] = compact( 'id', 'src', 'width', 'height' ); 2638 $response['thumb'] = compact( 'id', 'src', 'width', 'height' ); 2627 2639 } 2628 2640 } 2629 2641