Ticket #42039: 42039.2.diff
| File 42039.2.diff, 6.7 KB (added by , 9 years ago) |
|---|
-
src/wp-admin/js/widgets/media-video-widget.js
136 136 /** 137 137 * Whether a url is a supported external host. 138 138 * 139 * @deprecated since 4.9. 140 * 139 141 * @param {String} url - Video url. 140 142 * @returns {boolean} Whether url is a supported video host. 141 143 */ 142 144 isHostedVideo: function isHostedVideo( url ) { 143 var parsedUrl = document.createElement( 'a' ); 144 parsedUrl.href = url; 145 return /vimeo|youtu\.?be/.test( parsedUrl.host ); 145 return false; 146 146 }, 147 147 148 148 /** … … 151 151 * @returns {void} 152 152 */ 153 153 renderPreview: function renderPreview() { 154 var control = this, previewContainer, previewTemplate, attachmentId, attachmentUrl, poster, isHostedEmbed = false, mime, error;154 var control = this, previewContainer, previewTemplate, attachmentId, attachmentUrl, poster, html = '', isOEmbed = false, mime, error, urlParser, matches; 155 155 attachmentId = control.model.get( 'attachment_id' ); 156 156 attachmentUrl = control.model.get( 'url' ); 157 157 error = control.model.get( 'error' ); … … 160 160 return; 161 161 } 162 162 163 if ( ! attachmentId && attachmentUrl ) {164 isHostedEmbed = control.isHostedVideo( attachmentUrl );165 }166 167 if ( isHostedEmbed ) {168 control.fetchEmbed();169 poster = control.oembedResponses[ attachmentUrl ] ? control.oembedResponses[ attachmentUrl ].thumbnail_url : null;170 }171 172 163 // Verify the selected attachment mime is supported. 173 164 mime = control.selectedAttachment.get( 'mime' ); 174 165 if ( mime && attachmentId ) { 175 166 if ( ! _.contains( _.values( wp.media.view.settings.embedMimes ), mime ) ) { 176 167 error = 'unsupported_file_type'; 177 168 } 169 } else if ( ! attachmentId ) { 170 urlParser = document.createElement( 'a' ); 171 urlParser.href = attachmentUrl; 172 matches = urlParser.pathname.toLowerCase().match( /\.(\w+)$/ ); 173 if ( matches ) { 174 if ( ! _.contains( _.keys( wp.media.view.settings.embedMimes ), matches[1] ) ) { 175 error = 'unsupported_file_type'; 176 } 177 } else { 178 isOEmbed = true; 179 } 180 } 181 182 if ( isOEmbed ) { 183 control.fetchEmbed(); 184 if ( control.oembedResponses[ attachmentUrl ] ) { 185 poster = control.oembedResponses[ attachmentUrl ].thumbnail_url; 186 html = control.oembedResponses[ attachmentUrl ].html.replace( /\swidth="\d+"/, ' width="100%"' ).replace( /\sheight="\d+"/, '' ); 187 } 178 188 } 179 189 180 190 previewContainer = control.$el.find( '.media-widget-preview' ); … … 182 192 183 193 previewContainer.html( previewTemplate({ 184 194 model: { 185 attachment_id: control.model.get( 'attachment_id' ), 195 attachment_id: attachmentId, 196 html: html, 186 197 src: attachmentUrl, 187 198 poster: poster 188 199 }, 189 is_ hosted_embed: isHostedEmbed,200 is_oembed: isOEmbed, 190 201 error: error 191 202 })); 192 203 wp.mediaelement.initialize(); -
src/wp-admin/js/widgets/media-widgets.js
184 184 return; 185 185 } 186 186 187 // If video, test for Vimeo and YouTube, otherwise, renderFail(). This should be removed once #34115 is resolved.188 if ( 'video' === this.controller.options.mimeType && ! /vimeo|youtu\.?be/.test( urlParser.host ) ) {189 embedLinkView.renderFail();190 return;191 }192 193 187 // Support YouTube embed links. 194 188 url = embedLinkView.model.get( 'url' ); 195 189 re = /https?:\/\/www\.youtube\.com\/embed\/([^/]+)/; -
src/wp-includes/widgets/class-wp-widget-media-video.php
121 121 return; 122 122 } 123 123 124 add_filter( 'wp_video_shortcode', array( $this, 'inject_video_max_width_style' ) ); 124 if ( $attachment ) { 125 add_filter( 'wp_video_shortcode', array( $this, 'inject_video_max_width_style' ) ); 125 126 126 echo wp_video_shortcode( 127 array_merge( 128 $instance, 129 compact( 'src' ) 130 ), 131 $instance['content'] 132 ); 133 134 remove_filter( 'wp_video_shortcode', array( $this, 'inject_video_max_width_style' ) ); 127 echo wp_video_shortcode( 128 array_merge( 129 $instance, 130 compact( 'src' ) 131 ), 132 $instance['content'] 133 ); 134 135 remove_filter( 'wp_video_shortcode', array( $this, 'inject_video_max_width_style' ) ); 136 } else { 137 echo $this->inject_video_max_width_style( wp_oembed_get( $src ) ); 138 } 135 139 } 136 140 137 141 /** … … 227 231 <div class="notice notice-error notice-alt"> 228 232 <p><?php _e( 'Unable to preview media due to an unknown error.' ); ?></p> 229 233 </div> 230 <# } else if ( data.is_hosted_embed && data.model.poster ) { #> 234 <# } else if ( data.model.html ) { #> 235 {{{ data.model.html }}} 236 <# } else if ( data.is_oembed && data.model.poster ) { #> 231 237 <a href="{{ data.model.src }}" target="_blank" class="media-widget-video-link"> 232 238 <img src="{{ data.model.poster }}" /> 233 239 </a> 234 <# } else if ( data.is_ hosted_embed ) { #>240 <# } else if ( data.is_oembed ) { #> 235 241 <a href="{{ data.model.src }}" target="_blank" class="media-widget-video-link no-poster"> 236 242 <span class="dashicons dashicons-format-video"></span> 237 243 </a> -
tests/qunit/wp-admin/js/widgets/test-media-video-widget.js
34 34 equal( mappedProps.title, undefined, 'mapMediaToModelProps should ignore title inputs' ); 35 35 equal( mappedProps.loop, false, 'mapMediaToModelProps should set loop' ); 36 36 equal( mappedProps.preload, 'meta', 'mapMediaToModelProps should set preload' ); 37 38 // Test isHostedVideo().39 equal( videoWidgetControlInstance.isHostedVideo( 'https://www.youtube.com/watch?v=OQSNhk5ICTI' ), true, 'isHostedVideo should return true for full YouTube url.' );40 equal( videoWidgetControlInstance.isHostedVideo( 'https://youtu.be/OQSNhk5ICTI' ), true, 'isHostedVideo should return true for shortened youtube url' );41 equal( videoWidgetControlInstance.isHostedVideo( 'https://vimeo.com/190372437' ), true, 'isHostedVideo should return true for vimeo url.' );42 equal( videoWidgetControlInstance.isHostedVideo( 'https://wordpress.org/' ), false, 'isHostedVideo should return false for non-supported video url.' );43 37 }); 44 38 45 39 test( 'video widget control renderPreview', function( assert ) {