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

898 lines 35.2 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 /**
372 * Live Event Player
373 *
374 * @author cretu
375 */
376
377 function wpstream_live_event_player($product_id,$poster_show='',$use_chat=''){
378 $live_event_uri = get_post_meta($product_id,'live_event_uri',true);
379 $api20_event_id = get_post_meta($product_id,'server_id',true);
380
381 $thumb_id = get_post_thumbnail_id($product_id);
382 $thumb = wp_get_attachment_image_src($thumb_id,'small');
383
384 $chatUrl= get_post_meta($product_id,'statsUrl',true);
385
386
387 $live_event_uri_final = $this->wpstream_request_hls_player_dynamic('',$product_id);// buleala lu Gabi
388 $now = time().rand(0,10);
389 $live_conect_array = explode('live.streamer.wpstream.net',$live_event_uri_final);
390 $live_conect_views = $live_conect_array[0].'live.streamer.wpstream.net';
391 $live_conect_views = $this->remove_http($live_conect_views);
392 $usernamestream = esc_html ( get_option('wpstream_api_username','') );
393
394 echo '<div class="wpstream_live_player_wrapper" data-now="'.$now.'" data-me="'.esc_attr($usernamestream).'" data-product-id="'.$product_id.'" id="wpstream_live_player_wrapper'.$now.'" > '
395 . '<div id="wpestream_live_counting" class="wpestream_live_counting"></div>';
396
397 $show_wpstream_not_live_mess=' style="display:none;" ';
398 if(trim($live_event_uri_final) ==''){
399 $show_wpstream_not_live_mess='';
400 }
401
402
403 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>';
404
405
406 $poster_data=' poster="'.$thumb[0].'" ';
407 if($poster_show=='no'){
408 $poster_data='';
409 }
410
411 echo'
412 <video id="wpstream-video'.$now.'" '.$poster_data.' class="video-js vjs-default-skin vjs-16-9" playsinline="true" controls>
413 <source
414 src="'.$live_event_uri_final.'"
415 type="application/x-mpegURL">
416 </video>';
417
418 print '<script type="text/javascript">
419 //<![CDATA[
420 jQuery(document).ready(function(){
421 wpstream_player_initialize("'.$now.'","'.$live_event_uri_final.'","'.$live_conect_views.'");';
422 print'});
423 //]]>
424 </script>';
425 print '</div>';
426
427
428 if(trim($live_event_uri_final) ==''){
429 // $show_wpstream_not_live_mess='';
430 }else{
431 print '<script type="text/javascript">
432 //<![CDATA[
433 jQuery(document).ready(function(){
434 var player_wrapper = jQuery(".wpstream_live_player_wrapper");
435 wpstream_read_websocket_info("'.$product_id.'","wpstream_live_player_wrapper'.$now.'", player_wrapper ,"'.$chatUrl.'", "'.$live_event_uri_final.'");
436 });
437 //]]>
438 </script>';
439 }
440
441
442 if($use_chat=="yes"){
443 $this->wpstream_connect_to_chat($product_id);
444 }
445
446 usleep (10000);
447
448 }
449
450
451
452 /**
453 * Live Event Player
454 *
455 * @author cretu
456 */
457
458 function wpstream_live_event_player_low_latency($product_id,$poster_show='',$use_chat=''){
459 $live_event_uri = get_post_meta($product_id,'live_event_uri',true);
460 $api20_event_id = get_post_meta($product_id,'server_id',true);
461
462 $thumb_id = get_post_thumbnail_id($product_id);
463 $thumb = wp_get_attachment_image_src($thumb_id,'small');
464
465 $chatUrl= get_post_meta($product_id,'statsUrl',true);
466
467
468 //$live_event_uri_final = $this->wpstream_request_hls_player_dynamic('',$product_id);// buleala lu Gabi
469
470
471 $live_event_uri_final= get_post_meta($product_id,'sldpPlaybackUrl',true);
472 $now = time().rand(0,10);
473
474 $usernamestream = esc_html ( get_option('wpstream_api_username','') );
475
476
477
478
479 echo '<div class="wpstream_live_player_wrapper wpstream_low_latency" data-now="'.$now.'" data-me="'.esc_attr($usernamestream).'" data-product-id="'.$product_id.'" id="wpstream_live_player_wrapper'.$now.'" > '
480 . '<div id="wpestream_live_counting" class="wpestream_live_counting"></div>';
481
482 $show_wpstream_not_live_mess=' style="display:none;" ';
483 if(trim($live_event_uri_final) ==''){
484 $show_wpstream_not_live_mess='';
485 }
486
487
488 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>';
489
490
491 $poster_data=' poster="'.$thumb[0].'" ';
492 if($poster_show=='no'){
493 $poster_data='';
494 }
495
496
497 echo'
498 <div iccd="player" id="wpstream-video'.$now.'" '.$poster_data.' class="" >
499 </div>';
500
501 print '<script type="text/javascript">
502 //<![CDATA[
503 jQuery(document).ready(function(){
504 var low_latencyid="wpstream-video'.$now.'";
505 document.addEventListener("DOMContentLoaded", initPlayer(low_latencyid,"'.$live_event_uri_final.'") ); ';
506 print'});
507 //]]>
508 </script>';
509
510
511
512 if(trim($live_event_uri_final) ==''){
513 // $show_wpstream_not_live_mess='';
514 }else{
515 print '<script type="text/javascript">
516 //<![CDATA[
517 jQuery(document).ready(function(){
518 var player_wrapper = jQuery(".wpstream_live_player_wrapper");
519 wpstream_read_websocket_info("'.$product_id.'","wpstream_live_player_wrapper'.$now.'", player_wrapper ,"'.$chatUrl.'", "'.$live_event_uri_final.'");
520 });
521 //]]>
522 </script>';
523 }
524
525
526 if($use_chat=="yes"){
527 $this->wpstream_connect_to_chat($product_id);
528 }
529
530 usleep (10000);
531
532 }
533
534
535
536 /**
537 * HLS PLAYER
538 *
539 * @author cretu
540 */
541 public function wpstream_request_hls_player_dynamic($server_id,$product_id){
542
543 $transient_name = 'hls_to_return_'.$product_id;
544 $hls_to_return = get_transient( $transient_name );
545
546 if ( false === $hls_to_return || $hls_to_return=='' ) { //ws || $hls_to_return==''
547
548 $token = $this->main->wpstream_live_connection->wpstream_get_token();
549 $values_array = array();
550 $values_array['server_id'] = $server_id;
551
552 if($server_id==''){
553 $this->main->wpstream_live_connection->wpstream_check_event_status_front_player($product_id,$server_id);
554 $server_id = get_post_meta($product_id,'server_id', true );
555 $values_array['server_id'] = $server_id;
556 }
557
558
559 if($server_id==''){
560 delete_transient($transient_name);
561 return '';exit();
562 }
563
564 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/api20-livestrem/ap20_get_player_hls_dynamic/?access_token=".$token;
565
566
567 $arguments = array(
568 'method' => 'GET',
569 'timeout' => 45,
570 'redirection' => 5,
571 'httpversion' => '1.0',
572 'blocking' => true,
573 'headers' => array(),
574 'body' => $values_array,
575 'cookies' => array()
576 );
577 $response = wp_remote_post($url,$arguments);
578
579 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
580
581
582
583
584 if( isset($response['response']['code']) && $response['response']['code']=='200'){
585 $hls_to_return = trim($received_data);
586
587
588 set_transient( $transient_name, $hls_to_return, 60 );
589 return $hls_to_return;
590 }else{
591 return 'failed connection';
592 }
593 exit();
594 }else{
595 return $hls_to_return;
596 }
597
598 }
599
600
601
602 /**
603 * HLS PLAYER
604 *
605 * @author cretu
606 */
607
608
609 public function wpstream_request_hls_player($product_id){
610
611 $transient_name = 'hls_to_return_'.$product_id;
612 $hls_to_return = get_transient( $transient_name );
613
614 if ( false === $hls_to_return || $hls_to_return=='' ) {
615
616 $show_id = intval($product_id);
617 $token = $this->main->wpstream_live_connection->wpstream_get_token();
618 $values_array = array();
619 $values_array['show_id'] = $show_id;
620
621 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/ap20_get_player_hls/?access_token=".$token;
622
623
624 $arguments = array(
625 'method' => 'GET',
626 'timeout' => 45,
627 'redirection' => 5,
628 'httpversion' => '1.0',
629 'blocking' => true,
630 'headers' => array(),
631 'body' => $values_array,
632 'cookies' => array()
633 );
634 $response = wp_remote_post($url,$arguments);
635
636 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
637
638
639
640 if( isset($response['response']['code']) && $response['response']['code']=='200'){
641 $hls_to_return = trim($received_data);
642 set_transient( $transient_name, $hls_to_return, 60 );
643 return $hls_to_return = trim($received_data);
644 }else{
645 return 'failed connection';
646 }
647 exit();
648 }else{
649 return $hls_to_return;
650 }
651
652 }
653
654
655
656 /**
657 * VODPlayer uri details
658 *
659 * @author cretu
660 */
661 public function wpstream_video_on_demand_player_uri_request($product_id){
662
663 $wpstream_data_setup = ' data-setup="{}" ';
664
665 /* free_video_type
666 * 1 - free live channel
667 * 2 - free video encrypted
668 * 3 - free video -not encrypted
669 */
670 $free_video_type = intval( get_post_meta($product_id, 'wpstream_product_type', true));
671
672
673 if($free_video_type==2 || get_post_type($product_id)=='product' ){
674
675 /* IF vide is encrypted- readed from vod,streaner
676 */
677
678 $video_type = 'application/x-mpegURL';
679 $video_path = get_post_meta($product_id,'_movie_url',true);
680 if(get_post_type($product_id)=='wpstream_product'){
681 $video_path = esc_html(get_post_meta($product_id, 'wpstream_free_video', true));
682 }
683
684 $username = esc_html ( get_option('wpstream_api_username','') );
685 if (filter_var($username, FILTER_VALIDATE_EMAIL)) {
686 $username = $this->wpstream_retrive_username();
687 }
688
689 if(strpos($username,'@')!=false){
690 $username_array= explode('@', $username);
691 $username=$username_array[0];
692 }
693
694 $video_path_final = 'https://vod.streamer.wpstream.net/'.$username.'/'.$video_path.'/index.m3u8?'.get_site_url();
695 if(!is_ssl()){
696 $video_path_final = 'http://vod.streamer.wpstream.net/'.$username.'/'.$video_path.'/index.m3u8?'.get_site_url();
697 }
698
699 }else if($free_video_type==3){
700
701 /* Video is unecrypted - read from local or youtube / vimeo
702 */
703
704 $video_type = 'video/mp4';
705 $video_path_final=esc_html(get_post_meta($product_id, 'wpstream_free_video_external', true));
706
707 if (strpos($video_path_final, 'www.youtube') !== false) {
708 $wpstream_data_setup= ' data-setup=\'{ "techOrder": ["youtube"], "sources": [{ "type": "video/youtube", "src": "'.$video_path_final.'"}] }\' ';
709 $video_path_final='';
710 }
711 if (strpos($video_path_final, 'vimeo.com') !== false) {
712 $wpstream_data_setup= ' data-setup=\'{"techOrder": ["vimeo"], "sources": [{ "type": "video/vimeo", "src": "'.$video_path_final.'"}], "vimeo": { "color": "#fbc51b"} }\' ';
713 $video_path_final='';
714 }
715
716 }
717
718 $return_array=array();
719 $return_array['video_path_final'] = $video_path_final;
720 $return_array['wpstream_data_setup']= $wpstream_data_setup;
721 $return_array['video_type'] = $video_type;
722 return $return_array;
723 }
724
725
726
727 /**
728 * VODPlayer url
729 *
730 * @author cretu
731 */
732
733 public function wpstream_video_on_demand_player($product_id){
734
735 $uri_details = $this->wpstream_video_on_demand_player_uri_request($product_id);
736 $video_path_final = $uri_details['video_path_final'];
737 $wpstream_data_setup = $uri_details['wpstream_data_setup'];
738 $video_type = $uri_details['video_type'];
739
740 $thumb_id = get_post_thumbnail_id($product_id);
741 $thumb = wp_get_attachment_image_src($thumb_id,'small');
742 $usernamestream = esc_html ( get_option('wpstream_api_username','') );
743
744 $pack = $this->main->wpstream_live_connection->wpstream_request_pack_data_per_user();
745
746 if($pack['band']>0){
747 echo '<video id="wpstream-video'.time().'" class="video-js vjs-default-skin vjs-16-9 kuk wpstream_video_on_demand" data-me="'.esc_attr($usernamestream).'" data-product-id="'.$product_id.'" controls preload="auto"
748 poster="'.$thumb[0].'" '.$wpstream_data_setup.'>
749
750 <source src="'.trim($video_path_final).'" type="'.$video_type.'">
751 <p class="vjs-no-js">
752 To view this video please enable JavaScript, and consider upgrading to a web browser that
753 <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>
754 </p>
755 </video>';
756 }else{
757 print esc_html_e('Insufficient resources to stream this title','wpstream');
758 }
759
760 }
761
762
763
764
765
766
767 /**
768 * Retreive username for vod path
769 *
770 * @author cretu
771 */
772 private function wpstream_retrive_username(){
773 $token = $this->main->wpstream_live_connection->wpstream_get_token();
774
775 $url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/return_login/?access_token=".$token;
776 $arguments = array(
777 'method' => 'GET',
778 'timeout' => 45,
779 'redirection' => 5,
780 'httpversion' => '1.0',
781 'blocking' => true,
782 'headers' => array(),
783 'cookies' => array()
784 );
785 $response = wp_remote_post($url,$arguments);
786 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
787 if( isset($response['response']['code']) && $response['response']['code']=='200'){
788 return ($received_data); die();
789 }else{
790 print 'Failed to conbect media server';
791 die();
792 }
793 }
794
795
796
797
798
799 /**
800 * check if the user bought the product and display the player - TO REDo
801 *
802 * @since 3.0.1
803 * returns html of the player
804 */
805 public function wpstream_user_logged_in_product_already_bought($from_sh_id='') {
806
807 if ( is_user_logged_in() ) {
808 global $product;
809 $current_user = wp_get_current_user();
810 $product_id = $product->get_id();
811
812
813 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') ) ){
814
815
816 echo '<div class="wpstream_player_wrapper"><div class="wpstream_player_container">';
817
818 $is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true));
819 $term_list = wp_get_post_terms($product_id, 'product_type');
820
821
822 if( $term_list[0]->name=='live_stream' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){
823 $this->wpstream_live_event_player($product_id);
824 }else if( $term_list[0]->name=='video_on_demand' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='no' ) ){
825 $this->wpstream_video_on_demand_player($product_id);
826 }
827 echo '</div></div>';
828 }else{
829 if( get_post_type($product_id) == 'wpstream_product' ){
830 echo '<div class="wpstream_player_wrapper no_buy"><div class="wpstream_player_container">';
831 echo '<div class="wpstream_notice">'.__('You did not buy this product!','wpstream').'</div>';
832 echo '</div></div>';
833 }
834 }
835
836
837 }
838 }
839
840 /**
841 * check if the user bought the product and display the player - TO REDo
842 *
843 * @since 3.0.1
844 * returns html of the player
845 */
846
847 public function wpstream_chat_wrapper($product_id){
848 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/templates/wpstream_chat_template.php';
849 }
850
851
852
853 public function wpstream_connect_to_chat($product_id){
854 $current_user = wp_get_current_user();
855 $userID = $current_user->ID;
856 $user_login = $current_user->user_login;
857
858 $key='';
859
860 $chatUrl = get_post_meta($product_id,'chatUrl',true);
861
862
863 wp_enqueue_script( 'sockjs-0.3.min' );
864 wp_enqueue_script( 'emojione.min.js' );
865 wp_enqueue_script( "jquery-effects-core");
866 wp_enqueue_script( 'jquery.linkify.min.js');
867 wp_enqueue_script( 'ripples.min.js');
868 wp_enqueue_script( 'material.min.js');
869 wp_enqueue_script( 'chat.js');
870
871
872
873 wp_enqueue_style( 'chat.css');
874 wp_enqueue_style( 'ripples.css');
875 wp_enqueue_style( 'emojione.min.css');
876
877
878
879
880 if(!is_user_logged_in()){
881 $user_login='';
882 $chatUrl='';
883 }
884
885
886 print '<script type="text/javascript">
887 //<![CDATA[
888 jQuery(document).ready(function(){
889 username = "'.$user_login.'";
890 key="'.$key.'";
891
892 });
893 //]]>
894 </script>';
895
896 }
897 }
898