diff options
Diffstat (limited to 'plugins/jetpack/modules/videopress')
4 files changed, 83 insertions, 1 deletions
diff --git a/plugins/jetpack/modules/videopress/class.jetpack-videopress.php b/plugins/jetpack/modules/videopress/class.jetpack-videopress.php index c765d37a..46c12a28 100644 --- a/plugins/jetpack/modules/videopress/class.jetpack-videopress.php +++ b/plugins/jetpack/modules/videopress/class.jetpack-videopress.php @@ -52,6 +52,8 @@ class Jetpack_VideoPress { add_filter( 'wp_mime_type_icon', array( $this, 'wp_mime_type_icon' ), 10, 3 ); + add_filter( 'wp_video_extensions', array( $this, 'add_videopress_extenstion' ) ); + $this->add_media_new_notice(); VideoPress_Scheduler::init(); @@ -162,6 +164,14 @@ class Jetpack_VideoPress { ), $this->version ); + + wp_enqueue_script( + 'media-video-widget-extensions', + plugins_url( 'js/media-video-widget-extensions.js', __FILE__ ), + array(), + $this->version, + true + ); } /** @@ -296,6 +306,9 @@ class Jetpack_VideoPress { $existing_mimes[ $key ] = $value; } + // Make sure that videopress mimes are considered videos. + $existing_mimes['videopress'] = 'video/videopress'; + return $existing_mimes; } @@ -330,6 +343,17 @@ class Jetpack_VideoPress { return 'https://wordpress.com/wp-content/mu-plugins/videopress/images/media-video-processing-icon.png'; } + + /** + * @param array $extensions + * + * @return array + */ + public function add_videopress_extenstion( $extensions ) { + $extensions[] = 'videopress'; + + return $extensions; + } } // Initialize the module. diff --git a/plugins/jetpack/modules/videopress/editor-media-view.php b/plugins/jetpack/modules/videopress/editor-media-view.php index a4727deb..427c3552 100644 --- a/plugins/jetpack/modules/videopress/editor-media-view.php +++ b/plugins/jetpack/modules/videopress/editor-media-view.php @@ -101,6 +101,14 @@ function videopress_ajax_query_attachments_args( $args ) { */ add_action( 'pre_get_posts', 'videopress_media_list_table_query' ); function videopress_media_list_table_query( $query ) { + + if ( + ! function_exists( 'get_current_screen' ) + || is_null( get_current_screen() ) + ) { + return; + } + if ( is_admin() && $query->is_main_query() && ( 'upload' === get_current_screen()->id ) ) { $meta_query = array( array( @@ -212,4 +220,4 @@ function videopress_media_send_to_editor( $html, $id, $attachment ) { $html = sprintf( '[videopress postid=%d]', $id ); } return $html; -}
\ No newline at end of file +} diff --git a/plugins/jetpack/modules/videopress/js/media-video-widget-extensions.js b/plugins/jetpack/modules/videopress/js/media-video-widget-extensions.js new file mode 100644 index 00000000..2fa8c93b --- /dev/null +++ b/plugins/jetpack/modules/videopress/js/media-video-widget-extensions.js @@ -0,0 +1,45 @@ +window.wp = window.wp || {}; + +( function( wp ) { + if ( wp.mediaWidgets ) { + + // Over-ride core media_video#mapMediaToModelProps to set the url based upon videopress_guid if it exists. + wp.mediaWidgets.controlConstructors.media_video.prototype.mapMediaToModelProps = ( function( originalMapMediaToModelProps ) { + return function( mediaFrameProps ) { + var newProps, originalProps, videoPressGuid; + originalProps = originalMapMediaToModelProps.call( this, mediaFrameProps ); + newProps = _.extend( {}, originalProps ); + + // API response on new media will have the guid at videopress.guid. + if ( mediaFrameProps.videopress && mediaFrameProps.videopress.guid ) { + videoPressGuid = mediaFrameProps.videopress.guid; + } + + // Selecting an existing VideoPress file will have the guid at .videopress_guid[ 0 ]. + if ( ! videoPressGuid && mediaFrameProps.videopress_guid && mediaFrameProps.videopress_guid.length ) { + videoPressGuid = mediaFrameProps.videopress_guid[ 0 ]; + } + + if ( videoPressGuid ) { + newProps = _.extend( {}, originalProps, { + url: 'https://videopress.com/v/' + videoPressGuid, + attachment_id: 0 + }); + } + return newProps; + }; + }( wp.mediaWidgets.controlConstructors.media_video.prototype.mapMediaToModelProps )); + + // Over-ride core media_video#isHostedVideo() to add support for videopress oembed urls. + wp.mediaWidgets.controlConstructors.media_video.prototype.isHostedVideo = (function( originalIsHostedVideo ) { + return function( url ) { + var parsedUrl = document.createElement( 'a' ); + parsedUrl.href = url; + if ( 'videopress.com' === parsedUrl.hostname ) { + return true; + } + return originalIsHostedVideo.call( this, url ); + }; + }( wp.mediaWidgets.controlConstructors.media_video.prototype.isHostedVideo )); + } +} )( window.wp ); diff --git a/plugins/jetpack/modules/videopress/shortcode.php b/plugins/jetpack/modules/videopress/shortcode.php index dd041dbb..3e185bbb 100644 --- a/plugins/jetpack/modules/videopress/shortcode.php +++ b/plugins/jetpack/modules/videopress/shortcode.php @@ -184,6 +184,11 @@ class VideoPress_Shortcode { $videopress_guid = $matches[2]; } + // Also test for videopress oembed url, which is used by the Video Media Widget. + if ( ! $videopress_guid && preg_match( '@https://videopress.com/v/([a-z0-9]{8})@i', $url, $matches ) ) { + $videopress_guid = $matches[1]; + } + break; } } |