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

1,044 lines 40.0 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 function __construct($plugin_main) {
17 $this->main = $plugin_main;
18
19 add_filter( 'the_content',array($this, 'wpstream_filter_the_title') );
20 add_action( 'woocommerce_before_single_product', array($this,'wpstream_user_logged_in_product_already_bought') );
21
22 add_action( 'wp_ajax_wpstream_player_check_status', array($this,'wpstream_player_check_status') );
23 add_action('wp_ajax_nopriv_wpstream_player_check_status', array($this,'wpstream_player_check_status'));
24
25
26
27
28
29 }
30
31
32
33
34
35
36 /**
37 *
38 * edited 4.0
39 *
40 * check player status
41 *
42 * @author cretu
43 */
44
45 public function wpstream_player_check_status(){
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
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
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 echo json_encode( array(
65
66 'started' => 'yes',
67 'channel_id' => $channel_id,
68 'event_uri' => $event_data_for_transient['hls_playback_url'],
69 'live_conect_views' => $event_data_for_transient['stats_url'],
70 'chat_url' => $event_data_for_transient['chat_url'],
71 '$event_data_for_transient'=>$event_data_for_transient
72
73
74 ));
75 update_post_meta($channel_id,'stream_name',$event_data_for_transient['stream_name']);
76 update_post_meta($channel_id,'hls_key_retrieval_url',$event_data_for_transient['hls_key_retrieval_url']);
77 delete_transient( 'free_event_streamName_'.$event_data_for_transient['stream_name']);
78
79 }else{
80 echo json_encode( array(
81 'started' => 'no',
82 'server_id' => '',
83 'channel_id' => $channel_id,
84 'event_uri' => '',
85 'live_conect_views' => '',
86 'chat_url' => '',
87
88 ));
89
90 }
91
92 die();
93 }
94
95
96
97 /**
98 * Insert player in page
99 *
100 * @author cretu
101 */
102 public function wpstream_filter_the_title( $content ) {
103 if( is_singular('wpstream_product') || is_singular('wpstream_product_vod') ){
104 global $post;
105 $args=array('id'=>$post->ID);
106 $custom_content = $this->wpstream_insert_player_inpage($args);
107 $content = '<div class="wpestream_inserted_player">'.$custom_content.'</div>'.$content;
108 return $content;
109 }else{
110 return $content;
111 }
112 }
113
114 /**
115 * Insert player in page
116 *
117 * @author cretu
118 */
119
120 public function wpstream_insert_player_inpage($attributes, $content = null){
121 $product_id = '';
122 $return_string = '';
123 $attributes = shortcode_atts(
124 array(
125 'id' => 0,
126 ), $attributes) ;
127
128
129 if ( isset($attributes['id']) ){
130 $product_id=$attributes['id'];
131 }
132
133 if(intval($product_id)==0){
134 $product_id= $this->wpstream_player_retrive_first_id();
135 }
136
137 ob_start();
138
139 $this->wpstream_video_player_shortcode($product_id);
140 $return_string= ob_get_contents();
141 ob_end_clean();
142
143 return $return_string;
144 }
145
146
147
148
149 /**
150 * Video Player shortcode
151 *
152 * @author cretu
153 */
154
155 public function wpstream_video_player_shortcode($from_sh_id='') {
156
157
158
159 if ( is_user_logged_in() ) {
160 global $product;
161 $current_user = wp_get_current_user();
162 $product_id = intval($from_sh_id);
163 $term_list = wp_get_post_terms($product_id, 'product_type');
164
165
166
167
168
169 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) )
170 || get_post_type($product_id)=='wpstream_product' || get_post_type($product_id)=='wpstream_product_vod' ){
171 global $product;
172 echo '<div class="wpstream_player_wrapper wpstream_player_shortcode"><div class="wpstream_player_container">';
173
174
175 if( get_post_type($product_id) == 'wpstream_product' ){
176 $this->wpstream_live_event_player($product_id);
177 }else if( get_post_type($product_id) == 'wpstream_product_vod' ){
178 $this->wpstream_video_on_demand_player($product_id);
179 }else{
180
181 $is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true));
182
183 if( $term_list[0]->name=='live_stream' || ( $term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){
184 $this->wpstream_live_event_player($product_id);
185 }else if( $term_list[0]->name=='video_on_demand' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='no' ) ){
186 $this->wpstream_video_on_demand_player($product_id);
187 }
188 }
189
190
191 echo '</div></div>';
192 }else{
193
194 if( get_post_type($product_id) == 'product' ){
195 echo '<div class="wpstream_player_wrapper wpstream_player_shortcode no_buy"><div class="wpstream_player_container">';
196 echo '<div class="wpstream_notice" style="background:#e16767;">'.esc_html__('You did not buy this product!','wpstream').'</div>';
197 echo '</div></div>';
198 }
199 }
200
201
202 }else{
203
204 $product_id = intval($from_sh_id);
205 if( get_post_type($product_id) == 'wpstream_product' ){
206 $this->wpstream_live_event_player($product_id);
207 } else if( get_post_type($product_id) == 'wpstream_product_vod' ){
208 $this->wpstream_video_on_demand_player($product_id);
209 }
210 }
211 }
212
213
214
215 /**
216 * Video Player shortcode - low latency
217 *
218 * @author cretu
219 */
220
221 public function wpstream_video_player_shortcode_low_latency($from_sh_id='') {
222
223 if ( is_user_logged_in() ) {
224 global $product;
225 $current_user = wp_get_current_user();
226 $product_id = intval($from_sh_id);
227
228
229 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' ){
230 global $product;
231 echo '<div class="wpstream_player_wrapper wpstream_player_shortcode"><div class="wpstream_player_container">';
232
233
234 if( get_post_type($product_id) == 'wpstream_product' ){
235 $this->wpstream_live_event_player_low_latency($product_id);
236 }else{
237 $term_list = wp_get_post_terms($product_id, 'product_type');
238 $is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true));
239
240 if( $term_list[0]->name=='live_stream' || ( $term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){
241 $this->wpstream_live_event_player_low_latency($product_id);
242 }
243 }
244
245
246 echo '</div></div>';
247 }else{
248
249 if( get_post_type($product_id) == 'product' ){
250 echo '<div class="wpstream_player_wrapper wpstream_player_shortcode no_buy"><div class="wpstream_player_container">';
251 echo '<div class="wpstream_notice" style="background:#e16767;">'.esc_html__('You did not buy this product!','wpstream').'</div>';
252 echo '</div></div>';
253 }
254 }
255
256
257 }else{
258 $product_id = intval($from_sh_id);
259 if( get_post_type($product_id) == 'wpstream_product' ){
260 $this->wpstream_live_event_player_low_latency($product_id);
261 }
262 }
263 }
264
265
266
267
268
269 /**
270 * Live Event Player
271 *
272 * @author cretu
273 */
274 function remove_http($url) {
275 $disallowed = array('http://', 'https://');
276 foreach($disallowed as $d) {
277 if(strpos($url, $d) === 0) {
278 return str_replace($d, '', $url);
279 }
280 }
281 return $url;
282 }
283
284 /**
285 * Get event settings
286 *
287 * @author cretu
288 */
289
290 function wpestream_return_event_settings($product_id){
291
292 $local_event_options = get_post_meta($product_id,'local_event_options',true);
293 if(!is_array($local_event_options)){
294 $local_event_options = get_option('wpstream_user_streaming_global_channel_options') ;
295 }
296
297 return $local_event_options;
298 }
299
300
301
302 /**
303 * edited in 4.0
304 *
305 * Live Event Player
306 *
307 * @author cretu
308 */
309
310 function wpstream_live_event_player($channel_id,$poster_show='',$use_chat=''){
311
312 $now = time().rand(0,1000000);
313 $thumb_id = get_post_thumbnail_id($channel_id);
314 $thumb = wp_get_attachment_image_src($thumb_id,'small');
315 $usernamestream = esc_html ( get_option('wpstream_api_username','') );
316 $autoplay = 'autoplay';
317
318 $event_settings = $this->wpestream_return_event_settings($channel_id);
319 $notes = 'wpstream_live_event_player_note';
320 $event_status = $this->main->wpstream_live_connection-> wpstream_check_event_status_api_call($channel_id,$notes);
321 $hls_playback_url = '';
322 $live_conect_views = '';
323
324 if(isset($event_status['status']) && $event_status['status']=='active'){
325 //live event
326 if(isset($event_status['hls_playback_url'])){
327 $hls_playback_url = $event_status['hls_playback_url'];
328
329 update_post_meta($channel_id,'stream_name',$event_status['stream_name']);
330 update_post_meta($channel_id,'hls_key_retrieval_url',$event_status['hls_key_retrieval_url']);
331 delete_transient( 'free_event_streamName_'.$event_status['stream_name']);
332
333 $live_conect_array = explode('live.streamer.wpstream.net',$hls_playback_url);
334 $live_conect_views = $live_conect_array[0].'live.streamer.wpstream.net';
335 $live_conect_views = $this->remove_http($live_conect_views);
336
337 }
338 if(isset($event_status['chat_url'])){
339 $chat_url = $event_status['chat_url'];
340 }
341
342 }else{
343 // event not live
344 }
345
346
347
348
349
350
351
352 if(isset($event_settings['autoplay']) && intval($event_settings['autoplay'])==0){
353 $autoplay='no_autoplay';
354 }
355
356 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.'" > ';
357
358 if( ( isset($event_settings['view_count'] ) && intval($event_settings['view_count'])==1 ) || !isset($event_settings['view_count']) ){
359 echo '<div id="wpestream_live_counting" class="wpestream_live_counting"></div>';
360 }
361
362 $show_wpstream_not_live_mess=' style="display:none;" ';
363 if(trim($hls_playback_url) ==''){
364
365 $show_wpstream_not_live_mess='';
366 }
367
368 $message_show= esc_html( get_option('wpstream_you_are_not_live','We are not live at this moment. Please check back later.')) ;
369 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">'.esc_html($message_show).'</div></div>';
370
371 $poster_data='';
372 if(isset($thumb[0])){
373 $poster_data=' poster="'.$thumb[0].'" ';
374 }
375 if($poster_show=='no'){
376 $poster_data='';
377 }
378
379 $is_muted='';
380 if( isset($event_settings['mute']) && intval($event_settings['mute'])==1){
381 $is_muted=' muted ';
382 }
383
384
385
386 echo'
387 <video id="wpstream-video'.$now.'" '.$poster_data.' class="video-js vjs-default-skin vjs-16-9 vjs-wpstream" playsinline="true" '.$is_muted.' controls data-autoplay='.$autoplay.'>
388 <source
389 src="'.$hls_playback_url.'"
390 type="application/x-mpegURL">
391 </video>';
392
393 print '<script type="text/javascript">
394 //<![CDATA[
395 jQuery(document).ready(function(){
396 wpstream_player_initialize("'.$now.'","'.$hls_playback_url.'","'.$live_conect_views.'","'.$autoplay.'");';
397 print'});
398 //]]>
399 </script>';
400 print '</div>';
401
402
403 if(trim($hls_playback_url) ==''){
404 // $show_wpstream_not_live_mess='';
405 }else{
406 print '<script type="text/javascript">
407 //<![CDATA[
408 jQuery(document).ready(function(){
409 var player_wrapper = jQuery(".wpstream_live_player_wrapper");
410 wpstream_read_websocket_info("'.$channel_id.'","wpstream_live_player_wrapper'.$now.'", player_wrapper ,"'.$chat_url.'", "'.$hls_playback_url.'");
411 });
412 //]]>
413 </script>';
414 }
415
416
417 if($use_chat=="yes"){
418 $this->wpstream_connect_to_chat($channel_id);
419 }
420
421 usleep (10000);
422
423 }
424
425
426
427 /**
428 *
429 * Edited in 4.0
430 *
431 *
432 * Live Event Player
433 *
434 * @author cretu
435 */
436
437 function wpstream_live_event_player_low_latency($channel_id,$poster_show='',$use_chat=''){
438 $usernamestream = esc_html ( get_option('wpstream_api_username','') );
439 $thumb_id = get_post_thumbnail_id($channel_id);
440 $thumb = wp_get_attachment_image_src($thumb_id,'small');
441
442 $event_settings = $this->wpestream_return_event_settings($channel_id);
443 $notes = 'wpstream_live_event_player_low_latency_note';
444 $event_status = $this->main->wpstream_live_connection-> wpstream_check_event_status_api_call($channel_id,$notes);
445 $hls_playback_url = '';
446 $live_conect_views = '';
447 $now = time().rand(0,10);
448
449
450
451 if(isset($event_status['status']) && $event_status['status']=='active'){
452 //live event
453 if(isset($event_status['sldp_playback_url'])){
454 $hls_playback_url = $event_status['sldp_playback_url'];
455
456 $live_conect_array = explode('live.streamer.wpstream.net',$hls_playback_url);
457 $live_conect_views = $live_conect_array[0].'live.streamer.wpstream.net';
458 $live_conect_views = $this->remove_http($live_conect_views);
459
460 }
461 if(isset($event_status['chat_url'])){
462 $chat_url =$event_status['chat_url'];
463 }
464
465 }else{
466 // event not live
467 }
468
469
470
471
472 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.'" > ';
473
474
475 if( ( isset($event_settings['view_count'] ) && intval($event_settings['view_count'])==1 ) || !isset($event_settings['view_count']) ){
476 echo '<div id="wpestream_live_counting" class="wpestream_live_counting"></div>';
477 }
478
479 $show_wpstream_not_live_mess=' style="display:none;" ';
480 if(trim($hls_playback_url) ==''){
481 $show_wpstream_not_live_mess='';
482 }
483
484 $message_show= esc_html( get_option('wpstream_you_are_not_live','We are not live at this moment. Please check back later.')) ;
485 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>';
486
487
488 $poster_data=' poster="'.$thumb[0].'" ';
489 if($poster_show=='no'){
490 $poster_data='';
491 }
492
493
494 $is_muted='';
495 if( isset($event_settings['mute']) && intval($event_settings['mute'])==1){
496 $is_muted=' muted ';
497 }
498
499
500 $autoplay='autoplay';
501 if(isset($event_settings['autoplay']) && intval($event_settings['autoplay'])==0){
502 $autoplay='no_autoplay';
503 }
504
505 echo'
506 <div iccd="player" id="wpstream-video'.$now.'" '.$poster_data.' '.$is_muted.' class="" >
507 </div>';
508
509 print '<script type="text/javascript">
510 //<![CDATA[
511 jQuery(document).ready(function(){
512 var low_latencyid="wpstream-video'.$now.'";
513 document.addEventListener("DOMContentLoaded", initPlayer(low_latencyid, "'.$hls_playback_url.'","'.$is_muted.'","'.$autoplay.'" ) ); ';
514 print'});
515 //]]>
516 </script>';
517
518
519
520 if(trim($hls_playback_url) ==''){
521 // $show_wpstream_not_live_mess='';
522 }else{
523 print '<script type="text/javascript">
524 //<![CDATA[
525 jQuery(document).ready(function(){
526 var player_wrapper = jQuery(".wpstream_live_player_wrapper");
527 wpstream_read_websocket_info("'.$channel_id.'","wpstream_live_player_wrapper'.$now.'", player_wrapper ,"'.$chat_url.'", "'.$hls_playback_url.'");
528 });
529 //]]>
530 </script>';
531 }
532
533
534 if($use_chat=="yes"){
535 $this->wpstream_connect_to_chat($channel_id);
536 }
537
538 usleep (10000);
539
540 }
541
542
543
544
545
546 /*
547 *
548 * Request HLS player
549 *
550 *
551 *
552 */
553 public function wpstream_request_video_on_demand_hls_player($video_name,$product_id){
554 if($video_name==''){
555 return '';
556 }
557
558 $transient_name = 'wpstream_video_on_demand_'.$video_name;
559 $hls_to_return = get_transient( $transient_name );
560 $hls_to_return = false;
561
562
563 if($hls_to_return==false){
564
565 $access_token = $this->main->wpstream_live_connection->wpstream_get_token();
566 $url = 'video/info';
567
568 //corsorigin de check
569 $local_event_options = get_option('wpstream_user_streaming_global_channel_options') ;
570 $domain = parse_url ( get_site_url() );
571 $domain_scheme = 'http';
572 if(is_ssl()){
573 $domain_scheme='https';
574 }
575
576 $corsorigin='';
577 if( isset($local_event_options['vod_domain_lock']) ){
578 if (intval( $local_event_options['vod_domain_lock']) ==0 ){
579 $corsorigin='*';
580 }
581 }else{
582 $corsorigin='*';
583 }
584
585 if($corsorigin!='*'){
586 $corsorigin=$domain_scheme.'://'.$domain['host'];
587 }
588
589 $is_encrypt="false";
590 if( isset($local_event_options['vod_encrypt']) && intval( $local_event_options['vod_encrypt']) ==1 ){
591 $is_encrypt="true";
592 }
593
594 $hlsKeysUrlPrefix = get_site_url().'?wpstream_voddrm=';
595 $encrypt = $is_encrypt;
596 $debugDrm = false;
597
598 $curl_post_fields=array(
599 'access_token' => $access_token,
600 'name' => $video_name,
601 'corsOrigin' => $corsorigin,
602 'encryptHls' => $encrypt,
603 'hlsKeysUrlPrefix' => $hlsKeysUrlPrefix,
604 'debugDrm' => $debugDrm,
605 );
606
607
608 $curl_response = $this->main->wpstream_live_connection->wpstream_baker_do_curl_base($url,$curl_post_fields);
609 $curl_response_decoded = json_decode($curl_response,JSON_OBJECT_AS_ARRAY);
610
611 if($curl_response_decoded['success']){
612 set_transient( $transient_name, $curl_response_decoded['hlsUrl'] ,300);
613 $hls_to_return = $curl_response_decoded['hlsUrl'];
614 if( isset($curl_response_decoded['hlsDecryptionKey']) && isset($curl_response_decoded['hlsDecryptionKeyIndex']) ){
615 update_post_meta($product_id,'hlsDecryptionKey',$curl_response_decoded['hlsDecryptionKey']);
616 update_post_meta($product_id,'hlsDecryptionKeyIndex',$curl_response_decoded['hlsDecryptionKeyIndex']);
617 }else{
618 delete_post_meta($product_id,'hlsDecryptionKey');
619 delete_post_meta($product_id,'hlsDecryptionKeyIndex');
620 }
621
622 }else{
623 return '';
624 }
625
626 }
627
628 return $hls_to_return;
629
630 }
631
632
633
634
635 /**
636 * VODPlayer uri details
637 *
638 * @author cretu
639 */
640 public function wpstream_video_on_demand_player_uri_request($product_id){
641
642 $wpstream_data_setup = ' data-setup="{}" ';
643
644 /* free_video_type
645 * 1 - free live channel
646 * 2 - free video encrypted
647 * 3 - free video -not encrypted
648 */
649
650
651 $free_video_type = intval( get_post_meta($product_id, 'wpstream_product_type', true));
652 if( ( get_post_type($product_id)=='wpstream_product_vod' && $free_video_type==2 ) || get_post_type($product_id)=='product' ){
653
654 /*
655 * IF vide is encrypted- readed from vod,streaner
656 *
657 */
658
659
660 $video_type = 'application/x-mpegURL';
661 $video_path = get_post_meta($product_id,'_movie_url',true);
662 if(get_post_type($product_id)=='wpstream_product_vod'){
663 $video_path = esc_html(get_post_meta($product_id, 'wpstream_free_video', true));
664 }
665 $video_path_final = $this->wpstream_request_video_on_demand_hls_player($video_path,$product_id);
666
667
668 }else if( get_post_type($product_id)=='wpstream_product_vod' && $free_video_type==3 ){
669
670 /* Video is unecrypted - read from local or youtube / vimeo
671 */
672
673 $video_type = 'video/mp4';
674 $video_path_final=esc_html(get_post_meta($product_id, 'wpstream_free_video_external', true));
675
676 if (strpos($video_path_final, 'www.youtube') !== false) {
677 $wpstream_data_setup= ' data-setup=\'{ "techOrder": ["youtube"], "sources": [{ "type": "video/youtube", "src": "'.$video_path_final.'"}] }\' ';
678 $video_path_final='';
679 }
680 if (strpos($video_path_final, 'vimeo.com') !== false) {
681 $wpstream_data_setup= ' data-setup=\'{"techOrder": ["vimeo"], "sources": [{ "type": "video/vimeo", "src": "'.$video_path_final.'"}], "vimeo": { "color": "#fbc51b"} }\' ';
682 $video_path_final='';
683 }
684
685 }
686
687 $return_array=array();
688 $return_array['video_path_final'] = $video_path_final;
689 $return_array['wpstream_data_setup']= $wpstream_data_setup;
690 $return_array['video_type'] = $video_type;
691 return $return_array;
692 }
693
694
695
696 /**
697 * VODPlayer url
698 *
699 * @author cretu
700 */
701
702 public function wpstream_video_on_demand_player($product_id){
703
704 $uri_details = $this->wpstream_video_on_demand_player_uri_request($product_id);
705 $video_path_final = $uri_details['video_path_final'];
706 $wpstream_data_setup = $uri_details['wpstream_data_setup'];
707 $video_type = $uri_details['video_type'];
708
709 $thumb_id = get_post_thumbnail_id($product_id);
710 $thumb = wp_get_attachment_image_src($thumb_id,'small');
711 $usernamestream = esc_html ( get_option('wpstream_api_username','') );
712
713 $poster_thumb = '';
714 if(isset($thumb[0])){
715 $poster_thumb=$thumb[0];
716 }
717
718 $hlsDecryptionKey = get_post_meta($product_id,'hlsDecryptionKey',true);
719 $hlsDecryptionKeyIndex = get_post_meta($product_id,'hlsDecryptionKeyIndex',true);
720
721
722 $pack = $this->main->wpstream_live_connection->wpstream_request_pack_data_per_user();
723
724
725 if(isset($pack['available_data_mb']) && $pack['available_data_mb']>0){
726
727 if($video_path_final==''){
728 print '<div class="wpstream_vod_notice">This video does not exist or it has been deleted!</div>';
729 }
730
731 echo '<video id="wpstream-video'.time().'" class="video-js vjs-default-skin vjs-16-9 kuk wpstream_video_on_demand vjs-wpstream" data-me="'.esc_attr($usernamestream).'" data-product-id="'.$product_id.'" controls preload="auto"
732 poster="'.esc_url($poster_thumb).'" '.$wpstream_data_setup.'>
733
734 <source src="'.trim($video_path_final).'" type="'.$video_type.'">
735 <p class="vjs-no-js">
736 To view this video please enable JavaScript, and consider upgrading to a web browser that
737 <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>
738 </p>
739 </video>';
740 }else{
741 print esc_html_e('Insufficient resources to stream this title','wpstream');
742 }
743
744 }
745
746
747
748
749
750
751 /**
752 *
753 * edited 4.0
754 *
755 * Retreive username for vod path
756 *
757 * @author cretu
758 */
759 private function wpstream_retrive_username(){
760
761 return get_option('wpstream_api_username_from_token');
762 }
763
764 /**
765 * check if the we can add display the player
766 *
767 * @since 3.12
768 * returns html of the player
769 */
770
771 public function wpstream_check_if_player_can_dsplay($product_id){
772 if ( is_user_logged_in() ) {
773
774 $term_list = wp_get_post_terms($product_id, 'product_type');
775 $current_user = wp_get_current_user();
776 $subscription_model = esc_html( get_option('wpstream_global_sub','')) ;
777
778
779 if($subscription_model==1){ // if we have Neflix mode
780 if( $term_list[0]->name=='subscription' ){ // if the product loaded is a subscription and we are on netflix mode
781 return false;
782 }
783 if($this->wpstream_in_plugin_check_global_subscription_model($product_id)){
784 return true;
785 }
786 }else{
787 // ppv mode
788 if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id) ||
789 ( function_exists('wcs_user_has_subscription') && wcs_user_has_subscription( $current_user->ID, $product_id ,'active') ) ){
790 return true;
791 }
792 }
793 return false;
794
795 }
796 return false;
797
798 }
799
800
801
802 /**
803 * in plugin - check if global subscription model is enabled
804 *
805 * @since 3.12
806 *
807 */
808 public function wpstream_in_plugin_check_global_subscription_model($product_id) {
809
810 // $selected_sub= get_post_meta($post->ID,'_wpstream_parent_sub',true);
811 if( is_user_logged_in() && function_exists('wcs_user_has_subscription') ){
812
813 global $woocommerce;
814 $current_user = wp_get_current_user();
815
816 $subscription_model = esc_html( get_option('wpstream_global_sub','')) ;
817 $main_subscription = intval( get_option('wpstream_global_sub_id',''));
818
819 if($subscription_model==1){
820 $selected_sub= get_post_meta($product_id,'_wpstream_parent_sub',true) ;
821
822 if( is_array($selected_sub) ){
823
824 // we have per product sub
825 foreach($selected_sub as $key=>$subscrition_id ):
826 if( wcs_user_has_subscription( $current_user->ID, $subscrition_id ,'active') ) {
827 return true;
828 }
829 endforeach;
830
831 } else if($main_subscription!=0){
832
833 // if we have one main subscription
834 if( wcs_user_has_subscription( $current_user->ID, $main_subscription ,'active') ) {
835 return true;
836 }
837 }
838
839
840 }
841 return false;
842
843 }
844 // there is no woo subscription or user not logged in
845 return false;
846 }
847
848
849
850
851
852
853
854
855
856 /**
857 *
858 *
859 *
860 *
861 * check if the user bought the product and display the player - TO REDo
862 *
863 * @since 3.0.1
864 * returns html of the player
865 *
866 *
867 *
868 *
869 *
870 */
871 public function wpstream_user_logged_in_product_already_bought($from_sh_id='') {
872 global $product;
873 $product_id = $product->get_id();
874 $current_user = wp_get_current_user();
875 if ( is_user_logged_in() ) {
876
877 if($this->wpstream_check_if_player_can_dsplay($product_id) ){
878
879 echo '<div class="wpstream_player_wrapper "><div class="wpstream_player_container">';
880
881 $is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true));
882 $term_list = wp_get_post_terms($product_id, 'product_type');
883
884
885 if( $term_list[0]->name=='live_stream' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){
886 $this->wpstream_live_event_player($product_id);
887 }else if( $term_list[0]->name=='video_on_demand' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='no' ) ){
888 $this->wpstream_video_on_demand_player($product_id);
889 }
890 echo '</div></div>';
891 }else{
892
893
894 $term_list = wp_get_post_terms($product_id, 'product_type');
895 if( $term_list[0]->name=='subscription' ){
896 if( !wcs_user_has_subscription( $current_user->ID, $product_id ,'active') ) {
897 $this->wpstream_display_no_buy_message('nobuy',$product_id);
898 }
899
900 }
901
902
903
904 }
905
906
907 }else{
908
909 $this->wpstream_display_no_buy_message('nolog',$product_id);
910 }
911 }
912
913
914
915
916
917 /**
918 *
919 *
920 * check if the user bought the product and display the player - TO REDo
921 *
922 * @since 3.0.1
923 * returns html of the player
924 */
925
926 public function wpstream_chat_wrapper($product_id){
927 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/templates/wpstream_chat_template.php';
928 }
929
930
931
932
933
934
935
936
937 /**
938 * coonect to chat
939 *
940 * @since 1.12.2
941 *
942 */
943
944
945
946 public function wpstream_connect_to_chat($product_id){
947 $current_user = wp_get_current_user();
948 $userID = $current_user->ID;
949 $user_login = $current_user->user_login;
950
951 $key='';
952
953 $chat_url = get_post_meta($product_id,'chat_url',true);
954
955
956 wp_enqueue_script( 'sockjs-0.3.min' );
957 wp_enqueue_script( 'emojione.min.js' );
958 wp_enqueue_script( "jquery-effects-core");
959 wp_enqueue_script( 'jquery.linkify.min.js');
960 wp_enqueue_script( 'ripples.min.js');
961 wp_enqueue_script( 'material.min.js');
962 wp_enqueue_script( 'chat.js');
963
964
965
966 wp_enqueue_style( 'chat.css');
967 wp_enqueue_style( 'ripples.css');
968 wp_enqueue_style( 'emojione.min.css');
969
970
971
972
973 if(!is_user_logged_in()){
974 $user_login='';
975 $chat_url='';
976 }
977
978
979 print '<script type="text/javascript">
980 //<![CDATA[
981 jQuery(document).ready(function(){
982 username = "'.$user_login.'";
983 key="'.$key.'";
984
985 });
986 //]]>
987 </script>';
988
989 }
990
991
992 /**
993 * display no buy Message
994 *
995 * @since 3.12.2
996 *
997 */
998 public function wpstream_display_no_buy_message($log,$product_id) {
999
1000 if($log=='sub_active'){
1001 $message= esc_html( get_option('wpstream_subscription_active','Your Subscription is Active.')) ;
1002 echo '<div class="wpstream_player_wrapper no_buy"><div class="wpstream_player_container">';
1003 echo '<div class="wpstream_notice"> '.$message.'</div>';
1004 echo '</div></div>';
1005 return;
1006
1007 }else if($log=='nolog'){
1008 $message= esc_html( get_option('wpstream_product_not_login','You must be logged in to watch this video.')) ;
1009 }else{
1010 $message =esc_html( get_option('wpstream_product_not_bought','You did not yet purchase this item.')) ;
1011 }
1012 $subscription_model = esc_html( get_option('wpstream_global_sub','')) ;
1013 if($subscription_model==1){
1014 $message =esc_html( get_option('wpstream_product_not_subscribe','You did not yet subscribe to this item.'));
1015 }
1016
1017
1018 if( get_post_type($product_id) == 'product' && $subscription_model==0 ){
1019
1020 $term_list = wp_get_post_terms($product_id, 'product_type');
1021 if( $term_list[0]->name=='video_on_demand' || $term_list[0]->name=='live_stream'){
1022
1023 echo '<div class="wpstream_player_wrapper no_buy"><div class="wpstream_player_container">';
1024 echo '<div class="wpstream_notice">'.$message.'</div>';
1025 echo '</div></div>';
1026
1027 }
1028
1029 }else if( get_post_type($product_id) == 'product' && $subscription_model==1 ){
1030 echo '<div class="wpstream_player_wrapper no_buy"><div class="wpstream_player_container">';
1031 echo '<div class="wpstream_notice"> '.$message.'</div>';
1032 echo '</div></div>';
1033 }
1034
1035
1036
1037
1038
1039
1040 }
1041
1042
1043 }
1044