VideoPress_Player

VideoPress playback module markup generator.

Defined (1)

The class is defined in the following location(s).

/modules/videopress/class.videopress-player.php  
  1. class VideoPress_Player { 
  2. /** 
  3. * Video data for the requested guid and maximum width 
  4. * @since 1.3 
  5. * @var VideoPress_Video 
  6. */ 
  7. protected $video; 
  8.  
  9. /** 
  10. * DOM identifier of the video container 
  11. * @var string 
  12. * @since 1.3 
  13. */ 
  14. protected $video_container_id; 
  15.  
  16. /** 
  17. * DOM identifier of the video element (video, object, embed) 
  18. * @var string 
  19. * @since 1.3 
  20. */ 
  21. protected $video_id; 
  22.  
  23. /** 
  24. * Array of playback options: force_flash or freedom 
  25. * @var array 
  26. * @since 1.3 
  27. */ 
  28. protected $options; 
  29.  
  30. /** 
  31. * Array of video GUIDs shown and their counts,  
  32. * moved from the old VideoPress class. 
  33. */ 
  34. public static $shown = array(); 
  35.  
  36. /** 
  37. * Initiate a player object based on shortcode values and possible blog-level option overrides 
  38. * @since 1.3 
  39. * @var string $guid VideoPress unique identifier 
  40. * @var int $maxwidth maximum desired width of the video player if specified 
  41. * @var array $options player customizations 
  42. */ 
  43. public function __construct( $guid, $maxwidth = 0, $options = array() ) { 
  44. if ( empty( self::$shown[ $guid ] ) ) 
  45. self::$shown[ $guid ] = 0; 
  46.  
  47. self::$shown[ $guid ]++; 
  48.  
  49. $this->video_container_id = 'v-' . $guid . '-' . self::$shown[ $guid ]; 
  50. $this->video_id = $this->video_container_id . '-video'; 
  51.  
  52. if ( is_array( $options ) ) 
  53. $this->options = $options; 
  54. else 
  55. $this->options = array(); 
  56.  
  57. // set up the video 
  58. $cache_key = null; 
  59.  
  60. // disable cache in debug mode 
  61. if ( defined('WP_DEBUG') && WP_DEBUG === true ) { 
  62. $cached_video = null; 
  63. } else { 
  64. $cache_key_pieces = array( 'video' ); 
  65.  
  66. if ( is_multisite() && is_subdomain_install() ) 
  67. $cache_key_pieces[] = get_current_blog_id(); 
  68.  
  69. $cache_key_pieces[] = $guid; 
  70. if ( $maxwidth > 0 ) 
  71. $cache_key_pieces[] = $maxwidth; 
  72. if ( is_ssl() ) 
  73. $cache_key_pieces[] = 'ssl'; 
  74. $cache_key = implode( '-', $cache_key_pieces ); 
  75. unset( $cache_key_pieces ); 
  76. $cached_video = wp_cache_get( $cache_key, 'video' ); 
  77. if ( empty( $cached_video ) ) { 
  78. $video = new VideoPress_Video( $guid, $maxwidth ); 
  79. if ( empty( $video ) ) { 
  80. return; 
  81. } elseif ( isset( $video->error ) ) { 
  82. $this->video = $video->error; 
  83. return; 
  84. } elseif ( is_wp_error( $video ) ) { 
  85. $this->video = $video; 
  86. return; 
  87.  
  88. $this->video = $video; 
  89. unset( $video ); 
  90.  
  91. if ( ! defined( 'WP_DEBUG' ) || WP_DEBUG !== true ) { 
  92. $expire = 3600; 
  93. if ( isset( $video->expires ) && is_int( $video->expires ) ) { 
  94. $expires_diff = time() - $video->expires; 
  95. if ( $expires_diff > 0 && $expires_diff < 86400 ) // allowed range: 1 second to 1 day 
  96. $expire = $expires_diff; 
  97. unset( $expires_diff ); 
  98.  
  99. wp_cache_set( $cache_key, serialize( $this->video ), 'video', $expire ); 
  100. unset( $expire ); 
  101. } else { 
  102. $this->video = unserialize( $cached_video ); 
  103. unset( $cache_key ); 
  104. unset( $cached_video ); 
  105.  
  106. /** 
  107. * Wrap output in a VideoPress player container 
  108. * @since 1.3 
  109. * @var string $content HTML string 
  110. * @return string HTML string or blank string if nothing to wrap 
  111. */ 
  112. private function html_wrapper( $content ) { 
  113. if ( empty( $content ) ) 
  114. return ''; 
  115. else 
  116. return '<div id="' . esc_attr( $this->video_container_id ) . '" class="video-player">' . $content . '</div>'; 
  117.  
  118. /** 
  119. * Output content suitable for a feed reader displaying RSS or Atom feeds 
  120. * We do not display error messages in the feed view due to caching concerns. 
  121. * Flash content presented using <embed> markup for feed reader compatibility. 
  122. * @since 1.3 
  123. * @return string HTML string or empty string if error 
  124. */ 
  125. public function asXML() { 
  126. if ( empty( $this->video ) || is_wp_error( $this->video ) ) 
  127. return ''; 
  128.  
  129. if ( isset( $this->options['freedom'] ) && $this->options['freedom'] === true ) 
  130. $content = $this->html5_static(); 
  131. else 
  132. $content = $this->flash_embed(); 
  133.  
  134. return $this->html_wrapper( $content ); 
  135.  
  136. /** 
  137. * Video player markup for best matching the current request and publisher options 
  138. * @since 1.3 
  139. * @return string HTML markup string or empty string if no video property found 
  140. */ 
  141. public function asHTML() { 
  142. if ( empty( $this->video ) ) { 
  143. $content = ''; 
  144. } elseif ( is_wp_error( $this->video ) ) { 
  145. $content = $this->error_message( $this->video ); 
  146. } elseif ( isset( $this->options['force_flash'] ) && $this->options['force_flash'] === true ) { 
  147. $content = $this->flash_object(); 
  148. } elseif ( isset( $this->video->restricted_embed ) && $this->video->restricted_embed === true ) { 
  149. if( $this->options['forcestatic'] ) 
  150. $content = $this->flash_object(); 
  151. else 
  152. $content = $this->html5_dynamic(); 
  153. } elseif ( isset( $this->options['freedom'] ) && $this->options['freedom'] === true ) { 
  154. $content = $this->html5_static(); 
  155. } else { 
  156. $content = $this->html5_dynamic(); 
  157. return $this->html_wrapper( $content ); 
  158.  
  159. /** 
  160. * Display an error message to users capable of doing something about the error 
  161. * @since 1.3 
  162. * @uses current_user_can() to test if current user has edit_posts capability 
  163. * @var WP_Error $error WordPress error 
  164. * @return string HTML string 
  165. */ 
  166. private function error_message( $error ) { 
  167. if ( ! current_user_can( 'edit_posts' ) || empty( $error ) ) 
  168. return ''; 
  169.  
  170. $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">'; 
  171. $html .= '<h1 style="font-size:180%;font-style:bold;line-height:130%;text-decoration:underline">' . esc_html( sprintf( __( '%s Error', 'jetpack' ), 'VideoPress' ) ) . '</h1>'; 
  172. foreach( $error->get_error_messages() as $message ) { 
  173. $html .= $message; 
  174. $html .= '</div>'; 
  175. return $html; 
  176.  
  177. /** 
  178. * Rating agencies and industry associations require a potential viewer verify his or her age before a video or its poster frame are displayed. 
  179. * Content rated for audiences 17 years of age or older requires such verification across multiple rating agencies and industry associations 
  180. * @since 1.3 
  181. * @return bool true if video requires the viewer verify he or she is 17 years of age or older 
  182. */ 
  183. private function age_gate_required() { 
  184. if ( isset( $this->video->age_rating ) && $this->video->age_rating >= 17 ) 
  185. return true; 
  186. else 
  187. return false; 
  188.  
  189. /** 
  190. * Select a date of birth using HTML form elements. 
  191. * @since 1.5 
  192. * @return string HTML markup 
  193. */ 
  194. private function html_age_gate() { 
  195. global $wp_locale; 
  196. $text_align = 'left'; 
  197. if ( $this->video->text_direction === 'rtl' ) 
  198. $text_align = 'right'; 
  199.  
  200. $html = '<div class="videopress-age-gate" style="margin:0 60px">'; 
  201. $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>'; 
  202. $html .= '<fieldset id="birthday" style="border:0 none;text-align:' . $text_align . ';padding:0;">'; 
  203. $inputs_style = 'border:1px solid #444;margin-'; 
  204. if ( $this->video->text_direction === 'rtl' ) 
  205. $inputs_style .= 'left'; 
  206. else 
  207. $inputs_style .= 'right'; 
  208. $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'; 
  209.  
  210. /** 
  211. * Display a list of months in the Gregorian calendar. 
  212. * Set values to 0-based to match JavaScript Date. 
  213. * @link https://developer.mozilla.org/en/JavaScript/Reference/global_objects/date Mozilla JavaScript Reference: Date 
  214. */ 
  215. $html .= '<select name="month" style="' . $inputs_style . '">'; 
  216.  
  217. for( $i=0; $i<12; $i++ ) { 
  218. $html .= '<option value="' . esc_attr( $i ) . '">' . esc_html( $wp_locale->get_month( $i + 1 ) ) . '</option>'; 
  219. $html .= '</select>'; 
  220.  
  221. /** 
  222. * todo: numdays variance by month 
  223. */ 
  224. $html .= '<select name="day" style="' . $inputs_style . '">'; 
  225. for ( $i=1; $i<32; $i++ ) { 
  226. $html .= '<option>' . $i . '</option>'; 
  227. $html .= '</select>'; 
  228.  
  229. /** 
  230. * Current record for human life is 122. Go back 130 years and no one is left out. 
  231. * Don't ask infants younger than 2 for their birthday 
  232. * Default to 13 
  233. */ 
  234. $html .= '<select name="year" style="' . $inputs_style . '">'; 
  235. $start_year = date('Y') - 2; 
  236. $default_year = $start_year - 11; 
  237. $end_year = $start_year - 128; 
  238. for ( $year=$start_year; $year>$end_year; $year-- ) { 
  239. $html .= '<option'; 
  240. if ( $year === $default_year ) 
  241. $html .= ' selected="selected"'; 
  242. $html .= '>' . $year . '</option>'; 
  243. unset( $start_year ); 
  244. unset( $default_year ); 
  245. unset( $end_year ); 
  246. $html .= '</select>'; 
  247.  
  248. $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" />'; 
  249.  
  250. $html .= '</fieldset>'; 
  251. $html .= '<p style="padding-top:20px;padding-bottom:60px;text-align:' . $text_align . ';"><a rel="nofollow" href="http://videopress.com/" style="color:rgb(128, 128, 128);text-decoration:underline;font-size:15px">' . __( 'More information', 'jetpack' ) . '</a></p>'; 
  252.  
  253. $html .= '</div>'; 
  254. return $html; 
  255.  
  256. /** 
  257. * Return HTML5 video static markup for the given video parameters. 
  258. * Use default browser player controls. 
  259. * No Flash fallback. 
  260. * @since 1.2 
  261. * @link http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html HTML5 video 
  262. * @return string HTML5 video element and children 
  263. */ 
  264. private function html5_static() { 
  265. wp_enqueue_script( 'videopress' ); 
  266. $thumbnail = esc_url( $this->video->poster_frame_uri ); 
  267. $html = "<video id=\"{$this->video_id}\" width=\"{$this->video->calculated_width}\" height=\"{$this->video->calculated_height}\" poster=\"$thumbnail\" controls=\"true\""; 
  268. if ( isset( $this->options['autoplay'] ) && $this->options['autoplay'] === true ) 
  269. $html .= ' autoplay="true"'; 
  270. else 
  271. $html .= ' preload="metadata"'; 
  272. if ( isset( $this->video->text_direction ) ) 
  273. $html .= ' dir="' . esc_attr( $this->video->text_direction ) . '"'; 
  274. if ( isset( $this->video->language ) ) 
  275. $html .= ' lang="' . esc_attr( $this->video->language ) . '"'; 
  276. $html .= '>'; 
  277. if ( ! isset( $this->options['freedom'] ) || $this->options['freedom'] === false ) { 
  278. $mp4 = $this->video->videos->mp4->url; 
  279. if ( ! empty( $mp4 ) ) 
  280. $html .= '<source src="' . esc_url( $mp4 ) . '" type="video/mp4; codecs="' . esc_attr( $this->video->videos->mp4->codecs ) . '"" />'; 
  281. unset( $mp4 ); 
  282. $ogg = $this->video->videos->ogv->url; 
  283. if ( ! empty( $ogg ) ) 
  284. $html .= '<source src="' . esc_url( $ogg ) . '" type="video/ogg; codecs="' . esc_attr( $this->video->videos->ogv->codecs ) . '"" />'; 
  285. unset( $ogg ); 
  286.  
  287. $html .= '<div><img alt="'; 
  288. if ( isset( $this->video->title ) ) 
  289. $html .= esc_attr( $this->video->title ); 
  290. $html .= '" src="' . $thumbnail . '" width="' . $this->video->calculated_width . '" height="' . $this->video->calculated_height . '" /></div>'; 
  291. if ( isset( $this->options['freedom'] ) && $this->options['freedom'] === true ) 
  292. $html .= '<p class="robots-nocontent">' . sprintf( __( 'You do not have sufficient <a rel="nofollow" href="%s">freedom levels</a> to view this video. Support free software and upgrade.', 'jetpack' ), 'http://www.gnu.org/philosophy/free-sw.html' ) . '</p>'; 
  293. elseif ( isset( $this->video->title ) ) 
  294. $html .= '<p>' . esc_html( $this->video->title ) . '</p>'; 
  295. $html .= '</video>'; 
  296. return $html; 
  297.  
  298. /** 
  299. * Click to play dynamic HTML5-capable player. 
  300. * The player displays a video preview section including poster frame,  
  301. * video title, play button and watermark on the original page load 
  302. * and calculates the playback capabilities of the browser. The video player 
  303. * is loaded when the visitor clicks on the video preview area. 
  304. * If Flash Player 10 or above is available the browser will display 
  305. * the Flash version of the video. If HTML5 video appears to be supported 
  306. * and the browser may be capable of MP4 (H.264, AAC) or OGV (Theora, Vorbis) 
  307. * playback the browser will display its native HTML5 player. 
  308. * @since 1.5 
  309. * @return string HTML markup 
  310. */ 
  311. private function html5_dynamic() { 
  312.  
  313. /** 
  314. * Filter the VideoPress legacy player feature 
  315. * This filter allows you to control whether the legacy VideoPress player should be used 
  316. * instead of the improved one. 
  317. * @module videopress 
  318. * @since 3.7.0 
  319. * @param boolean $videopress_use_legacy_player 
  320. */ 
  321. if ( ! apply_filters( 'jetpack_videopress_use_legacy_player', false ) ) { 
  322. return $this->html5_dynamic_next(); 
  323.  
  324. wp_enqueue_script( 'videopress' ); 
  325. $video_placeholder_id = $this->video_container_id . '-placeholder'; 
  326. $age_gate_required = $this->age_gate_required(); 
  327. $width = absint( $this->video->calculated_width ); 
  328. $height = absint( $this->video->calculated_height ); 
  329.  
  330. $html = '<div id="' . $video_placeholder_id . '" class="videopress-placeholder" style="'; 
  331. if ( $age_gate_required ) 
  332. $html .= "min-width:{$width}px;min-height:{$height}px"; 
  333. else 
  334. $html .= "width:{$width}px;height:{$height}px"; 
  335. $html .= ';display:none;cursor:pointer !important;position:relative;'; 
  336. if ( isset( $this->video->skin ) && isset( $this->video->skin->background_color ) ) 
  337. $html .= 'background-color:' . esc_attr( $this->video->skin->background_color ) . ';'; 
  338. $html .= 'font-family: \'Helvetica Neue\', Arial, Helvetica, \'Nimbus Sans L\', sans-serif;font-weight:bold;font-size:18px">' . PHP_EOL; 
  339.  
  340. /** 
  341. * Do not display a poster frame, title, or any other content hints for mature content. 
  342. */ 
  343. if ( ! $age_gate_required ) { 
  344. if ( ! empty( $this->video->title ) ) { 
  345. $html .= '<div class="videopress-title" style="display:inline;position:absolute;margin:20px 20px 0 20px;padding:4px 8px;vertical-align:top;text-align:'; 
  346. if ( $this->video->text_direction === 'rtl' ) 
  347. $html .= 'right" dir="rtl"'; 
  348. else 
  349. $html .= 'left" dir="ltr"'; 
  350. if ( isset( $this->video->language ) ) 
  351. $html .= ' lang="' . esc_attr( $this->video->language ) . '"'; 
  352. $html .= '><span style="padding:3px 0;line-height:1.5em;'; 
  353. if ( isset( $this->video->skin ) && isset( $this->video->skin->background_color ) ) { 
  354. $html .= 'background-color:'; 
  355. if ( $this->video->skin->background_color === 'rgb(0, 0, 0)' ) 
  356. $html .= 'rgba(0, 0, 0, 0.8)'; 
  357. else 
  358. $html .= esc_attr( $this->video->skin->background_color ); 
  359. $html .= ';'; 
  360. $html .= 'color:rgb(255, 255, 255)">' . esc_html( $this->video->title ) . '</span></div>'; 
  361. $html .= '<img class="videopress-poster" alt="'; 
  362. if ( ! empty( $this->video->title ) ) 
  363. $html .= esc_attr( $this->video->title ) . '" title="' . esc_attr( sprintf( _x( 'Watch: %s', 'watch a video title', 'jetpack' ), $this->video->title ) ); 
  364. $html .= '" src="' . esc_url( $this->video->poster_frame_uri, array( 'http', 'https' ) ) . '" width="' . $width . '" height="' . $height . '" />' . PHP_EOL; 
  365.  
  366. //style a play button hovered over the poster frame 
  367. $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; 
  368.  
  369. // watermark 
  370. if ( isset( $this->video->skin ) && isset( $this->video->skin->watermark ) ) { 
  371. $html .= '<div style="position:relative;margin-top:-40px;height:25px;margin-bottom:35px;'; 
  372. if ( $this->video->text_direction === 'rtl' ) 
  373. $html .= 'margin-left:20px;text-align:left;'; 
  374. else 
  375. $html .= 'margin-right:20px;text-align:right;'; 
  376. $html .= 'vertical-align:bottom;z-index:3">'; 
  377. $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"/>'; 
  378. $html .= '</div>' . PHP_EOL; 
  379.  
  380. $data = array( 
  381. 'blog' => absint( $this->video->blog_id ),  
  382. 'post' => absint( $this->video->post_id ),  
  383. 'duration'=> absint( $this->video->duration ),  
  384. 'poster' => esc_url_raw( $this->video->poster_frame_uri, array( 'http', 'https' ) ),  
  385. 'hd' => (bool) $this->options['hd'] 
  386. ); 
  387. if ( isset( $this->video->videos ) ) { 
  388. if ( isset( $this->video->videos->mp4 ) && isset( $this->video->videos->mp4->url ) ) 
  389. $data['mp4'] = array( 'size' => $this->video->videos->mp4->format, 'uri' => esc_url_raw( $this->video->videos->mp4->url, array( 'http', 'https' ) ) ); 
  390. if ( isset( $this->video->videos->ogv ) && isset( $this->video->videos->ogv->url ) ) 
  391. $data['ogv'] = array( 'size' => 'std', 'uri' => esc_url_raw( $this->video->videos->ogv->url, array( 'http', 'https' ) ) ); 
  392. $locale = array( 'dir' => $this->video->text_direction ); 
  393. if ( isset( $this->video->language ) ) 
  394. $locale['lang'] = $this->video->language; 
  395. $data['locale'] = $locale; 
  396. unset( $locale ); 
  397.  
  398. $guid = $this->video->guid; 
  399. $guid_js = json_encode( $guid ); 
  400. $html .= '<script type="text/javascript">' . PHP_EOL; 
  401. $html .= 'jQuery(document).ready(function() {'; 
  402.  
  403. $html .= 'if ( !jQuery.VideoPress.data[' . json_encode($guid) . '] ) { jQuery.VideoPress.data[' . json_encode($guid) . '] = new Array(); }' . PHP_EOL; 
  404. $html .= 'jQuery.VideoPress.data[' . json_encode( $guid ) . '][' . self::$shown[ $guid ] . ']=' . json_encode($data) . ';' . PHP_EOL; 
  405. unset( $data ); 
  406.  
  407. $jq_container = json_encode( '#' . $this->video_container_id ); 
  408. $jq_placeholder = json_encode( '#' . $video_placeholder_id ); 
  409. $player_config = "{width:{$width}, height:{$height}, "; 
  410. if ( isset( $this->options['freedom'] ) && $this->options['freedom'] === true ) 
  411. $player_config .= 'freedom:"true", '; 
  412. $player_config .= 'container:jQuery(' . $jq_container . ')}'; 
  413.  
  414. $html .= "jQuery({$jq_placeholder}).show(0, function() {jQuery.VideoPress.analytics.impression({$guid_js})});" . PHP_EOL; 
  415.  
  416. if ( $age_gate_required ) { 
  417. $html .= 'if ( jQuery.VideoPress.support.flash() ) {' . PHP_EOL; 
  418. /** 
  419. * @link http://code.google.com/p/swfobject/wiki/api#swfobject.embedSWF(swfUrlStr, _replaceElemIdStr, _widthStr, _height 
  420. */ 
  421. $html .= 'swfobject.embedSWF(' . implode( ', ', array( 
  422. 'jQuery.VideoPress.video.flash.player_uri',  
  423. json_encode( $this->video_container_id ),  
  424. json_encode( $width ),  
  425. json_encode( $height ),  
  426. 'jQuery.VideoPress.video.flash.min_version',  
  427. '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 
  428. '{guid:' . $guid_js . '}', // FlashVars 
  429. 'jQuery.VideoPress.video.flash.params',  
  430. 'null', // no attributes 
  431. 'jQuery.VideoPress.video.flash.embedCallback' // error fallback 
  432. ) ) . ');'; 
  433. $html .= '} else {' . PHP_EOL; 
  434. $html .= "if ( jQuery.VideoPress.video.prepare({$guid_js}, {$player_config}, " . self::$shown[ $guid ] . ') ) {' . PHP_EOL; 
  435. $html .= 'if ( jQuery(' . $jq_container . ').data( "player" ) === "flash" ) {jQuery.VideoPress.video.play(jQuery(' . json_encode('#' . $this->video_container_id) . '));}else{'; 
  436. $html .= 'jQuery(' . $jq_placeholder . ').html(' . json_encode( $this->html_age_date() ) . ');' . PHP_EOL; 
  437. $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; 
  438. $html .= '}}}' . PHP_EOL; 
  439. } else { 
  440. $html .= "if ( jQuery.VideoPress.video.prepare({$guid_js}, {$player_config}, " . self::$shown[ $guid ] . ') ) {' . PHP_EOL; 
  441. if ( isset( $this->options['autoplay'] ) && $this->options['autoplay'] === true ) 
  442. $html .= "jQuery.VideoPress.video.play(jQuery({$jq_container}));"; 
  443. else 
  444. $html .= 'jQuery(' . $jq_placeholder . ').one("click", function() {jQuery.VideoPress.video.play(jQuery(' . $jq_container . '))});'; 
  445. $html .= '}'; 
  446.  
  447. // close the jQuery(document).ready() function 
  448. $html .= '});'; 
  449. $html .= '</script>' . PHP_EOL; 
  450. $html .= '</div>' . PHP_EOL; 
  451.  
  452. /** 
  453. * JavaScript required 
  454. */ 
  455. $noun = __( 'this video', 'jetpack' ); 
  456. if ( ! $age_gate_required ) { 
  457. $vid_type = ''; 
  458. if ( ( isset( $this->options['freedom'] ) && $this->options['freedom'] === true ) && ( isset( $this->video->videos->ogv ) && isset( $this->video->videos->ogv->url ) ) ) 
  459. $vid_type = 'ogv'; 
  460. elseif ( isset( $this->video->videos->mp4 ) && isset( $this->video->videos->mp4->url ) ) 
  461. $vid_type = 'mp4'; 
  462. elseif ( isset( $this->video->videos->ogv ) && isset( $this->video->videos->ogv->url ) ) 
  463. $vid_type = 'ogv'; 
  464.  
  465. if ( $vid_type !== '' ) { 
  466. $noun = '<a '; 
  467. if ( isset( $this->video->language ) ) 
  468. $noun .= 'hreflang="' . esc_attr( $this->video->language ) . '" '; 
  469. if ( $vid_type === 'mp4' ) 
  470. $noun .= 'type="video/mp4" href="' . esc_url( $this->video->videos->mp4->url, array( 'http', 'https' ) ); 
  471. elseif ( $vid_type === 'ogv' ) 
  472. $noun .= 'type="video/ogv" href="' . esc_url( $this->video->videos->ogv->url, array( 'http', 'https' ) ); 
  473. $noun .= '">'; 
  474. if ( isset( $this->video->title ) ) 
  475. $noun .= esc_html( $this->video->title ); 
  476. else 
  477. $noun .= __( 'this video', 'jetpack' ); 
  478. $noun .= '</a>'; 
  479. } elseif ( ! empty( $this->title ) ) { 
  480. $noun = esc_html( $this->title ); 
  481. unset( $vid_type ); 
  482. $html .= '<noscript><p>' . sprintf( _x( 'JavaScript required to play %s.', 'Play as in playback or view a movie', 'jetpack' ), $noun ) . '</p></noscript>'; 
  483.  
  484. return $html; 
  485.  
  486. function html5_dynamic_next() { 
  487. $video_container_id = 'v-' . $this->video->guid; 
  488.  
  489. // Must not use iframes for IE11 due to a fullscreen bug 
  490. if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && stristr( $_SERVER['HTTP_USER_AGENT'], 'Trident/7.0; rv:11.0' ) ) { 
  491. $iframe_embed = false; 
  492. } else { 
  493.  
  494. /** 
  495. * Filter the VideoPress iframe embed 
  496. * This filter allows you to control whether the videos will be embedded using an iframe. 
  497. * Set this to false in order to use an in-page embed rather than an iframe. 
  498. * @module videopress 
  499. * @since 3.7.0 
  500. * @param boolean $videopress_player_use_iframe 
  501. */ 
  502. $iframe_embed = apply_filters( 'jetpack_videopress_player_use_iframe', true ); 
  503.  
  504. if ( ! array_key_exists( 'hd', $this->options ) ) { 
  505. $this->options['hd'] = (bool) get_option( 'video_player_high_quality', false ); 
  506.  
  507. $videopress_options = array( 
  508. 'width' => absint( $this->video->calculated_width ),  
  509. 'height' => absint( $this->video->calculated_height ),  
  510. ); 
  511. foreach ( $this->options as $option => $value ) { 
  512. switch ( $option ) { 
  513. case 'at': 
  514. if ( intval( $value ) ) { 
  515. $videopress_options[ $option ] = intval( $value ); 
  516. break; 
  517. case 'autoplay': 
  518. $option = 'autoPlay'; 
  519. case 'hd': 
  520. case 'loop': 
  521. case 'permalink': 
  522. if ( in_array( $value, array( 1, 'true' ) ) ) { 
  523. $videopress_options[ $option ] = true; 
  524. } elseif ( in_array( $value, array( 0, 'false' ) ) ) { 
  525. $videopress_options[ $option ] = false; 
  526. break; 
  527. case 'defaultlangcode': 
  528. $option = 'defaultLangCode'; 
  529. if ( $value ) { 
  530. $videopress_options[ $option ] = $value; 
  531. break; 
  532.  
  533. if ( $iframe_embed ) { 
  534. $iframe_url = "https://videopress.com/embed/{$this->video->guid}"; 
  535.  
  536. foreach ( $videopress_options as $option => $value ) { 
  537. if ( ! in_array( $option, array( 'width', 'height' ) ) ) { 
  538.  
  539. // add_query_arg ignores false as a value, so replacing it with 0 
  540. $iframe_url = add_query_arg( $option, ( false === $value ) ? 0 : $value, $iframe_url ); 
  541.  
  542. $js_url = 'https://s0.wp.com/wp-content/plugins/video/assets/js/next/videopress-iframe.js'; 
  543. $js_url = add_query_arg( 'jetpack_version', JETPACK__VERSION, $js_url ); 
  544.  
  545. return "<iframe width='" . esc_attr( $videopress_options['width'] ) 
  546. . "' height='" . esc_attr( $videopress_options['height'] ) 
  547. . "' src='" . esc_attr( $iframe_url ) 
  548. . "' frameborder='0' allowfullscreen></iframe>" 
  549. . "<script src='" . esc_attr( $js_url ) . "'></script>"; 
  550.  
  551. } else { 
  552. $videopress_options = json_encode( $videopress_options ); 
  553. $js_url = 'https://s0.wp.com/wp-content/plugins/video/assets/js/next/videopress.js'; 
  554. $js_url = add_query_arg( 'jetpack_version', JETPACK__VERSION, $js_url ); 
  555.  
  556. return "<div id='{$video_container_id}'></div> 
  557. <script src='{$js_url}'></script> 
  558. <script> 
  559. videopress('{$this->video->guid}', document.querySelector('#{$video_container_id}'), {$videopress_options}); 
  560. </script>"; 
  561.  
  562. /** 
  563. * Only allow legitimate Flash parameters and their values 
  564. * @since 1.2 
  565. * @link http://kb2.adobe.com/cps/127/tn_12701.html Flash object and embed attributes 
  566. * @link http://kb2.adobe.com/cps/133/tn_13331.html devicefont 
  567. * @link http://kb2.adobe.com/cps/164/tn_16494.html allowscriptaccess 
  568. * @link http://www.adobe.com/devnet/flashplayer/articles/full_screen_mode.html full screen mode 
  569. * @link http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001079.html allownetworking 
  570. * @param array $flash_params Flash parameters expressed in key-value form 
  571. * @return array validated Flash parameters 
  572. */ 
  573. public static function esc_flash_params( $flash_params ) { 
  574. $allowed_params = array( 
  575. 'swliveconnect' => array('true', 'false'),  
  576. 'play' => array('true', 'false'),  
  577. 'loop' => array('true', 'false'),  
  578. 'menu' => array('true', 'false'),  
  579. 'quality' => array('low', 'autolow', 'autohigh', 'medium', 'high', 'best'),  
  580. 'scale' => array('default', 'noborder', 'exactfit', 'noscale'),  
  581. 'align' => array('l', 'r', 't'),  
  582. 'salign' => array('l', 'r', 't', 'tl', 'tr', 'bl', 'br'),  
  583. 'wmode' => array('window', 'opaque', 'transparent', 'direct', 'gpu'),  
  584. 'devicefont' => array('_sans', '_serif', '_typewriter'),  
  585. 'allowscriptaccess' => array('always', 'samedomain', 'never'),  
  586. 'allownetworking' => array('all', 'internal', 'none'),  
  587. 'seamlesstabbing' => array('true', 'false'),  
  588. 'allowfullscreen' => array('true', 'false'),  
  589. 'fullScreenAspectRatio' => array('portrait', 'landscape'),  
  590. 'base',  
  591. 'bgcolor',  
  592. 'flashvars' 
  593. ); 
  594.  
  595. $allowed_params_keys = array_keys( $allowed_params ); 
  596.  
  597. $filtered_params = array(); 
  598. foreach( $flash_params as $param=>$value ) { 
  599. if ( empty($param) || empty($value) ) 
  600. continue; 
  601. $param = strtolower($param); 
  602. if ( in_array($param, $allowed_params_keys) ) { 
  603. if ( isset( $allowed_params[$param] ) && is_array( $allowed_params[$param] ) ) { 
  604. $value = strtolower($value); 
  605. if ( in_array( $value, $allowed_params[$param] ) ) 
  606. $filtered_params[$param] = $value; 
  607. } else { 
  608. $filtered_params[$param] = $value; 
  609. unset( $allowed_params_keys ); 
  610.  
  611. /** 
  612. * Flash specifies sameDomain, not samedomain. change from lowercase value for preciseness 
  613. */ 
  614. if ( isset( $filtered_params['allowscriptaccess'] ) && $filtered_params['allowscriptaccess'] === 'samedomain' ) 
  615. $filtered_params['allowscriptaccess'] = 'sameDomain'; 
  616.  
  617. return $filtered_params; 
  618.  
  619. /** 
  620. * Filter Flash variables from the response, taking into consideration player options. 
  621. * @since 1.3 
  622. * @return array Flash variable key value pairs 
  623. */ 
  624. private function get_flash_variables() { 
  625. if ( ! isset( $this->video->players->swf->vars ) ) 
  626. return array(); 
  627.  
  628. $flashvars = (array) $this->video->players->swf->vars; 
  629. if ( isset( $this->options['autoplay'] ) && $this->options['autoplay'] === true ) 
  630. $flashvars['autoPlay'] = 'true'; 
  631. return $flashvars; 
  632.  
  633. /** 
  634. * Validate and filter Flash parameters 
  635. * @since 1.3 
  636. * @return array Flash parameters passed through key and value validation 
  637. */ 
  638. private function get_flash_parameters() { 
  639. if ( ! isset( $this->video->players->swf->params ) ) 
  640. return array(); 
  641. else 
  642. return self::esc_flash_params( 
  643. /** 
  644. * Filters the Flash parameters of the VideoPress player. 
  645. * @module videopress 
  646. * @since 1.2.0 
  647. * @param array $this->video->players->swf->params Array of swf parameters for the VideoPress flash player. 
  648. */ 
  649. apply_filters( 'video_flash_params', (array) $this->video->players->swf->params, 10, 1 ) 
  650. ); 
  651.  
  652. /** 
  653. * Flash player markup in a HTML embed element. 
  654. * @since 1.1 
  655. * @link http://www.whatwg.org/specs/web-apps/current-work/multipage/the-iframe-element.html#the-embed-element embed element 
  656. * @link http://www.google.com/support/reader/bin/answer.py?answer=70664 Google Reader markup support 
  657. * @return string HTML markup. Embed element with no children 
  658. */ 
  659. private function flash_embed() { 
  660. wp_enqueue_script( 'videopress' ); 
  661. if ( ! isset( $this->video->players->swf ) || ! isset( $this->video->players->swf->url ) ) 
  662. return ''; 
  663.  
  664. $embed = array( 
  665. 'id' => $this->video_id,  
  666. 'src' => esc_url_raw( $this->video->players->swf->url . '&' . http_build_query( $this->get_flash_variables(), null, '&' ) , array( 'http', 'https' ) ),  
  667. 'type' => 'application/x-shockwave-flash',  
  668. 'width' => $this->video->calculated_width,  
  669. 'height' => $this->video->calculated_height 
  670. ); 
  671. if ( isset( $this->video->title ) ) 
  672. $embed['title'] = $this->video->title; 
  673. $embed = array_merge( $embed, $this->get_flash_parameters() ); 
  674.  
  675. $html = '<embed'; 
  676. foreach ( $embed as $attribute => $value ) { 
  677. $html .= ' ' . esc_html( $attribute ) . '="' . esc_attr( $value ) . '"'; 
  678. unset( $embed ); 
  679. $html .= '></embed>'; 
  680. return $html; 
  681.  
  682. /** 
  683. * Double-baked Flash object markup for Internet Explorer and more standards-friendly consuming agents. 
  684. * @since 1.1 
  685. * @return HTML markup. Object and children. 
  686. */ 
  687. private function flash_object() { 
  688. wp_enqueue_script( 'videopress' ); 
  689. if ( ! isset( $this->video->players->swf ) || ! isset( $this->video->players->swf->url ) ) 
  690. return ''; 
  691.  
  692. $thumbnail_html = '<img alt="'; 
  693. if ( isset( $this->video->title ) ) 
  694. $thumbnail_html .= esc_attr( $this->video->title ); 
  695. $thumbnail_html .= '" src="' . esc_url( $this->video->poster_frame_uri, array( 'http', 'https' ) ) . '" width="' . $this->video->calculated_width . '" height="' . $this->video->calculated_height . '" />'; 
  696. $flash_vars = esc_attr( http_build_query( $this->get_flash_variables(), null, '&' ) ); 
  697. $flash_params = ''; 
  698. foreach ( $this->get_flash_parameters() as $attribute => $value ) { 
  699. $flash_params .= '<param name="' . esc_attr( $attribute ) . '" value="' . esc_attr( $value ) . '" />'; 
  700. $flash_help = sprintf( __( 'This video requires <a rel="nofollow" href="%s">Adobe Flash</a> for playback.', 'jetpack' ), 'http://www.adobe.com/go/getflashplayer'); 
  701. $flash_player_url = esc_url( $this->video->players->swf->url, array( 'http', 'https' ) ); 
  702. $description = ''; 
  703. if ( isset( $this->video->title ) ) { 
  704. $standby = $this->video->title; 
  705. $description = '<p><strong>' . esc_html( $this->video->title ) . '</strong></p>'; 
  706. } else { 
  707. $standby = __( 'Loading video...', 'jetpack' ); 
  708. $standby = ' standby="' . esc_attr( $standby ) . '"'; 
  709. return <<<OBJECT 
  710. <script type="text/javascript">if(typeof swfobject!=="undefined") {swfobject.registerObject("{$this->video_id}", "{$this->video->players->swf->version}");}</script> 
  711. <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="{$this->video->calculated_width}" height="{$this->video->calculated_height}" id="{$this->video_id}"{$standby}> 
  712. <param name="movie" value="{$flash_player_url}" /> 
  713. {$flash_params} 
  714. <param name="flashvars" value="{$flash_vars}" /> 
  715. <!--[if !IE]>--> 
  716. <object type="application/x-shockwave-flash" data="{$flash_player_url}" width="{$this->video->calculated_width}" height="{$this->video->calculated_height}"{$standby}> 
  717. {$flash_params} 
  718. <param name="flashvars" value="{$flash_vars}" /> 
  719. <!--<![endif]--> 
  720. {$thumbnail_html}{$description}<p class="robots-nocontent">{$flash_help}</p> 
  721. <!--[if !IE]>--> 
  722. </object> 
  723. <!--<![endif]--> 
  724. </object> 
  725. OBJECT;