public function w3tc_ajax_cdn_rackspace_intro_done()
 {
     $user_name = $_REQUEST['user_name'];
     $api_key = $_REQUEST['api_key'];
     try {
         $r = Cdn_RackSpace_Api_Tokens::authenticate($user_name, $api_key);
     } catch (\Exception $ex) {
         $details = array('user_name' => $user_name, 'api_key' => $api_key, 'error_message' => 'Can\'t authenticate: ' . $ex->getMessage());
         include W3TC_DIR . '/Cdn_RackSpaceCloudFiles_Popup_View_Intro.php';
         exit;
     }
     $r['regions'] = Cdn_RackSpace_Api_Tokens::cloudfiles_services_by_region($r['services']);
     $details = array('user_name' => $user_name, 'api_key' => $api_key, 'access_token' => $r['access_token'], 'region_descriptors' => $r['regions'], 'region_descriptors_serialized' => strtr(json_encode($r['regions']), '"\\', '!^'));
     include W3TC_DIR . '/Cdn_RackSpaceCloudFiles_Popup_View_Regions.php';
     exit;
 }
 /**
  * Called when new access token issued by api objects
  */
 public function _on_new_access_requested_api()
 {
     $r = Cdn_RackSpace_Api_Tokens::authenticate($this->_config['user_name'], $this->_config['api_key']);
     if (!isset($r['access_token']) || !isset($r['services'])) {
         throw new \Exception('Authentication failed');
     }
     $r['regions'] = Cdn_RackSpace_Api_Tokens::cdn_services_by_region($r['services']);
     if (!isset($r['regions'][$this->_config['region']])) {
         throw new \Exception('Region ' . $this->_config['region'] . ' not found');
     }
     $this->_access_state['access_token'] = $r['access_token'];
     $this->_access_state['access_region_descriptor'] = $r['regions'][$this->_config['region']];
     $this->_create_api(array($this, '_on_new_access_requested_second_time'));
     if (!empty($this->_new_access_state_callback)) {
         call_user_func($this->_new_access_state_callback, json_encode($this->_access_state));
     }
     return $this->_api;
 }
 private function _on_new_access_requested()
 {
     $r = Cdn_RackSpace_Api_Tokens::authenticate($this->_config['user_name'], $this->_config['api_key']);
     if (!isset($r['access_token']) || !isset($r['services'])) {
         throw new \Exception('Authentication failed');
     }
     $r['regions'] = Cdn_RackSpace_Api_Tokens::cloudfiles_services_by_region($r['services']);
     if (!isset($r['regions'][$this->_config['region']])) {
         throw new \Exception('Region ' . $this->_config['region'] . ' not found');
     }
     $this->_access_state['access_token'] = $r['access_token'];
     $this->_access_state['access_region_descriptor'] = $r['regions'][$this->_config['region']];
     $this->_create_api(array($this, '_on_new_access_requested_second_time'), array($this, '_on_new_access_requested_second_time'));
     $c = $this->_api_cdn->container_get($this->_config['container']);
     $this->_access_state['host_http'] = substr($c['x-cdn-uri'], 7);
     $this->_access_state['host_https'] = substr($c['x-cdn-ssl-uri'], 8);
     call_user_func($this->_new_access_state_callback, json_encode($this->_access_state));
 }
 private function _render_cdn_rackspace_regions($details)
 {
     $user_name = $details['user_name'];
     $api_key = $details['api_key'];
     try {
         $r = Cdn_RackSpace_Api_Tokens::authenticate($user_name, $api_key);
     } catch (\Exception $ex) {
         $details = array('user_name' => $user_name, 'api_key' => $api_key, 'error_message' => 'Can\'t authenticate: ' . $ex->getMessage());
         include W3TC_DIR . '/Cdn_RackSpaceCdn_Popup_View_Intro.php';
         exit;
     }
     $r['regions'] = Cdn_RackSpace_Api_Tokens::cdn_services_by_region($r['services']);
     $details['access_token'] = $r['access_token'];
     $details['region_descriptors'] = $r['regions'];
     // avoid fights with quotes, magic_quotes may break randomly
     $details['region_descriptors_serialized'] = strtr(json_encode($r['regions']), '"\\', '!^');
     include W3TC_DIR . '/Cdn_RackSpaceCdn_Popup_View_Regions.php';
     exit;
 }