/**
  * Returns CDN object
  *
  * @return W3_Cdn_Base
  */
 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 'ftp':
                 $engine_config = array('host' => $this->_config->get_string('cdn.ftp.host'), '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' => w3_get_document_root());
                 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 '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 'rscf':
                 $engine_config = array('user' => $this->_config->get_string('cdn.rscf.user'), 'key' => $this->_config->get_string('cdn.rscf.key'), 'location' => $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);
                 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 'mirror':
                 $engine_config = array('domain' => $this->_config->get_array('cdn.mirror.domain'), 'ssl' => $this->_config->get_string('cdn.mirror.ssl'), 'compression' => false);
                 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 '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 '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 '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 '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;
         }
         $engine_config = array_merge($engine_config, array('debug' => $this->_config->get_boolean('cdn.debug')));
         w3_require_once(W3TC_LIB_W3_DIR . '/Cdn.php');
         $cdn[0] = W3_Cdn::instance($engine, $engine_config);
         /**
          * Set cache config for CDN
          */
         if ($this->_config->get_boolean('browsercache.enabled')) {
             $w3_plugin_browsercache = w3_instance('W3_Plugin_BrowserCache');
             $cdn[0]->cache_config = $w3_plugin_browsercache->get_cache_config();
         }
     }
     return $cdn[0];
 }
 /**
  * Create container action
  *
  * @return void
  */
 function action_cdn_create_container()
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     w3_require_once(W3TC_LIB_W3_DIR . '/Cdn.php');
     $engine = W3_Request::get_string('engine');
     $config = W3_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 'rscf':
         case 'azure':
             $result = true;
             break;
     }
     if ($result) {
         $w3_cdn = W3_Cdn::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);
 }
Exemple #3
0
 /**
  * Returns CDN object
  *
  * @return W3_Cdn_Base
  */
 function &get_cdn()
 {
     static $cdn = array();
     if (!isset($cdn[0])) {
         $engine = $this->_config->get_string('cdn.engine');
         $engine_config = array();
         switch ($engine) {
             case 'mirror':
                 $engine_config = array('domain' => $this->_config->get_string('cdn.mirror.domain'));
                 break;
             case 'ftp':
                 $engine_config = array('host' => $this->_config->get_string('cdn.ftp.host'), '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_string('cdn.ftp.domain'));
                 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'));
                 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_string('cdn.cf.cname'));
                 break;
         }
         require_once W3TC_LIB_W3_DIR . '/Cdn.php';
         $cdn[0] =& W3_Cdn::instance($engine, $engine_config);
     }
     return $cdn[0];
 }
Exemple #4
0
 /**
  * Returns CDN object
  *
  * @return W3_Cdn_Base
  */
 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 '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('apiid' => $this->_config->get_string('cdn.netdna.apiid'), 'apikey' => $this->_config->get_string('cdn.netdna.apikey'), 'domain' => $this->_config->get_array('cdn.netdna.domain'), 'ssl' => $this->_config->get_string('cdn.netdna.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 'ftp':
                 $engine_config = array('host' => $this->_config->get_string('cdn.ftp.host'), 'port' => $this->_config->get_integer('cdn.ftp.port'), '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);
                 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 '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 'rscf':
                 $engine_config = array('user' => $this->_config->get_string('cdn.rscf.user'), 'key' => $this->_config->get_string('cdn.rscf.key'), 'location' => $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);
                 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;
         }
         $engine_config = array_merge($engine_config, array('debug' => $this->_config->get_boolean('cdn.debug')));
         require_once W3TC_LIB_W3_DIR . '/Cdn.php';
         $cdn[0] =& W3_Cdn::instance($engine, $engine_config);
         /**
          * Set cache config for CDN
          */
         if ($this->_config->get_boolean('browsercache.enabled')) {
             require_once W3TC_LIB_W3_DIR . '/Plugin/BrowserCache.php';
             $w3_plugin_browsercache =& W3_Plugin_BrowserCache::instance();
             $cdn[0]->cache_config = $w3_plugin_browsercache->get_cache_config();
         }
     }
     return $cdn[0];
 }
Exemple #5
0
 /**
  * Create bucket action
  */
 function cdn_create_bucket()
 {
     require_once W3TC_LIB_W3_DIR . '/Request.php';
     require_once W3TC_LIB_W3_DIR . '/Cdn.php';
     $type = W3_Request::get_string('type');
     $key = W3_Request::get_string('key');
     $secret = W3_Request::get_string('secret');
     $bucket = W3_Request::get_string('bucket');
     switch ($type) {
         case 's3':
         case 'cf':
             $result = true;
             break;
         default:
             $result = false;
             $error = 'Incorrect type.';
             break;
     }
     if ($result) {
         $w3_cdn_s3 =& W3_Cdn::instance($type, array('key' => $key, 'secret' => $secret, 'bucket' => $bucket));
         $error = null;
         if ($w3_cdn_s3->create_bucket($error)) {
             $result = true;
             $error = 'Bucket has been successfully created.';
         } else {
             $result = false;
             $error = sprintf('Error: %s', $error);
         }
         echo sprintf('{result: %d, error: "%s"}', $result, addslashes($error));
     }
 }