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

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