| 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 |
$received_data = json_decode( wp_remote_retrieve_body($response) ,true); |
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
if( isset($response['response']['code']) && $response['response']['code']=='200'){ |
| 270 |
print trim($received_data); |
| 271 |
}else{ |
| 272 |
return 'failed connection'; |
| 273 |
} |
| 274 |
exit(); |
| 275 |
|
| 276 |
|
| 277 |
} |
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
add_action( 'wp_ajax_wpstream_update_video_status', 'wpstream_update_video_status' ); |
| 282 |
function wpstream_update_video_status(){ |
| 283 |
if( !current_user_can('administrator') ){ |
| 284 |
exit('okko'); |
| 285 |
} |
| 286 |
|
| 287 |
$video_id = intval($_POST['video_id']); |
| 288 |
$status = intval($_POST['status']); |
| 289 |
$video_name = esc_html($_POST['video_name']); |
| 290 |
$video_name_storage = esc_html($_POST['video_name_storage']); |
| 291 |
|
| 292 |
$token = wpstream_rcapi_retrive_token(); |
| 293 |
$values_array = array(); |
| 294 |
$values_array['video_id'] = $video_id; |
| 295 |
$values_array['status'] = $status; |
| 296 |
$values_array['video_name'] = $video_name; |
| 297 |
$values_array['video_name_storage']=$video_name_storage; |
| 298 |
|
| 299 |
|
| 300 |
$url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/update_video_status/?access_token=".$token; |
| 301 |
|
| 302 |
|
| 303 |
$arguments = array( |
| 304 |
'method' => 'GET', |
| 305 |
'timeout' => 45, |
| 306 |
'redirection' => 5, |
| 307 |
'httpversion' => '1.0', |
| 308 |
'blocking' => true, |
| 309 |
'headers' => array(), |
| 310 |
'body' => $values_array, |
| 311 |
'cookies' => array() |
| 312 |
); |
| 313 |
$response = wp_remote_post($url,$arguments); |
| 314 |
$received_data = json_decode( wp_remote_retrieve_body($response) ,true); |
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
if( isset($response['response']['code']) && $response['response']['code']=='200'){ |
| 320 |
return $received_data; |
| 321 |
}else{ |
| 322 |
return 'failed connection'; |
| 323 |
} |
| 324 |
exit(); |
| 325 |
|
| 326 |
|
| 327 |
} |
| 328 |
|
| 329 |
function wpstream_get_signed_form_upload_data(){ |
| 330 |
if( !current_user_can('administrator') ){ |
| 331 |
exit('okko'); |
| 332 |
} |
| 333 |
|
| 334 |
$token = wpstream_rcapi_retrive_token(); |
| 335 |
$values_array = array(); |
| 336 |
$url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_upload_form/?access_token=".$token; |
| 337 |
|
| 338 |
|
| 339 |
$arguments = array( |
| 340 |
'method' => 'GET', |
| 341 |
'timeout' => 45, |
| 342 |
'redirection' => 5, |
| 343 |
'httpversion' => '1.0', |
| 344 |
'blocking' => true, |
| 345 |
'headers' => array(), |
| 346 |
'body' => $values_array, |
| 347 |
'cookies' => array() |
| 348 |
); |
| 349 |
$response = wp_remote_post($url,$arguments); |
| 350 |
$received_data = json_decode( wp_remote_retrieve_body($response) ,true); |
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
if( isset($response['response']['code']) && $response['response']['code']=='200'){ |
| 355 |
return $received_data; |
| 356 |
}else{ |
| 357 |
return 'failed connection'; |
| 358 |
} |
| 359 |
} |
| 360 |
|
| 361 |
function wpstream_get_videos_from_storage_raw_data(){ |
| 362 |
|
| 363 |
if( !current_user_can('administrator') ){ |
| 364 |
exit('okko'); |
| 365 |
} |
| 366 |
$token = wpstream_rcapi_retrive_token(); |
| 367 |
$values_array = array(); |
| 368 |
$url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_list_row/?access_token=".$token; |
| 369 |
|
| 370 |
|
| 371 |
$arguments = array( |
| 372 |
'method' => 'GET', |
| 373 |
'timeout' => 45, |
| 374 |
'redirection' => 5, |
| 375 |
'httpversion' => '1.0', |
| 376 |
'blocking' => true, |
| 377 |
'headers' => array(), |
| 378 |
'body' => $values_array, |
| 379 |
'cookies' => array() |
| 380 |
); |
| 381 |
$response = wp_remote_post($url,$arguments); |
| 382 |
$received_data = json_decode( wp_remote_retrieve_body($response) ,true); |
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
if( isset($response['response']['code']) && $response['response']['code']=='200'){ |
| 387 |
return $received_data; |
| 388 |
}else{ |
| 389 |
return 'failed connection'; |
| 390 |
} |
| 391 |
|
| 392 |
} |
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
function wpstream_request_pack_data_per_user(){ |
| 397 |
|
| 398 |
if( !current_user_can('administrator') ){ |
| 399 |
exit('okko'); |
| 400 |
} |
| 401 |
$token = wpstream_rcapi_retrive_token(); |
| 402 |
$values_array = array(); |
| 403 |
$url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/status/packdetails/?access_token=".$token; |
| 404 |
|
| 405 |
|
| 406 |
$arguments = array( |
| 407 |
'method' => 'GET', |
| 408 |
'timeout' => 45, |
| 409 |
'redirection' => 5, |
| 410 |
'httpversion' => '1.0', |
| 411 |
'blocking' => true, |
| 412 |
'headers' => array(), |
| 413 |
'body' => $values_array, |
| 414 |
'cookies' => array() |
| 415 |
); |
| 416 |
$response = wp_remote_post($url,$arguments); |
| 417 |
$received_data = json_decode( wp_remote_retrieve_body($response) ,true); |
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
if( isset($response['response']['code']) && $response['response']['code']=='200'){ |
| 422 |
return ($received_data); |
| 423 |
}else{ |
| 424 |
return 'failed connection'; |
| 425 |
} |
| 426 |
|
| 427 |
} |
| 428 |
|
| 429 |
|
| 430 |
function wpstream_request_live_stream_for_user($user_id){ |
| 431 |
if( !current_user_can('administrator') ){ |
| 432 |
exit('okko'); |
| 433 |
} |
| 434 |
$domain = parse_url ( get_site_url() ); |
| 435 |
$token = wpstream_rcapi_retrive_token(); |
| 436 |
|
| 437 |
$values_array=array( |
| 438 |
"show_id" => $user_id, |
| 439 |
"scheme" => $domain['scheme'], |
| 440 |
"domain" => $domain['host'], |
| 441 |
"domain_ip" => $_SERVER['SERVER_ADDR'] |
| 442 |
); |
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
$url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/livestrem/peruser/?access_token=".$token; |
| 447 |
|
| 448 |
|
| 449 |
$arguments = array( |
| 450 |
'method' => 'GET', |
| 451 |
'timeout' => 45, |
| 452 |
'redirection' => 5, |
| 453 |
'httpversion' => '1.0', |
| 454 |
'blocking' => true, |
| 455 |
'headers' => array(), |
| 456 |
'body' => $values_array, |
| 457 |
'cookies' => array() |
| 458 |
); |
| 459 |
$response = wp_remote_post($url,$arguments); |
| 460 |
$received_data = json_decode( wp_remote_retrieve_body($response) ,true); |
| 461 |
|
| 462 |
if(is_wp_error($response)){ |
| 463 |
return 'failed connection'; |
| 464 |
} |
| 465 |
if( isset($response['response']['code']) && $response['response']['code']=='200'){ |
| 466 |
return ($received_data); |
| 467 |
}else{ |
| 468 |
return 'failed connection'; |
| 469 |
} |
| 470 |
|
| 471 |
} |
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
add_action( 'wp_ajax_wpstream_check_dns_sync', 'wpstream_check_dns_sync' ); |
| 476 |
function wpstream_check_dns_sync(){ |
| 477 |
$token = wpstream_rcapi_retrive_token(); |
| 478 |
|
| 479 |
|
| 480 |
$values_array=array( |
| 481 |
"dns_change_id" => esc_html($_POST['change_id']), |
| 482 |
); |
| 483 |
|
| 484 |
$url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/checkdns/get/?access_token=".$token; |
| 485 |
|
| 486 |
|
| 487 |
$arguments = array( |
| 488 |
'method' => 'GET', |
| 489 |
'timeout' => 45, |
| 490 |
'redirection' => 5, |
| 491 |
'httpversion' => '1.0', |
| 492 |
'blocking' => true, |
| 493 |
'headers' => array(), |
| 494 |
'body' => $values_array, |
| 495 |
'cookies' => array() |
| 496 |
); |
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
$response = wp_remote_post($url,$arguments); |
| 501 |
|
| 502 |
$received_data = json_decode( wp_remote_retrieve_body($response) ,true); |
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
if( isset($response['response']['code']) && $response['response']['code']=='200'){ |
| 508 |
print ($received_data); |
| 509 |
}else{ |
| 510 |
// print 'failed connection'; |
| 511 |
} |
| 512 |
die(); |
| 513 |
} |
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
function wpstream_request_live_stream_uri($show_id,$is_record){ |
| 520 |
$token = wpstream_rcapi_retrive_token(); |
| 521 |
$domain = parse_url ( get_site_url() ); |
| 522 |
|
| 523 |
$values_array=array( |
| 524 |
"show_id" => $show_id, |
| 525 |
"scheme" => $domain['scheme'], |
| 526 |
"domain" => $domain['host'], |
| 527 |
"domain_ip" => $_SERVER['SERVER_ADDR'], |
| 528 |
"is_record" => $is_record, |
| 529 |
"location" => get_home_url() |
| 530 |
); |
| 531 |
|
| 532 |
$url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/livestrem/new/?access_token=".$token; |
| 533 |
|
| 534 |
|
| 535 |
$arguments = array( |
| 536 |
'method' => 'GET', |
| 537 |
'timeout' => 45, |
| 538 |
'redirection' => 5, |
| 539 |
'httpversion' => '1.0', |
| 540 |
'blocking' => true, |
| 541 |
'headers' => array(), |
| 542 |
'body' => $values_array, |
| 543 |
'cookies' => array() |
| 544 |
); |
| 545 |
$response = wp_remote_post($url,$arguments); |
| 546 |
|
| 547 |
$received_data = json_decode( wp_remote_retrieve_body($response) ,true); |
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
if( isset($response['response']['code']) && $response['response']['code']=='200'){ |
| 553 |
return ($received_data); |
| 554 |
}else{ |
| 555 |
return 'failed connection'; |
| 556 |
} |
| 557 |
|
| 558 |
} |
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
function wpstream_rcapi_retrive_token(){ |
| 563 |
$token_expiration = floatval( esc_html ( get_option('wp_estate_token_expire','') ) ); |
| 564 |
$time= time(); |
| 565 |
|
| 566 |
$check= $token_expiration - $time + 3600; |
| 567 |
|
| 568 |
if ( $check <= 0 || $token_expiration==0){ |
| 569 |
$token = wpstream_club_get_token(); |
| 570 |
update_option('wp_estate_token_expire',time()); |
| 571 |
update_option('wp_estate_curent_token',$token); |
| 572 |
}else{ |
| 573 |
$token = esc_html ( get_option('wp_estate_curent_token','') ); |
| 574 |
} |
| 575 |
|
| 576 |
if($token==''){ |
| 577 |
$token = wpstream_club_get_token(); |
| 578 |
update_option('wp_estate_token_expire',time()); |
| 579 |
update_option('wp_estate_curent_token',$token); |
| 580 |
} |
| 581 |
|
| 582 |
return $token; |
| 583 |
|
| 584 |
} |
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
function wpstream_club_get_token(){ |
| 589 |
|
| 590 |
$client_id = esc_html ( get_option('wpstream_api_key','') ); |
| 591 |
$client_secret = esc_html ( get_option('wpstream_api_secret_key','') ); |
| 592 |
$username = esc_html ( get_option('wpstream_api_username','') ); |
| 593 |
$password = esc_html ( get_option('wpstream_api_password','') ); |
| 594 |
|
| 595 |
if ($client_id=='' || $client_secret=='' || $username=='' || $password==''){ |
| 596 |
return; |
| 597 |
} |
| 598 |
$curl = curl_init(); |
| 599 |
|
| 600 |
curl_setopt_array($curl, array( |
| 601 |
CURLOPT_URL => WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/?oauth=token", |
| 602 |
CURLOPT_RETURNTRANSFER => true, |
| 603 |
CURLOPT_ENCODING => "", |
| 604 |
CURLOPT_MAXREDIRS => 10, |
| 605 |
CURLOPT_TIMEOUT => 30, |
| 606 |
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
| 607 |
CURLOPT_CUSTOMREQUEST => "POST", |
| 608 |
CURLOPT_POSTFIELDS => "grant_type=password&username=".$username."&password=".$password, |
| 609 |
CURLOPT_HTTPHEADER => array( |
| 610 |
"authorization: Basic ". base64_encode( $client_id . ':' . $client_secret ), |
| 611 |
"cache-control: no-cache", |
| 612 |
"content-type: application/x-www-form-urlencoded", |
| 613 |
"postman-token: 3d65984a-9f80-a881-5fe9-59717126687e" |
| 614 |
), |
| 615 |
)); |
| 616 |
|
| 617 |
$response = curl_exec($curl); |
| 618 |
$err = curl_error($curl); |
| 619 |
|
| 620 |
curl_close($curl); |
| 621 |
$response= json_decode($response); |
| 622 |
|
| 623 |
if(isset($response->access_token)){ |
| 624 |
return $response->access_token; |
| 625 |
}else{ |
| 626 |
return; |
| 627 |
} |
| 628 |
} |
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
function wpstream_client_check_api_status(){ |
| 635 |
|
| 636 |
$token= wpstream_rcapi_retrive_token(); |
| 637 |
|
| 638 |
$url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/status/?access_token=".$token; |
| 639 |
$arguments = array( |
| 640 |
'method' => 'GET', |
| 641 |
'timeout' => 45, |
| 642 |
'redirection' => 5, |
| 643 |
'httpversion' => '1.0', |
| 644 |
'blocking' => true, |
| 645 |
'headers' => array(), |
| 646 |
'cookies' => array() |
| 647 |
); |
| 648 |
$response = wp_remote_post($url,$arguments); |
| 649 |
$body = wp_remote_retrieve_body($response); |
| 650 |
|
| 651 |
if ( $body === true || $body ==='true'){ |
| 652 |
return true; |
| 653 |
}else{ |
| 654 |
return false; |
| 655 |
} |
| 656 |
} |
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
function wpstream_retrive_username(){ |
| 661 |
$token= wpstream_rcapi_retrive_token(); |
| 662 |
|
| 663 |
$url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/return_login/?access_token=".$token; |
| 664 |
$arguments = array( |
| 665 |
'method' => 'GET', |
| 666 |
'timeout' => 45, |
| 667 |
'redirection' => 5, |
| 668 |
'httpversion' => '1.0', |
| 669 |
'blocking' => true, |
| 670 |
'headers' => array(), |
| 671 |
'cookies' => array() |
| 672 |
); |
| 673 |
$response = wp_remote_post($url,$arguments); |
| 674 |
|
| 675 |
$received_data = json_decode( wp_remote_retrieve_body($response) ,true); |
| 676 |
|
| 677 |
|
| 678 |
if( isset($response['response']['code']) && $response['response']['code']=='200'){ |
| 679 |
return ($received_data); die(); |
| 680 |
}else{ |
| 681 |
print 'Failed to conbect media server'; |
| 682 |
die(); |
| 683 |
} |
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
} |