/**
  * Reads legacy config file
  * @param int $blog_id
  * @param bool $force_master
  * @return array
  */
 public function get_imported_legacy_config_keys($blog_id, $force_master = false)
 {
     $suffix = '';
     if ($force_master) {
     } else {
         if ($blog_id > 0) {
             if (w3_is_network()) {
                 if (w3_is_subdomain_install()) {
                     $suffix = '-' . w3_get_domain(w3_get_host());
                 } else {
                     // try subdir blog
                     $request_uri = rtrim($_SERVER['REQUEST_URI'], '/');
                     $site_home_uri = w3_get_base_path();
                     if (substr($request_uri, 0, strlen($site_home_uri)) == $site_home_uri) {
                         $request_path_in_wp = '/' . substr($request_uri, strlen($site_home_uri));
                         $n = strpos($request_path_in_wp, '/', 1);
                         if ($n === false) {
                             $blog_path_in_wp = substr($request_path_in_wp, 1);
                         } else {
                             $blog_path_in_wp = substr($request_path_in_wp, 1, $n - 1);
                         }
                         $suffix = '-' . ($blog_path_in_wp != 'wp-admin' ? $blog_path_in_wp . '.' : '') . w3_get_domain(w3_get_host());
                     }
                 }
             }
         }
     }
     $filename = WP_CONTENT_DIR . '/w3-total-cache-config' . $suffix . '.php';
     $legacy_config = W3_ConfigData::get_array_from_file($filename);
     if (is_array($legacy_config) && isset($legacy_config['pgcache.engine']) && $legacy_config['pgcache.engine'] == 'file_pgcache') {
         $legacy_config['pgcache.engine'] = 'file_generic';
     }
     return $legacy_config;
 }
 /**
  * Flush varnish cache
  */
 function flush()
 {
     if (!is_network_admin()) {
         $this->_purge(w3_get_home_url() . '/.*');
     } else {
         global $wpdb;
         $protocall = w3_is_https() ? 'https://' : 'http://';
         // If WPMU Domain Mapping plugin is installed and active
         if (defined('SUNRISE_LOADED') && SUNRISE_LOADED && isset($wpdb->dmtable) && !empty($wpdb->dmtable)) {
             $blogs = $wpdb->get_results("SELECT {$wpdb->blogs}.domain, {$wpdb->blogs}.path, {$wpdb->dmtable}.domain AS mapped_domain\n                                    FROM {$wpdb->dmtable}\n                                    RIGHT JOIN {$wpdb->blogs} ON {$wpdb->dmtable}.blog_id = {$wpdb->blogs}.blog_id\n                                    WHERE site_id = {$wpdb->siteid}\n                                    AND spam = 0\n                                    AND deleted = 0\n                                    AND archived = '0'\n                                   ");
             foreach ($blogs as $blog) {
                 if (!isset($blog->mapped_domain)) {
                     $url = $protocall . $blog->domain . (strlen($blog->path) > 1 ? '/' . trim($blog->path, '/') : '') . '/.*';
                 } else {
                     $url = $protocall . $blog->mapped_domain . '/.*';
                 }
                 $this->_purge($url);
             }
         } else {
             if (!w3_is_subdomain_install()) {
                 $this->_purge(w3_get_home_url() . '/.*');
             } else {
                 $blogs = $wpdb->get_results("\n                                        SELECT domain, path\n                                        FROM {$wpdb->blogs}\n                                        WHERE site_id = '{$wpdb->siteid}'\n                                        AND spam = 0\n                                        AND deleted = 0\n                                        AND archived = '0'\n                                    ");
                 foreach ($blogs as $blog) {
                     $url = $protocall . $blog->domain . (strlen($blog->path) > 1 ? '/' . trim($blog->path, '/') : '') . '/.*';
                     $this->_purge($url);
                 }
             }
         }
     }
 }
 public function fix_on_wpadmin_request($config, $force_all_checks)
 {
     $exs = new SelfTestExceptions();
     $this->fix_folders($config, $exs);
     /**
      * @var W3_Config $config
      */
     if ($config->get_boolean('config.check') || $force_all_checks) {
         if ($config->get_boolean('minify.enabled') && $config->get_boolean('minify.rewrite')) {
             $this->rules_core_add($config, $exs);
         } else {
             $this->rules_core_remove($exs);
         }
         if ((w3_is_apache() || w3_is_litespeed()) && w3_is_network() && !w3_is_subdomain_install()) {
             if ($config->get_boolean('minify.enabled') && $config->get_boolean('minify.rewrite')) {
                 $this->rules_wpmu_subfolder_add($config, $exs);
             } else {
                 $this->rules_wpmu_subfolder_remove($exs);
             }
         }
         if ($config->get_boolean('minify.enabled') && $config->get_string('minify.engine') == 'file') {
             $this->rules_cache_add($config, $exs);
         } else {
             $this->rules_cache_remove($exs);
         }
     }
     // if no errors so far - check if rewrite actually works
     if (count($exs->exceptions()) <= 0 || true) {
         try {
             if ($config->get_boolean('minify.enabled') && $config->get_string('minify.engine') == 'file' && $config->get_boolean('minify.debug')) {
                 $this->verify_rewrite_working();
             }
         } catch (Exception $ex) {
             $exs->push($ex);
         }
         if ($config->get_boolean('minify.enabled')) {
             $this->verify_engine_working($config, $exs);
         }
     }
     if (count($exs->exceptions()) > 0) {
         throw $exs;
     }
 }
 /**
  * Flush cache based on regex
  * @param string $regex
  */
 private function _flush_based_on_regex($regex)
 {
     if (w3_is_multisite() && !w3_is_subdomain_install()) {
         $domain = w3_get_home_url();
         $parsed = parse_url($domain);
         $host = $parsed['host'];
         $path = trim($parsed['path'], '/');
         $flush_dir = W3TC_CACHE_PAGE_ENHANCED_DIR . '/' . $host . '/' . $path;
     } else {
         $flush_dir = W3TC_CACHE_PAGE_ENHANCED_DIR . '/' . w3_get_domain(w3_get_host());
     }
     $dir = @opendir($flush_dir);
     if ($dir) {
         while (($entry = @readdir($dir)) !== false) {
             if ($entry == '.' || $entry == '..') {
                 continue;
             }
             if (preg_match('/' . $regex . '/', basename($entry))) {
                 w3_rmdir($flush_dir . DIRECTORY_SEPARATOR . $entry);
             }
         }
         @closedir($dir);
     }
 }
 /**
  * Remove script tags from the source
  *
  * @param string $content
  * @param array $files
  * @return void
  */
 function remove_scripts(&$content, $files)
 {
     $regexps = array();
     $home_url_regexp = w3_get_home_url_regexp();
     $path = '';
     if (w3_is_network() && !w3_is_subdomain_install()) {
         $path = ltrim(w3_get_home_path(), '/');
     }
     foreach ($files as $file) {
         if ($path && strpos($file, $path) === 0) {
             $file = substr($file, strlen($path));
         }
         $this->replaced_scripts[] = $file;
         if (w3_is_url($file) && !preg_match('~' . $home_url_regexp . '~i', $file)) {
             // external JS files
             $regexps[] = w3_preg_quote($file);
         } else {
             // local JS files
             $file = ltrim($file, '/');
             if (ltrim(w3_get_site_path(), '/') && strpos($file, ltrim(w3_get_site_path(), '/')) === 0) {
                 $file = str_replace(ltrim(w3_get_site_path(), '/'), '', $file);
             }
             $file = ltrim(preg_replace('~' . $home_url_regexp . '~i', '', $file), '/\\');
             $regexps[] = '(' . $home_url_regexp . ')?/?' . w3_preg_quote($file);
         }
     }
     foreach ($regexps as $regexp) {
         $content = preg_replace('~<script\\s+[^<>]*src=["\']?' . $regexp . '["\']?[^<>]*>\\s*</script>~Uis', '', $content);
     }
 }
Exemple #6
0
/**
 * Detect WPMU blogname
 *
 * @return string
 */
function w3_get_blogname()
{
    static $blogname = null;
    if ($blogname === null) {
        if (w3_is_network()) {
            $host = w3_get_host();
            $domain = w3_get_domain($host);
            if (w3_is_subdomain_install()) {
                $blogname = $domain;
            } else {
                $uri = $_SERVER['REQUEST_URI'];
                $base_path = w3_get_base_path();
                if ($base_path != '' && strpos($uri, $base_path) === 0) {
                    $uri = substr_replace($uri, '/', 0, strlen($base_path));
                }
                $blogname = w3_get_blogname_from_uri($uri);
                if ($blogname != '') {
                    $blogname = $blogname . '.' . $domain;
                } else {
                    $blogname = $domain;
                }
            }
        } else {
            $blogname = '';
        }
    }
    return $blogname;
}
 /**
  * Activate plugin action
  *
  * @return void
  */
 function activate()
 {
     require_once W3TC_INC_DIR . '/functions/activation.php';
     /**
      * Disable buggy sitewide activation in WPMU and WP 3.0
      */
     if (w3_is_wpmu() && isset($_GET['sitewide']) || w3_is_multisite() && isset($_GET['networkwide'])) {
         w3_network_activate_error();
     }
     /**
      * Check installation files
      */
     $files = array(W3TC_INSTALL_FILE_ADVANCED_CACHE, W3TC_INSTALL_FILE_DB, W3TC_INSTALL_FILE_OBJECT_CACHE);
     $nonexistent_files = array();
     foreach ($files as $file) {
         if (!file_exists($file)) {
             $nonexistent_files[] = $file;
         }
     }
     if (count($nonexistent_files)) {
         $error = sprintf('Unfortunately core file(s): (<strong>%s</strong>) are missing, so activation will fail. Please re-start the installation process from the beginning.', implode(', ', $nonexistent_files));
         w3_activate_error($error);
     }
     if (!@is_dir(W3TC_CONTENT_DIR) && !@mkdir(W3TC_CONTENT_DIR)) {
         w3_writable_error(W3TC_CONTENT_DIR);
     }
     if (!@is_dir(W3TC_CACHE_FILE_DBCACHE_DIR) && !@mkdir(W3TC_CACHE_FILE_DBCACHE_DIR)) {
         w3_writable_error(W3TC_CACHE_FILE_DBCACHE_DIR);
     }
     if (!@is_dir(W3TC_CACHE_FILE_OBJECTCACHE_DIR) && !@mkdir(W3TC_CACHE_FILE_OBJECTCACHE_DIR)) {
         w3_writable_error(W3TC_CACHE_FILE_OBJECTCACHE_DIR);
     }
     if (!@is_dir(W3TC_CACHE_FILE_PGCACHE_DIR) && !@mkdir(W3TC_CACHE_FILE_PGCACHE_DIR)) {
         w3_writable_error(W3TC_CACHE_FILE_PGCACHE_DIR);
     }
     if (!@is_dir(W3TC_CACHE_FILE_MINIFY_DIR) && !@mkdir(W3TC_CACHE_FILE_MINIFY_DIR)) {
         w3_writable_error(W3TC_CACHE_FILE_MINIFY_DIR);
     }
     if (!@is_dir(W3TC_LOG_DIR) && !@mkdir(W3TC_LOG_DIR)) {
         w3_writable_error(W3TC_LOG_DIR);
     }
     if (!@is_dir(W3TC_TMP_DIR) && !@mkdir(W3TC_TMP_DIR)) {
         w3_writable_error(W3TC_TMP_DIR);
     }
     if (w3_is_network() && file_exists(W3TC_CONFIG_MASTER_PATH)) {
         /**
          * For multisite load master config
          */
         $this->_config->load_master();
         if (!$this->_config->save(false)) {
             w3_writable_error(W3TC_CONFIG_PATH);
         }
     } elseif (!file_exists(W3TC_CONFIG_PATH)) {
         /**
          * Set default settings
          */
         $this->_config->set_defaults();
         /**
          * If config doesn't exist enable preview mode
          */
         if (!$this->_config->save(true)) {
             w3_writable_error(W3TC_CONFIG_PREVIEW_PATH);
         }
     }
     /**
      * Save blognames into file
      */
     if (w3_is_network() && !w3_is_subdomain_install()) {
         if (!w3_save_blognames()) {
             w3_writable_error(W3TC_BLOGNAMES_PATH);
         }
     }
     delete_option('w3tc_request_data');
     add_option('w3tc_request_data', '', null, 'no');
 }
 /**
  * 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'));
     }
 }
 /**
  * Generates rules for WP dir
  *
  * @return string
  */
 function generate_rules_core_nginx()
 {
     $is_network = w3_is_network();
     $is_vhost = w3_is_subdomain_install();
     $base_path = w3_get_base_path();
     $cache_dir = w3_path(W3TC_CACHE_FILE_PGCACHE_DIR);
     $permalink_structure = get_option('permalink_structure');
     /**
      * Auto reject cookies
      */
     $reject_cookies = array('comment_author', 'wp-postpass');
     /**
      * Auto reject URIs
      */
     $reject_uris = array('\\/wp-admin\\/', '\\/xmlrpc.php', '\\/wp-(app|cron|login|register|mail)\\.php');
     /**
      * Reject cache for logged in users
      */
     if ($this->_config->get_boolean('pgcache.reject.logged')) {
         $reject_cookies = array_merge($reject_cookies, array('wordpress_[a-f0-9]+', 'wordpress_logged_in'));
     }
     /**
      * Reject cache for home page
      */
     if (!$this->_config->get_boolean('pgcache.cache.home')) {
         $reject_uris[] = '^(\\/|\\/index.php)$';
     }
     /**
      * Reject cache for feeds
      */
     if (!$this->_config->get_boolean('pgcache.cache.feed')) {
         $reject_uris[] = '\\/feed\\/';
     }
     /**
      * Custom config
      */
     $reject_cookies = array_merge($reject_cookies, $this->_config->get_array('pgcache.reject.cookie'));
     $reject_uris = array_merge($reject_uris, $this->_config->get_array('pgcache.reject.uri'));
     $reject_uris = array_map('w3_parse_path', $reject_uris);
     $reject_user_agents = array_merge(array(W3TC_POWERED_BY), $this->_config->get_array('pgcache.reject.ua'));
     $accept_uris = $this->_config->get_array('pgcache.accept.uri');
     $accept_files = $this->_config->get_array('pgcache.accept.files');
     /**
      * Generate rules
      */
     $rules = '';
     $rules .= W3TC_MARKER_BEGIN_PGCACHE_CORE . "\n";
     $rules .= "rewrite ^(.*\\/)?w3tc_rewrite_test\$ \$1?w3tc_rewrite_test=1 last;\n";
     /**
      * Check for mobile redirect
      */
     if ($this->_config->get_boolean('mobile.enabled')) {
         $mobile_groups = $this->_config->get_array('mobile.rgroups');
         foreach ($mobile_groups as $mobile_group => $mobile_config) {
             $mobile_enabled = isset($mobile_config['enabled']) ? (bool) $mobile_config['enabled'] : false;
             $mobile_agents = isset($mobile_config['agents']) ? (array) $mobile_config['agents'] : '';
             $mobile_redirect = isset($mobile_config['redirect']) ? $mobile_config['redirect'] : '';
             if ($mobile_enabled && count($mobile_agents) && $mobile_redirect) {
                 $rules .= "if (\$http_user_agent ~* \"(" . implode('|', $mobile_agents) . ")\") {\n";
                 $rules .= "    rewrite .* " . $mobile_redirect . " last;\n";
                 $rules .= "}\n";
             }
         }
     }
     /**
      * Check for referrer redirect
      */
     if ($this->_config->get_boolean('referrer.enabled')) {
         $referrer_groups = $this->_config->get_array('referrer.rgroups');
         foreach ($referrer_groups as $referrer_group => $referrer_config) {
             $referrer_enabled = isset($referrer_config['enabled']) ? (bool) $referrer_config['enabled'] : false;
             $referrer_referrers = isset($referrer_config['referrers']) ? (array) $referrer_config['referrers'] : '';
             $referrer_redirect = isset($referrer_config['redirect']) ? $referrer_config['redirect'] : '';
             if ($referrer_enabled && count($referrer_referrers) && $referrer_redirect) {
                 $rules .= "if (\$http_cookie ~* \"w3tc_referrer=.*(" . implode('|', $referrer_referrers) . ")\") {\n";
                 $rules .= "    rewrite .* " . $referrer_redirect . " last;\n";
                 $rules .= "}\n";
             }
         }
     }
     /**
      * Don't accept POSTs
      */
     $rules .= "set \$w3tc_rewrite 1;\n";
     $rules .= "if (\$request_method = POST) {\n";
     $rules .= "    set \$w3tc_rewrite 0;\n";
     $rules .= "}\n";
     /**
      * Query string should be empty
      */
     $rules .= "if (\$query_string != \"\") {\n";
     $rules .= "    set \$w3tc_rewrite 0;\n";
     $rules .= "}\n";
     /**
      * Check hostname
      */
     if ($this->_config->get_boolean('pgcache.check.domain')) {
         $rules .= "if (\$http_host != \"" . w3_get_home_domain() . "\") {\n";
         $rules .= "    set \$w3tc_rewrite 0;\n";
         $rules .= "}\n";
     }
     /**
      * Check permalink structure trailing slash
      */
     if (substr($permalink_structure, -1) == '/') {
         if (!count($accept_uris)) {
             $rules .= "if (\$request_uri !~ \\/\$) {\n";
             $rules .= "    set \$w3tc_rewrite 0;\n";
             $rules .= "}\n";
         } else {
             $rules .= "set \$w3tc_rewrite2 1;\n";
             $rules .= "if (\$request_uri !~ \\/\$) {\n";
             $rules .= "    set \$w3tc_rewrite2 0;\n";
             $rules .= "}\n";
             $rules .= "if (\$request_uri ~* \"(" . implode('|', $accept_uris) . ")\") {\n";
             $rules .= "    set \$w3tc_rewrite2 1;\n";
             $rules .= "}\n";
             $rules .= "if (\$w3tc_rewrite2 != 1) {\n";
             $rules .= "    set \$w3tc_rewrite 0;\n";
             $rules .= "}\n";
         }
     }
     /**
      * Check for rejected URIs
      */
     if (!count($accept_files)) {
         $rules .= "if (\$request_uri ~* \"(" . implode('|', $reject_uris) . "\") {\n";
         $rules .= "    set \$w3tc_rewrite 0;\n";
         $rules .= "}\n";
     } else {
         $rules .= "set \$w3tc_rewrite3 1;\n";
         $rules .= "if (\$request_uri ~* \"(" . implode('|', $reject_uris) . ")\") {\n";
         $rules .= "    set \$w3tc_rewrite3 0;\n";
         $rules .= "}\n";
         $rules .= "if (\$request_uri ~* \"(" . implode('|', array_map('w3_preg_quote', $accept_files)) . ")\") {\n";
         $rules .= "    set \$w3tc_rewrite3 1;\n";
         $rules .= "}\n";
         $rules .= "if (\$w3tc_rewrite3 != 1) {\n";
         $rules .= "    set \$w3tc_rewrite 0;\n";
         $rules .= "}\n";
     }
     /**
      * Check for rejected cookies
      */
     $rules .= "if (\$http_cookie ~* \"(" . implode('|', array_map('w3_preg_quote', $reject_cookies)) . ")\") {\n";
     $rules .= "    set \$w3tc_rewrite 0;\n";
     $rules .= "}\n";
     /**
      * Check for rejected user agents
      */
     if (count($reject_user_agents)) {
         $rules .= "if (\$http_user_agent ~* \"(" . implode('|', array_map('w3_preg_quote', $reject_user_agents)) . ")\") {\n";
         $rules .= "    set \$w3tc_rewrite 0;\n";
         $rules .= "}\n";
     }
     /**
      * Network mode rules
      */
     if ($is_network) {
         /**
          * Detect domain
          */
         $rules .= "set \$w3tc_domain \"\";\n";
         $rules .= "if (\$http_host ~ ^(www\\.)?([a-z0-9\\-\\.]+\\.[a-z]+)\\.?(:[0-9]+)?\$) {\n";
         $rules .= "    set \$w3tc_domain \$2;\n";
         $rules .= "}\n";
         $replacement = '/w3tc-$w3tc_domain/';
         /**
          * If VHOST is off, detect blogname from URI
          */
         if (!$is_vhost) {
             $blognames = w3_get_blognames();
             if (count($blognames)) {
                 $rules .= "set \$w3tc_blogname \"\";\n";
                 $rules .= "if (\$request_uri ~ ^" . $base_path . "(" . implode('|', array_map('w3_preg_quote', $blognames)) . ")/) {\n";
                 $rules .= "    set \$w3tc_blogname \$1.;\n";
                 $rules .= "}\n";
                 $replacement = '/w3tc-$w3tc_blogname$w3tc_domain/';
             }
         }
         $cache_dir = preg_replace('~/w3tc.*?/~', $replacement, $cache_dir, 1);
     }
     /**
      * Check mobile groups
      */
     $rules .= "set \$w3tc_ua \"\";\n";
     if ($this->_config->get_boolean('mobile.enabled')) {
         $mobile_groups = array_reverse($this->_config->get_array('mobile.rgroups'));
         foreach ($mobile_groups as $mobile_group => $mobile_config) {
             $mobile_enabled = isset($mobile_config['enabled']) ? (bool) $mobile_config['enabled'] : false;
             $mobile_agents = isset($mobile_config['agents']) ? (array) $mobile_config['agents'] : '';
             $mobile_redirect = isset($mobile_config['redirect']) ? $mobile_config['redirect'] : '';
             if ($mobile_enabled && count($mobile_agents) && !$mobile_redirect) {
                 $rules .= "if (\$http_user_agent ~* \"(" . implode('|', $mobile_agents) . ")\") {\n";
                 $rules .= "    set \$w3tc_ua _" . $mobile_group . ";\n";
                 $rules .= "}\n";
             }
         }
     }
     /**
      * Check referrer groups
      */
     $rules .= "set \$w3tc_ref \"\";\n";
     if ($this->_config->get_boolean('referrer.enabled')) {
         $referrer_groups = array_reverse($this->_config->get_array('referrer.rgroups'));
         foreach ($referrer_groups as $referrer_group => $referrer_config) {
             $referrer_enabled = isset($referrer_config['enabled']) ? (bool) $referrer_config['enabled'] : false;
             $referrer_referrers = isset($referrer_config['referrers']) ? (array) $referrer_config['referrers'] : '';
             $referrer_redirect = isset($referrer_config['redirect']) ? $referrer_config['redirect'] : '';
             if ($referrer_enabled && count($referrer_referrers) && !$referrer_redirect) {
                 $rules .= "if (\$http_cookie ~* \"w3tc_referrer=.*(" . implode('|', $referrer_referrers) . ")\") {\n";
                 $rules .= "    set \$w3tc_ref _" . $referrer_group . ";\n";
                 $rules .= "}\n";
             }
         }
     }
     $rules .= "set \$w3tc_ssl \"\";\n";
     if ($this->_config->get_boolean('pgcache.cache.ssl')) {
         $rules .= "if (\$scheme = https) {\n";
         $rules .= "    set \$w3tc_ssl _ssl;\n";
         $rules .= "}\n";
     }
     $rules .= "set \$w3tc_enc \"\";\n";
     if ($this->_config->get_boolean('browsercache.enabled') && $this->_config->get_boolean('browsercache.html.compression')) {
         $rules .= "if (\$http_accept_encoding ~ gzip) {\n";
         $rules .= "    set \$w3tc_enc _gzip;\n";
         $rules .= "}\n";
     }
     $cache_path = str_replace(w3_get_document_root(), '', $cache_dir);
     $rules .= "set \$w3tc_ext \"\";\n";
     $rules .= "if (-f \"\$document_root" . $cache_path . "/\$request_uri/_index\$w3tc_ua\$w3tc_ref\$w3tc_ssl.html\$w3tc_enc\") {\n";
     $rules .= "    set \$w3tc_ext .html;\n";
     $rules .= "}\n";
     if ($this->_config->get_boolean('pgcache.cache.feed')) {
         $rules .= "if (-f \"\$document_root" . $cache_path . "/\$request_uri/_index\$w3tc_ua\$w3tc_ref\$w3tc_ssl.xml\$w3tc_enc\") {\n";
         $rules .= "    set \$w3tc_ext .xml;\n";
         $rules .= "}\n";
     }
     $rules .= "if (\$w3tc_ext = \"\") {\n";
     $rules .= "  set \$w3tc_rewrite 0;\n";
     $rules .= "}\n";
     $rules .= "if (\$w3tc_rewrite = 1) {\n";
     $rules .= "    rewrite .* \"" . $cache_path . "/\$request_uri/_index\$w3tc_ua\$w3tc_ref\$w3tc_ssl\$w3tc_ext\$w3tc_enc\" last;\n";
     $rules .= "}\n";
     $rules .= W3TC_MARKER_END_PGCACHE_CORE . "\n";
     return $rules;
 }
 /**
  * Returns the sitepath for multisite subfolder or subdomain path for multisite subdomain
  * @return string
  */
 private function _get_multisite_url_identifier()
 {
     if (defined('DOMAIN_MAPPING') && DOMAIN_MAPPING) {
         $parsedUrl = parse_url(w3_get_site_url());
         return $parsedUrl['host'];
     } elseif (w3_is_subdomain_install()) {
         $parsedUrl = parse_url(w3_get_domain_url());
         $urlparts = explode('.', $parsedUrl['host']);
         if (sizeof($urlparts) > 2) {
             $subdomain = array_shift($urlparts);
             return trim($subdomain, '/');
         }
     }
     return trim(w3_get_site_path(), '/');
 }
            <code>Disabled</code>
            <?php 
}
?>

        </li>

        <li>
            Network mode:
            <?php 
if (w3_is_network()) {
    ?>

            <code>Yes (<?php 
    echo w3_is_subdomain_install() ? 'subdomain' : 'subdir';
    ?>
)</code>
            <?php 
} else {
    ?>

            <code>No</code>
            <?php 
}
?>

        </li>
    </ul>
</div>
/**
 * Returns blog_id by home url
 * If database not initialized yet - returns 0
 *
 * @return integer
 */
function w3_blogmap_get_blog_data()
{
    $host = w3_get_host();
    // subdomain
    if (w3_is_subdomain_install()) {
        $blog_data = w3_blogmap_try_get_blog_data($host);
        if (is_null($blog_data)) {
            $GLOBALS['w3tc_blogmap_register_new_item'] = $host;
        }
        return $blog_data;
    } else {
        // try subdir blog
        $url = $host . $_SERVER['REQUEST_URI'];
        $pos = strpos($url, '?');
        if ($pos !== false) {
            $url = substr($url, 0, $pos);
        }
        $url = rtrim($url, '/');
        $start_url = $url;
        for (;;) {
            $blog_data = w3_blogmap_try_get_blog_data($url);
            if (!is_null($blog_data)) {
                return $blog_data;
            }
            $pos = strrpos($url, '/');
            if ($pos === false) {
                break;
            }
            $url = rtrim(substr($url, 0, $pos), '/');
        }
        $GLOBALS['w3tc_blogmap_register_new_item'] = $start_url;
        return null;
    }
}
Exemple #13
0
 /**
  * Save config action
  *
  * Do some actions on config keys update
  * Used in several places such as:
  *
  * 1. common config save
  * 2. import settings
  * 3. enable/disable preview mode
  *
  * @param W3_Config $old_config
  * @param W3_Config $new_config
  * @param boolean $preview
  * @return void
  */
 function config_save(&$old_config, &$new_config, $preview = null)
 {
     $browsercache_dependencies = array();
     if ($new_config->get_boolean('browsercache.enabled')) {
         $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.cssjs.replace', 'browsercache.html.replace', 'browsercache.other.replace'));
         if ($new_config->get_boolean('browsercache.cssjs.replace')) {
             $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.cssjs.compression', 'browsercache.cssjs.expires', 'browsercache.cssjs.lifetime', 'browsercache.cssjs.cache.control', 'browsercache.cssjs.cache.policy', 'browsercache.cssjs.etag', 'browsercache.cssjs.w3tc'));
         }
         if ($new_config->get_boolean('browsercache.html.replace')) {
             $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.html.compression', 'browsercache.html.expires', 'browsercache.html.lifetime', 'browsercache.html.cache.control', 'browsercache.html.cache.policy', 'browsercache.html.etag', 'browsercache.html.w3tc'));
         }
         if ($new_config->get_boolean('browsercache.other.replace')) {
             $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.other.compression', 'browsercache.other.expires', 'browsercache.other.lifetime', 'browsercache.other.cache.control', 'browsercache.other.cache.policy', 'browsercache.other.etag', 'browsercache.other.w3tc'));
         }
     }
     /**
      * Show need empty page cache notification
      */
     if ($new_config->get_boolean('pgcache.enabled')) {
         $pgcache_dependencies = array_merge($browsercache_dependencies, array('pgcache.debug', 'dbcache.enabled', 'objectcache.enabled', 'minify.enabled', 'cdn.enabled', 'mobile.enabled', 'referrer.enabled'));
         if ($new_config->get_boolean('dbcache.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('dbcache.debug'));
         }
         if ($new_config->get_boolean('objectcache.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('objectcache.debug'));
         }
         if ($new_config->get_boolean('minify.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('minify.auto', 'minify.debug', 'minify.rewrite', 'minify.html.enable', 'minify.html.engine', 'minify.html.inline.css', 'minify.html.inline.js', 'minify.html.strip.crlf', 'minify.html.comments.ignore', 'minify.css.enable', 'minify.css.groups', 'minify.js.enable', 'minify.js.groups', 'minify.htmltidy.options.clean', 'minify.htmltidy.options.hide-comments', 'minify.htmltidy.options.wrap', 'minify.reject.logged', 'minify.reject.ua', 'minify.reject.uri'));
         }
         if ($new_config->get_boolean('cdn.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('cdn.debug', 'cdn.engine', 'cdn.uploads.enable', 'cdn.includes.enable', 'cdn.includes.files', 'cdn.theme.enable', 'cdn.theme.files', 'cdn.minify.enable', 'cdn.custom.enable', 'cdn.custom.files', 'cdn.mirror.domain', 'cdn.mirror.ssl', 'cdn.netdna.domain', 'cdn.netdna.ssl', 'cdn.cotendo.domain', 'cdn.cotendo.ssl', 'cdn.ftp.domain', 'cdn.ftp.ssl', 'cdn.s3.cname', 'cdn.s3.ssl', 'cdn.cf.cname', 'cdn.cf.ssl', 'cdn.cf2.cname', 'cdn.cf2.ssl', 'cdn.rscf.cname', 'cdn.rscf.ssl', 'cdn.azure.cname', 'cdn.azure.ssl', 'cdn.reject.admins', 'cdn.reject.ua', 'cdn.reject.uri', 'cdn.reject.files'));
         }
         if ($new_config->get_boolean('mobile.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('mobile.rgroups'));
         }
         if ($new_config->get_boolean('referrer.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('referrer.rgroups'));
         }
         $old_pgcache_dependencies_values = array();
         $new_pgcache_dependencies_values = array();
         foreach ($pgcache_dependencies as $pgcache_dependency) {
             $old_pgcache_dependencies_values[] = $old_config->get($pgcache_dependency);
             $new_pgcache_dependencies_values[] = $new_config->get($pgcache_dependency);
         }
         if (serialize($old_pgcache_dependencies_values) != serialize($new_pgcache_dependencies_values)) {
             $new_config->set('notes.need_empty_pgcache', true);
         }
     }
     /**
      * Show need empty minify notification
      */
     if ($new_config->get_boolean('minify.enabled') && ($new_config->get_boolean('minify.css.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.css.groups'))) || $new_config->get_boolean('minify.js.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.js.groups'))))) {
         $minify_dependencies = array_merge($browsercache_dependencies, array('minify.auto', 'minify.debug', 'minify.options', 'minify.symlinks', 'minify.css.enable', 'minify.js.enable'));
         if ($new_config->get_boolean('minify.css.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.css.groups')))) {
             $minify_dependencies = array_merge($minify_dependencies, array('minify.css.engine', 'minify.css.combine', 'minify.css.strip.comments', 'minify.css.strip.crlf', 'minify.css.imports', 'minify.css.groups', 'minify.yuicss.path.java', 'minify.yuicss.path.jar', 'minify.yuicss.options.line-break', 'minify.csstidy.options.remove_bslash', 'minify.csstidy.options.compress_colors', 'minify.csstidy.options.compress_font-weight', 'minify.csstidy.options.lowercase_s', 'minify.csstidy.options.optimise_shorthands', 'minify.csstidy.options.remove_last_;', 'minify.csstidy.options.case_properties', 'minify.csstidy.options.sort_properties', 'minify.csstidy.options.sort_selectors', 'minify.csstidy.options.merge_selectors', 'minify.csstidy.options.discard_invalid_properties', 'minify.csstidy.options.css_level', 'minify.csstidy.options.preserve_css', 'minify.csstidy.options.timestamp', 'minify.csstidy.options.template'));
         }
         if ($new_config->get_boolean('minify.js.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.js.groups')))) {
             $minify_dependencies = array_merge($minify_dependencies, array('minify.js.engine', 'minify.js.combine.header', 'minify.js.combine.body', 'minify.js.combine.footer', 'minify.js.strip.comments', 'minify.js.strip.crlf', 'minify.js.groups', 'minify.yuijs.path.java', 'minify.yuijs.path.jar', 'minify.yuijs.options.line-break', 'minify.yuijs.options.nomunge', 'minify.yuijs.options.preserve-semi', 'minify.yuijs.options.disable-optimizations', 'minify.ccjs.path.java', 'minify.ccjs.path.jar', 'minify.ccjs.options.compilation_level', 'minify.ccjs.options.formatting'));
         }
         $old_minify_dependencies_values = array();
         $new_minify_dependencies_values = array();
         foreach ($minify_dependencies as $minify_dependency) {
             $old_minify_dependencies_values[] = $old_config->get($minify_dependency);
             $new_minify_dependencies_values[] = $new_config->get($minify_dependency);
         }
         if (serialize($old_minify_dependencies_values) != serialize($new_minify_dependencies_values)) {
             $new_config->set('notes.need_empty_minify', true);
         }
     }
     if ($new_config->get_boolean('cdn.enabled') && !w3_is_cdn_mirror($new_config->get_string('cdn.engine'))) {
         /**
          * Show notification when CDN enabled
          */
         if (!$old_config->get_boolean('cdn.enabled')) {
             $new_config->set('notes.cdn_upload', true);
         }
         /**
          * Show notification when Browser Cache settings changes
          */
         $cdn_dependencies = array('browsercache.enabled');
         if ($new_config->get_boolean('cdn.enabled')) {
             $cdn_dependencies = array('browsercache.cssjs.compression', 'browsercache.cssjs.expires', 'browsercache.cssjs.lifetime', 'browsercache.cssjs.cache.control', 'browsercache.cssjs.cache.policy', 'browsercache.cssjs.etag', 'browsercache.cssjs.w3tc', 'browsercache.html.compression', 'browsercache.html.expires', 'browsercache.html.lifetime', 'browsercache.html.cache.control', 'browsercache.html.cache.policy', 'browsercache.html.etag', 'browsercache.html.w3tc', 'browsercache.other.compression', 'browsercache.other.expires', 'browsercache.other.lifetime', 'browsercache.other.cache.control', 'browsercache.other.cache.policy', 'browsercache.other.etag', 'browsercache.other.w3tc');
         }
         $old_cdn_dependencies_values = array();
         $new_cdn_dependencies_values = array();
         foreach ($cdn_dependencies as $cdn_dependency) {
             $old_cdn_dependencies_values[] = $old_config->get($cdn_dependency);
             $new_cdn_dependencies_values[] = $new_config->get($cdn_dependency);
         }
         if (serialize($old_cdn_dependencies_values) != serialize($new_cdn_dependencies_values)) {
             $new_config->set('notes.cdn_reupload', true);
         }
     }
     /**
      * Show need empty object cache notification
      */
     if ($this->_config->get_boolean('objectcache.enabled')) {
         $objectcache_dependencies = array('objectcache.reject.admin', 'objectcache.reject.uri', 'objectcache.groups.global', 'objectcache.groups.nonpersistent');
         $old_objectcache_dependencies_values = array();
         $new_objectcache_dependencies_values = array();
         foreach ($objectcache_dependencies as $objectcache_dependency) {
             $old_objectcache_dependencies_values[] = $old_config->get($objectcache_dependency);
             $new_objectcache_dependencies_values[] = $new_config->get($objectcache_dependency);
         }
         if (serialize($old_objectcache_dependencies_values) != serialize($new_objectcache_dependencies_values)) {
             $new_config->set('notes.need_empty_objectcache', true);
         }
     }
     /**
      * Save config
      */
     if ($new_config->save($preview)) {
         require_once W3TC_LIB_W3_DIR . '/Plugin/PgCache.php';
         require_once W3TC_LIB_W3_DIR . '/Plugin/DbCache.php';
         require_once W3TC_LIB_W3_DIR . '/Plugin/ObjectCache.php';
         require_once W3TC_LIB_W3_DIR . '/Plugin/BrowserCache.php';
         require_once W3TC_LIB_W3_DIR . '/Plugin/Cdn.php';
         $w3_plugin_pgcache =& W3_Plugin_PgCache::instance();
         $w3_plugin_dbcache =& W3_Plugin_DbCache::instance();
         $w3_plugin_objectcache =& W3_Plugin_ObjectCache::instance();
         $w3_plugin_browsercache =& W3_Plugin_BrowserCache::instance();
         $w3_plugin_cdn =& W3_Plugin_Cdn::instance();
         if (W3TC_PHP5) {
             require_once W3TC_LIB_W3_DIR . '/Plugin/Minify.php';
             $w3_plugin_minify =& W3_Plugin_Minify::instance();
         }
         /**
          * Empty caches on engine change or cache enable/disable
          */
         if ($old_config->get_string('pgcache.engine') != $new_config->get_string('pgcache.engine') || $old_config->get_string('pgcache.enabled') != $new_config->get_string('pgcache.enabled')) {
             $this->flush_pgcache();
         }
         if ($old_config->get_string('dbcache.engine') != $new_config->get_string('dbcache.engine') || $old_config->get_string('dbcache.enabled') != $new_config->get_string('dbcache.enabled')) {
             $this->flush_dbcache();
         }
         if ($old_config->get_string('objectcache.engine') != $new_config->get_string('objectcache.engine') || $old_config->get_string('objectcache.enabled') != $new_config->get_string('objectcache.enabled')) {
             $this->flush_objectcache();
         }
         if ($old_config->get_string('minify.engine') != $new_config->get_string('minify.engine') || $old_config->get_string('minify.enabled') != $new_config->get_string('minify.enabled')) {
             $this->flush_minify();
         }
         /**
          * Unschedule events if changed file gc interval
          */
         if ($old_config->get_integer('pgcache.file.gc') != $new_config->get_integer('pgcache.file.gc')) {
             $w3_plugin_pgcache->unschedule();
         }
         if ($old_config->get_integer('pgcache.prime.interval') != $new_config->get_integer('pgcache.prime.interval')) {
             $w3_plugin_pgcache->unschedule_prime();
         }
         if ($old_config->get_integer('dbcache.file.gc') != $new_config->get_integer('dbcache.file.gc')) {
             $w3_plugin_dbcache->unschedule();
         }
         if ($old_config->get_integer('objectcache.file.gc') != $new_config->get_integer('objectcache.file.gc')) {
             $w3_plugin_objectcache->unschedule();
         }
         if ($old_config->get_integer('cdn.autoupload.interval') != $new_config->get_integer('cdn.autoupload.interval')) {
             $w3_plugin_cdn->unschedule_upload();
         }
         if (W3TC_PHP5 && $old_config->get_integer('minify.file.gc') != $new_config->get_integer('minify.file.gc')) {
             $w3_plugin_minify->unschedule();
         }
         /**
          * Create CDN queue table
          */
         if (($old_config->get_boolean('cdn.enabled') != $new_config->get_boolean('cdn.enabled') || $old_config->get_string('cdn.engine') != $new_config->get_string('cdn.engine')) && $new_config->get_boolean('cdn.enabled') && !w3_is_cdn_mirror($new_config->get_string('cdn.engine'))) {
             $w3_plugin_cdn->table_create();
         }
         /**
          * Update CloudFront CNAMEs
          */
         $update_cf_cnames = false;
         if ($new_config->get_boolean('cdn.enabled') && in_array($new_config->get_string('cdn.engine'), array('cf', 'cf2'))) {
             if ($new_config->get_string('cdn.engine') == 'cf') {
                 $old_cnames = $old_config->get_array('cdn.cf.cname');
                 $new_cnames = $new_config->get_array('cdn.cf.cname');
             } else {
                 $old_cnames = $old_config->get_array('cdn.cf2.cname');
                 $new_cnames = $new_config->get_array('cdn.cf2.cname');
             }
             if (count($old_cnames) != count($new_cnames) || count(array_diff($old_cnames, $new_cnames))) {
                 $update_cf_cnames = true;
             }
         }
         /**
          * Refresh config
          */
         $old_config->load();
         /**
          * Schedule events
          */
         $w3_plugin_pgcache->schedule();
         $w3_plugin_pgcache->schedule_prime();
         $w3_plugin_dbcache->schedule();
         $w3_plugin_objectcache->schedule();
         $w3_plugin_cdn->schedule();
         $w3_plugin_cdn->schedule_upload();
         if (W3TC_PHP5) {
             $w3_plugin_minify->schedule();
         }
         /**
          * Update support us option
          */
         $this->link_update();
         /**
          * Write page cache rewrite rules
          */
         if ($new_config->get_boolean('pgcache.enabled') && $new_config->get_string('pgcache.engine') == 'file_generic') {
             if (w3_can_modify_rules(w3_get_pgcache_rules_core_path())) {
                 $w3_plugin_pgcache->write_rules_core();
             }
             if (w3_can_modify_rules(w3_get_pgcache_rules_cache_path())) {
                 $w3_plugin_pgcache->write_rules_cache();
             }
         } else {
             if (w3_can_modify_rules(w3_get_pgcache_rules_core_path())) {
                 $w3_plugin_pgcache->remove_rules_core();
             }
             if (w3_can_modify_rules(w3_get_pgcache_rules_cache_path())) {
                 $w3_plugin_pgcache->remove_rules_cache();
             }
         }
         /**
          * Write browsercache rules
          */
         if ($new_config->get_boolean('browsercache.enabled')) {
             if (w3_can_modify_rules(w3_get_browsercache_rules_cache_path())) {
                 $w3_plugin_browsercache->write_rules_cache();
             }
             if ($new_config->get_boolean('browsercache.no404wp')) {
                 if (w3_can_modify_rules(w3_get_browsercache_rules_no404wp_path())) {
                     $w3_plugin_browsercache->write_rules_no404wp();
                 }
             } else {
                 if (w3_can_modify_rules(w3_get_browsercache_rules_no404wp_path())) {
                     $w3_plugin_browsercache->remove_rules_no404wp();
                 }
             }
         } else {
             if (w3_can_modify_rules(w3_get_browsercache_rules_cache_path())) {
                 $w3_plugin_browsercache->remove_rules_cache();
             }
             if (w3_can_modify_rules(w3_get_browsercache_rules_no404wp_path())) {
                 $w3_plugin_browsercache->remove_rules_no404wp();
             }
         }
         /**
          * Write minify rewrite rules
          */
         if (W3TC_PHP5) {
             if ($new_config->get_boolean('minify.enabled') && $new_config->get_boolean('minify.rewrite')) {
                 if (w3_can_modify_rules(w3_get_minify_rules_core_path())) {
                     $w3_plugin_minify->write_rules_core();
                 }
                 if ($this->_config->get_string('minify.engine') == 'file') {
                     if (w3_can_modify_rules(w3_get_minify_rules_cache_path())) {
                         $w3_plugin_minify->write_rules_cache();
                     }
                 } else {
                     if (w3_can_modify_rules(w3_get_minify_rules_cache_path())) {
                         $w3_plugin_minify->remove_rules_cache();
                     }
                 }
             } else {
                 if (w3_can_modify_rules(w3_get_minify_rules_core_path())) {
                     $w3_plugin_minify->remove_rules_core();
                 }
                 if (w3_can_modify_rules(w3_get_minify_rules_cache_path())) {
                     $w3_plugin_minify->remove_rules_cache();
                 }
             }
         }
         /**
          * Auto upload minify files to CDN
          */
         if ($new_config->get_boolean('minify.enabled') && $new_config->get_boolean('minify.upload') && $new_config->get_boolean('cdn.enabled') && !w3_is_cdn_mirror($new_config->get_string('cdn.engine'))) {
             $this->cdn_upload_minify();
         }
         /**
          * Auto upload browsercache files to CDN
          */
         if ($new_config->get_boolean('cdn.enabled') && $new_config->get_string('cdn.engine') == 'ftp') {
             $this->cdn_delete_browsercache();
             if ($new_config->get_boolean('browsercache.enabled')) {
                 $this->cdn_upload_browsercache();
             }
         }
         /**
          * Update CloudFront CNAMEs
          */
         if ($update_cf_cnames) {
             $error = null;
             $cdn = $w3_plugin_cdn->get_cdn();
             $cdn->update_cnames($error);
         }
         /**
          * Save blognames into file
          */
         if (w3_is_network() && !w3_is_subdomain_install()) {
             w3_save_blognames();
         }
         return true;
     }
     return false;
 }
 /**
  * Reads legacy config file
  *
  * @param object $compiled_config
  * @return array
  */
 private function _import_legacy_config($compiled_config)
 {
     $suffix = '';
     if ($this->_blog_id > 0) {
         if (w3_is_network()) {
             if (w3_is_subdomain_install()) {
                 $suffix = '-' . w3_get_domain(w3_get_host());
             } else {
                 // try subdir blog
                 $request_uri = rtrim($_SERVER['REQUEST_URI'], '/');
                 $site_home_uri = w3_get_base_path();
                 if (substr($request_uri, 0, strlen($site_home_uri)) == $site_home_uri) {
                     $request_path_in_wp = '/' . substr($request_uri, strlen($site_home_uri));
                     $n = strpos($request_path_in_wp, '/', 1);
                     if ($n === false) {
                         $blog_path_in_wp = substr($request_path_in_wp, 1);
                     } else {
                         $blog_path_in_wp = substr($request_path_in_wp, 1, $n - 1);
                     }
                     $suffix = '-' . ($blog_path_in_wp != 'wp-admin' ? $blog_path_in_wp . '.' : '') . w3_get_domain(w3_get_host());
                 }
             }
         }
     }
     $filename = WP_CONTENT_DIR . '/w3-total-cache-config' . $suffix . '.php';
     return $compiled_config->get_array_from_file($filename);
 }
 /**
  * Options page
  *
  * @return void
  */
 function options()
 {
     $remove_results = array();
     $w3tc_error = array();
     w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
     $preview = $this->_config->is_preview();
     if (w3_is_network() && !$this->is_master()) {
         $this->_config_master = new W3_Config(true);
     } else {
         $this->_config_master = $this->_config;
     }
     $w3_verify = w3_instance('W3_FileVerification');
     /**
      * Check for page cache availability
      */
     $wp_config_edit = false;
     if ($this->_config->get_boolean('pgcache.enabled')) {
         if (!defined('WP_CACHE') || !WP_CACHE) {
             try {
                 $w3_plugin_admin = w3_instance('W3_Plugin_PgCacheAdmin');
                 $w3_plugin_admin->enable_wp_cache(w3_is_network() ? network_admin_url('admin.php?page=w3tc_general') : admin_url('admin.php?page=w3tc_general'));
             } catch (Exception $e) {
                 $ftp_message = '';
                 if (!isset($this->_ftp_form) && $e instanceof FilesystemCredentialException) {
                     $this->_ftp_form = $e->ftp_form();
                     $ftp_message = ' Or use the <a href="#ftp_upload_form">FTP form</a> below.';
                 } elseif ($e instanceof FileOperationException) {
                     $file_operation_exception = true;
                     $wp_config_edit = true;
                 }
                 if (!$this->_disable_add_in_files_notification) {
                     $this->_errors[] = sprintf('Page caching is not available: please add: <strong>define(\'WP_CACHE\', true);</strong> to <strong>%s</strong>. %s', w3_get_wp_config_path(), $ftp_message);
                 }
             }
         }
         if (!$w3_verify->advanced_cache_check()) {
             if (!$this->_disable_add_in_files_notification) {
                 $this->_errors[] = sprintf('Page caching is not available. The current add-in %s is either missing, an incorrect file or an old version. De-activate the plugin, remove the file, then activate the plugin again.', W3TC_ADDIN_FILE_ADVANCED_CACHE);
             }
         } elseif ($this->_config->get_string('pgcache.engine') == 'file_generic' && $this->_config->get_boolean('config.check') && w3_can_check_rules()) {
             $w3_plugin_pgcache = w3_instance('W3_Plugin_PgCacheAdmin');
             if (w3_get_blog_id() == 0) {
                 if ($w3_plugin_pgcache->check_rules_core()) {
                     if ($this->_config->get_boolean('pgcache.debug') && !$this->test_rewrite_pgcache()) {
                         $url = w3_get_home_url() . '/w3tc_rewrite_test';
                         $key = sprintf('w3tc_rewrite_test_result_%s', substr(md5($url), 0, 16));
                         $result = get_transient($key);
                         $tech_message = '%s contains rules to rewrite url %2$s/w3tc_rewrite_test into %2$s/?w3tc_rewrite_test which, if handled by plugin, return "OK" message.<br/>';
                         $tech_message .= 'The plugin made a request to %s/w3tc_rewrite_test but received: <br />%s<br />';
                         $tech_message .= 'instead of "OK" response. <br />';
                         $tech_message .= 'Unfortunately disk enhanced page caching will not function without custom rewrite rules. Please ask your server administrator for assistance. Also refer to <a href="%s">the install page</a>  for the rules for your server.';
                         $tech_message = sprintf($tech_message, w3_is_nginx() ? 'nginx configuration file' : '.htaccess file', w3_get_home_url(), $result, admin_url('admin.php?page=w3tc_install'));
                         $error = 'It appears Page Cache <acronym title="Uniform Resource Locator">URL</acronym> rewriting is not working. If using apache, verify that the server configuration allows .htaccess. Or if using nginx verify all configuration files are included in the configuration file (and that you have reloaded / restarted nginx).';
                         $error .= ' <br /><a id="w3tc_read_technical_info" href="#">Technical info</a><div id="w3tc_technical_info">' . $tech_message . '</div>';
                         $this->_errors[] = $error;
                     }
                     if ($w3_plugin_pgcache->check_rules_has_legacy()) {
                         try {
                             $w3_plugin_pgcache->remove_rules_legacy();
                             $w3_plugin_pgcache->write_rules_core();
                         } catch (Exception $e) {
                             $this->_rule_errors_root[] = sprintf('Edit the configuration file (<strong>%s</strong>) and ' . 'remove all lines between and including <strong>%s</strong> and ' . '<strong>%s</strong> markers inclusive.', w3_get_pgcache_rules_core_path(), W3TC_MARKER_BEGIN_PGCACHE_LEGACY, W3TC_MARKER_END_PGCACHE_LEGACY);
                             if (!isset($this->_ftp_form) && $e instanceof FilesystemCredentialException) {
                                 $this->_ftp_form = $e->ftp_form();
                             } elseif ($e instanceof FileOperationException) {
                                 $file_operation_exception = true;
                             }
                         }
                     }
                 } else {
                     if ($w3_plugin_pgcache->check_rules_has_core()) {
                         $instructions = sprintf('replace the content of the server configuration ' . 'file <strong>%s</strong> between %s and %s markers inclusive. Required after modifying Page Cache / Browser Cache settings or plugin update', w3_get_pgcache_rules_core_path(), W3TC_MARKER_BEGIN_PGCACHE_CORE, W3TC_MARKER_END_PGCACHE_CORE);
                     } elseif ($w3_plugin_pgcache->check_rules_has_legacy()) {
                         $legacy = true;
                         $instructions = sprintf('replace the content of the server configuration ' . 'file <strong>%s</strong> between %s and %s markers inclusive', w3_get_pgcache_rules_core_path(), W3TC_MARKER_BEGIN_PGCACHE_LEGACY, W3TC_MARKER_END_PGCACHE_LEGACY);
                     } else {
                         $instructions = sprintf('add the following rules into the server ' . 'configuration file (<strong>%s</strong>) of the site above the ' . 'WordPress directives', w3_get_pgcache_rules_core_path());
                     }
                     if (isset($instructions)) {
                         try {
                             if (isset($legacy) && $legacy) {
                                 $w3_plugin_pgcache->remove_rules_legacy();
                             }
                             $w3_plugin_pgcache->write_rules_core();
                         } catch (Exception $e) {
                             $this->_rule_errors_root[] = sprintf('To enable Disk enhanced page caching, ' . $instructions . ' %s <textarea class="w3tc-rules"' . ' cols="120" rows="10" readonly="readonly">%s</textarea>.', $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($w3_plugin_pgcache->generate_rules_core()));
                             if (!isset($this->_ftp_form) && $e instanceof FilesystemCredentialException) {
                                 $this->_ftp_form = $e->ftp_form();
                             } elseif ($e instanceof FileOperationException) {
                                 $file_operation_exception = true;
                             }
                         }
                     }
                 }
                 if ($this->_config->get_boolean('notes.pgcache_rules_wpsc') && $w3_plugin_pgcache->check_rules_wpsc()) {
                     $this->_errors[] = sprintf('WP Super Cache rewrite rules have been found. To remove them manually, edit the configuration file (<strong>%s</strong>) and remove all lines between and including <strong>%s</strong> and <strong>%s</strong> markers inclusive. Or if permission allow this can be done automatically, by clicking here: %s. %s', w3_get_pgcache_rules_core_path(), W3TC_MARKER_BEGIN_PGCACHE_WPSC, W3TC_MARKER_END_PGCACHE_WPSC, $this->button_link('auto-remove', wp_nonce_url(sprintf('admin.php?page=%s&w3tc_pgcache_remove_rules_wpsc', $this->_page), 'w3tc')), $this->button_hide_note('Hide this message', 'pgcache_rules_wpsc'));
                 }
             }
             if (!$w3_plugin_pgcache->check_rules_cache()) {
                 if (w3_is_nginx() && w3_get_blog_id() == 0) {
                     try {
                         $w3_plugin_pgcache->write_rules_cache(true);
                     } catch (Exception $e) {
                         $this->_rule_errors_root[] = sprintf('To enable Disk enhanced page caching, add ' . 'the following rules into the server configuration file ' . '(<strong>%s</strong>) of the site %s <textarea class="w3tc-rules" ' . 'cols="120" rows="10" readonly="readonly">%s</textarea>.', w3_get_pgcache_rules_cache_path(), $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($w3_plugin_pgcache->generate_rules_cache()));
                         if (!isset($this->_ftp_form) && $e instanceof FilesystemCredentialException) {
                             $this->_ftp_form = $e->ftp_form();
                         } elseif ($e instanceof FileOperationException) {
                             $file_operation_exception = true;
                         }
                     }
                 } else {
                     $this->_rule_errors[] = array(sprintf('To enable Disk enhanced page caching, add ' . 'the following rules into the server configuration file ' . '(<strong>%s</strong>) of the site %s <textarea class="w3tc-rules" ' . 'cols="120" rows="10" readonly="readonly">%s</textarea>.', w3_get_pgcache_rules_cache_path(), $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($w3_plugin_pgcache->generate_rules_cache())), 'pgcache_write_rules_cache');
                 }
             }
         }
     } elseif (w3_get_blog_id() == 0 && $this->_config->get_boolean('config.check') && w3_can_check_rules()) {
         $w3_plugin_pgcache = w3_instance('W3_Plugin_PgCacheAdmin');
         $remove_results[] = $w3_plugin_pgcache->remove_rules_cache_multisite_nginx_with_message();
     }
     if (w3_get_blog_id() == 0 && $this->_config->get_boolean('config.check') && w3_can_check_rules()) {
         $w3_plugin_pgcache = w3_instance('W3_Plugin_PgCacheAdmin');
         $remove_results[] = $w3_plugin_pgcache->remove_rules_core_with_message(true);
     }
     /**
      * Check for minify availability
      */
     if ($this->_config->get_boolean('minify.enabled')) {
         $minify_rule_error = '';
         if ($this->_config->get_boolean('minify.rewrite') && $this->_config->get_boolean('config.check') && w3_can_check_rules()) {
             $w3_plugin_minify = w3_instance('W3_Plugin_MinifyAdmin');
             if ($w3_plugin_minify->check_rules_core()) {
                 if (!$this->test_rewrite_minify() && (!w3_is_multisite() || w3_is_multisite() && w3_get_blog_id() != 0)) {
                     $this->_errors[] = 'It appears Minify <acronym title="Uniform Resource Locator">URL</acronym> rewriting is not working. If using apache, verify that the server configuration allows .htaccess. Or if using nginx verify all configuration files are included in the main configuration fail (and that you have reloaded / restarted nginx).';
                 }
                 if ($w3_plugin_minify->check_rules_has_legacy()) {
                     $this->_rule_errors[] = array(sprintf('Edit the configuration file (<strong>%s</strong>) and ' . 'remove all lines between and including <strong>%s</strong> and ' . '<strong>%s</strong> markers inclusive.', w3_get_minify_rules_core_path(), W3TC_MARKER_BEGIN_MINIFY_LEGACY, W3TC_MARKER_END_MINIFY_LEGACY), 'minify_remove_rules_legacy');
                 }
             } else {
                 if ($w3_plugin_minify->check_rules_has_core()) {
                     $minify_rule_error = sprintf('replace the content of ' . 'the server configuration file <strong>%s</strong> between %s and ' . '%s markers inclusive', w3_get_minify_rules_core_path(), W3TC_MARKER_BEGIN_MINIFY_CORE, W3TC_MARKER_END_MINIFY_CORE);
                 } elseif ($w3_plugin_minify->check_rules_has_legacy()) {
                     $minify_rule_error = sprintf('replace the content of ' . 'the server configuration file <strong>%s</strong> between %s and ' . '%s markers inclusive', w3_get_minify_rules_core_path(), W3TC_MARKER_BEGIN_MINIFY_LEGACY, W3TC_MARKER_END_MINIFY_LEGACY);
                 } else {
                     $minify_rule_error = sprintf('add the following rules ' . 'into the server configuration file (<strong>%s</strong>) of the site', w3_get_minify_rules_core_path());
                 }
                 $minify_rule_content = $w3_plugin_minify->generate_rules_core();
             }
             if ($this->_config->get_string('minify.engine') == 'file' && !$w3_plugin_minify->check_rules_cache()) {
                 if ($minify_rule_error == '') {
                     $minify_rule_error = sprintf('add the following rules ' . 'into the server configuration file (<strong>%s</strong>) of the ' . 'site', w3_get_minify_rules_cache_path());
                 }
                 $minify_rule_content .= $w3_plugin_minify->generate_rules_cache();
             }
             if ($minify_rule_error != '' && w3_get_blog_id() == 0) {
                 $this->_rule_errors[] = array(sprintf('To enable Minify, ' . $minify_rule_error . ' %s <textarea class="w3tc-rules" cols="120" rows="10" ' . 'readonly="readonly">%s</textarea>.', $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($minify_rule_content)), 'minify_write_rules');
             }
             if ((w3_is_apache() || w3_is_litespeed()) && w3_is_network() && !w3_is_subdomain_install() && !$w3_plugin_minify->check_multisite_subfolder_test_rules_cache_apache()) {
                 $minify_rule_test = sprintf('To enable Minify Rewrite Test, add the following rules ' . 'into the server configuration file (<strong>%s</strong>) of the ' . 'site', w3_get_document_root() . '/.htaccess');
                 $minify_test_rule_content = $w3_plugin_minify->generate_multisite_subfolder_rewrite_test_rules_apache();
                 $this->_rule_errors[] = array(sprintf($minify_rule_test . ' %s <textarea class="w3tc-rules" cols="120" rows="10" ' . 'readonly="readonly">%s</textarea>.', $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($minify_test_rule_content)), 'minify_write_test_rules');
             }
         }
         /**
          * Minifiers availability error handling
          */
         $minifiers_errors = array();
         if ($this->_config->get_string('minify.js.engine') == 'yuijs') {
             $path_java = $this->_config->get_string('minify.yuijs.path.java');
             $path_jar = $this->_config->get_string('minify.yuijs.path.jar');
             if (!file_exists($path_java)) {
                 $minifiers_errors[] = sprintf('YUI Compressor (JS): JAVA executable path was not found. The default minifier JSMin will be used instead.');
             } elseif (!file_exists($path_jar)) {
                 $minifiers_errors[] = sprintf('YUI Compressor (JS): JAR file path was not found. The default minifier JSMin will be used instead.');
             }
         }
         if ($this->_config->get_string('minify.css.engine') == 'yuicss') {
             $path_java = $this->_config->get_string('minify.yuicss.path.java');
             $path_jar = $this->_config->get_string('minify.yuicss.path.jar');
             if (!file_exists($path_java)) {
                 $minifiers_errors[] = sprintf('YUI Compressor (CSS): JAVA executable path was not found. The default CSS minifier will be used instead.');
             } elseif (!file_exists($path_jar)) {
                 $minifiers_errors[] = sprintf('YUI Compressor (CSS): JAR file path was not found. The default CSS minifier will be used instead.');
             }
         }
         if ($this->_config->get_string('minify.js.engine') == 'ccjs') {
             $path_java = $this->_config->get_string('minify.ccjs.path.java');
             $path_jar = $this->_config->get_string('minify.ccjs.path.jar');
             if (!file_exists($path_java)) {
                 $minifiers_errors[] = sprintf('Closure Compiler: JAVA executable path was not found. The default minifier JSMin will be used instead.');
             } elseif (!file_exists($path_jar)) {
                 $minifiers_errors[] = sprintf('Closure Compiler: JAR file path was not found. The default minifier JSMin will be used instead.');
             }
         }
         if (count($minifiers_errors)) {
             $minify_error = 'The following minifiers cannot be found or are no longer working:</p><ul>';
             foreach ($minifiers_errors as $minifiers_error) {
                 $minify_error .= '<li>' . $minifiers_error . '</li>';
             }
             $minify_error .= '</ul><p>This message will automatically disappear once the issue is resolved.';
             $this->_errors[] = $minify_error;
         }
     }
     /**
      * Check for browser cache availability
      */
     if ($this->_config->get_boolean('browsercache.enabled') && $this->_config->get_boolean('config.check') && w3_can_check_rules()) {
         $w3_plugin_browsercache = w3_instance('W3_Plugin_BrowserCacheAdmin');
         if (!$w3_plugin_browsercache->check_rules_cache()) {
             try {
                 $w3_plugin_browsercache->write_rules_cache();
             } catch (Exception $e) {
                 $this->_rule_errors_root[] = sprintf('To enable Browser caching, add the following rules ' . 'into the server configuration file (<strong>%s</strong>) of the site %s ' . '<textarea class="w3tc-rules" cols="120" rows="10" readonly="readonly">%s' . '</textarea>.', w3_get_browsercache_rules_cache_path(), $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($w3_plugin_browsercache->generate_rules_cache()));
                 if (!isset($this->_ftp_form) && $e instanceof FilesystemCredentialException) {
                     $this->_ftp_form = $e->ftp_form();
                 } elseif ($e instanceof FileOperationException) {
                     $file_operation_exception = true;
                 }
             }
         }
         if ($this->_config->get_boolean('notes.browsercache_rules_no404wp') && $this->_config->get_boolean('browsercache.no404wp') && !$w3_plugin_browsercache->check_rules_no404wp()) {
             try {
                 $w3_plugin_browsercache->write_rules_no404wp();
             } catch (Exception $e) {
                 $ftp_message = '';
                 if (!isset($this->_ftp_form) && $e instanceof FilesystemCredentialException) {
                     $this->_ftp_form = $e->ftp_form();
                     $ftp_message = ' Or try using the <a href="#ftp_upload_form">FTP form</a> below.';
                 } elseif ($e instanceof FileOperationException) {
                     $file_operation_exception = true;
                 }
                 $this->_errors[] = sprintf('"Do not process 404 errors for static objects with WordPress" feature
                                         is not active. To enable it, add the following rules into the server
                                         configuration file (<strong>%s</strong>) of the site %s
                                         <textarea class="w3tc-rules" cols="120" rows="10" readonly="readonly">%s</textarea>.
                                         <br />%s %s', w3_get_browsercache_rules_no404wp_path(), $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($w3_plugin_browsercache->generate_rules_no404wp()), $ftp_message, $this->button_hide_note('Hide this message', 'browsercache_rules_no404wp'));
             }
         }
         $remove_results[] = $w3_plugin_browsercache->remove_rules_no404wp_with_message(true, $this->button_hide_note('Hide this message', 'browsercache_rules_no404wp'));
     } elseif (!$this->_config->get_boolean('browsercache.enabled') && $this->_config->get_boolean('config.check') && w3_can_check_rules()) {
         $w3_plugin_browsercache = w3_instance('W3_Plugin_BrowserCacheAdmin');
         $remove_results[] = $w3_plugin_browsercache->remove_rules_cache_with_message();
         $remove_results[] = $w3_plugin_browsercache->remove_rules_no404wp_with_message(false, $this->button_hide_note('Hide this message', 'browsercache_rules_no404wp'));
     }
     /**
      * Check for database cache availability
      */
     if ($this->_config->get_boolean('dbcache.enabled')) {
         if (!$this->_disable_add_in_files_notification && !$w3_verify->db_check()) {
             $this->_errors[] = sprintf('Database caching is not available. The current add-in %s is either missing, an incorrect file or an old version. De-activate the plugin, remove the file, then activate the plugin again.', W3TC_ADDIN_FILE_DB);
         }
     }
     /**
      * Check for object cache availability
      */
     if ($this->_config->get_boolean('objectcache.enabled')) {
         if (!$this->_disable_add_in_files_notification && !$w3_verify->objectcache_check()) {
             $this->_errors[] = sprintf('Object caching is not available. The current add-in %s is either missing, an incorrect file or an old version. De-activate the plugin, remove the file, then activate the plugin again.', W3TC_ADDIN_FILE_OBJECT_CACHE);
         }
     }
     /**
      * Check memcached
      */
     $memcaches_errors = array();
     if ($this->_config->get_boolean('pgcache.enabled') && $this->_config->get_string('pgcache.engine') == 'memcached') {
         $pgcache_memcached_servers = $this->_config->get_array('pgcache.memcached.servers');
         if (!$this->is_memcache_available($pgcache_memcached_servers)) {
             $memcaches_errors[] = sprintf('Page Cache: %s.', implode(', ', $pgcache_memcached_servers));
         }
     }
     if ($this->_config->get_boolean('minify.enabled') && $this->_config->get_string('minify.engine') == 'memcached') {
         $minify_memcached_servers = $this->_config->get_array('minify.memcached.servers');
         if (!$this->is_memcache_available($minify_memcached_servers)) {
             $memcaches_errors[] = sprintf('Minify: %s.', implode(', ', $minify_memcached_servers));
         }
     }
     if ($this->_config->get_boolean('dbcache.enabled') && $this->_config->get_string('dbcache.engine') == 'memcached') {
         $dbcache_memcached_servers = $this->_config->get_array('dbcache.memcached.servers');
         if (!$this->is_memcache_available($dbcache_memcached_servers)) {
             $memcaches_errors[] = sprintf('Database Cache: %s.', implode(', ', $dbcache_memcached_servers));
         }
     }
     if ($this->_config->get_boolean('objectcache.enabled') && $this->_config->get_string('objectcache.engine') == 'memcached') {
         $objectcache_memcached_servers = $this->_config->get_array('objectcache.memcached.servers');
         if (!$this->is_memcache_available($objectcache_memcached_servers)) {
             $memcaches_errors[] = sprintf('Object Cache: %s.', implode(', ', $objectcache_memcached_servers));
         }
     }
     if (count($memcaches_errors)) {
         $memcache_error = 'The following memcached servers are not responding or not running:</p><ul>';
         foreach ($memcaches_errors as $memcaches_error) {
             $memcache_error .= '<li>' . $memcaches_error . '</li>';
         }
         $memcache_error .= '</ul><p>This message will automatically disappear once the issue is resolved.';
         $this->_errors[] = $memcache_error;
     }
     /**
      * Check PHP version
      */
     if (!W3TC_PHP5 && $this->_config->get_boolean('notes.php_is_old')) {
         $this->_notes[] = sprintf('Unfortunately, <strong>PHP5</strong> is required for full functionality of this plugin; incompatible features are automatically disabled. Please upgrade if possible. %s', $this->button_hide_note('Hide this message', 'php_is_old'));
     }
     /**
      * Check CURL extension
      */
     if ($this->_config->get_boolean('notes.no_curl') && $this->_config->get_boolean('cdn.enabled') && !function_exists('curl_init')) {
         $this->_notes[] = sprintf('The <strong>CURL PHP</strong> extension is not available. Please install it to enable S3 or CloudFront functionality. %s', $this->button_hide_note('Hide this message', 'no_curl'));
     }
     /**
      * Check Zlib extension
      */
     if ($this->_config->get_boolean('notes.no_zlib') && !function_exists('gzencode')) {
         $this->_notes[] = sprintf('Unfortunately the PHP installation is incomplete, the <strong>zlib module is missing</strong>. This is a core PHP module. Notify the server administrator. %s', $this->button_hide_note('Hide this message', 'no_zlib'));
     }
     /**
      * Check if Zlib output compression is enabled
      */
     if ($this->_config->get_boolean('notes.zlib_output_compression') && w3_zlib_output_compression()) {
         $this->_notes[] = sprintf('Either the PHP configuration, web server configuration or a script in the WordPress installation has <strong>zlib.output_compression</strong> enabled.<br />Please locate and disable this setting to ensure proper HTTP compression behavior. %s', $this->button_hide_note('Hide this message', 'zlib_output_compression'));
     }
     /**
      * Check wp-content permissions
      */
     if (!W3TC_WIN && $this->_config->get_boolean('notes.wp_content_perms')) {
         $wp_content_mode = w3_get_file_permissions(WP_CONTENT_DIR);
         if ($wp_content_mode > 0755) {
             $this->_notes[] = sprintf('<strong>%s</strong> is write-able. When finished installing the plugin,
                                     change the permissions back to the default: <strong>chmod 755 %s</strong>.
                                     Permissions are currently %s. %s', WP_CONTENT_DIR, WP_CONTENT_DIR, base_convert(w3_get_file_permissions(WP_CONTENT_DIR), 10, 8), $this->button_hide_note('Hide this message', 'wp_content_perms'));
         }
     }
     /**
      * Check wp-content permissions
      */
     if (!W3TC_WIN && $this->_config->get_boolean('notes.wp_content_changed_perms')) {
         $perm = get_transient('w3tc_prev_permission');
         $current_perm = w3_get_file_permissions(WP_CONTENT_DIR);
         if ($perm && $perm != base_convert($current_perm, 10, 8) && ($current_perm > 0755 || $perm < base_convert($current_perm, 10, 8))) {
             $this->_notes[] = sprintf('<strong>%s</strong> permissions were changed during the setup process.
                                     Permissions are currently %s.<br />To restore permissions run
                                     <strong>chmod %s %s</strong>. %s', WP_CONTENT_DIR, base_convert($current_perm, 10, 8), $perm, WP_CONTENT_DIR, $this->button_hide_note('Hide this message', 'wp_content_changed_perms'));
         }
     }
     /**
      * Check permalinks
      */
     if ($this->_config->get_boolean('notes.no_permalink_rules') && ($this->_config->get_boolean('pgcache.enabled') && $this->_config->get_string('pgcache.engine') == 'file_generic' || $this->_config->get_boolean('browsercache.enabled') && $this->_config->get_boolean('browsercache.no404wp')) && !w3_is_permalink_rules()) {
         $this->_errors[] = sprintf('The required directives for fancy permalinks could not be detected, please confirm they are available: <a href="http://codex.wordpress.org/Using_Permalinks#Creating_and_editing_.28.htaccess.29">Creating and editing</a> %s', $this->button_hide_note('Hide this message', 'no_permalink_rules'));
     }
     /**
      * CDN
      */
     if ($this->_config->get_boolean('cdn.enabled')) {
         /**
          * Check upload settings
          */
         $upload_info = w3_upload_info();
         if (!$upload_info) {
             $upload_path = get_option('upload_path');
             $upload_path = trim($upload_path);
             if (empty($upload_path)) {
                 $upload_path = WP_CONTENT_DIR . '/uploads';
                 $this->_errors[] = sprintf('The uploads directory is not available. Default WordPress directories will be created: <strong>%s</strong>.', $upload_path);
             }
             if (!w3_is_multisite()) {
                 $this->_errors[] = sprintf('The uploads path found in the database (%s) is inconsistent with the actual path. Please manually adjust the upload path either in miscellaneous settings or if not using a custom path %s automatically to resolve the issue.', $upload_path, $this->button_link('update the path', wp_nonce_url(sprintf('admin.php?page=%s&w3tc_update_upload_path', $this->_page), 'w3tc')));
             }
         }
         /**
          * Check CDN settings
          */
         $cdn_engine = $this->_config->get_string('cdn.engine');
         $error = '';
         switch (true) {
             case $cdn_engine == 'ftp' && !count($this->_config->get_array('cdn.ftp.domain')):
                 $this->_errors[] = 'A configuration issue prevents <acronym title="Content Delivery Network">CDN</acronym> from working: ' . 'The <strong>"Replace default hostname with"</strong> ' . 'field cannot be empty. Enter <acronym ' . 'title="Content Delivery Network">CDN</acronym> ' . 'provider hostname <a href="?page=w3tc_cdn#configuration">here</a>. ' . '<em>(This is the hostname used in order to view objects ' . 'in a browser.)</em>';
                 break;
             case $cdn_engine == 's3' && ($this->_config->get_string('cdn.s3.key') == '' || $this->_config->get_string('cdn.s3.secret') == '' || $this->_config->get_string('cdn.s3.bucket') == ''):
                 $error = 'The <strong>"Access key", "Secret key" and "Bucket"</strong> fields cannot be empty.';
                 break;
             case $cdn_engine == 'cf' && ($this->_config->get_string('cdn.cf.key') == '' || $this->_config->get_string('cdn.cf.secret') == '' || $this->_config->get_string('cdn.cf.bucket') == '' || $this->_config->get_string('cdn.cf.id') == '' && !count($this->_config->get_array('cdn.cf.cname'))):
                 $error = 'The <strong>"Access key", "Secret key", "Bucket" and "Replace default hostname with"</strong> fields cannot be empty.';
                 break;
             case $cdn_engine == 'cf2' && ($this->_config->get_string('cdn.cf2.key') == '' || $this->_config->get_string('cdn.cf2.secret') == '' || $this->_config->get_string('cdn.cf2.id') == '' && !count($this->_config->get_array('cdn.cf2.cname'))):
                 $error = 'The <strong>"Access key", "Secret key" and "Replace default hostname with"</strong> fields cannot be empty.';
                 break;
             case $cdn_engine == 'rscf' && ($this->_config->get_string('cdn.rscf.user') == '' || $this->_config->get_string('cdn.rscf.key') == '' || $this->_config->get_string('cdn.rscf.container') == '' || !count($this->_config->get_array('cdn.rscf.cname'))):
                 $error = 'The <strong>"Username", "API key", "Container" and "Replace default hostname with"</strong> fields cannot be empty.';
                 break;
             case $cdn_engine == 'azure' && ($this->_config->get_string('cdn.azure.user') == '' || $this->_config->get_string('cdn.azure.key') == '' || $this->_config->get_string('cdn.azure.container') == ''):
                 $error = 'The <strong>"Account name", "Account key" and "Container"</strong> fields cannot be empty.';
                 break;
             case $cdn_engine == 'mirror' && !count($this->_config->get_array('cdn.mirror.domain')):
                 $error = 'The <strong>"Replace default hostname with"</strong> field cannot be empty.';
                 break;
             case $cdn_engine == 'netdna' && !count($this->_config->get_array('cdn.netdna.domain')):
                 $error = 'The <strong>"Replace default hostname with"</strong> field cannot be empty.';
                 break;
             case $cdn_engine == 'cotendo' && !count($this->_config->get_array('cdn.cotendo.domain')):
                 $error = 'The <strong>"Replace default hostname with"</strong> field cannot be empty.';
                 break;
             case $cdn_engine == 'edgecast' && !count($this->_config->get_array('cdn.edgecast.domain')):
                 $error = 'The <strong>"Replace default hostname with"</strong> field cannot be empty.';
                 break;
             case $cdn_engine == 'att' && !count($this->_config->get_array('cdn.att.domain')):
                 $error = 'The <strong>"Replace default hostname with"</strong> field cannot be empty.';
                 break;
         }
         if ($error) {
             $this->_errors[] = 'A configuration issue prevents <acronym title="Content Delivery Network">CDN</acronym> from working: ' . $error . ' <a href="?page=w3tc_cdn#configuration">Specify it here</a>.';
         }
     }
     if (($this->_config->get_boolean('cdn.enabled') || $this->_config->get_boolean('cloudflare.enabled')) && $this->_config->get_boolean('config.check') && w3_can_check_rules()) {
         $service = $this->_config->get_boolean('cdn.enabled') ? 'CDN' : 'CloudFlare';
         $w3_plugin_cdnadmin = w3_instance('W3_Plugin_CdnAdmin');
         if (!$w3_plugin_cdnadmin->check_rules()) {
             try {
                 $w3_plugin_cdnadmin->write_rules();
             } catch (Exception $e) {
                 $this->_rule_errors_root[] = sprintf($service . ' requires some rules to function properly, add the following rules ' . 'into the server configuration file (<strong>%s</strong>) of the site %s ' . '<textarea class="w3tc-rules" cols="120" rows="10" readonly="readonly">%s' . '</textarea>.', w3_get_browsercache_rules_cache_path(), $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($w3_plugin_cdnadmin->generate_rules()));
                 if (!isset($this->_ftp_form) && $e instanceof FilesystemCredentialException) {
                     $this->_ftp_form = $e->ftp_form();
                 } elseif ($e instanceof FileOperationException) {
                     $file_operation_exception = true;
                 }
             }
         }
     } elseif (!$this->_config->get_boolean('cdn.enabled') && !$this->_config->get_boolean('cloudflare.enabled') && $this->_config->get_boolean('config.check') && w3_can_check_rules()) {
         $w3_plugin_cdnadmin = w3_instance('W3_Plugin_CdnAdmin');
         $remove_results[] = $w3_plugin_cdnadmin->remove_rules_with_message();
     }
     /**
      * Preview mode
      */
     if ($this->_config->is_preview()) {
         $this->_notes[] = sprintf('Preview mode is active: Changed settings will not take effect until preview mode is %s or %s. %s any changed settings (without deploying), or make additional changes.', $this->button_link('deploy', wp_nonce_url(sprintf('admin.php?page=%s&w3tc_preview_deploy', $this->_page), 'w3tc')), $this->button_link('disable', wp_nonce_url(sprintf('admin.php?page=%s&w3tc_preview_disable', $this->_page), 'w3tc')), $this->button_link('Preview', w3_get_home_url() . '/?w3tc_preview=1', true));
     }
     /**
      * New Relic module
      */
     if ($this->_config->get_boolean('newrelic.enabled')) {
         /**
          * @var $w3_plugin_newrelic W3_Plugin_NewRelicAdmin
          */
         $w3_plugin_newrelic = w3_instance('W3_Plugin_NewRelicAdmin');
         if (w3_get_blog_id() == 0 && w3_is_apache()) {
             if (!$w3_plugin_newrelic->check_rules_has_core()) {
                 try {
                     $w3_plugin_newrelic->write_rules_core();
                 } catch (Exception $ex) {
                     $this->_rule_errors_root[] = sprintf(__('New Relic requires some rules to function properly, add the following rules ' . 'into the server configuration file (<strong>%s</strong>) of the site %s ', 'w3-total-cache') . '<textarea class="w3tc-rules" cols="120" rows="10" readonly="readonly">%s' . '</textarea>.', w3_get_new_relic_rules_core_path(), $this->button(__('view code', 'w3-total-cache'), '', 'w3tc-show-rules'), htmlspecialchars($w3_plugin_newrelic->generate_rules_core()));
                     if (!isset($this->_ftp_form) && $ex instanceof FilesystemCredentialException) {
                         $this->_ftp_form = $ex->ftp_form();
                     } elseif ($ex instanceof FileOperationException) {
                         $file_operation_exception = true;
                     }
                 }
             }
         }
     }
     /**
      *
      */
     if ($this->_config->get_boolean('notes.root_rules') && count($this->_rule_errors_root) > 0) {
         $this->_rule_errors_root_hide = $this->button_hide_note('Hide this message', 'root_rules');
     } else {
         $this->_rule_errors_root = array();
     }
     $this->_disable_file_operation_notification = $this->_disable_add_in_files_notification || $this->_disable_cache_write_notification;
     if (!$this->_disable_file_operation_notification && isset($file_operation_exception) && $file_operation_exception) {
         $tech_message = '<ul>';
         $core_rules_perms = '';
         if (w3_get_file_permissions(w3_get_wp_config_path()) != 0644) {
             $core_config_perms = sprintf('File permissions are <strong>%s</strong>, however they should be
                                     <strong>644</strong>.', base_convert(w3_get_file_permissions(w3_get_wp_config_path()), 10, 8));
         } else {
             $core_config_perms = sprintf('File permissions are <strong>%s</strong>', base_convert(w3_get_file_permissions(w3_get_wp_config_path()), 10, 8));
         }
         if (w3_get_file_permissions(w3_get_pgcache_rules_core_path()) != 0644) {
             $core_rules_perms = sprintf('File permissions are <strong>%s</strong>, however they should be
                                         <strong>644</strong>.', base_convert(w3_get_file_permissions(w3_get_pgcache_rules_core_path()), 10, 8));
         } else {
             $core_rules_perms = sprintf('File permissions are <strong>%s</strong>', base_convert(w3_get_file_permissions(w3_get_pgcache_rules_core_path()), 10, 8));
         }
         $wp_content_perms = '';
         if (w3_get_file_permissions(WP_CONTENT_DIR) != 0755) {
             $wp_content_perms = sprintf('Directory permissions are <strong>%s</strong>, however they should be
                                         <strong>755</strong>.', base_convert(w3_get_file_permissions(WP_CONTENT_DIR), 10, 8));
         }
         $tech_message .= '<li>' . sprintf('File: <strong>%s</strong> %s File owner: %s', w3_get_wp_config_path(), $core_config_perms, w3_get_file_owner(w3_get_wp_config_path())) . '</li>';
         $tech_message .= '<li>' . sprintf('File: <strong>%s</strong> %s File owner: %s', w3_get_pgcache_rules_core_path(), $core_rules_perms, w3_get_file_owner(w3_get_pgcache_rules_core_path())) . '</li>';
         $tech_message .= '<li>' . sprintf('Directory: <strong>%s</strong> %s File owner: %s', WP_CONTENT_DIR, $wp_content_perms, w3_get_file_owner(WP_CONTENT_DIR)) . '</li>';
         $tech_message .= '<li>' . sprintf('Owner of current file: %s', w3_get_file_owner()) . '</li>';
         if (!(w3_get_file_owner() == w3_get_file_owner(w3_get_pgcache_rules_core_path()) && w3_get_file_owner() == w3_get_file_owner(WP_CONTENT_DIR))) {
             $tech_message .= '<li>The files and directories have different ownership, they should have the same ownership.
                               </li>';
         }
         $tech_message .= '</ul>';
         $tech_message = '<div class="w3tc-technical-info" style="display:none">' . $tech_message . '</div>';
         $w3tc_error[] = sprintf('<strong>W3 Total Cache Error:</strong> The plugin tried to edit, %s, but failed.
                             Files and directories cannot be modified. Please review your
                             <a target="_blank" href="http://codex.wordpress.org/Changing_File_Permissions">
                             file permissions</a>. A common cause is %s and %s having different ownership or permissions.
                              %s %s', $wp_config_edit ? w3_get_wp_config_path() : w3_get_pgcache_rules_core_path(), $wp_config_edit ? basename(w3_get_wp_config_path()) : basename(w3_get_pgcache_rules_core_path()), WP_CONTENT_DIR, $this->button('View technical information', '', 'w3tc-show-technical-info'), $tech_message);
     }
     /**
      * Remove functions results
      */
     if ($remove_results) {
         foreach ($remove_results as $result) {
             $this->_errors = array_merge($this->_errors, $result['errors']);
             if (!isset($this->_ftp_form) && isset($result['ftp_form'])) {
                 $extra_ftp_message = 'Please enter FTP details <a href="#ftp_upload_form">below</a> to remove the disabled modules. ';
                 $this->_ftp_form = $result['ftp_form'];
                 $this->_use_ftp_form = true;
             }
         }
         if (isset($extra_ftp_message)) {
             $this->_errors[] = $extra_ftp_message;
         }
     }
     foreach ($w3tc_error as $error) {
         array_unshift($this->_errors, $error);
     }
     if (isset($this->_ftp_form)) {
         $this->_use_ftp_form = true;
     }
     /**
      * Prepare rule errors auto-install link
      */
     if ($this->_config->get_boolean('notes.rules') && count($this->_rule_errors) > 0) {
         $autoinstall_commands = '';
         foreach ($this->_rule_errors as $error) {
             $autoinstall_commands .= ',' . $error[1];
         }
         $this->_rule_errors_autoinstall = $this->button_link('auto-install', wp_nonce_url(sprintf('admin.php?page=%s&w3tc_rules_autoinstall&autoinstall=%s', $this->_page, $autoinstall_commands), 'w3tc'));
         $this->_rule_errors_hide = $this->button_hide_note('Hide this message', 'rules');
     }
     /*
      * Hidden pages
      */
     if (isset($_REQUEST['w3tc_dbcluster_config'])) {
         $this->dbcluster_config();
     }
     /**
      * Show tab
      */
     switch ($this->_page) {
         case 'w3tc_dashboard':
             $this->options_dashboard();
             break;
         case 'w3tc_general':
             $this->options_general();
             break;
         case 'w3tc_pgcache':
             $this->options_pgcache();
             break;
         case 'w3tc_minify':
             $this->options_minify();
             break;
         case 'w3tc_dbcache':
             $this->options_dbcache();
             break;
         case 'w3tc_objectcache':
             $this->options_objectcache();
             break;
         case 'w3tc_fragmentcache':
             $this->options_fragmentcache();
             break;
         case 'w3tc_browsercache':
             $this->options_browsercache();
             break;
         case 'w3tc_mobile':
             $this->options_mobile();
             break;
         case 'w3tc_referrer':
             $this->options_referrer();
             break;
         case 'w3tc_cdn':
             $this->options_cdn();
             break;
         case 'w3tc_monitoring':
             $this->options_monitoring();
             break;
         case 'w3tc_faq':
             $this->options_faq();
             break;
         case 'w3tc_support':
             $this->options_support();
             break;
         case 'w3tc_install':
             $this->options_install();
             break;
         case 'w3tc_about':
             $this->options_about();
             break;
     }
 }