PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 4.12.3
WpStream – Live Streaming, Video on Demand, Pay Per View v4.12.3
4.14.1 4.14.0 4.13.2 4.13.1 4.13 4.12.5 4.12.4 4.12.3 4.12.2 4.12.1 4.12 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5 4.5.1 4.5.11 4.5.11.1 4.5.11.2 4.5.11.4 4.5.11.5 4.5.11.6 All 181 releases
wpstream / includes / class-wpstream-player.php

class-wpstream-player.php in WpStream – Live Streaming, Video on Demand, Pay Per View 4.12.3, at includes/class-wpstream-player.php

2,003 lines 94.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * To change this license header, choose License Headers in Project Properties.
5 * To change this template file, choose Tools | Templates
6 * and open the template in the editor.
7 */
8
9
10 /**
11 * Description of class-wpstream-player
12 *
13 * @author cretu
14 */
15 class Wpstream_Player{
16 public $main;
17
18 /**
19 * @var Wpstream_Playback_Session
20 */
21 public $playback_session;
22
23 public function __construct($plugin_main) {
24 $this->main = $plugin_main;
25
26 require_once dirname( __FILE__ ) . '/player/class-wpstream-playback-session.php';
27 $this->playback_session = new Wpstream_Playback_Session();
28
29 add_filter( 'the_content',array($this, 'wpstream_filter_the_title') );
30 add_action( 'woocommerce_before_single_product', array($this,'wpstream_user_logged_in_product_already_bought') );
31
32 add_action( 'wp_ajax_wpstream_player_check_status', array($this,'wpstream_player_check_status') );
33 add_action('wp_ajax_nopriv_wpstream_player_check_status', array($this,'wpstream_player_check_status'));
34
35 }
36
37
38
39
40
41
42 /**
43 *
44 * edited 4.0
45 *
46 * check player status
47 *
48 * @author cretu
49 */
50
51 public function wpstream_player_check_status(){
52 // did not add a nonce check here because this is a call done from the frontend
53 // and the page might be cached, so the nonce would not be valid
54 $channel_id = intval($_POST['channel_id']);
55
56
57 $transient_name = 'event_data_to_return_'. $channel_id;
58 $event_data_for_transient = get_transient( $transient_name );
59
60
61 $usefull_info =' get cache from transiet';
62 if ( false === $event_data_for_transient || $event_data_for_transient=='' ) { //ws || $hls_to_return==''
63 $notes = 'wpstream_player_check_status_note_from_js';
64 $event_status = $this->main->wpstream_live_connection->wpstream_check_event_status_api_call($channel_id,$notes);
65 $event_data_for_transient = $event_status;
66 $usefull_info =' no cache found';
67 set_transient($transient_name,$event_data_for_transient,45);
68 }
69
70
71 if( isset($event_data_for_transient['hls_playback_url']) && $event_data_for_transient['hls_playback_url']!=''){
72 // cleanup any previous echo before sending json
73 ob_end_clean();
74 echo json_encode( array(
75
76 'started' => 'yes',
77 'usefull_info' => $usefull_info,
78 'channel_id' => $channel_id,
79 'event_uri' => $event_data_for_transient['hls_playback_url'],
80 'live_conect_views' => $event_data_for_transient['stats_url'],
81 'chat_url' => $event_data_for_transient['chat_url'],
82 '$event_data_for_transient'=>$event_data_for_transient
83
84
85 ));
86 $usedfull_info =' ';
87 update_post_meta($channel_id,'stream_name',$event_data_for_transient['stream_name']);
88 update_post_meta($channel_id,'hls_key_retrieval_url',$event_data_for_transient['hls_key_retrieval_url']);
89 delete_transient( 'free_event_streamName_'.$event_data_for_transient['stream_name']);
90
91 }else{
92 // cleanup any previous echo before sending json
93 ob_end_clean();
94 echo json_encode( array(
95 'started' => 'no',
96 'usefull_info' => $usefull_info,
97 'server_id' => '',
98 'channel_id' => $channel_id,
99 'event_uri' => '',
100 'live_conect_views' => '',
101 'chat_url' => '',
102
103
104 ));
105
106 }
107
108 die();
109 }
110
111
112
113 /**
114 * Insert player in page
115 *
116 * @author cretu
117 */
118 public function wpstream_filter_the_title( $content ) {
119 if(function_exists('wpstream_remove_wpstream_filter')){
120 return $content;
121 }
122
123 if( is_singular('wpstream_product') || is_singular('wpstream_product_vod') ){
124 global $post;
125 $args=array('id'=>$post->ID);
126 $custom_content = $this->wpstream_insert_player_inpage($args);
127 $content = '<div class="wpestream_inserted_player">'.$custom_content.'</div>'.$content;
128 return $content;
129 }else{
130 return $content;
131 }
132 }
133
134 /**
135 * Insert player in page
136 *
137 * @author cretu
138 */
139
140 public function wpstream_insert_player_inpage($attributes, $content = null){
141 $product_id = '';
142 $return_string = '';
143 $attributes = shortcode_atts(
144 array(
145 'id' => 0,
146 ), $attributes) ;
147
148
149 if ( isset($attributes['id']) ){
150 $product_id=$attributes['id'];
151 }
152
153 if(intval($product_id)==0){
154 $product_id= $this->wpstream_player_retrive_first_id();
155 }
156
157 ob_start();
158
159 $this->wpstream_video_player_shortcode($product_id);
160 $return_string= ob_get_contents();
161 ob_end_clean();
162
163 return $return_string;
164 }
165
166
167
168
169 /**
170 * Video Player shortcode
171 *
172 * @author cretu
173 */
174
175 public function wpstream_video_player_shortcode($from_sh_id='') {
176 // disable cache in order to be able to check the nonce
177 if ( !defined( 'DONOTCACHEPAGE' ) ) {
178 define( 'DONOTCACHEPAGE', true );
179 }
180
181 wp_enqueue_script('video.min');
182 wp_enqueue_script('wpstream-player');
183
184 if ( is_user_logged_in() ) {
185 global $product;
186 $current_user = wp_get_current_user();
187 $product_id = intval($from_sh_id);
188 $term_list = wp_get_post_terms($product_id, 'product_type');
189 $possible_bundle = get_post_meta($product_id, 'wpstream_part_of_bundle', true);
190
191
192
193
194 if (
195
196 ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) && wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id) ) ||
197 ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) && (intval($possible_bundle)!=0) && wc_customer_bought_product( $current_user->user_email, $current_user->ID, $possible_bundle) ) ||
198 get_post_type($product_id)=='wpstream_product' ||
199 get_post_type($product_id)=='wpstream_product_vod' ){
200 global $product;
201 echo '<div class="wpstream_player_wrapper wpstream_player_shortcode"><div class="wpstream_player_container">';
202
203
204 if( get_post_type($product_id) == 'wpstream_product' ){
205 $this->wpstream_live_event_player($product_id);
206 }else if( get_post_type($product_id) == 'wpstream_product_vod' ){
207 $this->wpstream_video_on_demand_player($product_id);
208 }else{
209
210 $is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true));
211
212 if( $term_list[0]->name=='live_stream' || ( $term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){
213 $this->wpstream_live_event_player($product_id);
214 }else if( $term_list[0]->name=='video_on_demand' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='no' ) ){
215 $this->wpstream_video_on_demand_player($product_id);
216 }
217 }
218
219
220 echo '</div></div>';
221 }else{
222
223 if( get_post_type($product_id) == 'product' ){
224 echo '<div class="wpstream_player_wrapper wpstream_player_shortcode no_buy"><div class="wpstream_player_container">';
225 $message =esc_html( get_option('wpstream_product_not_bought','You did not yet purchase this item.')) ;
226 echo '<div class="wpstream_notice" style="background:#e16767;">'.esc_html($message).'</div>';
227 echo '</div></div>';
228 }
229 }
230
231
232 }else{
233
234 $product_id = intval($from_sh_id);
235 $term_list = wp_get_post_terms($product_id, 'product_type');
236
237 if( get_post_type($product_id) == 'product' && ($term_list[0]->name=='live_stream' || $term_list[0]->name=='video_on_demand') ){
238
239 echo '<div class="wpstream_player_wrapper wpstream_player_shortcode no_buy"><div class="wpstream_player_container">';
240 $message= esc_html( get_option('wpstream_product_not_login','You must be logged in to watch this video.')) ;
241
242
243 echo '<div class="wpstream_notice" style="background:#e16767;">'.esc_html($message).'</div>';
244 echo '</div></div>';
245 }elseif( get_post_type($product_id) == 'wpstream_product' ){
246 echo '<div class="wpstream_player_wrapper wpstream_player_shortcode"><div class="wpstream_player_container">';
247 $this->wpstream_live_event_player($product_id);
248 echo '</div></div>';
249 } else if( get_post_type($product_id) == 'wpstream_product_vod' ){
250 echo '<div class="wpstream_player_wrapper wpstream_player_shortcode"><div class="wpstream_player_container">';
251 $this->wpstream_video_on_demand_player($product_id);
252 echo '</div></div>';
253 }
254 }
255 }
256
257
258
259 /**
260 * Video Player shortcode - low latency
261 *
262 * @author cretu
263 */
264
265 public function wpstream_video_player_shortcode_low_latency($from_sh_id='') {
266 if ( !defined( 'DONOTCACHEPAGE' ) ) {
267 define( 'DONOTCACHEPAGE', true );
268 }
269
270 wp_enqueue_script('video.min');
271 wp_enqueue_script('wpstream-player');
272
273
274 if ( is_user_logged_in() ) {
275 global $product;
276 $current_user = wp_get_current_user();
277 $product_id = intval($from_sh_id);
278
279
280 if ( ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) && wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id) ) || get_post_type($product_id)=='wpstream_product' ){
281 global $product;
282 echo '<div class="wpstream_player_wrapper wpstream_player_shortcode"><div class="wpstream_player_container">';
283
284
285 if( get_post_type($product_id) == 'wpstream_product' ){
286 $this->wpstream_live_event_player_low_latency($product_id);
287 }else{
288 $term_list = wp_get_post_terms($product_id, 'product_type');
289 $is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true));
290
291 if( $term_list[0]->name=='live_stream' || ( $term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){
292 $this->wpstream_live_event_player_low_latency($product_id);
293 }
294 }
295
296
297 echo '</div></div>';
298 }else{
299
300 if( get_post_type($product_id) == 'product' ){
301 echo '<div class="wpstream_player_wrapper wpstream_player_shortcode no_buy"><div class="wpstream_player_container">';
302
303 $message =esc_html( get_option('wpstream_product_not_bought','You did not yet purchase this item.')) ;
304 echo '<div class="wpstream_notice" style="background:#e16767;">'.$message.'</div>';
305 echo '</div></div>';
306 }
307 }
308
309
310 }else{
311 $product_id = intval($from_sh_id);
312 if( get_post_type($product_id) == 'wpstream_product' ){
313 $this->wpstream_live_event_player_low_latency($product_id);
314 }
315 }
316 }
317
318
319
320
321
322 /**
323 * Live Event Player
324 *
325 * @author cretu
326 */
327 function remove_http($url) {
328 $disallowed = array('http://', 'https://');
329 foreach($disallowed as $d) {
330 if(strpos($url, $d) === 0) {
331 return str_replace($d, '', $url);
332 }
333 }
334 return $url;
335 }
336
337 /**
338 * Site origin (scheme://host:port) for the new player `embedAncestor` query param.
339 * The player includes this value in the embed-key hash; mint keys with the same string.
340 *
341 * @return string
342 */
343 private function wpstream_get_site_origin_for_embed() {
344 $parts = wp_parse_url( home_url() );
345 if ( empty( $parts['host'] ) ) {
346 return '';
347 }
348 $scheme = isset( $parts['scheme'] ) ? $parts['scheme'] . '://' : 'https://';
349 $host = $parts['host'];
350 $port = isset( $parts['port'] ) ? ':' . $parts['port'] : '';
351 return $scheme . $host . $port;
352 }
353
354 /**
355 * Keep this in sync with player/src/config/env.js fallback.
356 *
357 * @return string
358 */
359 private function wpstream_get_player_embed_key_salt() {
360 $default_salt = 'EYjb84vNTXE85TfR';
361 $configured = trim( (string) get_option( 'wpstream_player_embed_key_salt', '' ) );
362 $base_salt = '' !== $configured ? $configured : $default_salt;
363
364 return (string) apply_filters( 'wpstream_player_embed_key_salt', $base_salt );
365 }
366
367 /**
368 * Masked salt metadata for debugging embed-key mismatches.
369 *
370 * @return array<string,mixed>
371 */
372 private function wpstream_get_player_embed_key_salt_debug_meta() {
373 $default_salt = 'EYjb84vNTXE85TfR';
374 $configured = trim( (string) get_option( 'wpstream_player_embed_key_salt', '' ) );
375 $base_salt = '' !== $configured ? $configured : $default_salt;
376 $final_salt = (string) apply_filters( 'wpstream_player_embed_key_salt', $base_salt );
377 $len = strlen( $final_salt );
378 $prefix = $len > 0 ? substr( $final_salt, 0, min( 2, $len ) ) : '';
379 $suffix = $len > 2 ? substr( $final_salt, -2 ) : '';
380
381 return array(
382 'source' => '' !== $configured ? 'option_or_filter' : 'default_or_filter',
383 'length' => $len,
384 'sha256_12' => substr( hash( 'sha256', $final_salt ), 0, 12 ),
385 'maskedPreview' => $prefix . ( $len > 0 ? '***' : '' ) . $suffix,
386 );
387 }
388
389 /**
390 * Mirror player/src/security/embed-key.js hash generation.
391 *
392 * @param string $video Media path used by /player/vod?video=...
393 * @param string $validate_playback_session_url Optional session verify URL.
394 * @param string $embed_ancestor Optional frame ancestor origin.
395 * @param string $encrypt_raw Optional encrypt toggle (yes/true/1).
396 * @return string
397 */
398 private function wpstream_generate_player_embed_key( $video, $validate_playback_session_url = '', $embed_ancestor = '', $encrypt_raw = '' ) {
399 $video = trim( (string) $video );
400 if ( '' === $video ) {
401 return '';
402 }
403
404 $hash_input = $video . ' ' . $this->wpstream_get_player_embed_key_salt();
405 $validate_playback_session_url = trim( (string) $validate_playback_session_url );
406 if ( '' !== $validate_playback_session_url ) {
407 $hash_input = $validate_playback_session_url . ' ' . $hash_input;
408 }
409
410 $embed_ancestor = trim( (string) $embed_ancestor );
411 if ( '' !== $embed_ancestor ) {
412 $hash_input = $embed_ancestor . ' ' . $hash_input;
413 }
414
415 $encrypt_raw = strtolower( trim( (string) $encrypt_raw ) );
416 if ( in_array( $encrypt_raw, array( 'yes', 'true', '1' ), true ) ) {
417 $hash_input = 'crypt ' . $hash_input;
418 }
419
420 $binary_hash = md5( $hash_input, true );
421 $base64 = base64_encode( $binary_hash );
422
423 return rtrim( strtr( $base64, '+/', '-_' ), '=' );
424 }
425
426 function wpstream_get_live_connect_uri($event_status, $playback_url_key = 'hls_playback_url') {
427 if (isset($event_status['stats_url']) && trim($event_status['stats_url']) !== '') {
428 return trim($event_status['stats_url']);
429 }
430
431 if (
432 isset($event_status[$playback_url_key]) &&
433 trim($event_status[$playback_url_key]) !== '' &&
434 strpos($event_status[$playback_url_key], 'live.streamer.wpstream.net') !== false
435 ) {
436 $live_conect_array = explode('live.streamer.wpstream.net', $event_status[$playback_url_key]);
437 return $this->remove_http($live_conect_array[0] . 'live.streamer.wpstream.net');
438 }
439
440 return '';
441 }
442
443 /**
444 * Get event settings
445 *
446 * @author cretu
447 */
448
449 function wpestream_return_event_settings($product_id){
450
451 $local_event_options = get_post_meta( $product_id, 'local_event_options', true);
452 $use_global_event_options = get_post_meta($product_id, 'use_global_event_options',true);
453 $is_local_event_options_enabled = isset( $local_event_options ) &&
454 ( ! isset( $use_global_event_options ) || (int) $use_global_event_options === 0 );
455
456 if( !$is_local_event_options_enabled ) {
457 $local_event_options = get_option('wpstream_user_streaming_global_channel_options') ;
458 }
459
460 return $local_event_options;
461 }
462
463
464
465 /**
466 * edited in 4.0
467 *
468 * Live Event Player
469 *
470 * @author cretu
471 */
472
473 function wpstream_live_event_player($channel_id,$poster_show='',$use_chat=''){
474 wp_enqueue_script('video.min');
475 wp_enqueue_script('wpstream-player');
476 wp_enqueue_script( 'wpstream-player-controls' );
477
478 wp_localize_script(
479 'wpstream-player-controls',
480 'wpstreamLiveUiConfig',
481 array(
482 'wpstream_player_state_stopped_msg' => esc_html(
483 get_option(
484 'wpstream_you_are_not_live',
485 __( 'We are not live at this moment', 'wpstream' )
486 ),
487 ),
488 'wpstream_player_state_init_msg' => esc_html__( 'The live stream has not yet started', 'wpstream' ),
489 'wpstream_player_state_startup_msg' => esc_html__( 'The live stream is starting...', 'wpstream' ),
490 'wpstream_player_state_paused_msg' => esc_html__( 'The live stream is paused', 'wpstream' ),
491 'wpstream_player_state_ended_msg' => esc_html__( 'The live stream has ended', 'wpstream' ),
492 'wpstream_player_state_error_msg' => esc_html__( 'Something went wrong', 'wpstream' ),
493 'isThemeActive' => get_template() === 'hello-wpstream',
494 )
495 );
496
497 $player_theme = $this->wpstream_get_player_theme( $channel_id );
498 $now = time().rand(0,1000000);
499 $overlay_video_div_id = "random_id_".$now;
500 // print '<div id="'.esc_attr($overlay_video_div_id).'" class="vjs-title-overlay wpstream-video-title-overlay">'.esc_html__('Playing:','wpstream').' '.get_the_title($channel_id).'</div>';
501
502
503 $thumb_id = get_post_thumbnail_id($channel_id);
504 $thumb = wp_get_attachment_image_src($thumb_id,'small');
505 $usernamestream = esc_html ( get_option('wpstream_api_username','') );
506 $autoplay = true;
507
508 $event_settings = $this->wpestream_return_event_settings($channel_id);
509
510 $transient_name = 'event_data_to_return_'. $channel_id;
511 $event_status = get_transient( $transient_name );
512
513 if ( false === $event_status || $event_status=='' ) {
514 $notes = 'wpstream_live_event_player_note';
515 $event_status = $this->main->wpstream_live_connection-> wpstream_check_event_status_api_call($channel_id,$notes);
516 set_transient($transient_name, $event_status, 45);
517 }
518
519 $hls_playback_url = '';
520 $live_conect_views = '';
521
522 if(isset($event_status['status']) && $event_status['status']=='active'){
523 //live event
524 if(isset($event_status['hls_playback_url'])){
525 $hls_playback_url = $event_status['hls_playback_url'];
526
527 update_post_meta($channel_id,'stream_name',$event_status['stream_name']);
528 update_post_meta($channel_id,'hls_key_retrieval_url',$event_status['hls_key_retrieval_url']);
529 delete_transient( 'free_event_streamName_'.$event_status['stream_name']);
530
531 }
532 $live_conect_views = $this->wpstream_get_live_connect_uri($event_status, 'hls_playback_url');
533 if(isset($event_status['chat_url'])){
534 $chat_url = $event_status['chat_url'];
535 }
536
537 }else{
538 // event not live
539 }
540
541 $trailer_attachment_id = intval( get_post_meta( $channel_id, 'video_trailer', true ) );
542 $video_trailer = '';
543 $has_trailer_class = '';
544 if ( $trailer_attachment_id != 0 ) {
545 $video_trailer = wp_get_attachment_url( $trailer_attachment_id );
546 $attachment_metadata = wp_get_attachment_metadata( $trailer_attachment_id );
547 if ( isset ( $attachment_metadata['mime_type'] ) ) {
548 $video_trailer_type = $attachment_metadata['mime_type'];
549 }
550 $poster_data = ''; // cancel poster for theme
551 $has_trailer_class = 'wpstream_theme_player_has_trailer';
552 }
553
554 if(isset($event_settings['autoplay']) && intval($event_settings['autoplay'])==0){
555 $autoplay=false;
556 }
557
558 $bootstrap_is_muted = ( isset( $event_settings['mute'] ) && intval( $event_settings['mute'] ) === 1 );
559 $bootstrap_trailer_attachment_id = intval( get_post_meta( $channel_id, 'video_trailer', true ) );
560 $bootstrap_trailer_url = '';
561 if ( $bootstrap_trailer_attachment_id !== 0 ) {
562 $bootstrap_trailer_url = wp_get_attachment_url( $bootstrap_trailer_attachment_id );
563 }
564 $live_content_uri = isset( $hls_playback_url ) ? trim( $hls_playback_url ) : '';
565 $live_stats_uri = isset( $live_conect_views ) ? trim( $live_conect_views ) : '';
566 $live_chat_uri = isset( $chat_url ) ? trim( $chat_url ) : '';
567 $play_trailer_button_element_id = 'wpstream_live_video_play_trailer_btn_' . $now;
568 $mute_trailer_button_element_id = 'wpstream_live_video_mute_trailer_btn_' . $now;
569 $unmute_trailer_button_element_id = 'wpstream_live_video_unmute_trailer_btn_' . $now;
570
571
572
573 $player_nonce = wp_create_nonce( 'wpstream_player_check_status_nonce' );
574
575 $live_channel_embed_url = get_post_meta( $channel_id, 'embedUrl', true );
576
577 // if embedUrl is set, we are using the new player
578 if ( !$live_channel_embed_url ) {
579 echo '<div class="wpstream_live_player_wrapper function_wpstream_live_event_player" data-now="' . $now . '" data-me="' . esc_attr( $usernamestream ) . '" data-product-id="' . $channel_id . '" id="wpstream_live_player_wrapper' . $now . '" data-nonce="' . $player_nonce . '" data-wpstream-bootstrap="live" data-instance-id="wpstream-live-' . esc_attr( $now ) . '" data-video-element-id="' . esc_attr( $now ) . '" data-title-overlay-element-id="' . esc_attr( $overlay_video_div_id ) . '" data-content-url="' . esc_attr( $live_content_uri ) . '" data-stats-uri="' . esc_attr( $live_stats_uri ) . '" data-chat-url="' . esc_attr( $live_chat_uri ) . '" data-trailer-url="' . esc_attr( $bootstrap_trailer_url ) . '" data-autoplay="' . ( $autoplay ? '1' : '0' ) . '" data-muted="' . ( $bootstrap_is_muted ? '1' : '0' ) . '" data-play-trailer-button-element-id="' . esc_attr( $play_trailer_button_element_id ) . '" data-mute-trailer-button-element-id="' . esc_attr( $mute_trailer_button_element_id ) . '" data-unmute-trailer-button-element-id="' . esc_attr( $unmute_trailer_button_element_id ) . '" > ';
580
581 $show_viewer_count = (
582 ( isset( $event_settings['view_count'] ) && intval( $event_settings['view_count'] ) == 1 )
583 || ! isset( $event_settings['view_count'] )
584 );
585
586 echo '<div id="wpestream_live_counting" class="wpestream_live_counting" data-showviewercount="' . ( $show_viewer_count ? '1' : '0' ) . '"></div>';
587
588 $show_wpstream_not_live_mess = ' style="display:none;" ';
589 if ( trim( $hls_playback_url ) == '' ) {
590
591 $show_wpstream_not_live_mess = '';
592 }
593
594 $message_show = esc_html( get_option( 'wpstream_you_are_not_live', 'We are not live at this moment' ) );
595
596 if ( function_exists( 'wpstream_theme_not_live_section' ) ) {
597 print wpstream_theme_not_live_section( $channel_id );
598 } else {
599 print '<div class="wpstream_not_live_mess" ' . $show_wpstream_not_live_mess . ' style="display: none">
600 <div class="wpstream_not_live_mess_back"></div>
601 <div class="wpstream_not_live_mess_mess">' . esc_html( $message_show ) . '</div>
602 </div>';
603 }
604
605
606 $poster_data = '';
607 if ( isset( $thumb[0] ) ) {
608 $poster_data = ' poster="' . $thumb[0] . '" ';
609 }
610 if ( $poster_show == 'no' ) {
611 $poster_data = '';
612 }
613
614 $is_muted = false;
615 if ( isset( $event_settings['mute'] ) && intval( $event_settings['mute'] ) == 1 ) {
616 $is_muted = true;
617 }
618 // override $is_muted and $autoplay here - for testing
619 // $autoplay = true;
620 // $is_muted = false;
621
622 $autoplay_str = $autoplay ? 'autoplay' : '';
623 $is_muted_str = $is_muted ? 'muted' : '';
624
625 // override trailer url here - for testing
626 // $video_trailer = '';
627 // $video_trailer = '/wp-content/uploads/2023/10/production-ID_4608975.mp4';
628 // $video_trailer = '/wp-content/uploads/2023/10/ultrawide.mp4';
629
630
631 $player_logo_position_data = $this->wpstream_get_player_logo_data( $channel_id );
632 $player_logo_position = $player_logo_position_data['player_logo_position'];
633 $player_logo_position_class = $player_logo_position_data['player_logo_position_class'];
634 $player_logo_horizontal_position = $player_logo_position_data['player_logo_horizontal_position'];
635 // echo'
636 // <div class="wpstream-video-container">
637 // <div id="wpstream-pre-load-spinner" class="wpstream-pre-load-spinner"></div>
638 // <video id="wpstream-video'.$now.'" '.$poster_data.' class="video-js vjs-default-skin vjs-fluid vjs-wpstream ' . esc_attr($has_trailer_class) . ' ' . $player_theme . ' ' . $player_logo_position_class . ' ' . $player_logo_horizontal_position . '" playsinline="true" '.$is_muted_str." ".$autoplay_str.'>
639 // </video>
640 // </div>';
641 echo '<div class="wpstream-pre-load-spinner"></div>';
642 echo '
643 <video id="wpstream-video' . $now . '" ' . $poster_data . ' class="video-js vjs-default-skin vjs-fluid vjs-wpstream ' . esc_attr( $has_trailer_class ) . ' ' . $player_theme . ' ' . $player_logo_position_class . ' ' . $player_logo_horizontal_position . '" playsinline="true" ' . $is_muted_str . " " . $autoplay_str . '>
644
645 </video>';
646 if ( $video_trailer ) {
647 print '<div class="wpstream_theme_trailer_wrapper">';
648 print '<div id="' . esc_attr( $play_trailer_button_element_id ) . '" style="display: none;" class="wpstream_video_on_demand_play_trailer">
649 <svg width="30" height="24" viewBox="0 0 30 24" fill="none" xmlns="http://www.w3.org/2000/svg">
650 <path fill-rule="evenodd" clip-rule="evenodd" d="M26.6667 1.5H3.33337C2.50495 1.5 1.83337 2.17157 1.83337 3V21C1.83337 21.8284 2.50495 22.5 3.33338 22.5H26.6667C27.4951 22.5 28.1667 21.8284 28.1667 21V3C28.1667 2.17157 27.4951 1.5 26.6667 1.5ZM3.33337 0C1.67652 0 0.333374 1.34315 0.333374 3V21C0.333374 22.6569 1.67652 24 3.33338 24H26.6667C28.3236 24 29.6667 22.6569 29.6667 21V3C29.6667 1.34315 28.3236 0 26.6667 0H3.33337ZM4.83337 4C4.55723 4 4.33337 4.22386 4.33337 4.5V6.16667C4.33337 6.44281 4.55723 6.66667 4.83337 6.66667H6.50004C6.77618 6.66667 7.00004 6.44281 7.00004 6.16667V4.5C7.00004 4.22386 6.77618 4 6.50004 4H4.83337ZM23.5 4C23.2239 4 23 4.22386 23 4.5V6.16667C23 6.44281 23.2239 6.66667 23.5 6.66667H25.1667C25.4428 6.66667 25.6667 6.44281 25.6667 6.16667V4.5C25.6667 4.22386 25.4428 4 25.1667 4H23.5ZM4.33337 11.167C4.33337 10.8909 4.55723 10.667 4.83337 10.667H6.50004C6.77618 10.667 7.00004 10.8909 7.00004 11.167V12.8337C7.00004 13.1098 6.77618 13.3337 6.50004 13.3337H4.83337C4.55723 13.3337 4.33337 13.1098 4.33337 12.8337V11.167ZM23.5001 10.667C23.224 10.667 23.0001 10.8909 23.0001 11.167V12.8337C23.0001 13.1098 23.224 13.3337 23.5001 13.3337H25.1668C25.4429 13.3337 25.6668 13.1098 25.6668 12.8337V11.167C25.6668 10.8909 25.4429 10.667 25.1668 10.667H23.5001ZM4.33337 17.833C4.33337 17.5569 4.55723 17.333 4.83337 17.333H6.50004C6.77618 17.333 7.00004 17.5569 7.00004 17.833V19.4997C7.00004 19.7758 6.77618 19.9997 6.50004 19.9997H4.83337C4.55723 19.9997 4.33337 19.7758 4.33337 19.4997V17.833ZM23.5001 17.333C23.224 17.333 23.0001 17.5569 23.0001 17.833V19.4997C23.0001 19.7758 23.224 19.9997 23.5001 19.9997H25.1668C25.4429 19.9997 25.6668 19.7758 25.6668 19.4997V17.833C25.6668 17.5569 25.4429 17.333 25.1668 17.333H23.5001ZM19.0677 13.0997L13.4077 16.5087C13.0434 16.7281 12.6092 16.7094 12.2661 16.5091C11.9218 16.3081 11.6666 15.9224 11.6666 15.4086V8.59072C11.6666 8.07698 11.9218 7.69125 12.2661 7.49026C12.6092 7.28999 13.0434 7.27126 13.4077 7.49064L19.0677 10.8996C19.8663 11.3805 19.8663 12.6188 19.0677 13.0997Z"/>
651 </svg>
652 ' . esc_html__( 'Play Trailer', 'wpstream' ) . '</div>';
653 print '<div id="' . esc_attr( $mute_trailer_button_element_id ) . '" style="display: none;" class="wpstream_video_on_demand_mute_trailer">
654 <svg width="37" height="36" viewBox="0 0 37 36" fill="none" xmlns="http://www.w3.org/2000/svg">
655 <path fill-rule="evenodd" clip-rule="evenodd" d="M1.32143 10.0789H8.69499L18.8964 0L21.1428 0.921053V35.1316L18.8964 36L8.69499 25.8684H1.32143L0 24.5526V11.3947L1.32143 10.0789ZM10.175 23.6842L18.5 31.9474V4.10526L10.175 12.3158L9.24999 12.7105H2.64286V23.2368H9.24999L10.175 23.6842ZM37 17.9737C37.0069 22.2216 35.5329 26.3401 32.8295 29.6263L30.9478 27.7579C33.1613 24.9734 34.3629 21.5249 34.3571 17.9737C34.3571 14.2895 33.0885 10.8974 30.9637 8.21053L32.8454 6.34211C35.5382 9.62494 37.0062 13.735 37 17.9737ZM31.7143 17.9737C31.7193 20.8255 30.7895 23.6011 29.0661 25.8789L27.1738 23.9947C28.4127 22.2295 29.0752 20.1272 29.0714 17.9737C29.0751 15.8287 28.4174 13.7344 27.1871 11.9737L29.0793 10.0895C30.7338 12.2868 31.7143 15.0158 31.7143 17.9737ZM26.4286 17.9737C26.4286 19.4842 26.0057 20.8947 25.2657 22.0947L23.3126 20.1526C23.6249 19.4729 23.7876 18.7345 23.7899 17.9869C23.7922 17.2394 23.634 16.5001 23.3258 15.8184L25.2789 13.8737C26.0083 15.0684 26.4286 16.4737 26.4286 17.9737Z" fill="white"/>
656 </svg>
657
658 </div>';
659 print '<div id="' . esc_attr( $unmute_trailer_button_element_id ) . '" style="display: none;" class="wpstream_video_on_demand_unmute_trailer">
660 <svg width="33" height="32" viewBox="0 0 33 32" fill="none" xmlns="http://www.w3.org/2000/svg">
661 <path fill-rule="evenodd" clip-rule="evenodd" d="M1.15625 8.85688H7.60813L16.5344 0L18.5 0.809375V30.8719L16.5344 31.635L7.60813 22.7319H1.15625L0 21.5756V10.0131L1.15625 8.85688ZM8.90313 20.8125L16.1875 28.0738V3.6075L8.90313 10.8225L8.09375 11.1694H2.3125V20.4194H8.09375L8.90313 20.8125ZM30.5967 11.3127L32.2316 12.9477L28.2287 16.9506L32.2316 20.9559L30.5967 22.5908L26.5938 18.5856L22.5885 22.5908L20.9536 20.9559L24.9588 16.9506L20.9513 12.95L22.5862 11.3151L26.5938 15.3157L30.5967 11.3127Z" fill="white"/>
662 </svg>
663 </div>';
664 print '</div>';
665 }
666 print '</div>';
667
668
669 // Live player bootstrap is handled by wpstream-player-bootstrap.js.
670
671
672 if ( $use_chat == "yes" ) {
673 $this->wpstream_connect_to_chat( $channel_id );
674 }
675
676 usleep( 10000 );
677 } else {
678 $live_channel_frame_base = WPSTREAM_PLAYER . "/player/live?";
679 $live_channel_id = get_post_meta( $channel_id, 'channelId', true );
680
681 $local_event_options = get_option( 'wpstream_user_streaming_global_channel_options' );
682 $wpstream_session_encryption = false;
683 $wpstream_live_channel_lock_to_website = false;
684 $wpstream_live_channel_autoplay = false;
685
686 if ( isset( $local_event_options['ses_encrypt'] ) && intval( $local_event_options['ses_encrypt'] ) == 1 ) {
687 $wpstream_session_encryption = true;
688 }
689 if ( isset( $local_event_options['domain_lock'] ) && intval( $local_event_options['domain_lock'] ) == 1 ) {
690 $wpstream_live_channel_lock_to_website = true;
691 }
692 if ( isset( $local_event_options['autoplay'] ) && intval( $local_event_options['autoplay'] ) == 1 ) {
693 $wpstream_live_channel_autoplay = true;
694 }
695
696 $wpstream_live_channel_validate_url = '';
697 if ( $wpstream_session_encryption ) {
698 $wpstream_live_channel_validate_url = esc_url_raw(
699 apply_filters(
700 'wpstream_live_channel_validate_playback_session_url',
701 $this->playback_session->wpstream_get_default_validate_playback_session_url(),
702 $live_channel_id
703 )
704 );
705 wp_localize_script(
706 'wpstream-player-controls',
707 'wpstreamLiveIframeSessionApi',
708 array(
709 'requirePlaybackSession' => true,
710 'nonce' => wp_create_nonce( 'wpstream_playback_session_issue' ),
711 'productId' => (int) $channel_id,
712 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
713 )
714 );
715 }
716
717 $local_event_options = get_option( 'wpstream_user_streaming_global_channel_options' );
718 $wpstream_live_channel_lock_to_website = 0;
719 $wpstream_live_channel_encrypt = 0;
720 $wpstream_live_channel_abr = 0;
721 $wpstream_live_channel_muted = 0;
722
723 if ( isset( $local_event_options['domain_lock'] ) && intval( $local_event_options['domain_lock'] ) == 1 ) {
724 $wpstream_live_channel_lock_to_website = 1;
725 }
726 if ( isset( $local_event_options['encrypt'] ) && intval( $local_event_options['encrypt'] ) == 1 ) {
727 $wpstream_live_channel_encrypt = 1;
728 }
729 if ( isset( $local_event_options['adaptive_bitrate'] ) && intval( $local_event_options['adaptive_bitrate'] ) == 1 ) {
730 $wpstream_live_channel_abr = 1;
731 }
732 if ( isset( $local_event_options['mute'] ) && intval( $local_event_options['mute'] ) == 1 ) {
733 $wpstream_live_channel_muted = 1;
734 }
735
736 $live_channel_embed_ancestor = '';
737 if ( $wpstream_live_channel_lock_to_website ) {
738 $live_channel_embed_ancestor = esc_url_raw(
739 apply_filters(
740 'wpstream_live_channel_embed_ancestor',
741 $this->wpstream_get_site_origin_for_embed(),
742 $live_channel_id
743 )
744 );
745 }
746
747 $wpstream_live_channel_embed_key = $this->wpstream_generate_player_embed_key(
748 $live_channel_id,
749 $wpstream_live_channel_validate_url,
750 $live_channel_embed_ancestor,
751 $wpstream_live_channel_encrypt ? 'yes' : ''
752 );
753 if ( '' === $wpstream_live_channel_embed_key ) {
754 $wpstream_live_channel_embed_key = (string) get_post_meta( $channel_id, 'embed_key', true );
755 }
756 $wpstream_live_channel_trailer_embed_key = $this->wpstream_generate_player_embed_key(
757 $video_trailer,
758 $wpstream_live_channel_validate_url,
759 $live_channel_embed_ancestor,
760 $wpstream_live_channel_encrypt ? 'yes' : ''
761 );
762
763 $wpstream_player_iframe_skin_slug = '';
764 if ( preg_match( '/^vjs-theme-(city|fantasy|forest|sea)$/', $player_theme, $vod_iframe_skin_m ) ) {
765 $wpstream_player_iframe_skin_slug = $vod_iframe_skin_m[1];
766 }
767 $wpstream_show_viewer_count = (
768 ( isset( $event_settings['view_count'] ) && intval( $event_settings['view_count'] ) == 1 )
769 || ! isset( $event_settings['view_count'] )
770 );
771
772 $wpstream_poster_image = get_the_post_thumbnail_url( $channel_id, 'full' );
773
774 $wpstream_player_logo_data = $this->wpstream_get_player_logo_data( $channel_id );
775 $wpstream_player_logo_image = $wpstream_player_logo_data['player_logo_src'];
776
777 $live_channel_query_args = array_filter(
778 array(
779 'channel' => $live_channel_id,
780 'posterImage' => $wpstream_poster_image,
781 'embedKey' => $wpstream_live_channel_embed_key,
782 'autoplay' => $wpstream_live_channel_autoplay ? true : '',
783 'startMuted' => (bool) $wpstream_live_channel_muted,
784 'viewerCountBadge' => $wpstream_show_viewer_count ? true : '',
785 'encrypt' => $wpstream_live_channel_encrypt ? true : '',
786 'abr' => $wpstream_live_channel_abr ? true : '',
787 'validatePlaybackSessionUrl' => $wpstream_live_channel_validate_url,
788 'embedAncestor' => $live_channel_embed_ancestor,
789 'skin' => $wpstream_player_iframe_skin_slug,
790 'logoImage' => $wpstream_player_logo_image,
791 'logoPosition' => $wpstream_player_logo_image ? $wpstream_player_logo_data['player_logo_position'] : '',
792 'logoOpacity' => $wpstream_player_logo_image ? $wpstream_player_logo_data['player_logo_opacity'] : '',
793 'isThemeActive' => get_template() == 'hello-wpstream',
794 ),
795 static function ( $v ) {
796 return $v !== null && $v !== '';
797 }
798 );
799
800 $live_channel_trailer_iframe_query_args = array_filter(
801 array(
802 'video' => $video_trailer,
803 'embedKey' => $wpstream_live_channel_trailer_embed_key,
804 'skin' => $wpstream_player_iframe_skin_slug,
805 'startMuted' => (bool) $wpstream_live_channel_muted,
806 'encrypt' => $wpstream_live_channel_encrypt ? true : '',
807 'validatePlaybackSessionUrl' => $wpstream_live_channel_validate_url,
808 'embedAncestor' => $live_channel_embed_ancestor,
809 ),
810 static function ( $v ) {
811 return $v !== null && $v !== '';
812 }
813 );
814
815 echo '<div class="wpstream_player_iframe_wrap">';
816 echo '<iframe id="playerFrame"
817 class="wpstream_live_channel_iframe"
818 title="' . esc_attr__( 'Embedded content', 'wpstream' ) . '"
819 src="' . esc_url( add_query_arg( $live_channel_query_args, $live_channel_frame_base ) ) . '"
820 data-wpstream-frame-role="content"
821 allowfullscreen
822 allow="autoplay; fullscreen">
823 </iframe>';
824 if ( $trailer_attachment_id && get_template() === 'hello-wpstream' ) {
825 echo '<iframe id="playerFrameTrailer"
826 class="wpstream_live_channel_iframe wpstream_live_channel_iframe_trailer"
827 title="' . esc_attr__( 'Embedded trailer content', 'wpstream' ) . '"
828 src="' . esc_url( add_query_arg( $live_channel_trailer_iframe_query_args, WPSTREAM_PLAYER . "/player/vod?" ) ) . '"
829 data-wpstream-frame-role="trailer"
830 allowfullscreen
831 allow="autoplay; fullscreen"
832 style="display:none;"
833 aria-hidden="true"
834 tabindex="-1">
835 </iframe>';
836 }
837 echo '</div>';
838
839 }
840
841 }
842
843
844
845
846
847 /**
848 *
849 * Edited in 4.0
850 *
851 *
852 * Live Event Player
853 *
854 * @author cretu
855 */
856
857 function wpstream_live_event_player_low_latency($channel_id,$poster_show='',$use_chat=''){
858 $usernamestream = esc_html ( get_option('wpstream_api_username','') );
859 $thumb_id = get_post_thumbnail_id($channel_id);
860 $thumb = wp_get_attachment_image_src($thumb_id,'small');
861
862 $event_settings = $this->wpestream_return_event_settings($channel_id);
863 $notes = 'wpstream_live_event_player_low_latency_note';
864 $event_status = $this->main->wpstream_live_connection-> wpstream_check_event_status_api_call($channel_id,$notes);
865 $hls_playback_url = '';
866 $live_conect_views = '';
867 $now = time().rand(0,10);
868
869
870
871 if(isset($event_status['status']) && $event_status['status']=='active'){
872 //live event
873 if(isset($event_status['sldp_playback_url'])){
874 $hls_playback_url = $event_status['sldp_playback_url'];
875
876 }
877 $live_conect_views = $this->wpstream_get_live_connect_uri($event_status, 'sldp_playback_url');
878 if(isset($event_status['chat_url'])){
879 $chat_url =$event_status['chat_url'];
880 }
881
882 }else{
883 // event not live
884 }
885
886
887
888
889 $low_latency_is_muted = ( isset($event_settings['mute']) && intval($event_settings['mute']) == 1 );
890 $low_latency_autoplay = true;
891 if ( isset($event_settings['autoplay']) && intval($event_settings['autoplay']) == 0 ) {
892 $low_latency_autoplay = false;
893 }
894 $low_latency_content_uri = isset( $hls_playback_url ) ? trim( $hls_playback_url ) : '';
895 $low_latency_chat_uri = isset( $chat_url ) ? trim( $chat_url ) : '';
896 $low_latency_stats_uri = isset( $live_conect_views ) ? trim( $live_conect_views ) : '';
897
898 echo '<div class="wpstream_live_player_wrapper function_wpstream_live_event_player_low_latency wpstream_low_latency" data-now="'.$now.'" data-me="'.esc_attr($usernamestream).'" data-product-id="'.$channel_id.'" id="wpstream_live_player_wrapper'.$now.'" data-instance-id="wpstream-live-low-latency-'.esc_attr( $now ).'" data-wpstream-bootstrap="live-low-latency" data-event-id="'.esc_attr( $channel_id ).'" data-video-element-id="wpstream-video'.esc_attr( $now ).'" data-content-url="'.esc_attr( $low_latency_content_uri ).'" data-chat-url="'.esc_attr( $low_latency_chat_uri ).'" data-stats-uri="'.esc_attr( $low_latency_stats_uri ).'" data-autoplay="'. ( $low_latency_autoplay ? '1' : '0' ) .'" data-muted="'. ( $low_latency_is_muted ? '1' : '0' ) .'" > ';
899
900
901 if( ( isset($event_settings['view_count'] ) && intval($event_settings['view_count'])==1 ) || !isset($event_settings['view_count']) ){
902 echo '<div id="wpestream_live_counting" class="wpestream_live_counting"></div>';
903 }
904
905 $show_wpstream_not_live_mess=' style="display:none;" ';
906 if(trim($hls_playback_url) ==''){
907 $show_wpstream_not_live_mess='';
908 }
909
910 $message_show= esc_html( get_option('wpstream_you_are_not_live','We are not live at this moment')) ;
911 print '<div class="wpstream_not_live_mess " '.$show_wpstream_not_live_mess.' ><div class="wpstream_not_live_mess_back"></div><div class="wpstream_not_live_mess_mess">'. $message_show.'</div></div>';
912
913
914 $poster_data=' poster="'.$thumb[0].'" ';
915 if($poster_show=='no'){
916 $poster_data='';
917 }
918
919
920 $is_muted='';
921 if( $low_latency_is_muted ){
922 $is_muted=' muted ';
923 }
924
925
926 $autoplay='autoplay';
927 if( !$low_latency_autoplay ){
928 $autoplay='';
929 }
930
931 echo'
932 <div iccd="player" id="wpstream-video'.$now.'" '.$poster_data.' '.$is_muted.' class="" >
933 </div>';
934
935 // Low-latency player bootstrap is handled by wpstream-player-bootstrap.js.
936
937
938 if($use_chat=="yes"){
939 $this->wpstream_connect_to_chat($channel_id);
940 }
941
942 usleep (10000);
943
944 }
945
946
947
948
949
950 /*
951 *
952 * Request HLS player
953 *
954 *
955 *
956 */
957 public function wpstream_request_video_on_demand_hls_player($video_name,$product_id){
958 if($video_name==''){
959 return '';
960 }
961
962 $transient_name = 'wpstream_video_on_demand_'.$video_name;
963 $hls_to_return = get_transient( $transient_name );
964 $hls_to_return = false;
965
966
967 if($hls_to_return==false){
968
969 $access_token = $this->main->wpstream_live_connection->wpstream_get_token();
970 $url = 'video/info';
971
972 //corsorigin de check
973 $local_event_options = get_option('wpstream_user_streaming_global_channel_options') ;
974 $domain = parse_url ( get_site_url() );
975 $domain_scheme = 'http';
976 if(is_ssl()){
977 $domain_scheme='https';
978 }
979
980
981 $wpstream_vod_domain_lock = intval( get_option('wpstream_vod_domain_lock','') ) ;
982 $corsorigin='*';
983 if($wpstream_vod_domain_lock !== 0 ){
984 $corsorigin=$domain_scheme.'://'.$domain['host'];
985 }
986
987
988 $is_encrypt="false";
989 $wpstream_vod_encrypt = intval( get_option('wpstream_vod_encrypt','') ) ;
990 if( intval( $wpstream_vod_encrypt ) ==1 ){
991 $is_encrypt="true";
992 }
993
994 $hlsKeysUrlPrefix = get_site_url().'?wpstream_voddrm=';
995 $encrypt = $is_encrypt;
996 $debugDrm = false;
997
998 $curl_post_fields=array(
999 'access_token' => $access_token,
1000 'name' => $video_name,
1001 'corsOrigin' => $corsorigin,
1002 'encryptHls' => $encrypt,
1003 'hlsKeysUrlPrefix' => $hlsKeysUrlPrefix,
1004 'debugDrm' => $debugDrm,
1005 'embed' => true,
1006 );
1007
1008
1009 $curl_response = $this->main->wpstream_live_connection->wpstream_baker_do_curl_base($url,$curl_post_fields);
1010 $curl_response_decoded = json_decode($curl_response,JSON_OBJECT_AS_ARRAY);
1011
1012 if($curl_response_decoded['success']){
1013 set_transient( $transient_name, $curl_response_decoded['hlsUrl'] ,300);
1014 $hls_to_return = $curl_response_decoded['hlsUrl'];
1015 if( isset($curl_response_decoded['hlsDecryptionKey']) && isset($curl_response_decoded['hlsDecryptionKeyIndex']) ){
1016 update_post_meta($product_id,'hlsDecryptionKey',$curl_response_decoded['hlsDecryptionKey']);
1017 update_post_meta($product_id,'hlsDecryptionKeyIndex',$curl_response_decoded['hlsDecryptionKeyIndex']);
1018 }else{
1019 delete_post_meta($product_id,'hlsDecryptionKey');
1020 delete_post_meta($product_id,'hlsDecryptionKeyIndex');
1021 }
1022
1023 if ( isset( $curl_response_decoded['video'] ) &&
1024 isset( $curl_response_decoded['embedKey'] ) &&
1025 isset( $curl_response_decoded['embedUrl'] )
1026 ) {
1027 update_post_meta( $product_id, 'wpstream_vod_video_data', trim( (string) $curl_response_decoded['video'] ) );
1028 update_post_meta( $product_id, 'wpstream_vod_embed_key', trim( (string) $curl_response_decoded['embedKey'] ) );
1029 update_post_meta( $product_id, 'wpstream_vod_embed_url', trim( (string) $curl_response_decoded['embedUrl'] ) );
1030 }
1031 }else{
1032 return '';
1033 }
1034
1035 }
1036
1037 return $hls_to_return;
1038
1039 }
1040
1041 function wpstream_get_player_theme( $channel_id = null ) {
1042 $player_theme = get_option('wpstream_video_player_theme');
1043 $is_streamify_user = $this->wpstream_is_streamify_user( $channel_id );
1044 if ( !empty($player_theme) && !$is_streamify_user ) {
1045 $this->wpstream_enqueue_player_theme_style( $player_theme );
1046 return 'vjs-theme-' . $player_theme;
1047 }
1048
1049 return '';
1050 }
1051
1052 function wpstream_enqueue_player_theme_style( $player_theme ) {
1053 if ( $player_theme != 'default' ) {
1054 wp_enqueue_style('videojs-theme-' . $player_theme, 'https://cdn.jsdelivr.net/npm/@videojs/themes@1/dist/' . $player_theme . '/index.min.css', array(), '1.0.0');
1055
1056 }
1057 }
1058
1059 /*
1060 * Return data about the logo
1061 */
1062 private function wpstream_get_player_logo_data( $product_id ): array {
1063 $player_logo_position = get_option( 'wpstream_player_logo_position', 'top-right' );
1064 $player_logo_position_class = '';
1065 $player_logo_horizontal_position = '';
1066 if ( $player_logo_position && $player_logo_position != '' ) {
1067 $player_logo_position_parts = explode( '-', $player_logo_position );
1068 if ( isset( $player_logo_position_parts[0], $player_logo_position_parts[1] ) ) {
1069 $player_logo_position_class = 'logo-' . $player_logo_position_parts[0];
1070 $player_logo_horizontal_position = 'logo-' . $player_logo_position_parts[1];
1071 }
1072 }
1073
1074 $player_logo_src = $this->wpstream_get_video_player_logo( $product_id );
1075 $player_logo_opacity = intval( esc_html( get_option('wpstream_player_logo_opacity','100') ) ) / 100;
1076
1077 return array(
1078 'player_logo_src' => $player_logo_src,
1079 'player_logo_position' => $player_logo_position,
1080 'player_logo_position_class' => $player_logo_position_class,
1081 'player_logo_horizontal_position' => $player_logo_horizontal_position,
1082 'player_logo_opacity' => $player_logo_opacity,
1083 );
1084 }
1085
1086
1087
1088 /**
1089 * VODPlayer uri details
1090 *
1091 * @author cretu
1092 */
1093 public function wpstream_video_on_demand_player_uri_request($product_id){
1094
1095 $wpstream_data_setup = ' data-setup="{}" ';
1096
1097 /* free_video_type
1098 * 1 - free live channel
1099 * 2 - free video encrypted
1100 * 3 - free video -not encrypted
1101 */
1102
1103 $post_type = get_post_type($product_id);
1104 $free_video_type = intval( get_post_meta($product_id, 'wpstream_product_type', true));
1105 $video_path_final = '';
1106 $video_type = '';
1107 if( ( $post_type =='wpstream_product_vod' && $free_video_type==2 ) || get_post_type($product_id)=='product' ){
1108
1109 /*
1110 * IF vide is encrypted- readed from vod,streaner
1111 *
1112 */
1113
1114
1115 $video_type = 'application/x-mpegURL';
1116 $video_path = get_post_meta($product_id,'_movie_url',true);
1117 if(get_post_type($product_id)=='wpstream_product_vod'){
1118 $video_path = esc_html(get_post_meta($product_id, 'wpstream_free_video', true));
1119 }
1120 $video_path_final = $this->wpstream_request_video_on_demand_hls_player($video_path,$product_id);
1121
1122
1123 }else if( $post_type =='wpstream_product_vod' && $free_video_type==3 ){
1124
1125 /* Video is unecrypted - read from local or youtube / vimeo
1126 */
1127
1128 $video_type = 'video/mp4';
1129 $video_path_final=esc_html(get_post_meta($product_id, 'wpstream_free_video_external', true));
1130 wp_enqueue_script('youtube.min');
1131 }
1132
1133 $return_array = array();
1134 $return_array['video_path_final'] = $video_path_final;
1135 $return_array['wpstream_data_setup']= $wpstream_data_setup;
1136 $return_array['video_type'] = $video_type;
1137 $return_array['free_video_type'] = $free_video_type;
1138 $return_array['post_type'] = $post_type ;
1139 return $return_array;
1140 }
1141
1142
1143
1144 /**
1145 * VODPlayer url
1146 *
1147 * @author cretu
1148 */
1149
1150 public function wpstream_video_on_demand_player($product_id){
1151 wp_enqueue_script('video.min');
1152 wp_enqueue_script('wpstream-player');
1153 wp_enqueue_script( 'wpstream-player-controls' );
1154
1155 $player_theme = $this->wpstream_get_player_theme( $product_id );
1156
1157 $uri_details = $this->wpstream_video_on_demand_player_uri_request($product_id);
1158 $video_path_final = $uri_details['video_path_final'];
1159 $wpstream_data_setup = $uri_details['wpstream_data_setup'];
1160 $video_type = $uri_details['video_type'];
1161 $now = time().rand(0,1000000);
1162
1163 $overlay_video_div_id = "random_id_".$now;
1164 $this->wpstream_render_vod_title_overlay(
1165 $overlay_video_div_id,
1166 get_the_title($product_id)
1167 );
1168
1169 $thumb_id = get_post_thumbnail_id($product_id);
1170 $thumb = wp_get_attachment_image_src($thumb_id,'small');
1171 $usernamestream = esc_html ( get_option('wpstream_api_username','') );
1172
1173 $poster_thumb = '';
1174 if(isset($thumb[0])){
1175 $poster_thumb=$thumb[0];
1176 }
1177
1178 $hlsDecryptionKey = get_post_meta($product_id,'hlsDecryptionKey',true);
1179 $hlsDecryptionKeyIndex = get_post_meta($product_id,'hlsDecryptionKeyIndex',true);
1180
1181
1182 $pack = $this->main->quota_manager->get_live_quota_data( 'wpstream_video_on_demand_player' );
1183
1184
1185
1186 $trailer_attachment_id = intval (get_post_meta( $product_id, 'video_trailer', true ));
1187 $video_trailer = '';
1188 $video_trailer_type = '';
1189 if($trailer_attachment_id!=0) {
1190 $video_trailer = wp_get_attachment_url( $trailer_attachment_id );
1191 $attachment_metadata = wp_get_attachment_metadata($trailer_attachment_id);
1192 if( isset ($attachment_metadata['mime_type']) ) {
1193 $video_trailer_type = $attachment_metadata['mime_type'];
1194 }
1195 }
1196
1197 // override trailer setup here (for testing)
1198 // $trailer_attachment_id = 1;
1199 // $video_trailer = '/wp-content/uploads/2023/10/production-ID_4608975.mp4';
1200 // $video_trailer = '/wp-content/uploads/2023/10/ultrawide.mp4';
1201
1202 // If the video is self hosted or external, we should let the user see it
1203 $video_type = intval( get_post_meta($product_id, 'wpstream_product_type', true));
1204
1205
1206 if ( (isset($pack['available_data_mb']) && $pack['available_data_mb']>0) || $video_type === 3 ) {
1207
1208 if($video_path_final==''){
1209 if( $uri_details['post_type']=='wpstream_product_vod' && $uri_details['free_video_type']==3 ){
1210 }else{
1211 print '<div class="wpstream_vod_notice">This video does not exist or it has been deleted!</div>';
1212 }
1213
1214 }
1215
1216 // TODO (crerem) populate these from VOD settings
1217 $autoplay = false;
1218 $muted = false;
1219
1220 $wpstream_vod_start_muted = intval ( get_option('wpstream_vod_start_muted','') );
1221 if($wpstream_vod_start_muted===1){
1222 $muted=true;
1223 }
1224 $wpstream_vod_autoplay = intval ( get_option('wpstream_vod_autoplay','') );
1225 if($wpstream_vod_autoplay===1){
1226 $autoplay=true;
1227 }
1228
1229 $poster_data = 'poster="'.esc_url($poster_thumb).'"';
1230 $has_trailer_class='';
1231 if($trailer_attachment_id !=0){
1232 $poster_data=''; // cancel poster for theme
1233 $has_trailer_class='wpstream_theme_player_has_trailer';
1234 }
1235
1236 $player_logo_data = $this->wpstream_get_player_logo_data( $product_id );
1237 $player_logo_image = $player_logo_data['player_logo_src'];
1238 $player_logo_position = $player_logo_data['player_logo_position'];
1239 $player_logo_position_class = $player_logo_data['player_logo_position_class'];
1240 $player_logo_horizontal_position = $player_logo_data['player_logo_horizontal_position'];
1241 $player_logo_opacity = $player_logo_data['player_logo_opacity'];
1242
1243 $captionsUrl = get_post_meta( $product_id, 'wpstream_closed_captions_file', true );
1244 $play_trailer_button_element_id = $trailer_attachment_id != 0 ? 'wpstream_video_on_demand_play_trailer_btn_' . $now : '';
1245 $mute_trailer_button_element_id = $trailer_attachment_id != 0 ? 'wpstream_video_on_demand_mute_trailer_btn_' . $now : '';
1246 $unmute_trailer_button_element_id = $trailer_attachment_id != 0 ? 'wpstream_video_on_demand_unmute_trailer_btn_' . $now : '';
1247 $play_video_button_element_id = $trailer_attachment_id != 0 ? 'wpstream_video_on_demand_play_video_btn_' . $now : '';
1248
1249 $wpstream_vod_encrypt = intval( get_option( 'wpstream_vod_encrypt', '' ) );
1250 $wpstream_vod_lock_to_website = intval( get_option( 'wpstream_vod_domain_lock', '' ) );
1251
1252 $wpstream_session_encryption = 0;
1253 $local_event_options = get_option('wpstream_user_streaming_global_channel_options') ;
1254 if(isset($local_event_options['ses_encrypt']) && intval($local_event_options['ses_encrypt'])==1 ) {
1255 $wpstream_session_encryption = 1;
1256 }
1257
1258 /**
1259 * Presence bootstrap expects validatePlaybackSessionUrl as an absolute HTTP(S) URL that returns JSON { success: true } when the playback session is valid — not the literals "true"/"false".
1260 * Embed keys must be minted with the same inputs as the iframe query (video, validatePlaybackSessionUrl, embedAncestor, encrypt) per player embed-key.js.
1261 *
1262 * @see WPStream player embed-key.js and session-validation.js (verifyPlaybackSessionUrl).
1263 */
1264 $vod_validate_url = '';
1265 if ( $wpstream_session_encryption ) {
1266 $vod_validate_url = esc_url_raw(
1267 apply_filters(
1268 'wpstream_vod_validate_playback_session_url',
1269 $this->playback_session->wpstream_get_default_validate_playback_session_url(),
1270 $product_id
1271 )
1272 );
1273 wp_localize_script(
1274 'wpstream-player-controls',
1275 'wpstreamVodIframeSessionApi',
1276 array(
1277 'requirePlaybackSession' => true,
1278 'nonce' => wp_create_nonce( 'wpstream_playback_session_issue' ),
1279 'productId' => (int) $product_id,
1280 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
1281 )
1282 );
1283 }
1284
1285 $vod_embed_ancestor = '';
1286 if ( $wpstream_vod_lock_to_website ) {
1287 $vod_embed_ancestor = esc_url_raw(
1288 apply_filters(
1289 'wpstream_vod_embed_ancestor',
1290 $this->wpstream_get_site_origin_for_embed(),
1291 $product_id
1292 )
1293 );
1294 }
1295
1296 // if there's "wpstream_vod_embed_url" set, it means that we use the new player
1297 $wpstream_vod_embed_url = get_post_meta( $product_id, 'wpstream_vod_embed_url', true );
1298
1299 $vod_iframe_base = WPSTREAM_PLAYER . "/player/vod?";
1300 $vod_iframe_video_raw = (string) get_post_meta( $product_id, 'wpstream_vod_video_data', true );
1301 $vod_iframe_video = trim( $vod_iframe_video_raw );
1302 if ( strlen( $vod_iframe_video ) >= 2 ) {
1303 $first_char = $vod_iframe_video[0];
1304 $last_char = substr( $vod_iframe_video, -1 );
1305 $is_wrapped_in_double_quotes = '"' === $first_char && '"' === $last_char;
1306 $is_wrapped_in_single_quotes = "'" === $first_char && "'" === $last_char;
1307 if ( $is_wrapped_in_double_quotes || $is_wrapped_in_single_quotes ) {
1308 $vod_iframe_video = substr( $vod_iframe_video, 1, -1 );
1309 }
1310 }
1311 $vod_iframe_embed_key = $this->wpstream_generate_player_embed_key(
1312 $vod_iframe_video,
1313 $vod_validate_url,
1314 $vod_embed_ancestor,
1315 $wpstream_vod_encrypt ? 'yes' : ''
1316 );
1317 if ( '' === $vod_iframe_embed_key ) {
1318 $vod_iframe_embed_key = (string) get_post_meta( $product_id, 'wpstream_vod_embed_key', true );
1319 }
1320 $vod_iframe_trailer_embed_key = $this->wpstream_generate_player_embed_key(
1321 $video_trailer,
1322 $vod_validate_url,
1323 $vod_embed_ancestor,
1324 $wpstream_vod_encrypt ? 'yes' : ''
1325 );
1326
1327 $vod_poster_image = get_the_post_thumbnail_url( $product_id, 'full' );
1328 $current_active_theme = wp_get_theme();
1329
1330 $vod_iframe_skin_slug = '';
1331 if ( preg_match( '/^vjs-theme-(city|fantasy|forest|sea)$/', $player_theme, $vod_iframe_skin_m ) ) {
1332 $vod_iframe_skin_slug = $vod_iframe_skin_m[1];
1333 }
1334
1335 $vod_iframe_query_args = array_filter(
1336 array(
1337 'video' => $vod_iframe_video,
1338 'posterImage' => $vod_poster_image,
1339 'embedKey' => $vod_iframe_embed_key,
1340 'startMuted' => $muted ? '1' : '',
1341 'skin' => $vod_iframe_skin_slug,
1342 'encrypt' => $wpstream_vod_encrypt ? 'yes' : '',
1343 'validatePlaybackSessionUrl' => $vod_validate_url,
1344 'embedAncestor' => $vod_embed_ancestor,
1345 'logoImage' => $player_logo_image,
1346 'logoPosition' => $player_logo_image ? $player_logo_position : '',
1347 'logoOpacity' => $player_logo_image ? $player_logo_opacity : '',
1348 'isThemeActive' => $current_active_theme->get('Name') === 'Hello WPStream',
1349 ),
1350 static function ( $v ) {
1351 return $v !== null && $v !== '';
1352 }
1353 );
1354
1355 $vod_trailer_iframe_query_args = array_filter(
1356 array(
1357 'video' => $video_trailer,
1358 'embedKey' => $vod_iframe_trailer_embed_key,
1359 'skin' => $vod_iframe_skin_slug,
1360 'startMuted' => $muted ? '1' : '',
1361 'encrypt' => $wpstream_vod_encrypt ? 'yes' : '',
1362 'validatePlaybackSessionUrl' => $vod_validate_url,
1363 'embedAncestor' => $vod_embed_ancestor,
1364 ),
1365 static function ( $v ) {
1366 return $v !== null && $v !== '';
1367 }
1368 );
1369
1370 if ( $wpstream_vod_embed_url ) {
1371 echo '<div class="wpstream_player_iframe_wrap">';
1372 echo '<iframe id="playerFrame"
1373 class="wpstream_video_on_demand_iframe"
1374 title="' . esc_attr__( 'Embedded content', 'wpstream' ) . '"
1375 src="' . esc_url( add_query_arg( $vod_iframe_query_args, $vod_iframe_base ) ) . '"
1376 data-wpstream-frame-role="content"
1377 allowfullscreen
1378 allow="autoplay; fullscreen">
1379 </iframe>';
1380 if ( $trailer_attachment_id != 0 && get_template() == 'hello-wpstream' ) {
1381 echo '<iframe id="playerFrameTrailer"
1382 class="wpstream_video_on_demand_iframe wpstream_video_on_demand_iframe_trailer"
1383 title="' . esc_attr__( 'Embedded trailer content', 'wpstream' ) . '"
1384 src="' . esc_url( add_query_arg( $vod_trailer_iframe_query_args, $vod_iframe_base ) ) . '"
1385 data-wpstream-frame-role="trailer"
1386 allowfullscreen
1387 allow="autoplay; fullscreen"
1388 style="display:none;"
1389 aria-hidden="true"
1390 tabindex="-1">
1391 </iframe>';
1392 }
1393 echo '</div>';
1394 } else {
1395 echo '<video id="wpstream-video-vod-'.$now.'" class="'.esc_attr($has_trailer_class).' video-js vjs-default-skin vjs-fluid kuk wpstream_video_on_demand vjs-wpstream ' . $player_theme .' ' . $player_logo_position_class . ' ' . $player_logo_horizontal_position . '" data-me="'.esc_attr($usernamestream).'" data-product-id="'.$product_id.'" data-wpstream-bootstrap="vod" data-instance-id="wpstream-vod-'.esc_attr( $now ).'" data-video-element-id="wpstream-video-vod-'.esc_attr( $now ).'" data-title-overlay-element-id="'.esc_attr( $overlay_video_div_id ).'" data-video-url="'.esc_attr( $video_path_final ).'" data-trailer-url="'.esc_attr( $video_trailer ).'" data-autoplay="'. ( $autoplay ? '1' : '0' ) .'" data-muted="'. ( $muted ? '1' : '0' ) .'" data-captions-url="'.esc_attr( $captionsUrl ).'" data-play-trailer-button-element-id="'.esc_attr( $play_trailer_button_element_id ).'" data-mute-trailer-button-element-id="'.esc_attr( $mute_trailer_button_element_id ).'" data-unmute-trailer-button-element-id="'.esc_attr( $unmute_trailer_button_element_id ).'" data-play-video-button-element-id="'.esc_attr( $play_video_button_element_id ).'" data-player-logo-image="'.esc_attr( $player_logo_image ).'" data-player-logo-position="'.esc_attr( $player_logo_position ).'" data-player-logo-opacity="'.esc_attr( $player_logo_opacity ).'" data-player-logo-width="100" data-player-logo-height="auto" data-player-logo-padding="10" playsinline preload="auto"
1396 '. $poster_data.' '.$wpstream_data_setup.'>
1397 <p class="vjs-no-js">
1398 To view this video please enable JavaScript, and consider upgrading to a web browser that
1399 <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>
1400 </p>
1401 </video>';
1402
1403 if($trailer_attachment_id !=0){
1404 print '<div class="wpstream_theme_trailer_wrapper">';
1405 print '<div id="'.esc_attr( $play_trailer_button_element_id ).'" class="wpstream_video_on_demand_play_trailer">
1406 <svg width="30" height="24" viewBox="0 0 30 24" fill="none" xmlns="http://www.w3.org/2000/svg">
1407 <path fill-rule="evenodd" clip-rule="evenodd" d="M26.6667 1.5H3.33337C2.50495 1.5 1.83337 2.17157 1.83337 3V21C1.83337 21.8284 2.50495 22.5 3.33338 22.5H26.6667C27.4951 22.5 28.1667 21.8284 28.1667 21V3C28.1667 2.17157 27.4951 1.5 26.6667 1.5ZM3.33337 0C1.67652 0 0.333374 1.34315 0.333374 3V21C0.333374 22.6569 1.67652 24 3.33338 24H26.6667C28.3236 24 29.6667 22.6569 29.6667 21V3C29.6667 1.34315 28.3236 0 26.6667 0H3.33337ZM4.83337 4C4.55723 4 4.33337 4.22386 4.33337 4.5V6.16667C4.33337 6.44281 4.55723 6.66667 4.83337 6.66667H6.50004C6.77618 6.66667 7.00004 6.44281 7.00004 6.16667V4.5C7.00004 4.22386 6.77618 4 6.50004 4H4.83337ZM23.5 4C23.2239 4 23 4.22386 23 4.5V6.16667C23 6.44281 23.2239 6.66667 23.5 6.66667H25.1667C25.4428 6.66667 25.6667 6.44281 25.6667 6.16667V4.5C25.6667 4.22386 25.4428 4 25.1667 4H23.5ZM4.33337 11.167C4.33337 10.8909 4.55723 10.667 4.83337 10.667H6.50004C6.77618 10.667 7.00004 10.8909 7.00004 11.167V12.8337C7.00004 13.1098 6.77618 13.3337 6.50004 13.3337H4.83337C4.55723 13.3337 4.33337 13.1098 4.33337 12.8337V11.167ZM23.5001 10.667C23.224 10.667 23.0001 10.8909 23.0001 11.167V12.8337C23.0001 13.1098 23.224 13.3337 23.5001 13.3337H25.1668C25.4429 13.3337 25.6668 13.1098 25.6668 12.8337V11.167C25.6668 10.8909 25.4429 10.667 25.1668 10.667H23.5001ZM4.33337 17.833C4.33337 17.5569 4.55723 17.333 4.83337 17.333H6.50004C6.77618 17.333 7.00004 17.5569 7.00004 17.833V19.4997C7.00004 19.7758 6.77618 19.9997 6.50004 19.9997H4.83337C4.55723 19.9997 4.33337 19.7758 4.33337 19.4997V17.833ZM23.5001 17.333C23.224 17.333 23.0001 17.5569 23.0001 17.833V19.4997C23.0001 19.7758 23.224 19.9997 23.5001 19.9997H25.1668C25.4429 19.9997 25.6668 19.7758 25.6668 19.4997V17.833C25.6668 17.5569 25.4429 17.333 25.1668 17.333H23.5001ZM19.0677 13.0997L13.4077 16.5087C13.0434 16.7281 12.6092 16.7094 12.2661 16.5091C11.9218 16.3081 11.6666 15.9224 11.6666 15.4086V8.59072C11.6666 8.07698 11.9218 7.69125 12.2661 7.49026C12.6092 7.28999 13.0434 7.27126 13.4077 7.49064L19.0677 10.8996C19.8663 11.3805 19.8663 12.6188 19.0677 13.0997Z"/>
1408 </svg>
1409 '.esc_html__('Play Trailer','wpstream').'</div>';
1410
1411 print '<div class="wpstream_video_on_demand_play_video_wrapper" id="'.esc_attr( $play_video_button_element_id ).'" >
1412 <div class="wpstream_video_on_demand_play_video">
1413 <svg width="29" height="30" viewBox="0 0 29 30" fill="none" xmlns="http://www.w3.org/2000/svg">
1414 <path fill-rule="evenodd" clip-rule="evenodd" d="M6.1808 28.9035L26.274 18.1652C29.1087 16.6503 29.1087 12.7497 26.274 11.2348L6.1808 0.496557C4.88769 -0.194506 3.34623 -0.1355 2.1283 0.495357C0.906043 1.12846 1.0095e-06 2.34351 9.38766e-07 3.96179L0 25.4382C-7.07369e-08 27.0565 0.906042 28.2715 2.1283 28.9046C3.34622 29.5355 4.88769 29.5945 6.1808 28.9035ZM24.8221 13.8026C25.5742 14.2045 25.5742 15.1955 24.8221 15.5974L4.72891 26.3356C3.94628 26.7539 3.01386 26.2165 3.01386 25.4382L3.01386 3.96179C3.01386 3.18347 3.94628 2.6461 4.72891 3.06436L24.8221 13.8026Z" fill="#F1F1F1"/>
1415 </svg>
1416 </div>
1417 '.esc_html__('Play Video','wpstream').'
1418 </div>';
1419
1420
1421
1422 print '<div id="'.esc_attr( $mute_trailer_button_element_id ).'" class="wpstream_video_on_demand_mute_trailer">
1423
1424 <svg width="37" height="36" viewBox="0 0 37 36" fill="none" xmlns="http://www.w3.org/2000/svg">
1425 <path fill-rule="evenodd" clip-rule="evenodd" d="M1.32143 10.0789H8.69499L18.8964 0L21.1428 0.921053V35.1316L18.8964 36L8.69499 25.8684H1.32143L0 24.5526V11.3947L1.32143 10.0789ZM10.175 23.6842L18.5 31.9474V4.10526L10.175 12.3158L9.24999 12.7105H2.64286V23.2368H9.24999L10.175 23.6842ZM37 17.9737C37.0069 22.2216 35.5329 26.3401 32.8295 29.6263L30.9478 27.7579C33.1613 24.9734 34.3629 21.5249 34.3571 17.9737C34.3571 14.2895 33.0885 10.8974 30.9637 8.21053L32.8454 6.34211C35.5382 9.62494 37.0062 13.735 37 17.9737ZM31.7143 17.9737C31.7193 20.8255 30.7895 23.6011 29.0661 25.8789L27.1738 23.9947C28.4127 22.2295 29.0752 20.1272 29.0714 17.9737C29.0751 15.8287 28.4174 13.7344 27.1871 11.9737L29.0793 10.0895C30.7338 12.2868 31.7143 15.0158 31.7143 17.9737ZM26.4286 17.9737C26.4286 19.4842 26.0057 20.8947 25.2657 22.0947L23.3126 20.1526C23.6249 19.4729 23.7876 18.7345 23.7899 17.9869C23.7922 17.2394 23.634 16.5001 23.3258 15.8184L25.2789 13.8737C26.0083 15.0684 26.4286 16.4737 26.4286 17.9737Z" fill="white"/>
1426 </svg>
1427 </div>';
1428 print '<div id="'.esc_attr( $unmute_trailer_button_element_id ).'" class="wpstream_video_on_demand_unmute_trailer">
1429 <svg width="33" height="32" viewBox="0 0 33 32" fill="none" xmlns="http://www.w3.org/2000/svg">
1430 <path fill-rule="evenodd" clip-rule="evenodd" d="M1.15625 8.85688H7.60813L16.5344 0L18.5 0.809375V30.8719L16.5344 31.635L7.60813 22.7319H1.15625L0 21.5756V10.0131L1.15625 8.85688ZM8.90313 20.8125L16.1875 28.0738V3.6075L8.90313 10.8225L8.09375 11.1694H2.3125V20.4194H8.09375L8.90313 20.8125ZM30.5967 11.3127L32.2316 12.9477L28.2287 16.9506L32.2316 20.9559L30.5967 22.5908L26.5938 18.5856L22.5885 22.5908L20.9536 20.9559L24.9588 16.9506L20.9513 12.95L22.5862 11.3151L26.5938 15.3157L30.5967 11.3127Z" fill="white"/>
1431 </svg>
1432
1433 </div>';
1434 print '</div>';
1435 }
1436 }
1437 }else{
1438 print '<div class="wpstream_insuficent_res">'.esc_html__('Insufficient resources to stream this title','wpstream').'</div>';
1439 }
1440
1441 }
1442
1443
1444
1445 /**
1446 * VODPlayer url - only trailer - used in theme
1447 *
1448 * @author cretu
1449 */
1450 public function wpstream_video_on_demand_player_only_trailer($product_id){
1451 wp_enqueue_script('video.min');
1452 wp_enqueue_script('wpstream-player');
1453
1454 $player_theme = $this->wpstream_get_player_theme();
1455 $now = time().rand(0,1000000);
1456 $overlay_video_div_id = "random_id_".$now;
1457 $this->wpstream_render_vod_title_overlay(
1458 $overlay_video_div_id,
1459 get_the_title($product_id)
1460 );
1461
1462
1463
1464 $thumb_id = get_post_thumbnail_id($product_id);
1465 $thumb = wp_get_attachment_image_src($thumb_id,'small');
1466 $usernamestream = esc_html ( get_option('wpstream_api_username','') );
1467
1468 $poster_thumb = '';
1469 if(isset($thumb[0])){
1470 $poster_thumb=$thumb[0];
1471 }
1472
1473
1474 $trailer_attachment_id = intval (get_post_meta( $product_id, 'video_trailer', true ));
1475 $video_trailer = '';
1476 $video_trailer_type = '';
1477 if($trailer_attachment_id!=0) {
1478 $video_trailer = wp_get_attachment_url( $trailer_attachment_id );
1479 $attachment_metadata = wp_get_attachment_metadata($trailer_attachment_id);
1480 if(isset($attachment_metadata['mime_type'])){
1481 $video_trailer_type = $attachment_metadata['mime_type'];
1482 }
1483
1484 }
1485
1486
1487 $autoplay = false;
1488 $muted = false;
1489
1490 if( intval ( get_option('wpstream_vod_start_muted','') ) === 1){
1491 $muted = true;
1492 }
1493 if( intval ( get_option('wpstream_vod_autoplay','') ) === 1 ){
1494 $autoplay = true;
1495 }
1496 $video_path_final='';
1497 $has_trailer_class='wpstream_theme_player_has_trailer';
1498 $captions_url = get_post_meta( $product_id, 'wpstream_closed_captions_file', true );
1499 $play_trailer_button_element_id = $trailer_attachment_id != 0 ? 'wpstream_video_on_demand_play_trailer_btn_' . $now : '';
1500 $mute_trailer_button_element_id = $trailer_attachment_id != 0 ? 'wpstream_video_on_demand_mute_trailer_btn_' . $now : '';
1501 $unmute_trailer_button_element_id = $trailer_attachment_id != 0 ? 'wpstream_video_on_demand_unmute_trailer_btn_' . $now : '';
1502
1503 echo '<video id="wpstream-video-vod-'.$now.'" class="video-js vjs-default-skin vjs-fluid kuk wpstream_video_on_demand vjs-wpstream '.esc_attr( $has_trailer_class ).' ' . $player_theme . '" data-me="'.esc_attr($usernamestream).'" data-product-id="'.$product_id.'" data-wpstream-bootstrap="vod" data-instance-id="wpstream-vod-trailer-'.esc_attr( $now ).'" data-video-element-id="wpstream-video-vod-'.esc_attr( $now ).'" data-title-overlay-element-id="'.esc_attr( $overlay_video_div_id ).'" data-video-url="" data-trailer-url="'.esc_attr( $video_trailer ).'" data-autoplay="'. ( $autoplay ? '1' : '0' ) .'" data-muted="'. ( $muted ? '1' : '0' ) .'" data-captions-url="'.esc_attr( $captions_url ).'" data-play-trailer-button-element-id="'.esc_attr( $play_trailer_button_element_id ).'" data-mute-trailer-button-element-id="'.esc_attr( $mute_trailer_button_element_id ).'" data-unmute-trailer-button-element-id="'.esc_attr( $unmute_trailer_button_element_id ).'" playsinline preload="auto"
1504 >
1505 <p class="vjs-no-js">
1506 To view this video please enable JavaScript, and consider upgrading to a web browser that
1507 <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>
1508 </p>
1509 </video>';
1510
1511 if($trailer_attachment_id !=0){
1512 print '<div class="wpstream_theme_trailer_wrapper">';
1513 print '<div id="'.esc_attr( $play_trailer_button_element_id ).'" class="wpstream_video_on_demand_play_trailer">
1514 <svg width="30" height="24" viewBox="0 0 30 24" fill="none" xmlns="http://www.w3.org/2000/svg">
1515 <path fill-rule="evenodd" clip-rule="evenodd" d="M26.6667 1.5H3.33337C2.50495 1.5 1.83337 2.17157 1.83337 3V21C1.83337 21.8284 2.50495 22.5 3.33338 22.5H26.6667C27.4951 22.5 28.1667 21.8284 28.1667 21V3C28.1667 2.17157 27.4951 1.5 26.6667 1.5ZM3.33337 0C1.67652 0 0.333374 1.34315 0.333374 3V21C0.333374 22.6569 1.67652 24 3.33338 24H26.6667C28.3236 24 29.6667 22.6569 29.6667 21V3C29.6667 1.34315 28.3236 0 26.6667 0H3.33337ZM4.83337 4C4.55723 4 4.33337 4.22386 4.33337 4.5V6.16667C4.33337 6.44281 4.55723 6.66667 4.83337 6.66667H6.50004C6.77618 6.66667 7.00004 6.44281 7.00004 6.16667V4.5C7.00004 4.22386 6.77618 4 6.50004 4H4.83337ZM23.5 4C23.2239 4 23 4.22386 23 4.5V6.16667C23 6.44281 23.2239 6.66667 23.5 6.66667H25.1667C25.4428 6.66667 25.6667 6.44281 25.6667 6.16667V4.5C25.6667 4.22386 25.4428 4 25.1667 4H23.5ZM4.33337 11.167C4.33337 10.8909 4.55723 10.667 4.83337 10.667H6.50004C6.77618 10.667 7.00004 10.8909 7.00004 11.167V12.8337C7.00004 13.1098 6.77618 13.3337 6.50004 13.3337H4.83337C4.55723 13.3337 4.33337 13.1098 4.33337 12.8337V11.167ZM23.5001 10.667C23.224 10.667 23.0001 10.8909 23.0001 11.167V12.8337C23.0001 13.1098 23.224 13.3337 23.5001 13.3337H25.1668C25.4429 13.3337 25.6668 13.1098 25.6668 12.8337V11.167C25.6668 10.8909 25.4429 10.667 25.1668 10.667H23.5001ZM4.33337 17.833C4.33337 17.5569 4.55723 17.333 4.83337 17.333H6.50004C6.77618 17.333 7.00004 17.5569 7.00004 17.833V19.4997C7.00004 19.7758 6.77618 19.9997 6.50004 19.9997H4.83337C4.55723 19.9997 4.33337 19.7758 4.33337 19.4997V17.833ZM23.5001 17.333C23.224 17.333 23.0001 17.5569 23.0001 17.833V19.4997C23.0001 19.7758 23.224 19.9997 23.5001 19.9997H25.1668C25.4429 19.9997 25.6668 19.7758 25.6668 19.4997V17.833C25.6668 17.5569 25.4429 17.333 25.1668 17.333H23.5001ZM19.0677 13.0997L13.4077 16.5087C13.0434 16.7281 12.6092 16.7094 12.2661 16.5091C11.9218 16.3081 11.6666 15.9224 11.6666 15.4086V8.59072C11.6666 8.07698 11.9218 7.69125 12.2661 7.49026C12.6092 7.28999 13.0434 7.27126 13.4077 7.49064L19.0677 10.8996C19.8663 11.3805 19.8663 12.6188 19.0677 13.0997Z"/>
1516 </svg>
1517 '.esc_html__('Play Trailer','wpstream').'
1518 </div>';
1519 print '<div id="'.esc_attr( $mute_trailer_button_element_id ).'" class="wpstream_video_on_demand_mute_trailer">
1520 <svg width="37" height="36" viewBox="0 0 37 36" fill="none" xmlns="http://www.w3.org/2000/svg">
1521 <path fill-rule="evenodd" clip-rule="evenodd" d="M1.32143 10.0789H8.69499L18.8964 0L21.1428 0.921053V35.1316L18.8964 36L8.69499 25.8684H1.32143L0 24.5526V11.3947L1.32143 10.0789ZM10.175 23.6842L18.5 31.9474V4.10526L10.175 12.3158L9.24999 12.7105H2.64286V23.2368H9.24999L10.175 23.6842ZM37 17.9737C37.0069 22.2216 35.5329 26.3401 32.8295 29.6263L30.9478 27.7579C33.1613 24.9734 34.3629 21.5249 34.3571 17.9737C34.3571 14.2895 33.0885 10.8974 30.9637 8.21053L32.8454 6.34211C35.5382 9.62494 37.0062 13.735 37 17.9737ZM31.7143 17.9737C31.7193 20.8255 30.7895 23.6011 29.0661 25.8789L27.1738 23.9947C28.4127 22.2295 29.0752 20.1272 29.0714 17.9737C29.0751 15.8287 28.4174 13.7344 27.1871 11.9737L29.0793 10.0895C30.7338 12.2868 31.7143 15.0158 31.7143 17.9737ZM26.4286 17.9737C26.4286 19.4842 26.0057 20.8947 25.2657 22.0947L23.3126 20.1526C23.6249 19.4729 23.7876 18.7345 23.7899 17.9869C23.7922 17.2394 23.634 16.5001 23.3258 15.8184L25.2789 13.8737C26.0083 15.0684 26.4286 16.4737 26.4286 17.9737Z" fill="white"/>
1522 </svg>
1523
1524
1525 </div>';
1526 print '<div id="'.esc_attr( $unmute_trailer_button_element_id ).'" class="wpstream_video_on_demand_unmute_trailer">
1527 <svg width="33" height="32" viewBox="0 0 33 32" fill="none" xmlns="http://www.w3.org/2000/svg">
1528 <path fill-rule="evenodd" clip-rule="evenodd" d="M1.15625 8.85688H7.60813L16.5344 0L18.5 0.809375V30.8719L16.5344 31.635L7.60813 22.7319H1.15625L0 21.5756V10.0131L1.15625 8.85688ZM8.90313 20.8125L16.1875 28.0738V3.6075L8.90313 10.8225L8.09375 11.1694H2.3125V20.4194H8.09375L8.90313 20.8125ZM30.5967 11.3127L32.2316 12.9477L28.2287 16.9506L32.2316 20.9559L30.5967 22.5908L26.5938 18.5856L22.5885 22.5908L20.9536 20.9559L24.9588 16.9506L20.9513 12.95L22.5862 11.3151L26.5938 15.3157L30.5967 11.3127Z" fill="white"/>
1529 </svg>
1530
1531 </div>';
1532 print '</div>';
1533 }
1534 else {
1535 //just show the poster or don't show anything; no player needed
1536 }
1537
1538 }
1539
1540
1541
1542 /**
1543 *
1544 * edited 4.0
1545 *
1546 * Retreive username for vod path
1547 *
1548 * @author cretu
1549 */
1550 private function wpstream_retrive_username(){
1551
1552 return get_option('wpstream_api_username_from_token');
1553 }
1554
1555 /**
1556 * Render title overlay via action hook.
1557 *
1558 * @param string $overlay_id Overlay element id.
1559 * @param string $title_text Title text.
1560 */
1561 private function wpstream_render_vod_title_overlay( $overlay_id, $title_text ) {
1562 if ( has_action( 'wpstream_vod_title_overlay' ) ) {
1563 do_action(
1564 'wpstream_vod_title_overlay',
1565 $overlay_id,
1566 $title_text,
1567 esc_html__( 'Playing:', 'wpstream' )
1568 );
1569 }
1570 }
1571
1572 /**
1573 * check if the we can add display the player
1574 *
1575 * @since 3.12
1576 * returns html of the player
1577 */
1578
1579 public function wpstream_check_if_player_can_dsplay($product_id){
1580 if ( is_user_logged_in() ) {
1581
1582 $term_list = wp_get_post_terms($product_id, 'product_type');
1583 $current_user = wp_get_current_user();
1584 $subscription_model = intval( get_option('wpstream_global_sub','')) ;
1585
1586 $product = wc_get_product($product_id);
1587 $product_type = $product->get_type();
1588
1589
1590 if($subscription_model==1){ // if we have Neflix mode
1591 if( $product_type=='subscription' ){ // if the product loaded is a subscription and we are on netflix mode
1592 return false;
1593 }
1594 if($this->wpstream_in_plugin_check_global_subscription_model($product_id)){
1595 return true;
1596 }
1597 }else{
1598 // ppv mode
1599
1600 if( $product_type=='subscription' ){
1601
1602 // $user_subscriptions = wcs_get_users_subscriptions($current_user->ID );
1603 // foreach ($user_subscriptions as $subscription) {
1604 // $subscription_status = $subscription->get_status();
1605 // echo "</br>*** Subscription ID $subscription->ID for User ID $current_user->ID has status: $subscription_status";
1606 // }
1607
1608
1609 if( wcs_user_has_subscription( $current_user->ID, $product_id ,'active') ) {
1610 // user has active subcription
1611 return true;
1612 }
1613
1614 }else{
1615 if( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id)){
1616 return true;
1617 }
1618 }
1619
1620
1621 }
1622 return false;
1623
1624 }
1625 return false;
1626
1627 }
1628
1629
1630
1631 /**
1632 * check if the we can add display the player - theme variant
1633 *
1634 * @since 3.12
1635 * returns html of the player
1636 */
1637 public function wpstream_check_if_player_can_dsplay_theme($product_id){
1638
1639 $post_type= get_post_type($product_id);
1640
1641
1642
1643 if($post_type=='wpstream_product_vod' || $post_type=='wpstream_product'){
1644 return true; // if we have free vod or live
1645 }
1646
1647
1648
1649 if ( is_user_logged_in() && $post_type==='product' ) {
1650
1651 $product = wc_get_product( $product_id );
1652 $product_type = $product->get_type();
1653 $possible_bundle = get_post_meta($product_id, 'wpstream_part_of_bundle',true);
1654
1655
1656
1657
1658
1659 $current_user = wp_get_current_user();
1660 $subscription_model = intval( get_option('wpstream_global_sub','')) ;
1661 // print 'subscription model '.$subscription_model.'</br>';
1662
1663 if($subscription_model==1){ // if we have Neflix mode
1664 if( $product_type=='subscription' ){ // if the product loaded is a subscription and we are on netflix mode
1665 return false;
1666 }
1667 if($this->wpstream_in_plugin_check_global_subscription_model($product_id)){
1668 return true;
1669 }
1670 }else{
1671 // ppv mode
1672 if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id) ){
1673 return true; //simple product bought
1674 }else if (function_exists('wcs_user_has_subscription') && wcs_user_has_subscription( $current_user->ID, $product_id ,'active') ){
1675 return true; // subscription boght
1676 }else if( get_post_type($product_id) =='product' &&
1677 intval($possible_bundle )!=0 &&
1678 wc_customer_bought_product( $current_user->user_email, $current_user->ID, $possible_bundle)
1679 ){
1680 return true; // part of a boght bundle
1681 }
1682 }
1683 // print ' fac return false </br>';
1684 return false;
1685
1686 }
1687 return false;
1688
1689 }
1690
1691
1692 /**
1693 * in plugin - check if global subscription model is enabled
1694 *
1695 * @since 3.12
1696 *
1697 */
1698 public function wpstream_in_plugin_check_global_subscription_model($product_id) {
1699
1700 // $selected_sub= get_post_meta($post->ID,'_wpstream_parent_sub',true);
1701 if( is_user_logged_in() && function_exists('wcs_user_has_subscription') ){
1702
1703 global $woocommerce;
1704 $current_user = wp_get_current_user();
1705
1706 $subscription_model = intval( get_option('wpstream_global_sub','')) ;
1707 $main_subscription = intval( get_option('wpstream_global_sub_id',''));
1708
1709 if($subscription_model==1){
1710 $selected_sub= get_post_meta($product_id,'_wpstream_parent_sub',true) ;
1711
1712 if( is_array($selected_sub) ){
1713
1714 // we have per product sub
1715 foreach($selected_sub as $key=>$subscrition_id ):
1716 if( wcs_user_has_subscription( $current_user->ID, $subscrition_id ,'active') ) {
1717 return true;
1718 }
1719 endforeach;
1720
1721 } else if($main_subscription!=0){
1722
1723 // if we have one main subscription
1724 if( wcs_user_has_subscription( $current_user->ID, $main_subscription ,'active') ) {
1725 return true;
1726 }
1727 }
1728
1729
1730 }
1731 return false;
1732
1733 }
1734 // there is no woo subscription or user not logged in
1735 return false;
1736 }
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746 /**
1747 *
1748 *
1749 *
1750 *
1751 * check if the user bought the product and display the player - TO REDo
1752 *
1753 * @since 3.0.1
1754 * returns html of the player
1755 *
1756 *
1757 *
1758 *
1759 *
1760 */
1761 public function wpstream_user_logged_in_product_already_bought($from_sh_id='') {
1762 if(function_exists('wpstream_remove_wpstream_filter')){
1763 return;
1764 }
1765 global $product;
1766 $product_id = $product->get_id();
1767 $current_user = wp_get_current_user();
1768
1769 if ( is_user_logged_in() ) {
1770
1771
1772 if($this->wpstream_check_if_player_can_dsplay($product_id) ){
1773
1774 echo '<div class="wpstream_player_wrapper "><div class="wpstream_player_container">';
1775
1776 $is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true));
1777 $term_list = wp_get_post_terms($product_id, 'product_type');
1778
1779
1780 if( $term_list[0]->name=='live_stream' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){
1781 $this->wpstream_live_event_player($product_id);
1782 }else if( $term_list[0]->name=='video_on_demand' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='no' ) ){
1783
1784 $this->wpstream_video_on_demand_player($product_id);
1785 }
1786 echo '</div></div>';
1787 }else{
1788
1789
1790 $term_list = wp_get_post_terms($product_id, 'product_type');
1791
1792 if( $term_list[0]->name=='subscription' ){
1793
1794 if( !wcs_user_has_subscription( $current_user->ID, $product_id ,'active') ) {
1795 $this->wpstream_display_no_buy_message('nobuy',$product_id);
1796 }
1797
1798 }else{
1799 $this->wpstream_display_no_buy_message('nobuy',$product_id);
1800 }
1801
1802
1803
1804 }
1805
1806
1807 }else{
1808
1809 $this->wpstream_display_no_buy_message('nolog',$product_id);
1810 }
1811 }
1812
1813
1814
1815
1816
1817 /**
1818 *
1819 *
1820 * check if the user bought the product and display the player - TO REDo
1821 *
1822 * @since 3.0.1
1823 * returns html of the player
1824 */
1825
1826 public function wpstream_chat_wrapper($product_id){
1827 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/templates/wpstream_chat_template.php';
1828 }
1829
1830
1831
1832
1833
1834
1835
1836
1837 /**
1838 * coonect to chat
1839 *
1840 * @since 1.12.2
1841 *
1842 */
1843
1844
1845
1846 public function wpstream_connect_to_chat($product_id){
1847 $current_user = wp_get_current_user();
1848 $userID = $current_user->ID;
1849 $user_login = $current_user->user_login;
1850
1851 $key='';
1852
1853 $chat_url = get_post_meta($product_id,'chat_url',true);
1854
1855
1856 wp_enqueue_script( 'sockjs-0.3.min' );
1857 wp_enqueue_script( 'emojione.min.js' );
1858 wp_enqueue_script( "jquery-effects-core");
1859 wp_enqueue_script( 'jquery.linkify.min.js');
1860 wp_enqueue_script( 'ripples.min.js');
1861 wp_enqueue_script( 'material.min.js');
1862 wp_enqueue_script( 'chat.js');
1863
1864
1865
1866 wp_enqueue_style( 'chat.css');
1867 wp_enqueue_style( 'ripples.css');
1868 wp_enqueue_style( 'emojione.min.css');
1869
1870
1871
1872
1873 if(!is_user_logged_in()){
1874 $user_login='';
1875 $chat_url='';
1876 }
1877
1878
1879 print '<script type="text/javascript">
1880 //<![CDATA[
1881 jQuery(document).ready(function(){
1882 username = "'.$user_login.'";
1883 key="'.$key.'";
1884
1885 });
1886 //]]>
1887 </script>';
1888
1889 }
1890
1891
1892 /**
1893 * display no buy Message
1894 *
1895 * @since 3.12.2
1896 *
1897 */
1898 public function wpstream_display_no_buy_message($log,$product_id) {
1899
1900 if($log=='sub_active'){
1901 $message= esc_html( get_option('wpstream_subscription_active','Your Subscription is Active.')) ;
1902 echo '<div class="wpstream_player_wrapper no_buy"><div class="wpstream_player_container">';
1903 echo '<div class="wpstream_notice"> '.$message.'</div>';
1904 echo '</div></div>';
1905 return;
1906
1907 }else if($log=='nolog'){
1908 $message= esc_html( get_option('wpstream_product_not_login','You must be logged in to watch this video.')) ;
1909 }else{
1910 $message =esc_html( get_option('wpstream_product_not_bought','You did not yet purchase this item.')) ;
1911 }
1912 $subscription_model = intval( get_option('wpstream_global_sub','')) ;
1913 if($subscription_model==1){
1914 $message =esc_html( get_option('wpstream_product_not_subscribe','You did not yet subscribe to this item.'));
1915 }
1916
1917
1918 if( get_post_type($product_id) == 'product' && $subscription_model==0 ){
1919 $product = wc_get_product($product_id);
1920 $term_list = wp_get_post_terms($product_id, 'product_type');
1921 $product_type = $product->get_type();
1922 $is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true));
1923
1924
1925
1926 if( $term_list[0]->name=='video_on_demand' || $term_list[0]->name=='live_stream' || $product_type=='subscription'){
1927
1928 echo '<div class="wpstream_player_wrapper no_buy"><div class="wpstream_player_container">';
1929 echo '<div class="wpstream_notice">'.$message.'</div>';
1930 echo '</div></div>';
1931
1932 }
1933
1934 }else if( get_post_type($product_id) == 'product' && $subscription_model==1 ){
1935 $term_list = wp_get_post_terms($product_id, 'product_type');
1936 if( $term_list[0]->name!=='simple'){
1937 echo '<div class="wpstream_player_wrapper no_buy"><div class="wpstream_player_container">';
1938 echo '<div class="wpstream_notice"> '.$message.'</div>';
1939 echo '</div></div>';
1940 }
1941 }
1942
1943
1944
1945
1946
1947
1948 }
1949
1950 /**
1951 * Get the video player logo URL.
1952 *
1953 * @param int $product_id Product ID.
1954 * @return mixed|string
1955 */
1956 public function wpstream_get_video_player_logo( $product_id ) {
1957 $is_streamify_user = $this->wpstream_is_streamify_user( $product_id );
1958 if ( $is_streamify_user ) {
1959 return WPSTREAM_PLUGIN_DIR_URL . 'img/wpstream-symbol-large.png';
1960 }
1961
1962 $logo = get_option( 'wpstream_player_logo', '' );
1963 if ( ! empty( $logo ) ) {
1964 return $logo;
1965 }
1966
1967 return '';
1968 }
1969
1970 /**
1971 * Get cached pack data or request fresh pack data
1972 *
1973 * @param bool $force_refresh Force a refresh of the cached data
1974 * @return array Pack data
1975 */
1976 private function wpstream_get_cached_pack_data( $force_refresh = false ) {
1977 $cached_data = get_transient( 'wpstream_user_pack_data' );
1978
1979 if ( $force_refresh || $cached_data === false ) {
1980 $fresh_data = $this->main->wpstream_live_connection->wpstream_request_pack_data_per_user('wpstream_get_cached_pack_data');
1981 set_transient( 'wpstream_user_pack_data', $fresh_data, 60);
1982
1983 return $fresh_data;
1984 }
1985
1986 return $cached_data;
1987 }
1988
1989 /*
1990 * Check if the user is on a basic subscription
1991 *
1992 * @param int $channel_id Channel ID
1993 * @return bool
1994 */
1995 public function wpstream_is_streamify_user( $channel_id ) {
1996 $is_basic_streaming = get_post_meta( $channel_id, 'basicStreaming', true );
1997 if ( $is_basic_streaming === '1' ) {
1998 return true;
1999 }
2000 return false;
2001 }
2002 }
2003