/** * Create a NetDNA or MaxCDN pull zone automatically */ function action_cdn_auto_create_netdna_maxcdn_pull_zone() { w3_require_once(W3TC_LIB_NETDNA_DIR . '/NetDNA.php'); w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/admin.php'); $cdn_engine = W3_Request::get_string('type'); $this->validate_cdnengine_is_netdna_maxcdn($cdn_engine); $authorization_key = W3_Request::get_string('authorization_key'); $this->validate_authorization_key($authorization_key); $keys = explode('+', $authorization_key); list($alias, $consumerkey, $consumersecret) = $keys; $url = w3_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(); $config_admin = w3_instance('W3_ConfigAdmin'); $zones = $api->get_pull_zones(); $zone_count = sizeof($zones); w3tc_make_track_call(array('type' => 'cdn', 'data' => array('cdn' => $cdn_engine, 'action' => 'zonecreation', 'creation' => 'manual', 'creationtime' => time(), 'signupclick' => $config_admin->get_integer('track.maxcdn_signup'), 'authorizeclick' => $config_admin->get_integer('track.maxcdn_authorize'), 'validationclick' => $config_admin->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; }