PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 3.5.3
WpStream – Live Streaming, Video on Demand, Pay Per View v3.5.3
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-live-api-connection.php

class-wpstream-live-api-connection.php in WpStream – Live Streaming, Video on Demand, Pay Per View 3.5.3, at includes/class-wpstream-live-api-connection.php

1,149 lines 36.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Wpstream_Live_Api_Connection {
4
5
6
7
8 public function __construct() {
9 add_action( 'wp_ajax_wpstream_give_me_live_uri', array($this,'wpstream_give_me_live_uri') );
10 add_action('wp_ajax_wpstream_stop_server', array($this,'wpstream_stop_server'));
11
12 add_action( 'wp_ajax_wpstream_check_dns_sync', array($this,'wpstream_check_dns_sync') );
13 add_action( 'wp_ajax_wpstream_check_event_status', array($this,'wpstream_check_event_status') );
14
15 add_action( 'wp_ajax_wpstream_check_server_against_db', array($this,'wpstream_check_server_against_db') );
16 add_action( 'wp_ajax_wpstream_close_event', array($this,'wpstream_close_event') );
17 add_action( 'wp_ajax_wpstream_get_download_link', array($this,'wpstream_get_download_link') );
18 add_action( 'wp_ajax_wpstream_get_delete_file', array($this,'wpstream_get_delete_file') );
19 }
20
21 /**
22 * Check live stream in db
23 *
24 * @since 3.0.1
25 * returns live url
26 */
27 public function wpstream_check_server_against_db(){
28 $show_id = intval($_POST['show_id']);
29 $is_live = false;
30
31 $live_event_for_user = $this->api20_wpstream_get_live_event_for_user($show_id);
32 if(isset($live_event_for_user[$show_id])) {
33 $is_live=true;
34 }
35
36 echo json_encode( array('islive' =>$is_live) );
37 exit();
38 }
39
40
41
42
43
44
45 /**
46 * retreive server id based on show id
47 *
48 * @since 3.0.1
49 * returns live url
50 */
51
52 function retrive_server_id_based_on_show_id($show_id){
53
54 $transient_name = 'server_id_to_return_'.$show_id;
55 $server_id_to_return = get_transient( $transient_name );
56
57 if ( false === $server_id_to_return ) {
58 $token = $this->wpstream_get_token();
59 $values_array=array(
60 "show_id" => intval($show_id),
61 );
62
63
64 $url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/api20-livestrem/server_id_by_show_id/?access_token=".$token;
65 $arguments = array(
66 'method' => 'GET',
67 'timeout' => 45,
68 'redirection' => 5,
69 'httpversion' => '1.0',
70 'blocking' => true,
71 'headers' => array(),
72 'body' => $values_array,
73 'cookies' => array()
74 );
75
76 $response = wp_remote_post($url,$arguments);
77
78 $received_data = wp_remote_retrieve_body($response);
79
80
81
82
83 if( isset($response['response']['code']) && $response['response']['code']=='200'){
84 $server_id_to_return= set_transient( $transient_name, json_decode($received_data), 30 );
85 return json_decode($received_data);
86 die();
87 }else{
88 print 'failed connection';
89 }
90 }else{
91 return $server_id_to_return;
92 }
93
94 die();
95 }
96
97
98
99 /**
100 * check event status
101 *
102 * @since 3.0.1
103 * returns live url
104 */
105
106 public function wpstream_check_event_status(){
107 $token = $this->wpstream_get_token();
108 $show_id = intval($_POST['show_id']);
109 $server_id = esc_html(trim($_POST['server_id']));
110
111 // serever id may be blank if the user decide to close browser before receiving it
112
113 if($server_id==''){
114 update_post_meta($show_id,'server_id', '' );
115 $server_id = $this->retrive_server_id_based_on_show_id($show_id);
116
117 }
118
119
120 update_post_meta($show_id,'server_id', $server_id );
121
122 $values_array=array(
123 "server_id" => esc_html($server_id),
124 'from_where' => 'wpstream_check_event_status'
125 );
126
127
128 if($server_id==''){
129 print 'failed connection';
130 die();
131 }
132
133
134 $url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/api20-livestrem/event_status/?access_token=".$token;
135 $arguments = array(
136 'method' => 'GET',
137 'timeout' => 45,
138 'redirection' => 5,
139 'httpversion' => '1.0',
140 'blocking' => true,
141 'headers' => array(),
142 'body' => $values_array,
143 'cookies' => array()
144 );
145
146 $response = wp_remote_post($url,$arguments);
147 $received_data = wp_remote_retrieve_body($response);
148
149 if( isset($response['response']['code']) && $response['response']['code']=='200'){
150 $received_data_encoded=json_decode($received_data,true);
151
152 if( isset($received_data_encoded['success']) && intval( $received_data_encoded['success'] ) ==1 ){
153 $this->api20_wpstream_update_event($received_data_encoded,$show_id,$server_id);
154
155 if( isset($received_data_encoded['broadcastUrl']) && isset($received_data_encoded['status']) && $received_data_encoded['status']==='active' ){
156 $to_split=explode('wpstream/',$received_data_encoded['broadcastUrl']);
157
158 $obs_uri = $to_split[0].'wpstream/';
159 $obs_stream = $to_split[1];
160
161 $received_data_encoded['obs_uri']=$obs_uri;
162 $received_data_encoded['obs_stream']=$obs_stream;
163
164 update_post_meta($show_id,'obs_uri',$obs_uri);
165 update_post_meta($show_id,'obs_stream',$obs_stream);
166
167 $received_data=json_encode($received_data_encoded);
168 }
169 print $received_data;
170 die();
171 }
172
173 }else{
174 print 'failed connection';
175 }
176 die();
177 }
178
179
180 /**
181 * check event status for front end player
182 *
183 * @since 3.0.1
184 * returns live url
185 */
186
187 public function wpstream_check_event_status_front_player($show_id,$server_id){
188 $token = $this->wpstream_get_token();
189 // serever id may be blank if the user decide to close browser before receiving it
190
191 if($server_id==''){
192 update_post_meta($show_id,'server_id', '' );
193 $server_id = $this->retrive_server_id_based_on_show_id($show_id);
194 }
195
196
197
198 update_post_meta($show_id,'server_id', $server_id );
199 $values_array=array(
200 "server_id" => esc_html($server_id),
201 'from_where' => 'wpstream_check_event_status_front_player'
202 );
203
204 if($server_id==''){
205 $this->wpstream_reset_event_data($show_id);
206 //print 'failed connection';
207 return;
208 }
209
210
211
212 $url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/api20-livestrem/event_status/?access_token=".$token;
213 $arguments = array(
214 'method' => 'GET',
215 'timeout' => 45,
216 'redirection' => 5,
217 'httpversion' => '1.0',
218 'blocking' => true,
219 'headers' => array(),
220 'body' => $values_array,
221 'cookies' => array()
222 );
223
224 $response = wp_remote_post($url,$arguments);
225 $received_data = wp_remote_retrieve_body($response);
226
227 if( isset($response['response']['code']) && $response['response']['code']=='200'){
228 $received_data_encoded=json_decode($received_data,true);
229
230 if( isset($received_data_encoded['success']) && intval( $received_data_encoded['success'] ) ==1 ){
231 $this->api20_wpstream_update_event($received_data_encoded,$show_id,$server_id);
232
233 if( isset($received_data_encoded['broadcastUrl']) && isset($received_data_encoded['status']) && $received_data_encoded['status']==='active' ){
234 $to_split=explode('wpstream/',$received_data_encoded['broadcastUrl']);
235
236 $obs_uri = $to_split[0].'wpstream/';
237 $obs_stream = $to_split[1];
238
239 $received_data_encoded['obs_uri']=$obs_uri;
240 $received_data_encoded['obs_stream']=$obs_stream;
241
242 update_post_meta($show_id,'obs_uri',$obs_uri);
243 update_post_meta($show_id,'obs_stream',$obs_stream);
244
245 $received_data=json_encode($received_data_encoded);
246 }
247
248 }else{
249 $this->wpstream_reset_event_data($event_id);
250 }
251
252 }else{
253 $this->wpstream_reset_event_data($event_id);
254 print 'failed connection';
255 }
256
257 }
258
259
260 public function wpstream_reset_event_data($event_id){
261 update_post_meta($event_id,'statsUrl','');
262 update_post_meta($event_id,'hlsPlaybackUrl','');
263 update_post_meta($event_id,'server_id', '' );
264 }
265
266 /**
267 * update event metadata
268 *
269 * @since 3.0.1
270 * returns live url
271 */
272
273
274
275 function api20_wpstream_update_event($received_data,$show_id,$server_id=''){
276
277 if( is_array($received_data) ) {
278 $event_data_for_transient = array();
279 $event_data_for_transient['server_id'] = $server_id;
280 $transient_name = 'event_data_to_return_'.$show_id;
281
282 foreach($received_data as $key=>$value){
283 update_post_meta($show_id,$key,$value);
284 $event_data_for_transient[$key]=$value;
285 }
286 set_transient($transient_name,$event_data_for_transient,45);
287 return $event_data_for_transient;
288 }else{
289 return false;
290 }
291
292
293 }
294
295
296
297 /**
298 * Stop Server
299 *
300 * @since 3.0.1
301 * returns live url
302 */
303 public function wpstream_stop_server(){
304
305
306 check_ajax_referer( 'wpstream_stop_event_nonce', 'security' );
307 $current_user = wp_get_current_user();
308 $allowded_html = array();
309 $userID = $current_user->ID;
310 $return_uri = '';
311
312 if( !current_user_can('administrator') ){
313 exit('not admin');
314 }
315
316 $show_id = intval($_POST['show_id']);
317 $token = $this->wpstream_get_token();
318
319
320 $values_array=array(
321 "show_id" => $show_id,
322 "request_by_userid" => $userID,
323 );
324
325 $url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/api20-livestrem/stop-event/?access_token=".$token;
326
327 $arguments = array(
328 'method' => 'GET',
329 'timeout' => 45,
330 'redirection' => 5,
331 'httpversion' => '1.0',
332 'blocking' => true,
333 'headers' => array(),
334 'body' => $values_array,
335 'cookies' => array()
336 );
337 $response = wp_remote_post($url,$arguments);
338
339 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
340
341
342
343 if( isset($response['response']['code']) && $response['response']['code']=='200'){
344 print_r($received_data);
345 print 'closed';
346 }else{
347 print 'Failed to connect to WpStream. Please try again later.';
348 }
349
350 die();
351 }
352
353
354
355
356
357
358
359 /**
360 * Request live url
361 *
362 * @since 3.0.1
363 * returns live url
364 */
365 public function wpstream_give_me_live_uri(){
366
367 check_ajax_referer( 'wpstream_start_event_nonce', 'security' );
368 $current_user = wp_get_current_user();
369 $allowded_html = array();
370 $userID = $current_user->ID;
371 $return_uri = '';
372
373
374 if(function_exists('wpstream_get_option') && intval(wpstream_get_option('allow_streaming_regular_users',''))==1 ){
375 if( !is_user_logged_in() ){
376 exit('okko xab1');
377 }
378 }else{
379 if( !current_user_can('administrator') ){
380 exit('okko xa1');
381 }
382 }
383
384
385 if( ( trim( get_option('wpstream_api_username') )=='' || trim( get_option('wpstream_api_password')== '')) || !$this->wpstream_client_check_api_status() ){
386
387 echo json_encode( array(
388 'conected' => false,
389 'event_data' => '',
390 'error' => esc_html__('You are not connected to wpstream.net! Please check your WpStream credentials! ','wpstream')
391
392 ));
393 die();
394
395
396 }
397
398
399 $show_id = intval ( $_POST['show_id'] );
400 update_post_meta($show_id,'server_id', '' );
401 $is_record = esc_html( $_POST['is_record'] );
402 $is_encrypt = esc_html( $_POST['is_encrypt'] );
403 $event_data = $this->wpstream_request_live_stream_uri($show_id,$is_record,$is_encrypt,$userID);
404
405
406
407 if($event_data){
408 echo json_encode( array(
409 'conected' => true,
410 'event_data' => $event_data,
411
412 ));
413 }else{
414 echo json_encode( array(
415 'conected' => false,
416 'event_data' => $event_data,
417 'error' => 'Error 4176'// no aws server dns propagation,
418
419 ));
420 }
421 die();
422 }
423
424
425
426
427
428 public function wpstream_request_live_stream_uri($show_id,$is_record,$is_encrypt,$request_by_userid){
429 $token = $this->wpstream_get_token();
430 $domain = parse_url ( get_site_url() );
431
432 $home_url = get_home_url();
433 $domain_scheme = 'http';
434 $home_url = str_replace('https://','http://',$home_url);
435
436 if(is_ssl()){
437 $domain_scheme='https';
438 $home_url = str_replace('http://','https://',$home_url);
439 }
440
441 $domain_ip= esc_html( $_SERVER['SERVER_ADDR'] );
442 if($domain_ip==''){
443 $domain_ip="0.0.0.0/0";
444 }
445
446 $values_array=array(
447 "show_id" => $show_id,
448 "scheme" => $domain_scheme,
449 "domain" => $domain['host'],
450 "domain_ip" => $domain_ip,
451 "is_record" => $is_record,
452 "is_encrypt" => $is_encrypt,
453 "location" => $home_url,
454 "request_by_userid" => $request_by_userid,
455 "pluginVersion" => WPSTREAM_PLUGIN_VERSION
456 );
457
458 $url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/api20-livestrem/new/?access_token=".$token;
459
460 $arguments = array(
461 'method' => 'GET',
462 'timeout' => 45,
463 'redirection' => 5,
464 'httpversion' => '1.0',
465 'blocking' => true,
466 'headers' => array(),
467 'body' => $values_array,
468 'cookies' => array()
469 );
470 $response = wp_remote_post($url,$arguments);
471
472 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
473
474
475
476 if( isset($response['response']['code']) && $response['response']['code']=='200'){
477 return ($received_data);
478 }else{
479 if($received_data['data']['status']=='401'){
480 return('You are not connected to wpstream.net! Please check your WpStream credentials! ');
481
482 }else{
483 return 'Failed to connect to WpStream. Please try again later.';
484 }
485
486 }
487
488 }
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512 /**
513 * Retrive auth token from tranzient
514 *
515 * @since 3.0.1
516 * returns token
517 */
518 public function wpstream_get_token(){
519 $token = get_transient('wpstream_token_request');
520 if ( false === $token || $token==='' ) {
521 $token = $this->wpstream_club_get_token();
522 set_transient( 'wpstream_token_request', $token ,600);
523 }
524
525 return $token;
526
527 }
528
529
530
531 /**
532 * Request auth token from wpstream.net
533 *
534 * @since 3.0.1
535 * returns token fron wpstream
536 */
537 protected function wpstream_club_get_token(){
538
539 $client_id = esc_html ( get_option('wpstream_api_key','') );
540 $client_secret = esc_html ( get_option('wpstream_api_secret_key','') );
541 $username = esc_html ( get_option('wpstream_api_username','') );
542 $password = esc_html ( get_option('wpstream_api_password','') );
543
544 if ( $username=='' || $password==''){
545 return;
546 }
547 $curl = curl_init();
548
549 $json = array(
550 'grant_type'=>'password',
551 'username' =>$username,
552 'password' =>$password,
553 'client_id'=>'qxZ6fCoOMj4cNK8SXRHa5nug6vnswlFWSF37hsW3',
554 'client_secret'=>'L1fzLosJf9TlwnCCTZ5pkKmdqqkHShKEi0d4oFNE'
555 );
556
557 curl_setopt_array($curl, array(
558 CURLOPT_URL => WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/?oauth=token",
559 CURLOPT_RETURNTRANSFER => true,
560 CURLOPT_ENCODING => "",
561 CURLOPT_MAXREDIRS => 10,
562 CURLOPT_TIMEOUT => 30,
563 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
564 CURLOPT_CUSTOMREQUEST => "POST",
565 // CURLOPT_POSTFIELDS => "grant_type=password&username=".$username."&password=".$password."&client_id=qxZ6fCoOMj4cNK8SXRHa5nug6vnswlFWSF37hsW3&client_secret=L1fzLosJf9TlwnCCTZ5pkKmdqqkHShKEi0d4oFNE",
566 CURLOPT_POSTFIELDS=> json_encode($json),
567 CURLOPT_HTTPHEADER => array(
568
569 "cache-control: no-cache",
570 "content-type: application/json",
571
572 ),
573 ));
574
575 $response = curl_exec($curl);
576
577 if(!$response){
578 print '<div class="api_not_conected" style="margin:15px;">We could not connect to WpStream.net. Make sure you have the php Curl library enabled and your hosting allows outgoing HTTP Connection. </div>';
579 }
580
581 $err = curl_error($curl);
582
583
584
585
586
587 curl_close($curl);
588 $response= json_decode($response);
589
590 if(isset($response->access_token)){
591 return $response->access_token;
592 }else{
593 return;
594 }
595 }
596
597
598
599
600 /**
601 * Return admin package data
602 *
603 * @since 3.0.1
604 * returns pack data
605 */
606
607 public function wpstream_request_pack_data_per_user(){
608
609 if( !current_user_can('administrator') ){
610 exit('okko 1');
611 }
612 $token = $this->wpstream_get_token();
613 $values_array = array();
614 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/status/packdetails/?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 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
629
630
631
632 if( !is_wp_error($response) && isset($response['response']['code']) && $response['response']['code']=='200'){
633 return ($received_data);
634 }else{
635 return 'failed connection';
636 }
637
638 }
639
640 /**
641 * Check Api Status
642 *
643 * @since 3.0.1
644 * returns true or false
645 */
646
647 function wpstream_client_check_api_status(){
648
649 $token= $this->wpstream_get_token();
650
651 $url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/status/?access_token=".$token;
652 $arguments = array(
653 'method' => 'GET',
654 'timeout' => 45,
655 'redirection' => 5,
656 'httpversion' => '1.0',
657 'blocking' => true,
658 'headers' => array(),
659 'cookies' => array()
660 );
661 $response = wp_remote_post($url,$arguments);
662 $body = wp_remote_retrieve_body($response);
663
664 if ( $body === true || $body ==='true'){
665 return true;
666 }else{
667 return false;
668 }
669 }
670
671 /**
672 * Start Get live events for users
673 *
674 * @since 3.0.1
675 * returns true or false
676 */
677 public function wpstream_get_live_event_for_user(){
678 $current_user = wp_get_current_user();
679 $allowded_html = array();
680 $userID = $current_user->ID;
681 $return_uri = '';
682
683 if(function_exists('wpstream_get_option') && intval(wpstream_get_option('allow_streaming_regular_users',''))==1 ){
684 if( !is_user_logged_in() ){
685 exit('okko mnb1');
686 }
687 }else{
688 if( !current_user_can('administrator') ){
689 exit('okko mn1');
690 }
691 }
692
693
694 $event_data = $this->wpstream_request_live_stream_for_user($userID);
695 return $event_data;
696 }
697
698
699
700 /**
701 * Start Get live events for users and $show_id
702 *
703 * @since 3.0.1
704 * returns true or false
705 */
706 public function api20_wpstream_get_live_event_for_user(){
707
708 if(function_exists('wpstream_get_option') && intval(wpstream_get_option('allow_streaming_regular_users',''))==1 ){
709 if( !is_user_logged_in() ){
710 exit('okko mnb1');
711 }
712 }else{
713 if( !current_user_can('administrator') ){
714 exit('okko mn1');
715 }
716 }
717
718
719 $event_data = $this->api20_wpstream_request_live_stream_for_user();
720 return $event_data;
721 }
722
723
724
725
726
727
728
729 /**
730 * Start Get live events for users
731 *
732 * @since 3.0.1
733 * returns true or false
734 */
735 public function wpstream_request_live_stream_for_user($user_id){
736
737 if(function_exists('wpstream_get_option') && intval(wpstream_get_option('allow_streaming_regular_users',''))==1 ){
738 if( !is_user_logged_in() ){
739 exit('okko grt1z');
740 }
741 }else{
742 if( !current_user_can('administrator') ){
743 exit('okko grt1');
744 }
745 }
746
747
748 $domain = parse_url ( get_site_url() );
749 $token= $this->wpstream_get_token();
750
751 $values_array=array(
752 "show_id" => $user_id,
753 "scheme" => $domain['scheme'],
754 "domain" => $domain['host'],
755 "domain_ip" => $_SERVER['SERVER_ADDR']
756 );
757
758
759
760 $url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/livestrem/api20_peruser/?access_token=".$token;
761
762
763 $arguments = array(
764 'method' => 'GET',
765 'timeout' => 45,
766 'redirection' => 5,
767 'httpversion' => '1.0',
768 'blocking' => true,
769 'headers' => array(),
770 'body' => $values_array,
771 'cookies' => array()
772 );
773 $response = wp_remote_post($url,$arguments);
774 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
775
776 if(is_wp_error($response)){
777 return 'failed connection';
778 }
779 if( isset($response['response']['code']) && $response['response']['code']=='200'){
780 return ($received_data);
781 }else{
782 return 'failed connection';
783 }
784
785 }
786
787 public function api20_wpstream_request_live_stream_for_user(){
788
789 if(function_exists('wpstream_get_option') && intval(wpstream_get_option('allow_streaming_regular_users',''))==1 ){
790 if( !is_user_logged_in() ){
791 exit('okko grt1z');
792 }
793 }else{
794 if( !current_user_can('administrator') ){
795 exit('okko grt1');
796 }
797 }
798
799 $token = $this->wpstream_get_token();
800 $values_array = array();
801
802
803
804 $url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/livestrem/api20_peruser/?access_token=".$token;
805
806
807 $arguments = array(
808 'method' => 'GET',
809 'timeout' => 45,
810 'redirection' => 5,
811 'httpversion' => '1.0',
812 'blocking' => true,
813 'headers' => array(),
814 'body' => $values_array,
815 'cookies' => array()
816 );
817 $response = wp_remote_post($url,$arguments);
818
819 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
820
821 if(is_wp_error($response)){
822 return 'failed connection';
823 }
824 if( isset($response['response']['code']) && $response['response']['code']=='200'){
825 return ($received_data);
826 }else{
827 return 'failed connection';
828 }
829
830 }
831
832
833
834
835 /**
836 * Delete event
837 *
838 * @since 3.0.1
839 * returns noda
840 */
841
842 public function wpstream_close_event(){
843 check_ajax_referer( 'wpstream_start_event_nonce', 'security' );
844 $current_user = wp_get_current_user();
845 $allowded_html = array();
846 $userID = $current_user->ID;
847 $return_uri = '';
848 if( !current_user_can('administrator') ){
849 exit('okko');
850 }
851
852 $show_id = intval($_POST['show_id']);
853 update_post_meta ($show_id,'event_passed',1);
854 die();
855 }
856
857
858 /**
859 * Get signed upload form data
860 *
861 * @since 3.0.1
862 * returns aws form
863 */
864 public function wpstream_get_signed_form_upload_data(){
865 if( !current_user_can('administrator') ){
866 exit('okko');
867 }
868
869 $token = $this->wpstream_get_token();
870 $values_array = array();
871 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_upload_form/?access_token=".$token;
872
873
874 $arguments = array(
875 'method' => 'GET',
876 'timeout' => 45,
877 'redirection' => 5,
878 'httpversion' => '1.0',
879 'blocking' => true,
880 'headers' => array(),
881 'body' => $values_array,
882 'cookies' => array()
883 );
884 $response = wp_remote_post($url,$arguments);
885 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
886
887
888
889 if( isset($response['response']['code']) && $response['response']['code']=='200'){
890 return $received_data;
891 }else{
892 return 'failed connection';
893 }
894 }
895
896 /**
897 * Get video from storage- clear data for front end use
898 *
899 * @since 3.0.1
900 * returns aws data
901 */
902 public function wpstream_get_videos(){
903 if( !current_user_can('administrator') ){
904 exit('okko');
905 }
906 $token = $this->wpstream_get_token();
907 $values_array = array();
908 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_list_row/?access_token=".$token;
909
910
911 $arguments = array(
912 'method' => 'GET',
913 'timeout' => 45,
914 'redirection' => 5,
915 'httpversion' => '1.0',
916 'blocking' => true,
917 'headers' => array(),
918 'body' => $values_array,
919 'cookies' => array()
920 );
921 $response = wp_remote_post($url,$arguments);
922 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
923
924
925
926 if( isset($response['response']['code']) && $response['response']['code']=='200'){
927 $video_options=array();
928 foreach ($received_data as $key=>$videos){
929 $video_options[$videos['video_name_storage']]=$videos['video_name_storage'].'';
930 }
931
932 return $video_options;
933 }else{
934 return 'failed connection';
935 }
936
937
938
939
940 }
941
942
943
944 /**
945 * Get video from storage- raw data
946 *
947 * @since 3.0.1
948 * returns aws data
949 */
950 public function wpstream_get_videos_from_storage_raw_data( ){
951
952 if( !current_user_can('administrator') ){
953 exit('okko');
954 }
955 $token = $this->wpstream_get_token();
956 $values_array = array();
957 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_list_row/?access_token=".$token;
958
959
960 $arguments = array(
961 'method' => 'GET',
962 'timeout' => 45,
963 'redirection' => 5,
964 'httpversion' => '1.0',
965 'blocking' => true,
966 'headers' => array(),
967 'body' => $values_array,
968 'cookies' => array()
969 );
970 $response = wp_remote_post($url,$arguments);
971
972
973 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
974
975
976
977 if( isset($response['response']['code']) && $response['response']['code']=='200'){
978 return $received_data;
979 }else{
980 return 'failed connection';
981 }
982
983 }
984
985
986
987 /**
988 * Get download link from aws
989 *
990 * @since 3.0.1
991 * returns aws data
992 */
993
994 function wpstream_get_download_link(){
995 if( !current_user_can('administrator') ){
996 exit('okko get_download_link');
997 }
998
999 $video_name = sanitize_text_field($_POST['video_name']);
1000 $token = $this->wpstream_get_token();
1001 $values_array = array();
1002 $values_array['video_name'] = $video_name;
1003 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_download_link/?access_token=".$token;
1004
1005
1006 $arguments = array(
1007 'method' => 'GET',
1008 'timeout' => 45,
1009 'redirection' => 5,
1010 'httpversion' => '1.0',
1011 'blocking' => true,
1012 'headers' => array(),
1013 'body' => $values_array,
1014 'cookies' => array()
1015 );
1016 $response = wp_remote_post($url,$arguments);
1017 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
1018
1019 if( isset($response['response']['code']) && $response['response']['code']=='200'){
1020 print trim($received_data);
1021 }else{
1022 return 'failed connection';
1023 }
1024 exit();
1025 }
1026
1027
1028 /**
1029 * Delete file from storage
1030 *
1031 * @since 3.0.1
1032 *
1033 */
1034 public function wpstream_get_delete_file(){
1035 if( !current_user_can('administrator') ){
1036 exit('okko get_delete_file');
1037 }
1038
1039 $video_name = esc_html($_POST['video_name']);
1040 $token = $this->wpstream_get_token();
1041 $values_array = array();
1042 $values_array['video_name'] = $video_name;
1043 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_delete_file/?access_token=".$token;
1044
1045
1046 $arguments = array(
1047 'method' => 'GET',
1048 'timeout' => 45,
1049 'redirection' => 5,
1050 'httpversion' => '1.0',
1051 'blocking' => true,
1052 'headers' => array(),
1053 'body' => $values_array,
1054 'cookies' => array()
1055 );
1056 $response = wp_remote_post($url,$arguments);
1057 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
1058
1059
1060 if( isset($response['response']['code']) && $response['response']['code']=='200'){
1061 print $received_data;
1062 }else{
1063 return 'failed connection';
1064 }
1065 exit();
1066
1067
1068 }
1069
1070 /**
1071 * check if stream is live
1072 *
1073 * @since 3.0.1
1074 *
1075 */
1076 public function wpstream_is_is_live($product_id){
1077
1078 $token = $this->wpstream_get_token();
1079
1080 $values_array=array(
1081 "show_id" => $product_id,
1082 );
1083 $url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/livestrem/checklive/?access_token=".$token;
1084
1085
1086 $arguments = array(
1087 'method' => 'GET',
1088 'timeout' => 45,
1089 'redirection' => 5,
1090 'httpversion' => '1.0',
1091 'blocking' => true,
1092 'headers' => array(),
1093 'body' => $values_array,
1094 'cookies' => array()
1095 );
1096 $response = wp_remote_post($url,$arguments);
1097 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
1098
1099 if(is_wp_error($response)){
1100 return 'failed connection';
1101 }
1102 if( isset($response['response']['code']) && $response['response']['code']=='200'){
1103 return ($received_data);
1104 }else{
1105 return 'failed connection';
1106 }
1107
1108 }
1109
1110 /**
1111 * get server ip for live streaming
1112 *
1113 * @since 3.0.1
1114 *
1115 */
1116 public function wpstream_get_live_stream_server($current_user,$streamname){
1117
1118 $token = $this->wpstream_get_token();
1119 $values_array = array();
1120 $values_array['new_stream'] = $streamname;
1121
1122 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/livestrem/get_server_ip/?access_token=".$token;
1123
1124
1125 $arguments = array(
1126 'method' => 'GET',
1127 'timeout' => 45,
1128 'redirection' => 5,
1129 'httpversion' => '1.0',
1130 'blocking' => true,
1131 'headers' => array(),
1132 'body' => $values_array,
1133 'cookies' => array()
1134 );
1135 $response = wp_remote_post($url,$arguments);
1136
1137
1138 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
1139
1140 if( isset($response['response']['code']) && $response['response']['code']=='200'){
1141 return trim($received_data);
1142 }else{
1143 return 'failed connection';
1144 }
1145 exit();
1146
1147 }
1148
1149 }// end class