| @@ -1,0 +1,950 @@ | ||
| 1 | +<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName | |
| 2 | +use Automattic\Jetpack\VideoPress\Inline_Player; | |
| 3 | +use Automattic\Jetpack\VideoPress\Jwt_Token_Bridge; | |
| 4 | + | |
| 5 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 6 | + exit( 0 ); | |
| 7 | +} | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * VideoPress playback module markup generator. | |
| 11 | + * | |
| 12 | + * @since 1.3 | |
| 13 | + */ | |
| 14 | +class VideoPress_Player { | |
| 15 | + /** | |
| 16 | + * Video data for the requested guid and maximum width | |
| 17 | + * | |
| 18 | + * @since 1.3 | |
| 19 | + * @var VideoPress_Video | |
| 20 | + */ | |
| 21 | + protected $video; | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * DOM identifier of the video container | |
| 25 | + * | |
| 26 | + * @var string | |
| 27 | + * @since 1.3 | |
| 28 | + */ | |
| 29 | + protected $video_container_id; | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * DOM identifier of the video element (video, object, embed) | |
| 33 | + * | |
| 34 | + * @var string | |
| 35 | + * @since 1.3 | |
| 36 | + */ | |
| 37 | + protected $video_id; | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * Array of playback options: force_flash or freedom | |
| 41 | + * | |
| 42 | + * @var array | |
| 43 | + * @since 1.3 | |
| 44 | + */ | |
| 45 | + protected $options; | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * Array of video GUIDs shown and their counts, | |
| 49 | + * moved from the old VideoPress class. | |
| 50 | + * | |
| 51 | + * @var array | |
| 52 | + */ | |
| 53 | + public static $shown = array(); | |
| 54 | + | |
| 55 | + /** | |
| 56 | + * Fallback video title. | |
| 57 | + * | |
| 58 | + * @var ?string | |
| 59 | + */ | |
| 60 | + protected $title; | |
| 61 | + | |
| 62 | + /** | |
| 63 | + * Initiate a player object based on shortcode values and possible blog-level option overrides | |
| 64 | + * | |
| 65 | + * @since 1.3 | |
| 66 | + * @param string $guid VideoPress unique identifier. | |
| 67 | + * @param int $maxwidth Maximum desired width of the video player if specified. | |
| 68 | + * @param array $options Player customizations. | |
| 69 | + */ | |
| 70 | + public function __construct( $guid, $maxwidth = 0, $options = array() ) { | |
| 71 | + if ( empty( self::$shown[ $guid ] ) ) { | |
| 72 | + self::$shown[ $guid ] = 0; | |
| 73 | + } | |
| 74 | + | |
| 75 | + ++self::$shown[ $guid ]; | |
| 76 | + | |
| 77 | + $this->video_container_id = 'v-' . $guid . '-' . self::$shown[ $guid ]; | |
| 78 | + $this->video_id = $this->video_container_id . '-video'; | |
| 79 | + | |
| 80 | + if ( is_array( $options ) ) { | |
| 81 | + $this->options = $options; | |
| 82 | + } else { | |
| 83 | + $this->options = array(); | |
| 84 | + } | |
| 85 | + | |
| 86 | + // set up the video | |
| 87 | + $cache_key = null; | |
| 88 | + | |
| 89 | + // disable cache in debug mode | |
| 90 | + if ( defined( 'WP_DEBUG' ) && WP_DEBUG === true ) { | |
| 91 | + $cached_video = null; | |
| 92 | + } else { | |
| 93 | + $cache_key_pieces = array( 'video' ); | |
| 94 | + | |
| 95 | + if ( is_multisite() && is_subdomain_install() ) { | |
| 96 | + $cache_key_pieces[] = get_current_blog_id(); | |
| 97 | + } | |
| 98 | + | |
| 99 | + $cache_key_pieces[] = $guid; | |
| 100 | + if ( $maxwidth > 0 ) { | |
| 101 | + $cache_key_pieces[] = $maxwidth; | |
| 102 | + } | |
| 103 | + if ( is_ssl() ) { | |
| 104 | + $cache_key_pieces[] = 'ssl'; | |
| 105 | + } | |
| 106 | + $cache_key = implode( '-', $cache_key_pieces ); | |
| 107 | + unset( $cache_key_pieces ); | |
| 108 | + $cached_video = wp_cache_get( $cache_key, 'video' ); | |
| 109 | + } | |
| 110 | + if ( empty( $cached_video ) ) { | |
| 111 | + $video = new VideoPress_Video( $guid, $maxwidth ); | |
| 112 | + if ( isset( $video->error ) ) { | |
| 113 | + $this->video = $video->error; | |
| 114 | + return; | |
| 115 | + } elseif ( is_wp_error( $video ) ) { | |
| 116 | + $this->video = $video; | |
| 117 | + return; | |
| 118 | + } | |
| 119 | + | |
| 120 | + $this->video = $video; | |
| 121 | + unset( $video ); | |
| 122 | + | |
| 123 | + if ( ! defined( 'WP_DEBUG' ) || WP_DEBUG !== true ) { | |
| 124 | + $expire = 3600; | |
| 125 | + if ( isset( $this->video->expires ) && is_int( $this->video->expires ) ) { | |
| 126 | + $expires_diff = time() - $this->video->expires; | |
| 127 | + if ( $expires_diff > 0 && $expires_diff < 86400 ) { // allowed range: 1 second to 1 day | |
| 128 | + $expire = $expires_diff; | |
| 129 | + } | |
| 130 | + unset( $expires_diff ); | |
| 131 | + } | |
| 132 | + | |
| 133 | + wp_cache_set( $cache_key, serialize( $this->video ), 'video', $expire ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize | |
| 134 | + unset( $expire ); | |
| 135 | + } | |
| 136 | + } else { | |
| 137 | + $this->video = unserialize( $cached_video ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize -- Make sure to unserialize as VideoPress_Video class. | |
| 138 | + } | |
| 139 | + unset( $cache_key ); | |
| 140 | + unset( $cached_video ); | |
| 141 | + } | |
| 142 | + | |
| 143 | + /** | |
| 144 | + * Wrap output in a VideoPress player container. | |
| 145 | + * | |
| 146 | + * @since 1.3 | |
| 147 | + * @param string $content HTML string. | |
| 148 | + * @return string HTML string or blank string if nothing to wrap. | |
| 149 | + */ | |
| 150 | + private function html_wrapper( $content ) { | |
| 151 | + if ( empty( $content ) ) { | |
| 152 | + return ''; | |
| 153 | + } else { | |
| 154 | + return '<div id="' . esc_attr( $this->video_container_id ) . '" class="video-player">' . $content . '</div>'; | |
| 155 | + } | |
| 156 | + } | |
| 157 | + | |
| 158 | + /** | |
| 159 | + * Output content suitable for a feed reader displaying RSS or Atom feeds | |
| 160 | + * We do not display error messages in the feed view due to caching concerns. | |
| 161 | + * Flash content presented using <embed> markup for feed reader compatibility. | |
| 162 | + * | |
| 163 | + * @since 1.3 | |
| 164 | + * @return string HTML string or empty string if error | |
| 165 | + */ | |
| 166 | + public function as_xml() { | |
| 167 | + if ( empty( $this->video ) || is_wp_error( $this->video ) ) { | |
| 168 | + return ''; | |
| 169 | + } | |
| 170 | + | |
| 171 | + if ( isset( $this->options['force_flash'] ) && true === $this->options['force_flash'] ) { | |
| 172 | + $content = $this->flash_embed(); | |
| 173 | + | |
| 174 | + } else { | |
| 175 | + $content = $this->html5_static(); | |
| 176 | + } | |
| 177 | + | |
| 178 | + return $this->html_wrapper( $content ); | |
| 179 | + } | |
| 180 | + | |
| 181 | + /** | |
| 182 | + * Video player markup for best matching the current request and publisher options | |
| 183 | + * | |
| 184 | + * @since 1.3 | |
| 185 | + * @return string HTML markup string or empty string if no video property found | |
| 186 | + */ | |
| 187 | + public function as_html() { | |
| 188 | + if ( empty( $this->video ) ) { | |
| 189 | + $content = ''; | |
| 190 | + | |
| 191 | + } elseif ( is_wp_error( $this->video ) ) { | |
| 192 | + $content = $this->error_message( $this->video ); | |
| 193 | + | |
| 194 | + } elseif ( isset( $this->options['force_flash'] ) && true === $this->options['force_flash'] ) { | |
| 195 | + $content = $this->flash_object(); | |
| 196 | + | |
| 197 | + } elseif ( isset( $this->video->restricted_embed ) && true === $this->video->restricted_embed ) { | |
| 198 | + | |
| 199 | + if ( $this->options['forcestatic'] ) { | |
| 200 | + $content = $this->flash_object(); | |
| 201 | + | |
| 202 | + } else { | |
| 203 | + $content = $this->html5_dynamic(); | |
| 204 | + } | |
| 205 | + } elseif ( isset( $this->options['freedom'] ) && true === $this->options['freedom'] ) { | |
| 206 | + $content = $this->html5_static(); | |
| 207 | + | |
| 208 | + } else { | |
| 209 | + $content = $this->html5_dynamic(); | |
| 210 | + } | |
| 211 | + | |
| 212 | + return $this->html_wrapper( $content ); | |
| 213 | + } | |
| 214 | + | |
| 215 | + /** | |
| 216 | + * Display an error message to users capable of doing something about the error | |
| 217 | + * | |
| 218 | + * @since 1.3 | |
| 219 | + * @uses current_user_can() to test if current user has edit_posts capability. | |
| 220 | + * @param WP_Error $error WordPress error. | |
| 221 | + * @return string HTML string | |
| 222 | + */ | |
| 223 | + private function error_message( $error ) { | |
| 224 | + if ( ! current_user_can( 'edit_posts' ) || empty( $error ) ) { | |
| 225 | + return ''; | |
| 226 | + } | |
| 227 | + | |
| 228 | + $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">'; | |
| 229 | + /* translators: %s is 'VideoPress' */ | |
| 230 | + $html .= '<h1 style="font-size:180%;font-style:bold;line-height:130%;text-decoration:underline">' . esc_html( sprintf( __( '%s Error', 'jetpack' ), 'VideoPress' ) ) . '</h1>'; | |
| 231 | + foreach ( $error->get_error_messages() as $message ) { | |
| 232 | + $html .= $message; | |
| 233 | + } | |
| 234 | + $html .= '</div>'; | |
| 235 | + return $html; | |
| 236 | + } | |
| 237 | + | |
| 238 | + /** | |
| 239 | + * Rating agencies and industry associations require a potential viewer verify their age before a video or its poster frame are displayed. | |
| 240 | + * Content rated for audiences 17 years of age or older requires such verification across multiple rating agencies and industry associations | |
| 241 | + * | |
| 242 | + * @since 1.3 | |
| 243 | + * @return bool true if video requires the viewer verify they are 17 years of age or older | |
| 244 | + */ | |
| 245 | + private function age_gate_required() { | |
| 246 | + if ( isset( $this->video->age_rating ) && $this->video->age_rating >= 17 ) { | |
| 247 | + return true; | |
| 248 | + } else { | |
| 249 | + return false; | |
| 250 | + } | |
| 251 | + } | |
| 252 | + | |
| 253 | + /** | |
| 254 | + * Select a date of birth using HTML form elements. | |
| 255 | + * | |
| 256 | + * @since 1.5 | |
| 257 | + * @return string HTML markup | |
| 258 | + */ | |
| 259 | + private function html_age_gate() { | |
| 260 | + global $wp_locale; | |
| 261 | + $text_align = 'left'; | |
| 262 | + if ( $this->video->text_direction === 'rtl' ) { | |
| 263 | + $text_align = 'right'; | |
| 264 | + } | |
| 265 | + | |
| 266 | + $html = '<div class="videopress-age-gate" style="margin:0 60px">'; | |
| 267 | + $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>'; | |
| 268 | + $html .= '<fieldset id="birthday" style="border:0 none;text-align:' . $text_align . ';padding:0;">'; | |
| 269 | + $inputs_style = 'border:1px solid #444;margin-'; | |
| 270 | + if ( $this->video->text_direction === 'rtl' ) { | |
| 271 | + $inputs_style .= 'left'; | |
| 272 | + } else { | |
| 273 | + $inputs_style .= 'right'; | |
| 274 | + } | |
| 275 | + $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'; | |
| 276 | + | |
| 277 | + /** | |
| 278 | + * Display a list of months in the Gregorian calendar. | |
| 279 | + * Set values to 0-based to match JavaScript Date. | |
| 280 | + * | |
| 281 | + * @link https://developer.mozilla.org/en/JavaScript/Reference/global_objects/date Mozilla JavaScript Reference: Date | |
| 282 | + */ | |
| 283 | + $html .= '<select name="month" style="' . $inputs_style . '">'; | |
| 284 | + | |
| 285 | + for ( $i = 0; $i < 12; $i++ ) { | |
| 286 | + $html .= '<option value="' . esc_attr( $i ) . '">' . esc_html( $wp_locale->get_month( $i + 1 ) ) . '</option>'; | |
| 287 | + } | |
| 288 | + $html .= '</select>'; | |
| 289 | + | |
| 290 | + /** | |
| 291 | + * Todo: numdays variance by month. | |
| 292 | + */ | |
| 293 | + $html .= '<select name="day" style="' . $inputs_style . '">'; | |
| 294 | + for ( $i = 1; $i < 32; $i++ ) { | |
| 295 | + $html .= '<option>' . $i . '</option>'; | |
| 296 | + } | |
| 297 | + $html .= '</select>'; | |
| 298 | + | |
| 299 | + /** | |
| 300 | + * Current record for human life is 122. Go back 130 years and no one is left out. | |
| 301 | + * Don't ask infants younger than 2 for their birthday | |
| 302 | + * Default to 13 | |
| 303 | + */ | |
| 304 | + $html .= '<select name="year" style="' . $inputs_style . '">'; | |
| 305 | + $start_year = gmdate( 'Y' ) - 2; | |
| 306 | + $default_year = $start_year - 11; | |
| 307 | + $end_year = $start_year - 128; | |
| 308 | + for ( $year = $start_year; $year > $end_year; $year-- ) { | |
| 309 | + $html .= '<option'; | |
| 310 | + if ( $year === $default_year ) { | |
| 311 | + $html .= ' selected="selected"'; | |
| 312 | + } | |
| 313 | + $html .= '>' . $year . '</option>'; | |
| 314 | + } | |
| 315 | + unset( $start_year ); | |
| 316 | + unset( $default_year ); | |
| 317 | + unset( $end_year ); | |
| 318 | + $html .= '</select>'; | |
| 319 | + | |
| 320 | + $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" />'; | |
| 321 | + | |
| 322 | + $html .= '</fieldset>'; | |
| 323 | + $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>'; | |
| 324 | + | |
| 325 | + $html .= '</div>'; | |
| 326 | + return $html; | |
| 327 | + } | |
| 328 | + | |
| 329 | + /** | |
| 330 | + * Return HTML5 video static markup for the given video parameters. | |
| 331 | + * Use default browser player controls. | |
| 332 | + * No Flash fallback. | |
| 333 | + * | |
| 334 | + * @since 1.2 | |
| 335 | + * @link https://html.spec.whatwg.org/multipage/media.html#the-video-element HTML5 video | |
| 336 | + * @return string HTML5 video element and children | |
| 337 | + */ | |
| 338 | + private function html5_static() { | |
| 339 | + wp_enqueue_script( 'videopress' ); | |
| 340 | + $thumbnail = esc_url( $this->video->poster_frame_uri ); | |
| 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 | + | |
| 348 | + if ( isset( $this->options['autoplay'] ) && $this->options['autoplay'] === true ) { | |
| 349 | + $html .= ' autoplay="true"'; | |
| 350 | + } else { | |
| 351 | + $html .= ' preload="' . esc_attr( $preload ) . '"'; | |
| 352 | + } | |
| 353 | + if ( isset( $this->video->text_direction ) ) { | |
| 354 | + $html .= ' dir="' . esc_attr( $this->video->text_direction ) . '"'; | |
| 355 | + } | |
| 356 | + if ( isset( $this->video->language ) ) { | |
| 357 | + $html .= ' lang="' . esc_attr( $this->video->language ) . '"'; | |
| 358 | + } | |
| 359 | + $html .= '>'; | |
| 360 | + if ( | |
| 361 | + ( ! isset( $this->options['freedom'] ) || $this->options['freedom'] === false ) | |
| 362 | + && isset( $this->video->videos->mp4 ) | |
| 363 | + ) { | |
| 364 | + $mp4 = $this->video->videos->mp4->url; | |
| 365 | + if ( ! empty( $mp4 ) ) { | |
| 366 | + $html .= '<source src="' . esc_url( $mp4 ) . '" type="video/mp4; codecs="' . esc_attr( $this->video->videos->mp4->codecs ) . '"" />'; | |
| 367 | + } | |
| 368 | + unset( $mp4 ); | |
| 369 | + } | |
| 370 | + | |
| 371 | + if ( isset( $this->video->videos->ogv ) ) { | |
| 372 | + $ogg = $this->video->videos->ogv->url; | |
| 373 | + if ( ! empty( $ogg ) ) { | |
| 374 | + $html .= '<source src="' . esc_url( $ogg ) . '" type="video/ogg; codecs="' . esc_attr( $this->video->videos->ogv->codecs ) . '"" />'; | |
| 375 | + } | |
| 376 | + | |
| 377 | + unset( $ogg ); | |
| 378 | + } | |
| 379 | + | |
| 380 | + $html .= '<div><img alt="'; | |
| 381 | + if ( isset( $this->video->title ) ) { | |
| 382 | + $html .= esc_attr( $this->video->title ); | |
| 383 | + } | |
| 384 | + $html .= '" src="' . $thumbnail . '" width="' . $this->video->calculated_width . '" height="' . $this->video->calculated_height . '" /></div>'; | |
| 385 | + if ( isset( $this->options['freedom'] ) && $this->options['freedom'] === true ) { | |
| 386 | + /* translators: %s url to the gnu.org website */ | |
| 387 | + $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>'; | |
| 388 | + } elseif ( isset( $this->video->title ) ) { | |
| 389 | + $html .= '<p>' . esc_html( $this->video->title ) . '</p>'; | |
| 390 | + } | |
| 391 | + $html .= '</video>'; | |
| 392 | + return $html; | |
| 393 | + } | |
| 394 | + | |
| 395 | + /** | |
| 396 | + * Click to play dynamic HTML5-capable player. | |
| 397 | + * The player displays a video preview section including poster frame, | |
| 398 | + * video title, play button and watermark on the original page load | |
| 399 | + * and calculates the playback capabilities of the browser. The video player | |
| 400 | + * is loaded when the visitor clicks on the video preview area. | |
| 401 | + * If Flash Player 10 or above is available the browser will display | |
| 402 | + * the Flash version of the video. If HTML5 video appears to be supported | |
| 403 | + * and the browser may be capable of MP4 (H.264, AAC) or OGV (Theora, Vorbis) | |
| 404 | + * playback the browser will display its native HTML5 player. | |
| 405 | + * | |
| 406 | + * @since 1.5 | |
| 407 | + * @return string HTML markup | |
| 408 | + */ | |
| 409 | + private function html5_dynamic() { | |
| 410 | + | |
| 411 | + /** | |
| 412 | + * Filter the VideoPress legacy player feature | |
| 413 | + * | |
| 414 | + * This filter allows you to control whether the legacy VideoPress player should be used | |
| 415 | + * instead of the improved one. | |
| 416 | + * | |
| 417 | + * @module videopress | |
| 418 | + * | |
| 419 | + * @since 3.7.0 | |
| 420 | + * | |
| 421 | + * @param boolean $videopress_use_legacy_player | |
| 422 | + */ | |
| 423 | + if ( ! apply_filters( 'jetpack_videopress_use_legacy_player', false ) ) { | |
| 424 | + return $this->html5_dynamic_next(); | |
| 425 | + } | |
| 426 | + | |
| 427 | + wp_enqueue_script( 'videopress' ); | |
| 428 | + $video_placeholder_id = $this->video_container_id . '-placeholder'; | |
| 429 | + $age_gate_required = $this->age_gate_required(); | |
| 430 | + $width = absint( $this->video->calculated_width ); | |
| 431 | + $height = absint( $this->video->calculated_height ); | |
| 432 | + | |
| 433 | + $html = '<div id="' . $video_placeholder_id . '" class="videopress-placeholder" style="'; | |
| 434 | + if ( $age_gate_required ) { | |
| 435 | + $html .= "min-width:{$width}px;min-height:{$height}px"; | |
| 436 | + } else { | |
| 437 | + $html .= "width:{$width}px;height:{$height}px"; | |
| 438 | + } | |
| 439 | + $html .= ';display:none;cursor:pointer !important;position:relative;'; | |
| 440 | + if ( isset( $this->video->skin ) && isset( $this->video->skin->background_color ) ) { | |
| 441 | + $html .= 'background-color:' . esc_attr( $this->video->skin->background_color ) . ';'; | |
| 442 | + } | |
| 443 | + $html .= 'font-family: \'Helvetica Neue\',Arial,Helvetica,\'Nimbus Sans L\',sans-serif;font-weight:bold;font-size:18px">' . PHP_EOL; | |
| 444 | + | |
| 445 | + /** | |
| 446 | + * Do not display a poster frame, title, or any other content hints for mature content. | |
| 447 | + */ | |
| 448 | + if ( ! $age_gate_required ) { | |
| 449 | + if ( ! empty( $this->video->title ) ) { | |
| 450 | + $html .= '<div class="videopress-title" style="display:inline;position:absolute;margin:20px 20px 0 20px;padding:4px 8px;vertical-align:top;text-align:'; | |
| 451 | + if ( $this->video->text_direction === 'rtl' ) { | |
| 452 | + $html .= 'right" dir="rtl"'; | |
| 453 | + } else { | |
| 454 | + $html .= 'left" dir="ltr"'; | |
| 455 | + } | |
| 456 | + if ( isset( $this->video->language ) ) { | |
| 457 | + $html .= ' lang="' . esc_attr( $this->video->language ) . '"'; | |
| 458 | + } | |
| 459 | + $html .= '><span style="padding:3px 0;line-height:1.5em;'; | |
| 460 | + if ( isset( $this->video->skin ) && isset( $this->video->skin->background_color ) ) { | |
| 461 | + $html .= 'background-color:'; | |
| 462 | + if ( $this->video->skin->background_color === 'rgb(0,0,0)' ) { | |
| 463 | + $html .= 'rgba(0,0,0,0.8)'; | |
| 464 | + } else { | |
| 465 | + $html .= esc_attr( $this->video->skin->background_color ); | |
| 466 | + } | |
| 467 | + $html .= ';'; | |
| 468 | + } | |
| 469 | + $html .= 'color:rgb(255,255,255)">' . esc_html( $this->video->title ) . '</span></div>'; | |
| 470 | + } | |
| 471 | + $html .= '<img class="videopress-poster" alt="'; | |
| 472 | + if ( ! empty( $this->video->title ) ) { | |
| 473 | + /* translators: %s is the video title */ | |
| 474 | + $html .= esc_attr( $this->video->title ) . '" title="' . esc_attr( sprintf( _x( 'Watch: %s', 'watch a video title', 'jetpack' ), $this->video->title ) ); | |
| 475 | + } | |
| 476 | + $html .= '" src="' . esc_url( $this->video->poster_frame_uri, array( 'http', 'https' ) ) . '" width="' . $width . '" height="' . $height . '" />' . PHP_EOL; | |
| 477 | + | |
| 478 | + // style a play button hovered over the poster frame | |
| 479 | + $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; | |
| 480 | + | |
| 481 | + // watermark | |
| 482 | + if ( isset( $this->video->skin ) && isset( $this->video->skin->watermark ) ) { | |
| 483 | + $html .= '<div style="position:relative;margin-top:-40px;height:25px;margin-bottom:35px;'; | |
| 484 | + if ( $this->video->text_direction === 'rtl' ) { | |
| 485 | + $html .= 'margin-left:20px;text-align:left;'; | |
| 486 | + } else { | |
| 487 | + $html .= 'margin-right:20px;text-align:right;'; | |
| 488 | + } | |
| 489 | + $html .= 'vertical-align:bottom;z-index:3">'; | |
| 490 | + $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"/>'; | |
| 491 | + $html .= '</div>' . PHP_EOL; | |
| 492 | + } | |
| 493 | + } | |
| 494 | + | |
| 495 | + $data = array( | |
| 496 | + 'blog' => absint( $this->video->blog_id ), | |
| 497 | + 'post' => absint( $this->video->post_id ), | |
| 498 | + 'duration' => absint( $this->video->duration ), | |
| 499 | + 'poster' => esc_url_raw( $this->video->poster_frame_uri, array( 'http', 'https' ) ), | |
| 500 | + 'hd' => (bool) $this->options['hd'], | |
| 501 | + ); | |
| 502 | + if ( isset( $this->video->videos ) ) { | |
| 503 | + if ( isset( $this->video->videos->mp4 ) && isset( $this->video->videos->mp4->url ) ) { | |
| 504 | + $data['mp4'] = array( | |
| 505 | + 'size' => $this->video->videos->mp4->format, | |
| 506 | + 'uri' => esc_url_raw( $this->video->videos->mp4->url, array( 'http', 'https' ) ), | |
| 507 | + ); | |
| 508 | + } | |
| 509 | + if ( isset( $this->video->videos->ogv ) && isset( $this->video->videos->ogv->url ) ) { | |
| 510 | + $data['ogv'] = array( | |
| 511 | + 'size' => 'std', | |
| 512 | + 'uri' => esc_url_raw( $this->video->videos->ogv->url, array( 'http', 'https' ) ), | |
| 513 | + ); | |
| 514 | + } | |
| 515 | + } | |
| 516 | + $locale = array( 'dir' => $this->video->text_direction ); | |
| 517 | + if ( isset( $this->video->language ) ) { | |
| 518 | + $locale['lang'] = $this->video->language; | |
| 519 | + } | |
| 520 | + $data['locale'] = $locale; | |
| 521 | + unset( $locale ); | |
| 522 | + | |
| 523 | + $guid = $this->video->guid; | |
| 524 | + $guid_js = wp_json_encode( $guid, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); | |
| 525 | + $html .= '<script type="text/javascript">' . PHP_EOL; | |
| 526 | + $html .= 'jQuery(document).ready(function() {'; | |
| 527 | + | |
| 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; | |
| 530 | + unset( $data ); | |
| 531 | + | |
| 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 ); | |
| 534 | + $player_config = "{width:{$width},height:{$height},"; | |
| 535 | + if ( isset( $this->options['freedom'] ) && $this->options['freedom'] === true ) { | |
| 536 | + $player_config .= 'freedom:"true",'; | |
| 537 | + } | |
| 538 | + $player_config .= 'container:jQuery(' . $jq_container . ')}'; | |
| 539 | + | |
| 540 | + $html .= "jQuery({$jq_placeholder}).show(0,function(){jQuery.VideoPress.analytics.impression({$guid_js})});" . PHP_EOL; | |
| 541 | + | |
| 542 | + if ( $age_gate_required ) { | |
| 543 | + $html .= 'if ( jQuery.VideoPress.support.flash() ) {' . PHP_EOL; | |
| 544 | + /** | |
| 545 | + * Insert alternative content for Flash players. | |
| 546 | + * | |
| 547 | + * @link https://github.com/swfobject/swfobject/wiki/SWFObject-API#swfobjectembedswfswfurlstr-replaceelemidstr-widthstr-heightstr-swfversionstr-xiswfurlstr-flashvarsobj-parobj-attobj-callbackfn | |
| 548 | + */ | |
| 549 | + $html .= 'swfobject.embedSWF(' . implode( | |
| 550 | + ',', | |
| 551 | + array( | |
| 552 | + 'jQuery.VideoPress.video.flash.player_uri', | |
| 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 ), | |
| 556 | + 'jQuery.VideoPress.video.flash.min_version', | |
| 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 | |
| 558 | + '{guid:' . $guid_js . '}', // FlashVars | |
| 559 | + 'jQuery.VideoPress.video.flash.params', | |
| 560 | + 'null', // no attributes | |
| 561 | + 'jQuery.VideoPress.video.flash.embedCallback', // error fallback | |
| 562 | + ) | |
| 563 | + ) . ');'; | |
| 564 | + $html .= '} else {' . PHP_EOL; | |
| 565 | + $html .= "if ( jQuery.VideoPress.video.prepare({$guid_js},{$player_config}," . self::$shown[ $guid ] . ') ) {' . 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; | |
| 569 | + $html .= '}}}' . PHP_EOL; | |
| 570 | + } else { | |
| 571 | + $html .= "if ( jQuery.VideoPress.video.prepare({$guid_js}, {$player_config}," . self::$shown[ $guid ] . ') ) {' . PHP_EOL; | |
| 572 | + if ( isset( $this->options['autoplay'] ) && $this->options['autoplay'] === true ) { | |
| 573 | + $html .= "jQuery.VideoPress.video.play(jQuery({$jq_container}));"; | |
| 574 | + } else { | |
| 575 | + $html .= 'jQuery(' . $jq_placeholder . ').one("click",function(){jQuery.VideoPress.video.play(jQuery(' . $jq_container . '))});'; | |
| 576 | + } | |
| 577 | + $html .= '}'; | |
| 578 | + | |
| 579 | + // close the jQuery(document).ready() function | |
| 580 | + $html .= '});'; | |
| 581 | + } | |
| 582 | + $html .= '</script>' . PHP_EOL; | |
| 583 | + $html .= '</div>' . PHP_EOL; | |
| 584 | + | |
| 585 | + /* | |
| 586 | + * JavaScript required | |
| 587 | + */ | |
| 588 | + $noun = __( 'this video', 'jetpack' ); | |
| 589 | + if ( ! $age_gate_required ) { | |
| 590 | + $vid_type = ''; | |
| 591 | + if ( ( isset( $this->options['freedom'] ) && $this->options['freedom'] === true ) && ( isset( $this->video->videos->ogv ) && isset( $this->video->videos->ogv->url ) ) ) { | |
| 592 | + $vid_type = 'ogv'; | |
| 593 | + } elseif ( isset( $this->video->videos->mp4 ) && isset( $this->video->videos->mp4->url ) ) { | |
| 594 | + $vid_type = 'mp4'; | |
| 595 | + } elseif ( isset( $this->video->videos->ogv ) && isset( $this->video->videos->ogv->url ) ) { | |
| 596 | + $vid_type = 'ogv'; | |
| 597 | + } | |
| 598 | + | |
| 599 | + if ( $vid_type !== '' ) { | |
| 600 | + $noun = '<a '; | |
| 601 | + if ( isset( $this->video->language ) ) { | |
| 602 | + $noun .= 'hreflang="' . esc_attr( $this->video->language ) . '" '; | |
| 603 | + } | |
| 604 | + if ( $vid_type === 'mp4' ) { | |
| 605 | + $noun .= 'type="video/mp4" href="' . esc_url( $this->video->videos->mp4->url, array( 'http', 'https' ) ); | |
| 606 | + } elseif ( $vid_type === 'ogv' ) { | |
| 607 | + $noun .= 'type="video/ogv" href="' . esc_url( $this->video->videos->ogv->url, array( 'http', 'https' ) ); | |
| 608 | + } | |
| 609 | + $noun .= '">'; | |
| 610 | + if ( isset( $this->video->title ) ) { | |
| 611 | + $noun .= esc_html( $this->video->title ); | |
| 612 | + } else { | |
| 613 | + $noun .= __( 'this video', 'jetpack' ); | |
| 614 | + } | |
| 615 | + $noun .= '</a>'; | |
| 616 | + } elseif ( ! empty( $this->title ) ) { | |
| 617 | + $noun = esc_html( $this->title ); | |
| 618 | + } | |
| 619 | + unset( $vid_type ); | |
| 620 | + } | |
| 621 | + /* translators: %s video title or generic 'this video' string */ | |
| 622 | + $html .= '<noscript><p>' . sprintf( _x( 'JavaScript required to play %s.', 'Play as in playback or view a movie', 'jetpack' ), $noun ) . '</p></noscript>'; | |
| 623 | + | |
| 624 | + return $html; | |
| 625 | + } | |
| 626 | + | |
| 627 | + /** | |
| 628 | + * Output for the non-legacy HTML5 player. | |
| 629 | + */ | |
| 630 | + public function html5_dynamic_next() { | |
| 631 | + $video_container_id = 'v-' . $this->video->guid; | |
| 632 | + | |
| 633 | + Jwt_Token_Bridge::enqueue_jwt_token_bridge(); | |
| 634 | + | |
| 635 | + // Must not use iframes for IE11 due to a fullscreen bug | |
| 636 | + if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && stristr( sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ), 'Trident/7.0; rv:11.0' ) ) { | |
| 637 | + $iframe_embed = false; | |
| 638 | + } else { | |
| 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(); | |
| 641 | + } | |
| 642 | + | |
| 643 | + if ( ! array_key_exists( 'hd', $this->options ) ) { | |
| 644 | + $this->options['hd'] = (bool) get_option( 'video_player_high_quality', false ); | |
| 645 | + } | |
| 646 | + | |
| 647 | + if ( ! array_key_exists( 'cover', $this->options ) ) { | |
| 648 | + $this->options['cover'] = true; | |
| 649 | + } | |
| 650 | + | |
| 651 | + $videopress_options = array( | |
| 652 | + 'width' => absint( $this->video->calculated_width ), | |
| 653 | + 'height' => absint( $this->video->calculated_height ), | |
| 654 | + ); | |
| 655 | + foreach ( $this->options as $option => $value ) { | |
| 656 | + switch ( $option ) { | |
| 657 | + case 'at': | |
| 658 | + if ( (int) $value ) { | |
| 659 | + $videopress_options[ $option ] = (int) $value; | |
| 660 | + } | |
| 661 | + break; | |
| 662 | + case 'autoplay': | |
| 663 | + $option = 'autoPlay'; // Fall-through ok. | |
| 664 | + case 'hd': | |
| 665 | + case 'loop': | |
| 666 | + case 'permalink': | |
| 667 | + case 'cover': | |
| 668 | + case 'muted': | |
| 669 | + case 'controls': | |
| 670 | + case 'playsinline': | |
| 671 | + case 'useAverageColor': | |
| 672 | + if ( in_array( $value, array( true, 1, 'true' ), true ) ) { | |
| 673 | + $videopress_options[ $option ] = true; | |
| 674 | + } elseif ( in_array( $value, array( false, 0, 'false' ), true ) ) { | |
| 675 | + $videopress_options[ $option ] = false; | |
| 676 | + } | |
| 677 | + // phpcs:enable | |
| 678 | + break; | |
| 679 | + case 'defaultlangcode': | |
| 680 | + $option = 'defaultLangCode'; | |
| 681 | + if ( $value ) { | |
| 682 | + $videopress_options[ $option ] = $value; | |
| 683 | + } | |
| 684 | + break; | |
| 685 | + case 'preloadContent': | |
| 686 | + if ( $value ) { | |
| 687 | + $videopress_options['preloadContent'] = $value; | |
| 688 | + } | |
| 689 | + } | |
| 690 | + } | |
| 691 | + | |
| 692 | + if ( $iframe_embed ) { | |
| 693 | + $iframe_url = "https://videopress.com/embed/{$this->video->guid}"; | |
| 694 | + | |
| 695 | + foreach ( $videopress_options as $option => $value ) { | |
| 696 | + if ( ! in_array( $option, array( 'width', 'height' ), true ) ) { | |
| 697 | + | |
| 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. | |
| 700 | + $iframe_url = add_query_arg( $option, ( false === $value ) ? 0 : $value, $iframe_url ); | |
| 701 | + } | |
| 702 | + } | |
| 703 | + | |
| 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 | + | |
| 708 | + return "<iframe title='" . __( 'VideoPress Video Player', 'jetpack' ) | |
| 709 | + . "' aria-label='" . __( 'VideoPress Video Player', 'jetpack' ) | |
| 710 | + . "' width='" . esc_attr( $videopress_options['width'] ) | |
| 711 | + . "' height='" . esc_attr( $videopress_options['height'] ) | |
| 712 | + . "' src='" . esc_attr( $iframe_url ) | |
| 713 | + . "' frameborder='0' allowfullscreen" | |
| 714 | + . $cover | |
| 715 | + . " allow='clipboard-write; presentation'></iframe>"; | |
| 716 | + | |
| 717 | + } else { | |
| 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; | |
| 734 | + | |
| 735 | + $guid = (string) $this->video->guid; | |
| 736 | + | |
| 737 | + // The video data already carries the poster frame VideoPress serves for this site. | |
| 738 | + $poster = ! empty( $this->video->poster_frame_uri ) && is_string( $this->video->poster_frame_uri ) | |
| 739 | + ? $this->video->poster_frame_uri | |
| 740 | + : Inline_Player::get_poster_url( $guid ); | |
| 741 | + | |
| 742 | + return "<div id='" . esc_attr( $video_container_id ) . "'>" | |
| 743 | + . Inline_Player::render( | |
| 744 | + $guid, | |
| 745 | + Inline_Player::get_player_options( $attributes ), | |
| 746 | + $ratio, | |
| 747 | + array( | |
| 748 | + 'poster' => $poster, | |
| 749 | + 'title' => isset( $this->video->title ) ? (string) $this->video->title : '', | |
| 750 | + ) | |
| 751 | + ) | |
| 752 | + . '</div>'; | |
| 753 | + } | |
| 754 | + } | |
| 755 | + | |
| 756 | + /** | |
| 757 | + * Only allow legitimate Flash parameters and their values | |
| 758 | + * | |
| 759 | + * @since 1.2 | |
| 760 | + * @link https://helpx.adobe.com/flash/kb/flash-object-embed-tag-attributes.html Flash object and embed attributes | |
| 761 | + * @link https://helpx.adobe.com/flash/kb/font-outlines-device-fonts.html devicefont | |
| 762 | + * @link https://helpx.adobe.com/flash/kb/control-access-scripts-host-web.html allowscriptaccess | |
| 763 | + * @link https://www.adobe.com/devnet/flashplayer/articles/full_screen_mode.html full screen mode | |
| 764 | + * @link https://help.adobe.com/en_US/as3/dev/WS1EFE2EDA-026D-4d14-864E-79DFD56F87C6.html allownetworking | |
| 765 | + * @param array $flash_params Flash parameters expressed in key-value form. | |
| 766 | + * @return array validated Flash parameters | |
| 767 | + */ | |
| 768 | + public static function esc_flash_params( $flash_params ) { | |
| 769 | + $allowed_params = array( | |
| 770 | + 'swliveconnect' => array( 'true', 'false' ), | |
| 771 | + 'play' => array( 'true', 'false' ), | |
| 772 | + 'loop' => array( 'true', 'false' ), | |
| 773 | + 'menu' => array( 'true', 'false' ), | |
| 774 | + 'quality' => array( 'low', 'autolow', 'autohigh', 'medium', 'high', 'best' ), | |
| 775 | + 'scale' => array( 'default', 'noborder', 'exactfit', 'noscale' ), | |
| 776 | + 'align' => array( 'l', 'r', 't' ), | |
| 777 | + 'salign' => array( 'l', 'r', 't', 'tl', 'tr', 'bl', 'br' ), | |
| 778 | + 'wmode' => array( 'window', 'opaque', 'transparent', 'direct', 'gpu' ), | |
| 779 | + 'devicefont' => array( '_sans', '_serif', '_typewriter' ), | |
| 780 | + 'allowscriptaccess' => array( 'always', 'samedomain', 'never' ), | |
| 781 | + 'allownetworking' => array( 'all', 'internal', 'none' ), | |
| 782 | + 'seamlesstabbing' => array( 'true', 'false' ), | |
| 783 | + 'allowfullscreen' => array( 'true', 'false' ), | |
| 784 | + 'fullScreenAspectRatio' => array( 'portrait', 'landscape' ), | |
| 785 | + 'base', | |
| 786 | + 'bgcolor', | |
| 787 | + 'flashvars', | |
| 788 | + ); | |
| 789 | + | |
| 790 | + $allowed_params_keys = array_keys( $allowed_params ); | |
| 791 | + | |
| 792 | + $filtered_params = array(); | |
| 793 | + foreach ( $flash_params as $param => $value ) { | |
| 794 | + if ( empty( $param ) || empty( $value ) ) { | |
| 795 | + continue; | |
| 796 | + } | |
| 797 | + $param = strtolower( $param ); | |
| 798 | + if ( in_array( $param, $allowed_params_keys, true ) ) { | |
| 799 | + if ( isset( $allowed_params[ $param ] ) && is_array( $allowed_params[ $param ] ) ) { | |
| 800 | + $value = strtolower( $value ); | |
| 801 | + if ( in_array( $value, $allowed_params[ $param ], true ) ) { | |
| 802 | + $filtered_params[ $param ] = $value; | |
| 803 | + } | |
| 804 | + } else { | |
| 805 | + $filtered_params[ $param ] = $value; | |
| 806 | + } | |
| 807 | + } | |
| 808 | + } | |
| 809 | + unset( $allowed_params_keys ); | |
| 810 | + | |
| 811 | + /** | |
| 812 | + * Flash specifies sameDomain, not samedomain. change from lowercase value for preciseness | |
| 813 | + */ | |
| 814 | + if ( isset( $filtered_params['allowscriptaccess'] ) && $filtered_params['allowscriptaccess'] === 'samedomain' ) { | |
| 815 | + $filtered_params['allowscriptaccess'] = 'sameDomain'; | |
| 816 | + } | |
| 817 | + | |
| 818 | + return $filtered_params; | |
| 819 | + } | |
| 820 | + | |
| 821 | + /** | |
| 822 | + * Filter Flash variables from the response, taking into consideration player options. | |
| 823 | + * | |
| 824 | + * @since 1.3 | |
| 825 | + * @return array Flash variable key value pairs | |
| 826 | + */ | |
| 827 | + private function get_flash_variables() { | |
| 828 | + if ( ! isset( $this->video->players->swf->vars ) ) { | |
| 829 | + return array(); | |
| 830 | + } | |
| 831 | + | |
| 832 | + $flashvars = (array) $this->video->players->swf->vars; | |
| 833 | + if ( isset( $this->options['autoplay'] ) && $this->options['autoplay'] === true ) { | |
| 834 | + $flashvars['autoPlay'] = 'true'; | |
| 835 | + } | |
| 836 | + return $flashvars; | |
| 837 | + } | |
| 838 | + | |
| 839 | + /** | |
| 840 | + * Validate and filter Flash parameters | |
| 841 | + * | |
| 842 | + * @since 1.3 | |
| 843 | + * @return array Flash parameters passed through key and value validation | |
| 844 | + */ | |
| 845 | + private function get_flash_parameters() { | |
| 846 | + if ( ! isset( $this->video->players->swf->params ) ) { | |
| 847 | + return array(); | |
| 848 | + } else { | |
| 849 | + return self::esc_flash_params( | |
| 850 | + /** | |
| 851 | + * Filters the Flash parameters of the VideoPress player. | |
| 852 | + * | |
| 853 | + * @module videopress | |
| 854 | + * | |
| 855 | + * @since 1.2.0 | |
| 856 | + * | |
| 857 | + * @param array $this->video->players->swf->params Array of swf parameters for the VideoPress flash player. | |
| 858 | + */ | |
| 859 | + apply_filters( 'video_flash_params', (array) $this->video->players->swf->params, 10, 1 ) | |
| 860 | + ); | |
| 861 | + } | |
| 862 | + } | |
| 863 | + | |
| 864 | + /** | |
| 865 | + * Flash player markup in a HTML embed element. | |
| 866 | + * | |
| 867 | + * @since 1.1 | |
| 868 | + * @link https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-embed-element embed element | |
| 869 | + * @link http://www.google.com/support/reader/bin/answer.py?answer=70664 Google Reader markup support | |
| 870 | + * @return string HTML markup. Embed element with no children | |
| 871 | + */ | |
| 872 | + private function flash_embed() { | |
| 873 | + wp_enqueue_script( 'videopress' ); | |
| 874 | + if ( ! isset( $this->video->players->swf ) || ! isset( $this->video->players->swf->url ) ) { | |
| 875 | + return ''; | |
| 876 | + } | |
| 877 | + | |
| 878 | + $embed = array( | |
| 879 | + 'id' => $this->video_id, | |
| 880 | + 'src' => esc_url_raw( $this->video->players->swf->url . '&' . http_build_query( $this->get_flash_variables(), '', '&' ), array( 'http', 'https' ) ), | |
| 881 | + 'type' => 'application/x-shockwave-flash', | |
| 882 | + 'width' => $this->video->calculated_width, | |
| 883 | + 'height' => $this->video->calculated_height, | |
| 884 | + ); | |
| 885 | + if ( isset( $this->video->title ) ) { | |
| 886 | + $embed['title'] = $this->video->title; | |
| 887 | + } | |
| 888 | + $embed = array_merge( $embed, $this->get_flash_parameters() ); | |
| 889 | + | |
| 890 | + $html = '<embed'; | |
| 891 | + foreach ( $embed as $attribute => $value ) { | |
| 892 | + $html .= ' ' . esc_html( $attribute ) . '="' . esc_attr( $value ) . '"'; | |
| 893 | + } | |
| 894 | + unset( $embed ); | |
| 895 | + $html .= '></embed>'; | |
| 896 | + return $html; | |
| 897 | + } | |
| 898 | + | |
| 899 | + /** | |
| 900 | + * Double-baked Flash object markup for Internet Explorer and more standards-friendly consuming agents. | |
| 901 | + * | |
| 902 | + * @since 1.1 | |
| 903 | + * @return string HTML markup. Object and children. | |
| 904 | + */ | |
| 905 | + private function flash_object() { | |
| 906 | + wp_enqueue_script( 'videopress' ); | |
| 907 | + if ( ! isset( $this->video->players->swf ) || ! isset( $this->video->players->swf->url ) ) { | |
| 908 | + return ''; | |
| 909 | + } | |
| 910 | + | |
| 911 | + $thumbnail_html = '<img alt="'; | |
| 912 | + if ( isset( $this->video->title ) ) { | |
| 913 | + $thumbnail_html .= esc_attr( $this->video->title ); | |
| 914 | + } | |
| 915 | + $thumbnail_html .= '" src="' . esc_url( $this->video->poster_frame_uri, array( 'http', 'https' ) ) . '" width="' . $this->video->calculated_width . '" height="' . $this->video->calculated_height . '" />'; | |
| 916 | + $flash_vars = esc_attr( http_build_query( $this->get_flash_variables(), '', '&' ) ); | |
| 917 | + $flash_params = ''; | |
| 918 | + foreach ( $this->get_flash_parameters() as $attribute => $value ) { | |
| 919 | + $flash_params .= '<param name="' . esc_attr( $attribute ) . '" value="' . esc_attr( $value ) . '" />'; | |
| 920 | + } | |
| 921 | + /* translators: %s url to the Adobe Flash Player website */ | |
| 922 | + $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/' ); | |
| 923 | + $flash_player_url = esc_url( $this->video->players->swf->url, array( 'http', 'https' ) ); | |
| 924 | + $description = ''; | |
| 925 | + if ( isset( $this->video->title ) ) { | |
| 926 | + $standby = $this->video->title; | |
| 927 | + $description = '<p><strong>' . esc_html( $this->video->title ) . '</strong></p>'; | |
| 928 | + } else { | |
| 929 | + $standby = __( 'Loading video...', 'jetpack' ); | |
| 930 | + } | |
| 931 | + $standby = ' standby="' . esc_attr( $standby ) . '"'; | |
| 932 | + return <<<OBJECT | |
| 933 | +<script type="text/javascript">if(typeof swfobject!=="undefined"){swfobject.registerObject("{$this->video_id}", "{$this->video->players->swf->version}");}</script> | |
| 934 | +<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="{$this->video->calculated_width}" height="{$this->video->calculated_height}" id="{$this->video_id}"{$standby}> | |
| 935 | + <param name="movie" value="{$flash_player_url}" /> | |
| 936 | + {$flash_params} | |
| 937 | + <param name="flashvars" value="{$flash_vars}" /> | |
| 938 | + <!--[if !IE]>--> | |
| 939 | + <object type="application/x-shockwave-flash" data="{$flash_player_url}" width="{$this->video->calculated_width}" height="{$this->video->calculated_height}"{$standby}> | |
| 940 | + {$flash_params} | |
| 941 | + <param name="flashvars" value="{$flash_vars}" /> | |
| 942 | + <!--<![endif]--> | |
| 943 | + {$thumbnail_html}{$description}<p class="robots-nocontent">{$flash_help}</p> | |
| 944 | + <!--[if !IE]>--> | |
| 945 | + </object> | |
| 946 | + <!--<![endif]--> | |
| 947 | +</object> | |
| 948 | +OBJECT; | |
| 949 | + } | |
| 950 | +} | |