/**
  * Create a NetDNA or MaxCDN pull zone automatically
  */
 function w3tc_cdn_auto_create_netdna_maxcdn_pull_zone()
 {
     require_once W3TC_LIB_NETDNA_DIR . '/NetDNA.php';
     $cdn_engine = Util_Request::get_string('type');
     $this->validate_cdnengine_is_netdna_maxcdn($cdn_engine);
     $authorization_key = Util_Request::get_string('authorization_key');
     $this->validate_authorization_key($authorization_key);
     $keys = explode('+', $authorization_key);
     list($alias, $consumerkey, $consumersecret) = $keys;
     $url = get_home_url();
     try {
         $api = new \NetDNA($alias, $consumerkey, $consumersecret);
         $disable_cooker_header = $this->_config->get_boolean('browsercache.other.nocookies') || $this->_config->get_boolean('browsercache.cssjs.nocookies');
         $zone = $api->create_default_pull_zone($url, null, null, array('ignore_setcookie_header' => $disable_cooker_header));
         $name = $zone['name'];
         $temporary_url = "{$name}.{$alias}.netdna-cdn.com";
         $test_result = -1;
         if (!$this->_config->get_array("cdn.{$cdn_engine}.domain")) {
             $test_result = $this->test_cdn_url($temporary_url) ? 1 : 0;
             $this->_config->set("cdn.{$cdn_engine}.zone_id", $zone['id']);
             if ($test_result) {
                 $this->_config->set("cdn.enabled", true);
             }
             $this->_config->set("cdn.{$cdn_engine}.domain", array($temporary_url));
         }
         $this->_config->save();
         $state = Dispatcher::config_state();
         $zones = $api->get_pull_zones();
         $zone_count = sizeof($zones);
         Util_Admin::make_track_call(array('type' => 'cdn', 'data' => array('cdn' => $cdn_engine, 'action' => 'zonecreation', 'creation' => 'manual', 'creationtime' => time(), 'signupclick' => $state->get_integer('track.maxcdn_signup'), 'authorizeclick' => $state->get_integer('track.maxcdn_authorize'), 'validationclick' => $state->get_integer('track.maxcdn_validation'), 'total_zones' => $zone_count, 'test' => $test_result)));
         $result = array('result' => 'single', 'cnames' => array($temporary_url));
     } catch (\Exception $ex) {
         $result = array('result' => 'error', 'message' => sprintf(__('Could not create default zone.' . $ex->getMessage(), 'w3-total-cache')));
     }
     echo json_encode($result);
     exit;
 }