PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 3.9
WpStream – Live Streaming, Video on Demand, Pay Per View v3.9
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 4.5.12 All 180 releases
wpstream / includes / class-wpstream-player.php

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

948 lines 37.4 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 add_action( 'wp_ajax_wpstream_force_clear_transient', array($this,'wpstream_force_clear_transient') );
27 add_action('wp_ajax_nopriv_wpstream_force_clear_transient', array($this,'wpstream_force_clear_transient'));
28
29
30 }
31
32
33
34 /**
35 * clear status transients
36 *
37 * @author cretu
38 */
39
40
41 public function wpstream_force_clear_transient($event_id){
42
43 $transient_name = 'event_data_to_return_'.$event_id;
44 delete_transient($transient_name);
45 update_post_meta($event_id,'statsUrl','');
46 update_post_meta($event_id,'chatUrl','');
47
48 }
49
50
51
52 /**
53 * check player status
54 *
55 * @author cretu
56 */
57
58 public function wpstream_player_check_status(){
59 $event_id = intval($_POST['event_id']);
60 $show_id=$event_id;
61 $transient_name = 'event_data_to_return_'.$event_id;
62 $event_data_for_transient = get_transient( $transient_name );
63
64
65
66 if ( false === $event_data_for_transient || $event_data_for_transient=='' ) { //ws || $hls_to_return==''
67
68 $server_id = ''; // server id IS blank - need to retrive it
69 $token = $this->main->wpstream_live_connection->wpstream_get_token();
70
71 if($server_id==''){
72 update_post_meta($show_id,'server_id', '' );
73
74 $server_id =$this->main->wpstream_live_connection->retrive_server_id_based_on_show_id($show_id);
75
76 }
77
78
79
80 update_post_meta($show_id,'server_id', $server_id );
81 $values_array=array(
82 "server_id" => esc_html($server_id),
83 'from_where' => 'wpstream_check_event_status_front_player'
84 );
85
86 if($server_id==''){
87 $this->main->wpstream_live_connection->wpstream_reset_event_data($show_id);
88 //print 'failed connection';
89 return;
90 }
91
92
93
94 $url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/api20-livestrem/event_status/?access_token=".$token;
95 $arguments = array(
96 'method' => 'GET',
97 'timeout' => 45,
98 'redirection' => 5,
99 'httpversion' => '1.0',
100 'blocking' => true,
101 'headers' => array(),
102 'body' => $values_array,
103 'cookies' => array()
104 );
105
106 $response = wp_remote_post($url,$arguments);
107 $received_data = wp_remote_retrieve_body($response);
108
109 if( isset($response['response']['code']) && $response['response']['code']=='200'){
110 $received_data_encoded=json_decode($received_data,true);
111
112 if( isset($received_data_encoded['success']) && intval( $received_data_encoded['success'] ) ==1 ){
113
114 /*
115 * we set transient and return the array saved
116 * false if no data
117 *
118 * */
119 $event_data_for_transient= $this->main->wpstream_live_connection->api20_wpstream_update_event($received_data_encoded,$show_id,$server_id);
120 }else{
121 $this->main->wpstream_live_connection->wpstream_reset_event_data($show_id);
122 }
123
124 }else{
125 $this->main->wpstream_live_connection->wpstream_reset_event_data($show_id);
126 }
127
128
129
130
131 if ( false === $event_data_for_transient || $event_data_for_transient=='' ){
132 //we are not live
133 $event_data_for_transient=array();
134 $event_data_for_transient['hlsPlaybackUrl']='';
135
136 }
137 }
138
139
140
141 // 1==2 &&
142
143 if( $event_data_for_transient['hlsPlaybackUrl']!=''){
144 echo json_encode( array(
145
146 'started' => 'yes',
147 'server_id' => $event_data_for_transient['server_id'],
148 'event_id' => $event_id,
149 'event_uri' => $event_data_for_transient['hlsPlaybackUrl'],
150 'live_conect_views' => $event_data_for_transient['statsUrl'],
151 'chat_url' => $event_data_for_transient['chatUrl'],
152
153 ));
154 }else{
155 echo json_encode( array(
156 'started' => 'no',
157 'server_id' => $server_id,
158 'event_id' => $event_id,
159 'event_uri' => '',
160 'live_conect_views' => '',
161 'chat_url' => '',
162
163 ));
164 $this->wpstream_force_clear_transient($event_id);
165 }
166 die();
167 }
168
169
170
171 /**
172 * Insert player in page
173 *
174 * @author cretu
175 */
176 public function wpstream_filter_the_title( $content ) {
177 if( is_singular('wpstream_product')){
178 global $post;
179 $args=array('id'=>$post->ID);
180 $custom_content = $this->wpstream_insert_player_inpage($args);
181 $content = '<div class="wpestream_inserted_player">'.$custom_content.'</div>'.$content;
182 return $content;
183 }else{
184 return $content;
185 }
186 }
187
188 /**
189 * Insert player in page
190 *
191 * @author cretu
192 */
193
194 public function wpstream_insert_player_inpage($attributes, $content = null){
195 $product_id = '';
196 $return_string = '';
197 $attributes = shortcode_atts(
198 array(
199 'id' => 0,
200 ), $attributes) ;
201
202
203 if ( isset($attributes['id']) ){
204 $product_id=$attributes['id'];
205 }
206
207 if(intval($product_id)==0){
208 $product_id= $this->wpstream_player_retrive_first_id();
209 }
210
211 ob_start();
212
213 $this->wpstream_video_player_shortcode($product_id);
214 $return_string= ob_get_contents();
215 ob_end_clean();
216
217 return $return_string;
218 }
219
220
221
222
223 /**
224 * Video Player shortcode
225 *
226 * @author cretu
227 */
228
229 public function wpstream_video_player_shortcode($from_sh_id='') {
230
231 if ( is_user_logged_in() ) {
232 global $product;
233 $current_user = wp_get_current_user();
234 $product_id = intval($from_sh_id);
235
236
237 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' ){
238 global $product;
239 echo '<div class="wpstream_player_wrapper wpstream_player_shortcode"><div class="wpstream_player_container">';
240
241
242 if( get_post_type($product_id) == 'wpstream_product' ){
243
244 $wpstream_product_type = esc_html(get_post_meta($product_id, 'wpstream_product_type', true));
245 if($wpstream_product_type==1){
246 $this->wpstream_live_event_player($product_id);
247 } else if($wpstream_product_type==2 || $wpstream_product_type==3){
248 $this->wpstream_video_on_demand_player($product_id);
249 }
250
251 }else{
252 $term_list = wp_get_post_terms($product_id, 'product_type');
253 $is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true));
254
255 if( $term_list[0]->name=='live_stream' || ( $term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){
256 $this->wpstream_live_event_player($product_id);
257 }else if( $term_list[0]->name=='video_on_demand' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='no' ) ){
258 $this->wpstream_video_on_demand_player($product_id);
259 }
260 }
261
262
263 echo '</div></div>';
264 }else{
265
266 if( get_post_type($product_id) == 'product' ){
267 echo '<div class="wpstream_player_wrapper wpstream_player_shortcode no_buy"><div class="wpstream_player_container">';
268 echo '<div class="wpstream_notice" style="background:#e16767;">'.esc_html__('You did not buy this product!','wpstream').'</div>';
269 echo '</div></div>';
270 }
271 }
272
273
274 }else{
275
276 $product_id = intval($from_sh_id);
277 if( get_post_type($product_id) == 'wpstream_product' ){
278
279 $wpstream_product_type = esc_html(get_post_meta($product_id, 'wpstream_product_type', true));
280 if($wpstream_product_type==1){
281 $this->wpstream_live_event_player($product_id);
282 } else if($wpstream_product_type==2 || $wpstream_product_type==3){
283 $this->wpstream_video_on_demand_player($product_id);
284 }
285
286 }
287 }
288 }
289
290
291
292 /**
293 * Video Player shortcode - low latency
294 *
295 * @author cretu
296 */
297
298 public function wpstream_video_player_shortcode_low_latency($from_sh_id='') {
299
300 if ( is_user_logged_in() ) {
301 global $product;
302 $current_user = wp_get_current_user();
303 $product_id = intval($from_sh_id);
304
305
306 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' ){
307 global $product;
308 echo '<div class="wpstream_player_wrapper wpstream_player_shortcode"><div class="wpstream_player_container">';
309
310
311 if( get_post_type($product_id) == 'wpstream_product' ){
312
313 $wpstream_product_type = esc_html(get_post_meta($product_id, 'wpstream_product_type', true));
314 if($wpstream_product_type==1){
315 $this->wpstream_live_event_player_low_latency($product_id);
316 }
317
318 }else{
319 $term_list = wp_get_post_terms($product_id, 'product_type');
320 $is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true));
321
322 if( $term_list[0]->name=='live_stream' || ( $term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){
323 $this->wpstream_live_event_player_low_latency($product_id);
324 }
325 }
326
327
328 echo '</div></div>';
329 }else{
330
331 if( get_post_type($product_id) == 'product' ){
332 echo '<div class="wpstream_player_wrapper wpstream_player_shortcode no_buy"><div class="wpstream_player_container">';
333 echo '<div class="wpstream_notice" style="background:#e16767;">'.esc_html__('You did not buy this product!','wpstream').'</div>';
334 echo '</div></div>';
335 }
336 }
337
338
339 }else{
340 $product_id = intval($from_sh_id);
341 if( get_post_type($product_id) == 'wpstream_product' ){
342
343 $wpstream_product_type = esc_html(get_post_meta($product_id, 'wpstream_product_type', true));
344 if($wpstream_product_type==1){
345 $this->wpstream_live_event_player_low_latency($product_id);
346 }
347 }
348 }
349 }
350
351
352
353
354
355 /**
356 * Live Event Player
357 *
358 * @author cretu
359 */
360 function remove_http($url) {
361 $disallowed = array('http://', 'https://');
362 foreach($disallowed as $d) {
363 if(strpos($url, $d) === 0) {
364 return str_replace($d, '', $url);
365 }
366 }
367 return $url;
368 }
369
370 /**
371 * Get event settings
372 *
373 * @author cretu
374 */
375
376 function wpestream_return_event_settings($product_id){
377
378 $local_event_options = get_post_meta($product_id,'local_event_options',true);
379 if(!is_array($local_event_options)){
380 $local_event_options = get_option('wpstream_user_streaming_global_channel_options') ;
381 }
382
383 return $local_event_options;
384 }
385
386
387
388 /**
389 * Live Event Player
390 *
391 * @author cretu
392 */
393
394 function wpstream_live_event_player($product_id,$poster_show='',$use_chat=''){
395
396 $event_settings = $this->wpestream_return_event_settings($product_id);
397 $live_event_uri = get_post_meta($product_id,'live_event_uri',true);
398 $api20_event_id = get_post_meta($product_id,'server_id',true);
399
400 $thumb_id = get_post_thumbnail_id($product_id);
401 $thumb = wp_get_attachment_image_src($thumb_id,'small');
402
403 $chatUrl= get_post_meta($product_id,'statsUrl',true);
404
405
406 $live_event_uri_final = $this->wpstream_request_hls_player_dynamic('',$product_id);// buleala lu Gabi
407 $now = time().rand(0,10);
408 $live_conect_array = explode('live.streamer.wpstream.net',$live_event_uri_final);
409 $live_conect_views = $live_conect_array[0].'live.streamer.wpstream.net';
410 $live_conect_views = $this->remove_http($live_conect_views);
411 $usernamestream = esc_html ( get_option('wpstream_api_username','') );
412 $autoplay = 'autoplay';
413
414 if(isset($event_settings['autoplay']) && intval($event_settings['autoplay'])==0){
415 $autoplay='no_autoplay';
416 }
417
418 echo '<div class="wpstream_live_player_wrapper function_wpstream_live_event_player" data-now="'.$now.'" data-me="'.esc_attr($usernamestream).'" data-product-id="'.$product_id.'" id="wpstream_live_player_wrapper'.$now.'" > ';
419
420 if( ( isset($event_settings['view_count'] ) && intval($event_settings['view_count'])==1 ) || !isset($event_settings['view_count']) ){
421 echo '<div id="wpestream_live_counting" class="wpestream_live_counting"></div>';
422 }
423
424 $show_wpstream_not_live_mess=' style="display:none;" ';
425 if(trim($live_event_uri_final) ==''){
426 $show_wpstream_not_live_mess='';
427 }
428
429
430 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>';
431
432
433 $poster_data=' poster="'.$thumb[0].'" ';
434 if($poster_show=='no'){
435 $poster_data='';
436 }
437
438 $is_muted='';
439 if( isset($event_settings['mute']) && intval($event_settings['mute'])==1){
440 $is_muted=' muted ';
441 }
442
443
444
445 echo'
446 <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.'>
447 <source
448 src="'.$live_event_uri_final.'"
449 type="application/x-mpegURL">
450 </video>';
451
452 print '<script type="text/javascript">
453 //<![CDATA[
454 jQuery(document).ready(function(){
455 wpstream_player_initialize("'.$now.'","'.$live_event_uri_final.'","'.$live_conect_views.'","'.$autoplay.'");';
456 print'});
457 //]]>
458 </script>';
459 print '</div>';
460
461
462 if(trim($live_event_uri_final) ==''){
463 // $show_wpstream_not_live_mess='';
464 }else{
465 print '<script type="text/javascript">
466 //<![CDATA[
467 jQuery(document).ready(function(){
468 var player_wrapper = jQuery(".wpstream_live_player_wrapper");
469 wpstream_read_websocket_info("'.$product_id.'","wpstream_live_player_wrapper'.$now.'", player_wrapper ,"'.$chatUrl.'", "'.$live_event_uri_final.'");
470 });
471 //]]>
472 </script>';
473 }
474
475
476 if($use_chat=="yes"){
477 $this->wpstream_connect_to_chat($product_id);
478 }
479
480 usleep (10000);
481
482 }
483
484
485
486 /**
487 * Live Event Player
488 *
489 * @author cretu
490 */
491
492 function wpstream_live_event_player_low_latency($product_id,$poster_show='',$use_chat=''){
493 $event_settings = $this->wpestream_return_event_settings($product_id);
494 $live_event_uri = get_post_meta($product_id,'live_event_uri',true);
495 $api20_event_id = get_post_meta($product_id,'server_id',true);
496
497 $thumb_id = get_post_thumbnail_id($product_id);
498 $thumb = wp_get_attachment_image_src($thumb_id,'small');
499
500 $chatUrl= get_post_meta($product_id,'statsUrl',true);
501
502
503 //$live_event_uri_final = $this->wpstream_request_hls_player_dynamic('',$product_id);// buleala lu Gabi
504
505
506 $live_event_uri_final= get_post_meta($product_id,'sldpPlaybackUrl',true);
507 $now = time().rand(0,10);
508
509 $usernamestream = esc_html ( get_option('wpstream_api_username','') );
510
511
512
513
514 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="'.$product_id.'" id="wpstream_live_player_wrapper'.$now.'" > ';
515
516
517 if( ( isset($event_settings['view_count'] ) && intval($event_settings['view_count'])==1 ) || !isset($event_settings['view_count']) ){
518 echo '<div id="wpestream_live_counting" class="wpestream_live_counting"></div>';
519 }
520
521 $show_wpstream_not_live_mess=' style="display:none;" ';
522 if(trim($live_event_uri_final) ==''){
523 $show_wpstream_not_live_mess='';
524 }
525
526
527 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>';
528
529
530 $poster_data=' poster="'.$thumb[0].'" ';
531 if($poster_show=='no'){
532 $poster_data='';
533 }
534
535
536 $is_muted='';
537 if( isset($event_settings['mute']) && intval($event_settings['mute'])==1){
538 $is_muted=' muted ';
539 }
540
541
542 $autoplay='autoplay';
543 if(isset($event_settings['autoplay']) && intval($event_settings['autoplay'])==0){
544 $autoplay='no_autoplay';
545 }
546
547 echo'
548 <div iccd="player" id="wpstream-video'.$now.'" '.$poster_data.' '.$is_muted.' class="" >
549 </div>';
550
551 print '<script type="text/javascript">
552 //<![CDATA[
553 jQuery(document).ready(function(){
554 var low_latencyid="wpstream-video'.$now.'";
555 document.addEventListener("DOMContentLoaded", initPlayer(low_latencyid, "'.$live_event_uri_final.'","'.$is_muted.'","'.$autoplay.'" ) ); ';
556 print'});
557 //]]>
558 </script>';
559
560
561
562 if(trim($live_event_uri_final) ==''){
563 // $show_wpstream_not_live_mess='';
564 }else{
565 print '<script type="text/javascript">
566 //<![CDATA[
567 jQuery(document).ready(function(){
568 var player_wrapper = jQuery(".wpstream_live_player_wrapper");
569 wpstream_read_websocket_info("'.$product_id.'","wpstream_live_player_wrapper'.$now.'", player_wrapper ,"'.$chatUrl.'", "'.$live_event_uri_final.'");
570 });
571 //]]>
572 </script>';
573 }
574
575
576 if($use_chat=="yes"){
577 $this->wpstream_connect_to_chat($product_id);
578 }
579
580 usleep (10000);
581
582 }
583
584
585
586 /**
587 * HLS PLAYER
588 *
589 * @author cretu
590 */
591 public function wpstream_request_hls_player_dynamic($server_id,$product_id){
592
593 $transient_name = 'hls_to_return_'.$product_id;
594 $hls_to_return = get_transient( $transient_name );
595
596 if ( false === $hls_to_return || $hls_to_return=='' ) { //ws || $hls_to_return==''
597
598 $token = $this->main->wpstream_live_connection->wpstream_get_token();
599 $values_array = array();
600 $values_array['server_id'] = $server_id;
601
602 if($server_id==''){
603 $this->main->wpstream_live_connection->wpstream_check_event_status_front_player($product_id,$server_id);
604 $server_id = get_post_meta($product_id,'server_id', true );
605 $values_array['server_id'] = $server_id;
606 }
607
608
609 if($server_id==''){
610 delete_transient($transient_name);
611 return '';exit();
612 }
613
614 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/api20-livestrem/ap20_get_player_hls_dynamic/?access_token=".$token;
615
616
617 $arguments = array(
618 'method' => 'GET',
619 'timeout' => 45,
620 'redirection' => 5,
621 'httpversion' => '1.0',
622 'blocking' => true,
623 'headers' => array(),
624 'body' => $values_array,
625 'cookies' => array()
626 );
627 $response = wp_remote_post($url,$arguments);
628
629 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
630
631
632
633
634 if( isset($response['response']['code']) && $response['response']['code']=='200'){
635 $hls_to_return = trim($received_data);
636
637
638 set_transient( $transient_name, $hls_to_return, 60 );
639 return $hls_to_return;
640 }else{
641 return 'failed connection';
642 }
643 exit();
644 }else{
645 return $hls_to_return;
646 }
647
648 }
649
650
651
652 /**
653 * HLS PLAYER
654 *
655 * @author cretu
656 */
657
658
659 public function wpstream_request_hls_player($product_id){
660
661 $transient_name = 'hls_to_return_'.$product_id;
662 $hls_to_return = get_transient( $transient_name );
663
664 if ( false === $hls_to_return || $hls_to_return=='' ) {
665
666 $show_id = intval($product_id);
667 $token = $this->main->wpstream_live_connection->wpstream_get_token();
668 $values_array = array();
669 $values_array['show_id'] = $show_id;
670
671 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/ap20_get_player_hls/?access_token=".$token;
672
673
674 $arguments = array(
675 'method' => 'GET',
676 'timeout' => 45,
677 'redirection' => 5,
678 'httpversion' => '1.0',
679 'blocking' => true,
680 'headers' => array(),
681 'body' => $values_array,
682 'cookies' => array()
683 );
684 $response = wp_remote_post($url,$arguments);
685
686 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
687
688
689
690 if( isset($response['response']['code']) && $response['response']['code']=='200'){
691 $hls_to_return = trim($received_data);
692 set_transient( $transient_name, $hls_to_return, 60 );
693 return $hls_to_return = trim($received_data);
694 }else{
695 return 'failed connection';
696 }
697 exit();
698 }else{
699 return $hls_to_return;
700 }
701
702 }
703
704
705
706 /**
707 * VODPlayer uri details
708 *
709 * @author cretu
710 */
711 public function wpstream_video_on_demand_player_uri_request($product_id){
712
713 $wpstream_data_setup = ' data-setup="{}" ';
714
715 /* free_video_type
716 * 1 - free live channel
717 * 2 - free video encrypted
718 * 3 - free video -not encrypted
719 */
720 $free_video_type = intval( get_post_meta($product_id, 'wpstream_product_type', true));
721
722
723 if($free_video_type==2 || get_post_type($product_id)=='product' ){
724
725 /* IF vide is encrypted- readed from vod,streaner
726 */
727
728 $video_type = 'application/x-mpegURL';
729 $video_path = get_post_meta($product_id,'_movie_url',true);
730 if(get_post_type($product_id)=='wpstream_product'){
731 $video_path = esc_html(get_post_meta($product_id, 'wpstream_free_video', true));
732 }
733
734 $username = esc_html ( get_option('wpstream_api_username','') );
735 if (filter_var($username, FILTER_VALIDATE_EMAIL)) {
736 $username = $this->wpstream_retrive_username();
737 }
738
739 if(strpos($username,'@')!=false){
740 $username_array= explode('@', $username);
741 $username=$username_array[0];
742 }
743
744 $video_path_final = 'https://vod.streamer.wpstream.net/'.$username.'/'.$video_path.'/index.m3u8?'.get_site_url();
745 if(!is_ssl()){
746 $video_path_final = 'http://vod.streamer.wpstream.net/'.$username.'/'.$video_path.'/index.m3u8?'.get_site_url();
747 }
748
749 }else if($free_video_type==3){
750
751 /* Video is unecrypted - read from local or youtube / vimeo
752 */
753
754 $video_type = 'video/mp4';
755 $video_path_final=esc_html(get_post_meta($product_id, 'wpstream_free_video_external', true));
756
757 if (strpos($video_path_final, 'www.youtube') !== false) {
758 $wpstream_data_setup= ' data-setup=\'{ "techOrder": ["youtube"], "sources": [{ "type": "video/youtube", "src": "'.$video_path_final.'"}] }\' ';
759 $video_path_final='';
760 }
761 if (strpos($video_path_final, 'vimeo.com') !== false) {
762 $wpstream_data_setup= ' data-setup=\'{"techOrder": ["vimeo"], "sources": [{ "type": "video/vimeo", "src": "'.$video_path_final.'"}], "vimeo": { "color": "#fbc51b"} }\' ';
763 $video_path_final='';
764 }
765
766 }
767
768 $return_array=array();
769 $return_array['video_path_final'] = $video_path_final;
770 $return_array['wpstream_data_setup']= $wpstream_data_setup;
771 $return_array['video_type'] = $video_type;
772 return $return_array;
773 }
774
775
776
777 /**
778 * VODPlayer url
779 *
780 * @author cretu
781 */
782
783 public function wpstream_video_on_demand_player($product_id){
784
785 $uri_details = $this->wpstream_video_on_demand_player_uri_request($product_id);
786 $video_path_final = $uri_details['video_path_final'];
787 $wpstream_data_setup = $uri_details['wpstream_data_setup'];
788 $video_type = $uri_details['video_type'];
789
790 $thumb_id = get_post_thumbnail_id($product_id);
791 $thumb = wp_get_attachment_image_src($thumb_id,'small');
792 $usernamestream = esc_html ( get_option('wpstream_api_username','') );
793
794 $pack = $this->main->wpstream_live_connection->wpstream_request_pack_data_per_user();
795
796 if(isset($pack['band']) && $pack['band']>0){
797 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"
798 poster="'.$thumb[0].'" '.$wpstream_data_setup.'>
799
800 <source src="'.trim($video_path_final).'" type="'.$video_type.'">
801 <p class="vjs-no-js">
802 To view this video please enable JavaScript, and consider upgrading to a web browser that
803 <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>
804 </p>
805 </video>';
806 }else{
807 print esc_html_e('Insufficient resources to stream this title','wpstream');
808 }
809
810 }
811
812
813
814
815
816
817 /**
818 * Retreive username for vod path
819 *
820 * @author cretu
821 */
822 private function wpstream_retrive_username(){
823 $token = $this->main->wpstream_live_connection->wpstream_get_token();
824
825 $url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/return_login/?access_token=".$token;
826 $arguments = array(
827 'method' => 'GET',
828 'timeout' => 45,
829 'redirection' => 5,
830 'httpversion' => '1.0',
831 'blocking' => true,
832 'headers' => array(),
833 'cookies' => array()
834 );
835 $response = wp_remote_post($url,$arguments);
836 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
837 if( isset($response['response']['code']) && $response['response']['code']=='200'){
838 return ($received_data); die();
839 }else{
840 print 'Failed to conbect media server';
841 die();
842 }
843 }
844
845
846
847
848
849 /**
850 * check if the user bought the product and display the player - TO REDo
851 *
852 * @since 3.0.1
853 * returns html of the player
854 */
855 public function wpstream_user_logged_in_product_already_bought($from_sh_id='') {
856
857 if ( is_user_logged_in() ) {
858 global $product;
859 $current_user = wp_get_current_user();
860 $product_id = $product->get_id();
861
862
863 if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id) || ( function_exists('wcs_user_has_subscription') && wcs_user_has_subscription( $current_user->ID, $product_id ,'active') ) ){
864
865
866 echo '<div class="wpstream_player_wrapper"><div class="wpstream_player_container">';
867
868 $is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true));
869 $term_list = wp_get_post_terms($product_id, 'product_type');
870
871
872 if( $term_list[0]->name=='live_stream' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){
873 $this->wpstream_live_event_player($product_id);
874 }else if( $term_list[0]->name=='video_on_demand' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='no' ) ){
875 $this->wpstream_video_on_demand_player($product_id);
876 }
877 echo '</div></div>';
878 }else{
879 if( get_post_type($product_id) == 'wpstream_product' ){
880 echo '<div class="wpstream_player_wrapper no_buy"><div class="wpstream_player_container">';
881 echo '<div class="wpstream_notice">'.__('You did not buy this product!','wpstream').'</div>';
882 echo '</div></div>';
883 }
884 }
885
886
887 }
888 }
889
890 /**
891 * check if the user bought the product and display the player - TO REDo
892 *
893 * @since 3.0.1
894 * returns html of the player
895 */
896
897 public function wpstream_chat_wrapper($product_id){
898 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/templates/wpstream_chat_template.php';
899 }
900
901
902
903 public function wpstream_connect_to_chat($product_id){
904 $current_user = wp_get_current_user();
905 $userID = $current_user->ID;
906 $user_login = $current_user->user_login;
907
908 $key='';
909
910 $chatUrl = get_post_meta($product_id,'chatUrl',true);
911
912
913 wp_enqueue_script( 'sockjs-0.3.min' );
914 wp_enqueue_script( 'emojione.min.js' );
915 wp_enqueue_script( "jquery-effects-core");
916 wp_enqueue_script( 'jquery.linkify.min.js');
917 wp_enqueue_script( 'ripples.min.js');
918 wp_enqueue_script( 'material.min.js');
919 wp_enqueue_script( 'chat.js');
920
921
922
923 wp_enqueue_style( 'chat.css');
924 wp_enqueue_style( 'ripples.css');
925 wp_enqueue_style( 'emojione.min.css');
926
927
928
929
930 if(!is_user_logged_in()){
931 $user_login='';
932 $chatUrl='';
933 }
934
935
936 print '<script type="text/javascript">
937 //<![CDATA[
938 jQuery(document).ready(function(){
939 username = "'.$user_login.'";
940 key="'.$key.'";
941
942 });
943 //]]>
944 </script>';
945
946 }
947 }
948