PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 4.11.1
WpStream – Live Streaming, Video on Demand, Pay Per View v4.11.1
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.11.1, at includes/class-wpstream-player.php

1,631 lines 78.1 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 public function __construct($plugin_main) {
19 $this->main = $plugin_main;
20
21 add_filter( 'the_content',array($this, 'wpstream_filter_the_title') );
22 add_action( 'woocommerce_before_single_product', array($this,'wpstream_user_logged_in_product_already_bought') );
23
24 add_action( 'wp_ajax_wpstream_player_check_status', array($this,'wpstream_player_check_status') );
25 add_action('wp_ajax_nopriv_wpstream_player_check_status', array($this,'wpstream_player_check_status'));
26
27 }
28
29
30
31
32
33
34 /**
35 *
36 * edited 4.0
37 *
38 * check player status
39 *
40 * @author cretu
41 */
42
43 public function wpstream_player_check_status(){
44 // did not add a nonce check here because this is a call done from the frontend
45 // and the page might be cached, so the nonce would not be valid
46 $channel_id = intval($_POST['channel_id']);
47
48
49 $transient_name = 'event_data_to_return_'. $channel_id;
50 $event_data_for_transient = get_transient( $transient_name );
51
52
53 $usefull_info =' get cache from transiet';
54 if ( false === $event_data_for_transient || $event_data_for_transient=='' ) { //ws || $hls_to_return==''
55 $notes = 'wpstream_player_check_status_note_from_js';
56 $event_status = $this->main->wpstream_live_connection->wpstream_check_event_status_api_call($channel_id,$notes);
57 $event_data_for_transient = $event_status;
58 $usefull_info =' no cache found';
59 set_transient($transient_name,$event_data_for_transient,45);
60 }
61
62
63 if( isset($event_data_for_transient['hls_playback_url']) && $event_data_for_transient['hls_playback_url']!=''){
64 // cleanup any previous echo before sending json
65 ob_end_clean();
66 echo json_encode( array(
67
68 'started' => 'yes',
69 'usefull_info' => $usefull_info,
70 'channel_id' => $channel_id,
71 'event_uri' => $event_data_for_transient['hls_playback_url'],
72 'live_conect_views' => $event_data_for_transient['stats_url'],
73 'chat_url' => $event_data_for_transient['chat_url'],
74 '$event_data_for_transient'=>$event_data_for_transient
75
76
77 ));
78 $usedfull_info =' ';
79 update_post_meta($channel_id,'stream_name',$event_data_for_transient['stream_name']);
80 update_post_meta($channel_id,'hls_key_retrieval_url',$event_data_for_transient['hls_key_retrieval_url']);
81 delete_transient( 'free_event_streamName_'.$event_data_for_transient['stream_name']);
82
83 }else{
84 // cleanup any previous echo before sending json
85 ob_end_clean();
86 echo json_encode( array(
87 'started' => 'no',
88 'usefull_info' => $usefull_info,
89 'server_id' => '',
90 'channel_id' => $channel_id,
91 'event_uri' => '',
92 'live_conect_views' => '',
93 'chat_url' => '',
94
95
96 ));
97
98 }
99
100 die();
101 }
102
103
104
105 /**
106 * Insert player in page
107 *
108 * @author cretu
109 */
110 public function wpstream_filter_the_title( $content ) {
111 if(function_exists('wpstream_remove_wpstream_filter')){
112 return $content;
113 }
114
115 if( is_singular('wpstream_product') || is_singular('wpstream_product_vod') ){
116 global $post;
117 $args=array('id'=>$post->ID);
118 $custom_content = $this->wpstream_insert_player_inpage($args);
119 $content = '<div class="wpestream_inserted_player">'.$custom_content.'</div>'.$content;
120 return $content;
121 }else{
122 return $content;
123 }
124 }
125
126 /**
127 * Insert player in page
128 *
129 * @author cretu
130 */
131
132 public function wpstream_insert_player_inpage($attributes, $content = null){
133 $product_id = '';
134 $return_string = '';
135 $attributes = shortcode_atts(
136 array(
137 'id' => 0,
138 ), $attributes) ;
139
140
141 if ( isset($attributes['id']) ){
142 $product_id=$attributes['id'];
143 }
144
145 if(intval($product_id)==0){
146 $product_id= $this->wpstream_player_retrive_first_id();
147 }
148
149 ob_start();
150
151 $this->wpstream_video_player_shortcode($product_id);
152 $return_string= ob_get_contents();
153 ob_end_clean();
154
155 return $return_string;
156 }
157
158
159
160
161 /**
162 * Video Player shortcode
163 *
164 * @author cretu
165 */
166
167 public function wpstream_video_player_shortcode($from_sh_id='') {
168 // disable cache in order to be able to check the nonce
169 if ( !defined( 'DONOTCACHEPAGE' ) ) {
170 define( 'DONOTCACHEPAGE', true );
171 }
172
173 wp_enqueue_script('video.min');
174 wp_enqueue_script('wpstream-player');
175
176 if ( is_user_logged_in() ) {
177 global $product;
178 $current_user = wp_get_current_user();
179 $product_id = intval($from_sh_id);
180 $term_list = wp_get_post_terms($product_id, 'product_type');
181 $possible_bundle = get_post_meta($product_id, 'wpstream_part_of_bundle', true);
182
183
184
185
186 if (
187
188 ( 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) ) ||
189 ( 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) ) ||
190 get_post_type($product_id)=='wpstream_product' ||
191 get_post_type($product_id)=='wpstream_product_vod' ){
192 global $product;
193 echo '<div class="wpstream_player_wrapper wpstream_player_shortcode"><div class="wpstream_player_container">';
194
195
196 if( get_post_type($product_id) == 'wpstream_product' ){
197 $this->wpstream_live_event_player($product_id);
198 }else if( get_post_type($product_id) == 'wpstream_product_vod' ){
199 $this->wpstream_video_on_demand_player($product_id);
200 }else{
201
202 $is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true));
203
204 if( $term_list[0]->name=='live_stream' || ( $term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){
205 $this->wpstream_live_event_player($product_id);
206 }else if( $term_list[0]->name=='video_on_demand' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='no' ) ){
207 $this->wpstream_video_on_demand_player($product_id);
208 }
209 }
210
211
212 echo '</div></div>';
213 }else{
214
215 if( get_post_type($product_id) == 'product' ){
216 echo '<div class="wpstream_player_wrapper wpstream_player_shortcode no_buy"><div class="wpstream_player_container">';
217 $message =esc_html( get_option('wpstream_product_not_bought','You did not yet purchase this item.')) ;
218 echo '<div class="wpstream_notice" style="background:#e16767;">'.esc_html($message).'</div>';
219 echo '</div></div>';
220 }
221 }
222
223
224 }else{
225
226 $product_id = intval($from_sh_id);
227 $term_list = wp_get_post_terms($product_id, 'product_type');
228
229 if( get_post_type($product_id) == 'product' && ($term_list[0]->name=='live_stream' || $term_list[0]->name=='video_on_demand') ){
230
231 echo '<div class="wpstream_player_wrapper wpstream_player_shortcode no_buy"><div class="wpstream_player_container">';
232 $message= esc_html( get_option('wpstream_product_not_login','You must be logged in to watch this video.')) ;
233
234
235 echo '<div class="wpstream_notice" style="background:#e16767;">'.esc_html($message).'</div>';
236 echo '</div></div>';
237 }elseif( get_post_type($product_id) == 'wpstream_product' ){
238 echo '<div class="wpstream_player_wrapper wpstream_player_shortcode"><div class="wpstream_player_container">';
239 $this->wpstream_live_event_player($product_id);
240 echo '</div></div>';
241 } else if( get_post_type($product_id) == 'wpstream_product_vod' ){
242 echo '<div class="wpstream_player_wrapper wpstream_player_shortcode"><div class="wpstream_player_container">';
243 $this->wpstream_video_on_demand_player($product_id);
244 echo '</div></div>';
245 }
246 }
247 }
248
249
250
251 /**
252 * Video Player shortcode - low latency
253 *
254 * @author cretu
255 */
256
257 public function wpstream_video_player_shortcode_low_latency($from_sh_id='') {
258 if ( !defined( 'DONOTCACHEPAGE' ) ) {
259 define( 'DONOTCACHEPAGE', true );
260 }
261
262 wp_enqueue_script('video.min');
263 wp_enqueue_script('wpstream-player');
264
265
266 if ( is_user_logged_in() ) {
267 global $product;
268 $current_user = wp_get_current_user();
269 $product_id = intval($from_sh_id);
270
271
272 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' ){
273 global $product;
274 echo '<div class="wpstream_player_wrapper wpstream_player_shortcode"><div class="wpstream_player_container">';
275
276
277 if( get_post_type($product_id) == 'wpstream_product' ){
278 $this->wpstream_live_event_player_low_latency($product_id);
279 }else{
280 $term_list = wp_get_post_terms($product_id, 'product_type');
281 $is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true));
282
283 if( $term_list[0]->name=='live_stream' || ( $term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){
284 $this->wpstream_live_event_player_low_latency($product_id);
285 }
286 }
287
288
289 echo '</div></div>';
290 }else{
291
292 if( get_post_type($product_id) == 'product' ){
293 echo '<div class="wpstream_player_wrapper wpstream_player_shortcode no_buy"><div class="wpstream_player_container">';
294
295 $message =esc_html( get_option('wpstream_product_not_bought','You did not yet purchase this item.')) ;
296 echo '<div class="wpstream_notice" style="background:#e16767;">'.$message.'</div>';
297 echo '</div></div>';
298 }
299 }
300
301
302 }else{
303 $product_id = intval($from_sh_id);
304 if( get_post_type($product_id) == 'wpstream_product' ){
305 $this->wpstream_live_event_player_low_latency($product_id);
306 }
307 }
308 }
309
310
311
312
313
314 /**
315 * Live Event Player
316 *
317 * @author cretu
318 */
319 function remove_http($url) {
320 $disallowed = array('http://', 'https://');
321 foreach($disallowed as $d) {
322 if(strpos($url, $d) === 0) {
323 return str_replace($d, '', $url);
324 }
325 }
326 return $url;
327 }
328
329 /**
330 * Get event settings
331 *
332 * @author cretu
333 */
334
335 function wpestream_return_event_settings($product_id){
336
337 $local_event_options = get_post_meta( $product_id, 'local_event_options', true);
338 $use_global_event_options = get_post_meta($product_id, 'use_global_event_options',true);
339 $is_local_event_options_enabled = is_array( $local_event_options ) || intval( $use_global_event_options ) === 1;
340
341 if( !$is_local_event_options_enabled ) {
342 $local_event_options = get_option('wpstream_user_streaming_global_channel_options') ;
343 }
344
345 return $local_event_options;
346 }
347
348
349
350 /**
351 * edited in 4.0
352 *
353 * Live Event Player
354 *
355 * @author cretu
356 */
357
358 function wpstream_live_event_player($channel_id,$poster_show='',$use_chat=''){
359 wp_enqueue_script('video.min');
360 wp_enqueue_script('wpstream-player');
361
362
363 $player_theme = $this->wpstream_get_player_theme( $channel_id );
364 $now = time().rand(0,1000000);
365 $overlay_video_div_id = "random_id_".$now;
366 // 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>';
367
368
369 $thumb_id = get_post_thumbnail_id($channel_id);
370 $thumb = wp_get_attachment_image_src($thumb_id,'small');
371 $usernamestream = esc_html ( get_option('wpstream_api_username','') );
372 $autoplay = true;
373
374 $event_settings = $this->wpestream_return_event_settings($channel_id);
375
376 $transient_name = 'event_data_to_return_'. $channel_id;
377 $event_status = get_transient( $transient_name );
378
379 if ( false === $event_status || $event_status=='' ) {
380 $notes = 'wpstream_live_event_player_note';
381 $event_status = $this->main->wpstream_live_connection-> wpstream_check_event_status_api_call($channel_id,$notes);
382 set_transient($transient_name, $event_status, 45);
383 }
384
385 $hls_playback_url = '';
386 $live_conect_views = '';
387
388 if(isset($event_status['status']) && $event_status['status']=='active'){
389 //live event
390 if(isset($event_status['hls_playback_url'])){
391 $hls_playback_url = $event_status['hls_playback_url'];
392
393 update_post_meta($channel_id,'stream_name',$event_status['stream_name']);
394 update_post_meta($channel_id,'hls_key_retrieval_url',$event_status['hls_key_retrieval_url']);
395 delete_transient( 'free_event_streamName_'.$event_status['stream_name']);
396
397 $live_conect_array = explode('live.streamer.wpstream.net',$hls_playback_url);
398 $live_conect_views = $live_conect_array[0].'live.streamer.wpstream.net';
399 $live_conect_views = $this->remove_http($live_conect_views);
400
401 }
402 if(isset($event_status['chat_url'])){
403 $chat_url = $event_status['chat_url'];
404 }
405
406 }else{
407 // event not live
408 }
409
410 if(isset($event_settings['autoplay']) && intval($event_settings['autoplay'])==0){
411 $autoplay=false;
412 }
413
414
415
416 $player_nonce = wp_create_nonce( 'wpstream_player_check_status_nonce' );
417 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 . '" > ';
418
419 $show_viewer_count = (
420 ( isset($event_settings['view_count']) && intval($event_settings['view_count']) == 1 )
421 || !isset($event_settings['view_count'])
422 );
423
424 echo '<div id="wpestream_live_counting" class="wpestream_live_counting" data-showviewercount="' . ($show_viewer_count ? '1' : '0') . '"></div>';
425
426 $show_wpstream_not_live_mess=' style="display:none;" ';
427 if(trim($hls_playback_url) ==''){
428
429 $show_wpstream_not_live_mess='';
430 }
431
432 $message_show= esc_html( get_option('wpstream_you_are_not_live','We are not live at this moment')) ;
433
434 if( function_exists('wpstream_theme_not_live_section' ) ) {
435 print wpstream_theme_not_live_section( $channel_id );
436 } else {
437 print '<div class="wpstream_not_live_mess" '.$show_wpstream_not_live_mess.' style="display: none">
438 <div class="wpstream_not_live_mess_back"></div>
439 <div class="wpstream_not_live_mess_mess">'.esc_html($message_show).'</div>
440 </div>';
441 }
442
443
444 $poster_data='';
445 if(isset($thumb[0])){
446 $poster_data=' poster="'.$thumb[0].'" ';
447 }
448 if($poster_show=='no'){
449 $poster_data='';
450 }
451
452 $is_muted=false;
453 if( isset($event_settings['mute']) && intval($event_settings['mute'])==1){
454 $is_muted=true;
455 }
456 // override $is_muted and $autoplay here - for testing
457 // $autoplay = true;
458 // $is_muted = false;
459
460 $autoplay_str = $autoplay ? 'autoplay' : '';
461 $is_muted_str = $is_muted ? 'muted' : '';
462
463 $video_trailer = '';
464 $trailer_attachment_id = intval (get_post_meta( $channel_id, 'video_trailer', true ));
465 $video_trailer = '';
466 $video_trailer_type = '';
467 $has_trailer_class = '';
468 if($trailer_attachment_id!=0) {
469 $video_trailer = wp_get_attachment_url( $trailer_attachment_id );
470 $attachment_metadata = wp_get_attachment_metadata($trailer_attachment_id);
471 if( isset ($attachment_metadata['mime_type']) ) {
472 $video_trailer_type = $attachment_metadata['mime_type'];
473 }
474 $poster_data=''; // cancel poster for theme
475 $has_trailer_class='wpstream_theme_player_has_trailer';
476 }
477
478 // override trailer url here - for testing
479 // $video_trailer = '';
480 // $video_trailer = '/wp-content/uploads/2023/10/production-ID_4608975.mp4';
481 // $video_trailer = '/wp-content/uploads/2023/10/ultrawide.mp4';
482
483
484
485 $player_logo_position = get_option('wpstream_player_logo_position');
486 $player_logo_position_class = '';
487 $player_logo_horizontal_position = '';
488 if( $player_logo_position && $player_logo_position != '' ){
489 $player_logo_position_class = 'logo-' . explode( '-', $player_logo_position )[0];
490 $player_logo_horizontal_position = 'logo-' . explode( '-', $player_logo_position )[1];
491 }
492 // echo'
493 // <div class="wpstream-video-container">
494 // <div id="wpstream-pre-load-spinner" class="wpstream-pre-load-spinner"></div>
495 // <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.'>
496 // </video>
497 // </div>';
498 echo '<div class="wpstream-pre-load-spinner"></div>';
499 echo'
500 <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.'>
501
502 </video>';
503 if ($video_trailer){
504 print '<div class="wpstream_theme_trailer_wrapper">';
505 print '<div id="wpstream_live_video_play_trailer_btn_' . $now . '" style="display: none;" class="wpstream_video_on_demand_play_trailer">
506 <svg width="30" height="24" viewBox="0 0 30 24" fill="none" xmlns="http://www.w3.org/2000/svg">
507 <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"/>
508 </svg>
509 '.esc_html__('Play Trailer', 'wpstream').'</div>';
510 print '<div id="wpstream_live_video_mute_trailer_btn_' . $now . '" style="display: none;" class="wpstream_video_on_demand_mute_trailer">
511 <svg width="37" height="36" viewBox="0 0 37 36" fill="none" xmlns="http://www.w3.org/2000/svg">
512 <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"/>
513 </svg>
514
515 </div>';
516 print '<div id="wpstream_live_video_unmute_trailer_btn_' . $now . '" style="display: none;" class="wpstream_video_on_demand_unmute_trailer">
517 <svg width="33" height="32" viewBox="0 0 33 32" fill="none" xmlns="http://www.w3.org/2000/svg">
518 <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"/>
519 </svg>
520 </div>';
521 print '</div>';
522 }
523 print '<script type="text/javascript">
524 //<![CDATA[
525 jQuery(document).ready(function(){
526 wpstream_player_initialize({
527 titleOverlayElementId:"'.$overlay_video_div_id.'",
528 videoElementId: "'.$now.'",
529 trailerUrl: "'.$video_trailer.'",
530 contentUrl: "'.$hls_playback_url.'",
531 statsUri: "'.$live_conect_views.'",
532 autoplay: '.var_export($autoplay, true).',
533 muted: '.var_export($is_muted, true).',
534 playTrailerButtonElementId: "wpstream_live_video_play_trailer_btn_'.$now.'",
535 muteTrailerButtonElementId: "wpstream_live_video_mute_trailer_btn_'.$now.'",
536 unmuteTrailerButtonElementId: "wpstream_live_video_unmute_trailer_btn_'.$now.'",
537 });
538 });
539 //]]>
540 </script>';
541 print '</div>';
542
543
544 if(trim($hls_playback_url) ==''){
545 // $show_wpstream_not_live_mess='';
546 }else{
547 print '<script type="text/javascript">
548 //<![CDATA[
549 jQuery(document).ready(function(){
550 var player_wrapper = jQuery(".wpstream_live_player_wrapper");
551 wpstream_read_websocket_info("'.$channel_id.'","wpstream_live_player_wrapper'.$now.'", player_wrapper ,"'.$chat_url.'", "'.$hls_playback_url.'");
552 });
553 //]]>
554 </script>';
555 }
556
557
558 if($use_chat=="yes"){
559 $this->wpstream_connect_to_chat($channel_id);
560 }
561
562 usleep (10000);
563
564 }
565
566
567
568
569
570 /**
571 *
572 * Edited in 4.0
573 *
574 *
575 * Live Event Player
576 *
577 * @author cretu
578 */
579
580 function wpstream_live_event_player_low_latency($channel_id,$poster_show='',$use_chat=''){
581 $usernamestream = esc_html ( get_option('wpstream_api_username','') );
582 $thumb_id = get_post_thumbnail_id($channel_id);
583 $thumb = wp_get_attachment_image_src($thumb_id,'small');
584
585 $event_settings = $this->wpestream_return_event_settings($channel_id);
586 $notes = 'wpstream_live_event_player_low_latency_note';
587 $event_status = $this->main->wpstream_live_connection-> wpstream_check_event_status_api_call($channel_id,$notes);
588 $hls_playback_url = '';
589 $live_conect_views = '';
590 $now = time().rand(0,10);
591
592
593
594 if(isset($event_status['status']) && $event_status['status']=='active'){
595 //live event
596 if(isset($event_status['sldp_playback_url'])){
597 $hls_playback_url = $event_status['sldp_playback_url'];
598
599 $live_conect_array = explode('live.streamer.wpstream.net',$hls_playback_url);
600 $live_conect_views = $live_conect_array[0].'live.streamer.wpstream.net';
601 $live_conect_views = $this->remove_http($live_conect_views);
602
603 }
604 if(isset($event_status['chat_url'])){
605 $chat_url =$event_status['chat_url'];
606 }
607
608 }else{
609 // event not live
610 }
611
612
613
614
615 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.'" > ';
616
617
618 if( ( isset($event_settings['view_count'] ) && intval($event_settings['view_count'])==1 ) || !isset($event_settings['view_count']) ){
619 echo '<div id="wpestream_live_counting" class="wpestream_live_counting"></div>';
620 }
621
622 $show_wpstream_not_live_mess=' style="display:none;" ';
623 if(trim($hls_playback_url) ==''){
624 $show_wpstream_not_live_mess='';
625 }
626
627 $message_show= esc_html( get_option('wpstream_you_are_not_live','We are not live at this moment')) ;
628 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>';
629
630
631 $poster_data=' poster="'.$thumb[0].'" ';
632 if($poster_show=='no'){
633 $poster_data='';
634 }
635
636
637 $is_muted='';
638 if( isset($event_settings['mute']) && intval($event_settings['mute'])==1){
639 $is_muted=' muted ';
640 }
641
642
643 $autoplay='autoplay';
644 if(isset($event_settings['autoplay']) && intval($event_settings['autoplay'])==0){
645 $autoplay='';
646 }
647
648 echo'
649 <div iccd="player" id="wpstream-video'.$now.'" '.$poster_data.' '.$is_muted.' class="" >
650 </div>';
651
652 print '<script type="text/javascript">
653 //<![CDATA[
654 jQuery(document).ready(function(){
655 var low_latencyid="wpstream-video'.$now.'";
656 document.addEventListener("DOMContentLoaded", initPlayer(low_latencyid, "'.$hls_playback_url.'","'.$is_muted.'","'.$autoplay.'" ) ); ';
657 print'});
658 //]]>
659 </script>';
660
661
662
663 if(trim($hls_playback_url) ==''){
664 // $show_wpstream_not_live_mess='';
665 }else{
666 print '<script type="text/javascript">
667 //<![CDATA[
668 jQuery(document).ready(function(){
669 var player_wrapper = jQuery(".wpstream_live_player_wrapper");
670 wpstream_read_websocket_info("'.$channel_id.'","wpstream_live_player_wrapper'.$now.'", player_wrapper ,"'.$chat_url.'", "'.$hls_playback_url.'");
671 });
672 //]]>
673 </script>';
674 }
675
676
677 if($use_chat=="yes"){
678 $this->wpstream_connect_to_chat($channel_id);
679 }
680
681 usleep (10000);
682
683 }
684
685
686
687
688
689 /*
690 *
691 * Request HLS player
692 *
693 *
694 *
695 */
696 public function wpstream_request_video_on_demand_hls_player($video_name,$product_id){
697 if($video_name==''){
698 return '';
699 }
700
701 $transient_name = 'wpstream_video_on_demand_'.$video_name;
702 $hls_to_return = get_transient( $transient_name );
703 $hls_to_return = false;
704
705
706 if($hls_to_return==false){
707
708 $access_token = $this->main->wpstream_live_connection->wpstream_get_token();
709 $url = 'video/info';
710
711 //corsorigin de check
712 $local_event_options = get_option('wpstream_user_streaming_global_channel_options') ;
713 $domain = parse_url ( get_site_url() );
714 $domain_scheme = 'http';
715 if(is_ssl()){
716 $domain_scheme='https';
717 }
718
719
720 $wpstream_vod_domain_lock = intval( get_option('wpstream_vod_domain_lock','') ) ;
721 $corsorigin='*';
722 if($wpstream_vod_domain_lock !== 0 ){
723 $corsorigin=$domain_scheme.'://'.$domain['host'];
724 }
725
726
727 $is_encrypt="false";
728 $wpstream_vod_encrypt = intval( get_option('wpstream_vod_encrypt','') ) ;
729 if( intval( $wpstream_vod_encrypt ) ==1 ){
730 $is_encrypt="true";
731 }
732
733 $hlsKeysUrlPrefix = get_site_url().'?wpstream_voddrm=';
734 $encrypt = $is_encrypt;
735 $debugDrm = false;
736
737 $curl_post_fields=array(
738 'access_token' => $access_token,
739 'name' => $video_name,
740 'corsOrigin' => $corsorigin,
741 'encryptHls' => $encrypt,
742 'hlsKeysUrlPrefix' => $hlsKeysUrlPrefix,
743 'debugDrm' => $debugDrm,
744 );
745
746
747 $curl_response = $this->main->wpstream_live_connection->wpstream_baker_do_curl_base($url,$curl_post_fields);
748 $curl_response_decoded = json_decode($curl_response,JSON_OBJECT_AS_ARRAY);
749
750 if($curl_response_decoded['success']){
751 set_transient( $transient_name, $curl_response_decoded['hlsUrl'] ,300);
752 $hls_to_return = $curl_response_decoded['hlsUrl'];
753 if( isset($curl_response_decoded['hlsDecryptionKey']) && isset($curl_response_decoded['hlsDecryptionKeyIndex']) ){
754 update_post_meta($product_id,'hlsDecryptionKey',$curl_response_decoded['hlsDecryptionKey']);
755 update_post_meta($product_id,'hlsDecryptionKeyIndex',$curl_response_decoded['hlsDecryptionKeyIndex']);
756 }else{
757 delete_post_meta($product_id,'hlsDecryptionKey');
758 delete_post_meta($product_id,'hlsDecryptionKeyIndex');
759 }
760
761 }else{
762 return '';
763 }
764
765 }
766
767 return $hls_to_return;
768
769 }
770
771 function wpstream_get_player_theme( $channel_id = null ) {
772 $player_theme = get_option('wpstream_video_player_theme');
773 $is_streamify_user = $this->wpstream_is_streamify_user( $channel_id );
774 if ( !empty($player_theme) && !$is_streamify_user ) {
775 $this->wpstream_enqueue_player_theme_style( $player_theme );
776 return 'vjs-theme-' . $player_theme;
777 }
778
779 return '';
780 }
781
782 function wpstream_enqueue_player_theme_style( $player_theme ) {
783 if ( $player_theme != 'default' ) {
784 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');
785
786 }
787 }
788
789
790
791 /**
792 * VODPlayer uri details
793 *
794 * @author cretu
795 */
796 public function wpstream_video_on_demand_player_uri_request($product_id){
797
798 $wpstream_data_setup = ' data-setup="{}" ';
799
800 /* free_video_type
801 * 1 - free live channel
802 * 2 - free video encrypted
803 * 3 - free video -not encrypted
804 */
805
806 $post_type = get_post_type($product_id);
807 $free_video_type = intval( get_post_meta($product_id, 'wpstream_product_type', true));
808 if( ( $post_type =='wpstream_product_vod' && $free_video_type==2 ) || get_post_type($product_id)=='product' ){
809
810 /*
811 * IF vide is encrypted- readed from vod,streaner
812 *
813 */
814
815
816 $video_type = 'application/x-mpegURL';
817 $video_path = get_post_meta($product_id,'_movie_url',true);
818 if(get_post_type($product_id)=='wpstream_product_vod'){
819 $video_path = esc_html(get_post_meta($product_id, 'wpstream_free_video', true));
820 }
821 $video_path_final = $this->wpstream_request_video_on_demand_hls_player($video_path,$product_id);
822
823
824 }else if( $post_type =='wpstream_product_vod' && $free_video_type==3 ){
825
826 /* Video is unecrypted - read from local or youtube / vimeo
827 */
828
829 $video_type = 'video/mp4';
830 $video_path_final=esc_html(get_post_meta($product_id, 'wpstream_free_video_external', true));
831 wp_enqueue_script('youtube.min');
832 }
833
834 $return_array = array();
835 $return_array['video_path_final'] = $video_path_final;
836 $return_array['wpstream_data_setup']= $wpstream_data_setup;
837 $return_array['video_type'] = $video_type;
838 $return_array['free_video_type'] = $free_video_type;
839 $return_array['post_type'] = $post_type ;
840 return $return_array;
841 }
842
843
844
845 /**
846 * VODPlayer url
847 *
848 * @author cretu
849 */
850
851 public function wpstream_video_on_demand_player($product_id){
852 wp_enqueue_script('video.min');
853 wp_enqueue_script('wpstream-player');
854
855 $player_theme = $this->wpstream_get_player_theme();
856
857 $uri_details = $this->wpstream_video_on_demand_player_uri_request($product_id);
858 $video_path_final = $uri_details['video_path_final'];
859 $wpstream_data_setup = $uri_details['wpstream_data_setup'];
860 $video_type = $uri_details['video_type'];
861 $now = time().rand(0,1000000);
862
863 $overlay_video_div_id = "random_id_".$now;
864 $this->wpstream_render_vod_title_overlay(
865 $overlay_video_div_id,
866 get_the_title($product_id)
867 );
868
869 $thumb_id = get_post_thumbnail_id($product_id);
870 $thumb = wp_get_attachment_image_src($thumb_id,'small');
871 $usernamestream = esc_html ( get_option('wpstream_api_username','') );
872
873 $poster_thumb = '';
874 if(isset($thumb[0])){
875 $poster_thumb=$thumb[0];
876 }
877
878 $hlsDecryptionKey = get_post_meta($product_id,'hlsDecryptionKey',true);
879 $hlsDecryptionKeyIndex = get_post_meta($product_id,'hlsDecryptionKeyIndex',true);
880
881
882 $pack = $this->main->quota_manager->get_live_quota_data( 'wpstream_video_on_demand_player' );
883
884
885
886 $trailer_attachment_id = intval (get_post_meta( $product_id, 'video_trailer', true ));
887 $video_trailer = '';
888 $video_trailer_type = '';
889 if($trailer_attachment_id!=0) {
890 $video_trailer = wp_get_attachment_url( $trailer_attachment_id );
891 $attachment_metadata = wp_get_attachment_metadata($trailer_attachment_id);
892 if( isset ($attachment_metadata['mime_type']) ) {
893 $video_trailer_type = $attachment_metadata['mime_type'];
894 }
895 }
896
897 // override trailer setup here (for testing)
898 // $trailer_attachment_id = 1;
899 // $video_trailer = '/wp-content/uploads/2023/10/production-ID_4608975.mp4';
900 // $video_trailer = '/wp-content/uploads/2023/10/ultrawide.mp4';
901
902 // If the video is self hosted or external, we should let the user see it
903 $video_type = intval( get_post_meta($product_id, 'wpstream_product_type', true));
904
905
906 if ( (isset($pack['available_data_mb']) && $pack['available_data_mb']>0) || $video_type === 3 ) {
907
908 if($video_path_final==''){
909 if( $uri_details['post_type']=='wpstream_product_vod' && $uri_details['free_video_type']==3 ){
910 }else{
911 print '<div class="wpstream_vod_notice">This video does not exist or it has been deleted!</div>';
912 }
913
914 }
915
916 // TODO (crerem) populate these from VOD settings
917 $autoplay = false;
918 $muted = false;
919
920 $wpstream_vod_start_muted = intval ( get_option('wpstream_vod_start_muted','') );
921 if($wpstream_vod_start_muted===1){
922 $muted=true;
923 }
924 $wpstream_vod_autoplay = intval ( get_option('wpstream_vod_autoplay','') );
925 if($wpstream_vod_autoplay===1){
926 $autoplay=true;
927 }
928
929 $poster_data = 'poster="'.esc_url($poster_thumb).'"';
930 $has_trailer_class='';
931 if($trailer_attachment_id !=0){
932 $poster_data=''; // cancel poster for theme
933 $has_trailer_class='wpstream_theme_player_has_trailer';
934 }
935
936 $player_logo_position = get_option('wpstream_player_logo_position');
937 $player_logo_position_class = '';
938 $player_logo_horizontal_position = '';
939 if( $player_logo_position && $player_logo_position!='' ){
940 $player_logo_position_class = 'logo-' . explode( '-', $player_logo_position )[0];
941 $player_logo_horizontal_position = 'logo-' . explode( '-', $player_logo_position )[1];
942 }
943
944 $captionsUrl = get_post_meta( $product_id, 'wpstream_closed_captions_file', true );
945
946 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.'" playsinline preload="auto"
947 '. $poster_data.' '.$wpstream_data_setup.'>
948 <p class="vjs-no-js">
949 To view this video please enable JavaScript, and consider upgrading to a web browser that
950 <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>
951 </p>
952 </video>';
953
954 if($trailer_attachment_id !=0){
955 print '<div class="wpstream_theme_trailer_wrapper">';
956 print '<div id="wpstream_video_on_demand_play_trailer_btn_' . $now . '" class="wpstream_video_on_demand_play_trailer">
957 <svg width="30" height="24" viewBox="0 0 30 24" fill="none" xmlns="http://www.w3.org/2000/svg">
958 <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"/>
959 </svg>
960 '.esc_html__('Play Trailer','wpstream').'</div>';
961
962 print '<div class="wpstream_video_on_demand_play_video_wrapper" id="wpstream_video_on_demand_play_video_btn_' . $now . '" >
963 <div class="wpstream_video_on_demand_play_video">
964 <svg width="29" height="30" viewBox="0 0 29 30" fill="none" xmlns="http://www.w3.org/2000/svg">
965 <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"/>
966 </svg>
967 </div>
968 '.esc_html__('Play Video','wpstream').'
969 </div>';
970
971
972
973 print '<div id="wpstream_video_on_demand_mute_trailer_btn_' . $now . '" class="wpstream_video_on_demand_mute_trailer">
974
975 <svg width="37" height="36" viewBox="0 0 37 36" fill="none" xmlns="http://www.w3.org/2000/svg">
976 <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"/>
977 </svg>
978 </div>';
979 print '<div id="wpstream_video_on_demand_unmute_trailer_btn_' . $now . '" class="wpstream_video_on_demand_unmute_trailer">
980 <svg width="33" height="32" viewBox="0 0 33 32" fill="none" xmlns="http://www.w3.org/2000/svg">
981 <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"/>
982 </svg>
983
984 </div>';
985 print '<script type="text/javascript">
986 //<![CDATA[
987 jQuery(document).ready(function(){
988 console.log("wpstream_video_on_demand_player 886");
989 wpstream_player_initialize_vod({
990 titleOverlayElementId:"'.$overlay_video_div_id.'",
991 videoElementId: "wpstream-video-vod-'.$now.'",
992 trailerUrl: "'.$video_trailer.'",
993 videoUrl: "'.$video_path_final.'",
994 autoplay: '.var_export($autoplay, true).',
995 muted: '.var_export($muted, true).',
996 captionsUrl: "' . esc_js( $captionsUrl ) . '",
997 playTrailerButtonElementId: "wpstream_video_on_demand_play_trailer_btn_'.$now.'",
998 muteTrailerButtonElementId: "wpstream_video_on_demand_mute_trailer_btn_'.$now.'",
999 unmuteTrailerButtonElementId: "wpstream_video_on_demand_unmute_trailer_btn_'.$now.'",
1000 playVideoButtonElementId: "wpstream_video_on_demand_play_video_btn_'.$now.'",
1001 playerLogoSettings: {
1002 image: "'. $this->wpstream_get_video_player_logo( $product_id ) . '",
1003 position: "' . esc_html( get_option('wpstream_player_logo_position','top-right') ) . '",
1004 opacity: ' . ( intval ( esc_html( get_option('wpstream_player_logo_opacity','100') ) ) / 100 ) . ',
1005 width: 100,
1006 height: "auto",
1007 padding: 10,
1008 },
1009 });
1010 });
1011 //]]>
1012 </script>';
1013 print '</div>';
1014 }
1015 else {
1016 print '<script type="text/javascript">
1017 //<![CDATA[
1018 jQuery(document).ready(function(){
1019
1020 console.log("wpstream_video_on_demand_player 907");
1021
1022 wpstream_player_initialize_vod({
1023 titleOverlayElementId:"'.$overlay_video_div_id.'",
1024 videoElementId: "wpstream-video-vod-'.$now.'",
1025 videoUrl: "'.$video_path_final.'",
1026 autoplay: '.var_export($autoplay, true).',
1027 muted: '.var_export($muted, true).',
1028 captionsUrl: "' . esc_js( $captionsUrl ) . '",
1029 playerLogoSettings: {
1030 image: "'. $this->wpstream_get_video_player_logo( $product_id ) . '",
1031 position: "' . esc_html( get_option('wpstream_player_logo_position','top-right') ) . '",
1032 opacity: ' . ( intval ( esc_html( get_option('wpstream_player_logo_opacity','100') ) ) / 100 ) . ',
1033 width: 100,
1034 height: "auto",
1035 padding: 10,
1036 }
1037 });
1038 });
1039 //]]>
1040 </script>';
1041 }
1042 }else{
1043 print '<div class="wpstream_insuficent_res">'.esc_html__('Insufficient resources to stream this title','wpstream').'</div>';
1044 }
1045
1046 }
1047
1048
1049
1050 /**
1051 * VODPlayer url - only trailer - used in theme
1052 *
1053 * @author cretu
1054 */
1055 public function wpstream_video_on_demand_player_only_trailer($product_id){
1056 wp_enqueue_script('video.min');
1057 wp_enqueue_script('wpstream-player');
1058
1059
1060 $player_theme = $this->wpstream_get_player_theme();
1061 $now = time().rand(0,1000000);
1062 $overlay_video_div_id = "random_id_".$now;
1063 $this->wpstream_render_vod_title_overlay(
1064 $overlay_video_div_id,
1065 get_the_title($product_id)
1066 );
1067
1068
1069
1070 $thumb_id = get_post_thumbnail_id($product_id);
1071 $thumb = wp_get_attachment_image_src($thumb_id,'small');
1072 $usernamestream = esc_html ( get_option('wpstream_api_username','') );
1073
1074 $poster_thumb = '';
1075 if(isset($thumb[0])){
1076 $poster_thumb=$thumb[0];
1077 }
1078
1079
1080 $trailer_attachment_id = intval (get_post_meta( $product_id, 'video_trailer', true ));
1081 $video_trailer = '';
1082 $video_trailer_type = '';
1083 if($trailer_attachment_id!=0) {
1084 $video_trailer = wp_get_attachment_url( $trailer_attachment_id );
1085 $attachment_metadata = wp_get_attachment_metadata($trailer_attachment_id);
1086 if(isset($attachment_metadata['mime_type'])){
1087 $video_trailer_type = $attachment_metadata['mime_type'];
1088 }
1089
1090 }
1091
1092
1093 $autoplay = false;
1094 $muted = false;
1095
1096 if( intval ( get_option('wpstream_vod_start_muted','') ) === 1){
1097 $muted = true;
1098 }
1099 if( intval ( get_option('wpstream_vod_autoplay','') ) === 1 ){
1100 $autoplay = true;
1101 }
1102 $video_path_final='';
1103 $has_trailer_class='wpstream_theme_player_has_trailer';
1104
1105 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.'" playsinline preload="auto"
1106 >
1107 <p class="vjs-no-js">
1108 To view this video please enable JavaScript, and consider upgrading to a web browser that
1109 <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>
1110 </p>
1111 </video>';
1112
1113 if($trailer_attachment_id !=0){
1114 print '<div class="wpstream_theme_trailer_wrapper">';
1115 print '<div id="wpstream_video_on_demand_play_trailer_btn_' . $now . '" class="wpstream_video_on_demand_play_trailer">
1116 <svg width="30" height="24" viewBox="0 0 30 24" fill="none" xmlns="http://www.w3.org/2000/svg">
1117 <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"/>
1118 </svg>
1119 '.esc_html__('Play Trailer','wpstream').'
1120 </div>';
1121 print '<div id="wpstream_video_on_demand_mute_trailer_btn_' . $now . '" class="wpstream_video_on_demand_mute_trailer">
1122 <svg width="37" height="36" viewBox="0 0 37 36" fill="none" xmlns="http://www.w3.org/2000/svg">
1123 <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"/>
1124 </svg>
1125
1126
1127 </div>';
1128 print '<div id="wpstream_video_on_demand_unmute_trailer_btn_' . $now . '" class="wpstream_video_on_demand_unmute_trailer">
1129 <svg width="33" height="32" viewBox="0 0 33 32" fill="none" xmlns="http://www.w3.org/2000/svg">
1130 <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"/>
1131 </svg>
1132
1133 </div>';
1134 print '<script type="text/javascript">
1135 //<![CDATA[
1136 jQuery(document).ready(function(){
1137
1138 console.log("wpstream_video_on_demand_player trailer 995");
1139
1140 wpstream_player_initialize_vod({
1141 titleOverlayElementId:"'.$overlay_video_div_id.'",
1142 videoElementId: "wpstream-video-vod-'.$now.'",
1143 trailerUrl: "'.$video_trailer.'",
1144 autoplay: '.var_export($autoplay, true).',
1145 muted: '.var_export($muted, true).',
1146 captionsUrl: "' . esc_js( get_post_meta( $product_id, 'wpstream_closed_captions_file', true ) ) . '",
1147 playTrailerButtonElementId: "wpstream_video_on_demand_play_trailer_btn_'.$now.'",
1148 muteTrailerButtonElementId: "wpstream_video_on_demand_mute_trailer_btn_'.$now.'",
1149 unmuteTrailerButtonElementId: "wpstream_video_on_demand_unmute_trailer_btn_'.$now.'",
1150 // playerLogoSettings: {
1151 // image: "'. $this->wpstream_get_video_player_logo( get_the_ID() ) . '",
1152 // position: "' . esc_html( get_option('wpstream_player_logo_position','top-right') ) . '",
1153 // opacity: ' . ( intval ( esc_html( get_option('wpstream_player_logo_opacity','100') ) ) / 100 ) . ',
1154 // width: 100,
1155 // height: "auto",
1156 // padding: 10,
1157 // },
1158 });
1159 });
1160 //]]>
1161 </script>';
1162 print '</div>';
1163 }
1164 else {
1165 //just show the poster or don't show anything; no player needed
1166 }
1167
1168 }
1169
1170
1171
1172 /**
1173 *
1174 * edited 4.0
1175 *
1176 * Retreive username for vod path
1177 *
1178 * @author cretu
1179 */
1180 private function wpstream_retrive_username(){
1181
1182 return get_option('wpstream_api_username_from_token');
1183 }
1184
1185 /**
1186 * Render title overlay via action hook.
1187 *
1188 * @param string $overlay_id Overlay element id.
1189 * @param string $title_text Title text.
1190 */
1191 private function wpstream_render_vod_title_overlay( $overlay_id, $title_text ) {
1192 if ( has_action( 'wpstream_vod_title_overlay' ) ) {
1193 do_action(
1194 'wpstream_vod_title_overlay',
1195 $overlay_id,
1196 $title_text,
1197 esc_html__( 'Playing:', 'wpstream' )
1198 );
1199 }
1200 }
1201
1202 /**
1203 * check if the we can add display the player
1204 *
1205 * @since 3.12
1206 * returns html of the player
1207 */
1208
1209 public function wpstream_check_if_player_can_dsplay($product_id){
1210 if ( is_user_logged_in() ) {
1211
1212 $term_list = wp_get_post_terms($product_id, 'product_type');
1213 $current_user = wp_get_current_user();
1214 $subscription_model = intval( get_option('wpstream_global_sub','')) ;
1215
1216 $product = wc_get_product($product_id);
1217 $product_type = $product->get_type();
1218
1219
1220 if($subscription_model==1){ // if we have Neflix mode
1221 if( $product_type=='subscription' ){ // if the product loaded is a subscription and we are on netflix mode
1222 return false;
1223 }
1224 if($this->wpstream_in_plugin_check_global_subscription_model($product_id)){
1225 return true;
1226 }
1227 }else{
1228 // ppv mode
1229
1230 if( $product_type=='subscription' ){
1231
1232 // $user_subscriptions = wcs_get_users_subscriptions($current_user->ID );
1233 // foreach ($user_subscriptions as $subscription) {
1234 // $subscription_status = $subscription->get_status();
1235 // echo "</br>*** Subscription ID $subscription->ID for User ID $current_user->ID has status: $subscription_status";
1236 // }
1237
1238
1239 if( wcs_user_has_subscription( $current_user->ID, $product_id ,'active') ) {
1240 // user has active subcription
1241 return true;
1242 }
1243
1244 }else{
1245 if( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id)){
1246 return true;
1247 }
1248 }
1249
1250
1251 }
1252 return false;
1253
1254 }
1255 return false;
1256
1257 }
1258
1259
1260
1261 /**
1262 * check if the we can add display the player - theme variant
1263 *
1264 * @since 3.12
1265 * returns html of the player
1266 */
1267 public function wpstream_check_if_player_can_dsplay_theme($product_id){
1268
1269 $post_type= get_post_type($product_id);
1270
1271
1272
1273 if($post_type=='wpstream_product_vod' || $post_type=='wpstream_product'){
1274 return true; // if we have free vod or live
1275 }
1276
1277
1278
1279 if ( is_user_logged_in() && $post_type==='product' ) {
1280
1281 $product = wc_get_product( $product_id );
1282 $product_type = $product->get_type();
1283 $possible_bundle = get_post_meta($product_id, 'wpstream_part_of_bundle',true);
1284
1285
1286
1287
1288
1289 $current_user = wp_get_current_user();
1290 $subscription_model = intval( get_option('wpstream_global_sub','')) ;
1291 // print 'subscription model '.$subscription_model.'</br>';
1292
1293 if($subscription_model==1){ // if we have Neflix mode
1294 if( $product_type=='subscription' ){ // if the product loaded is a subscription and we are on netflix mode
1295 return false;
1296 }
1297 if($this->wpstream_in_plugin_check_global_subscription_model($product_id)){
1298 return true;
1299 }
1300 }else{
1301 // ppv mode
1302 if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id) ){
1303 return true; //simple product bought
1304 }else if (function_exists('wcs_user_has_subscription') && wcs_user_has_subscription( $current_user->ID, $product_id ,'active') ){
1305 return true; // subscription boght
1306 }else if( get_post_type($product_id) =='product' &&
1307 intval($possible_bundle )!=0 &&
1308 wc_customer_bought_product( $current_user->user_email, $current_user->ID, $possible_bundle)
1309 ){
1310 return true; // part of a boght bundle
1311 }
1312 }
1313 // print ' fac return false </br>';
1314 return false;
1315
1316 }
1317 return false;
1318
1319 }
1320
1321
1322 /**
1323 * in plugin - check if global subscription model is enabled
1324 *
1325 * @since 3.12
1326 *
1327 */
1328 public function wpstream_in_plugin_check_global_subscription_model($product_id) {
1329
1330 // $selected_sub= get_post_meta($post->ID,'_wpstream_parent_sub',true);
1331 if( is_user_logged_in() && function_exists('wcs_user_has_subscription') ){
1332
1333 global $woocommerce;
1334 $current_user = wp_get_current_user();
1335
1336 $subscription_model = intval( get_option('wpstream_global_sub','')) ;
1337 $main_subscription = intval( get_option('wpstream_global_sub_id',''));
1338
1339 if($subscription_model==1){
1340 $selected_sub= get_post_meta($product_id,'_wpstream_parent_sub',true) ;
1341
1342 if( is_array($selected_sub) ){
1343
1344 // we have per product sub
1345 foreach($selected_sub as $key=>$subscrition_id ):
1346 if( wcs_user_has_subscription( $current_user->ID, $subscrition_id ,'active') ) {
1347 return true;
1348 }
1349 endforeach;
1350
1351 } else if($main_subscription!=0){
1352
1353 // if we have one main subscription
1354 if( wcs_user_has_subscription( $current_user->ID, $main_subscription ,'active') ) {
1355 return true;
1356 }
1357 }
1358
1359
1360 }
1361 return false;
1362
1363 }
1364 // there is no woo subscription or user not logged in
1365 return false;
1366 }
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376 /**
1377 *
1378 *
1379 *
1380 *
1381 * check if the user bought the product and display the player - TO REDo
1382 *
1383 * @since 3.0.1
1384 * returns html of the player
1385 *
1386 *
1387 *
1388 *
1389 *
1390 */
1391 public function wpstream_user_logged_in_product_already_bought($from_sh_id='') {
1392 if(function_exists('wpstream_remove_wpstream_filter')){
1393 return;
1394 }
1395 global $product;
1396 $product_id = $product->get_id();
1397 $current_user = wp_get_current_user();
1398
1399 if ( is_user_logged_in() ) {
1400
1401
1402 if($this->wpstream_check_if_player_can_dsplay($product_id) ){
1403
1404 echo '<div class="wpstream_player_wrapper "><div class="wpstream_player_container">';
1405
1406 $is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true));
1407 $term_list = wp_get_post_terms($product_id, 'product_type');
1408
1409
1410 if( $term_list[0]->name=='live_stream' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){
1411 $this->wpstream_live_event_player($product_id);
1412 }else if( $term_list[0]->name=='video_on_demand' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='no' ) ){
1413
1414 $this->wpstream_video_on_demand_player($product_id);
1415 }
1416 echo '</div></div>';
1417 }else{
1418
1419
1420 $term_list = wp_get_post_terms($product_id, 'product_type');
1421
1422 if( $term_list[0]->name=='subscription' ){
1423
1424 if( !wcs_user_has_subscription( $current_user->ID, $product_id ,'active') ) {
1425 $this->wpstream_display_no_buy_message('nobuy',$product_id);
1426 }
1427
1428 }else{
1429 $this->wpstream_display_no_buy_message('nobuy',$product_id);
1430 }
1431
1432
1433
1434 }
1435
1436
1437 }else{
1438
1439 $this->wpstream_display_no_buy_message('nolog',$product_id);
1440 }
1441 }
1442
1443
1444
1445
1446
1447 /**
1448 *
1449 *
1450 * check if the user bought the product and display the player - TO REDo
1451 *
1452 * @since 3.0.1
1453 * returns html of the player
1454 */
1455
1456 public function wpstream_chat_wrapper($product_id){
1457 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/templates/wpstream_chat_template.php';
1458 }
1459
1460
1461
1462
1463
1464
1465
1466
1467 /**
1468 * coonect to chat
1469 *
1470 * @since 1.12.2
1471 *
1472 */
1473
1474
1475
1476 public function wpstream_connect_to_chat($product_id){
1477 $current_user = wp_get_current_user();
1478 $userID = $current_user->ID;
1479 $user_login = $current_user->user_login;
1480
1481 $key='';
1482
1483 $chat_url = get_post_meta($product_id,'chat_url',true);
1484
1485
1486 wp_enqueue_script( 'sockjs-0.3.min' );
1487 wp_enqueue_script( 'emojione.min.js' );
1488 wp_enqueue_script( "jquery-effects-core");
1489 wp_enqueue_script( 'jquery.linkify.min.js');
1490 wp_enqueue_script( 'ripples.min.js');
1491 wp_enqueue_script( 'material.min.js');
1492 wp_enqueue_script( 'chat.js');
1493
1494
1495
1496 wp_enqueue_style( 'chat.css');
1497 wp_enqueue_style( 'ripples.css');
1498 wp_enqueue_style( 'emojione.min.css');
1499
1500
1501
1502
1503 if(!is_user_logged_in()){
1504 $user_login='';
1505 $chat_url='';
1506 }
1507
1508
1509 print '<script type="text/javascript">
1510 //<![CDATA[
1511 jQuery(document).ready(function(){
1512 username = "'.$user_login.'";
1513 key="'.$key.'";
1514
1515 });
1516 //]]>
1517 </script>';
1518
1519 }
1520
1521
1522 /**
1523 * display no buy Message
1524 *
1525 * @since 3.12.2
1526 *
1527 */
1528 public function wpstream_display_no_buy_message($log,$product_id) {
1529
1530 if($log=='sub_active'){
1531 $message= esc_html( get_option('wpstream_subscription_active','Your Subscription is Active.')) ;
1532 echo '<div class="wpstream_player_wrapper no_buy"><div class="wpstream_player_container">';
1533 echo '<div class="wpstream_notice"> '.$message.'</div>';
1534 echo '</div></div>';
1535 return;
1536
1537 }else if($log=='nolog'){
1538 $message= esc_html( get_option('wpstream_product_not_login','You must be logged in to watch this video.')) ;
1539 }else{
1540 $message =esc_html( get_option('wpstream_product_not_bought','You did not yet purchase this item.')) ;
1541 }
1542 $subscription_model = intval( get_option('wpstream_global_sub','')) ;
1543 if($subscription_model==1){
1544 $message =esc_html( get_option('wpstream_product_not_subscribe','You did not yet subscribe to this item.'));
1545 }
1546
1547
1548 if( get_post_type($product_id) == 'product' && $subscription_model==0 ){
1549 $product = wc_get_product($product_id);
1550 $term_list = wp_get_post_terms($product_id, 'product_type');
1551 $product_type = $product->get_type();
1552 $is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true));
1553
1554
1555
1556 if( $term_list[0]->name=='video_on_demand' || $term_list[0]->name=='live_stream' || $product_type=='subscription'){
1557
1558 echo '<div class="wpstream_player_wrapper no_buy"><div class="wpstream_player_container">';
1559 echo '<div class="wpstream_notice">'.$message.'</div>';
1560 echo '</div></div>';
1561
1562 }
1563
1564 }else if( get_post_type($product_id) == 'product' && $subscription_model==1 ){
1565 $term_list = wp_get_post_terms($product_id, 'product_type');
1566 if( $term_list[0]->name!=='simple'){
1567 echo '<div class="wpstream_player_wrapper no_buy"><div class="wpstream_player_container">';
1568 echo '<div class="wpstream_notice"> '.$message.'</div>';
1569 echo '</div></div>';
1570 }
1571 }
1572
1573
1574
1575
1576
1577
1578 }
1579
1580 /**
1581 * Get the video player logo URL.
1582 *
1583 * @param int $product_id Product ID.
1584 * @return mixed|string
1585 */
1586 public function wpstream_get_video_player_logo( $product_id ) {
1587 $is_streamify_user = $this->wpstream_is_streamify_user( $product_id );
1588 if ( $is_streamify_user ) {
1589 return WPSTREAM_PLUGIN_DIR_URL . 'img/wpstream-symbol-large.png';
1590 }
1591
1592 $logo = get_option( 'wpstream_player_logo', '' );
1593 if ( ! empty( $logo ) ) {
1594 return $logo;
1595 }
1596 }
1597
1598 /**
1599 * Get cached pack data or request fresh pack data
1600 *
1601 * @param bool $force_refresh Force a refresh of the cached data
1602 * @return array Pack data
1603 */
1604 private function wpstream_get_cached_pack_data( $force_refresh = false ) {
1605 $cached_data = get_transient( 'wpstream_user_pack_data' );
1606
1607 if ( $force_refresh || $cached_data === false ) {
1608 $fresh_data = $this->main->wpstream_live_connection->wpstream_request_pack_data_per_user('wpstream_get_cached_pack_data');
1609 set_transient( 'wpstream_user_pack_data', $fresh_data, 60);
1610
1611 return $fresh_data;
1612 }
1613
1614 return $cached_data;
1615 }
1616
1617 /*
1618 * Check if the user is on a basic subscription
1619 *
1620 * @param int $channel_id Channel ID
1621 * @return bool
1622 */
1623 public function wpstream_is_streamify_user( $channel_id ) {
1624 $is_basic_streaming = get_post_meta( $channel_id, 'basicStreaming', true );
1625 if ( $is_basic_streaming === '1' ) {
1626 return true;
1627 }
1628 return false;
1629 }
1630 }
1631