PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 2.08
WpStream – Live Streaming, Video on Demand, Pay Per View v2.08
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 / libs / api_functions.php

api_functions.php in WpStream – Live Streaming, Video on Demand, Pay Per View 2.08, at libs/api_functions.php

753 lines 21.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 add_action( 'wp_ajax_wpstream_check_server_against_db', 'wpstream_check_server_against_db' );
3 function wpstream_check_server_against_db(){
4 $show_id = intval($_POST['show_id']);
5 $is_live = false;
6
7 $live_event_for_user = wpstream_get_live_event_for_user();
8 if(isset($live_event_for_user[$show_id])) {
9 $is_live=true;
10 }
11
12 echo json_encode( array('islive' =>$is_live) );
13 exit();
14 }
15
16
17
18 function wpstream_get_videos(){
19 $current_user = wp_get_current_user();
20 $allowded_html = array();
21 $userID = $current_user->ID;
22 $return_uri = '';
23 if( !current_user_can('administrator') ){
24 exit('');
25 }
26 $video_data = wpstream_get_videos_from_storage();
27 return $video_data;
28 }
29
30
31
32
33
34 function wpstream_get_pack_details_user(){
35 $current_user = wp_get_current_user();
36 $allowded_html = array();
37 $userID = $current_user->ID;
38 $return_uri = '';
39 if( !current_user_can('administrator') ){
40 exit('');
41 }
42 $pack_data = wpstream_request_pack_data_per_user();
43 return $pack_data;
44 }
45
46
47
48
49 function wpstream_get_live_event_for_user(){
50 $current_user = wp_get_current_user();
51 $allowded_html = array();
52 $userID = $current_user->ID;
53 $return_uri = '';
54 if( !current_user_can('administrator') ){
55 exit('');
56 }
57 $event_data = wpstream_request_live_stream_for_user($userID);
58 return $event_data;
59 }
60
61
62
63
64 add_action( 'wp_ajax_wpstream_close_event', 'wpstream_close_event' );
65 function wpstream_close_event(){
66 check_ajax_referer( 'wpstream_start_event_nonce', 'security' );
67 $current_user = wp_get_current_user();
68 $allowded_html = array();
69 $userID = $current_user->ID;
70 $return_uri = '';
71 if( !current_user_can('administrator') ){
72 exit('okko');
73 }
74
75 $show_id = intval($_POST['show_id']);
76
77 update_post_meta ($show_id,'event_passed',1);
78
79 die();
80 }
81
82
83
84
85
86 add_action( 'wp_ajax_wpstream_give_me_live_uri', 'wpstream_give_me_live_uri' );
87 function wpstream_give_me_live_uri(){
88
89 check_ajax_referer( 'wpstream_start_event_nonce', 'security' );
90 $current_user = wp_get_current_user();
91 $allowded_html = array();
92 $userID = $current_user->ID;
93 $return_uri = '';
94
95 if( !current_user_can('administrator') ){
96 exit('okko');
97 }
98
99 $show_id = intval($_POST['show_id']);
100 $is_record = floatval($_POST['is_record']);
101
102
103
104
105 $event_data = wpstream_request_live_stream_uri($show_id,$is_record);
106
107
108
109 if(is_array($event_data)){
110 $explode = explode('wpstream.net/', $event_data['live_uri']);
111 $uri = $explode[0].'wpstream.net/wpstream/';
112 $server_status_check =
113 $stream_key = trim(str_replace('wpstream/',' ',$explode[1]));
114
115
116 update_post_meta($show_id,'live_event_uri', $event_data['live_uri']);
117 update_post_meta($show_id,'live_event_stream_name', $event_data['carnat1']);
118 update_post_meta($show_id,'ip', $event_data['ip']);
119
120
121
122 if( isset($event_data['dns_change_id']) && $event_data['dns_change_id']!='' ){
123
124 echo json_encode( array(
125 'sometihng' => 'mr',
126 'conected' => true,
127 'caster_url' => $event_data['webcaster_url'],
128 'live_uri' => $event_data['live_uri'] ,
129 'all_data' => $event_data,
130 'obs_uri' => $event_data['live_uri2'],
131 'obs_stream' => $stream_key,
132 'server_status_check' => 'http://'.$event_data['ip'].':8444' ,
133 'ip' => $event_data['ip'],
134 'subdomain_key' => $event_data['subdomain_key'],
135 'dns_change_id' => $event_data['dns_change_id']
136 )
137 );
138
139 }else{
140 echo json_encode( array(
141 'error' =>'No dns change id'
142 ));
143 }
144
145 }else{
146 echo json_encode( array(
147 'error' =>'no answer'
148 ));
149 }
150 die();
151 }
152
153
154
155
156 function wpstream_get_videos_from_storage(){
157
158 if( !current_user_can('administrator') ){
159 exit('okko');
160 }
161 $token = wpstream_rcapi_retrive_token();
162 $values_array = array();
163 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_list_row/?access_token=".$token;
164
165
166 $arguments = array(
167 'method' => 'GET',
168 'timeout' => 45,
169 'redirection' => 5,
170 'httpversion' => '1.0',
171 'blocking' => true,
172 'headers' => array(),
173 'body' => $values_array,
174 'cookies' => array()
175 );
176 $response = wp_remote_post($url,$arguments);
177 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
178
179
180
181 if( isset($response['response']['code']) && $response['response']['code']=='200'){
182 $video_options=array();
183 foreach ($received_data as $key=>$videos){
184 $video_options[$videos['video_name_storage']]=$videos['video_name_storage'].'';
185 }
186
187 return $video_options;
188 }else{
189 return 'failed connection';
190 }
191
192 }
193
194
195
196
197
198 add_action( 'wp_ajax_wpstream_get_delete_file', 'wpstream_get_delete_file' );
199 function wpstream_get_delete_file(){
200 if( !current_user_can('administrator') ){
201 exit('okko');
202 }
203
204 $video_name = esc_html($_POST['video_name']);
205 $token = wpstream_rcapi_retrive_token();
206 $values_array = array();
207 $values_array['video_name'] = $video_name;
208
209 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_delete_file/?access_token=".$token;
210
211
212 $arguments = array(
213 'method' => 'GET',
214 'timeout' => 45,
215 'redirection' => 5,
216 'httpversion' => '1.0',
217 'blocking' => true,
218 'headers' => array(),
219 'body' => $values_array,
220 'cookies' => array()
221 );
222 $response = wp_remote_post($url,$arguments);
223
224 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
225
226
227 if( isset($response['response']['code']) && $response['response']['code']=='200'){
228 print $received_data;
229 }else{
230 return 'failed connection';
231 }
232 exit();
233
234
235 }
236
237
238 add_action( 'wp_ajax_wpstream_get_download_link', 'wpstream_get_download_link' );
239 function wpstream_get_download_link(){
240 if( !current_user_can('administrator') ){
241 exit('okko');
242 }
243
244 $video_name=esc_html($_POST['video_name']);
245 $token = wpstream_rcapi_retrive_token();
246 $values_array = array();
247 $values_array['video_name'] = $video_name;
248
249 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_download_link/?access_token=".$token;
250
251
252 $arguments = array(
253 'method' => 'GET',
254 'timeout' => 45,
255 'redirection' => 5,
256 'httpversion' => '1.0',
257 'blocking' => true,
258 'headers' => array(),
259 'body' => $values_array,
260 'cookies' => array()
261 );
262 $response = wp_remote_post($url,$arguments);
263
264
265 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
266
267
268
269
270 if( isset($response['response']['code']) && $response['response']['code']=='200'){
271 print trim($received_data);
272 }else{
273 return 'failed connection';
274 }
275 exit();
276
277
278 }
279
280
281
282 add_action( 'wp_ajax_wpstream_update_video_status', 'wpstream_update_video_status' );
283 function wpstream_update_video_status(){
284 if( !current_user_can('administrator') ){
285 exit('okko');
286 }
287
288 $video_id = intval($_POST['video_id']);
289 $status = intval($_POST['status']);
290 $video_name = esc_html($_POST['video_name']);
291 $video_name_storage = esc_html($_POST['video_name_storage']);
292
293 $token = wpstream_rcapi_retrive_token();
294 $values_array = array();
295 $values_array['video_id'] = $video_id;
296 $values_array['status'] = $status;
297 $values_array['video_name'] = $video_name;
298 $values_array['video_name_storage']=$video_name_storage;
299
300
301 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/update_video_status/?access_token=".$token;
302
303
304 $arguments = array(
305 'method' => 'GET',
306 'timeout' => 45,
307 'redirection' => 5,
308 'httpversion' => '1.0',
309 'blocking' => true,
310 'headers' => array(),
311 'body' => $values_array,
312 'cookies' => array()
313 );
314 $response = wp_remote_post($url,$arguments);
315 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
316
317
318
319
320 if( isset($response['response']['code']) && $response['response']['code']=='200'){
321 return $received_data;
322 }else{
323 return 'failed connection';
324 }
325 exit();
326
327
328 }
329
330 function wpstream_get_signed_form_upload_data(){
331 if( !current_user_can('administrator') ){
332 exit('okko');
333 }
334
335 $token = wpstream_rcapi_retrive_token();
336 $values_array = array();
337 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_upload_form/?access_token=".$token;
338
339
340 $arguments = array(
341 'method' => 'GET',
342 'timeout' => 45,
343 'redirection' => 5,
344 'httpversion' => '1.0',
345 'blocking' => true,
346 'headers' => array(),
347 'body' => $values_array,
348 'cookies' => array()
349 );
350 $response = wp_remote_post($url,$arguments);
351 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
352
353
354
355 if( isset($response['response']['code']) && $response['response']['code']=='200'){
356 return $received_data;
357 }else{
358 return 'failed connection';
359 }
360 }
361
362 function wpstream_get_videos_from_storage_raw_data(){
363
364 if( !current_user_can('administrator') ){
365 exit('okko');
366 }
367 $token = wpstream_rcapi_retrive_token();
368 $values_array = array();
369 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_list_row/?access_token=".$token;
370
371
372 $arguments = array(
373 'method' => 'GET',
374 'timeout' => 45,
375 'redirection' => 5,
376 'httpversion' => '1.0',
377 'blocking' => true,
378 'headers' => array(),
379 'body' => $values_array,
380 'cookies' => array()
381 );
382 $response = wp_remote_post($url,$arguments);
383
384
385 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
386
387
388
389 if( isset($response['response']['code']) && $response['response']['code']=='200'){
390 return $received_data;
391 }else{
392 return 'failed connection';
393 }
394
395 }
396
397
398
399 function wpstream_request_pack_data_per_user(){
400
401 if( !current_user_can('administrator') ){
402 exit('okko');
403 }
404 $token = wpstream_rcapi_retrive_token();
405 $values_array = array();
406 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/status/packdetails/?access_token=".$token;
407
408
409 $arguments = array(
410 'method' => 'GET',
411 'timeout' => 45,
412 'redirection' => 5,
413 'httpversion' => '1.0',
414 'blocking' => true,
415 'headers' => array(),
416 'body' => $values_array,
417 'cookies' => array()
418 );
419 $response = wp_remote_post($url,$arguments);
420 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
421
422
423
424 if( isset($response['response']['code']) && $response['response']['code']=='200'){
425 return ($received_data);
426 }else{
427 return 'failed connection';
428 }
429
430 }
431
432
433 function wpstream_request_live_stream_for_user($user_id){
434 if( !current_user_can('administrator') ){
435 exit('okko');
436 }
437 $domain = parse_url ( get_site_url() );
438 $token = wpstream_rcapi_retrive_token();
439
440 $values_array=array(
441 "show_id" => $user_id,
442 "scheme" => $domain['scheme'],
443 "domain" => $domain['host'],
444 "domain_ip" => $_SERVER['SERVER_ADDR']
445 );
446
447
448
449 $url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/livestrem/peruser/?access_token=".$token;
450
451
452 $arguments = array(
453 'method' => 'GET',
454 'timeout' => 45,
455 'redirection' => 5,
456 'httpversion' => '1.0',
457 'blocking' => true,
458 'headers' => array(),
459 'body' => $values_array,
460 'cookies' => array()
461 );
462 $response = wp_remote_post($url,$arguments);
463 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
464
465 if(is_wp_error($response)){
466 return 'failed connection';
467 }
468 if( isset($response['response']['code']) && $response['response']['code']=='200'){
469 return ($received_data);
470 }else{
471 return 'failed connection';
472 }
473
474 }
475
476
477
478 add_action( 'wp_ajax_wpstream_check_dns_sync', 'wpstream_check_dns_sync' );
479 function wpstream_check_dns_sync(){
480 $token = wpstream_rcapi_retrive_token();
481
482
483 $values_array=array(
484 "dns_change_id" => esc_html($_POST['change_id']),
485 );
486
487 $url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/checkdns/get/?access_token=".$token;
488
489
490 $arguments = array(
491 'method' => 'GET',
492 'timeout' => 45,
493 'redirection' => 5,
494 'httpversion' => '1.0',
495 'blocking' => true,
496 'headers' => array(),
497 'body' => $values_array,
498 'cookies' => array()
499 );
500
501
502
503 $response = wp_remote_post($url,$arguments);
504
505 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
506
507
508
509
510 if( isset($response['response']['code']) && $response['response']['code']=='200'){
511 print ($received_data);
512 }else{
513 // print 'failed connection';
514 }
515 die();
516 }
517
518
519
520
521
522 function wpstream_request_live_stream_uri($show_id,$is_record){
523 $token = wpstream_rcapi_retrive_token();
524 $domain = parse_url ( get_site_url() );
525
526 $values_array=array(
527 "show_id" => $show_id,
528 "scheme" => $domain['scheme'],
529 "domain" => $domain['host'],
530 "domain_ip" => $_SERVER['SERVER_ADDR'],
531 "is_record" => $is_record,
532 "location" => get_home_url()
533 );
534
535 $url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/livestrem/new/?access_token=".$token;
536
537
538 $arguments = array(
539 'method' => 'GET',
540 'timeout' => 45,
541 'redirection' => 5,
542 'httpversion' => '1.0',
543 'blocking' => true,
544 'headers' => array(),
545 'body' => $values_array,
546 'cookies' => array()
547 );
548 $response = wp_remote_post($url,$arguments);
549
550 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
551
552
553
554
555 if( isset($response['response']['code']) && $response['response']['code']=='200'){
556 return ($received_data);
557 }else{
558 return 'failed connection';
559 }
560
561 }
562
563
564
565 function wpstream_rcapi_retrive_token(){
566 $token = get_transient('wpstream_token_request');
567 if ( false === $token || $token==='' ) {
568 $token = wpstream_club_get_token();
569 set_transient( 'wpstream_token_request', $token ,600);
570 }
571
572 return $token;
573
574 }
575
576
577
578 function wpstream_club_get_token(){
579
580 $client_id = esc_html ( get_option('wpstream_api_key','') );
581 $client_secret = esc_html ( get_option('wpstream_api_secret_key','') );
582 $username = esc_html ( get_option('wpstream_api_username','') );
583 $password = esc_html ( get_option('wpstream_api_password','') );
584
585 if ( $username=='' || $password==''){
586 return;
587 }
588 $curl = curl_init();
589
590 curl_setopt_array($curl, array(
591 CURLOPT_URL => WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/?oauth=token",
592 CURLOPT_RETURNTRANSFER => true,
593 CURLOPT_ENCODING => "",
594 CURLOPT_MAXREDIRS => 10,
595 CURLOPT_TIMEOUT => 30,
596 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
597 CURLOPT_CUSTOMREQUEST => "POST",
598 CURLOPT_POSTFIELDS => "grant_type=password&username=".$username."&password=".$password,
599 CURLOPT_HTTPHEADER => array(
600 "authorization: Basic ". base64_encode( '$client_id' . ':' . '$client_secret' ),
601 "cache-control: no-cache",
602 "content-type: application/x-www-form-urlencoded",
603 "postman-token: 3d65984a-9f80-a881-5fe9-59717126687e"
604 ),
605 ));
606
607 $response = curl_exec($curl);
608 $err = curl_error($curl);
609
610 curl_close($curl);
611 $response= json_decode($response);
612
613 if(isset($response->access_token)){
614 return $response->access_token;
615 }else{
616 return;
617 }
618 }
619
620
621
622
623
624 function wpstream_client_check_api_status(){
625
626 $token= wpstream_rcapi_retrive_token();
627
628 $url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/status/?access_token=".$token;
629 $arguments = array(
630 'method' => 'GET',
631 'timeout' => 45,
632 'redirection' => 5,
633 'httpversion' => '1.0',
634 'blocking' => true,
635 'headers' => array(),
636 'cookies' => array()
637 );
638 $response = wp_remote_post($url,$arguments);
639 $body = wp_remote_retrieve_body($response);
640
641 if ( $body === true || $body ==='true'){
642 return true;
643 }else{
644 return false;
645 }
646 }
647
648
649
650 function wpstream_retrive_username(){
651 $token= wpstream_rcapi_retrive_token();
652
653 $url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/return_login/?access_token=".$token;
654 $arguments = array(
655 'method' => 'GET',
656 'timeout' => 45,
657 'redirection' => 5,
658 'httpversion' => '1.0',
659 'blocking' => true,
660 'headers' => array(),
661 'cookies' => array()
662 );
663 $response = wp_remote_post($url,$arguments);
664
665 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
666
667
668 if( isset($response['response']['code']) && $response['response']['code']=='200'){
669 return ($received_data); die();
670 }else{
671 print 'Failed to conbect media server';
672 die();
673 }
674
675
676
677 }
678
679 function wpstream_get_live_stream_server($current_user,$streamname){
680
681 $token = wpstream_rcapi_retrive_token();
682 $values_array = array();
683 $values_array['new_stream'] = $streamname;
684
685 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/livestrem/get_server_ip/?access_token=".$token;
686
687
688 $arguments = array(
689 'method' => 'GET',
690 'timeout' => 45,
691 'redirection' => 5,
692 'httpversion' => '1.0',
693 'blocking' => true,
694 'headers' => array(),
695 'body' => $values_array,
696 'cookies' => array()
697 );
698 $response = wp_remote_post($url,$arguments);
699
700
701 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
702
703 if( isset($response['response']['code']) && $response['response']['code']=='200'){
704 return trim($received_data);
705 }else{
706 return 'failed connection';
707 }
708 exit();
709
710 }
711
712
713
714
715 function wpstream_request_hls_player($product_id){
716
717
718 $show_id = intval($product_id);
719 $token = wpstream_rcapi_retrive_token();
720 $values_array = array();
721 $values_array['show_id'] = $show_id;
722
723 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_player_hls/?access_token=".$token;
724
725
726 $arguments = array(
727 'method' => 'GET',
728 'timeout' => 45,
729 'redirection' => 5,
730 'httpversion' => '1.0',
731 'blocking' => true,
732 'headers' => array(),
733 'body' => $values_array,
734 'cookies' => array()
735 );
736 $response = wp_remote_post($url,$arguments);
737
738 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
739
740
741
742
743 if( isset($response['response']['code']) && $response['response']['code']=='200'){
744 return trim($received_data);
745 }else{
746 return 'failed connection';
747 }
748 exit();
749
750
751 }
752
753