| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
function wpstream_get_videos(){ |
| 5 |
$current_user = wp_get_current_user(); |
| 6 |
$allowded_html = array(); |
| 7 |
$userID = $current_user->ID; |
| 8 |
$return_uri = ''; |
| 9 |
if( !current_user_can('administrator') ){ |
| 10 |
exit('okko'); |
| 11 |
} |
| 12 |
|
| 13 |
|
| 14 |
$video_data = wpstream_get_videos_from_storage(); |
| 15 |
|
| 16 |
return $video_data; |
| 17 |
} |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
function wpstream_get_pack_details_user(){ |
| 24 |
$current_user = wp_get_current_user(); |
| 25 |
$allowded_html = array(); |
| 26 |
$userID = $current_user->ID; |
| 27 |
$return_uri = ''; |
| 28 |
if( !current_user_can('administrator') ){ |
| 29 |
exit('okko'); |
| 30 |
} |
| 31 |
|
| 32 |
$pack_data = wpstream_request_pack_data_per_user(); |
| 33 |
return $pack_data; |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
function wpstream_get_live_event_for_user(){ |
| 40 |
$current_user = wp_get_current_user(); |
| 41 |
$allowded_html = array(); |
| 42 |
$userID = $current_user->ID; |
| 43 |
$return_uri = ''; |
| 44 |
if( !current_user_can('administrator') ){ |
| 45 |
exit('okko'); |
| 46 |
} |
| 47 |
|
| 48 |
$event_data = wpstream_request_live_stream_for_user($userID); |
| 49 |
return $event_data; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
add_action( 'wp_ajax_wpstream_close_event', 'wpstream_close_event' ); |
| 56 |
function wpstream_close_event(){ |
| 57 |
check_ajax_referer( 'wpstream_start_event_nonce', 'security' ); |
| 58 |
$current_user = wp_get_current_user(); |
| 59 |
$allowded_html = array(); |
| 60 |
$userID = $current_user->ID; |
| 61 |
$return_uri = ''; |
| 62 |
if( !current_user_can('administrator') ){ |
| 63 |
exit('okko'); |
| 64 |
} |
| 65 |
|
| 66 |
$show_id = intval($_POST['show_id']); |
| 67 |
|
| 68 |
update_post_meta ($show_id,'event_passed',1); |
| 69 |
|
| 70 |
die(); |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
add_action( 'wp_ajax_wpstream_give_me_live_uri', 'wpstream_give_me_live_uri' ); |
| 78 |
function wpstream_give_me_live_uri(){ |
| 79 |
|
| 80 |
check_ajax_referer( 'wpstream_start_event_nonce', 'security' ); |
| 81 |
$current_user = wp_get_current_user(); |
| 82 |
$allowded_html = array(); |
| 83 |
$userID = $current_user->ID; |
| 84 |
$return_uri = ''; |
| 85 |
|
| 86 |
if( !current_user_can('administrator') ){ |
| 87 |
exit('okko'); |
| 88 |
} |
| 89 |
|
| 90 |
$show_id = intval($_POST['show_id']); |
| 91 |
$is_record = floatval($_POST['is_record']); |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
$event_data = wpstream_request_live_stream_uri($show_id,$is_record); |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
if(is_array($event_data)){ |
| 101 |
$explode = explode('wpstream.net/', $event_data['live_uri']); |
| 102 |
$uri = $explode[0].'wpstream.net/wpstream/'; |
| 103 |
$stream_key = trim(str_replace('wpstream/',' ',$explode[1])); |
| 104 |
|
| 105 |
echo json_encode( array( |
| 106 |
'sometihng' =>'mr', |
| 107 |
'conected' => true, |
| 108 |
'live_uri' => $event_data['live_uri'] , |
| 109 |
'all_data' => $event_data, |
| 110 |
'obs_uri' => '<strong>'.__('Url:').'</strong> <div class="wpstream_live_uri_text">'.$uri.'</div><div class="copy_live_uri">'.__('copy to clipboard','wpstream').'</div>', |
| 111 |
'obs_stream'=> '<strong>'.__('Stream Key:').'</strong> <div class="wpstream_live_key_text">'.$stream_key.'</div><div class="copy_live_key">'.__('copy to clipboard','wpstream').'</div>', |
| 112 |
) |
| 113 |
); |
| 114 |
update_post_meta($show_id,'live_event_uri', $event_data['live_uri']); |
| 115 |
update_post_meta($show_id,'live_event_stream_name', $event_data['carnat1']); |
| 116 |
update_post_meta($show_id,'ip', $event_data['ip']); |
| 117 |
|
| 118 |
}else{ |
| 119 |
echo json_encode( array( |
| 120 |
'sometihng' =>'NOT' |
| 121 |
)); |
| 122 |
} |
| 123 |
die(); |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
function wpstream_get_videos_from_storage(){ |
| 130 |
|
| 131 |
if( !current_user_can('administrator') ){ |
| 132 |
exit('okko'); |
| 133 |
} |
| 134 |
$token = wpstream_rcapi_retrive_token(); |
| 135 |
$values_array = array(); |
| 136 |
$url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_list/?access_token=".$token; |
| 137 |
|
| 138 |
|
| 139 |
$arguments = array( |
| 140 |
'method' => 'GET', |
| 141 |
'timeout' => 45, |
| 142 |
'redirection' => 5, |
| 143 |
'httpversion' => '1.0', |
| 144 |
'blocking' => true, |
| 145 |
'headers' => array(), |
| 146 |
'body' => $values_array, |
| 147 |
'cookies' => array() |
| 148 |
); |
| 149 |
$response = wp_remote_post($url,$arguments); |
| 150 |
$received_data = json_decode( wp_remote_retrieve_body($response) ,true); |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
if( isset($response['response']['code']) && $response['response']['code']=='200'){ |
| 155 |
$video_options=array(); |
| 156 |
foreach ($received_data as $key=>$videos){ |
| 157 |
$video_options[$videos['storage_name']]=$videos['name']; |
| 158 |
} |
| 159 |
return $video_options; |
| 160 |
}else{ |
| 161 |
return 'failed connection'; |
| 162 |
} |
| 163 |
|
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
function wpstream_request_pack_data_per_user(){ |
| 169 |
|
| 170 |
if( !current_user_can('administrator') ){ |
| 171 |
exit('okko'); |
| 172 |
} |
| 173 |
$token = wpstream_rcapi_retrive_token(); |
| 174 |
$values_array = array(); |
| 175 |
$url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/status/packdetails/?access_token=".$token; |
| 176 |
|
| 177 |
|
| 178 |
$arguments = array( |
| 179 |
'method' => 'GET', |
| 180 |
'timeout' => 45, |
| 181 |
'redirection' => 5, |
| 182 |
'httpversion' => '1.0', |
| 183 |
'blocking' => true, |
| 184 |
'headers' => array(), |
| 185 |
'body' => $values_array, |
| 186 |
'cookies' => array() |
| 187 |
); |
| 188 |
$response = wp_remote_post($url,$arguments); |
| 189 |
$received_data = json_decode( wp_remote_retrieve_body($response) ,true); |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
if( isset($response['response']['code']) && $response['response']['code']=='200'){ |
| 194 |
return ($received_data); |
| 195 |
}else{ |
| 196 |
return 'failed connection'; |
| 197 |
} |
| 198 |
|
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
function wpstream_request_live_stream_for_user($user_id){ |
| 203 |
if( !current_user_can('administrator') ){ |
| 204 |
exit('okko'); |
| 205 |
} |
| 206 |
$domain = parse_url ( get_site_url() ); |
| 207 |
$token = wpstream_rcapi_retrive_token(); |
| 208 |
|
| 209 |
$values_array=array( |
| 210 |
"show_id" => $user_id, |
| 211 |
"scheme" => $domain['scheme'], |
| 212 |
"domain" => $domain['host'], |
| 213 |
"domain_ip" => $_SERVER['SERVER_ADDR'] |
| 214 |
); |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
$url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/livestrem/peruser/?access_token=".$token; |
| 219 |
|
| 220 |
|
| 221 |
$arguments = array( |
| 222 |
'method' => 'GET', |
| 223 |
'timeout' => 45, |
| 224 |
'redirection' => 5, |
| 225 |
'httpversion' => '1.0', |
| 226 |
'blocking' => true, |
| 227 |
'headers' => array(), |
| 228 |
'body' => $values_array, |
| 229 |
'cookies' => array() |
| 230 |
); |
| 231 |
$response = wp_remote_post($url,$arguments); |
| 232 |
$received_data = json_decode( wp_remote_retrieve_body($response) ,true); |
| 233 |
|
| 234 |
if(is_wp_error($response)){ |
| 235 |
return 'failed connection'; |
| 236 |
} |
| 237 |
if( isset($response['response']['code']) && $response['response']['code']=='200'){ |
| 238 |
return ($received_data); |
| 239 |
}else{ |
| 240 |
return 'failed connection'; |
| 241 |
} |
| 242 |
|
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
function wpstream_request_live_stream_uri($show_id,$is_record){ |
| 248 |
$token = wpstream_rcapi_retrive_token(); |
| 249 |
$domain = parse_url ( get_site_url() ); |
| 250 |
|
| 251 |
$values_array=array( |
| 252 |
"show_id" => $show_id, |
| 253 |
"scheme" => $domain['scheme'], |
| 254 |
"domain" => $domain['host'], |
| 255 |
"domain_ip" => $_SERVER['SERVER_ADDR'], |
| 256 |
"is_record" => $is_record, |
| 257 |
"location" => get_home_url() |
| 258 |
); |
| 259 |
|
| 260 |
$url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/livestrem/new/?access_token=".$token; |
| 261 |
|
| 262 |
|
| 263 |
$arguments = array( |
| 264 |
'method' => 'GET', |
| 265 |
'timeout' => 45, |
| 266 |
'redirection' => 5, |
| 267 |
'httpversion' => '1.0', |
| 268 |
'blocking' => true, |
| 269 |
'headers' => array(), |
| 270 |
'body' => $values_array, |
| 271 |
'cookies' => array() |
| 272 |
); |
| 273 |
$response = wp_remote_post($url,$arguments); |
| 274 |
|
| 275 |
$received_data = json_decode( wp_remote_retrieve_body($response) ,true); |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
if( isset($response['response']['code']) && $response['response']['code']=='200'){ |
| 281 |
return ($received_data); |
| 282 |
}else{ |
| 283 |
return 'failed connection'; |
| 284 |
} |
| 285 |
|
| 286 |
} |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
function wpstream_rcapi_retrive_token(){ |
| 291 |
$token_expiration = floatval( esc_html ( get_option('wp_estate_token_expire','') ) ); |
| 292 |
$time= time(); |
| 293 |
|
| 294 |
$check= $token_expiration - $time + 3600; |
| 295 |
|
| 296 |
if ( $check <= 0 || $token_expiration==0){ |
| 297 |
$token = wpstream_club_get_token(); |
| 298 |
update_option('wp_estate_token_expire',time()); |
| 299 |
update_option('wp_estate_curent_token',$token); |
| 300 |
}else{ |
| 301 |
$token = esc_html ( get_option('wp_estate_curent_token','') ); |
| 302 |
} |
| 303 |
|
| 304 |
if($token==''){ |
| 305 |
$token = wpstream_club_get_token(); |
| 306 |
update_option('wp_estate_token_expire',time()); |
| 307 |
update_option('wp_estate_curent_token',$token); |
| 308 |
} |
| 309 |
|
| 310 |
return $token; |
| 311 |
|
| 312 |
} |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
function wpstream_club_get_token(){ |
| 317 |
|
| 318 |
$client_id = esc_html ( get_option('wpstream_api_key','') ); |
| 319 |
$client_secret = esc_html ( get_option('wpstream_api_secret_key','') ); |
| 320 |
$username = esc_html ( get_option('wpstream_api_username','') ); |
| 321 |
$password = esc_html ( get_option('wpstream_api_password','') ); |
| 322 |
|
| 323 |
if ($client_id=='' || $client_secret=='' || $username=='' || $password==''){ |
| 324 |
return; |
| 325 |
} |
| 326 |
$curl = curl_init(); |
| 327 |
|
| 328 |
curl_setopt_array($curl, array( |
| 329 |
CURLOPT_URL => WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/?oauth=token", |
| 330 |
CURLOPT_RETURNTRANSFER => true, |
| 331 |
CURLOPT_ENCODING => "", |
| 332 |
CURLOPT_MAXREDIRS => 10, |
| 333 |
CURLOPT_TIMEOUT => 30, |
| 334 |
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
| 335 |
CURLOPT_CUSTOMREQUEST => "POST", |
| 336 |
CURLOPT_POSTFIELDS => "grant_type=password&username=".$username."&password=".$password, |
| 337 |
CURLOPT_HTTPHEADER => array( |
| 338 |
"authorization: Basic ". base64_encode( $client_id . ':' . $client_secret ), |
| 339 |
"cache-control: no-cache", |
| 340 |
"content-type: application/x-www-form-urlencoded", |
| 341 |
"postman-token: 3d65984a-9f80-a881-5fe9-59717126687e" |
| 342 |
), |
| 343 |
)); |
| 344 |
|
| 345 |
$response = curl_exec($curl); |
| 346 |
$err = curl_error($curl); |
| 347 |
|
| 348 |
curl_close($curl); |
| 349 |
$response= json_decode($response); |
| 350 |
|
| 351 |
if(isset($response->access_token)){ |
| 352 |
return $response->access_token; |
| 353 |
}else{ |
| 354 |
return; |
| 355 |
} |
| 356 |
} |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
function wpstream_client_check_api_status(){ |
| 363 |
|
| 364 |
$token= wpstream_rcapi_retrive_token(); |
| 365 |
$url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/status/?access_token=".$token; |
| 366 |
$arguments = array( |
| 367 |
'method' => 'GET', |
| 368 |
'timeout' => 45, |
| 369 |
'redirection' => 5, |
| 370 |
'httpversion' => '1.0', |
| 371 |
'blocking' => true, |
| 372 |
'headers' => array(), |
| 373 |
'cookies' => array() |
| 374 |
); |
| 375 |
$response = wp_remote_post($url,$arguments); |
| 376 |
$body = wp_remote_retrieve_body($response); |
| 377 |
|
| 378 |
if ( $body === true || $body ==='true'){ |
| 379 |
return true; |
| 380 |
}else{ |
| 381 |
return false; |
| 382 |
} |
| 383 |
} |
| 384 |
|