Ticket #31139: 31139.2.diff
File 31139.2.diff, 9.6 KB (added by , 10 years ago) |
---|
-
src/wp-admin/includes/ajax-actions.php
2705 2705 } 2706 2706 2707 2707 $shortcode = wp_unslash( $_POST['shortcode'] ); 2708 $url = str_replace( '[embed]', '', str_replace( '[/embed]', '', $shortcode ) ); 2708 2709 preg_match( '/' . get_shortcode_regex() . '/s', $shortcode, $matches ); 2710 $atts = shortcode_parse_atts( $matches[3] ); 2711 if ( ! empty( $atts[5] ) ) { 2712 $url = $atts[5]; 2713 } elseif ( ! empty( $atts['src'] ) ) { 2714 $url = $atts['src']; 2715 } 2716 2709 2717 $parsed = false; 2710 2718 setup_postdata( $post ); 2711 2719 2712 2720 $wp_embed->return_false_on_fail = true; 2713 2721 2714 if ( is_ssl() && preg_match( '%^\\[embed[^\\]]*\\]http://%i', $shortcode) ) {2722 if ( is_ssl() && 0 === strpos( $url, 'http://' ) ) { 2715 2723 // Admin is ssl and the user pasted non-ssl URL. 2716 2724 // Check if the provider supports ssl embeds and use that for the preview. 2717 2725 $ssl_shortcode = preg_replace( '%^(\\[embed[^\\]]*\\])http://%i', '$1https://', $shortcode ); … … 2764 2772 } 2765 2773 2766 2774 wp_send_json_success( array( 2767 'body' => $parsed 2775 'body' => $parsed, 2776 'attr' => $wp_embed->last_attr 2768 2777 ) ); 2769 2778 } 2770 2779 -
src/wp-includes/class-wp-embed.php
11 11 public $post_ID; 12 12 public $usecache = true; 13 13 public $linkifunknown = true; 14 public $last_attr = array(); 15 public $last_url = ''; 14 16 15 17 /** 16 18 * When an URL cannot be embedded, return false instead of returning a link … … 134 136 $url = $attr['src']; 135 137 } 136 138 137 if ( empty( $url ) ) 139 $this->last_url = $url; 140 141 if ( empty( $url ) ) { 142 $this->last_attr = $attr; 138 143 return ''; 144 } 139 145 140 146 $rawattr = $attr; 141 147 $attr = wp_parse_args( $attr, wp_embed_defaults( $url ) ); 142 148 149 $this->last_attr = $attr; 150 143 151 // kses converts & into & and we need to undo this 144 152 // See https://core.trac.wordpress.org/ticket/11311 145 153 $url = str_replace( '&', '&', $url ); -
src/wp-includes/css/media-views.css
1951 1951 clear: both; 1952 1952 } 1953 1953 1954 .embed-link-settings .setting { 1955 display: none; 1956 } 1957 1958 .embed-link-dimensions:after { 1959 content: ''; 1960 display: block; 1961 clear: both; 1962 } 1963 1964 .embed-link-dimensions .width, 1965 .embed-link-dimensions .height { 1966 float: left; 1967 width: 125px; 1968 clear: none; 1969 margin-right: 10px; 1970 } 1971 1972 .embed-link-dimensions input { 1973 width: auto; 1974 max-width: 110px; 1975 } 1976 1954 1977 .image-details .embed-media-settings .setting { 1955 1978 float: none; 1956 1979 width: auto; … … 1997 2020 .media-embed .setting span { 1998 2021 display: block; 1999 2022 width: 200px; 2023 max-width: 100%; 2000 2024 font-size: 13px; 2001 2025 line-height: 24px; 2002 2026 color: #666; -
src/wp-includes/js/mce-view.js
763 763 edit: function( text, update ) { 764 764 var media = wp.media.embed, 765 765 frame = media.edit( text, !! this.url ), 766 self = this; 766 self = this, 767 events = 'change:url change:width change:height'; 767 768 768 769 this.pausePlayers(); 769 770 770 frame.state( 'embed' ).props.on( 'change:url', function( model, url ) {771 if ( url ) {771 frame.state( 'embed' ).props.on( events, function( model, url ) { 772 if ( url && model.get( 'url' ) ) { 772 773 frame.state( 'embed' ).metadata = model.toJSON(); 773 774 } 774 775 } ); 775 776 776 777 frame.state( 'embed' ).on( 'select', function() { 777 if ( self.url ) { 778 update( frame.state( 'embed' ).metadata.url ); 778 var data = frame.state( 'embed' ).metadata; 779 780 if ( data.width ) { 781 delete self.url; 779 782 } else { 780 update( media.shortcode( frame.state( 'embed' ).metadata ).string() );783 self.url = data.url; 781 784 } 785 786 if ( self.url ) { 787 update( data.url ); 788 } else { 789 update( media.shortcode( data ).string() ); 790 } 782 791 } ); 783 792 784 793 frame.on( 'close', function() { -
src/wp-includes/js/media/views/embed/link.js
20 20 initialize: function() { 21 21 this.spinner = $('<span class="spinner" />'); 22 22 this.$el.append( this.spinner[0] ); 23 this.listenTo( this.model, 'change:url ', this.updateoEmbed );23 this.listenTo( this.model, 'change:url change:width change:height', this.updateoEmbed ); 24 24 }, 25 25 26 updateoEmbed: function() {26 updateoEmbed: _.debounce( function() { 27 27 var url = this.model.get( 'url' ); 28 28 29 this.$('.setting.title').show();30 29 // clear out previous results 31 30 this.$('.embed-container').hide().find('.embed-preview').html(''); 32 31 … … 37 36 38 37 this.spinner.show(); 39 38 40 setTimeout( _.bind( this.fetch, this ), 500);41 }, 39 this.fetch(); 40 }, 600 ), 42 41 43 42 fetch: function() { 43 var embed; 44 44 45 // check if they haven't typed in 500 ms 45 46 if ( $('#embed-url-field').val() !== this.model.get('url') ) { 46 47 return; 47 48 } 48 49 50 embed = new wp.shortcode({ 51 tag: 'embed', 52 attrs: _.pick( this.model.attributes, [ 'width', 'height', 'src' ] ), 53 content: this.model.get('url') 54 }); 55 49 56 wp.ajax.send( 'parse-embed', { 50 57 data : { 51 58 post_ID: wp.media.view.settings.post.id, 52 shortcode: '[embed]' + this.model.get('url') + '[/embed]'59 shortcode: embed.string() 53 60 } 54 61 } ).done( _.bind( this.renderoEmbed, this ) ); 55 62 }, 56 63 57 64 renderoEmbed: function( response ) { 58 var html = ( response && response.body ) || ''; 65 var html = ( response && response.body ) || '', 66 attr = {}, 67 opts = { silent: true }; 59 68 69 if ( response && response.attr ) { 70 attr = response.attr; 71 72 _.each( [ 'width', 'height' ], function ( key ) { 73 var $el = this.$( '.setting.' + key ), 74 value = attr[ key ]; 75 76 if ( value ) { 77 this.model.set( key, value, opts ); 78 $el.show().find( 'input' ).val( value ); 79 } else { 80 this.model.unset( key, opts ); 81 $el.hide().find( 'input' ).val( '' ); 82 } 83 }, this ); 84 } else { 85 this.model.unset( 'height', opts ); 86 this.model.unset( 'width', opts ); 87 } 88 60 89 this.spinner.hide(); 61 90 62 this.$('.setting.title').hide();63 91 this.$('.embed-container').show().find('.embed-preview').html( html ); 64 92 } 65 93 }); -
src/wp-includes/js/media/views.js
4581 4581 initialize: function() { 4582 4582 this.spinner = $('<span class="spinner" />'); 4583 4583 this.$el.append( this.spinner[0] ); 4584 this.listenTo( this.model, 'change:url ', this.updateoEmbed );4584 this.listenTo( this.model, 'change:url change:width change:height', this.updateoEmbed ); 4585 4585 }, 4586 4586 4587 updateoEmbed: function() {4587 updateoEmbed: _.debounce( function() { 4588 4588 var url = this.model.get( 'url' ); 4589 4589 4590 this.$('.setting.title').show();4591 4590 // clear out previous results 4592 4591 this.$('.embed-container').hide().find('.embed-preview').html(''); 4593 4592 … … 4598 4597 4599 4598 this.spinner.show(); 4600 4599 4601 setTimeout( _.bind( this.fetch, this ), 500);4602 }, 4600 this.fetch(); 4601 }, 600 ), 4603 4602 4604 4603 fetch: function() { 4604 var embed; 4605 4605 4606 // check if they haven't typed in 500 ms 4606 4607 if ( $('#embed-url-field').val() !== this.model.get('url') ) { 4607 4608 return; 4608 4609 } 4609 4610 4611 embed = new wp.shortcode({ 4612 tag: 'embed', 4613 attrs: _.pick( this.model.attributes, [ 'width', 'height', 'src' ] ), 4614 content: this.model.get('url') 4615 }); 4616 4610 4617 wp.ajax.send( 'parse-embed', { 4611 4618 data : { 4612 4619 post_ID: wp.media.view.settings.post.id, 4613 shortcode: '[embed]' + this.model.get('url') + '[/embed]'4620 shortcode: embed.string() 4614 4621 } 4615 4622 } ).done( _.bind( this.renderoEmbed, this ) ); 4616 4623 }, 4617 4624 4618 4625 renderoEmbed: function( response ) { 4619 var html = ( response && response.body ) || ''; 4626 var html = ( response && response.body ) || '', 4627 attr = {}, 4628 opts = { silent: true }; 4620 4629 4630 if ( response && response.attr ) { 4631 attr = response.attr; 4632 4633 _.each( [ 'width', 'height' ], function ( key ) { 4634 var $el = this.$( '.setting.' + key ), 4635 value = attr[ key ]; 4636 4637 if ( value ) { 4638 this.model.set( key, value, opts ); 4639 $el.show().find( 'input' ).val( value ); 4640 } else { 4641 this.model.unset( key, opts ); 4642 $el.hide().find( 'input' ).val( '' ); 4643 } 4644 }, this ); 4645 } else { 4646 this.model.unset( 'height', opts ); 4647 this.model.unset( 'width', opts ); 4648 } 4649 4621 4650 this.spinner.hide(); 4622 4651 4623 this.$('.setting.title').hide();4624 4652 this.$('.embed-container').show().find('.embed-preview').html( html ); 4625 4653 } 4626 4654 }); -
src/wp-includes/media-template.php
816 816 <span><?php _e( 'Title' ); ?></span> 817 817 <input type="text" class="alignment" data-setting="title" /> 818 818 </label> 819 <div class="embed-link-dimensions"> 820 <label class="setting width"> 821 <span><?php _e( 'Maximum Width' ); ?></span> 822 <input type="text" class="alignment" data-setting="width" /> 823 </label> 824 <label class="setting height"> 825 <span><?php _e( 'Maximum Height' ); ?></span> 826 <input type="text" class="alignment" data-setting="height" /> 827 </label> 828 </div> 819 829 <div class="embed-container" style="display: none;"> 820 830 <div class="embed-preview"></div> 821 831 </div>