/**
  * Create container action
  *
  * @return void
  */
 function w3tc_cdn_create_container()
 {
     $engine = Util_Request::get_string('engine');
     $config = Util_Request::get_array('config');
     $config = array_merge($config, array('debug' => false));
     $result = false;
     $error = __('Incorrect type.', 'w3-total-cache');
     $container_id = '';
     switch ($engine) {
         case 's3':
         case 'cf':
         case 'cf2':
         case 'azure':
             $result = true;
             break;
     }
     if ($result) {
         $w3_cdn = CdnEngine::instance($engine, $config);
         @set_time_limit($this->_config->get_integer('timelimit.cdn_container_create'));
         if ($w3_cdn->create_container($container_id, $error)) {
             $result = true;
             $error = __('Created successfully.', 'w3-total-cache');
         } else {
             $result = false;
             $error = sprintf(__('Error: %s', 'w3-total-cache'), $error);
         }
     }
     $response = array('result' => $result, 'error' => $error, 'container_id' => $container_id);
     echo json_encode($response);
 }
示例#2
0
 /**
  * Returns CDN object
  */
 function get_cdn()
 {
     static $cdn = array();
     if (!isset($cdn[0])) {
         $engine = $this->_config->get_string('cdn.engine');
         $compression = $this->_config->get_boolean('browsercache.enabled') && $this->_config->get_boolean('browsercache.html.compression');
         switch ($engine) {
             case 'akamai':
                 $engine_config = array('username' => $this->_config->get_string('cdn.akamai.username'), 'password' => $this->_config->get_string('cdn.akamai.password'), 'zone' => $this->_config->get_string('cdn.akamai.zone'), 'domain' => $this->_config->get_array('cdn.akamai.domain'), 'ssl' => $this->_config->get_string('cdn.akamai.ssl'), 'email_notification' => $this->_config->get_array('cdn.akamai.email_notification'), 'compression' => false);
                 break;
             case 'att':
                 $engine_config = array('account' => $this->_config->get_string('cdn.att.account'), 'token' => $this->_config->get_string('cdn.att.token'), 'domain' => $this->_config->get_array('cdn.att.domain'), 'ssl' => $this->_config->get_string('cdn.att.ssl'), 'compression' => false);
                 break;
             case 'azure':
                 $engine_config = array('user' => $this->_config->get_string('cdn.azure.user'), 'key' => $this->_config->get_string('cdn.azure.key'), 'container' => $this->_config->get_string('cdn.azure.container'), 'cname' => $this->_config->get_array('cdn.azure.cname'), 'ssl' => $this->_config->get_string('cdn.azure.ssl'), 'compression' => $compression);
                 break;
             case 'cf':
                 $engine_config = array('key' => $this->_config->get_string('cdn.cf.key'), 'secret' => $this->_config->get_string('cdn.cf.secret'), 'bucket' => $this->_config->get_string('cdn.cf.bucket'), 'id' => $this->_config->get_string('cdn.cf.id'), 'cname' => $this->_config->get_array('cdn.cf.cname'), 'ssl' => $this->_config->get_string('cdn.cf.ssl'), 'compression' => $compression);
                 break;
             case 'cf2':
                 $engine_config = array('key' => $this->_config->get_string('cdn.cf2.key'), 'secret' => $this->_config->get_string('cdn.cf2.secret'), 'id' => $this->_config->get_string('cdn.cf2.id'), 'cname' => $this->_config->get_array('cdn.cf2.cname'), 'ssl' => $this->_config->get_string('cdn.cf2.ssl'), 'compression' => false);
                 break;
             case 'cotendo':
                 $engine_config = array('username' => $this->_config->get_string('cdn.cotendo.username'), 'password' => $this->_config->get_string('cdn.cotendo.password'), 'zones' => $this->_config->get_array('cdn.cotendo.zones'), 'domain' => $this->_config->get_array('cdn.cotendo.domain'), 'ssl' => $this->_config->get_string('cdn.cotendo.ssl'), 'compression' => false);
                 break;
             case 'edgecast':
                 $engine_config = array('account' => $this->_config->get_string('cdn.edgecast.account'), 'token' => $this->_config->get_string('cdn.edgecast.token'), 'domain' => $this->_config->get_array('cdn.edgecast.domain'), 'ssl' => $this->_config->get_string('cdn.edgecast.ssl'), 'compression' => false);
                 break;
             case 'ftp':
                 $engine_config = array('host' => $this->_config->get_string('cdn.ftp.host'), 'type' => $this->_config->get_string('cdn.ftp.type'), 'user' => $this->_config->get_string('cdn.ftp.user'), 'pass' => $this->_config->get_string('cdn.ftp.pass'), 'path' => $this->_config->get_string('cdn.ftp.path'), 'pasv' => $this->_config->get_boolean('cdn.ftp.pasv'), 'domain' => $this->_config->get_array('cdn.ftp.domain'), 'ssl' => $this->_config->get_string('cdn.ftp.ssl'), 'compression' => false, 'docroot' => Util_Environment::document_root());
                 break;
             case 'google_drive':
                 $state = Dispatcher::config_state();
                 $engine_config = array('client_id' => $this->_config->get_string('cdn.google_drive.client_id'), 'access_token' => $state->get_string('cdn.google_drive.access_token'), 'refresh_token' => $this->_config->get_string('cdn.google_drive.refresh_token'), 'root_url' => $this->_config->get_string('cdn.google_drive.folder.url'), 'root_folder_id' => $this->_config->get_string('cdn.google_drive.folder.id'), 'new_access_token_callback' => array($this, 'on_google_drive_new_access_token'));
                 break;
             case 'highwinds':
                 $state = Dispatcher::config_state();
                 $engine_config = array('domains' => $this->_config->get_array('cdn.highwinds.host.domains'), 'ssl' => $this->_config->get_string('cdn.highwinds.ssl'), 'api_token' => $this->_config->get_string('cdn.highwinds.api_token'), 'account_hash' => $this->_config->get_string('cdn.highwinds.account_hash'), 'host_hash_code' => $this->_config->get_string('cdn.highwinds.host.hash_code'));
                 break;
             case 'maxcdn':
                 $engine_config = array('authorization_key' => $this->_config->get_string('cdn.maxcdn.authorization_key'), 'zone_id' => $this->_config->get_integer('cdn.maxcdn.zone_id'), 'domain' => $this->_config->get_array('cdn.maxcdn.domain'), 'ssl' => $this->_config->get_string('cdn.maxcdn.ssl'), 'compression' => false);
                 break;
             case 'mirror':
                 $engine_config = array('domain' => $this->_config->get_array('cdn.mirror.domain'), 'ssl' => $this->_config->get_string('cdn.mirror.ssl'), 'compression' => false);
                 break;
             case 'netdna':
                 $engine_config = array('authorization_key' => $this->_config->get_string('cdn.netdna.authorization_key'), 'zone_id' => $this->_config->get_integer('cdn.netdna.zone_id'), 'domain' => $this->_config->get_array('cdn.netdna.domain'), 'ssl' => $this->_config->get_string('cdn.netdna.ssl'), 'compression' => false);
                 break;
             case 'rackspace_cdn':
                 $state = Dispatcher::config_state();
                 $engine_config = array('user_name' => $this->_config->get_string('cdn.rackspace_cdn.user_name'), 'api_key' => $this->_config->get_string('cdn.rackspace_cdn.api_key'), 'region' => $this->_config->get_string('cdn.rackspace_cdn.region'), 'service_access_url' => $this->_config->get_string('cdn.rackspace_cdn.service.access_url'), 'service_id' => $this->_config->get_string('cdn.rackspace_cdn.service.id'), 'service_protocol' => $this->_config->get_string('cdn.rackspace_cdn.service.protocol'), 'domains' => $this->_config->get_array('cdn.rackspace_cdn.domains'), 'access_state' => $state->get_string('cdn.rackspace_cdn.access_state'), 'new_access_state_callback' => array($this, 'on_rackspace_cdn_new_access_state'));
                 break;
             case 'rscf':
                 $state = Dispatcher::config_state();
                 $engine_config = array('user_name' => $this->_config->get_string('cdn.rscf.user'), 'api_key' => $this->_config->get_string('cdn.rscf.key'), 'region' => $this->_config->get_string('cdn.rscf.location'), 'container' => $this->_config->get_string('cdn.rscf.container'), 'cname' => $this->_config->get_array('cdn.rscf.cname'), 'ssl' => $this->_config->get_string('cdn.rscf.ssl'), 'compression' => false, 'access_state' => $state->get_string('cdn.rackspace_cf.access_state'), 'new_access_state_callback' => array($this, 'on_rackspace_cf_new_access_state'));
                 break;
             case 's3':
                 $engine_config = array('key' => $this->_config->get_string('cdn.s3.key'), 'secret' => $this->_config->get_string('cdn.s3.secret'), 'bucket' => $this->_config->get_string('cdn.s3.bucket'), 'cname' => $this->_config->get_array('cdn.s3.cname'), 'ssl' => $this->_config->get_string('cdn.s3.ssl'), 'compression' => $compression);
                 break;
             case 's3_compatible':
                 $engine_config = array('key' => $this->_config->get_string('cdn.s3.key'), 'secret' => $this->_config->get_string('cdn.s3.secret'), 'bucket' => $this->_config->get_string('cdn.s3.bucket'), 'cname' => $this->_config->get_array('cdn.s3.cname'), 'ssl' => $this->_config->get_string('cdn.s3.ssl'), 'compression' => $compression, 'api_host' => $this->_config->get_string('cdn.s3_compatible.api_host'));
                 break;
         }
         $engine_config = array_merge($engine_config, array('debug' => $this->_config->get_boolean('cdn.debug')));
         $cdn[0] = CdnEngine::instance($engine, $engine_config);
         /**
          * Set cache config for CDN
          */
         if ($this->_config->get_boolean('browsercache.enabled')) {
             $w3_plugin_browsercache = Dispatcher::component('BrowserCache_Plugin');
             $cdn[0]->cache_config = $w3_plugin_browsercache->get_cache_config();
         }
     }
     return $cdn[0];
 }