PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 4.4.9
WpStream – Live Streaming, Video on Demand, Pay Per View v4.4.9
4.14.1 4.14.0 4.13.2 4.13.1 4.13 4.12.5 4.12.4 4.12.3 4.12.2 4.12.1 4.12 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5 4.5.1 4.5.11 4.5.11.1 4.5.11.2 4.5.11.4 4.5.11.5 4.5.11.6 All 181 releases
wpstream / includes / class-wpstream-live-api-connection.php

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

1,193 lines 33.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_turn_of_channel', array($this,'wpstream_turn_of_channel') );
11 add_action( 'wp_ajax_wpstream_update_local_event_settings',array($this,'wpstream_update_local_event_settings'));
12
13 add_action( 'wp_ajax_wpstream_check_dns_sync', array($this,'wpstream_check_dns_sync') );
14 add_action( 'wp_ajax_wpstream_check_event_status', array($this,'wpstream_check_event_status') );
15
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 add_action( 'admin_notices',array($this, 'wpstream_admin_notices') );
21
22
23 }
24
25
26
27
28
29
30 /*
31 * Admin Notices
32 *
33 *
34 *
35 * */
36 function wpstream_admin_notices(){
37 global $pagenow;
38
39
40
41
42 if($pagenow!='admin.php'){
43 return;
44 }
45
46 $permited_pages=array('wpstream_plugin_options','wpstream_live_channels','wpstream_recordings','wpstream_settings');
47 if (!empty($_GET['page'])) {
48 $page = esc_html($_GET['page']) ;
49 if( !in_array($page, $permited_pages)){
50 return;
51 }
52 }
53
54 if(in_array('curl', get_loaded_extensions())){
55 //cURL module has been loaded
56 } else{
57 print '<div class="api_not_conected wpstream_notice_top">We could not connect to WpStream.net. Make sure you have the php Curl library enabled and your hosting allows outgoing HTTP Connection. </div>';
58 }
59
60 $token = $this->wpstream_get_token();
61 if($token=='' and $page!='wpstream_plugin_options'){
62 echo '<div class="api_not_conected wpstream_notice_top">'.__(' Incorrect username or password. Please check your credentials or go <a href="https://wpstream.net/my-account/edit-account/" target="_blank">here</a> to reset your password.','wpstream').'</div>';
63 }
64
65 }
66
67
68 /*
69 * Curl request
70 *
71 *
72 *
73 * */
74
75 function wpstream_baker_do_curl_base($url,$curl_post_fields){
76
77
78 $curl = curl_init();
79 $api_url = WPSTREAM_API.'/'.$url;
80
81
82
83 curl_setopt_array($curl, array(
84 CURLOPT_URL =>$api_url,
85 CURLOPT_RETURNTRANSFER => true,
86 CURLOPT_ENCODING => "",
87 CURLOPT_MAXREDIRS => 10,
88 CURLOPT_TIMEOUT => 10,
89 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
90 CURLOPT_CUSTOMREQUEST => "POST",
91 CURLOPT_POSTFIELDS => http_build_query($curl_post_fields),
92 CURLOPT_HTTPHEADER => array(
93 "cache-control: no-cache",
94 "content-type: application/x-www-form-urlencoded"
95 ),
96 ));
97
98 $response = curl_exec($curl);
99 $err = curl_error($curl);
100
101 curl_close($curl);
102
103 if ($err) {
104 echo "cURL Error #:" . $err;
105 }
106 return $response;
107
108 }
109
110
111
112
113
114
115
116 /**
117 * retreive server id based on show id
118 *
119 * @since 3.0.1
120 * returns live url
121 */
122
123 function retrive_server_id_based_on_show_id($show_id){
124
125 $transient_name = 'server_id_to_return_'.$show_id;
126 $server_id_to_return = get_transient( $transient_name );
127
128 if ( false === $server_id_to_return ) {
129 $token = $this->wpstream_get_token();
130 $values_array=array(
131 "show_id" => intval($show_id),
132 );
133 $values_array=array();
134 $show_id=intval($show_id);
135
136 $url="https://rest-baker.wpstream.net/?&apiFunctionName=server_id_by_show_id&show_id=".$show_id."&access_token=".$token;
137 $arguments = array(
138 'method' => 'GET',
139 'timeout' => 45,
140 'redirection' => 5,
141 'httpversion' => '1.0',
142 'blocking' => true,
143 'headers' => array(),
144 'body' => $values_array,
145 'cookies' => array()
146 );
147
148 $response = wp_remote_post($url,$arguments);
149
150 $received_data = wp_remote_retrieve_body($response);
151
152 $received_data_decoded=json_decode($received_data);
153
154
155 if( isset($response['response']['code']) && $response['response']['code']=='200' && $received_data_decoded->success===true && $received_data_decoded->result!=''){
156 $server_id_to_return = $received_data_decoded->result;
157 set_transient( $transient_name, json_decode($server_id_to_return), 60 );
158 return $server_id_to_return;
159
160 }else{
161 return '';
162
163 }
164 }else{
165 return $server_id_to_return;
166 }
167
168 die();
169 }
170
171
172
173 /**
174 * edited 4.0
175 *
176 *
177 *
178 * check event status from start stremaing process
179 *
180 * @since 3.0.1
181 * returns live url
182 */
183
184 public function wpstream_check_event_status(){
185 $channel_id = intval($_POST['channel_id']);
186 $notes = 'wpstream_check_event_status_note';
187 if(isset($_POST['notes'])){
188 $notes = sanitize_text_field($_POST['notes']);
189 }
190
191
192 $response = $this->wpstream_check_event_status_api_call($channel_id,$notes);
193
194
195
196 if( isset($response['success']) && $response['success']){
197 $this->api20_wpstream_update_event($response,$channel_id);
198
199 if( isset($response['broadcast_url']) && isset($response['status']) && $response['status']==='active' ){
200
201
202 $response['live_data_url'] = $response['qos_url'];
203
204 /* obsolote due to new url format
205 $local_event_options = get_post_meta ($channel_id,'local_event_options',true);
206 if( is_array( $local_event_options ) && intval( $local_event_options['autostart']) ==1 ){
207 $to_split=explode('/',$response['broadcast_url']);
208 $obs_stream = array_pop($to_split);;
209 $obs_uri = str_replace($obs_stream,'',$response['broadcast_url']);
210 }else{
211 $to_split=explode('wpstream/',$response['broadcast_url']);
212 $obs_uri = $to_split[0].'wpstream/';
213 $obs_stream = $to_split[1];
214 }
215 */
216
217
218 $to_split = explode('/',$response['broadcast_url']);
219 $obs_stream = array_pop($to_split);;
220 $obs_uri = str_replace($obs_stream,'',$response['broadcast_url']);
221
222 $response['obs_uri'] = $obs_uri;
223 $response['obs_stream'] = $obs_stream;
224
225 update_post_meta($channel_id,'obs_uri',$obs_uri);
226 update_post_meta($channel_id,'obs_stream',$obs_stream);
227 update_post_meta($channel_id,'broadcast_url',$response['broadcast_url']);
228
229 }
230
231
232 }
233
234 print json_encode($response);
235 die();
236
237 }
238
239 /**
240 * edited 4.0
241 *
242 * check event status from API
243 *
244 * @since 3.0.1
245 * returns live url
246 */
247
248
249 public function wpstream_check_event_status_api_call($channel_id,$notes){
250
251 $access_token = $this->wpstream_get_token();
252 $domain = parse_url ( get_site_url() );
253 $url = 'channel/info';
254
255 $curl_post_fields=array(
256 'access_token' => $access_token,
257 'channel_id' => $channel_id,
258 'domain' => $domain['host'],
259 'notes' => $notes
260 );
261
262
263
264
265
266 $curl_response = $this->wpstream_baker_do_curl_base($url,$curl_post_fields);
267
268
269 $curl_response_decoded = json_decode($curl_response,JSON_OBJECT_AS_ARRAY);
270
271 return $curl_response_decoded;
272
273
274 }
275
276
277
278
279
280
281
282
283
284
285
286
287 public function wpstream_reset_event_data($event_id){
288 update_post_meta($event_id,'stats_url','');
289 update_post_meta($event_id,'hls_playback_url','');
290 update_post_meta($event_id,'server_id', '' );
291 }
292
293 /**
294 * edited 4.0
295 * update event metadata
296 *
297 * @since 3.0.1
298 * returns live url
299 */
300
301
302
303 function api20_wpstream_update_event($response,$channel_id){
304
305 if( is_array($response) ) {
306 $event_data_for_transient = array();
307 $transient_name = 'event_data_to_return_'.$channel_id;
308
309 foreach($response as $key=>$value){
310 update_post_meta($channel_id,$key,$value);
311 $event_data_for_transient[$key]=$value;
312 }
313 set_transient($transient_name,$event_data_for_transient,45);
314 return $event_data_for_transient;
315 }else{
316 return false;
317 }
318
319
320 }
321
322 /**
323 * Update event settings
324 *
325 * @since 3.0.1
326 * returns live url
327 */
328
329
330 public function wpstream_update_local_event_settings(){
331
332 if(!is_user_logged_in()){
333 exit('not logged in');
334 }
335 if( !current_user_can('administrator') ){
336 exit('not admin');
337 }
338
339 $show_id = intval($_POST['show_id']);
340 $option_array = $_POST['option'];
341
342 $to_save_option=array();
343 foreach($option_array as $key=>$value){
344 $to_save_option[sanitize_key($key)]=sanitize_text_field($value);
345 }
346
347
348
349
350 update_post_meta ($show_id,'local_event_options',$to_save_option);
351 print 'do update with';
352 print_r($to_save_option);
353
354 $this->wpstream_update_chanel_on_baker($show_id,$to_save_option);
355
356 }
357
358
359
360 /**
361 * Update channel settings on baker
362 *
363 * @since 4.2
364 * returns live url
365 */
366
367
368 public function wpstream_update_chanel_on_baker($channel_id,$to_save_option){
369
370 $access_token = $this->wpstream_get_token();
371 if($access_token==''){
372 echo json_encode( array(
373 'is_record' => '',
374 'conected' => false,
375 'event_data' => '',
376 'error' => esc_html('You are not connected to wpstream.net! Please check your WpStream credentials!','wpstream'),
377 ));
378 exit();
379 }
380 $current_user = wp_get_current_user();
381 $userID = $current_user->ID;
382
383
384
385 $url = '/channel/update';
386 $local_event_options = get_post_meta($channel_id,'local_event_options',true);
387
388 $domain = parse_url ( get_site_url() );
389 $domain_scheme = 'http';
390 if(is_ssl()){
391 $domain_scheme='https';
392 }
393
394 $domain_ip= esc_html( $_SERVER['SERVER_ADDR'] );
395 if($domain_ip==''){
396 $domain_ip="0.0.0.0/0";
397 }
398
399 $corsorigin='*';
400 if( isset($local_event_options['domain_lock']) && intval( $local_event_options['domain_lock']) ==0 ){
401 $corsorigin='*';
402 }
403
404
405 if($corsorigin!='*'){
406 $corsorigin=$domain_scheme.'://'.$domain['host'];
407 }
408
409
410 $url = 'channel/update';
411
412
413 $to_record="false";
414 if($to_save_option['record']){
415 $to_record="true";
416 }
417
418 $curl_post_fields=array(
419 'access_token' => $access_token,
420 'channel_id' => $channel_id,
421 'domain' => $domain['host'],
422 'allow_access_from' => $corsorigin,
423 'record' => $to_record,
424 'encrypt' => boolval($to_save_option['encrypt']),
425 'autostart' => boolval($to_save_option['autostart']),
426 'hls_keys_url_prefix' => get_site_url().'?wpstream_livedrm=',
427 'allow_key_access_from' => $domain_ip,
428 );
429
430 print_r($curl_post_fields);
431 $curl_response = $this->wpstream_baker_do_curl_base($url,$curl_post_fields);
432 print_r($curl_response);
433 exit();
434 }
435
436
437
438
439
440 /**
441 *
442 * added 5.0
443 *
444 * Turn off channel
445 *
446 */
447 public function wpstream_turn_of_channel(){
448
449 $access_token = $this->wpstream_get_token();
450 if($access_token==''){
451 echo json_encode( array(
452 'is_record' => '',
453 'conected' => false,
454 'event_data' => '',
455 'error' => esc_html('You are not connected to wpstream.net! Please check your WpStream credentials!','wpstream'),
456 ));
457 exit();
458 }
459 $current_user = wp_get_current_user();
460 $userID = $current_user->ID;
461
462
463 global $wpstream_plugin;
464 if( !$wpstream_plugin->main->wpstream_check_user_can_stream() ){
465 exit('You are not allowed to stream.Code 407');
466 }
467
468
469 $channel_id = intval($_POST['show_id']);
470
471 $url = 'channel/stop';
472 $domain = parse_url ( get_site_url() );
473 $curl_post_fields=array(
474 'access_token' => $access_token,
475 'channel_id' => $channel_id,
476 'domain' => $domain['host'],
477
478 );
479
480
481
482 $curl_response = $this->wpstream_baker_do_curl_base($url,$curl_post_fields);
483 $curl_response_decoded = json_decode($curl_response,JSON_OBJECT_AS_ARRAY);
484
485
486
487 if( isset($curl_response_decoded['success']) && $curl_response_decoded['success']===true ){
488 echo json_encode( array(
489 'conected' => true,
490 'answer' => $curl_response_decoded,
491 ));
492 }else{
493 echo json_encode( array(
494 'conected' => false,
495 'error' => esc_html__('Channel is already turned off or does not exist!','wpstream'),
496 'answer' => $curl_response_decoded,
497 ));
498 }
499 die();
500
501
502
503
504 }
505
506
507 /**
508 *
509 * Edited 4.0
510 *
511 * Request live url
512 *
513 * @since 3.0.1
514 * returns live url
515 */
516 public function wpstream_give_me_live_uri(){
517
518 $access_token = $this->wpstream_get_token();
519 if($access_token==''){
520 echo json_encode( array(
521 'is_record' => '',
522 'conected' => false,
523 'event_data' => '',
524 'error' => esc_html('You are not connected to wpstream.net! Please check your WpStream credentials!','wpstream'),
525 ));
526 exit();
527 }
528
529 $current_user = wp_get_current_user();
530 $userID = $current_user->ID;
531
532
533 global $wpstream_plugin;
534 if( !$wpstream_plugin->main->wpstream_check_user_can_stream() ){
535 exit('You are not allowed to stream.Code 407');
536 }
537
538
539 $channel_id = intval($_POST['show_id']);
540 $on_boarding = '';
541 if(isset($_POST['start_onboarding'])){
542 $on_boarding = sanitize_text_field($_POST['start_onboarding']);
543 }
544
545
546 $local_event_options = get_post_meta($channel_id,'local_event_options',true);
547 if(!is_array($local_event_options)){
548 $local_event_options = get_option('wpstream_user_streaming_global_channel_options') ;
549 }
550
551
552 // set encrypt option
553 $is_autostart="false";
554 if( intval( $local_event_options['autostart']) ==1 ){
555 $is_autostart="true";
556 }
557
558
559 // set encrypt option
560 $is_encrypt="false";
561 if( intval( $local_event_options['encrypt']) ==1 ){
562 $is_encrypt="true";
563 }
564
565 // set record option
566 $is_record="false";
567 if( intval( $local_event_options['record']) ==1 ){
568 $is_record="true";
569 }
570
571 $corsorigin='';
572 if( isset($local_event_options['domain_lock']) && intval( $local_event_options['domain_lock']) ==0 ){
573 $corsorigin='*';
574 }
575
576
577 $event_data = $this->wpstream_request_live_stream_uri($channel_id,$is_autostart,$is_record,$is_encrypt,$userID,$corsorigin,$on_boarding);
578
579
580
581 if( isset($event_data['success']) && $event_data['success']===true ){
582 echo json_encode( array(
583 'is_record' => $is_record,
584 'conected' => true,
585 'event_data' => $event_data,
586
587 ));
588 }else{
589 $default_error= 'Failed to turn channel ON. Please try again in a few minutes.';
590 if( isset($event_data['error'])){
591 $plumer_error = $event_data['error'];
592 switch ($plumer_error) {
593 case 'NOT_ENOUGH_TRAFFIC':
594 $default_error= 'You do not have enough Streaming Data to turn ON a live channel. Please upgrade your subscription for more resources.' ;
595 break;
596
597 }
598
599 }
600 echo json_encode( array(
601 'is_record' => $is_record,
602 'conected' => false,
603 'event_data' => $event_data,
604 'error' => $default_error,
605
606
607 ));
608 }
609 die();
610 }
611
612
613 /**
614 *
615 * Edited 4.0
616 *
617 * Request live url via api
618 *
619 * @since 3.0.1
620 * returns live url
621 */
622
623
624 public function wpstream_request_live_stream_uri($schannel_id,$is_autostart,$is_record,$is_encrypt,$request_by_userid,$corsorigin,$on_boarding){
625
626 $domain = parse_url ( get_site_url() );
627 $domain_scheme = 'http';
628 if(is_ssl()){
629 $domain_scheme='https';
630 }
631
632 $domain_ip= esc_html( $_SERVER['SERVER_ADDR'] );
633 if($domain_ip==''){
634 $domain_ip="0.0.0.0/0";
635 }
636
637 if($corsorigin!='*'){
638 $corsorigin=$domain_scheme.'://'.$domain['host'];
639 }
640
641
642
643 $url = 'channel/start';
644 $access_token = $this->wpstream_get_token();
645
646 $metadata_array=array(
647 'pluginVersion'=>WPSTREAM_PLUGIN_VERSION
648 );
649
650 if($on_boarding!=''){
651 $metadata_array['on_boarding']='yes';
652 }
653
654
655 $curl_post_fields=array(
656 'access_token' => $access_token,
657 'channel_id' => $schannel_id,
658 'domain' => $domain['host'],
659 'allow_access_from' => $corsorigin,
660 'record' => $is_record,
661 'encrypt' => $is_encrypt,
662 'low_latency' => false,
663 'abr' => 'none',
664 'hls_keys_url_prefix' => get_site_url().'?wpstream_livedrm=',
665 'allow_key_access_from' => $domain_ip,
666 'metadata' => json_encode($metadata_array),
667 'autostart' => $is_autostart,
668 // 'fakeError' => 'init'
669 );
670
671
672
673 $curl_response = $this->wpstream_baker_do_curl_base($url,$curl_post_fields);
674 $curl_response_decoded = json_decode($curl_response,JSON_OBJECT_AS_ARRAY);
675
676 return $curl_response_decoded;
677
678
679
680 }
681
682
683
684
685
686
687
688
689
690
691
692 /**
693 * Retrive auth token from tranzient
694 *
695 * @since 3.0.1
696 * returns token
697 */
698 public function wpstream_get_token(){
699 $token = get_transient('wpstream_token_api');
700 if ( false === $token || $token==='' ) {
701 $token = $this->wpstream_club_get_token();
702 set_transient( 'wpstream_token_api', $token ,3500);
703 }
704
705 return $token;
706
707 }
708
709
710 public function wpstream_get_token_30(){
711 $token = get_transient('wpstream_token_request_30');
712 if ( false === $token || $token==='' ) {
713 $token = $this->wpstream_club_get_token_30();
714 set_transient( 'wpstream_token_request_30', $token ,600);
715 }
716
717 return $token;
718
719 }
720
721
722 /**
723 * Edited 4.0
724 *
725 * Request auth token from wpstream.net
726 *
727 * @since 3.0.1
728 * returns token fron wpstream
729 */
730 protected function wpstream_club_get_token(){
731
732
733 $username = esc_html ( get_option('wpstream_api_username','') );
734 $password = esc_html ( get_option('wpstream_api_password','') );
735
736 if ( $username=='' || $password==''){
737 return;
738 }
739
740 $url='access_token';
741 $curl_post_fields=array(
742 'grant_type' => 'password',
743 'username' => $username,
744 'password' => $password
745 );
746
747
748
749 $curl_response=$this->wpstream_baker_do_curl_base($url,$curl_post_fields);
750
751 $response= json_decode($curl_response);
752
753 if( isset($response->access_token) && $response->access_token!='' ){
754 return $response->access_token;
755 }else{
756 return false;
757 }
758 }
759
760
761
762 /*
763 *
764 * Return token for api version 3.0
765 *
766 */
767
768
769
770
771 protected function wpstream_club_get_token_30(){
772
773 $client_id = esc_html ( get_option('wpstream_api_key','') );
774 $client_secret = esc_html ( get_option('wpstream_api_secret_key','') );
775 $username = esc_html ( get_option('wpstream_api_username','') );
776 $password = esc_html ( get_option('wpstream_api_password','') );
777
778 if ( $username=='' || $password==''){
779 return;
780 }
781
782
783
784
785
786 $curl = curl_init();
787
788 $json = array(
789 'grant_type'=>'password',
790 'username' =>$username,
791 'password' =>$password,
792 'client_id'=>'qxZ6fCoOMj4cNK8SXRHa5nug6vnswlFWSF37hsW3',
793 'client_secret'=>'L1fzLosJf9TlwnCCTZ5pkKmdqqkHShKEi0d4oFNE'
794 );
795
796 curl_setopt_array($curl, array(
797 CURLOPT_URL => WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/?oauth=token",
798 CURLOPT_RETURNTRANSFER => true,
799 CURLOPT_ENCODING => "",
800 CURLOPT_MAXREDIRS => 10,
801 CURLOPT_TIMEOUT => 15,
802 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
803 CURLOPT_CUSTOMREQUEST => "POST",
804 CURLOPT_POSTFIELDS=> json_encode($json),
805 CURLOPT_HTTPHEADER => array(
806 "cache-control: no-cache",
807 "content-type: application/json",
808 ),
809 ));
810
811 $response = curl_exec($curl);
812
813 if(!$response){
814 //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>';
815 // echo '<div class="api_not_conected">'.__(' Incorrect username or password. Please check your credentials or go <a href="https://wpstream.net/my-account/edit-account/" target="_blank">here</a> to reset your password.','wpstream').'</div>';
816 }
817
818 $err = curl_error($curl);
819
820
821
822
823
824 curl_close($curl);
825 $response= json_decode($response);
826
827 if(isset($response->access_token)){
828 return $response->access_token;
829 }else{
830 return;
831 }
832 }
833
834
835
836 /**
837 * edited 4.0
838 * Return admin package data
839 *
840 * @since 3.0.1
841 * returns pack data
842 */
843
844 public function wpstream_request_pack_data_per_user(){
845
846 $event_data_for_transient = get_transient( 'wpstream_request_pack_data_per_user_transient' );
847
848 if($event_data_for_transient===false){
849 $url = 'user/quota';
850 $access_token = $this->wpstream_get_token();
851 $curl_post_fields=array(
852 'access_token'=>$access_token
853 );
854
855 $curl_response = $this->wpstream_baker_do_curl_base($url,$curl_post_fields);
856 $curl_response_decoded = json_decode($curl_response,JSON_OBJECT_AS_ARRAY);
857
858 if( isset($curl_response_decoded['success']) && $curl_response_decoded['success']===true ){
859 set_transient( 'wpstream_request_pack_data_per_user_transient', $curl_response_decoded, 15 );
860
861 update_option('wpstream_api_username_from_token',$curl_response_decoded['username']);
862 return $curl_response_decoded;
863 }else{
864 return false;
865 }
866
867 }else{
868 return $event_data_for_transient;
869 }
870
871 }
872
873
874
875
876 /**
877 * Edited 4.0
878 *
879 * Check Api Status
880 *
881 * @since 3.0.1
882 * returns true or false
883 */
884
885 function wpstream_client_check_api_status(){
886 return true;
887 }
888
889
890
891
892
893 /**
894 *
895 * Edited 4.0
896 *
897 * Start Get live events for users
898 *
899 * @since 3.0.1
900 * returns true or false
901 */
902
903 public function wpstream_get_live_event_for_user(){
904 $current_user = wp_get_current_user();
905 $userID = $current_user->ID;
906
907 global $wpstream_plugin;
908 if( !$wpstream_plugin->main->wpstream_check_user_can_stream() ){
909 exit('You are not allowed to start a live stream !');
910 }
911
912
913 $event_data = $this->wpstream_request_live_stream_for_user($userID);
914 $return_event = array();
915 if(is_array($event_data)):
916 foreach ($event_data as $key=>$event){
917 $return_event[$event['channel_id']]=$event;
918 }
919 endif;
920 return $return_event;
921 }
922
923
924
925
926
927
928
929
930
931
932 /**
933 *
934 * Edited 4.0
935 *
936 * Get live events for users
937 *
938 * @since 3.0.1
939 * returns true or false
940 */
941 public function wpstream_request_live_stream_for_user($user_id){
942
943 global $wpstream_plugin;
944 if( !$wpstream_plugin->main->wpstream_check_user_can_stream() ){
945 exit('You are not allowed to stream. Code 741.');
946 }
947
948
949 $domain = parse_url ( get_site_url() );
950
951
952 $url = 'channel/list';
953 $access_token = $this->wpstream_get_token();
954 $curl_post_fields=array(
955 'access_token' => $access_token,
956 'domain' => $domain['host'],
957 'status' => 'active'
958 );
959 $curl_response = $this->wpstream_baker_do_curl_base($url,$curl_post_fields);
960 $curl_response_decoded = json_decode($curl_response,JSON_OBJECT_AS_ARRAY);
961
962
963
964
965 if( isset($curl_response_decoded['success']) && $curl_response_decoded['success']==true ){
966 return $curl_response_decoded['channels'];
967 }else{
968 return false;
969 }
970
971
972 }
973
974
975 /**
976 * live events for shortocde - behind tranzisnt
977 * returns an array with local show id for live events
978 * @since 3.0.1
979 * returns noda
980 */
981 public function api20_wpstream_request_live_stream_for_user_for_shortcode($outside=''){
982 global $wpstream_plugin;
983 $return_array=array();
984
985 $result = get_transient('wpstream_live_stream_for_user_for_shortcode');
986 $result==false;
987 if($result===false){
988 $result = $this->wpstream_request_live_stream_for_user('');
989 set_transient('wpstream_live_stream_for_user_for_shortcode',$result,30);
990 }
991
992 if(is_array($result)):
993 foreach($result as $key=>$event){
994 $return_array[]=$event['channel_id'];
995 }
996 endif;
997 return $return_array;
998 }
999
1000
1001
1002
1003 /**
1004 * Delete event
1005 *
1006 * @since 3.0.1
1007 * returns noda
1008 */
1009
1010 public function wpstream_close_event(){
1011 //not implemented yet
1012 }
1013
1014
1015 /**
1016 * Get signed upload form data
1017 *
1018 * @since 3.0.1
1019 * returns aws form
1020 */
1021 public function wpstream_get_signed_form_upload_data(){
1022 if( !current_user_can('administrator') ){
1023 exit('not admin on wpstream_get_signed_form_upload_data');
1024 }
1025
1026
1027 $url = 'video/upload';
1028 $access_token = $this->wpstream_get_token();
1029 $curl_post_fields=array(
1030 'access_token' => $access_token,
1031 );
1032 $curl_response = $this->wpstream_baker_do_curl_base($url,$curl_post_fields);
1033 $curl_response_decoded = json_decode($curl_response,JSON_OBJECT_AS_ARRAY);
1034
1035
1036 return $curl_response_decoded;
1037 exit();
1038
1039 }
1040
1041
1042
1043
1044
1045
1046
1047 /**
1048 *
1049 * Get video from storage- clear data for front end use
1050 *
1051 * @since 3.0.1
1052 * returns aws data
1053 *
1054 */
1055 public function wpstream_get_videos(){
1056 if( !current_user_can('administrator') ){
1057 exit('not admin on wpstream_get_videos');
1058 }
1059
1060
1061 $video_options = array();
1062 $video_array = $this->wpstream_get_videos_from_api();
1063
1064 $video_list_raw_array = $video_array['items'];
1065
1066 $keys = array_column($video_list_raw_array, 'time');
1067 array_multisort($keys, SORT_DESC , $video_list_raw_array);
1068
1069
1070
1071 if(is_array($video_list_raw_array)){
1072 foreach ($video_list_raw_array as $key => $videos){
1073 if($videos['name']!=''):
1074 $video_options[$videos['name']]=$videos['name'];
1075 endif;
1076 }
1077
1078 }
1079 return $video_options;
1080
1081 }
1082
1083
1084
1085 /**
1086 *
1087 * Get video from storage- raw data
1088 *
1089 * @since 3.0.1
1090 * returns aws data
1091 *
1092 */
1093 public function wpstream_get_videos_from_api( ){
1094
1095 if( !current_user_can('administrator') ){
1096 exit('not admin on wpstream_get_videos_from_api');
1097 }
1098
1099
1100
1101 $url = 'video/list';
1102 $access_token = $this->wpstream_get_token();
1103 $curl_post_fields=array(
1104 'access_token' => $access_token,
1105 );
1106
1107 $current_page= get_current_screen();
1108 $curl_response = $this->wpstream_baker_do_curl_base($url,$curl_post_fields);
1109 $curl_response_decoded = json_decode($curl_response,JSON_OBJECT_AS_ARRAY);
1110
1111
1112
1113
1114 if( isset($curl_response_decoded['success']) && $curl_response_decoded['success']==true ){
1115 return $curl_response_decoded;
1116 }else{
1117 return array();
1118 }
1119
1120 }
1121
1122
1123
1124 /**
1125 * Get download link from aws
1126 *
1127 * @since 3.0.1
1128 * returns aws data
1129 */
1130
1131 function wpstream_get_download_link(){
1132
1133 if( !current_user_can('administrator') ){
1134 exit('not admin on get_download_link');
1135 }
1136
1137 $video_name = sanitize_text_field($_POST['video_name']);
1138
1139 $url = 'video/download';
1140 $access_token = $this->wpstream_get_token();
1141 $curl_post_fields=array(
1142 'access_token' => $access_token,
1143 'name' => $video_name,
1144 );
1145 $curl_response = $this->wpstream_baker_do_curl_base($url,$curl_post_fields);
1146 print $curl_response;
1147 exit();
1148
1149
1150
1151 }
1152
1153
1154 /**
1155 * Delete file from storage
1156 *
1157 * @since 3.0.1
1158 *
1159 */
1160 public function wpstream_get_delete_file(){
1161 if( !current_user_can('administrator') ){
1162 exit('not admin on get_delete_file');
1163 }
1164
1165 $video_name = esc_html($_POST['video_name']);
1166
1167
1168 $url = 'video/delete';
1169 $access_token = $this->wpstream_get_token();
1170 $curl_post_fields=array(
1171 'access_token' => $access_token,
1172 'name'=>$video_name,
1173 );
1174 $curl_response = $this->wpstream_baker_do_curl_base($url,$curl_post_fields);
1175 $curl_response_decoded = json_decode($curl_response,JSON_OBJECT_AS_ARRAY);
1176
1177
1178 print $curl_response;
1179
1180 exit();
1181
1182
1183 }
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193 }// end class