diff options
Diffstat (limited to 'plugins/jetpack/modules/videopress')
12 files changed, 450 insertions, 347 deletions
diff --git a/plugins/jetpack/modules/videopress/class.jetpack-videopress.php b/plugins/jetpack/modules/videopress/class.jetpack-videopress.php index 33e014d9..322d3797 100644 --- a/plugins/jetpack/modules/videopress/class.jetpack-videopress.php +++ b/plugins/jetpack/modules/videopress/class.jetpack-videopress.php @@ -2,7 +2,6 @@ /** * VideoPress in Jetpack - * */ class Jetpack_VideoPress { /** @var string */ @@ -18,7 +17,7 @@ class Jetpack_VideoPress { static $instance = false; if ( ! $instance ) { - $instance = new Jetpack_VideoPress; + $instance = new Jetpack_VideoPress(); } return $instance; @@ -30,7 +29,7 @@ class Jetpack_VideoPress { * Sets up the initializer and makes sure that videopress activates and deactivates properly. */ private function __construct() { - //$this->version = time(); // <s>ghost</s> cache busters! + // $this->version = time(); // <s>ghost</s> cache busters! add_action( 'init', array( $this, 'on_init' ) ); add_action( 'jetpack_deactivate_module_videopress', array( $this, 'jetpack_module_deactivated' ) ); } @@ -82,7 +81,6 @@ class Jetpack_VideoPress { } // Additional and internal caps checks - if ( ! user_can( $user_id, 'upload_files' ) ) { return false; } @@ -136,7 +134,7 @@ class Jetpack_VideoPress { ), array( 'jquery', - 'wp-plupload' + 'wp-plupload', ), $this->version ); @@ -148,7 +146,7 @@ class Jetpack_VideoPress { 'modules/videopress/js/videopress-uploader.js' ), array( - 'videopress-plupload' + 'videopress-plupload', ), $this->version ); @@ -179,7 +177,7 @@ class Jetpack_VideoPress { * This is an action proxy to the videopress_get_attachment_url() utility function. * * @param string $url - * @param int $post_id + * @param int $post_id * * @return string */ @@ -232,7 +230,7 @@ class Jetpack_VideoPress { ); // Only load on the post, new post, or upload pages. - if ( !in_array( $pagenow, $acceptable_pages ) ) { + if ( ! in_array( $pagenow, $acceptable_pages ) ) { return false; } @@ -258,7 +256,7 @@ class Jetpack_VideoPress { return false; } - if ( ! isset ( $_GET['action'] ) || $_GET['action'] !== 'add-new' ) { + if ( ! isset( $_GET['action'] ) || $_GET['action'] !== 'add-new' ) { return false; } @@ -281,7 +279,7 @@ class Jetpack_VideoPress { * @return array */ public function add_video_upload_mimes( $existing_mimes = array() ) { - $mime_types = wp_get_mime_types(); + $mime_types = wp_get_mime_types(); $video_types = array_filter( $mime_types, array( $this, 'filter_video_mimes' ) ); foreach ( $video_types as $key => $value ) { @@ -302,12 +300,12 @@ class Jetpack_VideoPress { */ public function filter_video_mimes( $value ) { return preg_match( '@^video/@', $value ); - } + } /** * @param string $icon * @param string $mime - * @param int $post_id + * @param int $post_id * * @return string */ diff --git a/plugins/jetpack/modules/videopress/class.videopress-ajax.php b/plugins/jetpack/modules/videopress/class.videopress-ajax.php index 5ddfd1d7..e1943c0b 100644 --- a/plugins/jetpack/modules/videopress/class.videopress-ajax.php +++ b/plugins/jetpack/modules/videopress/class.videopress-ajax.php @@ -15,10 +15,14 @@ class VideoPress_AJAX { private function __construct() { add_action( 'wp_ajax_videopress-get-upload-token', array( $this, 'wp_ajax_videopress_get_upload_token' ) ); - add_action( 'wp_ajax_videopress-update-transcoding-status', array( - $this, - 'wp_ajax_update_transcoding_status' - ), -1 ); + add_action( + 'wp_ajax_videopress-update-transcoding-status', + array( + $this, + 'wp_ajax_update_transcoding_status', + ), + -1 + ); } /** @@ -28,7 +32,7 @@ class VideoPress_AJAX { */ public static function init() { if ( is_null( self::$instance ) ) { - self::$instance = new VideoPress_AJAX; + self::$instance = new VideoPress_AJAX(); } return self::$instance; @@ -86,12 +90,14 @@ class VideoPress_AJAX { return; } - wp_send_json_success( array( - 'message' => __( 'Status updated', 'jetpack' ), - 'status' => videopress_get_transcoding_status( $post_id ) - ) ); + wp_send_json_success( + array( + 'message' => __( 'Status updated', 'jetpack' ), + 'status' => videopress_get_transcoding_status( $post_id ), + ) + ); } } // Let's start this thing up. -VideoPress_AJAX::init();
\ No newline at end of file +VideoPress_AJAX::init(); diff --git a/plugins/jetpack/modules/videopress/class.videopress-cli.php b/plugins/jetpack/modules/videopress/class.videopress-cli.php index 0963ca0f..e1200da0 100644 --- a/plugins/jetpack/modules/videopress/class.videopress-cli.php +++ b/plugins/jetpack/modules/videopress/class.videopress-cli.php @@ -16,10 +16,9 @@ if ( defined( 'WP_CLI' ) && WP_CLI ) { * ## EXAMPLES * * wp videopress import kUJmAcSf - * */ public function import( $args ) { - $guid = $args[0]; + $guid = $args[0]; $attachment_id = create_local_media_library_for_videopress_guid( $guid ); if ( $attachment_id && ! is_wp_error( $attachment_id ) ) { WP_CLI::success( sprintf( __( 'The video has been imported as Attachment ID %d', 'jetpack' ), $attachment_id ) ); @@ -51,11 +50,10 @@ if ( defined( 'WP_CLI' ) && WP_CLI ) { public function list_crons() { $scheduler = VideoPress_Scheduler::init(); - $crons = $scheduler->get_crons(); + $crons = $scheduler->get_crons(); $schedules = wp_get_schedules(); - if ( count( $crons ) === 0 ) { WP_CLI::success( __( 'Found no available cron jobs.', 'jetpack' ) ); @@ -64,9 +62,9 @@ if ( defined( 'WP_CLI' ) && WP_CLI ) { } foreach ( $crons as $cron_name => $cron ) { - $interval = isset( $schedules[ $cron['interval'] ]['display'] ) ? $schedules[ $cron['interval'] ]['display'] : $cron['interval']; + $interval = isset( $schedules[ $cron['interval'] ]['display'] ) ? $schedules[ $cron['interval'] ]['display'] : $cron['interval']; $runs_next = $scheduler->check_cron( $cron_name ); - $status = $runs_next ? sprintf( 'Scheduled - Runs Next at %s GMT', gmdate( 'Y-m-d H:i:s', $runs_next ) ) : 'Not Scheduled'; + $status = $runs_next ? sprintf( 'Scheduled - Runs Next at %s GMT', gmdate( 'Y-m-d H:i:s', $runs_next ) ) : 'Not Scheduled'; WP_CLI::log( 'Name: ' . $cron_name ); WP_CLI::log( 'Method: ' . $cron['method'] ); diff --git a/plugins/jetpack/modules/videopress/class.videopress-edit-attachment.php b/plugins/jetpack/modules/videopress/class.videopress-edit-attachment.php index d7f5bca8..be7ddfde 100644 --- a/plugins/jetpack/modules/videopress/class.videopress-edit-attachment.php +++ b/plugins/jetpack/modules/videopress/class.videopress-edit-attachment.php @@ -36,12 +36,12 @@ class VideoPress_Edit_Attachment { } /** - * @param string $post_type - * @param object $post + * @param string $post_type + * @param object $post */ - public function configure_meta_boxes( $post_type = 'unknown', $post = NULL ) { - if ( NULL == $post ) { - $post = (object) array ( 'ID' => 0 ); + public function configure_meta_boxes( $post_type = 'unknown', $post = null ) { + if ( null == $post ) { + $post = (object) array( 'ID' => 0 ); } if ( 'attachment' != $post_type ) { @@ -57,7 +57,7 @@ class VideoPress_Edit_Attachment { } /** - * @param array $post + * @param array $post * @param array|null $attachment * * @return array @@ -104,17 +104,17 @@ class VideoPress_Edit_Attachment { if ( isset( $attachment['display_embed'] ) ) { $display_embed = $attachment['display_embed']; - $values['display_embed'] = 'on' === $display_embed ? 1 : 0; + $values['display_embed'] = 'on' === $display_embed ? 1 : 0; } $args = array( - 'method' => 'POST', + 'method' => 'POST', ); - $guid = get_post_meta( $post_id, 'videopress_guid', true ); + $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 = Jetpack_Client::wpcom_json_api_request_as_blog( $endpoint, Jetpack_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' ); @@ -151,7 +151,7 @@ class VideoPress_Edit_Attachment { return sprintf( '%s://%s/rest/v%s/videos/%s', 'https', - 'public-api.wordpress.com', //JETPACK__WPCOM_JSON_API_HOST, + 'public-api.wordpress.com', // JETPACK__WPCOM_JSON_API_HOST, Jetpack_Client::WPCOM_JSON_API_VERSION, $guid ); @@ -161,7 +161,7 @@ class VideoPress_Edit_Attachment { /** * Creates an array of video fields to edit based on transcoded videos. * - * @param array $fields video fields of interest + * @param array $fields video fields of interest * @param stdClass $post post object * @return array modified version of video fields for administrative interface display */ @@ -175,18 +175,18 @@ class VideoPress_Edit_Attachment { return $fields; } - $info = (object) $meta['videopress']; - $file_statuses = isset( $meta['file_statuses'] ) ? $meta['file_statuses'] : array(); + $info = (object) $meta['videopress']; + $file_statuses = isset( $meta['file_statuses'] ) ? $meta['file_statuses'] : array(); - $guid = get_post_meta( $post_id, 'videopress_guid', true ); + $guid = get_post_meta( $post_id, 'videopress_guid', true ); unset( $fields['url'] ); unset( $fields['post_content'] ); - if ( isset( $file_statuses['ogg'] ) && 'done' === $file_statuses['ogg'] ) { - $v_name = preg_replace( '/\.\w+/', '', basename( $info->path ) ); + if ( isset( $file_statuses['ogg'] ) && 'done' === $file_statuses['ogg'] ) { + $v_name = preg_replace( '/\.\w+/', '', basename( $info->path ) ); $video_name = $v_name . '_fmt1.ogv'; - $ogg_url = videopress_cdn_file_url( $guid, $video_name ); + $ogg_url = videopress_cdn_file_url( $guid, $video_name ); $fields['video-ogg'] = array( 'label' => __( 'Ogg File URL', 'jetpack' ), @@ -218,13 +218,13 @@ class VideoPress_Edit_Attachment { $fields['display_embed'] = array( 'label' => _x( 'Share', 'A header for the video sharing options area', 'jetpack' ), 'input' => 'html', - 'html' => $this->display_embed_choice( $info ) + 'html' => $this->display_embed_choice( $info ), ); $fields['video-rating'] = array( 'label' => _x( 'Rating', 'A header for the video rating area', 'jetpack' ), 'input' => 'html', - 'html' => $this->display_rating( $info ) + 'html' => $this->display_rating( $info ), ); return $fields; @@ -237,7 +237,7 @@ class VideoPress_Edit_Attachment { $post_id = absint( $post->ID ); $meta = wp_get_attachment_metadata( $post_id ); - $guid = get_post_meta( $post_id, 'videopress_guid', true ); + $guid = get_post_meta( $post_id, 'videopress_guid', true ); // If this has not been processed by videopress, we can skip the rest. if ( ! is_videopress_attachment( $post_id ) ) { @@ -259,14 +259,14 @@ class VideoPress_Edit_Attachment { $shortcode = '<input type="text" id="plugin-embed" readonly="readonly" style="width:180px;" value="' . esc_attr( $embed ) . '" onclick="this.focus();this.select();" />'; - $trans_status = ''; + $trans_status = ''; $all_trans_done = true; foreach ( $formats as $status_key => $name ) { if ( 'DONE' !== $status[ $status_key ] ) { $all_trans_done = false; } - $trans_status .= '- <strong>' . $name . ":</strong> <span id=\"status_$status_key\">" . ( 'DONE' === $status[ $status_key ] ? 'Done' : 'Processing' ) . '</span><br>'; + $trans_status .= '- <strong>' . $name . ":</strong> <span id=\"status_$status_key\">" . ( 'DONE' === $status[ $status_key ] ? 'Done' : 'Processing' ) . '</span><br>'; } $nonce = wp_create_nonce( 'videopress-update-transcoding-status' ); @@ -344,11 +344,12 @@ HTML; * @return string input element of type checkbox set to checked state based on stored embed preference */ protected function display_embed_choice( $info ) { - $id = "attachments-{$info->post_id}-displayembed"; - $out = "<label for='$id'><input type='checkbox' name='attachments[{$info->post_id}][display_embed]' id='$id'"; - if ( $info->display_embed ) + $id = "attachments-{$info->post_id}-displayembed"; + $out = "<label for='$id'><input type='checkbox' name='attachments[{$info->post_id}][display_embed]' id='$id'"; + if ( $info->display_embed ) { $out .= ' checked="checked"'; - $out .= " />" . __( 'Display share menu and allow viewers to embed or download this video', 'jetpack' ) . '</label>'; + } + $out .= ' />' . __( 'Display share menu and allow viewers to embed or download this video', 'jetpack' ) . '</label>'; return $out; } @@ -368,8 +369,8 @@ HTML; 'X-18' => 'X', ); - foreach( $ratings as $r => $label ) { - $id = "attachments-{$info->post_id}-rating-$r"; + foreach ( $ratings as $r => $label ) { + $id = "attachments-{$info->post_id}-rating-$r"; $out .= "<label for=\"$id\"><input type=\"radio\" name=\"attachments[{$info->post_id}][rating]\" id=\"$id\" value=\"$r\""; if ( $info->rating == $r ) { $out .= ' checked="checked"'; @@ -384,4 +385,4 @@ HTML; } // Let's start this thing up. -VideoPress_Edit_Attachment::init();
\ No newline at end of file +VideoPress_Edit_Attachment::init(); diff --git a/plugins/jetpack/modules/videopress/class.videopress-options.php b/plugins/jetpack/modules/videopress/class.videopress-options.php index 1b431e92..b72abd5b 100644 --- a/plugins/jetpack/modules/videopress/class.videopress-options.php +++ b/plugins/jetpack/modules/videopress/class.videopress-options.php @@ -6,9 +6,6 @@ class VideoPress_Options { public static $option_name = 'videopress'; /** @var array */ - public static $jetpack_plans_with_videopress = array( 'jetpack_premium', 'jetpack_business' ); - - /** @var array */ protected static $options = array(); /** @@ -21,7 +18,7 @@ class VideoPress_Options { } $defaults = array( - 'meta' => array( + 'meta' => array( 'max_upload_size' => 0, ), ); @@ -59,4 +56,4 @@ class VideoPress_Options { self::$options = array(); } -}
\ No newline at end of file +} diff --git a/plugins/jetpack/modules/videopress/class.videopress-player.php b/plugins/jetpack/modules/videopress/class.videopress-player.php index e301802b..669523c9 100644 --- a/plugins/jetpack/modules/videopress/class.videopress-player.php +++ b/plugins/jetpack/modules/videopress/class.videopress-player.php @@ -52,36 +52,41 @@ class VideoPress_Player { * @var array $options player customizations */ public function __construct( $guid, $maxwidth = 0, $options = array() ) { - if ( empty( self::$shown[ $guid ] ) ) + if ( empty( self::$shown[ $guid ] ) ) { self::$shown[ $guid ] = 0; + } self::$shown[ $guid ]++; $this->video_container_id = 'v-' . $guid . '-' . self::$shown[ $guid ]; - $this->video_id = $this->video_container_id . '-video'; + $this->video_id = $this->video_container_id . '-video'; - if ( is_array( $options ) ) + if ( is_array( $options ) ) { $this->options = $options; - else + } else { $this->options = array(); + } // set up the video $cache_key = null; // disable cache in debug mode - if ( defined('WP_DEBUG') && WP_DEBUG === true ) { + if ( defined( 'WP_DEBUG' ) && WP_DEBUG === true ) { $cached_video = null; } else { $cache_key_pieces = array( 'video' ); - if ( is_multisite() && is_subdomain_install() ) + if ( is_multisite() && is_subdomain_install() ) { $cache_key_pieces[] = get_current_blog_id(); + } $cache_key_pieces[] = $guid; - if ( $maxwidth > 0 ) + if ( $maxwidth > 0 ) { $cache_key_pieces[] = $maxwidth; - if ( is_ssl() ) + } + if ( is_ssl() ) { $cache_key_pieces[] = 'ssl'; + } $cache_key = implode( '-', $cache_key_pieces ); unset( $cache_key_pieces ); $cached_video = wp_cache_get( $cache_key, 'video' ); @@ -105,8 +110,9 @@ class VideoPress_Player { $expire = 3600; if ( isset( $video->expires ) && is_int( $video->expires ) ) { $expires_diff = time() - $video->expires; - if ( $expires_diff > 0 && $expires_diff < 86400 ) // allowed range: 1 second to 1 day + if ( $expires_diff > 0 && $expires_diff < 86400 ) { // allowed range: 1 second to 1 day $expire = $expires_diff; + } unset( $expires_diff ); } @@ -128,10 +134,11 @@ class VideoPress_Player { * @return string HTML string or blank string if nothing to wrap */ private function html_wrapper( $content ) { - if ( empty( $content ) ) + if ( empty( $content ) ) { return ''; - else + } else { return '<div id="' . esc_attr( $this->video_container_id ) . '" class="video-player">' . $content . '</div>'; + } } /** @@ -159,6 +166,7 @@ class VideoPress_Player { /** * Video player markup for best matching the current request and publisher options + * * @since 1.3 * @return string HTML markup string or empty string if no video property found */ @@ -180,7 +188,6 @@ class VideoPress_Player { } else { $content = $this->html5_dynamic(); } - } elseif ( isset( $this->options['freedom'] ) && true === $this->options['freedom'] ) { $content = $this->html5_static(); @@ -200,12 +207,13 @@ class VideoPress_Player { * @return string HTML string */ private function error_message( $error ) { - if ( ! current_user_can( 'edit_posts' ) || empty( $error ) ) + if ( ! current_user_can( 'edit_posts' ) || empty( $error ) ) { return ''; + } - $html = '<div class="videopress-error" style="background-color:rgb(255,0,0);color:rgb(255,255,255);font-family:font-family:\'Helvetica Neue\',Arial,Helvetica,\'Nimbus Sans L\',sans-serif;font-size:140%;min-height:10em;padding-top:1.5em;padding-bottom:1.5em">'; + $html = '<div class="videopress-error" style="background-color:rgb(255,0,0);color:rgb(255,255,255);font-family:font-family:\'Helvetica Neue\',Arial,Helvetica,\'Nimbus Sans L\',sans-serif;font-size:140%;min-height:10em;padding-top:1.5em;padding-bottom:1.5em">'; $html .= '<h1 style="font-size:180%;font-style:bold;line-height:130%;text-decoration:underline">' . esc_html( sprintf( __( '%s Error', 'jetpack' ), 'VideoPress' ) ) . '</h1>'; - foreach( $error->get_error_messages() as $message ) { + foreach ( $error->get_error_messages() as $message ) { $html .= $message; } $html .= '</div>'; @@ -220,10 +228,11 @@ class VideoPress_Player { * @return bool true if video requires the viewer verify he or she is 17 years of age or older */ private function age_gate_required() { - if ( isset( $this->video->age_rating ) && $this->video->age_rating >= 17 ) + if ( isset( $this->video->age_rating ) && $this->video->age_rating >= 17 ) { return true; - else + } else { return false; + } } /** @@ -235,28 +244,31 @@ class VideoPress_Player { private function html_age_gate() { global $wp_locale; $text_align = 'left'; - if ( $this->video->text_direction === 'rtl' ) + if ( $this->video->text_direction === 'rtl' ) { $text_align = 'right'; + } - $html = '<div class="videopress-age-gate" style="margin:0 60px">'; - $html .= '<p class="instructions" style="color:rgb(255, 255, 255);font-size:21px;padding-top:60px;padding-bottom:20px;text-align:' . $text_align . '">' . esc_html( __( 'This video is intended for mature audiences.', 'jetpack' ) ) . '<br />' . esc_html( __( 'Please verify your birthday.', 'jetpack' ) ) . '</p>'; - $html .= '<fieldset id="birthday" style="border:0 none;text-align:' . $text_align . ';padding:0;">'; + $html = '<div class="videopress-age-gate" style="margin:0 60px">'; + $html .= '<p class="instructions" style="color:rgb(255, 255, 255);font-size:21px;padding-top:60px;padding-bottom:20px;text-align:' . $text_align . '">' . esc_html( __( 'This video is intended for mature audiences.', 'jetpack' ) ) . '<br />' . esc_html( __( 'Please verify your birthday.', 'jetpack' ) ) . '</p>'; + $html .= '<fieldset id="birthday" style="border:0 none;text-align:' . $text_align . ';padding:0;">'; $inputs_style = 'border:1px solid #444;margin-'; - if ( $this->video->text_direction === 'rtl' ) + if ( $this->video->text_direction === 'rtl' ) { $inputs_style .= 'left'; - else + } else { $inputs_style .= 'right'; + } $inputs_style .= ':10px;background-color:rgb(0, 0, 0);font-size:14px;color:rgb(255,255,255);padding:4px 6px;line-height: 2em;vertical-align: middle'; /** * Display a list of months in the Gregorian calendar. * Set values to 0-based to match JavaScript Date. + * * @link https://developer.mozilla.org/en/JavaScript/Reference/global_objects/date Mozilla JavaScript Reference: Date */ $html .= '<select name="month" style="' . $inputs_style . '">'; - for( $i=0; $i<12; $i++ ) { - $html .= '<option value="' . esc_attr( $i ) . '">' . esc_html( $wp_locale->get_month( $i + 1 ) ) . '</option>'; + for ( $i = 0; $i < 12; $i++ ) { + $html .= '<option value="' . esc_attr( $i ) . '">' . esc_html( $wp_locale->get_month( $i + 1 ) ) . '</option>'; } $html .= '</select>'; @@ -264,7 +276,7 @@ class VideoPress_Player { * todo: numdays variance by month */ $html .= '<select name="day" style="' . $inputs_style . '">'; - for ( $i=1; $i<32; $i++ ) { + for ( $i = 1; $i < 32; $i++ ) { $html .= '<option>' . $i . '</option>'; } $html .= '</select>'; @@ -274,14 +286,15 @@ class VideoPress_Player { * Don't ask infants younger than 2 for their birthday * Default to 13 */ - $html .= '<select name="year" style="' . $inputs_style . '">'; - $start_year = date('Y') - 2; + $html .= '<select name="year" style="' . $inputs_style . '">'; + $start_year = date( 'Y' ) - 2; $default_year = $start_year - 11; - $end_year = $start_year - 128; - for ( $year=$start_year; $year>$end_year; $year-- ) { + $end_year = $start_year - 128; + for ( $year = $start_year; $year > $end_year; $year-- ) { $html .= '<option'; - if ( $year === $default_year ) + if ( $year === $default_year ) { $html .= ' selected="selected"'; + } $html .= '>' . $year . '</option>'; } unset( $start_year ); @@ -292,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" href="http://videopress.com/" rel="noopener noreferrer" 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="http://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; @@ -310,20 +323,24 @@ class VideoPress_Player { private function html5_static() { wp_enqueue_script( 'videopress' ); $thumbnail = esc_url( $this->video->poster_frame_uri ); - $html = "<video id=\"{$this->video_id}\" width=\"{$this->video->calculated_width}\" height=\"{$this->video->calculated_height}\" poster=\"$thumbnail\" controls=\"true\""; - if ( isset( $this->options['autoplay'] ) && $this->options['autoplay'] === true ) + $html = "<video id=\"{$this->video_id}\" width=\"{$this->video->calculated_width}\" height=\"{$this->video->calculated_height}\" poster=\"$thumbnail\" controls=\"true\""; + if ( isset( $this->options['autoplay'] ) && $this->options['autoplay'] === true ) { $html .= ' autoplay="true"'; - else + } else { $html .= ' preload="metadata"'; - if ( isset( $this->video->text_direction ) ) + } + if ( isset( $this->video->text_direction ) ) { $html .= ' dir="' . esc_attr( $this->video->text_direction ) . '"'; - if ( isset( $this->video->language ) ) + } + if ( isset( $this->video->language ) ) { $html .= ' lang="' . esc_attr( $this->video->language ) . '"'; + } $html .= '>'; if ( ! isset( $this->options['freedom'] ) || $this->options['freedom'] === false ) { $mp4 = $this->video->videos->mp4->url; - if ( ! empty( $mp4 ) ) + if ( ! empty( $mp4 ) ) { $html .= '<source src="' . esc_url( $mp4 ) . '" type="video/mp4; codecs="' . esc_attr( $this->video->videos->mp4->codecs ) . '"" />'; + } unset( $mp4 ); } @@ -337,13 +354,15 @@ class VideoPress_Player { } $html .= '<div><img alt="'; - if ( isset( $this->video->title ) ) + if ( isset( $this->video->title ) ) { $html .= esc_attr( $this->video->title ); + } $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" href="%s" rel="noopener noreferrer" target="_blank">freedom levels</a> to view this video. Support free software and upgrade.', 'jetpack' ), 'http://www.gnu.org/philosophy/free-sw.html' ) . '</p>'; - elseif ( isset( $this->video->title ) ) + 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>'; + } elseif ( isset( $this->video->title ) ) { $html .= '<p>' . esc_html( $this->video->title ) . '</p>'; + } $html .= '</video>'; return $html; } @@ -382,18 +401,20 @@ class VideoPress_Player { wp_enqueue_script( 'videopress' ); $video_placeholder_id = $this->video_container_id . '-placeholder'; - $age_gate_required = $this->age_gate_required(); - $width = absint( $this->video->calculated_width ); - $height = absint( $this->video->calculated_height ); + $age_gate_required = $this->age_gate_required(); + $width = absint( $this->video->calculated_width ); + $height = absint( $this->video->calculated_height ); $html = '<div id="' . $video_placeholder_id . '" class="videopress-placeholder" style="'; - if ( $age_gate_required ) + if ( $age_gate_required ) { $html .= "min-width:{$width}px;min-height:{$height}px"; - else + } else { $html .= "width:{$width}px;height:{$height}px"; + } $html .= ';display:none;cursor:pointer !important;position:relative;'; - if ( isset( $this->video->skin ) && isset( $this->video->skin->background_color ) ) + if ( isset( $this->video->skin ) && isset( $this->video->skin->background_color ) ) { $html .= 'background-color:' . esc_attr( $this->video->skin->background_color ) . ';'; + } $html .= 'font-family: \'Helvetica Neue\',Arial,Helvetica,\'Nimbus Sans L\',sans-serif;font-weight:bold;font-size:18px">' . PHP_EOL; /** @@ -402,38 +423,43 @@ class VideoPress_Player { if ( ! $age_gate_required ) { if ( ! empty( $this->video->title ) ) { $html .= '<div class="videopress-title" style="display:inline;position:absolute;margin:20px 20px 0 20px;padding:4px 8px;vertical-align:top;text-align:'; - if ( $this->video->text_direction === 'rtl' ) + if ( $this->video->text_direction === 'rtl' ) { $html .= 'right" dir="rtl"'; - else + } else { $html .= 'left" dir="ltr"'; - if ( isset( $this->video->language ) ) + } + if ( isset( $this->video->language ) ) { $html .= ' lang="' . esc_attr( $this->video->language ) . '"'; + } $html .= '><span style="padding:3px 0;line-height:1.5em;'; if ( isset( $this->video->skin ) && isset( $this->video->skin->background_color ) ) { $html .= 'background-color:'; - if ( $this->video->skin->background_color === 'rgb(0,0,0)' ) + if ( $this->video->skin->background_color === 'rgb(0,0,0)' ) { $html .= 'rgba(0,0,0,0.8)'; - else + } else { $html .= esc_attr( $this->video->skin->background_color ); + } $html .= ';'; } $html .= 'color:rgb(255,255,255)">' . esc_html( $this->video->title ) . '</span></div>'; } $html .= '<img class="videopress-poster" alt="'; - if ( ! empty( $this->video->title ) ) + if ( ! empty( $this->video->title ) ) { $html .= esc_attr( $this->video->title ) . '" title="' . esc_attr( sprintf( _x( 'Watch: %s', 'watch a video title', 'jetpack' ), $this->video->title ) ); + } $html .= '" src="' . esc_url( $this->video->poster_frame_uri, array( 'http', 'https' ) ) . '" width="' . $width . '" height="' . $height . '" />' . PHP_EOL; - //style a play button hovered over the poster frame + // style a play button hovered over the poster frame $html .= '<div class="play-button"><span style="z-index:2;display:block;position:absolute;top:50%;left:50%;text-align:center;vertical-align:middle;color:rgb(255,255,255);opacity:0.9;margin:0 0 0 -0.45em;padding:0;line-height:0;font-size:500%;text-shadow:0 0 40px rgba(0,0,0,0.5)">▶</span></div>' . PHP_EOL; // watermark if ( isset( $this->video->skin ) && isset( $this->video->skin->watermark ) ) { $html .= '<div style="position:relative;margin-top:-40px;height:25px;margin-bottom:35px;'; - if ( $this->video->text_direction === 'rtl' ) + if ( $this->video->text_direction === 'rtl' ) { $html .= 'margin-left:20px;text-align:left;'; - else + } else { $html .= 'margin-right:20px;text-align:right;'; + } $html .= 'vertical-align:bottom;z-index:3">'; $html .= '<img alt="" src="' . esc_url( $this->video->skin->watermark, array( 'http', 'https' ) ) . '" width="90" height="13" style="background-color:transparent;background-image:none;background-repeat:no-repeat;border:none;margin:0;padding:0"/>'; $html .= '</div>' . PHP_EOL; @@ -441,38 +467,48 @@ class VideoPress_Player { } $data = array( - 'blog' => absint( $this->video->blog_id ), - 'post' => absint( $this->video->post_id ), - 'duration'=> absint( $this->video->duration ), - 'poster' => esc_url_raw( $this->video->poster_frame_uri, array( 'http', 'https' ) ), - 'hd' => (bool) $this->options['hd'] + 'blog' => absint( $this->video->blog_id ), + 'post' => absint( $this->video->post_id ), + 'duration' => absint( $this->video->duration ), + 'poster' => esc_url_raw( $this->video->poster_frame_uri, array( 'http', 'https' ) ), + 'hd' => (bool) $this->options['hd'], ); if ( isset( $this->video->videos ) ) { - if ( isset( $this->video->videos->mp4 ) && isset( $this->video->videos->mp4->url ) ) - $data['mp4'] = array( 'size' => $this->video->videos->mp4->format, 'uri' => esc_url_raw( $this->video->videos->mp4->url, array( 'http', 'https' ) ) ); - if ( isset( $this->video->videos->ogv ) && isset( $this->video->videos->ogv->url ) ) - $data['ogv'] = array( 'size' => 'std', 'uri' => esc_url_raw( $this->video->videos->ogv->url, array( 'http', 'https' ) ) ); + if ( isset( $this->video->videos->mp4 ) && isset( $this->video->videos->mp4->url ) ) { + $data['mp4'] = array( + 'size' => $this->video->videos->mp4->format, + 'uri' => esc_url_raw( $this->video->videos->mp4->url, array( 'http', 'https' ) ), + ); + } + if ( isset( $this->video->videos->ogv ) && isset( $this->video->videos->ogv->url ) ) { + $data['ogv'] = array( + 'size' => 'std', + 'uri' => esc_url_raw( $this->video->videos->ogv->url, array( 'http', 'https' ) ), + ); + } } $locale = array( 'dir' => $this->video->text_direction ); - if ( isset( $this->video->language ) ) + if ( isset( $this->video->language ) ) { $locale['lang'] = $this->video->language; + } $data['locale'] = $locale; unset( $locale ); - $guid = $this->video->guid; + $guid = $this->video->guid; $guid_js = json_encode( $guid ); - $html .= '<script type="text/javascript">' . PHP_EOL; - $html .= 'jQuery(document).ready(function() {'; + $html .= '<script type="text/javascript">' . PHP_EOL; + $html .= 'jQuery(document).ready(function() {'; - $html .= 'if ( !jQuery.VideoPress.data[' . json_encode($guid) . '] ) { jQuery.VideoPress.data[' . json_encode($guid) . '] = new Array(); }' . PHP_EOL; - $html .= 'jQuery.VideoPress.data[' . json_encode( $guid ) . '][' . self::$shown[ $guid ] . ']=' . json_encode($data) . ';' . PHP_EOL; + $html .= 'if ( !jQuery.VideoPress.data[' . json_encode( $guid ) . '] ) { jQuery.VideoPress.data[' . json_encode( $guid ) . '] = new Array(); }' . PHP_EOL; + $html .= 'jQuery.VideoPress.data[' . json_encode( $guid ) . '][' . self::$shown[ $guid ] . ']=' . json_encode( $data ) . ';' . PHP_EOL; unset( $data ); - $jq_container = json_encode( '#' . $this->video_container_id ); + $jq_container = json_encode( '#' . $this->video_container_id ); $jq_placeholder = json_encode( '#' . $video_placeholder_id ); - $player_config = "{width:{$width},height:{$height},"; - if ( isset( $this->options['freedom'] ) && $this->options['freedom'] === true ) + $player_config = "{width:{$width},height:{$height},"; + if ( isset( $this->options['freedom'] ) && $this->options['freedom'] === true ) { $player_config .= 'freedom:"true",'; + } $player_config .= 'container:jQuery(' . $jq_container . ')}'; $html .= "jQuery({$jq_placeholder}).show(0,function(){jQuery.VideoPress.analytics.impression({$guid_js})});" . PHP_EOL; @@ -482,30 +518,34 @@ class VideoPress_Player { /** * @link http://code.google.com/p/swfobject/wiki/api#swfobject.embedSWF(swfUrlStr,_replaceElemIdStr,_widthStr,_height */ - $html .= 'swfobject.embedSWF(' . implode( ',', array( - 'jQuery.VideoPress.video.flash.player_uri', - json_encode( $this->video_container_id ), - json_encode( $width ), - json_encode( $height ), - 'jQuery.VideoPress.video.flash.min_version', - 'jQuery.VideoPress.video.flash.expressinstall', // attempt to upgrade the Flash player if less than min_version. requires a 310x137 container or larger but we will always try to include - '{guid:' . $guid_js . '}', // FlashVars - 'jQuery.VideoPress.video.flash.params', - 'null', // no attributes - 'jQuery.VideoPress.video.flash.embedCallback' // error fallback - ) ) . ');'; + $html .= 'swfobject.embedSWF(' . implode( + ',', + array( + 'jQuery.VideoPress.video.flash.player_uri', + json_encode( $this->video_container_id ), + json_encode( $width ), + json_encode( $height ), + 'jQuery.VideoPress.video.flash.min_version', + 'jQuery.VideoPress.video.flash.expressinstall', // attempt to upgrade the Flash player if less than min_version. requires a 310x137 container or larger but we will always try to include + '{guid:' . $guid_js . '}', // FlashVars + 'jQuery.VideoPress.video.flash.params', + 'null', // no attributes + 'jQuery.VideoPress.video.flash.embedCallback', // error fallback + ) + ) . ');'; $html .= '} else {' . PHP_EOL; $html .= "if ( jQuery.VideoPress.video.prepare({$guid_js},{$player_config}," . self::$shown[ $guid ] . ') ) {' . PHP_EOL; - $html .= 'if ( jQuery(' . $jq_container . ').data( "player" ) === "flash" ){jQuery.VideoPress.video.play(jQuery(' . json_encode('#' . $this->video_container_id) . '));}else{'; + $html .= 'if ( jQuery(' . $jq_container . ').data( "player" ) === "flash" ){jQuery.VideoPress.video.play(jQuery(' . json_encode( '#' . $this->video_container_id ) . '));}else{'; $html .= 'jQuery(' . $jq_placeholder . ').html(' . json_encode( $this->html_age_date() ) . ');' . PHP_EOL; $html .= 'jQuery(' . json_encode( '#' . $video_placeholder_id . ' input[type=submit]' ) . ').one("click", function(event){jQuery.VideoPress.requirements.isSufficientAge(jQuery(' . $jq_container . '),' . absint( $this->video->age_rating ) . ')});' . PHP_EOL; $html .= '}}}' . PHP_EOL; } else { $html .= "if ( jQuery.VideoPress.video.prepare({$guid_js}, {$player_config}," . self::$shown[ $guid ] . ') ) {' . PHP_EOL; - if ( isset( $this->options['autoplay'] ) && $this->options['autoplay'] === true ) + if ( isset( $this->options['autoplay'] ) && $this->options['autoplay'] === true ) { $html .= "jQuery.VideoPress.video.play(jQuery({$jq_container}));"; - else - $html .= 'jQuery(' . $jq_placeholder . ').one("click",function(){jQuery.VideoPress.video.play(jQuery(' . $jq_container . '))});'; + } else { + $html .= 'jQuery(' . $jq_placeholder . ').one("click",function(){jQuery.VideoPress.video.play(jQuery(' . $jq_container . '))});'; + } $html .= '}'; // close the jQuery(document).ready() function @@ -520,26 +560,30 @@ class VideoPress_Player { $noun = __( 'this video', 'jetpack' ); if ( ! $age_gate_required ) { $vid_type = ''; - if ( ( isset( $this->options['freedom'] ) && $this->options['freedom'] === true ) && ( isset( $this->video->videos->ogv ) && isset( $this->video->videos->ogv->url ) ) ) + if ( ( isset( $this->options['freedom'] ) && $this->options['freedom'] === true ) && ( isset( $this->video->videos->ogv ) && isset( $this->video->videos->ogv->url ) ) ) { $vid_type = 'ogv'; - elseif ( isset( $this->video->videos->mp4 ) && isset( $this->video->videos->mp4->url ) ) + } elseif ( isset( $this->video->videos->mp4 ) && isset( $this->video->videos->mp4->url ) ) { $vid_type = 'mp4'; - elseif ( isset( $this->video->videos->ogv ) && isset( $this->video->videos->ogv->url ) ) + } elseif ( isset( $this->video->videos->ogv ) && isset( $this->video->videos->ogv->url ) ) { $vid_type = 'ogv'; + } if ( $vid_type !== '' ) { $noun = '<a '; - if ( isset( $this->video->language ) ) + if ( isset( $this->video->language ) ) { $noun .= 'hreflang="' . esc_attr( $this->video->language ) . '" '; - if ( $vid_type === 'mp4' ) + } + if ( $vid_type === 'mp4' ) { $noun .= 'type="video/mp4" href="' . esc_url( $this->video->videos->mp4->url, array( 'http', 'https' ) ); - elseif ( $vid_type === 'ogv' ) + } elseif ( $vid_type === 'ogv' ) { $noun .= 'type="video/ogv" href="' . esc_url( $this->video->videos->ogv->url, array( 'http', 'https' ) ); + } $noun .= '">'; - if ( isset( $this->video->title ) ) + if ( isset( $this->video->title ) ) { $noun .= esc_html( $this->video->title ); - else + } else { $noun .= __( 'this video', 'jetpack' ); + } $noun .= '</a>'; } elseif ( ! empty( $this->title ) ) { $noun = esc_html( $this->title ); @@ -579,7 +623,7 @@ class VideoPress_Player { } $videopress_options = array( - 'width' => absint( $this->video->calculated_width ), + 'width' => absint( $this->video->calculated_width ), 'height' => absint( $this->video->calculated_height ), ); foreach ( $this->options as $option => $value ) { @@ -630,7 +674,7 @@ class VideoPress_Player { } else { $videopress_options = json_encode( $videopress_options ); - $js_url = 'https://s0.wp.com/wp-content/plugins/video/assets/js/next/videopress.js'; + $js_url = 'https://s0.wp.com/wp-content/plugins/video/assets/js/next/videopress.js'; return "<div id='{$video_container_id}'></div> <script src='{$js_url}'></script> @@ -654,40 +698,42 @@ class VideoPress_Player { */ public static function esc_flash_params( $flash_params ) { $allowed_params = array( - 'swliveconnect' => array('true', 'false'), - 'play' => array('true', 'false'), - 'loop' => array('true', 'false'), - 'menu' => array('true', 'false'), - 'quality' => array('low', 'autolow', 'autohigh', 'medium', 'high', 'best'), - 'scale' => array('default', 'noborder', 'exactfit', 'noscale'), - 'align' => array('l', 'r', 't'), - 'salign' => array('l', 'r', 't', 'tl', 'tr', 'bl', 'br'), - 'wmode' => array('window', 'opaque', 'transparent','direct','gpu'), - 'devicefont' => array('_sans', '_serif', '_typewriter'), - 'allowscriptaccess' => array('always', 'samedomain', 'never'), - 'allownetworking' => array('all','internal', 'none'), - 'seamlesstabbing' => array('true', 'false'), - 'allowfullscreen' => array('true', 'false'), - 'fullScreenAspectRatio' => array('portrait', 'landscape'), + 'swliveconnect' => array( 'true', 'false' ), + 'play' => array( 'true', 'false' ), + 'loop' => array( 'true', 'false' ), + 'menu' => array( 'true', 'false' ), + 'quality' => array( 'low', 'autolow', 'autohigh', 'medium', 'high', 'best' ), + 'scale' => array( 'default', 'noborder', 'exactfit', 'noscale' ), + 'align' => array( 'l', 'r', 't' ), + 'salign' => array( 'l', 'r', 't', 'tl', 'tr', 'bl', 'br' ), + 'wmode' => array( 'window', 'opaque', 'transparent', 'direct', 'gpu' ), + 'devicefont' => array( '_sans', '_serif', '_typewriter' ), + 'allowscriptaccess' => array( 'always', 'samedomain', 'never' ), + 'allownetworking' => array( 'all', 'internal', 'none' ), + 'seamlesstabbing' => array( 'true', 'false' ), + 'allowfullscreen' => array( 'true', 'false' ), + 'fullScreenAspectRatio' => array( 'portrait', 'landscape' ), 'base', 'bgcolor', - 'flashvars' + 'flashvars', ); $allowed_params_keys = array_keys( $allowed_params ); $filtered_params = array(); - foreach( $flash_params as $param=>$value ) { - if ( empty($param) || empty($value) ) + foreach ( $flash_params as $param => $value ) { + if ( empty( $param ) || empty( $value ) ) { continue; - $param = strtolower($param); - if ( in_array($param, $allowed_params_keys) ) { - if ( isset( $allowed_params[$param] ) && is_array( $allowed_params[$param] ) ) { - $value = strtolower($value); - if ( in_array( $value, $allowed_params[$param] ) ) - $filtered_params[$param] = $value; + } + $param = strtolower( $param ); + if ( in_array( $param, $allowed_params_keys ) ) { + if ( isset( $allowed_params[ $param ] ) && is_array( $allowed_params[ $param ] ) ) { + $value = strtolower( $value ); + if ( in_array( $value, $allowed_params[ $param ] ) ) { + $filtered_params[ $param ] = $value; + } } else { - $filtered_params[$param] = $value; + $filtered_params[ $param ] = $value; } } } @@ -696,8 +742,9 @@ class VideoPress_Player { /** * Flash specifies sameDomain, not samedomain. change from lowercase value for preciseness */ - if ( isset( $filtered_params['allowscriptaccess'] ) && $filtered_params['allowscriptaccess'] === 'samedomain' ) + if ( isset( $filtered_params['allowscriptaccess'] ) && $filtered_params['allowscriptaccess'] === 'samedomain' ) { $filtered_params['allowscriptaccess'] = 'sameDomain'; + } return $filtered_params; } @@ -709,12 +756,14 @@ class VideoPress_Player { * @return array Flash variable key value pairs */ private function get_flash_variables() { - if ( ! isset( $this->video->players->swf->vars ) ) + if ( ! isset( $this->video->players->swf->vars ) ) { return array(); + } $flashvars = (array) $this->video->players->swf->vars; - if ( isset( $this->options['autoplay'] ) && $this->options['autoplay'] === true ) + if ( isset( $this->options['autoplay'] ) && $this->options['autoplay'] === true ) { $flashvars['autoPlay'] = 'true'; + } return $flashvars; } @@ -725,21 +774,22 @@ class VideoPress_Player { * @return array Flash parameters passed through key and value validation */ private function get_flash_parameters() { - if ( ! isset( $this->video->players->swf->params ) ) + if ( ! isset( $this->video->players->swf->params ) ) { return array(); - else + } else { return self::esc_flash_params( /** - * Filters the Flash parameters of the VideoPress player. - * - * @module videopress - * - * @since 1.2.0 - * - * @param array $this->video->players->swf->params Array of swf parameters for the VideoPress flash player. - */ + * Filters the Flash parameters of the VideoPress player. + * + * @module videopress + * + * @since 1.2.0 + * + * @param array $this->video->players->swf->params Array of swf parameters for the VideoPress flash player. + */ apply_filters( 'video_flash_params', (array) $this->video->players->swf->params, 10, 1 ) ); + } } /** @@ -752,18 +802,20 @@ class VideoPress_Player { */ private function flash_embed() { wp_enqueue_script( 'videopress' ); - if ( ! isset( $this->video->players->swf ) || ! isset( $this->video->players->swf->url ) ) + if ( ! isset( $this->video->players->swf ) || ! isset( $this->video->players->swf->url ) ) { return ''; + } $embed = array( - 'id' => $this->video_id, - 'src' => esc_url_raw( $this->video->players->swf->url . '&' . http_build_query( $this->get_flash_variables(), null, '&' ) , array( 'http', 'https' ) ), - 'type' => 'application/x-shockwave-flash', - 'width' => $this->video->calculated_width, - 'height' => $this->video->calculated_height + 'id' => $this->video_id, + 'src' => esc_url_raw( $this->video->players->swf->url . '&' . http_build_query( $this->get_flash_variables(), null, '&' ), array( 'http', 'https' ) ), + 'type' => 'application/x-shockwave-flash', + 'width' => $this->video->calculated_width, + 'height' => $this->video->calculated_height, ); - if ( isset( $this->video->title ) ) + if ( isset( $this->video->title ) ) { $embed['title'] = $this->video->title; + } $embed = array_merge( $embed, $this->get_flash_parameters() ); $html = '<embed'; @@ -783,23 +835,25 @@ class VideoPress_Player { */ private function flash_object() { wp_enqueue_script( 'videopress' ); - if ( ! isset( $this->video->players->swf ) || ! isset( $this->video->players->swf->url ) ) + if ( ! isset( $this->video->players->swf ) || ! isset( $this->video->players->swf->url ) ) { return ''; + } $thumbnail_html = '<img alt="'; - if ( isset( $this->video->title ) ) + if ( isset( $this->video->title ) ) { $thumbnail_html .= esc_attr( $this->video->title ); + } $thumbnail_html .= '" src="' . esc_url( $this->video->poster_frame_uri, array( 'http', 'https' ) ) . '" width="' . $this->video->calculated_width . '" height="' . $this->video->calculated_height . '" />'; - $flash_vars = esc_attr( http_build_query( $this->get_flash_variables(), null, '&' ) ); - $flash_params = ''; + $flash_vars = esc_attr( http_build_query( $this->get_flash_variables(), null, '&' ) ); + $flash_params = ''; 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" href="%s" rel="noopener noreferrer" 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' ), 'http://www.adobe.com/go/getflashplayer' ); $flash_player_url = esc_url( $this->video->players->swf->url, array( 'http', 'https' ) ); - $description = ''; + $description = ''; if ( isset( $this->video->title ) ) { - $standby = $this->video->title; + $standby = $this->video->title; $description = '<p><strong>' . esc_html( $this->video->title ) . '</strong></p>'; } else { $standby = __( 'Loading video...', 'jetpack' ); diff --git a/plugins/jetpack/modules/videopress/class.videopress-scheduler.php b/plugins/jetpack/modules/videopress/class.videopress-scheduler.php index bbc8de16..bff33684 100644 --- a/plugins/jetpack/modules/videopress/class.videopress-scheduler.php +++ b/plugins/jetpack/modules/videopress/class.videopress-scheduler.php @@ -22,10 +22,10 @@ class VideoPress_Scheduler { * @var array */ protected $crons = array( -// 'cleanup' => array( -// 'method' => self::CLEANUP_CRON_METHOD, -// 'interval' => 'minutes_30', -// ), + // 'cleanup' => array( + // 'method' => self::CLEANUP_CRON_METHOD, + // 'interval' => 'minutes_30', + // ), ); @@ -54,7 +54,7 @@ class VideoPress_Scheduler { */ public static function init() { if ( is_null( self::$instance ) ) { - self::$instance = new VideoPress_Scheduler; + self::$instance = new VideoPress_Scheduler(); } return self::$instance; @@ -73,7 +73,7 @@ class VideoPress_Scheduler { if ( ! isset( $current_schedules['minutes_30'] ) ) { $current_schedules['minutes_30'] = array( 'interval' => 30 * MINUTE_IN_SECONDS, - 'display' => 'Every 30 minutes' + 'display' => 'Every 30 minutes', ); } @@ -194,4 +194,4 @@ class VideoPress_Scheduler { public function get_crons() { return $this->crons; } -}
\ No newline at end of file +} diff --git a/plugins/jetpack/modules/videopress/class.videopress-video.php b/plugins/jetpack/modules/videopress/class.videopress-video.php index 103fa4d6..a8c3a6b8 100644 --- a/plugins/jetpack/modules/videopress/class.videopress-video.php +++ b/plugins/jetpack/modules/videopress/class.videopress-video.php @@ -1,6 +1,7 @@ <?php /** * VideoPress video object retrieved from VideoPress servers and parsed. + * * @since 1.3 */ class VideoPress_Video { @@ -178,80 +179,102 @@ class VideoPress_Video { $this->guid = $guid; $maxwidth = absint( $maxwidth ); - if ( $maxwidth > 0 ) + if ( $maxwidth > 0 ) { $this->maxwidth = $maxwidth; + } $data = $this->get_data(); if ( is_wp_error( $data ) || empty( $data ) ) { /** This filter is documented in modules/videopress/class.videopress-player.php */ if ( ! apply_filters( 'jetpack_videopress_use_legacy_player', false ) ) { // Unlike the Flash player, the new player does it's own error checking, age gate, etc. - $data = (object) array( 'guid' => $guid, 'width' => $maxwidth, 'height' => $maxwidth / 16 * 9 ); + $data = (object) array( + 'guid' => $guid, + 'width' => $maxwidth, + 'height' => $maxwidth / 16 * 9, + ); } else { $this->error = $data; return; } } - if ( isset( $data->blog_id ) ) + if ( isset( $data->blog_id ) ) { $this->blog_id = absint( $data->blog_id ); + } - if ( isset( $data->post_id ) ) + if ( isset( $data->post_id ) ) { $this->post_id = absint( $data->post_id ); + } - if ( isset( $data->title ) && $data->title !== '' ) + if ( isset( $data->title ) && $data->title !== '' ) { $this->title = trim( str_replace( ' ', ' ', $data->title ) ); + } - if ( isset( $data->description ) && $data->description !== '' ) + if ( isset( $data->description ) && $data->description !== '' ) { $this->description = trim( $data->description ); + } - if ( isset( $data->text_direction ) && $data->text_direction === 'rtl' ) + if ( isset( $data->text_direction ) && $data->text_direction === 'rtl' ) { $this->text_direction = 'rtl'; - else + } else { $this->text_direction = 'ltr'; + } - if ( isset( $data->language ) ) + if ( isset( $data->language ) ) { $this->language = $data->language; + } - if ( isset( $data->duration ) && $data->duration > 0 ) + if ( isset( $data->duration ) && $data->duration > 0 ) { $this->duration = absint( $data->duration ); + } - if ( isset( $data->width ) && $data->width > 0 ) + if ( isset( $data->width ) && $data->width > 0 ) { $this->calculated_width = absint( $data->width ); + } - if ( isset( $data->height ) && $data->height > 0 ) + if ( isset( $data->height ) && $data->height > 0 ) { $this->calculated_height = absint( $data->height ); + } - if ( isset( $data->age_rating ) ) + if ( isset( $data->age_rating ) ) { $this->age_rating = absint( $this->age_rating ); + } - if ( isset( $data->restricted_embed ) && $data->restricted_embed === true ) + if ( isset( $data->restricted_embed ) && $data->restricted_embed === true ) { $this->restricted_embed = true; - else + } else { $this->restricted_embed = false; + } - if ( isset( $data->posterframe ) && $data->posterframe !== '' ) + if ( isset( $data->posterframe ) && $data->posterframe !== '' ) { $this->poster_frame_uri = esc_url_raw( $data->posterframe, array( 'http', 'https' ) ); + } if ( isset( $data->mp4 ) || isset( $data->ogv ) ) { $this->videos = new stdClass(); - if ( isset( $data->mp4 ) ) + if ( isset( $data->mp4 ) ) { $this->videos->mp4 = $data->mp4; - if ( isset( $data->ogv ) ) + } + if ( isset( $data->ogv ) ) { $this->videos->ogv = $data->ogv; + } } if ( isset( $data->swf ) ) { - if ( ! isset( $this->players ) ) + if ( ! isset( $this->players ) ) { $this->players = new stdClass(); + } $this->players->swf = $data->swf; } - if ( isset( $data->skin ) ) + if ( isset( $data->skin ) ) { $this->skin = $data->skin; + } - if ( isset( $data->captions ) ) + if ( isset( $data->captions ) ) { $this->captions = (array) $data->captions; + } } /** @@ -262,20 +285,23 @@ class VideoPress_Video { * @return int|bool Unix time or false */ public static function calculate_expiration( $expires_header ) { - if ( empty( $expires_header ) || ! is_string( $expires_header ) ) + if ( empty( $expires_header ) || ! is_string( $expires_header ) ) { return false; + } if ( class_exists( 'DateTimeZone' ) && method_exists( 'DateTime', 'createFromFormat' ) ) { $expires_date = DateTime::createFromFormat( 'D, d M Y H:i:s T', $expires_header, new DateTimeZone( 'UTC' ) ); - if ( $expires_date instanceOf DateTime ) + if ( $expires_date instanceof DateTime ) { return date_format( $expires_date, 'U' ); + } } else { $expires_array = strptime( $expires_header, '%a, %d %b %Y %H:%M:%S %Z' ); - if ( is_array( $expires_array ) && isset( $expires_array['tm_hour'] ) && isset( $expires_array['tm_min'] ) && isset( $expires_array['tm_sec'] ) && isset( $expires_array['tm_mon'] ) && isset( $expires_array['tm_mday'] ) && isset( $expires_array['tm_year'] ) ) + if ( is_array( $expires_array ) && isset( $expires_array['tm_hour'] ) && isset( $expires_array['tm_min'] ) && isset( $expires_array['tm_sec'] ) && isset( $expires_array['tm_mon'] ) && isset( $expires_array['tm_mday'] ) && isset( $expires_array['tm_year'] ) ) { return gmmktime( $expires_array['tm_hour'], $expires_array['tm_min'], $expires_array['tm_sec'], 1 + $expires_array['tm_mon'], $expires_array['tm_mday'], 1900 + $expires_array['tm_year'] ); + } } return false; } @@ -301,19 +327,27 @@ class VideoPress_Video { private function get_data() { global $wp_version; - $domain = self::hostname( home_url() ); - $request_params = array( 'guid' => $this->guid, 'domain' => $domain ); - if ( isset( $this->maxwidth ) && $this->maxwidth > 0 ) + $domain = self::hostname( home_url() ); + $request_params = array( + 'guid' => $this->guid, + 'domain' => $domain, + ); + if ( isset( $this->maxwidth ) && $this->maxwidth > 0 ) { $request_params['maxwidth'] = $this->maxwidth; + } $url = 'http://videopress.com/data/wordpress.json'; - if ( is_ssl() ) + if ( is_ssl() ) { $url = 'https://v.wordpress.com/data/wordpress.json'; + } - $response = wp_remote_get( add_query_arg( $request_params, $url ), array( - 'redirection' => 1, - 'user-agent' => 'VideoPress plugin ' . $this->version . '; WordPress ' . $wp_version . ' (' . home_url('/') . ')', - ) ); + $response = wp_remote_get( + add_query_arg( $request_params, $url ), + array( + 'redirection' => 1, + 'user-agent' => 'VideoPress plugin ' . $this->version . '; WordPress ' . $wp_version . ' (' . home_url( '/' ) . ')', + ) + ); unset( $request_params ); unset( $url ); @@ -325,7 +359,7 @@ class VideoPress_Video { } elseif ( $response_code === 400 ) { return new WP_Error( 'bad_config', __( 'The VideoPress plugin could not communicate with the VideoPress servers. This error is most likely caused by a misconfigured plugin. Please reinstall or upgrade.', 'jetpack' ) ); } elseif ( $response_code === 403 ) { - return new WP_Error( 'http_forbidden', '<p>' . sprintf( __( '<strong>%s</strong> is not an allowed embed site.' , 'jetpack' ), esc_html( $domain ) ) . '</p><p>' . __( 'Publisher limits playback of video embeds.', 'jetpack' ) . '</p>' ); + return new WP_Error( 'http_forbidden', '<p>' . sprintf( __( '<strong>%s</strong> is not an allowed embed site.', 'jetpack' ), esc_html( $domain ) ) . '</p><p>' . __( 'Publisher limits playback of video embeds.', 'jetpack' ) . '</p>' ); } elseif ( $response_code === 404 ) { return new WP_Error( 'http_not_found', '<p>' . sprintf( __( 'No data found for VideoPress identifier: <strong>%s</strong>.', 'jetpack' ), $this->guid ) . '</p>' ); } elseif ( $response_code !== 200 || empty( $response_body ) ) { @@ -334,9 +368,9 @@ class VideoPress_Video { $expires_header = wp_remote_retrieve_header( $response, 'Expires' ); if ( ! empty( $expires_header ) ) { $expires = self::calculate_expiration( $expires_header ); - if ( ! empty( $expires ) ) + if ( ! empty( $expires ) ) { $this->expires = $expires; - + } } return json_decode( $response_body ); } diff --git a/plugins/jetpack/modules/videopress/class.videopress-xmlrpc.php b/plugins/jetpack/modules/videopress/class.videopress-xmlrpc.php index ff33b3cf..73c67d7d 100644 --- a/plugins/jetpack/modules/videopress/class.videopress-xmlrpc.php +++ b/plugins/jetpack/modules/videopress/class.videopress-xmlrpc.php @@ -28,7 +28,7 @@ class VideoPress_XMLRPC { */ public static function init() { if ( is_null( self::$instance ) ) { - self::$instance = new VideoPress_XMLRPC; + self::$instance = new VideoPress_XMLRPC(); } return self::$instance; @@ -43,8 +43,8 @@ class VideoPress_XMLRPC { */ public function xmlrpc_methods( $methods ) { - $methods['jetpack.createMediaItem'] = array( $this, 'create_media_item' ); - $methods['jetpack.updateVideoPressMediaItem'] = array( $this, 'update_videopress_media_item' ); + $methods['jetpack.createMediaItem'] = array( $this, 'create_media_item' ); + $methods['jetpack.updateVideoPressMediaItem'] = array( $this, 'update_videopress_media_item' ); $methods['jetpack.updateVideoPressPosterImage'] = array( $this, 'update_poster_image' ); return $methods; @@ -68,11 +68,14 @@ class VideoPress_XMLRPC { $media_id = videopress_create_new_media_item( $title, $guid ); - wp_update_attachment_metadata( $media_id, array( - 'original' => array( - 'url' => $media_item['url'], - ), - ) ); + wp_update_attachment_metadata( + $media_id, + array( + 'original' => array( + 'url' => $media_item['url'], + ), + ) + ); $media_item['post'] = get_post( $media_id ); } @@ -90,11 +93,11 @@ class VideoPress_XMLRPC { $id = $request['post_id']; $status = $request['status']; $format = $request['format']; - $info = $request['info']; + $info = $request['info']; - if ( ! $attachment = get_post( $id ) ) { - return false; - } + if ( ! $attachment = get_post( $id ) ) { + return false; + } $attachment->guid = $info['original']; @@ -103,18 +106,18 @@ class VideoPress_XMLRPC { // Update the vp guid and set it to a direct meta property. update_post_meta( $id, 'videopress_guid', $info['guid'] ); - $meta = wp_get_attachment_metadata( $id ); + $meta = wp_get_attachment_metadata( $id ); - $meta['width'] = $info['width']; - $meta['height'] = $info['height']; - $meta['original']['url'] = $info['original']; + $meta['width'] = $info['width']; + $meta['height'] = $info['height']; + $meta['original']['url'] = $info['original']; $meta['videopress'] = $info; $meta['videopress']['url'] = 'https://videopress.com/v/' . $info['guid']; - // Update file statuses + // Update file statuses $valid_formats = array( 'hd', 'ogg', 'mp4', 'dvd' ); if ( in_array( $format, $valid_formats ) ) { - $meta['file_statuses'][ $format ] = $status; + $meta['file_statuses'][ $format ] = $status; } if ( ! get_post_meta( $id, '_thumbnail_id', true ) ) { @@ -145,14 +148,14 @@ class VideoPress_XMLRPC { $post_id = $request['post_id']; $poster = $request['poster']; - if ( ! $attachment = get_post( $post_id ) ) { + if ( ! $attachment = get_post( $post_id ) ) { return false; } // We add ssl => 1 to make sure that the videos.files.wordpress.com domain is parsed as photon. $poster = apply_filters( 'jetpack_photon_url', $poster, array( 'ssl' => 1 ), 'https' ); - $meta = wp_get_attachment_metadata( $post_id ); + $meta = wp_get_attachment_metadata( $post_id ); $meta['videopress']['poster'] = $poster; wp_update_attachment_metadata( $post_id, $meta ); diff --git a/plugins/jetpack/modules/videopress/editor-media-view.php b/plugins/jetpack/modules/videopress/editor-media-view.php index 559eed3a..ed65a08c 100644 --- a/plugins/jetpack/modules/videopress/editor-media-view.php +++ b/plugins/jetpack/modules/videopress/editor-media-view.php @@ -23,26 +23,30 @@ function videopress_handle_editor_view_js() { false, true ); - wp_localize_script( 'videopress-editor-view', 'vpEditorView', array( - 'home_url_host' => parse_url( home_url(), PHP_URL_HOST ), - 'min_content_width' => VIDEOPRESS_MIN_WIDTH, - 'content_width' => $content_width, - 'modal_labels' => array( - 'title' => esc_html__( 'VideoPress Shortcode', 'jetpack' ), - 'guid' => esc_html__( 'Video ID', 'jetpack' ), - 'w' => esc_html__( 'Video Width', 'jetpack' ), - 'w_unit' => esc_html__( 'pixels', 'jetpack' ), - /* Translators: example of usage of this is "Start Video After 10 seconds" */ - 'at' => esc_html__( 'Start Video After', 'jetpack' ), - 'at_unit' => esc_html__( 'seconds', 'jetpack' ), - 'hd' => esc_html__( 'High definition on by default', 'jetpack' ), - 'permalink' => esc_html__( 'Link the video title to its URL on VideoPress.com', 'jetpack' ), - 'autoplay' => esc_html__( 'Autoplay video on page load', 'jetpack' ), - 'loop' => esc_html__( 'Loop video playback', 'jetpack' ), - 'freedom' => esc_html__( 'Use only Open Source codecs (may degrade performance)', 'jetpack' ), - 'flashonly' => esc_html__( 'Use legacy Flash Player (not recommended)', 'jetpack' ), + wp_localize_script( + 'videopress-editor-view', + 'vpEditorView', + array( + 'home_url_host' => parse_url( home_url(), PHP_URL_HOST ), + 'min_content_width' => VIDEOPRESS_MIN_WIDTH, + 'content_width' => $content_width, + 'modal_labels' => array( + 'title' => esc_html__( 'VideoPress Shortcode', 'jetpack' ), + 'guid' => esc_html__( 'Video ID', 'jetpack' ), + 'w' => esc_html__( 'Video Width', 'jetpack' ), + 'w_unit' => esc_html__( 'pixels', 'jetpack' ), + /* Translators: example of usage of this is "Start Video After 10 seconds" */ + 'at' => esc_html__( 'Start Video After', 'jetpack' ), + 'at_unit' => esc_html__( 'seconds', 'jetpack' ), + 'hd' => esc_html__( 'High definition on by default', 'jetpack' ), + 'permalink' => esc_html__( 'Link the video title to its URL on VideoPress.com', 'jetpack' ), + 'autoplay' => esc_html__( 'Autoplay video on page load', 'jetpack' ), + 'loop' => esc_html__( 'Loop video playback', 'jetpack' ), + 'freedom' => esc_html__( 'Use only Open Source codecs (may degrade performance)', 'jetpack' ), + 'flashonly' => esc_html__( 'Use legacy Flash Player (not recommended)', 'jetpack' ), + ), ) - ) ); + ); add_editor_style( plugins_url( 'css/videopress-editor-style.css', __FILE__ ) ); } @@ -77,7 +81,7 @@ function videopress_editor_view_js_templates() { /*************************************************\ | This is the chunk that handles overriding core | | media stuff so VideoPress can display natively. | -\*************************************************/ +\*/ /** * Media Grid: @@ -161,7 +165,7 @@ function add_videopress_media_overrides() { * * We have a template for the iframe to get injected. */ -function videopress_override_media_templates(){ +function videopress_override_media_templates() { ?> <script type="text/html" id="tmpl-videopress_iframe_vnext"> <iframe style="display: block; max-width: 100%;" width="{{ data.width }}" height="{{ data.height }}" src="https://videopress.com/embed/{{ data.guid }}?{{ data.urlargs }}" frameborder='0' allowfullscreen></iframe> diff --git a/plugins/jetpack/modules/videopress/shortcode.php b/plugins/jetpack/modules/videopress/shortcode.php index 8c87fee4..21b163ef 100644 --- a/plugins/jetpack/modules/videopress/shortcode.php +++ b/plugins/jetpack/modules/videopress/shortcode.php @@ -16,9 +16,9 @@ class VideoPress_Shortcode { wp_oembed_add_provider( '#^https?://videopress.com/v/.*#', 'http://public-api.wordpress.com/oembed/1.0/', true ); add_shortcode( 'videopress', array( $this, 'shortcode_callback' ) ); - add_shortcode( 'wpvideo', array( $this, 'shortcode_callback' ) ); + add_shortcode( 'wpvideo', array( $this, 'shortcode_callback' ) ); - add_filter('wp_video_shortcode_override', array( $this, 'video_shortcode_override' ), 10, 4); + add_filter( 'wp_video_shortcode_override', array( $this, 'video_shortcode_override' ), 10, 4 ); add_filter( 'oembed_fetch_url', array( $this, 'add_oembed_for_parameter' ) ); @@ -29,7 +29,7 @@ class VideoPress_Shortcode { * @return VideoPress_Shortcode */ public static function initialize() { - if ( ! isset ( self::$instance ) ) { + if ( ! isset( self::$instance ) ) { self::$instance = new self(); } @@ -124,24 +124,27 @@ class VideoPress_Shortcode { * * @param array $args Array of VideoPress shortcode options. */ - $options = apply_filters( 'videopress_shortcode_options', array( - 'at' => (int) $attr['at'], - 'hd' => $attr['hd'], - 'loop' => $attr['loop'], - 'freedom' => $attr['freedom'], - 'autoplay' => $attr['autoplay'], - 'permalink' => $attr['permalink'], - 'force_flash' => (bool) $attr['flashonly'], - 'defaultlangcode' => $attr['defaultlangcode'], - 'forcestatic' => false, // This used to be a displayed option, but now is only + $options = apply_filters( + 'videopress_shortcode_options', + array( + 'at' => (int) $attr['at'], + 'hd' => $attr['hd'], + 'loop' => $attr['loop'], + 'freedom' => $attr['freedom'], + 'autoplay' => $attr['autoplay'], + 'permalink' => $attr['permalink'], + 'force_flash' => (bool) $attr['flashonly'], + 'defaultlangcode' => $attr['defaultlangcode'], + 'forcestatic' => false, // This used to be a displayed option, but now is only // accessible via the `videopress_shortcode_options` filter. - ) ); + ) + ); // Register VideoPress scripts wp_register_script( 'videopress', 'https://v0.wordpress.com/js/videopress.js', array( 'jquery', 'swfobject' ), '1.09' ); - require_once( dirname( __FILE__ ) . '/class.videopress-video.php' ); - require_once( dirname( __FILE__ ) . '/class.videopress-player.php' ); + require_once dirname( __FILE__ ) . '/class.videopress-video.php'; + require_once dirname( __FILE__ ) . '/class.videopress-player.php'; $player = new VideoPress_Player( $guid, $attr['width'], $options ); @@ -165,7 +168,7 @@ class VideoPress_Shortcode { * * @return string */ - public function video_shortcode_override($html, $attr, $content, $instance) { + public function video_shortcode_override( $html, $attr, $content, $instance ) { $videopress_guid = null; @@ -177,9 +180,9 @@ class VideoPress_Shortcode { $url_keys = array( 'src', 'mp4' ); foreach ( $url_keys as $key ) { - if ( isset ( $attr[ $key ] ) ) { + if ( isset( $attr[ $key ] ) ) { $url = $attr[ $key ]; - + // phpcs:ignore WordPress.WP.CapitalPDangit if ( preg_match( '@videos.(videopress\.com|files\.wordpress\.com)/([a-z0-9]{8})/@i', $url, $matches ) ) { $videopress_guid = $matches[2]; } diff --git a/plugins/jetpack/modules/videopress/utility-functions.php b/plugins/jetpack/modules/videopress/utility-functions.php index 947f7552..345fa719 100644 --- a/plugins/jetpack/modules/videopress/utility-functions.php +++ b/plugins/jetpack/modules/videopress/utility-functions.php @@ -30,8 +30,8 @@ function videopress_get_video_details( $guid ) { return new WP_Error( 'bad-guid-format', __( 'Invalid Video GUID!', 'jetpack' ) ); } - $version = '1.1'; - $endpoint = sprintf( '/videos/%1$s', $guid ); + $version = '1.1'; + $endpoint = sprintf( '/videos/%1$s', $guid ); $query_url = sprintf( 'https://public-api.wordpress.com/rest/v%1$s%2$s', $version, @@ -97,7 +97,7 @@ function videopress_get_attachment_id_by_url( $url ) { 'compare' => 'LIKE', 'value' => $file, ), - ) + ), ); $query = new WP_Query( $query_args ); @@ -113,7 +113,6 @@ function videopress_get_attachment_id_by_url( $url ) { } } } - } return false; @@ -134,7 +133,7 @@ function videopress_download_poster_image( $url, $attachment_id ) { return new WP_Error( 'image_sideload_failed', __( 'Invalid image URL', 'jetpack' ) ); } - $file_array = array(); + $file_array = array(); $file_array['name'] = basename( $matches[0] ); $file_array['tmp_name'] = download_url( $url ); @@ -156,7 +155,7 @@ function videopress_download_poster_image( $url, $attachment_id ) { * Creates a local media library item of a remote VideoPress video. * * @param $guid - * @param int $parent_id + * @param int $parent_id * * @return int|object */ @@ -178,10 +177,13 @@ function create_local_media_library_for_videopress_guid( $guid, $parent_id = 0 ) if ( ! is_wp_error( $attachment_id ) ) { update_post_meta( $attachment_id, 'videopress_guid', $guid ); - wp_update_attachment_metadata( $attachment_id, array( - 'width' => $vp_data->width, - 'height' => $vp_data->height, - ) ); + wp_update_attachment_metadata( + $attachment_id, + array( + 'width' => $vp_data->width, + 'height' => $vp_data->height, + ) + ); $thumbnail_id = videopress_download_poster_image( $vp_data->poster, $attachment_id ); update_post_meta( $attachment_id, '_thumbnail_id', $thumbnail_id ); @@ -212,7 +214,7 @@ function videopress_cleanup_media_library() { 'key' => 'videopress_status', 'value' => 'new', ), - ) + ), ); $query = new WP_Query( $query_args ); @@ -272,7 +274,7 @@ function videopress_get_transcoding_status( $post_id ) { 'std_mp4' => isset( $info->mp4 ) ? $info->mp4 : null, 'std_ogg' => isset( $info->ogg ) ? $info->ogg : null, 'dvd_mp4' => isset( $info->dvd ) ? $info->dvd : null, - 'hd_mp4' => isset( $info->hd ) ? $info->hd : null, + 'hd_mp4' => isset( $info->hd ) ? $info->hd : null, ); return $status; @@ -518,10 +520,10 @@ function videopress_make_media_upload_path( $blog_id ) { function video_get_info_by_blogpostid( $blog_id, $post_id ) { $post = get_post( $post_id ); - $video_info = new stdClass(); - $video_info->post_id = $post_id; - $video_info->blog_id = $blog_id; - $video_info->guid = null; + $video_info = new stdClass(); + $video_info->post_id = $post_id; + $video_info->blog_id = $blog_id; + $video_info->guid = null; $video_info->finish_date_gmt = '0000-00-00 00:00:00'; if ( is_wp_error( $post ) ) { @@ -555,7 +557,7 @@ function video_get_info_by_blogpostid( $blog_id, $post_id ) { * API endpoint add all needed VideoPress data. * * @param stdClass $info - * @param string $format + * @param string $format * @return bool */ function video_format_done( $info, $format ) { @@ -637,16 +639,16 @@ function video_image_url_by_guid( $guid, $format ) { */ function video_get_post_by_guid( $guid ) { $args = array( - 'post_type' => 'attachment', + 'post_type' => 'attachment', 'post_mime_type' => 'video/videopress', - 'post_status' => 'inherit', - 'meta_query' => array( + 'post_status' => 'inherit', + 'meta_query' => array( array( - 'key' => 'videopress_guid', + 'key' => 'videopress_guid', 'value' => $guid, 'compare' => '=', - ) - ) + ), + ), ); $query = new WP_Query( $args ); @@ -661,7 +663,7 @@ function video_get_post_by_guid( $guid ) { * * When the MP4 hasn't been processed yet or this is not a VideoPress video, this will return null. * - * @param int $post_id + * @param int $post_id Post ID of the attachment. * @return string|null */ function videopress_get_attachment_url( $post_id ) { @@ -676,12 +678,15 @@ function videopress_get_attachment_url( $post_id ) { if ( ! isset( $meta['videopress']['files']['hd']['mp4'] ) ) { // Use the original file as the url if it isn't transcoded yet. if ( isset( $meta['original'] ) ) { - return $meta['original']; + $return = $meta['original']; + } else { + // Otherwise, there isn't much we can do. + return null; } - - // Otherwise, there isn't much we can do. - return null; + } else { + $return = $meta['videopress']['file_url_base']['https'] . $meta['videopress']['files']['hd']['mp4']; } - return $meta['videopress']['file_url_base']['https'] . $meta['videopress']['files']['hd']['mp4']; + // If the URL is a string, return it. Otherwise, we shouldn't to avoid errors downstream, so null. + return ( is_string( $return ) ) ? $return : null; } |