summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/modules/videopress')
-rw-r--r--plugins/jetpack/modules/videopress/class.jetpack-videopress.php24
-rw-r--r--plugins/jetpack/modules/videopress/class.videopress-ajax.php4
-rw-r--r--plugins/jetpack/modules/videopress/class.videopress-edit-attachment.php7
-rw-r--r--plugins/jetpack/modules/videopress/class.videopress-gutenberg.php27
-rw-r--r--plugins/jetpack/modules/videopress/class.videopress-player.php22
-rw-r--r--plugins/jetpack/modules/videopress/class.videopress-video.php7
-rw-r--r--plugins/jetpack/modules/videopress/editor-media-view.php6
-rw-r--r--plugins/jetpack/modules/videopress/js/gutenberg-video-upload.js63
-rw-r--r--plugins/jetpack/modules/videopress/shortcode.php6
-rw-r--r--plugins/jetpack/modules/videopress/utility-functions.php6
10 files changed, 135 insertions, 37 deletions
diff --git a/plugins/jetpack/modules/videopress/class.jetpack-videopress.php b/plugins/jetpack/modules/videopress/class.jetpack-videopress.php
index a1073f05..5b73dde6 100644
--- a/plugins/jetpack/modules/videopress/class.jetpack-videopress.php
+++ b/plugins/jetpack/modules/videopress/class.jetpack-videopress.php
@@ -1,5 +1,7 @@
<?php
+use Automattic\Jetpack\Assets;
+
/**
* VideoPress in Jetpack
*/
@@ -76,7 +78,7 @@ class Jetpack_VideoPress {
}
// Connection owners are allowed to do all the things.
- if ( $this->is_connection_owner( $user_id ) ) {
+ if ( Jetpack::connection()->is_connection_owner( $user_id ) ) {
return true;
}
@@ -98,15 +100,15 @@ class Jetpack_VideoPress {
/**
* Returns true if the provided user is the Jetpack connection owner.
+ *
+ * @deprecated since 7.7
+ *
+ * @param Integer|Boolean $user_id the user identifier. False for current user.
+ * @return bool Whether the current user is the connection owner.
*/
public function is_connection_owner( $user_id = false ) {
- if ( ! $user_id ) {
- $user_id = get_current_user_id();
- }
-
- $user_token = Jetpack_Data::get_access_token( JETPACK_MASTER_USER );
-
- return $user_token && is_object( $user_token ) && isset( $user_token->external_user_id ) && $user_id === $user_token->external_user_id;
+ _deprecated_function( __METHOD__, 'jetpack-7.7', 'Automattic\\Jetpack\\Connection\\Manager::is_connection_owner' );
+ return Jetpack::connection()->is_connection_owner( $user_id );
}
/**
@@ -128,7 +130,7 @@ class Jetpack_VideoPress {
if ( $this->should_override_media_uploader() ) {
wp_enqueue_script(
'videopress-plupload',
- Jetpack::get_file_url_for_environment(
+ Assets::get_file_url_for_environment(
'_inc/build/videopress/js/videopress-plupload.min.js',
'modules/videopress/js/videopress-plupload.js'
),
@@ -141,7 +143,7 @@ class Jetpack_VideoPress {
wp_enqueue_script(
'videopress-uploader',
- Jetpack::get_file_url_for_environment(
+ Assets::get_file_url_for_environment(
'_inc/build/videopress/js/videopress-uploader.min.js',
'modules/videopress/js/videopress-uploader.js'
),
@@ -153,7 +155,7 @@ class Jetpack_VideoPress {
wp_enqueue_script(
'media-video-widget-extensions',
- Jetpack::get_file_url_for_environment(
+ Assets::get_file_url_for_environment(
'_inc/build/videopress/js/media-video-widget-extensions.min.js',
'modules/videopress/js/media-video-widget-extensions.js'
),
diff --git a/plugins/jetpack/modules/videopress/class.videopress-ajax.php b/plugins/jetpack/modules/videopress/class.videopress-ajax.php
index e1943c0b..620605a9 100644
--- a/plugins/jetpack/modules/videopress/class.videopress-ajax.php
+++ b/plugins/jetpack/modules/videopress/class.videopress-ajax.php
@@ -1,5 +1,7 @@
<?php
+use Automattic\Jetpack\Connection\Client;
+
class VideoPress_AJAX {
/**
@@ -53,7 +55,7 @@ class VideoPress_AJAX {
);
$endpoint = "sites/{$options['shadow_blog_id']}/media/token";
- $result = Jetpack_Client::wpcom_json_api_request_as_blog( $endpoint, Jetpack_Client::WPCOM_JSON_API_VERSION, $args );
+ $result = Client::wpcom_json_api_request_as_blog( $endpoint, Client::WPCOM_JSON_API_VERSION, $args );
if ( is_wp_error( $result ) ) {
wp_send_json_error( array( 'message' => __( 'Could not obtain a VideoPress upload token. Please try again later.', 'jetpack' ) ) );
diff --git a/plugins/jetpack/modules/videopress/class.videopress-edit-attachment.php b/plugins/jetpack/modules/videopress/class.videopress-edit-attachment.php
index be7ddfde..5d55b2c6 100644
--- a/plugins/jetpack/modules/videopress/class.videopress-edit-attachment.php
+++ b/plugins/jetpack/modules/videopress/class.videopress-edit-attachment.php
@@ -1,4 +1,7 @@
<?php
+
+use Automattic\Jetpack\Connection\Client;
+
/**
* VideoPress edit attachment screen
*
@@ -114,7 +117,7 @@ class VideoPress_Edit_Attachment {
$guid = get_post_meta( $post_id, 'videopress_guid', true );
$endpoint = "videos/{$guid}";
- $result = Jetpack_Client::wpcom_json_api_request_as_blog( $endpoint, Jetpack_Client::WPCOM_JSON_API_VERSION, $args, $values );
+ $result = Client::wpcom_json_api_request_as_blog( $endpoint, Client::WPCOM_JSON_API_VERSION, $args, $values );
if ( is_wp_error( $result ) ) {
$post['errors']['videopress']['errors'][] = __( 'There was an issue saving your updates to the VideoPress service. Please try again later.', 'jetpack' );
@@ -152,7 +155,7 @@ class VideoPress_Edit_Attachment {
'%s://%s/rest/v%s/videos/%s',
'https',
'public-api.wordpress.com', // JETPACK__WPCOM_JSON_API_HOST,
- Jetpack_Client::WPCOM_JSON_API_VERSION,
+ Client::WPCOM_JSON_API_VERSION,
$guid
);
}
diff --git a/plugins/jetpack/modules/videopress/class.videopress-gutenberg.php b/plugins/jetpack/modules/videopress/class.videopress-gutenberg.php
index be0bd1db..55421ee9 100644
--- a/plugins/jetpack/modules/videopress/class.videopress-gutenberg.php
+++ b/plugins/jetpack/modules/videopress/class.videopress-gutenberg.php
@@ -5,6 +5,8 @@
* @package Jetpack
*/
+use Automattic\Jetpack\Assets;
+
/**
* Register a VideoPress extension to replace the default Core Video block.
*/
@@ -31,6 +33,7 @@ class VideoPress_Gutenberg {
private function __construct() {
add_action( 'init', array( $this, 'register_video_block_with_videopress' ) );
add_action( 'jetpack_register_gutenberg_extensions', array( $this, 'set_extension_availability' ) );
+ add_action( 'enqueue_block_editor_assets', array( $this, 'override_video_upload' ) );
}
/**
@@ -164,6 +167,30 @@ class VideoPress_Gutenberg {
1
);
}
+
+ /**
+ * Replaces the video uploaded in the block editor.
+ *
+ * Enqueues a script that registers an API fetch middleware replacing the video uploads in Gutenberg so they are
+ * uploaded against the WP.com API media endpoint and thus transcoded by VideoPress.
+ */
+ public function override_video_upload() {
+ // Bail if Jetpack or VideoPress is not active.
+ if ( ! Jetpack::is_active() || ! Jetpack::is_module_active( 'videopress' ) ) {
+ return;
+ }
+
+ wp_enqueue_script(
+ 'jetpack-videopress-gutenberg-override-video-upload',
+ Assets::get_file_url_for_environment(
+ '_inc/build/videopress/js/gutenberg-video-upload.min.js',
+ 'modules/videopress/js/gutenberg-video-upload.js'
+ ),
+ array( 'wp-api-fetch', 'wp-polyfill', 'lodash' ),
+ JETPACK__VERSION,
+ false
+ );
+ }
}
VideoPress_Gutenberg::init();
diff --git a/plugins/jetpack/modules/videopress/class.videopress-player.php b/plugins/jetpack/modules/videopress/class.videopress-player.php
index 669523c9..ab5105df 100644
--- a/plugins/jetpack/modules/videopress/class.videopress-player.php
+++ b/plugins/jetpack/modules/videopress/class.videopress-player.php
@@ -305,7 +305,7 @@ class VideoPress_Player {
$html .= '<input type="submit" value="' . __( 'Submit', 'jetpack' ) . '" style="cursor:pointer;border-radius: 1em;border:1px solid #333;background-color:#333;background:-webkit-gradient( linear, left top, left bottom, color-stop(0.0, #444), color-stop(1, #111) );background:-moz-linear-gradient(center top, #444 0%, #111 100%);font-size:13px;padding:4px 10px 5px;line-height:1em;vertical-align:top;color:white;text-decoration:none;margin:0" />';
$html .= '</fieldset>';
- $html .= '<p style="padding-top:20px;padding-bottom:60px;text-align:' . $text_align . ';"><a rel="nofollow noopener noreferrer" href="http://videopress.com/" target="_blank" style="color:rgb(128,128,128);text-decoration:underline;font-size:15px">' . __( 'More information', 'jetpack' ) . '</a></p>';
+ $html .= '<p style="padding-top:20px;padding-bottom:60px;text-align:' . $text_align . ';"><a rel="nofollow noopener noreferrer" href="https://videopress.com/" target="_blank" style="color:rgb(128,128,128);text-decoration:underline;font-size:15px">' . __( 'More information', 'jetpack' ) . '</a></p>';
$html .= '</div>';
return $html;
@@ -317,7 +317,7 @@ class VideoPress_Player {
* No Flash fallback.
*
* @since 1.2
- * @link http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html HTML5 video
+ * @link https://html.spec.whatwg.org/multipage/media.html#the-video-element HTML5 video
* @return string HTML5 video element and children
*/
private function html5_static() {
@@ -359,7 +359,7 @@ class VideoPress_Player {
}
$html .= '" src="' . $thumbnail . '" width="' . $this->video->calculated_width . '" height="' . $this->video->calculated_height . '" /></div>';
if ( isset( $this->options['freedom'] ) && $this->options['freedom'] === true ) {
- $html .= '<p class="robots-nocontent">' . sprintf( __( 'You do not have sufficient <a rel="nofollow noopener noreferrer" href="%s" target="_blank">freedom levels</a> to view this video. Support free software and upgrade.', 'jetpack' ), 'http://www.gnu.org/philosophy/free-sw.html' ) . '</p>';
+ $html .= '<p class="robots-nocontent">' . sprintf( __( 'You do not have sufficient <a rel="nofollow noopener noreferrer" href="%s" target="_blank">freedom levels</a> to view this video. Support free software and upgrade.', 'jetpack' ), 'https://www.gnu.org/philosophy/free-sw.html' ) . '</p>';
} elseif ( isset( $this->video->title ) ) {
$html .= '<p>' . esc_html( $this->video->title ) . '</p>';
}
@@ -516,7 +516,7 @@ class VideoPress_Player {
if ( $age_gate_required ) {
$html .= 'if ( jQuery.VideoPress.support.flash() ) {' . PHP_EOL;
/**
- * @link http://code.google.com/p/swfobject/wiki/api#swfobject.embedSWF(swfUrlStr,_replaceElemIdStr,_widthStr,_height
+ * @link https://github.com/swfobject/swfobject/wiki/SWFObject-API#swfobjectembedswfswfurlstr-replaceelemidstr-widthstr-heightstr-swfversionstr-xiswfurlstr-flashvarsobj-parobj-attobj-callbackfn
*/
$html .= 'swfobject.embedSWF(' . implode(
',',
@@ -688,11 +688,11 @@ class VideoPress_Player {
* Only allow legitimate Flash parameters and their values
*
* @since 1.2
- * @link http://kb2.adobe.com/cps/127/tn_12701.html Flash object and embed attributes
- * @link http://kb2.adobe.com/cps/133/tn_13331.html devicefont
- * @link http://kb2.adobe.com/cps/164/tn_16494.html allowscriptaccess
- * @link http://www.adobe.com/devnet/flashplayer/articles/full_screen_mode.html full screen mode
- * @link http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001079.html allownetworking
+ * @link https://helpx.adobe.com/flash/kb/flash-object-embed-tag-attributes.html Flash object and embed attributes
+ * @link https://helpx.adobe.com/flash/kb/font-outlines-device-fonts.html devicefont
+ * @link https://helpx.adobe.com/flash/kb/control-access-scripts-host-web.html allowscriptaccess
+ * @link https://www.adobe.com/devnet/flashplayer/articles/full_screen_mode.html full screen mode
+ * @link https://help.adobe.com/en_US/as3/dev/WS1EFE2EDA-026D-4d14-864E-79DFD56F87C6.html allownetworking
* @param array $flash_params Flash parameters expressed in key-value form
* @return array validated Flash parameters
*/
@@ -796,7 +796,7 @@ class VideoPress_Player {
* Flash player markup in a HTML embed element.
*
* @since 1.1
- * @link http://www.whatwg.org/specs/web-apps/current-work/multipage/the-iframe-element.html#the-embed-element embed element
+ * @link https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-embed-element embed element
* @link http://www.google.com/support/reader/bin/answer.py?answer=70664 Google Reader markup support
* @return string HTML markup. Embed element with no children
*/
@@ -849,7 +849,7 @@ class VideoPress_Player {
foreach ( $this->get_flash_parameters() as $attribute => $value ) {
$flash_params .= '<param name="' . esc_attr( $attribute ) . '" value="' . esc_attr( $value ) . '" />';
}
- $flash_help = sprintf( __( 'This video requires <a rel="nofollow noopener noreferrer" href="%s" target="_blank">Adobe Flash</a> for playback.', 'jetpack' ), 'http://www.adobe.com/go/getflashplayer' );
+ $flash_help = sprintf( __( 'This video requires <a rel="nofollow noopener noreferrer" href="%s" target="_blank">Adobe Flash</a> for playback.', 'jetpack' ), 'https://get.adobe.com/flashplayer/' );
$flash_player_url = esc_url( $this->video->players->swf->url, array( 'http', 'https' ) );
$description = '';
if ( isset( $this->video->title ) ) {
diff --git a/plugins/jetpack/modules/videopress/class.videopress-video.php b/plugins/jetpack/modules/videopress/class.videopress-video.php
index a8c3a6b8..f12c5fba 100644
--- a/plugins/jetpack/modules/videopress/class.videopress-video.php
+++ b/plugins/jetpack/modules/videopress/class.videopress-video.php
@@ -314,7 +314,7 @@ class VideoPress_Video {
* @return bool|string host component of the URL, or false if none found
*/
public static function hostname( $url ) {
- return parse_url( esc_url_raw( $url ), PHP_URL_HOST );
+ return wp_parse_url( esc_url_raw( $url ), PHP_URL_HOST );
}
@@ -336,10 +336,7 @@ class VideoPress_Video {
$request_params['maxwidth'] = $this->maxwidth;
}
- $url = 'http://videopress.com/data/wordpress.json';
- if ( is_ssl() ) {
- $url = 'https://v.wordpress.com/data/wordpress.json';
- }
+ $url = 'https://v.wordpress.com/data/wordpress.json';
$response = wp_remote_get(
add_query_arg( $request_params, $url ),
diff --git a/plugins/jetpack/modules/videopress/editor-media-view.php b/plugins/jetpack/modules/videopress/editor-media-view.php
index ed65a08c..f9ff3498 100644
--- a/plugins/jetpack/modules/videopress/editor-media-view.php
+++ b/plugins/jetpack/modules/videopress/editor-media-view.php
@@ -1,5 +1,7 @@
<?php
+use Automattic\Jetpack\Assets;
+
/**
* WordPress Shortcode Editor View JS Code
*/
@@ -15,7 +17,7 @@ function videopress_handle_editor_view_js() {
wp_enqueue_style( 'videopress-editor-ui', plugins_url( 'css/editor.css', __FILE__ ) );
wp_enqueue_script(
'videopress-editor-view',
- Jetpack::get_file_url_for_environment(
+ Assets::get_file_url_for_environment(
'_inc/build/videopress/js/editor-view.min.js',
'modules/videopress/js/editor-view.js'
),
@@ -27,7 +29,7 @@ function videopress_handle_editor_view_js() {
'videopress-editor-view',
'vpEditorView',
array(
- 'home_url_host' => parse_url( home_url(), PHP_URL_HOST ),
+ 'home_url_host' => wp_parse_url( home_url(), PHP_URL_HOST ),
'min_content_width' => VIDEOPRESS_MIN_WIDTH,
'content_width' => $content_width,
'modal_labels' => array(
diff --git a/plugins/jetpack/modules/videopress/js/gutenberg-video-upload.js b/plugins/jetpack/modules/videopress/js/gutenberg-video-upload.js
new file mode 100644
index 00000000..c3ba1739
--- /dev/null
+++ b/plugins/jetpack/modules/videopress/js/gutenberg-video-upload.js
@@ -0,0 +1,63 @@
+/* globals wp, lodash */
+
+wp.apiFetch.use( function( options, next ) {
+ var path = options.path;
+ var method = options.method;
+ var body = options.body;
+ var file = body ? body.get( 'file' ) : null;
+
+ // Override only requests to the WP REST API media endpoint uploading new videos.
+ if ( ! path || path.indexOf( '/wp/v2/media' ) === -1 ) {
+ return next( options );
+ }
+ if ( ! method || 'post' !== method.toLowerCase() ) {
+ return next( options );
+ }
+ if ( ! file || file.type.indexOf( 'video/' ) !== 0 ) {
+ return next( options );
+ }
+
+ // Get upload token.
+ wp.media
+ .ajax( 'videopress-get-upload-token', { async: false, data: { filename: file.name } } )
+ .done( function( response ) {
+ // Set auth header with upload token.
+ var headers = options.headers || {};
+ headers.Authorization =
+ 'X_UPLOAD_TOKEN token="' +
+ response.upload_token +
+ '" blog_id="' +
+ response.upload_blog_id +
+ '"';
+ options.headers = headers;
+
+ // Replace upload URL.
+ delete options.path;
+ options.url = response.upload_action_url;
+
+ // Handle CORS.
+ options.credentials = 'omit';
+
+ // Set data in expected param by WP.com media endpoint.
+ body.set( 'media[]', file );
+ body.delete( 'file' );
+ options.body = body;
+ } );
+
+ var result = next( options );
+
+ return new Promise( function( resolve, reject ) {
+ result
+ .then( function( data ) {
+ var wpcomMediaObject = lodash.get( data, 'media[0]' );
+ var id = lodash.get( wpcomMediaObject, 'ID' );
+ var gutenbergMediaObject = wp.apiFetch( {
+ path: '/wp/v2/media/' + id,
+ } );
+ resolve( gutenbergMediaObject );
+ } )
+ .catch( function() {
+ reject();
+ } );
+ } );
+} );
diff --git a/plugins/jetpack/modules/videopress/shortcode.php b/plugins/jetpack/modules/videopress/shortcode.php
index 21b163ef..51b7dd47 100644
--- a/plugins/jetpack/modules/videopress/shortcode.php
+++ b/plugins/jetpack/modules/videopress/shortcode.php
@@ -13,7 +13,7 @@ class VideoPress_Shortcode {
protected function __construct() {
// By explicitly declaring the provider here, we can speed things up by not relying on oEmbed discovery.
- wp_oembed_add_provider( '#^https?://videopress.com/v/.*#', 'http://public-api.wordpress.com/oembed/1.0/', true );
+ wp_oembed_add_provider( '#^https?://videopress.com/v/.*#', 'https://public-api.wordpress.com/oembed/1.0/', true );
add_shortcode( 'videopress', array( $this, 'shortcode_callback' ) );
add_shortcode( 'wpvideo', array( $this, 'shortcode_callback' ) );
@@ -44,7 +44,7 @@ class VideoPress_Shortcode {
* [videopress OcobLTqC]
* [wpvideo OcobLTqC]
*
- * @link http://codex.wordpress.org/Shortcode_API Shortcode API
+ * @link https://codex.wordpress.org/Shortcode_API Shortcode API
* @param array $attr shortcode attributes
* @return string HTML markup or blank string on fail
*/
@@ -226,7 +226,7 @@ class VideoPress_Shortcode {
if ( false === stripos( $oembed_provider, 'videopress.com' ) ) {
return $oembed_provider;
}
- return add_query_arg( 'for', parse_url( home_url(), PHP_URL_HOST ), $oembed_provider );
+ return add_query_arg( 'for', wp_parse_url( home_url(), PHP_URL_HOST ), $oembed_provider );
}
/**
diff --git a/plugins/jetpack/modules/videopress/utility-functions.php b/plugins/jetpack/modules/videopress/utility-functions.php
index 345fa719..989eaf52 100644
--- a/plugins/jetpack/modules/videopress/utility-functions.php
+++ b/plugins/jetpack/modules/videopress/utility-functions.php
@@ -1,5 +1,7 @@
<?php
+use Automattic\Jetpack\Connection\Client;
+
/**
* We won't have any videos less than sixty pixels wide. That would be silly.
*/
@@ -69,7 +71,7 @@ function videopress_get_video_details( $guid ) {
/**
* Get an attachment ID given a URL.
*
- * Modified from http://wpscholar.com/blog/get-attachment-id-from-wp-image-url/
+ * Modified from https://wpscholar.com/blog/get-attachment-id-from-wp-image-url/
*
* @todo: Add some caching in here.
*
@@ -490,7 +492,7 @@ function videopress_make_video_get_path( $guid ) {
'%s://%s/rest/v%s/videos/%s',
'https',
JETPACK__WPCOM_JSON_API_HOST,
- Jetpack_Client::WPCOM_JSON_API_VERSION,
+ Client::WPCOM_JSON_API_VERSION,
$guid
);
}