diff options
Diffstat (limited to 'plugins/jetpack/modules/videopress/class.videopress-video.php')
-rw-r--r-- | plugins/jetpack/modules/videopress/class.videopress-video.php | 104 |
1 files changed, 69 insertions, 35 deletions
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 ); } |