Exemplo n.º 1
0
 /**
  * Create NetDNA/MaxCDN pullzone
  */
 function action_cdn_create_netdna_maxcdn_pull_zone()
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $type = W3_Request::get_string('type');
     $name = W3_Request::get_string('name');
     $label = W3_Request::get_string('label');
     w3_require_once(W3TC_LIB_NETDNA_DIR . '/NetDNA.php');
     $cdn_engine = $this->_config->get_string('cdn.engine');
     $authorization_key = $this->_config->get_string("cdn.{$cdn_engine}.authorization_key");
     $alias = $consumerkey = $consumersecret = '';
     if ($authorization_key) {
         $keys = explode('+', $authorization_key);
         if (sizeof($keys) == 3) {
             list($alias, $consumerkey, $consumersecret) = $keys;
         }
     }
     $api = new NetDNA($alias, $consumerkey, $consumersecret);
     $url = w3_get_home_url();
     $zone = array();
     $zone['name'] = $name;
     $zone['label'] = $label;
     $zone['url'] = $url;
     try {
         $response = $api->create_pull_zone($zone);
         try {
             $this->_config->set('cdn.enabled', true);
             if (!$this->_config->get_array("cdn.{$cdn_engine}.domain")) {
                 $this->_config->set("cdn.{$cdn_engine}.domain", array("{$name}.{$alias}.netdna-cdn.com"));
             }
             $this->_config->save();
         } catch (Exception $ex) {
         }
         echo json_encode(array('status' => 'success', 'message' => 'Pull Zone created.', 'temporary_url' => "{$name}.{$alias}.netdna-cdn.com", 'data' => $response));
     } catch (Exception $ex) {
         echo json_encode(array('status' => 'error', 'message' => $ex->getMessage()));
     }
 }
Exemplo n.º 2
0
 /**
  * Create NetDNA/MaxCDN pullzone
  */
 function action_cdn_create_netdna_maxcdn_pull_zone()
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/admin.php');
     w3_require_once(W3TC_LIB_NETDNA_DIR . '/NetDNA.php');
     $type = W3_Request::get_string('type');
     $name = W3_Request::get_string('name');
     $label = W3_Request::get_string('label');
     $cdn_engine = $type;
     $authorization_key = $this->_config->get_string("cdn.{$cdn_engine}.authorization_key");
     $alias = $consumerkey = $consumersecret = '';
     if ($authorization_key) {
         $keys = explode('+', $authorization_key);
         if (sizeof($keys) == 3) {
             list($alias, $consumerkey, $consumersecret) = $keys;
         }
     }
     $api = new NetDNA($alias, $consumerkey, $consumersecret);
     $url = w3_get_home_url();
     $zone = array();
     $zone['name'] = $name;
     $zone['label'] = $label;
     $zone['url'] = $url;
     $zone['use_stale'] = 1;
     $zone['queries'] = 1;
     $zone['compress'] = 1;
     $zone['backend_compress'] = 1;
     try {
         $response = $api->create_pull_zone($zone);
         try {
             $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}.domain", array($temporary_url));
                 if ($test_result) {
                     $this->_config->set("cdn.enabled", true);
                 }
             }
             $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' => $type, '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)));
         } catch (Exception $ex) {
         }
         echo json_encode(array('status' => 'success', 'message' => 'Pull Zone created.', 'temporary_url' => "{$name}.{$alias}.netdna-cdn.com", 'data' => $response));
     } catch (Exception $ex) {
         echo json_encode(array('status' => 'error', 'message' => $ex->getMessage()));
     }
 }