Пример #1
0
 /**
  * New Relic tab
  */
 function view()
 {
     $applications = array();
     $dashboard = '';
     /**
      * @var $nerser W3_NewRelicService
      */
     $nerser = w3_instance('W3_NewRelicService');
     $new_relic_configured = $this->_config->get_string('newrelic.account_id') && $this->_config->get_string('newrelic.api_key') && $this->_config->get_string('newrelic.application_id');
     $view_application = $this->_config->get_string('newrelic.application_id');
     $new_relic_enabled = $this->_config->get_boolean('newrelic.enabled');
     $verify_running = $nerser->verify_running();
     $application_settings = array();
     if (!is_array($verify_running)) {
         try {
             $application_settings = $nerser->get_application_settings();
         } catch (Exception $ex) {
             $application_settings = array();
         }
     }
     if ($view_metric = W3_Request::get_boolean('view_metric', false)) {
         $metric_names = $nerser->get_metric_names(W3_Request::get_string('regex', ''));
     }
     include W3TC_INC_DIR . '/options/new_relic.php';
 }
 /**
  * Support tab
  *
  * @return void
  */
 function view()
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $request_type = W3_Request::get_string('request_type');
     $payment = W3_Request::get_boolean('payment');
     include W3TC_INC_DIR . '/options/support.php';
 }
Пример #3
0
 /**
  * PageSpeed widget
  *
  * @return void
  */
 function widget_pagespeed()
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/PageSpeed.php');
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $key = $this->_config->get_string('widget.pagespeed.key');
     $force = W3_Request::get_boolean('w3tc_widget_pagespeed_force');
     $results = null;
     if ($key) {
         $w3_pagespeed = new W3_PageSpeed();
         $results = $w3_pagespeed->analyze(w3_get_home_url(), $force);
     }
     include W3TC_INC_DIR . '/widget/pagespeed.php';
 }
 /**
  * Reads config from request
  */
 function read_request()
 {
     require_once W3TC_LIB_W3_DIR . '/Request.php';
     $request = W3_Request::get_request();
     foreach ($this->_keys as $key => $type) {
         $request_key = str_replace('.', '_', $key);
         if (!isset($request[$request_key])) {
             continue;
         }
         switch ($type) {
             case 'string':
                 $this->set($key, W3_Request::get_string($request_key));
                 break;
             case 'int':
             case 'integer':
                 $this->set($key, W3_Request::get_integer($request_key));
                 break;
             case 'float':
             case 'double':
                 $this->set($key, W3_Request::get_double($request_key));
                 break;
             case 'bool':
             case 'boolean':
                 $this->set($key, W3_Request::get_boolean($request_key));
                 break;
             case 'array':
                 $this->set($key, W3_Request::get_array($request_key));
                 break;
         }
     }
 }
Пример #5
0
 /**
  * Send support request action
  *
  * @return void
  */
 function action_support_request()
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $request_type = W3_Request::get_string('request_type');
     $payment = W3_Request::get_boolean('payment');
     $request_id = W3_Request::get_string('request_id');
     $url = W3_Request::get_string('url');
     $name = W3_Request::get_string('name');
     $email = W3_Request::get_string('email');
     $twitter = W3_Request::get_string('twitter');
     $phone = W3_Request::get_string('phone');
     $subject = W3_Request::get_string('subject');
     $description = W3_Request::get_string('description');
     $templates = W3_Request::get_array('templates');
     $forum_url = W3_Request::get_string('forum_url');
     $wp_login = W3_Request::get_string('wp_login');
     $wp_password = W3_Request::get_string('wp_password');
     $ftp_host = W3_Request::get_string('ftp_host');
     $ftp_login = W3_Request::get_string('ftp_login');
     $ftp_password = W3_Request::get_string('ftp_password');
     $subscribe_releases = W3_Request::get_string('subscribe_releases');
     $subscribe_customer = W3_Request::get_string('subscribe_customer');
     $params = array('request_type' => $request_type, 'payment' => $payment, 'url' => $url, 'name' => $name, 'email' => $email, 'twitter' => $twitter, 'phone' => $phone, 'subject' => $subject, 'description' => $description, 'forum_url' => $forum_url, 'wp_login' => $wp_login, 'wp_password' => $wp_password, 'ftp_host' => $ftp_host, 'ftp_login' => $ftp_login, 'ftp_password' => $ftp_password, 'subscribe_releases' => $subscribe_releases, 'subscribe_customer' => $subscribe_customer);
     $post = $params;
     foreach ($templates as $template_index => $template) {
         $template_key = sprintf('templates[%d]', $template_index);
         $params[$template_key] = $template;
     }
     if (!isset($this->_request_types[$request_type])) {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_type')), false);
     }
     $required = array('bug_report' => 'url,name,email,subject,description', 'new_feature' => 'url,name,email,subject,description', 'email_support' => 'url,name,email,subject,description', 'phone_support' => 'url,name,email,subject,description,phone', 'plugin_config' => 'url,name,email,subject,description,wp_login,wp_password', 'theme_config' => 'url,name,email,subject,description,wp_login,wp_password,ftp_host,ftp_login,ftp_password', 'linux_config' => 'url,name,email,subject,description,wp_login,wp_password,ftp_host,ftp_login,ftp_password');
     if (strstr($required[$request_type], 'url') !== false && $url == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_url')), false);
     }
     if (strstr($required[$request_type], 'name') !== false && $name == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_name')), false);
     }
     if (strstr($required[$request_type], 'email') !== false && !preg_match('~^[a-z0-9_\\-\\.]+@[a-z0-9-\\.]+\\.[a-z]{2,5}$~', $email)) {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_email')), false);
     }
     if (strstr($required[$request_type], 'phone') !== false && !preg_match('~^[0-9\\-\\.\\ \\(\\)\\+]+$~', $phone)) {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_phone')), false);
     }
     if (strstr($required[$request_type], 'subject') !== false && $subject == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_subject')), false);
     }
     if (strstr($required[$request_type], 'description') !== false && $description == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_description')), false);
     }
     if (strstr($required[$request_type], 'wp_login') !== false && $wp_login == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_wp_login')), false);
     }
     if (strstr($required[$request_type], 'wp_password') !== false && $wp_password == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_wp_password')), false);
     }
     if (strstr($required[$request_type], 'ftp_host') !== false && $ftp_host == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_ftp_host')), false);
     }
     if (strstr($required[$request_type], 'ftp_login') !== false && $ftp_login == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_ftp_login')), false);
     }
     if (strstr($required[$request_type], 'ftp_password') !== false && $ftp_password == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_ftp_password')), false);
     }
     /**
      * Add attachments
      */
     $attachments = array();
     $attach_files = array(w3_get_wp_config_path(), w3_cache_blog_dir('log') . '/minify.log', w3_get_pgcache_rules_core_path(), w3_get_pgcache_rules_cache_path(), w3_get_browsercache_rules_cache_path(), w3_get_browsercache_rules_no404wp_path(), w3_get_minify_rules_core_path(), w3_get_minify_rules_cache_path());
     /**
      * Attach config files
      */
     if ($handle = opendir(W3TC_CONFIG_DIR)) {
         while (($entry = @readdir($handle)) !== false) {
             if ($entry == '.' || $entry == '..' || $entry == 'index.html') {
                 continue;
             }
             $attachments[] = W3TC_CONFIG_DIR . '/' . $entry;
         }
         closedir($handle);
     }
     foreach ($attach_files as $attach_file) {
         if ($attach_file && file_exists($attach_file) && !in_array($attach_file, $attachments)) {
             $attachments[] = $attach_file;
         }
     }
     /**
      * Attach server info
      */
     $server_info = print_r($this->get_server_info(), true);
     $server_info = str_replace("\n", "\r\n", $server_info);
     $server_info_path = W3TC_CACHE_TMP_DIR . '/server_info.txt';
     if (@file_put_contents($server_info_path, $server_info)) {
         $attachments[] = $server_info_path;
     }
     /**
      * Attach phpinfo
      */
     ob_start();
     phpinfo();
     $php_info = ob_get_contents();
     ob_end_clean();
     $php_info_path = W3TC_CACHE_TMP_DIR . '/php_info.html';
     if (@file_put_contents($php_info_path, $php_info)) {
         $attachments[] = $php_info_path;
     }
     /**
      * Attach self-test
      */
     ob_start();
     $this->action_self_test();
     $self_test = ob_get_contents();
     ob_end_clean();
     $self_test_path = W3TC_CACHE_TMP_DIR . '/self_test.html';
     if (@file_put_contents($self_test_path, $self_test)) {
         $attachments[] = $self_test_path;
     }
     /**
      * Attach templates
      */
     foreach ($templates as $template) {
         if (!empty($template)) {
             $attachments[] = $template;
         }
     }
     /**
      * Attach other files
      */
     if (!empty($_FILES['files'])) {
         $files = (array) $_FILES['files'];
         for ($i = 0, $l = count($files); $i < $l; $i++) {
             if (isset($files['tmp_name'][$i]) && isset($files['name'][$i]) && isset($files['error'][$i]) && $files['error'][$i] == UPLOAD_ERR_OK) {
                 $path = W3TC_CACHE_TMP_DIR . '/' . $files['name'][$i];
                 if (@move_uploaded_file($files['tmp_name'][$i], $path)) {
                     $attachments[] = $path;
                 }
             }
         }
     }
     $data = array();
     if (!empty($wp_login) && !empty($wp_password)) {
         $data['WP Admin login'] = $wp_login;
         $data['WP Admin password'] = $wp_password;
     }
     if (!empty($ftp_host) && !empty($ftp_login) && !empty($ftp_password)) {
         $data['SSH / FTP host'] = $ftp_host;
         $data['SSH / FTP login'] = $ftp_login;
         $data['SSH / FTP password'] = $ftp_password;
     }
     /**
      * Store request data for future access
      */
     if (count($data)) {
         $hash = md5(microtime());
         $request_data = get_option('w3tc_request_data', array());
         $request_data[$hash] = $data;
         update_option('w3tc_request_data', $request_data);
         $request_data_url = sprintf('%s/w3tc_request_data/%s', w3_get_home_url(), $hash);
     } else {
         $request_data_url = '';
     }
     $nonce = wp_create_nonce('w3tc_support_request');
     if (is_network_admin()) {
         update_site_option('w3tc_support_request', $nonce);
     } else {
         update_option('w3tc_support_request', $nonce);
     }
     $file_access = WP_PLUGIN_URL . '/' . dirname(W3TC_FILE) . '/pub/files.php';
     if (w3_get_domain(w3_get_home_url()) != w3_get_domain(w3_get_site_url())) {
         $file_access = str_replace(w3_get_domain(w3_get_home_url()), w3_get_domain(w3_get_site_url()), $file_access);
     }
     $post['file_access'] = $file_access;
     $post['nonce'] = $nonce;
     $post['request_data_url'] = $request_data_url;
     $post['ip'] = $_SERVER['REMOTE_ADDR'];
     $post['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
     $post['version'] = W3TC_VERSION;
     $post['plugin'] = 'W3 Total Cache';
     $post['request_id'] = $request_id;
     $license_level = 'community';
     if (w3_is_pro($this->_config)) {
         $license_level = 'pro';
     } elseif (w3_is_enterprise($this->_config)) {
         $license_level = 'enterprise';
     }
     $post['license_level'] = $license_level;
     $unset = array('wp_login', 'wp_password', 'ftp_host', 'ftp_login', 'ftp_password');
     foreach ($unset as $key) {
         unset($post[$key]);
     }
     foreach ($attachments as $attachment) {
         if (is_network_admin()) {
             update_site_option('attachment_' . md5($attachment), $attachment);
         } else {
             update_option('attachment_' . md5($attachment), $attachment);
         }
     }
     $post = array_merge($post, array('files' => $attachments));
     if (defined('W3_SUPPORT_DEBUG') && W3_SUPPORT_DEBUG) {
         $data = sprintf("[%s] Post support request\n", date('r'));
         foreach ($post as $key => $value) {
             $data .= sprintf("%s => %s\n", $key, is_array($value) ? implode(',', $value) : $value);
         }
         $filename = w3_cache_blog_dir('log') . '/support.log';
         if (!is_dir(dirname($filename))) {
             w3_mkdir_from(dirname($filename), W3TC_CACHE_DIR);
         }
         @file_put_contents($filename, $data, FILE_APPEND);
     }
     $response = wp_remote_post(W3TC_SUPPORT_REQUEST_URL, array('body' => $post, 'timeout' => $this->_config->get_integer('timelimit.email_send')));
     if (defined('W3_SUPPORT_DEBUG') && W3_SUPPORT_DEBUG) {
         $filename = w3_cache_blog_dir('log') . '/support.log';
         $data = sprintf("[%s] Post response \n%s\n", date('r'), print_r($response, true));
         @file_put_contents($filename, $data, FILE_APPEND);
     }
     if (!is_wp_error($response)) {
         $result = $response['response']['code'] == 200 && $response['body'] == 'Ok';
     } else {
         $result = false;
     }
     /**
      * Remove temporary files
      */
     foreach ($attachments as $attachment) {
         if (strstr($attachment, W3TC_CACHE_TMP_DIR) !== false) {
             @unlink($attachment);
         }
         if (is_network_admin()) {
             delete_site_option('attachment_' . md5($attachment));
         } else {
             delete_option('attachment_' . md5($attachment));
         }
     }
     if (is_network_admin()) {
         delete_site_option('w3tc_support_request');
     } else {
         delete_option('w3tc_support_request');
     }
     if ($result) {
         w3_admin_redirect(array('tab' => 'general', 'w3tc_note' => 'support_request'), false);
     } else {
         w3_admin_redirect(array_merge($params, array('request_type' => $request_type, 'w3tc_error' => 'support_request')), false);
     }
 }
Пример #6
0
 /**
  * Init action
  *
  * @return void
  */
 function init()
 {
     // Load plugin text domain
     load_plugin_textdomain(W3TC_TEXT_DOMAIN, null, plugin_basename(W3TC_DIR) . '/languages/');
     if (is_multisite()) {
         global $w3_current_blog_id, $current_blog;
         if ($w3_current_blog_id != $current_blog->blog_id && !isset($GLOBALS['w3tc_blogmap_register_new_item'])) {
             $url = w3_get_host() . $_SERVER['REQUEST_URI'];
             $pos = strpos($url, '?');
             if ($pos !== false) {
                 $url = substr($url, 0, $pos);
             }
             $GLOBALS['w3tc_blogmap_register_new_item'] = $url;
         }
     }
     if (isset($GLOBALS['w3tc_blogmap_register_new_item'])) {
         $do_redirect = false;
         // true value is a sign to just generate config cache
         if ($GLOBALS['w3tc_blogmap_register_new_item'] != 'cache_options') {
             if (w3_is_subdomain_install()) {
                 $blog_home_url = $GLOBALS['w3tc_blogmap_register_new_item'];
             } else {
                 $home_url = rtrim(get_home_url(), '/');
                 if (substr($home_url, 0, 7) == 'http://') {
                     $home_url = substr($home_url, 7);
                 } else {
                     if (substr($home_url, 0, 8) == 'https://') {
                         $home_url = substr($home_url, 8);
                     }
                 }
                 if (substr($GLOBALS['w3tc_blogmap_register_new_item'], 0, strlen($home_url)) == $home_url) {
                     $blog_home_url = $home_url;
                 } else {
                     $blog_home_url = $GLOBALS['w3tc_blogmap_register_new_item'];
                 }
             }
             w3_require_once(W3TC_INC_DIR . '/functions/multisite.php');
             $do_redirect = w3_blogmap_register_new_item($blog_home_url, $this->_config);
             // reset cache of blog_id
             global $w3_current_blog_id;
             $w3_current_blog_id = null;
             // change config to actual blog, it was master before
             $this->_config = new W3_Config();
         }
         $do_redirect |= $this->_config->fill_missing_cache_options_and_save();
         // need to repeat request processing, since we was not able to realize
         // blog_id before so we are running with master config now.
         // redirect to the same url causes "redirect loop" error in browser,
         // so need to redirect to something a bit different
         if ($do_redirect) {
             if (strpos($_SERVER['REQUEST_URI'], '?') === false) {
                 w3_redirect_temp($_SERVER['REQUEST_URI'] . '?repeat=w3tc');
             } else {
                 if (strpos($_SERVER['REQUEST_URI'], 'repeat=w3tc') === false) {
                     w3_redirect_temp($_SERVER['REQUEST_URI'] . '&repeat=w3tc');
                 }
             }
         }
     }
     /**
      * Check request and handle w3tc_request_data requests
      */
     $pos = strpos($_SERVER['REQUEST_URI'], '/w3tc_request_data/');
     if ($pos !== false) {
         $hash = substr($_SERVER['REQUEST_URI'], $pos + 19, 32);
         if (strlen($hash) == 32) {
             $request_data = (array) get_option('w3tc_request_data');
             if (isset($request_data[$hash])) {
                 echo '<pre>';
                 foreach ($request_data[$hash] as $key => $value) {
                     printf("%s: %s\n", $key, $value);
                 }
                 echo '</pre>';
                 unset($request_data[$hash]);
                 update_option('w3tc_request_data', $request_data);
             } else {
                 echo 'Requested hash expired or invalid';
             }
             exit;
         }
     }
     /**
      * Check for rewrite test request
      */
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $rewrite_test = W3_Request::get_boolean('w3tc_rewrite_test');
     if ($rewrite_test) {
         echo 'OK';
         exit;
     }
     $admin_bar = false;
     if (function_exists('is_admin_bar_showing')) {
         $admin_bar = is_admin_bar_showing();
     }
     if (current_user_can('manage_options') && $admin_bar) {
         add_action('wp_print_scripts', array($this, 'popup_script'));
     }
 }
Пример #7
0
 /**
  * Page Speed results action
  *
  * @return void
  */
 function action_test_pagespeed_results()
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     w3_require_once(W3TC_LIB_W3_DIR . '/PageSpeed.php');
     $force = W3_Request::get_boolean('force');
     $title = 'Google Page Speed';
     $w3_pagespeed = new W3_PageSpeed();
     $results = $w3_pagespeed->analyze(w3_get_home_url(), $force);
     if ($force) {
         w3_admin_redirect(array('w3tc_pagespeed_results' => 1, '_wpnonce' => wp_create_nonce('w3tc')));
     }
     include W3TC_INC_POPUP_DIR . '/pagespeed_results.php';
 }
Пример #8
0
 /**
  * Runs minify
  *
  * @return void
  */
 function process()
 {
     require_once W3TC_LIB_W3_DIR . '/Request.php';
     /**
      * Check for rewrite test request
      */
     $rewrite_test = W3_Request::get_boolean('w3tc_rewrite_test');
     if ($rewrite_test) {
         echo 'OK';
         exit;
     }
     $file = W3_Request::get_string('file');
     if (!$file) {
         $this->error('File param is missing', false);
         return;
     }
     $hash = '';
     $matches = null;
     if (preg_match('~^([a-f0-9]+)\\.[a-f0-9]+\\.(css|js)$~', $file, $matches)) {
         list(, $hash, $type) = $matches;
     } elseif (preg_match('~^([a-f0-9]+)\\/(.+)\\.(include(\\-(footer|body))?(-nb)?)\\.[a-f0-9]+\\.(css|js)$~', $file, $matches)) {
         list(, $theme, $template, $location, , , , $type) = $matches;
     } else {
         $this->error(sprintf('Bad file param format: "%s"', $file), false);
         return;
     }
     require_once W3TC_LIB_MINIFY_DIR . '/Minify.php';
     require_once W3TC_LIB_MINIFY_DIR . '/HTTP/Encoder.php';
     /**
      * Fix DOCUMENT_ROOT
      */
     $_SERVER['DOCUMENT_ROOT'] = w3_get_document_root();
     /**
      * Set cache engine
      */
     Minify::setCache($this->_get_cache());
     /**
      * Set cache ID
      */
     $cache_id = $this->get_cache_id($file);
     Minify::setCacheId($cache_id);
     /**
      * Set logger
      */
     require_once W3TC_LIB_MINIFY_DIR . '/Minify/Logger.php';
     Minify_Logger::setLogger(array(&$this, 'error'));
     /**
      * Set options
      */
     $browsercache = $this->_config->get_boolean('browsercache.enabled');
     $serve_options = array_merge($this->_config->get_array('minify.options'), array('debug' => $this->_config->get_boolean('minify.debug'), 'maxAge' => $this->_config->get_integer('browsercache.cssjs.lifetime'), 'encodeOutput' => $browsercache && $this->_config->get_boolean('browsercache.cssjs.compression'), 'bubbleCssImports' => $this->_config->get_string('minify.css.imports') == 'bubble', 'processCssImports' => $this->_config->get_string('minify.css.imports') == 'process', 'cacheHeaders' => array('use_etag' => $browsercache && $this->_config->get_boolean('browsercache.cssjs.etag'), 'expires_enabled' => $browsercache && $this->_config->get_boolean('browsercache.cssjs.expires'), 'cacheheaders_enabled' => $browsercache && $this->_config->get_boolean('browsercache.cssjs.cache.control'), 'cacheheaders' => $this->_config->get_string('browsercache.cssjs.cache.policy'))));
     /**
      * Set sources
      */
     if ($hash) {
         $_GET['f'] = $this->get_files($hash, $type);
     } else {
         $_GET['g'] = $location;
         $serve_options['minApp']['groups'] = $this->get_groups($theme, $template, $type);
     }
     /**
      * Set minifier
      */
     $w3_minifier =& w3_instance('W3_Minifier');
     if ($type == 'js') {
         $minifier_type = 'application/x-javascript';
         switch (true) {
             case ($hash || $location == 'include' || $location == 'include-nb') && $this->_config->get_boolean('minify.js.combine.header'):
             case ($location == 'include-body' || $location == 'include-body-nb') && $this->_config->get_boolean('minify.js.combine.body'):
             case ($location == 'include-footer' || $location == 'include-footer-nb') && $this->_config->get_boolean('minify.js.combine.footer'):
                 $engine = 'combinejs';
                 break;
             default:
                 $engine = $this->_config->get_string('minify.js.engine');
                 if (!$w3_minifier->exists($engine) || !$w3_minifier->available($engine)) {
                     $engine = 'js';
                 }
                 break;
         }
     } elseif ($type == 'css') {
         $minifier_type = 'text/css';
         if (($hash || $location == 'include') && $this->_config->get_boolean('minify.css.combine')) {
             $engine = 'combinecss';
         } else {
             $engine = $this->_config->get_string('minify.css.engine');
             if (!$w3_minifier->exists($engine) || !$w3_minifier->available($engine)) {
                 $engine = 'css';
             }
         }
     }
     /**
      * Initialize minifier
      */
     $w3_minifier->init($engine);
     $serve_options['minifiers'][$minifier_type] = $w3_minifier->get_minifier($engine);
     $serve_options['minifierOptions'][$minifier_type] = $w3_minifier->get_options($engine);
     /**
      * Send X-Powered-By header
      */
     if ($browsercache && $this->_config->get_boolean('browsercache.cssjs.w3tc')) {
         @header('X-Powered-By: ' . W3TC_POWERED_BY);
     }
     /**
      * Minify!
      */
     try {
         Minify::serve('MinApp', $serve_options);
     } catch (Exception $exception) {
         $this->error($exception->getMessage());
     }
 }
Пример #9
0
 /**
  * CDN Test FTP
  */
 function cdn_test_ftp()
 {
     require_once W3TC_LIB_W3_DIR . '/Request.php';
     require_once W3TC_LIB_W3_DIR . '/Cdn.php';
     $host = W3_Request::get_string('host');
     $user = W3_Request::get_string('user');
     $pass = W3_Request::get_string('pass');
     $path = W3_Request::get_string('path');
     $pasv = W3_Request::get_boolean('pasv');
     $w3_cdn_ftp =& W3_Cdn::instance('ftp', array('host' => $host, 'user' => $user, 'pass' => $pass, 'path' => $path, 'pasv' => $pasv));
     $error = null;
     if ($w3_cdn_ftp->test($error)) {
         $result = true;
         $error = 'Test passed';
     } else {
         $result = false;
         $error = sprintf('Test failed. Error: %s', $error);
     }
     echo sprintf('{result: %d, error: "%s"}', $result, addslashes($error));
 }
Пример #10
0
 /**
  * Page Speed results popup
  *
  * @return void
  */
 function pagespeed_results()
 {
     require_once W3TC_LIB_W3_DIR . '/Request.php';
     require_once W3TC_LIB_W3_DIR . '/PageSpeed.php';
     $force = W3_Request::get_boolean('force');
     $title = 'Google Page Speed';
     $w3_pagespeed = new W3_PageSpeed();
     $results = $w3_pagespeed->analyze(w3_get_home_url(), $force);
     if ($force) {
         $this->redirect(array('w3tc_action' => 'pagespeed_results'));
     }
     include W3TC_DIR . '/inc/popup/pagespeed_results.phtml';
 }
Пример #11
0
 /**
  * Init action
  *
  * @return void
  */
 function init()
 {
     /**
      * Check request and handle w3tc_request_data requests
      */
     $pos = strpos($_SERVER['REQUEST_URI'], '/w3tc_request_data/');
     if ($pos !== false) {
         $hash = substr($_SERVER['REQUEST_URI'], $pos + 19, 32);
         if (strlen($hash) == 32) {
             $request_data = (array) get_option('w3tc_request_data');
             if (isset($request_data[$hash])) {
                 echo '<pre>';
                 foreach ($request_data[$hash] as $key => $value) {
                     printf("%s: %s\n", $key, $value);
                 }
                 echo '</pre>';
                 unset($request_data[$hash]);
                 update_option('w3tc_request_data', $request_data);
             } else {
                 echo 'Requested hash expired or invalid';
             }
             exit;
         }
     }
     /**
      * Check for rewrite test request
      */
     require_once W3TC_LIB_W3_DIR . '/Request.php';
     $rewrite_test = W3_Request::get_boolean('w3tc_rewrite_test');
     if ($rewrite_test) {
         echo 'OK';
         exit;
     }
 }
Пример #12
0
<?php

if (!defined('W3TC')) {
    die;
}
include W3TC_INC_DIR . '/options/common/header.php';
if (W3_Request::get_boolean('payment')) {
    ?>
    <div class="error fade">
    <p>To complete your support request fill out the form below!</p>
    </div>
<?php 
} else {
    ?>
<p>
    <?php 
    _e('Request premium services, suggest a feature or submit a bug using the form below:', 'w3-total-cache');
    ?>
</p>
<?php 
}
?>
<div id="support_container">
    <?php 
if (!$request_type || !isset($this->_request_types[$request_type])) {
    $this->action_support_select();
} else {
    if (isset($this->_request_prices[$request_type]) && !$payment) {
        $this->action_support_payment();
    } else {
        $this->action_support_form();
Пример #13
0
 /**
  * Save support us action
  *
  * @return void
  */
 function action_config_save_support_us()
 {
     $support = W3_Request::get_string('support');
     $tweeted = W3_Request::get_boolean('tweeted');
     $signmeup = W3_Request::get_boolean('signmeup');
     $this->_config->set('common.support', $support);
     $this->_config->set('common.tweeted', $tweeted);
     if ($signmeup) {
         if (w3_is_pro($this->_config)) {
             $license = 'pro';
         } elseif (w3_is_enterprise()) {
             $license = 'enterprise';
         } else {
             $license = 'community';
         }
         $email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
         wp_remote_post(W3TC_MAILLINGLIST_SIGNUP_URL, array('body' => array('email' => $email, 'license' => $license)));
     }
     $this->_config->save();
     w3_instance('W3_AdminLinks')->link_update($this->_config);
     w3_admin_redirect(array('w3tc_note' => 'config_save'));
 }
Пример #14
0
 /**
  * Checks User Agent
  *
  * @return boolean
  */
 function _check_ua()
 {
     require_once W3TC_LIB_W3_DIR . '/Request.php';
     $uas = $this->_config->get_array('pgcache.reject.ua');
     $preload = W3_Request::get_boolean('w3tc_preload');
     if (!$preload) {
         $uas = array_merge($uas, array(W3TC_POWERED_BY));
     }
     foreach ($uas as $ua) {
         if (isset($_SERVER['HTTP_USER_AGENT']) && stristr($_SERVER['HTTP_USER_AGENT'], $ua) !== false) {
             return false;
         }
     }
     return true;
 }
 /**
  * Save support us action
  *
  * @return void
  */
 function action_config_save_support_us()
 {
     $support = W3_Request::get_string('support');
     $tweeted = W3_Request::get_boolean('tweeted');
     $this->_config->set('common.support', $support);
     $this->_config->set('common.tweeted', $tweeted);
     $this->_config->save();
     w3_instance('W3_AdminLinks')->link_update($this->_config);
     w3_admin_redirect(array('w3tc_note' => 'config_save'));
 }
Пример #16
0
 /**
  * Runs minify
  *
  * @param string|null $file
  *
  * @return void
  */
 function process($file = NULL)
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     /**
      * Check for rewrite test request
      */
     $rewrite_test = W3_Request::get_boolean('w3tc_rewrite_test');
     if ($rewrite_test) {
         echo 'OK';
         exit;
     }
     $rewrite_test = W3_Request::get_string('test_file');
     if ($rewrite_test) {
         $cache = $this->_get_cache();
         header('Content-type: text/css');
         if ($cache->store(basename($rewrite_test), 'content ok')) {
             if (function_exists('gzencode') && $this->_config->get_boolean('browsercache.enabled') && $this->_config->get_boolean('browsercache.cssjs.compression')) {
                 if (!$cache->store(basename($rewrite_test) . '.gzip', gzencode('content ok'))) {
                     echo 'error storing';
                     exit;
                 }
             }
             if ($this->_config->get_string('minify.engine') != 'file') {
                 if ($cache->fetch(basename($rewrite_test)) == 'content ok') {
                     echo 'content ok';
                 } else {
                     echo 'error storing';
                 }
             } else {
                 echo 'retry';
             }
         } else {
             echo 'error storing';
         }
         exit;
     }
     if (is_null($file)) {
         $file = W3_Request::get_string('file');
     }
     if (!$file) {
         $this->error('File param is missing', false);
         return;
     }
     // remove blog_id
     $levels = '';
     if (defined('W3TC_BLOG_LEVELS')) {
         for ($n = 0; $n < W3TC_BLOG_LEVELS; $n++) {
             $levels .= '[0-9]+\\/';
         }
     }
     if (preg_match('~^(' . $levels . '[0-9]+)\\/(.+)$~', $file, $matches)) {
         $file = $matches[2];
     }
     // parse file
     $hash = '';
     $matches = null;
     $location = '';
     $type = '';
     if (preg_match('~^' . MINIFY_AUTO_FILENAME_REGEX . '$~', $file, $matches)) {
         list(, $hash, $type) = $matches;
     } elseif (preg_match('~^' . MINIFY_MANUAL_FILENAME_REGEX . '$~', $file, $matches)) {
         list(, $theme, $template, $location, , , $type) = $matches;
     } else {
         $this->error(sprintf('Bad file param format: "%s"', $file), false);
         return;
     }
     w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify.php');
     w3_require_once(W3TC_LIB_MINIFY_DIR . '/HTTP/Encoder.php');
     /**
      * Fix DOCUMENT_ROOT
      */
     $_SERVER['DOCUMENT_ROOT'] = w3_get_document_root();
     /**
      * Set cache engine
      */
     Minify::setCache($this->_get_cache());
     /**
      * Set cache ID
      */
     $cache_id = $this->get_cache_id($file);
     Minify::setCacheId($cache_id);
     /**
      * Set logger
      */
     w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/Logger.php');
     Minify_Logger::setLogger(array(&$this, 'error'));
     /**
      * Set options
      */
     $browsercache = $this->_config->get_boolean('browsercache.enabled');
     $serve_options = array_merge($this->_config->get_array('minify.options'), array('debug' => $this->_config->get_boolean('minify.debug'), 'maxAge' => $this->_config->get_integer('browsercache.cssjs.lifetime'), 'encodeOutput' => $browsercache && $this->_config->get_boolean('browsercache.cssjs.compression'), 'bubbleCssImports' => $this->_config->get_string('minify.css.imports') == 'bubble', 'processCssImports' => $this->_config->get_string('minify.css.imports') == 'process', 'cacheHeaders' => array('use_etag' => $browsercache && $this->_config->get_boolean('browsercache.cssjs.etag'), 'expires_enabled' => $browsercache && $this->_config->get_boolean('browsercache.cssjs.expires'), 'cacheheaders_enabled' => $browsercache && $this->_config->get_boolean('browsercache.cssjs.cache.control'), 'cacheheaders' => $this->_config->get_string('browsercache.cssjs.cache.policy'))));
     /**
      * Set sources
      */
     if ($hash) {
         $_GET['f'] = $this->get_custom_files($hash, $type);
     } else {
         $_GET['g'] = $location;
         $serve_options['minApp']['groups'] = $this->get_groups($theme, $template, $type);
     }
     /**
      * Set minifier
      */
     $w3_minifier = w3_instance('W3_Minifier');
     if ($type == 'js') {
         $minifier_type = 'application/x-javascript';
         switch (true) {
             case ($hash || $location == 'include') && $this->_config->get_boolean('minify.js.combine.header'):
             case $location == 'include-body' && $this->_config->get_boolean('minify.js.combine.body'):
             case $location == 'include-footer' && $this->_config->get_boolean('minify.js.combine.footer'):
                 $engine = 'combinejs';
                 break;
             default:
                 $engine = $this->_config->get_string('minify.js.engine');
                 if (!$w3_minifier->exists($engine) || !$w3_minifier->available($engine)) {
                     $engine = 'js';
                 }
                 break;
         }
     } elseif ($type == 'css') {
         $minifier_type = 'text/css';
         if (($hash || $location == 'include') && $this->_config->get_boolean('minify.css.combine')) {
             $engine = 'combinecss';
         } else {
             $engine = $this->_config->get_string('minify.css.engine');
             if (!$w3_minifier->exists($engine) || !$w3_minifier->available($engine)) {
                 $engine = 'css';
             }
         }
     }
     /**
      * Initialize minifier
      */
     $w3_minifier->init($engine);
     $serve_options['minifiers'][$minifier_type] = $w3_minifier->get_minifier($engine);
     $serve_options['minifierOptions'][$minifier_type] = $w3_minifier->get_options($engine);
     /**
      * Send X-Powered-By header
      */
     if ($browsercache && $this->_config->get_boolean('browsercache.cssjs.w3tc')) {
         @header('X-Powered-By: ' . W3TC_POWERED_BY);
     }
     /**
      * Minify!
      */
     try {
         Minify::serve('MinApp', $serve_options);
     } catch (Exception $exception) {
         $this->error($exception->getMessage());
     }
     if (!$this->_error_occurred && $this->_config_admin->get_boolean('notes.minify_error')) {
         $error_file = $this->_config_admin->get_string('minify.error.file');
         if ($error_file == $file) {
             $this->_config_admin->set('notes.minify_error', false);
             $this->_config_admin->save();
         }
     }
 }
Пример #17
0
 /**
  * Options save action
  *
  * @return void
  */
 function action_save_options()
 {
     if (!current_user_can('manage_options')) {
         wp_die(__('You do not have the rights to perform this action.', 'w3-total-cache'));
     }
     /**
      * Redirect params
      */
     $params = array();
     /**
      * Store error message regarding permalink not enabled
      */
     $redirect_permalink_error = '';
     /**
      * Read config
      * We should use new instance of WP_Config object here
      */
     $config = new W3_Config();
     $this->read_request($config);
     $config_admin = new W3_ConfigAdmin();
     $this->read_request($config_admin);
     if ($this->_page == 'w3tc_dashboard') {
         if (W3_Request::get_boolean('maxcdn')) {
             $config->set('cdn.enabled', true);
             $config->set('cdn.engine', 'maxcdn');
         }
     }
     /**
      * General tab
      */
     if ($this->_page == 'w3tc_general') {
         $file_nfs = W3_Request::get_boolean('file_nfs');
         $file_locking = W3_Request::get_boolean('file_locking');
         $config->set('pgcache.file.nfs', $file_nfs);
         $config->set('minify.file.nfs', $file_nfs);
         $config->set('dbcache.file.locking', $file_locking);
         $config->set('objectcache.file.locking', $file_locking);
         $config->set('pgcache.file.locking', $file_locking);
         $config->set('minify.file.locking', $file_locking);
         if (is_network_admin()) {
             if ($this->_config->get_boolean('common.force_master') !== $config->get_boolean('common.force_master') || !w3_force_master() && $this->_config->get_boolean('common.force_master') && $config->get_boolean('common.force_master') || w3_force_master() && !$this->_config->get_boolean('common.force_master') && !$config->get_boolean('common.force_master')) {
                 @unlink(W3TC_CACHE_BLOGMAP_FILENAME);
                 $blogmap_dir = dirname(W3TC_CACHE_BLOGMAP_FILENAME) . '/' . basename(W3TC_CACHE_BLOGMAP_FILENAME, '.php') . '/';
                 if (@is_dir($blogmap_dir)) {
                     w3_rmdir($blogmap_dir);
                 }
             }
             if ($config->get_boolean('common.force_master')) {
                 $config_admin->set('common.visible_by_master_only', true);
             }
         }
         /**
          * Check permalinks for page cache
          */
         if ($config->get_boolean('pgcache.enabled') && $config->get_string('pgcache.engine') == 'file_generic' && !get_option('permalink_structure')) {
             $config->set('pgcache.enabled', false);
             $redirect_permalink_error = 'fancy_permalinks_disabled_pgcache';
         }
         /**
          * Get New Relic application id
          */
         if ($config->get_boolean('newrelic.enabled')) {
             $method = W3_Request::get_string('application_id_method');
             $newrelic_prefix = '';
             if (w3_is_network() && w3_get_blog_id() != 0) {
                 $newrelic_prefix = $this->_config->get_string('newrelic.appname_prefix');
             }
             if (($newrelic_api_key = $config->get_string('newrelic.api_key')) && !$config->get_string('newrelic.account_id')) {
                 $nerser = w3_instance('W3_NewRelicService');
                 $account_id = $nerser->get_account_id($newrelic_api_key);
                 $config->set('newrelic.account_id', $account_id);
             }
             if ($method == 'dropdown' && $config->get_string('newrelic.application_id')) {
                 $application_id = $config->get_string('newrelic.application_id');
                 if ($config->get_string('newrelic.api_key') && $config->get_string('newrelic.account_id')) {
                     w3_require_once(W3TC_LIB_W3_DIR . '/NewRelicService.php');
                     $nerser = new W3_NewRelicService($config->get_string('newrelic.api_key'), $config->get_string('newrelic.account_id'));
                     $appname = $nerser->get_application_name($application_id);
                     $config->set('newrelic.appname', $appname);
                 }
             } else {
                 if ($method == 'manual' && $config->get_string('newrelic.appname')) {
                     if ($newrelic_prefix != '' && strpos($config->get_string('newrelic.appname'), $newrelic_prefix) === false) {
                         $application_name = $newrelic_prefix . $config->get_string('newrelic.appname');
                         $config->set('newrelic.appname', $application_name);
                     } else {
                         $application_name = $config->get_string('newrelic.appname');
                     }
                     if ($config->get_string('newrelic.api_key') && $config->get_string('newrelic.account_id')) {
                         w3_require_once(W3TC_LIB_W3_DIR . '/NewRelicService.php');
                         $nerser = new W3_NewRelicService($config->get_string('newrelic.api_key'), $config->get_string('newrelic.account_id'));
                         $application_id = $nerser->get_application_id($application_name);
                         if ($application_id) {
                             $config->set('newrelic.application_id', $application_id);
                         }
                     }
                 }
             }
         }
         if ($config->get_boolean('minify.enabled') && !$this->_config->get_boolean('minify.enabled') || $config->get_boolean('minify.enabled') && $config->get_boolean('browsercache.enabled') && !$this->_config->get_boolean('browsercache.enabled') || $config->get_boolean('minify.enabled') && $config->get_boolean('minify.auto') && !$this->_config->get_boolean('minify.auto') || $config->get_boolean('minify.enabled') && $config->get_string('minify.engine') != $this->_config->get_string('minify.engine')) {
             delete_transient('w3tc_minify_tested_filename_length');
         }
         if (!w3_is_pro($this->_config)) {
             delete_transient('w3tc_license_status');
         }
     }
     /**
      * Minify tab
      */
     if ($this->_page == 'w3tc_minify' && !$this->_config->get_boolean('minify.auto')) {
         $js_groups = array();
         $css_groups = array();
         $js_files = W3_Request::get_array('js_files');
         $css_files = W3_Request::get_array('css_files');
         foreach ($js_files as $theme => $templates) {
             foreach ($templates as $template => $locations) {
                 foreach ((array) $locations as $location => $types) {
                     foreach ((array) $types as $files) {
                         foreach ((array) $files as $file) {
                             if (!empty($file)) {
                                 $js_groups[$theme][$template][$location]['files'][] = w3_normalize_file_minify($file);
                             }
                         }
                     }
                 }
             }
         }
         foreach ($css_files as $theme => $templates) {
             foreach ($templates as $template => $locations) {
                 foreach ((array) $locations as $location => $files) {
                     foreach ((array) $files as $file) {
                         if (!empty($file)) {
                             $css_groups[$theme][$template][$location]['files'][] = w3_normalize_file_minify($file);
                         }
                     }
                 }
             }
         }
         $config->set('minify.js.groups', $js_groups);
         $config->set('minify.css.groups', $css_groups);
         $js_theme = W3_Request::get_string('js_theme');
         $css_theme = W3_Request::get_string('css_theme');
         $params = array_merge($params, array('js_theme' => $js_theme, 'css_theme' => $css_theme));
     }
     if ($this->_page == 'w3tc_minify') {
         if ($config->get_integer('minify.auto.filename_length') > 246) {
             $config->set('minify.auto.filename_length', 246);
         }
         delete_transient('w3tc_minify_tested_filename_length');
     }
     /**
      * Browser Cache tab
      */
     if ($this->_page == 'w3tc_browsercache') {
         if ($config->get_boolean('browsercache.enabled') && $config->get_boolean('browsercache.no404wp') && !get_option('permalink_structure')) {
             $config->set('browsercache.no404wp', false);
             $redirect_permalink_error = 'fancy_permalinks_disabled_browsercache';
         }
         $config->set('browsercache.timestamp', time());
         if (in_array($engine = $this->_config->get_string('cdn.engine'), array('netdna', 'maxcdn'))) {
             w3_require_once(W3TC_LIB_NETDNA_DIR . '/NetDNA.php');
             $keys = explode('+', $this->_config->get_string('cdn.' . $engine . '.authorization_key'));
             if (sizeof($keys) == 3) {
                 list($alias, $consumerkey, $consumersecret) = $keys;
                 try {
                     $api = new NetDNA($alias, $consumerkey, $consumersecret);
                     $disable_cooker_header = $config->get_boolean('browsercache.other.nocookies') || $config->get_boolean('browsercache.cssjs.nocookies');
                     $api->update_pull_zone($this->_config->get_string('cdn.' . $engine . '.zone_id'), array('ignore_setcookie_header' => $disable_cooker_header));
                 } catch (Exception $ex) {
                 }
             }
         }
     }
     /**
      * Mobile tab
      */
     if ($this->_page == 'w3tc_mobile') {
         $groups = W3_Request::get_array('mobile_groups');
         $mobile_groups = array();
         $cached_mobile_groups = array();
         foreach ($groups as $group => $group_config) {
             $group = strtolower($group);
             $group = preg_replace('~[^0-9a-z_]+~', '_', $group);
             $group = trim($group, '_');
             if ($group) {
                 $theme = isset($group_config['theme']) ? trim($group_config['theme']) : 'default';
                 $enabled = isset($group_config['enabled']) ? (bool) $group_config['enabled'] : true;
                 $redirect = isset($group_config['redirect']) ? trim($group_config['redirect']) : '';
                 $agents = isset($group_config['agents']) ? explode("\r\n", trim($group_config['agents'])) : array();
                 $mobile_groups[$group] = array('theme' => $theme, 'enabled' => $enabled, 'redirect' => $redirect, 'agents' => $agents);
                 $cached_mobile_groups[$group] = $agents;
             }
         }
         /**
          * Allow plugins modify WPSC mobile groups
          */
         $cached_mobile_groups = apply_filters('cached_mobile_groups', $cached_mobile_groups);
         /**
          * Merge existent and delete removed groups
          */
         foreach ($mobile_groups as $group => $group_config) {
             if (isset($cached_mobile_groups[$group])) {
                 $mobile_groups[$group]['agents'] = (array) $cached_mobile_groups[$group];
             } else {
                 unset($mobile_groups[$group]);
             }
         }
         /**
          * Add new groups
          */
         foreach ($cached_mobile_groups as $group => $agents) {
             if (!isset($mobile_groups[$group])) {
                 $mobile_groups[$group] = array('theme' => '', 'enabled' => true, 'redirect' => '', 'agents' => $agents);
             }
         }
         /**
          * Allow plugins modify W3TC mobile groups
          */
         $mobile_groups = apply_filters('w3tc_mobile_groups', $mobile_groups);
         /**
          * Sanitize mobile groups
          */
         foreach ($mobile_groups as $group => $group_config) {
             $mobile_groups[$group] = array_merge(array('theme' => '', 'enabled' => true, 'redirect' => '', 'agents' => array()), $group_config);
             $mobile_groups[$group]['agents'] = array_unique($mobile_groups[$group]['agents']);
             $mobile_groups[$group]['agents'] = array_map('strtolower', $mobile_groups[$group]['agents']);
             sort($mobile_groups[$group]['agents']);
         }
         $enable_mobile = false;
         foreach ($mobile_groups as $group_config) {
             if ($group_config['enabled']) {
                 $enable_mobile = true;
                 break;
             }
         }
         $config->set('mobile.enabled', $enable_mobile);
         $config->set('mobile.rgroups', $mobile_groups);
     }
     /**
      * Referrer tab
      */
     if ($this->_page == 'w3tc_referrer') {
         $groups = W3_Request::get_array('referrer_groups');
         $referrer_groups = array();
         foreach ($groups as $group => $group_config) {
             $group = strtolower($group);
             $group = preg_replace('~[^0-9a-z_]+~', '_', $group);
             $group = trim($group, '_');
             if ($group) {
                 $theme = isset($group_config['theme']) ? trim($group_config['theme']) : 'default';
                 $enabled = isset($group_config['enabled']) ? (bool) $group_config['enabled'] : true;
                 $redirect = isset($group_config['redirect']) ? trim($group_config['redirect']) : '';
                 $referrers = isset($group_config['referrers']) ? explode("\r\n", trim($group_config['referrers'])) : array();
                 $referrer_groups[$group] = array('theme' => $theme, 'enabled' => $enabled, 'redirect' => $redirect, 'referrers' => $referrers);
             }
         }
         /**
          * Allow plugins modify W3TC referrer groups
          */
         $referrer_groups = apply_filters('w3tc_referrer_groups', $referrer_groups);
         /**
          * Sanitize mobile groups
          */
         foreach ($referrer_groups as $group => $group_config) {
             $referrer_groups[$group] = array_merge(array('theme' => '', 'enabled' => true, 'redirect' => '', 'referrers' => array()), $group_config);
             $referrer_groups[$group]['referrers'] = array_unique($referrer_groups[$group]['referrers']);
             $referrer_groups[$group]['referrers'] = array_map('strtolower', $referrer_groups[$group]['referrers']);
             sort($referrer_groups[$group]['referrers']);
         }
         $enable_referrer = false;
         foreach ($referrer_groups as $group_config) {
             if ($group_config['enabled']) {
                 $enable_referrer = true;
                 break;
             }
         }
         $config->set('referrer.enabled', $enable_referrer);
         $config->set('referrer.rgroups', $referrer_groups);
     }
     /**
      * CDN tab
      */
     if ($this->_page == 'w3tc_cdn') {
         $cdn_cnames = W3_Request::get_array('cdn_cnames');
         $cdn_domains = array();
         foreach ($cdn_cnames as $cdn_cname) {
             $cdn_cname = trim($cdn_cname);
             /**
              * Auto expand wildcard domain to 10 subdomains
              */
             $matches = null;
             if (preg_match('~^\\*\\.(.*)$~', $cdn_cname, $matches)) {
                 $cdn_domains = array();
                 for ($i = 1; $i <= 10; $i++) {
                     $cdn_domains[] = sprintf('cdn%d.%s', $i, $matches[1]);
                 }
                 break;
             }
             if ($cdn_cname) {
                 $cdn_domains[] = $cdn_cname;
             }
         }
         switch ($this->_config->get_string('cdn.engine')) {
             case 'ftp':
                 $config->set('cdn.ftp.domain', $cdn_domains);
                 break;
             case 's3':
                 $config->set('cdn.s3.cname', $cdn_domains);
                 break;
             case 'cf':
                 $config->set('cdn.cf.cname', $cdn_domains);
                 break;
             case 'cf2':
                 $config->set('cdn.cf2.cname', $cdn_domains);
                 break;
             case 'rscf':
                 $config->set('cdn.rscf.cname', $cdn_domains);
                 break;
             case 'azure':
                 $config->set('cdn.azure.cname', $cdn_domains);
                 break;
             case 'mirror':
                 $config->set('cdn.mirror.domain', $cdn_domains);
                 break;
             case 'maxcdn':
                 $config->set('cdn.maxcdn.domain', $cdn_domains);
                 break;
             case 'netdna':
                 $config->set('cdn.netdna.domain', $cdn_domains);
                 break;
             case 'cotendo':
                 $config->set('cdn.cotendo.domain', $cdn_domains);
                 break;
             case 'edgecast':
                 $config->set('cdn.edgecast.domain', $cdn_domains);
                 break;
             case 'att':
                 $config->set('cdn.att.domain', $cdn_domains);
                 break;
             case 'akamai':
                 $config->set('cdn.akamai.domain', $cdn_domains);
                 break;
         }
     }
     w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/extensions.php');
     w3_extensions_admin_init();
     $all_extensions = w3_get_extensions($config);
     $old_extensions = $this->_config->get_array('extensions.settings', array());
     foreach ($all_extensions as $extension => $descriptor) {
         $extension_values = W3_Request::get_as_array('extensions.settings.');
         $extension_keys = array();
         $extension_settings = array();
         $tmp_grp = str_replace('.', '_', $extension) . '_';
         foreach ($extension_values as $key => $value) {
             if (strpos($key, $tmp_grp) !== false) {
                 $extension_settings[str_replace($tmp_grp, '', $key)] = $value;
             }
         }
         if ($extension_settings) {
             $old_extension_settings = isset($old_extensions[$extension]) ? $old_extensions[$extension] : array();
             if (!isset($old_extensions[$extension])) {
                 $old_extensions[$extension] = array();
             }
             $extension_keys[$extension] = apply_filters("w3tc_save_extension_settings-{$extension}", $extension_settings, $old_extension_settings);
             $new_settings = array_merge($old_extensions, $extension_keys);
             $config->set("extensions.settings", $new_settings);
             $old_extensions = $config->get_array('extensions.settings', array());
         }
     }
     //CloudFront does not support expires header. So disable it when its used
     if ($config->get_string('cdn.engine') == 'cf2') {
         $config->set('browsercache.cssjs.expires', false);
         $config->set('browsercache.html.expires', false);
         $config->set('browsercache.other.expires', false);
     }
     $config = apply_filters('w3tc_save_options', $config, $this->_config, $config_admin);
     $config = apply_filters("w3tc_save_options-{$this->_page}", $config, $this->_config, $config_admin);
     do_action('w3tc_saving_options', $config, $this->_config, $config_admin);
     do_action("w3tc_saving_options-{$this->_page}", $config, $this->_config, $config_admin);
     w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/admin.php');
     w3_config_save($this->_config, $config, $config_admin);
     switch ($this->_page) {
         case 'w3tc_cdn':
             /**
              * Handle Set Cookie Domain
              */
             $set_cookie_domain_old = W3_Request::get_boolean('set_cookie_domain_old');
             $set_cookie_domain_new = W3_Request::get_boolean('set_cookie_domain_new');
             if ($set_cookie_domain_old != $set_cookie_domain_new) {
                 if ($set_cookie_domain_new) {
                     if (!$this->enable_cookie_domain()) {
                         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'enable_cookie_domain')));
                     }
                 } else {
                     if (!$this->disable_cookie_domain()) {
                         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'disable_cookie_domain')));
                     }
                 }
             }
             break;
         case 'w3tc_general':
             break;
     }
     $notes[] = 'config_save';
     if ($redirect_permalink_error) {
         w3_admin_redirect(array('w3tc_error' => $redirect_permalink_error, 'w3tc_note' => 'config_save'));
     }
     w3_admin_redirect_with_custom_messages($params, null, $notes, true);
 }