Ticket #42039: 42039.diff
File 42039.diff, 5.4 KB (added by , 7 years ago) |
---|
-
src/wp-admin/js/widgets/media-video-widget.js
134 134 }, 135 135 136 136 /** 137 * Whether a url is a supported external host.137 * Whether MediaElement.js can directly play the URL from an external providers. 138 138 * 139 139 * @param {String} url - Video url. 140 140 * @returns {boolean} Whether url is a supported video host. … … 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, html = '', canHostedVideoPlayByMEJS = false, 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' ); … … 161 161 } 162 162 163 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; 164 canHostedVideoPlayByMEJS = control.isHostedVideo( attachmentUrl ); 170 165 } 171 166 172 167 // Verify the selected attachment mime is supported. … … 175 170 if ( ! _.contains( _.values( wp.media.view.settings.embedMimes ), mime ) ) { 176 171 error = 'unsupported_file_type'; 177 172 } 173 } else if ( ! attachmentId ) { 174 urlParser = document.createElement( 'a' ); 175 urlParser.href = attachmentUrl; 176 matches = urlParser.pathname.toLowerCase().match( /\.(\w+)$/ ); 177 if ( matches ) { 178 if ( ! _.contains( _.keys( wp.media.view.settings.embedMimes ), matches[1] ) ) { 179 error = 'unsupported_file_type'; 180 } 181 } else { 182 isOEmbed = true; 183 } 184 } 185 186 if ( isOEmbed ) { 187 control.fetchEmbed(); 188 if ( control.oembedResponses[ attachmentUrl ] ) { 189 html = control.oembedResponses[ attachmentUrl ].html.replace( /\swidth="\d+"/, ' width="100%"' ).replace( /\sheight="\d+"/, '' ); 190 } 178 191 } 179 192 180 193 previewContainer = control.$el.find( '.media-widget-preview' ); … … 182 195 183 196 previewContainer.html( previewTemplate({ 184 197 model: { 185 attachment_id: control.model.get( 'attachment_id' ),198 attachment_id: attachmentId, 186 199 src: attachmentUrl, 187 poster: poster200 html: html 188 201 }, 189 is_hosted_embed: isHostedEmbed, 202 is_hosted_embed: canHostedVideoPlayByMEJS, 203 is_oembed: isOEmbed, 190 204 error: error 191 205 })); 192 206 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 $yt_pattern = '#^https?://(?:www\.)?(?:youtube\.com/watch|youtu\.be/)#'; 125 $vimeo_pattern = '#^https?://(.+\.)?vimeo\.com/.*#'; 126 if ( ! $attachment && ! preg_match( $yt_pattern, $src ) && ! preg_match( $vimeo_pattern, $src ) ) { 127 echo $this->inject_video_max_width_style( wp_oembed_get( $src ) ); 128 129 } else { 130 add_filter( 'wp_video_shortcode', array( $this, 'inject_video_max_width_style' ) ); 131 132 echo wp_video_shortcode( 133 array_merge( 134 $instance, 135 compact( 'src' ) 136 ), 137 $instance['content'] 138 ); 125 139 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' ) ); 140 remove_filter( 'wp_video_shortcode', array( $this, 'inject_video_max_width_style' ) ); 141 } 135 142 } 136 143 137 144 /** … … 227 234 <div class="notice notice-error notice-alt"> 228 235 <p><?php _e( 'Unable to preview media due to an unknown error.' ); ?></p> 229 236 </div> 230 <# } else if ( data.is_hosted_embed && data.model.poster ) { #> 231 <a href="{{ data.model.src }}" target="_blank" class="media-widget-video-link"> 232 <img src="{{ data.model.poster }}" /> 233 </a> 234 <# } else if ( data.is_hosted_embed ) { #> 235 <a href="{{ data.model.src }}" target="_blank" class="media-widget-video-link no-poster"> 236 <span class="dashicons dashicons-format-video"></span> 237 </a> 237 <# } else if ( data.is_oembed ) { #> 238 {{{ data.model.html }}} 238 239 <# } else if ( data.model.src ) { #> 239 240 <?php wp_underscore_video_template() ?> 240 241 <# } #>