← All changes
|
includes/class-wpstream-live-api-connection.php
+231
-567
4.12.4
→
4.4.10
View file →
| @@ -1,28 +1,19 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -require_once dirname( __FILE__ ) . '/class-wpstream-user-quota-service.php'; | |
| 4 | - | |
| 5 | 3 | class Wpstream_Live_Api_Connection { |
| 6 | 4 | |
| 7 | - private $user_quota_service; | |
| 5 | + | |
| 8 | 6 | |
| 9 | 7 | |
| 10 | 8 | public function __construct() { |
| 11 | - $this->user_quota_service = new Wpstream_User_Quota_Service( $this ); | |
| 12 | - | |
| 13 | 9 | add_action( 'wp_ajax_wpstream_give_me_live_uri', array($this,'wpstream_give_me_live_uri') ); |
| 14 | 10 | add_action( 'wp_ajax_wpstream_turn_of_channel', array($this,'wpstream_turn_of_channel') ); |
| 15 | 11 | add_action( 'wp_ajax_wpstream_update_local_event_settings',array($this,'wpstream_update_local_event_settings')); |
| 16 | - add_action( 'wp_ajax_wpstream_update_use_global_event_options',array($this,'wpstream_update_use_global_event_options')); | |
| 17 | - add_action( 'wp_ajax_wpstream_update_default_channel_settings', array( $this, 'wpstream_update_default_channel_settings' ) ); | |
| 18 | - add_action( 'wp_ajax_wpstream_update_settings', array( $this, 'wpstream_update_settings' ) ); | |
| 19 | - | |
| 12 | + | |
| 20 | 13 | add_action( 'wp_ajax_wpstream_check_dns_sync', array($this,'wpstream_check_dns_sync') ); |
| 21 | 14 | add_action( 'wp_ajax_wpstream_check_event_status', array($this,'wpstream_check_event_status') ); |
| 22 | - add_action( 'wp_ajax_wpstream_check_whipurl', array($this, 'wpstream_check_whipurl') ); | |
| 23 | - add_action( 'wp_ajax_wpstream_check_user_quota', array($this, 'wpstream_check_user_quota') ); | |
| 24 | - | |
| 15 | + | |
| 25 | 16 | add_action( 'wp_ajax_wpstream_close_event', array($this,'wpstream_close_event') ); |
| 26 | 17 | add_action( 'wp_ajax_wpstream_get_download_link', array($this,'wpstream_get_download_link') ); |
| 27 | 18 | add_action( 'wp_ajax_wpstream_get_delete_file', array($this,'wpstream_get_delete_file') ); |
| 28 | 19 | |
| @@ -27,14 +18,16 @@ | ||
| 27 | 18 | add_action( 'wp_ajax_wpstream_get_delete_file', array($this,'wpstream_get_delete_file') ); |
| 28 | 19 | |
| 29 | 20 | add_action( 'admin_notices',array($this, 'wpstream_admin_notices') ); |
| 30 | 21 | |
| 31 | - add_action( 'wp_ajax_wpstream_check_pending_videos', array($this,'wpstream_check_pending_videos') ); | |
| 22 | + | |
| 23 | + } | |
| 24 | + | |
| 25 | + | |
| 32 | 26 | |
| 33 | 27 | |
| 34 | - } | |
| 35 | 28 | |
| 36 | - | |
| 29 | + | |
| 37 | 30 | /* |
| 38 | 31 | * Admin Notices |
| 39 | 32 | * |
| 40 | 33 | * |
| @@ -65,17 +58,12 @@ | ||
| 65 | 58 | } |
| 66 | 59 | |
| 67 | 60 | $token = $this->wpstream_get_token(); |
| 68 | 61 | if($token=='' and $page!='wpstream_plugin_options'){ |
| 69 | - // echo 'wpstream_curl_failed: ' . get_option('wpstream_curl_failed'); | |
| 70 | - $text = get_option('wpstream_curl_failed') === "0" ? | |
| 71 | - 'Not connected to WpStream. Please check your credentials <a href="/wp-admin/admin.php?page=wpstream_credentials">here</a>.' : | |
| 72 | - 'Not connected to WpStream. Please note the errors above and contact support.'; | |
| 73 | - | |
| 74 | - echo '<div class="api_not_conected wpstream_notice_top">'.__($text,'wpstream').'</div>'; | |
| 62 | + echo '<div class="api_not_conected wpstream_notice_top">'.__(' Incorrect username or password. Please check your credentials or go <a href="https://wpstream.net/my-account/edit-account/" target="_blank">here</a> to reset your password.','wpstream').'</div>'; | |
| 75 | 63 | } |
| 76 | 64 | |
| 77 | - } | |
| 65 | +} | |
| 78 | 66 | |
| 79 | 67 | |
| 80 | 68 | /* |
| 81 | 69 | * Curl request |
| @@ -83,19 +71,22 @@ | ||
| 83 | 71 | * |
| 84 | 72 | * |
| 85 | 73 | * */ |
| 86 | 74 | |
| 87 | - function wpstream_baker_do_curl_base($url,$curl_post_fields, $expect_json = false, $quiet = false, $timeout = 10){ | |
| 88 | - $curl = curl_init(); | |
| 89 | - $base_api_url = defined('WPSTREAM_TEST_API' ) ? WPSTREAM_TEST_API : WPSTREAM_API; | |
| 90 | - $api_url = $base_api_url . '/' . $url; | |
| 75 | + function wpstream_baker_do_curl_base($url,$curl_post_fields){ | |
| 76 | + | |
| 91 | 77 | |
| 78 | + $curl = curl_init(); | |
| 79 | + $api_url = WPSTREAM_API.'/'.$url; | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 92 | 83 | curl_setopt_array($curl, array( |
| 93 | 84 | CURLOPT_URL =>$api_url, |
| 94 | 85 | CURLOPT_RETURNTRANSFER => true, |
| 95 | 86 | CURLOPT_ENCODING => "", |
| 96 | 87 | CURLOPT_MAXREDIRS => 10, |
| 97 | - CURLOPT_TIMEOUT => $timeout, | |
| 88 | + CURLOPT_TIMEOUT => 10, | |
| 98 | 89 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
| 99 | 90 | CURLOPT_CUSTOMREQUEST => "POST", |
| 100 | 91 | CURLOPT_POSTFIELDS => http_build_query($curl_post_fields), |
| 101 | 92 | CURLOPT_HTTPHEADER => array( |
| @@ -105,89 +96,15 @@ | ||
| 105 | 96 | )); |
| 106 | 97 | |
| 107 | 98 | $response = curl_exec($curl); |
| 108 | 99 | $err = curl_error($curl); |
| 109 | - $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); | |
| 100 | + | |
| 110 | 101 | curl_close($curl); |
| 111 | 102 | |
| 112 | - $curl_failed = 0; | |
| 113 | - | |
| 114 | - $logger = new WpStream_Logger(); | |
| 115 | - | |
| 116 | 103 | if ($err) { |
| 117 | - // do not echo every time, some operations must return JSON | |
| 118 | - if (!$quiet){ | |
| 119 | - echo '<div class="api_not_conected wpstream_error_curl">Critical: Could Not Connect to WpStream - '.$err.'</div>'; | |
| 120 | - } | |
| 104 | + echo '<div class="api_not_conected wpstream_error_curl">cURL Error #: '.$err.'</div>'; | |
| 105 | + } | |
| 121 | 106 | |
| 122 | - $curl_failed = $err; | |
| 123 | - | |
| 124 | - $log_entry = new WpStream_Log_Entry([ | |
| 125 | - 'type' => 'error', | |
| 126 | - 'description' => 'CURL error: ' . $err . ' on endpoint ' . $url, | |
| 127 | - ]); | |
| 128 | - $logger->add( $log_entry ); | |
| 129 | - | |
| 130 | - $response = json_encode( array( | |
| 131 | - 'success' => false, | |
| 132 | - 'error' => $err, | |
| 133 | - )); | |
| 134 | - } | |
| 135 | - else if ($http_code != 200) { | |
| 136 | - $log_entry = new WpStream_Log_Entry([ | |
| 137 | - 'type' => 'error', | |
| 138 | - 'description' => 'HTTP error: ' . $http_code . ' on endpoint ' . $url, | |
| 139 | - ]); | |
| 140 | - $logger->add( $log_entry ); | |
| 141 | - | |
| 142 | - if (!$quiet){ | |
| 143 | - switch ($http_code) { | |
| 144 | - case 0: | |
| 145 | - $message = "CURL failed with code 0. Please address CURL connectivity with your hosting provider."; | |
| 146 | - break; | |
| 147 | - case 429: | |
| 148 | - $message = "API: Too many Requests"; | |
| 149 | - break; | |
| 150 | - case 403: | |
| 151 | - $message = "API: Access Forbidden with response: " . $response . ' and HTTP code: ' . $http_code; | |
| 152 | - break; | |
| 153 | - default: | |
| 154 | - $message = "API - Unexpected response: " . $http_code; | |
| 155 | - break; | |
| 156 | - } | |
| 157 | - echo '<div class="api_not_conected wpstream_error_curl">'.$message.'</div>'; | |
| 158 | - } | |
| 159 | - $curl_failed = $http_code; | |
| 160 | - | |
| 161 | - $response = json_encode( array( | |
| 162 | - 'success' => false, | |
| 163 | - 'error' => $http_code, | |
| 164 | - )); | |
| 165 | - } | |
| 166 | - else if ($expect_json){ | |
| 167 | - $curl_response_decoded = json_decode($response,JSON_OBJECT_AS_ARRAY); | |
| 168 | - if (JSON_ERROR_NONE !== json_last_error()) { | |
| 169 | - $log_entry = new WpStream_Log_Entry([ | |
| 170 | - 'type' => 'error', | |
| 171 | - 'description' => 'Malformed JSON response: ' . json_last_error_msg() . ' on endpoint ' . $url, | |
| 172 | - ]); | |
| 173 | - $logger->add( $log_entry ); | |
| 174 | - | |
| 175 | - if (!$quiet) { | |
| 176 | - echo '<div class="api_not_conected wpstream_error_curl">Critical: Malformed API response #: ' . json_last_error() . '</div>'; | |
| 177 | - } | |
| 178 | - | |
| 179 | - $curl_failed = json_last_error(); | |
| 180 | - | |
| 181 | - $response = json_encode(array( | |
| 182 | - 'success' => false, | |
| 183 | - 'error' => json_last_error(), | |
| 184 | - )); | |
| 185 | - } | |
| 186 | - } | |
| 187 | - | |
| 188 | - update_option( "wpstream_curl_failed", $curl_failed ); | |
| 189 | - | |
| 190 | 107 | return $response; |
| 191 | 108 | } |
| 192 | 109 | |
| 193 | 110 | |
| @@ -264,9 +181,8 @@ | ||
| 264 | 181 | * returns live url |
| 265 | 182 | */ |
| 266 | 183 | |
| 267 | 184 | public function wpstream_check_event_status(){ |
| 268 | - check_ajax_referer( 'wpstream_start_event_nonce', 'nonce' ); | |
| 269 | 185 | $channel_id = intval($_POST['channel_id']); |
| 270 | 186 | $notes = 'wpstream_check_event_status_note'; |
| 271 | 187 | if(isset($_POST['notes'])){ |
| 272 | 188 | $notes = sanitize_text_field($_POST['notes']); |
| @@ -273,28 +189,13 @@ | ||
| 273 | 189 | } |
| 274 | 190 | |
| 275 | 191 | |
| 276 | 192 | $response = $this->wpstream_check_event_status_api_call($channel_id,$notes); |
| 193 | + | |
| 194 | + | |
| 277 | 195 | |
| 278 | - $previous_status = get_post_meta( $channel_id, 'status', true ); | |
| 279 | - | |
| 280 | 196 | if( isset($response['success']) && $response['success']){ |
| 281 | 197 | $this->api20_wpstream_update_event($response,$channel_id); |
| 282 | - | |
| 283 | - if ( | |
| 284 | - isset( $response['status'] ) | |
| 285 | - && $response['status'] === 'active' | |
| 286 | - && $previous_status !== 'active' | |
| 287 | - ) { | |
| 288 | - /** | |
| 289 | - * Fires when a channel becomes active and is ready to stream. | |
| 290 | - * | |
| 291 | - * @param int $channel_id Channel post ID. | |
| 292 | - * @param array $response API response data. | |
| 293 | - * @param string $notes Caller context from JS (e.g. wpstream_check_live_connections_on_start). | |
| 294 | - */ | |
| 295 | - do_action( 'wpstream_channel_became_active', $channel_id, $response, $notes ); | |
| 296 | - } | |
| 297 | 198 | |
| 298 | 199 | if( isset($response['broadcast_url']) && isset($response['status']) && $response['status']==='active' ){ |
| 299 | 200 | |
| 300 | 201 | |
| @@ -323,11 +224,8 @@ | ||
| 323 | 224 | |
| 324 | 225 | update_post_meta($channel_id,'obs_uri',$obs_uri); |
| 325 | 226 | update_post_meta($channel_id,'obs_stream',$obs_stream); |
| 326 | 227 | update_post_meta($channel_id,'broadcast_url',$response['broadcast_url']); |
| 327 | - if ( isset( $response['embedKey'] ) && $response['embedKey'] != '' ) { | |
| 328 | - update_post_meta( $channel_id,'embedKey',$response['embedKey'] ); | |
| 329 | - } | |
| 330 | 228 | |
| 331 | 229 | } |
| 332 | 230 | |
| 333 | 231 | |
| @@ -336,32 +234,8 @@ | ||
| 336 | 234 | print json_encode($response); |
| 337 | 235 | die(); |
| 338 | 236 | |
| 339 | 237 | } |
| 340 | - | |
| 341 | - public function wpstream_check_whipurl() { | |
| 342 | - check_ajax_referer( 'wpstream_start_event_nonce', 'nonce' ); | |
| 343 | - $channel_id = intval($_POST['channel_id']); | |
| 344 | - | |
| 345 | - $whip_url = get_post_meta($channel_id, 'whipUrl', true); | |
| 346 | - | |
| 347 | - if ( $whip_url ) { | |
| 348 | - print json_encode( | |
| 349 | - array( | |
| 350 | - 'success' => true, | |
| 351 | - 'whip_url' => $whip_url, | |
| 352 | - ) | |
| 353 | - ); | |
| 354 | - } else { | |
| 355 | - print json_encode( | |
| 356 | - array( | |
| 357 | - 'success' => false, | |
| 358 | - 'error' => esc_html__('WHIP URL not found for this channel.', 'wpstream'), | |
| 359 | - ) | |
| 360 | - ); | |
| 361 | - } | |
| 362 | - die(); | |
| 363 | - } | |
| 364 | 238 | |
| 365 | 239 | /** |
| 366 | 240 | * edited 4.0 |
| 367 | 241 | * |
| @@ -377,16 +251,12 @@ | ||
| 377 | 251 | $access_token = $this->wpstream_get_token(); |
| 378 | 252 | $domain = parse_url ( get_site_url() ); |
| 379 | 253 | $url = 'channel/info'; |
| 380 | 254 | |
| 381 | - // do not make the call if no token is available | |
| 382 | - if (!$access_token) return false; | |
| 383 | - | |
| 384 | 255 | $curl_post_fields=array( |
| 385 | 256 | 'access_token' => $access_token, |
| 386 | 257 | 'channel_id' => $channel_id, |
| 387 | 258 | 'domain' => $domain['host'], |
| 388 | - 'embed' => true, | |
| 389 | 259 | 'notes' => $notes |
| 390 | 260 | ); |
| 391 | 261 | |
| 392 | 262 | |
| @@ -392,9 +262,9 @@ | ||
| 392 | 262 | |
| 393 | 263 | |
| 394 | 264 | |
| 395 | 265 | |
| 396 | - $curl_response = $this->wpstream_baker_do_curl_base($url,$curl_post_fields,true, false,WPSTREAM_TIMEOUT_CONST); | |
| 266 | + $curl_response = $this->wpstream_baker_do_curl_base($url,$curl_post_fields); | |
| 397 | 267 | |
| 398 | 268 | |
| 399 | 269 | $curl_response_decoded = json_decode($curl_response,JSON_OBJECT_AS_ARRAY); |
| 400 | 270 | |
| @@ -456,11 +326,10 @@ | ||
| 456 | 326 | * returns live url |
| 457 | 327 | */ |
| 458 | 328 | |
| 459 | 329 | |
| 460 | - public function wpstream_update_local_event_settings(){ | |
| 330 | + public function wpstream_update_local_event_settings(){ | |
| 461 | 331 | |
| 462 | - check_ajax_referer( 'wpstream_start_event_nonce', 'security' ); | |
| 463 | 332 | if(!is_user_logged_in()){ |
| 464 | 333 | exit('not logged in'); |
| 465 | 334 | } |
| 466 | 335 | if( !current_user_can('administrator') ){ |
| @@ -473,171 +342,16 @@ | ||
| 473 | 342 | $to_save_option=array(); |
| 474 | 343 | foreach($option_array as $key=>$value){ |
| 475 | 344 | $to_save_option[sanitize_key($key)]=sanitize_text_field($value); |
| 476 | 345 | } |
| 477 | - | |
| 478 | - if( $to_save_option['low_latency'] == 1 || $to_save_option['adaptive_bitrate'] ==1 ){ | |
| 479 | - $to_save_option['encrypt']=0; | |
| 480 | - } | |
| 481 | - | |
| 482 | - if( $to_save_option['encrypt']==1){ | |
| 483 | - $to_save_option['low_latency'] = 0; | |
| 484 | - $to_save_option['adaptive_bitrate'] =0; | |
| 485 | - } | |
| 486 | - | |
| 487 | - | |
| 488 | 346 | |
| 489 | 347 | update_post_meta ($show_id,'local_event_options',$to_save_option); |
| 490 | 348 | $this->wpstream_update_chanel_on_baker($show_id,$to_save_option); |
| 491 | 349 | |
| 492 | 350 | } |
| 351 | + | |
| 352 | + | |
| 493 | 353 | |
| 494 | - public function wpstream_update_local_event_settings_with_global() { | |
| 495 | - check_ajax_referer( 'wpstream_start_event_nonce', 'security' ); | |
| 496 | - | |
| 497 | - check_ajax_referer( 'wpstream_start_event_nonce', 'security' ); | |
| 498 | - if(!is_user_logged_in()){ | |
| 499 | - wp_send_json_error(['success' => false, 'message' => __('Not logged in', 'wpstream')]); | |
| 500 | - } | |
| 501 | - if( !current_user_can('administrator') ){ | |
| 502 | - wp_send_json_error(['success' => false, 'message' => __('Not admin', 'wpstream')]); | |
| 503 | - } | |
| 504 | - | |
| 505 | - if ( !isset($_POST['show_id']) || !isset($_POST['use_global']) ) { | |
| 506 | - wp_send_json_error(['success' => false, 'message' => __('Missing parameters', 'wpstream')]); | |
| 507 | - } | |
| 508 | - | |
| 509 | - $show_id = intval($_POST['show_id']); | |
| 510 | - $default_channel_settings = get_option('wpstream_user_streaming_global_channel_options') ; | |
| 511 | - | |
| 512 | - $this->wpstream_update_chanel_on_baker($show_id, $default_channel_settings); | |
| 513 | - } | |
| 514 | - | |
| 515 | - public function wpstream_update_use_global_event_options() { | |
| 516 | - check_ajax_referer( 'wpstream_start_event_nonce', 'security' ); | |
| 517 | - if(!is_user_logged_in()){ | |
| 518 | - wp_send_json_error(['success' => false, 'message' => __('Not logged in', 'wpstream')]); | |
| 519 | - } | |
| 520 | - if( !current_user_can('administrator') ){ | |
| 521 | - wp_send_json_error(['success' => false, 'message' => __('Not admin', 'wpstream')]); | |
| 522 | - } | |
| 523 | - | |
| 524 | - if ( !isset($_POST['show_id']) || !isset($_POST['use_global']) ) { | |
| 525 | - wp_send_json_error(['success' => false, 'message' => __('Missing parameters', 'wpstream')]); | |
| 526 | - } | |
| 527 | - | |
| 528 | - $show_id = intval($_POST['show_id']); | |
| 529 | - $use_global_event_options = intval($_POST['use_global']); | |
| 530 | - | |
| 531 | - $result = update_post_meta( | |
| 532 | - $show_id, | |
| 533 | - 'use_global_event_options', | |
| 534 | - $use_global_event_options | |
| 535 | - ); | |
| 536 | - | |
| 537 | - if ( !$result ) { | |
| 538 | - wp_send_json_error(['success' => false, 'message' => __('Failed to update event', 'wpstream')]); | |
| 539 | - } | |
| 540 | - | |
| 541 | - $local_event_options = get_post_meta($show_id,'local_event_options',true); | |
| 542 | - | |
| 543 | - if( $use_global_event_options ) { | |
| 544 | - $global_event_options = get_option('wpstream_user_streaming_global_channel_options'); | |
| 545 | - | |
| 546 | - $this->wpstream_update_chanel_on_baker( $show_id, $global_event_options ); | |
| 547 | - } else { | |
| 548 | - $global_event_options = get_option('wpstream_user_streaming_global_channel_options'); | |
| 549 | - | |
| 550 | - // if the local options are not set, we need to set them to the global ones | |
| 551 | - if ( !is_array($local_event_options) ) { | |
| 552 | - update_post_meta( $show_id, 'local_event_options', $global_event_options ); | |
| 553 | - } | |
| 554 | - | |
| 555 | - $this->wpstream_update_chanel_on_baker( $show_id, $global_event_options ); | |
| 556 | - } | |
| 557 | - } | |
| 558 | - | |
| 559 | - public function wpstream_update_default_channel_settings() { | |
| 560 | - check_ajax_referer( 'wpstream-settings-nonce', 'security' ); | |
| 561 | - | |
| 562 | - $options_array= $_POST['option']; | |
| 563 | - $sanitized_options = array(); | |
| 564 | - foreach( $options_array as $key => $value ) { | |
| 565 | - $sanitized_options[ sanitize_key( $key ) ] = sanitize_text_field( $value ); | |
| 566 | - } | |
| 567 | - | |
| 568 | - if ( $sanitized_options['low_latency'] == 1 || $sanitized_options['adaptive_bitrate'] == 1 ) { | |
| 569 | - $sanitized_options['encrypt'] = 0; | |
| 570 | - } | |
| 571 | - | |
| 572 | - if ( $sanitized_options['encrypt'] == 1 ) { | |
| 573 | - $sanitized_options['low_latency'] = 0; | |
| 574 | - $sanitized_options['adaptive_bitrate'] = 0; | |
| 575 | - } | |
| 576 | - | |
| 577 | - $successful_update = update_option( 'wpstream_user_streaming_global_channel_options', $sanitized_options ); | |
| 578 | - | |
| 579 | - if ( $successful_update ) { | |
| 580 | - wp_send_json( | |
| 581 | - array( | |
| 582 | - 'success' => true, | |
| 583 | - ) | |
| 584 | - ); | |
| 585 | - } else { | |
| 586 | - wp_send_json_error( | |
| 587 | - array( | |
| 588 | - 'success' => false, | |
| 589 | - ) | |
| 590 | - ); | |
| 591 | - } | |
| 592 | - | |
| 593 | - wp_die(); | |
| 594 | - } | |
| 595 | - | |
| 596 | - public function wpstream_update_settings() { | |
| 597 | - check_ajax_referer( 'wpstream-settings-nonce', 'security' ); | |
| 598 | - | |
| 599 | - $option_name = sanitize_key( $_POST['option_name'] ); | |
| 600 | - $option_type = sanitize_key( $_POST['option_type'] ); | |
| 601 | - | |
| 602 | - switch( $option_type ) { | |
| 603 | - case 'checkbox': | |
| 604 | - $option_value = filter_var( $_POST['option_value'], FILTER_VALIDATE_INT ); | |
| 605 | - break; | |
| 606 | - case 'text': | |
| 607 | - case 'select': | |
| 608 | - $option_value = sanitize_text_field( $_POST['option_value'] ); | |
| 609 | - break; | |
| 610 | - case 'multiple-select': | |
| 611 | - if ( !is_array( $_POST['option_value'] ) ) { | |
| 612 | - $option_value = array(); | |
| 613 | - break; | |
| 614 | - } | |
| 615 | - $option_value = array_map( 'sanitize_text_field', $_POST['option_value'] ); | |
| 616 | - break; | |
| 617 | - default: | |
| 618 | - $option_value = sanitize_text_field( $_POST['option_value'] ); | |
| 619 | - } | |
| 620 | - | |
| 621 | - $successful_update = update_option( 'wpstream_' . $option_name, $option_value ); | |
| 622 | - | |
| 623 | - if( $successful_update ) { | |
| 624 | - wp_send_json( | |
| 625 | - array( | |
| 626 | - 'success' => true, | |
| 627 | - ) | |
| 628 | - ); | |
| 629 | - } else { | |
| 630 | - wp_send_json_error( | |
| 631 | - array( | |
| 632 | - 'success' => false, | |
| 633 | - ) | |
| 634 | - ); | |
| 635 | - } | |
| 636 | - | |
| 637 | - wp_die(); | |
| 638 | - } | |
| 639 | - | |
| 640 | 354 | /** |
| 641 | 355 | * Update channel settings on baker |
| 642 | 356 | * |
| 643 | 357 | * @since 4.2 |
| @@ -648,10 +362,8 @@ | ||
| 648 | 362 | public function wpstream_update_chanel_on_baker($channel_id,$to_save_option){ |
| 649 | 363 | |
| 650 | 364 | $access_token = $this->wpstream_get_token(); |
| 651 | 365 | if($access_token==''){ |
| 652 | - // cleanup any previous echo before sending json | |
| 653 | - ob_end_clean(); | |
| 654 | 366 | echo json_encode( array( |
| 655 | 367 | 'is_record' => '', |
| 656 | 368 | 'conected' => false, |
| 657 | 369 | 'event_data' => '', |
| @@ -680,9 +392,12 @@ | ||
| 680 | 392 | |
| 681 | 393 | $corsorigin='*'; |
| 682 | 394 | if( isset($local_event_options['domain_lock']) && intval( $local_event_options['domain_lock']) ==0 ){ |
| 683 | 395 | $corsorigin='*'; |
| 684 | - } else{ | |
| 396 | + } | |
| 397 | + | |
| 398 | + | |
| 399 | + if($corsorigin!='*'){ | |
| 685 | 400 | $corsorigin=$domain_scheme.'://'.$domain['host']; |
| 686 | 401 | } |
| 687 | 402 | |
| 688 | 403 | |
| @@ -693,25 +408,8 @@ | ||
| 693 | 408 | if($to_save_option['record']){ |
| 694 | 409 | $to_record="true"; |
| 695 | 410 | } |
| 696 | 411 | |
| 697 | - if( $to_save_option['low_latency'] == 1 || $to_save_option['adaptive_bitrate'] ==1 ){ | |
| 698 | - $to_save_option['encrypt']=0; | |
| 699 | - } | |
| 700 | - | |
| 701 | - if( $to_save_option['encrypt']==1){ | |
| 702 | - $to_save_option['low_latency'] = 0; | |
| 703 | - $to_save_option['adaptive_bitrate'] =0; | |
| 704 | - } | |
| 705 | - | |
| 706 | - | |
| 707 | - $abr='none'; | |
| 708 | - if($to_save_option['adaptive_bitrate'] ==1 ){ | |
| 709 | - $abr='common'; | |
| 710 | - } | |
| 711 | - | |
| 712 | - | |
| 713 | - | |
| 714 | 412 | $curl_post_fields=array( |
| 715 | 413 | 'access_token' => $access_token, |
| 716 | 414 | 'channel_id' => $channel_id, |
| 717 | 415 | 'domain' => $domain['host'], |
| @@ -718,19 +416,14 @@ | ||
| 718 | 416 | 'allow_access_from' => $corsorigin, |
| 719 | 417 | 'record' => $to_record, |
| 720 | 418 | 'encrypt' => boolval($to_save_option['encrypt']), |
| 721 | 419 | 'autostart' => boolval($to_save_option['autostart']), |
| 722 | - 'low_latency' => boolval($to_save_option['low_latency']), | |
| 723 | - 'abr' => $abr, | |
| 724 | 420 | 'hls_keys_url_prefix' => get_site_url().'?wpstream_livedrm=', |
| 725 | - 'allow_key_access_from' => $domain_ip, | |
| 726 | - 'to_save_option' => $to_save_option, | |
| 421 | + 'allow_key_access_from' => $domain_ip, | |
| 727 | 422 | ); |
| 728 | 423 | |
| 729 | - | |
| 730 | - | |
| 731 | - $curl_response = $this->wpstream_baker_do_curl_base($url,$curl_post_fields,true); | |
| 732 | - print_r($curl_response); | |
| 424 | + $curl_response = $this->wpstream_baker_do_curl_base($url,$curl_post_fields); | |
| 425 | + | |
| 733 | 426 | exit(); |
| 734 | 427 | } |
| 735 | 428 | |
| 736 | 429 | |
| @@ -747,10 +440,8 @@ | ||
| 747 | 440 | public function wpstream_turn_of_channel(){ |
| 748 | 441 | |
| 749 | 442 | $access_token = $this->wpstream_get_token(); |
| 750 | 443 | if($access_token==''){ |
| 751 | - // cleanup any previous echo before sending json | |
| 752 | - ob_end_clean(); | |
| 753 | 444 | echo json_encode( array( |
| 754 | 445 | 'is_record' => '', |
| 755 | 446 | 'conected' => false, |
| 756 | 447 | 'event_data' => '', |
| @@ -780,23 +471,19 @@ | ||
| 780 | 471 | ); |
| 781 | 472 | |
| 782 | 473 | |
| 783 | 474 | |
| 784 | - $curl_response = $this->wpstream_baker_do_curl_base($url,$curl_post_fields,true); | |
| 475 | + $curl_response = $this->wpstream_baker_do_curl_base($url,$curl_post_fields); | |
| 785 | 476 | $curl_response_decoded = json_decode($curl_response,JSON_OBJECT_AS_ARRAY); |
| 786 | 477 | |
| 787 | 478 | |
| 788 | 479 | |
| 789 | 480 | if( isset($curl_response_decoded['success']) && $curl_response_decoded['success']===true ){ |
| 790 | - // cleanup any previous echo before sending json | |
| 791 | - ob_end_clean(); | |
| 792 | 481 | echo json_encode( array( |
| 793 | 482 | 'conected' => true, |
| 794 | 483 | 'answer' => $curl_response_decoded, |
| 795 | 484 | )); |
| 796 | 485 | }else{ |
| 797 | - // cleanup any previous echo before sending json | |
| 798 | - ob_end_clean(); | |
| 799 | 486 | echo json_encode( array( |
| 800 | 487 | 'conected' => false, |
| 801 | 488 | 'error' => esc_html__('Channel is already turned off or does not exist!','wpstream'), |
| 802 | 489 | 'answer' => $curl_response_decoded, |
| @@ -822,10 +509,8 @@ | ||
| 822 | 509 | public function wpstream_give_me_live_uri(){ |
| 823 | 510 | |
| 824 | 511 | $access_token = $this->wpstream_get_token(); |
| 825 | 512 | if($access_token==''){ |
| 826 | - // cleanup any previous echo before sending json | |
| 827 | - ob_end_clean(); | |
| 828 | 513 | echo json_encode( array( |
| 829 | 514 | 'is_record' => '', |
| 830 | 515 | 'conected' => false, |
| 831 | 516 | 'event_data' => '', |
| @@ -844,12 +529,8 @@ | ||
| 844 | 529 | } |
| 845 | 530 | |
| 846 | 531 | |
| 847 | 532 | $channel_id = intval($_POST['show_id']); |
| 848 | - | |
| 849 | - $pack_details = $wpstream_plugin->main->quota_manager->force_quota_update(); | |
| 850 | - $basic_streaming = $wpstream_plugin->main->quota_manager->is_basic_streaming_mode( $pack_details ); | |
| 851 | - | |
| 852 | 533 | $on_boarding = ''; |
| 853 | 534 | if(isset($_POST['start_onboarding'])){ |
| 854 | 535 | $on_boarding = sanitize_text_field($_POST['start_onboarding']); |
| 855 | 536 | } |
| @@ -854,79 +535,44 @@ | ||
| 854 | 535 | $on_boarding = sanitize_text_field($_POST['start_onboarding']); |
| 855 | 536 | } |
| 856 | 537 | |
| 857 | 538 | |
| 858 | - $local_event_options = get_post_meta($channel_id,'local_event_options',true); | |
| 859 | - $use_global_event_options = get_post_meta($channel_id,'use_global_event_options',true); | |
| 860 | - $is_local_event_options_enabled = ( is_array( $local_event_options ) && empty( $use_global_event_options ) ) || | |
| 861 | - ( !empty($use_global_event_options) && intval( $use_global_event_options ) === 0 ); | |
| 862 | - if( !$is_local_event_options_enabled ) { | |
| 863 | - $local_event_options = get_option('wpstream_user_streaming_global_channel_options') ; | |
| 864 | - } | |
| 539 | + $local_event_options = get_post_meta($channel_id,'local_event_options',true); | |
| 540 | + if(!is_array($local_event_options)){ | |
| 541 | + $local_event_options = get_option('wpstream_user_streaming_global_channel_options') ; | |
| 542 | + } | |
| 865 | 543 | |
| 866 | - $is_autostart="false"; | |
| 867 | - $is_encrypt="false"; | |
| 868 | - $low_latency="false"; | |
| 869 | - $adaptive_bitrate="false"; | |
| 870 | - $is_record="false"; | |
| 871 | - $corsorigin='*'; | |
| 872 | 544 | |
| 873 | - if ( is_array($local_event_options) ) { | |
| 874 | - if ( isset($local_event_options['autostart']) && | |
| 875 | - intval( $local_event_options['autostart']) == 1 ) { | |
| 876 | - $is_autostart = "true"; | |
| 877 | - } | |
| 545 | + // set encrypt option | |
| 546 | + $is_autostart="false"; | |
| 547 | + if( intval( $local_event_options['autostart']) ==1 ){ | |
| 548 | + $is_autostart="true"; | |
| 549 | + } | |
| 878 | 550 | |
| 879 | - if ( isset($local_event_options['encrypt']) && | |
| 880 | - intval( $local_event_options['encrypt']) == 1 ) { | |
| 881 | - $is_encrypt = "true"; | |
| 882 | - } | |
| 883 | 551 | |
| 884 | - if ( isset($local_event_options['low_latency']) && | |
| 885 | - intval( $local_event_options['low_latency']) == 1 ) { | |
| 886 | - $low_latency = "true"; | |
| 887 | - } | |
| 552 | + // set encrypt option | |
| 553 | + $is_encrypt="false"; | |
| 554 | + if( intval( $local_event_options['encrypt']) ==1 ){ | |
| 555 | + $is_encrypt="true"; | |
| 556 | + } | |
| 888 | 557 | |
| 889 | - if ( isset($local_event_options['adaptive_bitrate']) && | |
| 890 | - intval( $local_event_options['adaptive_bitrate']) == 1 ) { | |
| 891 | - $adaptive_bitrate = "true"; | |
| 892 | - } | |
| 558 | + // set record option | |
| 559 | + $is_record="false"; | |
| 560 | + if( intval( $local_event_options['record']) ==1 ){ | |
| 561 | + $is_record="true"; | |
| 562 | + } | |
| 893 | 563 | |
| 894 | - if ( isset($local_event_options['record']) && | |
| 895 | - intval( $local_event_options['record']) == 1 ) { | |
| 896 | - $is_record = "true"; | |
| 897 | - } | |
| 898 | - | |
| 899 | - if ( !isset($local_event_options['domain_lock']) || intval( $local_event_options['domain_lock']) == 0 ) { | |
| 900 | - $corsorigin = '*'; | |
| 901 | - } | |
| 902 | - } | |
| 903 | - | |
| 904 | - if( $adaptive_bitrate=="true" || $low_latency=="true" ) { | |
| 905 | - $is_encrypt="false"; | |
| 906 | - } | |
| 907 | - | |
| 908 | - if( $is_encrypt=="true" ) { | |
| 909 | - $adaptive_bitrate="false"; | |
| 910 | - $low_latency="false"; | |
| 911 | - } | |
| 912 | - | |
| 913 | - $event_data = $this->wpstream_request_live_stream_uri( | |
| 914 | - $channel_id, | |
| 915 | - $is_autostart, | |
| 916 | - $is_record, | |
| 917 | - $is_encrypt, | |
| 918 | - $low_latency, | |
| 919 | - $adaptive_bitrate, | |
| 920 | - $userID, | |
| 921 | - $corsorigin, | |
| 922 | - $on_boarding, | |
| 923 | - $basic_streaming | |
| 924 | - ); | |
| 564 | + $corsorigin=''; | |
| 565 | + if( isset($local_event_options['domain_lock']) && intval( $local_event_options['domain_lock']) ==0 ){ | |
| 566 | + $corsorigin='*'; | |
| 567 | + } | |
| 568 | + | |
| 925 | 569 | |
| 570 | + $event_data = $this->wpstream_request_live_stream_uri($channel_id,$is_autostart,$is_record,$is_encrypt,$userID,$corsorigin,$on_boarding); | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 926 | 574 | if( isset($event_data['success']) && $event_data['success']===true ){ |
| 927 | - // cleanup any previous echo before sending json | |
| 928 | - ob_end_clean(); | |
| 929 | 575 | echo json_encode( array( |
| 930 | 576 | 'is_record' => $is_record, |
| 931 | 577 | 'conected' => true, |
| 932 | 578 | 'event_data' => $event_data, |
| @@ -943,10 +589,8 @@ | ||
| 943 | 589 | |
| 944 | 590 | } |
| 945 | 591 | |
| 946 | 592 | } |
| 947 | - // cleanup any previous echo before sending json | |
| 948 | - ob_end_clean(); | |
| 949 | 593 | echo json_encode( array( |
| 950 | 594 | 'is_record' => $is_record, |
| 951 | 595 | 'conected' => false, |
| 952 | 596 | 'event_data' => $event_data, |
| @@ -957,20 +601,9 @@ | ||
| 957 | 601 | } |
| 958 | 602 | die(); |
| 959 | 603 | } |
| 960 | 604 | |
| 961 | - public function wpstream_is_streamify_user() { | |
| 962 | - return false; | |
| 963 | -// global $wpstream_plugin; | |
| 964 | -// $pack_details = $wpstream_plugin->main->quota_manager->get_live_quota_data( 'wpstream_is_streamify_user' ); | |
| 965 | -// | |
| 966 | -// if ( isset( $pack_details['available_data'] ) && $pack_details['available_data'] <= 0 ) { | |
| 967 | -// return true; | |
| 968 | -// } | |
| 969 | -// return false; | |
| 970 | - } | |
| 971 | 605 | |
| 972 | - | |
| 973 | 606 | /** |
| 974 | 607 | * |
| 975 | 608 | * Edited 4.0 |
| 976 | 609 | * |
| @@ -980,21 +613,10 @@ | ||
| 980 | 613 | * returns live url |
| 981 | 614 | */ |
| 982 | 615 | |
| 983 | 616 | |
| 984 | - public function wpstream_request_live_stream_uri( | |
| 985 | - $schannel_id, | |
| 986 | - $is_autostart, | |
| 987 | - $is_record, | |
| 988 | - $is_encrypt, | |
| 989 | - $low_latency, | |
| 990 | - $adaptive_bitrate, | |
| 991 | - $request_by_userid, | |
| 992 | - $corsorigin, | |
| 993 | - $on_boarding, | |
| 994 | - $basic_streaming | |
| 995 | - ) { | |
| 996 | - | |
| 617 | + public function wpstream_request_live_stream_uri($schannel_id,$is_autostart,$is_record,$is_encrypt,$request_by_userid,$corsorigin,$on_boarding){ | |
| 618 | + | |
| 997 | 619 | $domain = parse_url ( get_site_url() ); |
| 998 | 620 | $domain_scheme = 'http'; |
| 999 | 621 | if(is_ssl()){ |
| 1000 | 622 | $domain_scheme='https'; |
| @@ -1008,21 +630,10 @@ | ||
| 1008 | 630 | if($corsorigin!='*'){ |
| 1009 | 631 | $corsorigin=$domain_scheme.'://'.$domain['host']; |
| 1010 | 632 | } |
| 1011 | 633 | |
| 1012 | - $abr='none'; | |
| 1013 | - if($adaptive_bitrate=="true"){ | |
| 1014 | - $abr='common'; | |
| 1015 | - } | |
| 1016 | 634 | |
| 1017 | - if($low_latency=="true"){ | |
| 1018 | - $low_latency=true; | |
| 1019 | - }else{ | |
| 1020 | - $low_latency = false; | |
| 1021 | - } | |
| 1022 | - | |
| 1023 | - $basic_streaming = $basic_streaming ? 'true' : 'false'; | |
| 1024 | - | |
| 635 | + | |
| 1025 | 636 | $url = 'channel/start'; |
| 1026 | 637 | $access_token = $this->wpstream_get_token(); |
| 1027 | 638 | |
| 1028 | 639 | $metadata_array=array( |
| @@ -1031,12 +642,9 @@ | ||
| 1031 | 642 | |
| 1032 | 643 | if($on_boarding!=''){ |
| 1033 | 644 | $metadata_array['on_boarding']='yes'; |
| 1034 | 645 | } |
| 1035 | - $permalink = get_permalink($schannel_id); | |
| 1036 | - if ($permalink !== false) { | |
| 1037 | - $metadata_array['permalink'] = $permalink; | |
| 1038 | - } | |
| 646 | + | |
| 1039 | 647 | |
| 1040 | 648 | $curl_post_fields=array( |
| 1041 | 649 | 'access_token' => $access_token, |
| 1042 | 650 | 'channel_id' => $schannel_id, |
| @@ -1041,24 +649,24 @@ | ||
| 1041 | 649 | 'access_token' => $access_token, |
| 1042 | 650 | 'channel_id' => $schannel_id, |
| 1043 | 651 | 'domain' => $domain['host'], |
| 1044 | 652 | 'allow_access_from' => $corsorigin, |
| 1045 | - 'record' => $basic_streaming ? $is_record : 'false', | |
| 1046 | - 'encrypt' => $basic_streaming ? $is_encrypt : 'false', | |
| 1047 | - 'low_latency' => $basic_streaming ? $low_latency : 'false', | |
| 1048 | - 'abr' => $basic_streaming ? $abr : 'none', | |
| 653 | + 'record' => $is_record, | |
| 654 | + 'encrypt' => $is_encrypt, | |
| 655 | + 'low_latency' => false, | |
| 656 | + 'abr' => 'none', | |
| 1049 | 657 | 'hls_keys_url_prefix' => get_site_url().'?wpstream_livedrm=', |
| 1050 | 658 | 'allow_key_access_from' => $domain_ip, |
| 1051 | 659 | 'metadata' => json_encode($metadata_array), |
| 1052 | - 'autostart' => $basic_streaming ? $is_autostart : 'false', | |
| 1053 | - 'basic_streaming' => $basic_streaming, | |
| 660 | + 'autostart' => $is_autostart, | |
| 1054 | 661 | // 'fakeError' => 'init' |
| 1055 | 662 | ); |
| 1056 | 663 | |
| 1057 | 664 | |
| 1058 | - $curl_response = $this->wpstream_baker_do_curl_base($url,$curl_post_fields,true); | |
| 665 | + | |
| 666 | + $curl_response = $this->wpstream_baker_do_curl_base($url,$curl_post_fields); | |
| 1059 | 667 | $curl_response_decoded = json_decode($curl_response,JSON_OBJECT_AS_ARRAY); |
| 1060 | - // $curl_response_decoded['curl_post_fields']=$curl_post_fields; | |
| 668 | + | |
| 1061 | 669 | return $curl_response_decoded; |
| 1062 | 670 | |
| 1063 | 671 | |
| 1064 | 672 | |
| @@ -1081,23 +689,31 @@ | ||
| 1081 | 689 | * returns token |
| 1082 | 690 | */ |
| 1083 | 691 | public function wpstream_get_token(){ |
| 1084 | 692 | $token = get_transient('wpstream_token_api'); |
| 1085 | - if ( false === $token || $token === '' || $token=== NULL ) { | |
| 693 | + if ( false === $token || $token==='' ) { | |
| 1086 | 694 | $token = $this->wpstream_club_get_token(); |
| 1087 | - if ($token !== false){ | |
| 1088 | - set_transient( 'wpstream_token_api', $token ,3500); | |
| 1089 | - } | |
| 1090 | - else { | |
| 1091 | - // cache the failed response for a second, otherwise it'll make a shitload of requests | |
| 1092 | - set_transient( 'wpstream_token_api', 'failed' , 1); | |
| 1093 | - } | |
| 695 | + set_transient( 'wpstream_token_api', $token ,3500); | |
| 1094 | 696 | } |
| 1095 | - $ret = $token === 'failed' ? false : $token; | |
| 1096 | - return $ret; | |
| 697 | + | |
| 698 | + return $token; | |
| 699 | + | |
| 1097 | 700 | } |
| 1098 | 701 | |
| 1099 | - /** | |
| 702 | + | |
| 703 | + public function wpstream_get_token_30(){ | |
| 704 | + $token = get_transient('wpstream_token_request_30'); | |
| 705 | + if ( false === $token || $token==='' ) { | |
| 706 | + $token = $this->wpstream_club_get_token_30(); | |
| 707 | + set_transient( 'wpstream_token_request_30', $token ,600); | |
| 708 | + } | |
| 709 | + | |
| 710 | + return $token; | |
| 711 | + | |
| 712 | + } | |
| 713 | + | |
| 714 | + | |
| 715 | + /** | |
| 1100 | 716 | * Edited 4.0 |
| 1101 | 717 | * |
| 1102 | 718 | * Request auth token from wpstream.net |
| 1103 | 719 | * |
| @@ -1104,31 +720,39 @@ | ||
| 1104 | 720 | * @since 3.0.1 |
| 1105 | 721 | * returns token fron wpstream |
| 1106 | 722 | */ |
| 1107 | 723 | protected function wpstream_club_get_token(){ |
| 1108 | - $username = get_option('wpstream_api_username',''); | |
| 1109 | - $password = get_option('wpstream_api_password',''); | |
| 1110 | 724 | |
| 725 | + | |
| 726 | + $username = esc_html ( get_option('wpstream_api_username','') ); | |
| 727 | + $password = esc_html ( get_option('wpstream_api_password','') ); | |
| 728 | + | |
| 1111 | 729 | if ( $username=='' || $password==''){ |
| 1112 | 730 | return; |
| 1113 | 731 | } |
| 1114 | 732 | |
| 1115 | - $url = 'access_token'; | |
| 1116 | - $curl_post_fields = array( | |
| 1117 | - 'grant_type' => 'password', | |
| 1118 | - 'username' => $username, | |
| 1119 | - 'password' => $password | |
| 733 | + $url='access_token'; | |
| 734 | + $curl_post_fields=array( | |
| 735 | + 'grant_type' => 'password', | |
| 736 | + 'username' => $username, | |
| 737 | + 'password' => $password | |
| 1120 | 738 | ); |
| 1121 | - $curl_response = $this->wpstream_baker_do_curl_base($url, $curl_post_fields, true); | |
| 1122 | - $response = json_decode($curl_response); | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + $curl_response=$this->wpstream_baker_do_curl_base($url,$curl_post_fields); | |
| 743 | + | |
| 744 | + $response= json_decode($curl_response); | |
| 1123 | 745 | |
| 1124 | - if( isset( $response->access_token ) && $response->access_token != '' ) { | |
| 746 | + if( isset($response->access_token) && $response->access_token!='' ){ | |
| 1125 | 747 | return $response->access_token; |
| 1126 | - } else { | |
| 748 | + }else{ | |
| 1127 | 749 | return false; |
| 1128 | 750 | } |
| 1129 | 751 | } |
| 1130 | - | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 1131 | 755 | /* |
| 1132 | 756 | * |
| 1133 | 757 | * Return token for api version 3.0 |
| 1134 | 758 | * |
| @@ -1133,8 +757,70 @@ | ||
| 1133 | 757 | * Return token for api version 3.0 |
| 1134 | 758 | * |
| 1135 | 759 | */ |
| 1136 | 760 | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + protected function wpstream_club_get_token_30(){ | |
| 765 | + | |
| 766 | + $client_id = esc_html ( get_option('wpstream_api_key','') ); | |
| 767 | + $client_secret = esc_html ( get_option('wpstream_api_secret_key','') ); | |
| 768 | + $username = esc_html ( get_option('wpstream_api_username','') ); | |
| 769 | + $password = esc_html ( get_option('wpstream_api_password','') ); | |
| 770 | + | |
| 771 | + if ( $username=='' || $password==''){ | |
| 772 | + return; | |
| 773 | + } | |
| 774 | + | |
| 775 | + | |
| 776 | + $curl = curl_init(); | |
| 777 | + | |
| 778 | + $json = array( | |
| 779 | + 'grant_type'=>'password', | |
| 780 | + 'username' =>$username, | |
| 781 | + 'password' =>$password, | |
| 782 | + 'client_id'=>'qxZ6fCoOMj4cNK8SXRHa5nug6vnswlFWSF37hsW3', | |
| 783 | + 'client_secret'=>'L1fzLosJf9TlwnCCTZ5pkKmdqqkHShKEi0d4oFNE' | |
| 784 | + ); | |
| 785 | + | |
| 786 | + curl_setopt_array($curl, array( | |
| 787 | + CURLOPT_URL => WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/?oauth=token", | |
| 788 | + CURLOPT_RETURNTRANSFER => true, | |
| 789 | + CURLOPT_ENCODING => "", | |
| 790 | + CURLOPT_MAXREDIRS => 10, | |
| 791 | + CURLOPT_TIMEOUT => 15, | |
| 792 | + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, | |
| 793 | + CURLOPT_CUSTOMREQUEST => "POST", | |
| 794 | + CURLOPT_POSTFIELDS=> json_encode($json), | |
| 795 | + CURLOPT_HTTPHEADER => array( | |
| 796 | + "cache-control: no-cache", | |
| 797 | + "content-type: application/json", | |
| 798 | + ), | |
| 799 | + )); | |
| 800 | + | |
| 801 | + $response = curl_exec($curl); | |
| 802 | + | |
| 803 | + if(!$response){ | |
| 804 | + // | |
| 805 | + } | |
| 806 | + | |
| 807 | + $err = curl_error($curl); | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + curl_close($curl); | |
| 814 | + $response= json_decode($response); | |
| 815 | + | |
| 816 | + if(isset($response->access_token)){ | |
| 817 | + return $response->access_token; | |
| 818 | + }else{ | |
| 819 | + return; | |
| 820 | + } | |
| 821 | + } | |
| 822 | + | |
| 1137 | 823 | |
| 1138 | 824 | |
| 1139 | 825 | /** |
| 1140 | 826 | * edited 4.0 |
| @@ -1143,31 +829,38 @@ | ||
| 1143 | 829 | * @since 3.0.1 |
| 1144 | 830 | * returns pack data |
| 1145 | 831 | */ |
| 1146 | 832 | |
| 1147 | - public function wpstream_request_pack_data_per_user($context = ''){ | |
| 1148 | - return $this->user_quota_service->request_pack_data_per_user( $context ); | |
| 833 | + public function wpstream_request_pack_data_per_user(){ | |
| 834 | + | |
| 835 | + $event_data_for_transient = get_transient( 'wpstream_request_pack_data_per_user_transient' ); | |
| 836 | + | |
| 837 | + if($event_data_for_transient===false){ | |
| 838 | + $url = 'user/quota'; | |
| 839 | + $access_token = $this->wpstream_get_token(); | |
| 840 | + $curl_post_fields=array( | |
| 841 | + 'access_token'=>$access_token | |
| 842 | + ); | |
| 843 | + | |
| 844 | + $curl_response = $this->wpstream_baker_do_curl_base($url,$curl_post_fields); | |
| 845 | + $curl_response_decoded = json_decode($curl_response,JSON_OBJECT_AS_ARRAY); | |
| 846 | + | |
| 847 | + if( isset($curl_response_decoded['success']) && $curl_response_decoded['success']===true ){ | |
| 848 | + set_transient( 'wpstream_request_pack_data_per_user_transient', $curl_response_decoded, 15 ); | |
| 849 | + | |
| 850 | + update_option('wpstream_api_username_from_token',$curl_response_decoded['username']); | |
| 851 | + return $curl_response_decoded; | |
| 852 | + }else{ | |
| 853 | + return false; | |
| 854 | + } | |
| 855 | + | |
| 856 | + }else{ | |
| 857 | + return $event_data_for_transient; | |
| 858 | + } | |
| 859 | + | |
| 1149 | 860 | } |
| 1150 | - | |
| 1151 | - public function get_user_quota_service() { | |
| 1152 | - return $this->user_quota_service; | |
| 1153 | - } | |
| 1154 | 861 | |
| 1155 | 862 | |
| 1156 | - public function wpstream_check_user_quota() { | |
| 1157 | - $pack_data = $this->wpstream_request_pack_data_per_user('wpstream_check_user_quota'); | |
| 1158 | - if ( ! $pack_data || ! isset( $pack_data['success'] ) || ! $pack_data['success'] ) { | |
| 1159 | - print json_encode( | |
| 1160 | - array( | |
| 1161 | - 'success' => false, | |
| 1162 | - 'error' => esc_html__('Couldn\'t get user quota.', 'wpstream'), | |
| 1163 | - ) | |
| 1164 | - ); | |
| 1165 | - } else { | |
| 1166 | - print json_encode($pack_data); | |
| 1167 | - } | |
| 1168 | - die(); | |
| 1169 | - } | |
| 1170 | 863 | |
| 1171 | 864 | |
| 1172 | 865 | /** |
| 1173 | 866 | * Edited 4.0 |
| @@ -1194,21 +887,16 @@ | ||
| 1194 | 887 | * |
| 1195 | 888 | * @since 3.0.1 |
| 1196 | 889 | * returns true or false |
| 1197 | 890 | */ |
| 1198 | - public function wpstream_get_live_event_for_user($with_exit='yes'){ | |
| 891 | + | |
| 892 | + public function wpstream_get_live_event_for_user(){ | |
| 1199 | 893 | $current_user = wp_get_current_user(); |
| 1200 | 894 | $userID = $current_user->ID; |
| 1201 | 895 | |
| 1202 | 896 | global $wpstream_plugin; |
| 1203 | 897 | if( !$wpstream_plugin->main->wpstream_check_user_can_stream() ){ |
| 1204 | - if($with_exit=='yes'){ | |
| 1205 | - // esc_html_e ('You are not allowed to start a live stream !','wpstream'); | |
| 1206 | - return; | |
| 1207 | - }else{ | |
| 1208 | - return; | |
| 1209 | - } | |
| 1210 | - | |
| 898 | + exit('You are not allowed to start a live stream !'); | |
| 1211 | 899 | } |
| 1212 | 900 | |
| 1213 | 901 | |
| 1214 | 902 | $event_data = $this->wpstream_request_live_stream_for_user($userID); |
| @@ -1223,9 +911,8 @@ | ||
| 1223 | 911 | |
| 1224 | 912 | |
| 1225 | 913 | |
| 1226 | 914 | |
| 1227 | - | |
| 1228 | 915 | |
| 1229 | 916 | |
| 1230 | 917 | |
| 1231 | 918 | |
| @@ -1242,25 +929,24 @@ | ||
| 1242 | 929 | */ |
| 1243 | 930 | public function wpstream_request_live_stream_for_user($user_id){ |
| 1244 | 931 | |
| 1245 | 932 | global $wpstream_plugin; |
| 1246 | - | |
| 933 | + if( !$wpstream_plugin->main->wpstream_check_user_can_stream() ){ | |
| 934 | + exit('You are not allowed to stream. Code 741.'); | |
| 935 | + } | |
| 1247 | 936 | |
| 937 | + | |
| 1248 | 938 | $domain = parse_url ( get_site_url() ); |
| 1249 | 939 | |
| 1250 | 940 | |
| 1251 | 941 | $url = 'channel/list'; |
| 1252 | 942 | $access_token = $this->wpstream_get_token(); |
| 1253 | - | |
| 1254 | - // do not make the call if no token is available | |
| 1255 | - if (!$access_token) return false; | |
| 1256 | - | |
| 1257 | 943 | $curl_post_fields=array( |
| 1258 | 944 | 'access_token' => $access_token, |
| 1259 | 945 | 'domain' => $domain['host'], |
| 1260 | 946 | 'status' => 'active' |
| 1261 | 947 | ); |
| 1262 | - $curl_response = $this->wpstream_baker_do_curl_base($url,$curl_post_fields,true); | |
| 948 | + $curl_response = $this->wpstream_baker_do_curl_base($url,$curl_post_fields); | |
| 1263 | 949 | $curl_response_decoded = json_decode($curl_response,JSON_OBJECT_AS_ARRAY); |
| 1264 | 950 | |
| 1265 | 951 | |
| 1266 | 952 | |
| @@ -1285,9 +971,9 @@ | ||
| 1285 | 971 | global $wpstream_plugin; |
| 1286 | 972 | $return_array=array(); |
| 1287 | 973 | |
| 1288 | 974 | $result = get_transient('wpstream_live_stream_for_user_for_shortcode'); |
| 1289 | - | |
| 975 | + $result==false; | |
| 1290 | 976 | if($result===false){ |
| 1291 | 977 | $result = $this->wpstream_request_live_stream_for_user(''); |
| 1292 | 978 | set_transient('wpstream_live_stream_for_user_for_shortcode',$result,30); |
| 1293 | 979 | } |
| @@ -1328,19 +1014,12 @@ | ||
| 1328 | 1014 | |
| 1329 | 1015 | |
| 1330 | 1016 | $url = 'video/upload'; |
| 1331 | 1017 | $access_token = $this->wpstream_get_token(); |
| 1332 | - | |
| 1333 | - // do not make the call if no token is available | |
| 1334 | - if (!$access_token) return array( | |
| 1335 | - 'success' => false, | |
| 1336 | - 'error' => 'not_connected', | |
| 1337 | - ); | |
| 1338 | - | |
| 1339 | 1018 | $curl_post_fields=array( |
| 1340 | 1019 | 'access_token' => $access_token, |
| 1341 | 1020 | ); |
| 1342 | - $curl_response = $this->wpstream_baker_do_curl_base($url,$curl_post_fields,true); | |
| 1021 | + $curl_response = $this->wpstream_baker_do_curl_base($url,$curl_post_fields); | |
| 1343 | 1022 | $curl_response_decoded = json_decode($curl_response,JSON_OBJECT_AS_ARRAY); |
| 1344 | 1023 | |
| 1345 | 1024 | |
| 1346 | 1025 | return $curl_response_decoded; |
| @@ -1363,24 +1042,23 @@ | ||
| 1363 | 1042 | * |
| 1364 | 1043 | */ |
| 1365 | 1044 | public function wpstream_get_videos(){ |
| 1366 | 1045 | if( !current_user_can('administrator') ){ |
| 1367 | - return; | |
| 1046 | + exit('not admin on wpstream_get_videos'); | |
| 1368 | 1047 | } |
| 1369 | 1048 | |
| 1370 | 1049 | |
| 1371 | 1050 | $video_options = array(); |
| 1372 | 1051 | $video_array = $this->wpstream_get_videos_from_api(); |
| 1373 | - $video_list_raw_array = false; | |
| 1052 | + | |
| 1053 | + $video_list_raw_array = $video_array['items']; | |
| 1374 | 1054 | |
| 1375 | - if ( is_array($video_array) && isset($video_array['items']) && is_array($video_array['items']) ) { | |
| 1376 | - $video_list_raw_array = $video_array['items']; | |
| 1377 | - } | |
| 1055 | + $keys = array_column($video_list_raw_array, 'time'); | |
| 1056 | + array_multisort($keys, SORT_DESC , $video_list_raw_array); | |
| 1378 | 1057 | |
| 1379 | - if(is_array($video_list_raw_array)){ | |
| 1380 | - $keys = array_column($video_list_raw_array, 'time'); | |
| 1381 | - array_multisort($keys, SORT_DESC , $video_list_raw_array); | |
| 1382 | - | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + if(is_array($video_list_raw_array)){ | |
| 1383 | 1061 | foreach ($video_list_raw_array as $key => $videos){ |
| 1384 | 1062 | if($videos['name']!=''): |
| 1385 | 1063 | $video_options[$videos['name']]=$videos['name']; |
| 1386 | 1064 | endif; |
| @@ -1387,8 +1065,9 @@ | ||
| 1387 | 1065 | } |
| 1388 | 1066 | |
| 1389 | 1067 | } |
| 1390 | 1068 | return $video_options; |
| 1069 | + | |
| 1391 | 1070 | } |
| 1392 | 1071 | |
| 1393 | 1072 | |
| 1394 | 1073 | |
| @@ -1409,18 +1088,14 @@ | ||
| 1409 | 1088 | |
| 1410 | 1089 | |
| 1411 | 1090 | $url = 'video/list'; |
| 1412 | 1091 | $access_token = $this->wpstream_get_token(); |
| 1413 | - | |
| 1414 | - // do not make the call if no token is available | |
| 1415 | - if (!$access_token) return false; | |
| 1416 | - | |
| 1417 | 1092 | $curl_post_fields=array( |
| 1418 | 1093 | 'access_token' => $access_token, |
| 1419 | 1094 | ); |
| 1420 | 1095 | |
| 1421 | 1096 | $current_page= get_current_screen(); |
| 1422 | - $curl_response = $this->wpstream_baker_do_curl_base($url,$curl_post_fields,true); | |
| 1097 | + $curl_response = $this->wpstream_baker_do_curl_base($url,$curl_post_fields); | |
| 1423 | 1098 | $curl_response_decoded = json_decode($curl_response,JSON_OBJECT_AS_ARRAY); |
| 1424 | 1099 | |
| 1425 | 1100 | |
| 1426 | 1101 | |
| @@ -1451,12 +1126,8 @@ | ||
| 1451 | 1126 | $video_name = sanitize_text_field($_POST['video_name']); |
| 1452 | 1127 | |
| 1453 | 1128 | $url = 'video/download'; |
| 1454 | 1129 | $access_token = $this->wpstream_get_token(); |
| 1455 | - | |
| 1456 | - // do not make the call if no token is available | |
| 1457 | - if (!$access_token) return false; | |
| 1458 | - | |
| 1459 | 1130 | $curl_post_fields=array( |
| 1460 | 1131 | 'access_token' => $access_token, |
| 1461 | 1132 | 'name' => $video_name, |
| 1462 | 1133 | ); |
| @@ -1484,17 +1155,13 @@ | ||
| 1484 | 1155 | |
| 1485 | 1156 | |
| 1486 | 1157 | $url = 'video/delete'; |
| 1487 | 1158 | $access_token = $this->wpstream_get_token(); |
| 1488 | - | |
| 1489 | - // do not make the call if no token is available | |
| 1490 | - if (!$access_token) return false; | |
| 1491 | - | |
| 1492 | 1159 | $curl_post_fields=array( |
| 1493 | 1160 | 'access_token' => $access_token, |
| 1494 | 1161 | 'name'=>$video_name, |
| 1495 | 1162 | ); |
| 1496 | - $curl_response = $this->wpstream_baker_do_curl_base($url,$curl_post_fields,true); | |
| 1163 | + $curl_response = $this->wpstream_baker_do_curl_base($url,$curl_post_fields); | |
| 1497 | 1164 | $curl_response_decoded = json_decode($curl_response,JSON_OBJECT_AS_ARRAY); |
| 1498 | 1165 | |
| 1499 | 1166 | |
| 1500 | 1167 | print $curl_response; |
| @@ -1504,15 +1171,12 @@ | ||
| 1504 | 1171 | |
| 1505 | 1172 | } |
| 1506 | 1173 | |
| 1507 | 1174 | |
| 1508 | - public function wpstream_check_pending_videos() { | |
| 1509 | - if (!current_user_can('administrator')) { | |
| 1510 | - wp_send_json_error(__('Unauthorized', 'wpstream')); | |
| 1511 | - } | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1512 | 1178 | |
| 1513 | - $videos_list_raw = $this->wpstream_get_videos_from_api(); | |
| 1514 | - wp_send_json_success($videos_list_raw); | |
| 1515 | - } | |
| 1516 | - | |
| 1517 | - | |
| 1518 | -}// end class | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | +}// end class | |