PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 All 504 releases
← All changes | modules/videopress/class.videopress-player.php +61 -45 12.0.3 → 16.3-a.1 View file →
@@ -1,7 +1,12 @@
1 1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 +use Automattic\Jetpack\VideoPress\Inline_Player;
2 3 use Automattic\Jetpack\VideoPress\Jwt_Token_Bridge;
3 4
5 +if ( ! defined( 'ABSPATH' ) ) {
6 + exit( 0 );
7 +}
8 +
4 9 /**
5 10 * VideoPress playback module markup generator.
6 11 *
7 12 * @since 1.3
@@ -47,8 +52,15 @@
47 52 */
48 53 public static $shown = array();
49 54
50 55 /**
56 + * Fallback video title.
57 + *
58 + * @var ?string
59 + */
60 + protected $title;
61 +
62 + /**
51 63 * Initiate a player object based on shortcode values and possible blog-level option overrides
52 64 *
53 65 * @since 1.3
54 66 * @param string $guid VideoPress unique identifier.
@@ -96,11 +108,9 @@
96 108 $cached_video = wp_cache_get( $cache_key, 'video' );
97 109 }
98 110 if ( empty( $cached_video ) ) {
99 111 $video = new VideoPress_Video( $guid, $maxwidth );
100 - if ( empty( $video ) ) {
101 - return;
102 - } elseif ( isset( $video->error ) ) {
112 + if ( isset( $video->error ) ) {
103 113 $this->video = $video->error;
104 114 return;
105 115 } elseif ( is_wp_error( $video ) ) {
106 116 $this->video = $video;
@@ -328,12 +338,18 @@
328 338 private function html5_static() {
329 339 wp_enqueue_script( 'videopress' );
330 340 $thumbnail = esc_url( $this->video->poster_frame_uri );
331 341 $html = "<video id=\"{$this->video_id}\" width=\"{$this->video->calculated_width}\" height=\"{$this->video->calculated_height}\" poster=\"$thumbnail\" controls=\"true\"";
342 +
343 + $preload = 'metadata';
344 + if ( isset( $this->options['preloadContent'] ) && videopress_is_valid_preload( $this->options['preloadContent'] ) ) {
345 + $preload = $this->options['preloadContent'];
346 + }
347 +
332 348 if ( isset( $this->options['autoplay'] ) && $this->options['autoplay'] === true ) {
333 349 $html .= ' autoplay="true"';
334 350 } else {
335 - $html .= ' preload="' . $this->options['preloadContent'] . '"';
351 + $html .= ' preload="' . esc_attr( $preload ) . '"';
336 352 }
337 353 if ( isset( $this->video->text_direction ) ) {
338 354 $html .= ' dir="' . esc_attr( $this->video->text_direction ) . '"';
339 355 }
@@ -504,18 +520,18 @@
504 520 $data['locale'] = $locale;
505 521 unset( $locale );
506 522
507 523 $guid = $this->video->guid;
508 - $guid_js = wp_json_encode( $guid );
524 + $guid_js = wp_json_encode( $guid, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP );
509 525 $html .= '<script type="text/javascript">' . PHP_EOL;
510 526 $html .= 'jQuery(document).ready(function() {';
511 527
512 - $html .= 'if ( !jQuery.VideoPress.data[' . wp_json_encode( $guid ) . '] ) { jQuery.VideoPress.data[' . wp_json_encode( $guid ) . '] = new Array(); }' . PHP_EOL;
513 - $html .= 'jQuery.VideoPress.data[' . wp_json_encode( $guid ) . '][' . self::$shown[ $guid ] . ']=' . wp_json_encode( $data ) . ';' . PHP_EOL;
528 + $html .= 'if ( !jQuery.VideoPress.data[' . $guid_js . '] ) { jQuery.VideoPress.data[' . $guid_js . '] = new Array(); }' . PHP_EOL;
529 + $html .= 'jQuery.VideoPress.data[' . $guid_js . '][' . self::$shown[ $guid ] . ']=' . wp_json_encode( $data, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) . ';' . PHP_EOL;
514 530 unset( $data );
515 531
516 - $jq_container = wp_json_encode( '#' . $this->video_container_id );
517 - $jq_placeholder = wp_json_encode( '#' . $video_placeholder_id );
532 + $jq_container = wp_json_encode( '#' . $this->video_container_id, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP );
533 + $jq_placeholder = wp_json_encode( '#' . $video_placeholder_id, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP );
518 534 $player_config = "{width:{$width},height:{$height},";
519 535 if ( isset( $this->options['freedom'] ) && $this->options['freedom'] === true ) {
520 536 $player_config .= 'freedom:"true",';
521 537 }
@@ -533,11 +549,11 @@
533 549 $html .= 'swfobject.embedSWF(' . implode(
534 550 ',',
535 551 array(
536 552 'jQuery.VideoPress.video.flash.player_uri',
537 - wp_json_encode( $this->video_container_id ),
538 - wp_json_encode( $width ),
539 - wp_json_encode( $height ),
553 + wp_json_encode( $this->video_container_id, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ),
554 + wp_json_encode( $width, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ),
555 + wp_json_encode( $height, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ),
540 556 'jQuery.VideoPress.video.flash.min_version',
541 557 '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
542 558 '{guid:' . $guid_js . '}', // FlashVars
543 559 'jQuery.VideoPress.video.flash.params',
@@ -546,11 +562,11 @@
546 562 )
547 563 ) . ');';
548 564 $html .= '} else {' . PHP_EOL;
549 565 $html .= "if ( jQuery.VideoPress.video.prepare({$guid_js},{$player_config}," . self::$shown[ $guid ] . ') ) {' . PHP_EOL;
550 - $html .= 'if ( jQuery(' . $jq_container . ').data( "player" ) === "flash" ){jQuery.VideoPress.video.play(jQuery(' . wp_json_encode( '#' . $this->video_container_id ) . '));}else{';
551 - $html .= 'jQuery(' . $jq_placeholder . ').html(' . wp_json_encode( $this->html_age_date() ) . ');' . PHP_EOL;
552 - $html .= 'jQuery(' . wp_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;
566 + $html .= 'if ( jQuery(' . $jq_container . ').data( "player" ) === "flash" ){jQuery.VideoPress.video.play(jQuery(' . wp_json_encode( '#' . $this->video_container_id, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) . '));}else{';
567 + $html .= 'jQuery(' . $jq_placeholder . ').html(' . wp_json_encode( $this->html_age_date(), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) . ');' . PHP_EOL;
568 + $html .= 'jQuery(' . wp_json_encode( '#' . $video_placeholder_id . ' input[type="submit"]', JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) . ').one("click", function(event){jQuery.VideoPress.requirements.isSufficientAge(jQuery(' . $jq_container . '),' . absint( $this->video->age_rating ) . ')});' . PHP_EOL;
553 569 $html .= '}}}' . PHP_EOL;
554 570 } else {
555 571 $html .= "if ( jQuery.VideoPress.video.prepare({$guid_js}, {$player_config}," . self::$shown[ $guid ] . ') ) {' . PHP_EOL;
556 572 if ( isset( $this->options['autoplay'] ) && $this->options['autoplay'] === true ) {
@@ -619,22 +635,10 @@
619 635 // Must not use iframes for IE11 due to a fullscreen bug
620 636 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && stristr( sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ), 'Trident/7.0; rv:11.0' ) ) {
621 637 $iframe_embed = false;
622 638 } else {
623 -
624 - /**
625 - * Filter the VideoPress iframe embed
626 - *
627 - * This filter allows you to control whether the videos will be embedded using an iframe.
628 - * Set this to false in order to use an in-page embed rather than an iframe.
629 - *
630 - * @module videopress
631 - *
632 - * @since 3.7.0
633 - *
634 - * @param boolean $videopress_player_use_iframe
635 - */
636 - $iframe_embed = apply_filters( 'jetpack_videopress_player_use_iframe', true );
639 + // The site setting and the `jetpack_videopress_player_use_iframe` filter decide; see Inline_Player::is_enabled().
640 + $iframe_embed = ! Inline_Player::is_enabled();
637 641 }
638 642
639 643 if ( ! array_key_exists( 'hd', $this->options ) ) {
640 644 $this->options['hd'] = (bool) get_option( 'video_player_high_quality', false );
@@ -691,15 +695,17 @@
691 695 foreach ( $videopress_options as $option => $value ) {
692 696 if ( ! in_array( $option, array( 'width', 'height' ), true ) ) {
693 697
694 698 // add_query_arg ignores false as a value, so replacing it with 0
699 + // @phan-suppress-next-line PhanPluginSimplifyExpressionBool -- Probably it could, but semantically let's keep it as-is.
695 700 $iframe_url = add_query_arg( $option, ( false === $value ) ? 0 : $value, $iframe_url );
696 701 }
697 702 }
698 703
699 - $cover = $videopress_options['cover'] ? ' data-resize-to-parent="true"' : '';
700 - $js_url = 'https://s0.wp.com/wp-content/plugins/video/assets/js/next/videopress-iframe.js';
701 - // phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedScript
704 + $cover = $videopress_options['cover'] ? ' data-resize-to-parent="true"' : '';
705 +
706 + wp_enqueue_script( 'videopress-iframe', 'https://videopress.com/videopress-iframe.js', array(), JETPACK__VERSION, true );
707 +
702 708 return "<iframe title='" . __( 'VideoPress Video Player', 'jetpack' )
703 709 . "' aria-label='" . __( 'VideoPress Video Player', 'jetpack' )
704 710 . "' width='" . esc_attr( $videopress_options['width'] )
705 711 . "' height='" . esc_attr( $videopress_options['height'] )
@@ -705,21 +711,31 @@
705 711 . "' height='" . esc_attr( $videopress_options['height'] )
706 712 . "' src='" . esc_attr( $iframe_url )
707 713 . "' frameborder='0' allowfullscreen"
708 714 . $cover
709 - . " allow='clipboard-write'></iframe>"
710 - . "<script src='" . esc_attr( $js_url ) . "'></script>";
715 + . " allow='clipboard-write; presentation'></iframe>";
711 716
712 717 } else {
713 - $videopress_options = wp_json_encode( $videopress_options );
714 - $js_url = 'https://s0.wp.com/wp-content/plugins/video/assets/js/videojs/videopress.js';
718 + $attributes = array(
719 + 'autoplay' => $videopress_options['autoPlay'] ?? false,
720 + 'controls' => $videopress_options['controls'] ?? true,
721 + 'loop' => $videopress_options['loop'] ?? false,
722 + 'muted' => $videopress_options['muted'] ?? false,
723 + 'playsinline' => $videopress_options['playsinline'] ?? false,
724 + 'useAverageColor' => $videopress_options['useAverageColor'] ?? true,
725 + 'cover' => $videopress_options['cover'],
726 + 'hd' => $videopress_options['hd'],
727 + 'at' => $videopress_options['at'] ?? 0,
728 + 'preload' => $videopress_options['preloadContent'] ?? 'metadata',
729 + 'defaultLangCode' => $videopress_options['defaultLangCode'] ?? '',
730 + );
731 + $ratio = $videopress_options['width'] > 0
732 + ? ( $videopress_options['height'] / $videopress_options['width'] ) * 100
733 + : null;
715 734
716 - return "<div id='{$video_container_id}'></div>
717 - <script src='{$js_url}'></script>
718 - <script>
719 - videopress('{$this->video->guid}', document.querySelector('#{$video_container_id}'), {$videopress_options});
720 - </script>";
721 - // phpcs:enable WordPress.WP.EnqueuedResources.NonEnqueuedScript
735 + return "<div id='" . esc_attr( $video_container_id ) . "'>"
736 + . Inline_Player::render( (string) $this->video->guid, Inline_Player::get_player_options( $attributes ), $ratio )
737 + . '</div>';
722 738 }
723 739 }
724 740
725 741 /**
@@ -845,9 +861,9 @@
845 861 }
846 862
847 863 $embed = array(
848 864 'id' => $this->video_id,
849 - 'src' => esc_url_raw( $this->video->players->swf->url . '&' . http_build_query( $this->get_flash_variables(), null, '&' ), array( 'http', 'https' ) ),
865 + 'src' => esc_url_raw( $this->video->players->swf->url . '&' . http_build_query( $this->get_flash_variables(), '', '&' ), array( 'http', 'https' ) ),
850 866 'type' => 'application/x-shockwave-flash',
851 867 'width' => $this->video->calculated_width,
852 868 'height' => $this->video->calculated_height,
853 869 );
@@ -868,9 +884,9 @@
868 884 /**
869 885 * Double-baked Flash object markup for Internet Explorer and more standards-friendly consuming agents.
870 886 *
871 887 * @since 1.1
872 - * @return HTML markup. Object and children.
888 + * @return string HTML markup. Object and children.
873 889 */
874 890 private function flash_object() {
875 891 wp_enqueue_script( 'videopress' );
876 892 if ( ! isset( $this->video->players->swf ) || ! isset( $this->video->players->swf->url ) ) {
@@ -881,9 +897,9 @@
881 897 if ( isset( $this->video->title ) ) {
882 898 $thumbnail_html .= esc_attr( $this->video->title );
883 899 }
884 900 $thumbnail_html .= '" src="' . esc_url( $this->video->poster_frame_uri, array( 'http', 'https' ) ) . '" width="' . $this->video->calculated_width . '" height="' . $this->video->calculated_height . '" />';
885 - $flash_vars = esc_attr( http_build_query( $this->get_flash_variables(), null, '&' ) );
901 + $flash_vars = esc_attr( http_build_query( $this->get_flash_variables(), '', '&' ) );
886 902 $flash_params = '';
887 903 foreach ( $this->get_flash_parameters() as $attribute => $value ) {
888 904 $flash_params .= '<param name="' . esc_attr( $attribute ) . '" value="' . esc_attr( $value ) . '" />';
889 905 }