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