| 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 |
global $wpstream_plugin; |
| 375 |
if( !$wpstream_plugin->main->wpstream_check_user_can_stream() ){ |
| 376 |
exit('not allowed to stream 376'); |
| 377 |
} |
| 378 |
|
| 379 |
|
| 380 |
if( ( trim( get_option('wpstream_api_username') )=='' || trim( get_option('wpstream_api_password')== '')) || !$this->wpstream_client_check_api_status() ){ |
| 381 |
|
| 382 |
echo json_encode( array( |
| 383 |
'conected' => false, |
| 384 |
'event_data' => '', |
| 385 |
'error' => esc_html__('You are not connected to wpstream.net! Please check your WpStream credentials! ','wpstream') |
| 386 |
|
| 387 |
)); |
| 388 |
die(); |
| 389 |
|
| 390 |
|
| 391 |
} |
| 392 |
|
| 393 |
|
| 394 |
$show_id = intval ( $_POST['show_id'] ); |
| 395 |
update_post_meta($show_id,'server_id', '' ); |
| 396 |
$is_record = esc_html( $_POST['is_record'] ); |
| 397 |
$is_encrypt = esc_html( $_POST['is_encrypt'] ); |
| 398 |
$event_data = $this->wpstream_request_live_stream_uri($show_id,$is_record,$is_encrypt,$userID); |
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
if($event_data){ |
| 403 |
echo json_encode( array( |
| 404 |
'conected' => true, |
| 405 |
'event_data' => $event_data, |
| 406 |
|
| 407 |
)); |
| 408 |
}else{ |
| 409 |
echo json_encode( array( |
| 410 |
'conected' => false, |
| 411 |
'event_data' => $event_data, |
| 412 |
'error' => 'Error 4176'// no aws server dns propagation, |
| 413 |
|
| 414 |
)); |
| 415 |
} |
| 416 |
die(); |
| 417 |
} |
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
public function wpstream_request_live_stream_uri($show_id,$is_record,$is_encrypt,$request_by_userid){ |
| 424 |
$token = $this->wpstream_get_token(); |
| 425 |
$domain = parse_url ( get_site_url() ); |
| 426 |
|
| 427 |
$home_url = get_home_url(); |
| 428 |
$domain_scheme = 'http'; |
| 429 |
$home_url = str_replace('https://','http://',$home_url); |
| 430 |
|
| 431 |
if(is_ssl()){ |
| 432 |
$domain_scheme='https'; |
| 433 |
$home_url = str_replace('http://','https://',$home_url); |
| 434 |
} |
| 435 |
|
| 436 |
$domain_ip= esc_html( $_SERVER['SERVER_ADDR'] ); |
| 437 |
if($domain_ip==''){ |
| 438 |
$domain_ip="0.0.0.0/0"; |
| 439 |
} |
| 440 |
|
| 441 |
$values_array=array( |
| 442 |
"show_id" => $show_id, |
| 443 |
"scheme" => $domain_scheme, |
| 444 |
"domain" => $domain['host'], |
| 445 |
"domain_ip" => $domain_ip, |
| 446 |
"is_record" => $is_record, |
| 447 |
"is_encrypt" => $is_encrypt, |
| 448 |
"location" => $home_url, |
| 449 |
"request_by_userid" => $request_by_userid, |
| 450 |
"pluginVersion" => WPSTREAM_PLUGIN_VERSION |
| 451 |
); |
| 452 |
|
| 453 |
$url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/api20-livestrem/new/?access_token=".$token; |
| 454 |
|
| 455 |
$arguments = array( |
| 456 |
'method' => 'GET', |
| 457 |
'timeout' => 45, |
| 458 |
'redirection' => 5, |
| 459 |
'httpversion' => '1.0', |
| 460 |
'blocking' => true, |
| 461 |
'headers' => array(), |
| 462 |
'body' => $values_array, |
| 463 |
'cookies' => array() |
| 464 |
); |
| 465 |
$response = wp_remote_post($url,$arguments); |
| 466 |
|
| 467 |
$received_data = json_decode( wp_remote_retrieve_body($response) ,true); |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
if( isset($response['response']['code']) && $response['response']['code']=='200'){ |
| 472 |
return ($received_data); |
| 473 |
}else{ |
| 474 |
if($received_data['data']['status']=='401'){ |
| 475 |
return('You are not connected to wpstream.net! Please check your WpStream credentials! '); |
| 476 |
|
| 477 |
}else{ |
| 478 |
return 'Failed to connect to WpStream. Please try again later.'; |
| 479 |
} |
| 480 |
|
| 481 |
} |
| 482 |
|
| 483 |
} |
| 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 |
* Retrive auth token from tranzient |
| 509 |
* |
| 510 |
* @since 3.0.1 |
| 511 |
* returns token |
| 512 |
*/ |
| 513 |
public function wpstream_get_token(){ |
| 514 |
$token = get_transient('wpstream_token_request'); |
| 515 |
if ( false === $token || $token==='' ) { |
| 516 |
$token = $this->wpstream_club_get_token(); |
| 517 |
set_transient( 'wpstream_token_request', $token ,600); |
| 518 |
} |
| 519 |
|
| 520 |
return $token; |
| 521 |
|
| 522 |
} |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
/** |
| 527 |
* Request auth token from wpstream.net |
| 528 |
* |
| 529 |
* @since 3.0.1 |
| 530 |
* returns token fron wpstream |
| 531 |
*/ |
| 532 |
protected function wpstream_club_get_token(){ |
| 533 |
|
| 534 |
$client_id = esc_html ( get_option('wpstream_api_key','') ); |
| 535 |
$client_secret = esc_html ( get_option('wpstream_api_secret_key','') ); |
| 536 |
$username = esc_html ( get_option('wpstream_api_username','') ); |
| 537 |
$password = esc_html ( get_option('wpstream_api_password','') ); |
| 538 |
|
| 539 |
if ( $username=='' || $password==''){ |
| 540 |
return; |
| 541 |
} |
| 542 |
$curl = curl_init(); |
| 543 |
|
| 544 |
$json = array( |
| 545 |
'grant_type'=>'password', |
| 546 |
'username' =>$username, |
| 547 |
'password' =>$password, |
| 548 |
'client_id'=>'qxZ6fCoOMj4cNK8SXRHa5nug6vnswlFWSF37hsW3', |
| 549 |
'client_secret'=>'L1fzLosJf9TlwnCCTZ5pkKmdqqkHShKEi0d4oFNE' |
| 550 |
); |
| 551 |
|
| 552 |
curl_setopt_array($curl, array( |
| 553 |
CURLOPT_URL => WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/?oauth=token", |
| 554 |
CURLOPT_RETURNTRANSFER => true, |
| 555 |
CURLOPT_ENCODING => "", |
| 556 |
CURLOPT_MAXREDIRS => 10, |
| 557 |
CURLOPT_TIMEOUT => 30, |
| 558 |
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
| 559 |
CURLOPT_CUSTOMREQUEST => "POST", |
| 560 |
// CURLOPT_POSTFIELDS => "grant_type=password&username=".$username."&password=".$password."&client_id=qxZ6fCoOMj4cNK8SXRHa5nug6vnswlFWSF37hsW3&client_secret=L1fzLosJf9TlwnCCTZ5pkKmdqqkHShKEi0d4oFNE", |
| 561 |
CURLOPT_POSTFIELDS=> json_encode($json), |
| 562 |
CURLOPT_HTTPHEADER => array( |
| 563 |
|
| 564 |
"cache-control: no-cache", |
| 565 |
"content-type: application/json", |
| 566 |
|
| 567 |
), |
| 568 |
)); |
| 569 |
|
| 570 |
$response = curl_exec($curl); |
| 571 |
|
| 572 |
if(!$response){ |
| 573 |
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>'; |
| 574 |
} |
| 575 |
|
| 576 |
$err = curl_error($curl); |
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
curl_close($curl); |
| 583 |
$response= json_decode($response); |
| 584 |
|
| 585 |
if(isset($response->access_token)){ |
| 586 |
return $response->access_token; |
| 587 |
}else{ |
| 588 |
return; |
| 589 |
} |
| 590 |
} |
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
/** |
| 596 |
* Return admin package data |
| 597 |
* |
| 598 |
* @since 3.0.1 |
| 599 |
* returns pack data |
| 600 |
*/ |
| 601 |
|
| 602 |
public function wpstream_request_pack_data_per_user(){ |
| 603 |
|
| 604 |
|
| 605 |
$token = $this->wpstream_get_token(); |
| 606 |
$values_array = array(); |
| 607 |
$url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/status/packdetails/?access_token=".$token; |
| 608 |
|
| 609 |
|
| 610 |
$arguments = array( |
| 611 |
'method' => 'GET', |
| 612 |
'timeout' => 45, |
| 613 |
'redirection' => 5, |
| 614 |
'httpversion' => '1.0', |
| 615 |
'blocking' => true, |
| 616 |
'headers' => array(), |
| 617 |
'body' => $values_array, |
| 618 |
'cookies' => array() |
| 619 |
); |
| 620 |
$response = wp_remote_post($url,$arguments); |
| 621 |
$received_data = json_decode( wp_remote_retrieve_body($response) ,true); |
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
if( !is_wp_error($response) && isset($response['response']['code']) && $response['response']['code']=='200'){ |
| 626 |
return ($received_data); |
| 627 |
}else{ |
| 628 |
return 'failed connection'; |
| 629 |
} |
| 630 |
|
| 631 |
} |
| 632 |
|
| 633 |
/** |
| 634 |
* Check Api Status |
| 635 |
* |
| 636 |
* @since 3.0.1 |
| 637 |
* returns true or false |
| 638 |
*/ |
| 639 |
|
| 640 |
function wpstream_client_check_api_status(){ |
| 641 |
|
| 642 |
$token= $this->wpstream_get_token(); |
| 643 |
|
| 644 |
$url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/status/?access_token=".$token; |
| 645 |
$arguments = array( |
| 646 |
'method' => 'GET', |
| 647 |
'timeout' => 45, |
| 648 |
'redirection' => 5, |
| 649 |
'httpversion' => '1.0', |
| 650 |
'blocking' => true, |
| 651 |
'headers' => array(), |
| 652 |
'cookies' => array() |
| 653 |
); |
| 654 |
$response = wp_remote_post($url,$arguments); |
| 655 |
$body = wp_remote_retrieve_body($response); |
| 656 |
|
| 657 |
if ( $body === true || $body ==='true'){ |
| 658 |
return true; |
| 659 |
}else{ |
| 660 |
return false; |
| 661 |
} |
| 662 |
} |
| 663 |
|
| 664 |
/** |
| 665 |
* Start Get live events for users |
| 666 |
* |
| 667 |
* @since 3.0.1 |
| 668 |
* returns true or false |
| 669 |
*/ |
| 670 |
public function wpstream_get_live_event_for_user(){ |
| 671 |
$current_user = wp_get_current_user(); |
| 672 |
$allowded_html = array(); |
| 673 |
$userID = $current_user->ID; |
| 674 |
$return_uri = ''; |
| 675 |
|
| 676 |
global $wpstream_plugin; |
| 677 |
if( !$wpstream_plugin->main->wpstream_check_user_can_stream() ){ |
| 678 |
exit('not allowed to stream 678'); |
| 679 |
} |
| 680 |
|
| 681 |
|
| 682 |
$event_data = $this->wpstream_request_live_stream_for_user($userID); |
| 683 |
return $event_data; |
| 684 |
} |
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
/** |
| 689 |
* Start Get live events for users and $show_id |
| 690 |
* |
| 691 |
* @since 3.0.1 |
| 692 |
* returns true or false |
| 693 |
*/ |
| 694 |
public function api20_wpstream_get_live_event_for_user(){ |
| 695 |
|
| 696 |
global $wpstream_plugin; |
| 697 |
if( !$wpstream_plugin->main->wpstream_check_user_can_stream() ){ |
| 698 |
exit('not allowed to stream 698'); |
| 699 |
} |
| 700 |
|
| 701 |
|
| 702 |
$event_data = $this->api20_wpstream_request_live_stream_for_user(); |
| 703 |
return $event_data; |
| 704 |
} |
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
/** |
| 713 |
* Start Get live events for users |
| 714 |
* |
| 715 |
* @since 3.0.1 |
| 716 |
* returns true or false |
| 717 |
*/ |
| 718 |
public function wpstream_request_live_stream_for_user($user_id){ |
| 719 |
|
| 720 |
global $wpstream_plugin; |
| 721 |
if( !$wpstream_plugin->main->wpstream_check_user_can_stream() ){ |
| 722 |
exit('not allowed to stream 737'); |
| 723 |
} |
| 724 |
|
| 725 |
|
| 726 |
$domain = parse_url ( get_site_url() ); |
| 727 |
$token= $this->wpstream_get_token(); |
| 728 |
|
| 729 |
$values_array=array( |
| 730 |
"show_id" => $user_id, |
| 731 |
"scheme" => $domain['scheme'], |
| 732 |
"domain" => $domain['host'], |
| 733 |
"domain_ip" => $_SERVER['SERVER_ADDR'] |
| 734 |
); |
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
$url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/livestrem/api20_peruser/?access_token=".$token; |
| 739 |
|
| 740 |
|
| 741 |
$arguments = array( |
| 742 |
'method' => 'GET', |
| 743 |
'timeout' => 45, |
| 744 |
'redirection' => 5, |
| 745 |
'httpversion' => '1.0', |
| 746 |
'blocking' => true, |
| 747 |
'headers' => array(), |
| 748 |
'body' => $values_array, |
| 749 |
'cookies' => array() |
| 750 |
); |
| 751 |
$response = wp_remote_post($url,$arguments); |
| 752 |
$received_data = json_decode( wp_remote_retrieve_body($response) ,true); |
| 753 |
|
| 754 |
if(is_wp_error($response)){ |
| 755 |
return 'failed connection'; |
| 756 |
} |
| 757 |
if( isset($response['response']['code']) && $response['response']['code']=='200'){ |
| 758 |
return ($received_data); |
| 759 |
}else{ |
| 760 |
return 'failed connection'; |
| 761 |
} |
| 762 |
|
| 763 |
} |
| 764 |
|
| 765 |
public function api20_wpstream_request_live_stream_for_user(){ |
| 766 |
global $wpstream_plugin; |
| 767 |
if( !$wpstream_plugin->main->wpstream_check_user_can_stream() ){ |
| 768 |
return; |
| 769 |
}else{ |
| 770 |
|
| 771 |
|
| 772 |
$token = $this->wpstream_get_token(); |
| 773 |
$values_array = array(); |
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
$url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/livestrem/api20_peruser/?access_token=".$token; |
| 778 |
|
| 779 |
|
| 780 |
$arguments = array( |
| 781 |
'method' => 'GET', |
| 782 |
'timeout' => 45, |
| 783 |
'redirection' => 5, |
| 784 |
'httpversion' => '1.0', |
| 785 |
'blocking' => true, |
| 786 |
'headers' => array(), |
| 787 |
'body' => $values_array, |
| 788 |
'cookies' => array() |
| 789 |
); |
| 790 |
$response = wp_remote_post($url,$arguments); |
| 791 |
|
| 792 |
$received_data = json_decode( wp_remote_retrieve_body($response) ,true); |
| 793 |
|
| 794 |
if(is_wp_error($response)){ |
| 795 |
return 'failed connection'; |
| 796 |
} |
| 797 |
if( isset($response['response']['code']) && $response['response']['code']=='200'){ |
| 798 |
return ($received_data); |
| 799 |
}else{ |
| 800 |
return 'failed connection'; |
| 801 |
} |
| 802 |
} |
| 803 |
|
| 804 |
} |
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
/** |
| 810 |
* Delete event |
| 811 |
* |
| 812 |
* @since 3.0.1 |
| 813 |
* returns noda |
| 814 |
*/ |
| 815 |
|
| 816 |
public function wpstream_close_event(){ |
| 817 |
check_ajax_referer( 'wpstream_start_event_nonce', 'security' ); |
| 818 |
$current_user = wp_get_current_user(); |
| 819 |
$allowded_html = array(); |
| 820 |
$userID = $current_user->ID; |
| 821 |
$return_uri = ''; |
| 822 |
if( !current_user_can('administrator') ){ |
| 823 |
exit('okko'); |
| 824 |
} |
| 825 |
|
| 826 |
$show_id = intval($_POST['show_id']); |
| 827 |
update_post_meta ($show_id,'event_passed',1); |
| 828 |
die(); |
| 829 |
} |
| 830 |
|
| 831 |
|
| 832 |
/** |
| 833 |
* Get signed upload form data |
| 834 |
* |
| 835 |
* @since 3.0.1 |
| 836 |
* returns aws form |
| 837 |
*/ |
| 838 |
public function wpstream_get_signed_form_upload_data(){ |
| 839 |
if( !current_user_can('administrator') ){ |
| 840 |
exit('okko'); |
| 841 |
} |
| 842 |
|
| 843 |
$token = $this->wpstream_get_token(); |
| 844 |
$values_array = array(); |
| 845 |
$url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_upload_form/?access_token=".$token; |
| 846 |
|
| 847 |
|
| 848 |
$arguments = array( |
| 849 |
'method' => 'GET', |
| 850 |
'timeout' => 45, |
| 851 |
'redirection' => 5, |
| 852 |
'httpversion' => '1.0', |
| 853 |
'blocking' => true, |
| 854 |
'headers' => array(), |
| 855 |
'body' => $values_array, |
| 856 |
'cookies' => array() |
| 857 |
); |
| 858 |
$response = wp_remote_post($url,$arguments); |
| 859 |
$received_data = json_decode( wp_remote_retrieve_body($response) ,true); |
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
if( isset($response['response']['code']) && $response['response']['code']=='200'){ |
| 864 |
return $received_data; |
| 865 |
}else{ |
| 866 |
return 'failed connection'; |
| 867 |
} |
| 868 |
} |
| 869 |
|
| 870 |
/** |
| 871 |
* Get video from storage- clear data for front end use |
| 872 |
* |
| 873 |
* @since 3.0.1 |
| 874 |
* returns aws data |
| 875 |
*/ |
| 876 |
public function wpstream_get_videos(){ |
| 877 |
if( !current_user_can('administrator') ){ |
| 878 |
exit('okko'); |
| 879 |
} |
| 880 |
$token = $this->wpstream_get_token(); |
| 881 |
$values_array = array(); |
| 882 |
$url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_list_row/?access_token=".$token; |
| 883 |
|
| 884 |
|
| 885 |
$arguments = array( |
| 886 |
'method' => 'GET', |
| 887 |
'timeout' => 45, |
| 888 |
'redirection' => 5, |
| 889 |
'httpversion' => '1.0', |
| 890 |
'blocking' => true, |
| 891 |
'headers' => array(), |
| 892 |
'body' => $values_array, |
| 893 |
'cookies' => array() |
| 894 |
); |
| 895 |
$response = wp_remote_post($url,$arguments); |
| 896 |
$received_data = json_decode( wp_remote_retrieve_body($response) ,true); |
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
if( isset($response['response']['code']) && $response['response']['code']=='200'){ |
| 901 |
$video_options=array(); |
| 902 |
foreach ($received_data as $key=>$videos){ |
| 903 |
$video_options[$videos['video_name_storage']]=$videos['video_name_storage'].''; |
| 904 |
} |
| 905 |
|
| 906 |
return $video_options; |
| 907 |
}else{ |
| 908 |
return 'failed connection'; |
| 909 |
} |
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
} |
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
/** |
| 919 |
* Get video from storage- raw data |
| 920 |
* |
| 921 |
* @since 3.0.1 |
| 922 |
* returns aws data |
| 923 |
*/ |
| 924 |
public function wpstream_get_videos_from_storage_raw_data( ){ |
| 925 |
|
| 926 |
if( !current_user_can('administrator') ){ |
| 927 |
exit('okko'); |
| 928 |
} |
| 929 |
$token = $this->wpstream_get_token(); |
| 930 |
$values_array = array(); |
| 931 |
$url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_list_row/?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 |
|
| 950 |
|
| 951 |
if( isset($response['response']['code']) && $response['response']['code']=='200'){ |
| 952 |
return $received_data; |
| 953 |
}else{ |
| 954 |
return 'failed connection'; |
| 955 |
} |
| 956 |
|
| 957 |
} |
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
/** |
| 962 |
* Get download link from aws |
| 963 |
* |
| 964 |
* @since 3.0.1 |
| 965 |
* returns aws data |
| 966 |
*/ |
| 967 |
|
| 968 |
function wpstream_get_download_link(){ |
| 969 |
if( !current_user_can('administrator') ){ |
| 970 |
exit('okko get_download_link'); |
| 971 |
} |
| 972 |
|
| 973 |
$video_name = sanitize_text_field($_POST['video_name']); |
| 974 |
$token = $this->wpstream_get_token(); |
| 975 |
$values_array = array(); |
| 976 |
$values_array['video_name'] = $video_name; |
| 977 |
$url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_download_link/?access_token=".$token; |
| 978 |
|
| 979 |
|
| 980 |
$arguments = array( |
| 981 |
'method' => 'GET', |
| 982 |
'timeout' => 45, |
| 983 |
'redirection' => 5, |
| 984 |
'httpversion' => '1.0', |
| 985 |
'blocking' => true, |
| 986 |
'headers' => array(), |
| 987 |
'body' => $values_array, |
| 988 |
'cookies' => array() |
| 989 |
); |
| 990 |
$response = wp_remote_post($url,$arguments); |
| 991 |
$received_data = json_decode( wp_remote_retrieve_body($response) ,true); |
| 992 |
|
| 993 |
if( isset($response['response']['code']) && $response['response']['code']=='200'){ |
| 994 |
print trim($received_data); |
| 995 |
}else{ |
| 996 |
return 'failed connection'; |
| 997 |
} |
| 998 |
exit(); |
| 999 |
} |
| 1000 |
|
| 1001 |
|
| 1002 |
/** |
| 1003 |
* Delete file from storage |
| 1004 |
* |
| 1005 |
* @since 3.0.1 |
| 1006 |
* |
| 1007 |
*/ |
| 1008 |
public function wpstream_get_delete_file(){ |
| 1009 |
if( !current_user_can('administrator') ){ |
| 1010 |
exit('okko get_delete_file'); |
| 1011 |
} |
| 1012 |
|
| 1013 |
$video_name = esc_html($_POST['video_name']); |
| 1014 |
$token = $this->wpstream_get_token(); |
| 1015 |
$values_array = array(); |
| 1016 |
$values_array['video_name'] = $video_name; |
| 1017 |
$url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_delete_file/?access_token=".$token; |
| 1018 |
|
| 1019 |
|
| 1020 |
$arguments = array( |
| 1021 |
'method' => 'GET', |
| 1022 |
'timeout' => 45, |
| 1023 |
'redirection' => 5, |
| 1024 |
'httpversion' => '1.0', |
| 1025 |
'blocking' => true, |
| 1026 |
'headers' => array(), |
| 1027 |
'body' => $values_array, |
| 1028 |
'cookies' => array() |
| 1029 |
); |
| 1030 |
$response = wp_remote_post($url,$arguments); |
| 1031 |
$received_data = json_decode( wp_remote_retrieve_body($response) ,true); |
| 1032 |
|
| 1033 |
|
| 1034 |
if( isset($response['response']['code']) && $response['response']['code']=='200'){ |
| 1035 |
print $received_data; |
| 1036 |
}else{ |
| 1037 |
return 'failed connection'; |
| 1038 |
} |
| 1039 |
exit(); |
| 1040 |
|
| 1041 |
|
| 1042 |
} |
| 1043 |
|
| 1044 |
/** |
| 1045 |
* check if stream is live |
| 1046 |
* |
| 1047 |
* @since 3.0.1 |
| 1048 |
* |
| 1049 |
*/ |
| 1050 |
public function wpstream_is_is_live($product_id){ |
| 1051 |
|
| 1052 |
$token = $this->wpstream_get_token(); |
| 1053 |
|
| 1054 |
$values_array=array( |
| 1055 |
"show_id" => $product_id, |
| 1056 |
); |
| 1057 |
$url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/livestrem/checklive/?access_token=".$token; |
| 1058 |
|
| 1059 |
|
| 1060 |
$arguments = array( |
| 1061 |
'method' => 'GET', |
| 1062 |
'timeout' => 45, |
| 1063 |
'redirection' => 5, |
| 1064 |
'httpversion' => '1.0', |
| 1065 |
'blocking' => true, |
| 1066 |
'headers' => array(), |
| 1067 |
'body' => $values_array, |
| 1068 |
'cookies' => array() |
| 1069 |
); |
| 1070 |
$response = wp_remote_post($url,$arguments); |
| 1071 |
$received_data = json_decode( wp_remote_retrieve_body($response) ,true); |
| 1072 |
|
| 1073 |
if(is_wp_error($response)){ |
| 1074 |
return 'failed connection'; |
| 1075 |
} |
| 1076 |
if( isset($response['response']['code']) && $response['response']['code']=='200'){ |
| 1077 |
return ($received_data); |
| 1078 |
}else{ |
| 1079 |
return 'failed connection'; |
| 1080 |
} |
| 1081 |
|
| 1082 |
} |
| 1083 |
|
| 1084 |
/** |
| 1085 |
* get server ip for live streaming |
| 1086 |
* |
| 1087 |
* @since 3.0.1 |
| 1088 |
* |
| 1089 |
*/ |
| 1090 |
public function wpstream_get_live_stream_server($current_user,$streamname){ |
| 1091 |
|
| 1092 |
$token = $this->wpstream_get_token(); |
| 1093 |
$values_array = array(); |
| 1094 |
$values_array['new_stream'] = $streamname; |
| 1095 |
|
| 1096 |
$url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/livestrem/get_server_ip/?access_token=".$token; |
| 1097 |
|
| 1098 |
|
| 1099 |
$arguments = array( |
| 1100 |
'method' => 'GET', |
| 1101 |
'timeout' => 45, |
| 1102 |
'redirection' => 5, |
| 1103 |
'httpversion' => '1.0', |
| 1104 |
'blocking' => true, |
| 1105 |
'headers' => array(), |
| 1106 |
'body' => $values_array, |
| 1107 |
'cookies' => array() |
| 1108 |
); |
| 1109 |
$response = wp_remote_post($url,$arguments); |
| 1110 |
|
| 1111 |
|
| 1112 |
$received_data = json_decode( wp_remote_retrieve_body($response) ,true); |
| 1113 |
|
| 1114 |
if( isset($response['response']['code']) && $response['response']['code']=='200'){ |
| 1115 |
return trim($received_data); |
| 1116 |
}else{ |
| 1117 |
return 'failed connection'; |
| 1118 |
} |
| 1119 |
exit(); |
| 1120 |
|
| 1121 |
} |
| 1122 |
|
| 1123 |
}// end class |