/** * PHP5-style constructor */ function __construct() { $this->_config = w3_instance('W3_Config'); $this->_debug = $this->_config->get_boolean('varnish.debug'); $this->_servers = $this->_config->get_array('varnish.servers'); $this->_timeout = $this->_config->get_integer('timelimit.varnish_purge'); }
/** * Loads extensions stored in config */ function load_extensions() { $extensions = $this->_config->get_array('extensions.active'); foreach ($extensions as $extension => $path) { include W3TC_EXTENSION_DIR . '/' . trim($path, '/'); } }
/** * Returns minify cache object * * @return object */ function &_get_cache() { static $cache = array(); if (!isset($cache[0])) { switch ($this->_config->get_string('minify.engine')) { case 'memcached': require_once W3TC_LIB_W3_DIR . '/Cache/Memcached.php'; require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/Memcache.php'; $this->_memcached =& new W3_Cache_Memcached(array('servers' => $this->_config->get_array('minify.memcached.servers'), 'persistant' => $this->_config->get_boolean('minify.memcached.persistant'))); $cache[0] =& new Minify_Cache_Memcache($this->_memcached); break; case 'apc': require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/APC.php'; $cache[0] =& new Minify_Cache_APC(); break; case 'eaccelerator': require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/Eaccelerator.php'; $cache[0] =& new Minify_Cache_Eaccelerator(); break; case 'xcache': require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/XCache.php'; $cache[0] =& new Minify_Cache_XCache(); break; case 'file': default: require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/File.php'; if (!is_dir(W3TC_CACHE_FILE_MINIFY_DIR)) { $this->log(sprintf('Cache directory %s does not exist', W3TC_CACHE_FILE_MINIFY_DIR)); } $cache[0] =& new Minify_Cache_File(W3TC_CACHE_FILE_MINIFY_DIR, $this->_config->get_boolean('minify.file.locking')); break; } } return $cache[0]; }
/** * Returns cache object * * @param null $blog_id * @param string $group * @return W3_Cache_Base */ function _get_cache($blog_id = null, $group = 'transient') { static $cache = array(); if (is_null($blog_id) && $group != 'site-transient') { $blog_id = $this->_blog_id; } else { $blog_id = 0; } if (!isset($cache[$blog_id])) { $engine = $this->_config->get_string('fragmentcache.engine'); switch ($engine) { case 'memcached': $engineConfig = array('servers' => $this->_config->get_array('fragmentcache.memcached.servers'), 'persistant' => $this->_config->get_boolean('fragmentcache.memcached.persistant')); break; case 'file': $engineConfig = array('section' => 'fragment', 'locking' => $this->_config->get_boolean('fragmentcache.file.locking'), 'flush_timelimit' => $this->_config->get_integer('timelimit.cache_flush')); break; default: $engineConfig = array(); } $engineConfig['blog_id'] = $blog_id; $engineConfig['module'] = 'fragmentcache'; $engineConfig['host'] = w3_get_host(); $engineConfig['instance_id'] = w3_get_instance_id(); w3_require_once(W3TC_LIB_W3_DIR . '/Cache.php'); $cache[$blog_id] = W3_Cache::instance($engine, $engineConfig); } return $cache[$blog_id]; }
/** * Check * @throws FilesystemOperationException * @throws FileOperationException */ public function update_ip_ranges() { w3_require_once(W3TC_INC_DIR . '/functions/http.php'); $ip4_diff = $ip6_diff = false; $response = w3_http_get(W3TC_CLOUDFLARE_IP4_URL); $extensions_settings = $this->_config->get_array('extensions.settings', array()); if (!is_wp_error($response)) { $ip4_data = $response['body']; $ip4_data = explode("\n", $ip4_data); $ip4_data_old = w3tc_get_extension_config('cloudflare', 'ips.ip4', $this->_config, array()); if ($ip4_diff = array_diff($ip4_data, $ip4_data_old)) { $extensions_settings['cloudflare']['ips.ip4'] = $ip4_data; $this->_config->set('extensions.settings', $extensions_settings); } } $response = w3_http_get(W3TC_CLOUDFLARE_IP6_URL); if (!is_wp_error($response)) { $ip6_data = $response['body']; $ip6_data = explode("\n", $ip6_data); $ip6_data_old = w3tc_get_extension_config('cloudflare', 'ips.ip6', $this->_config, array()); if ($ip6_diff = array_diff($ip6_data, $ip6_data_old)) { $extensions_settings['cloudflare']['ips.ip6'] = $ip6_data; $this->_config->set('extensions.settings', $extensions_settings); } } if ($ip4_diff || $ip6_diff) { try { $this->_config->save(); $this->_config->refresh_cache(); } catch (Exception $ex) { } } }
/** * Check * @throws FilesystemOperationException * @throws FileOperationException */ public function update_ip_ranges() { w3_require_once(W3TC_INC_DIR . '/functions/http.php'); $ip4_diff = $ip6_diff = false; $config_master = new W3_Config(true); $response = w3_http_get(W3TC_CLOUDFLARE_IP4_URL); if (!is_wp_error($response)) { $ip4_data = $response['body']; $ip4_data = explode("\n", $ip4_data); $ip4_data_old = $this->_config->get_array('cloudflare.ips.ip4'); if ($ip4_diff = array_diff($ip4_data, $ip4_data_old)) { $config_master->set('cloudflare.ips.ip4', $ip4_data); } } $response = w3_http_get(W3TC_CLOUDFLARE_IP6_URL); if (!is_wp_error($response)) { $ip6_data = $response['body']; $ip6_data = explode("\n", $ip6_data); $ip6_data_old = $this->_config->get_array('cloudflare.ips.ip6'); if ($ip6_diff = array_diff($ip6_data, $ip6_data_old)) { $config_master->set('cloudflare.ips.ip6', $ip6_data); } } if ($ip4_diff || $ip6_diff) { $config_master->save(); } }
private function _check_query_string() { $accept_qs = $this->_config->get_array('pgcache.accept.qs'); foreach ($_GET as $key => $value) { if (!in_array(strtolower($key), $accept_qs)) { return false; } } return true; }
/** * Checks if User Agent is mobile * * @return boolean */ function _is_mobile() { $mobile_agents = $this->_config->get_array('pgcache.mobile.agents'); foreach ($mobile_agents as $mobile_agent) { if (stristr($_SERVER['HTTP_USER_AGENT'], $mobile_agent) !== false) { return true; } } return false; }
/** * Returns array of data headers * * @return array */ function _get_cached_headers() { $data_headers = array(); $cache_headers = $this->_config->get_array('pgcache.cache.headers'); $response_headers = $this->_get_response_headers(); foreach ($response_headers as $header_name => $header_value) { foreach ($cache_headers as $cache_header_name) { if (strcasecmp($header_name, $cache_header_name) == 0) { $data_headers[$header_name] = $header_value; } } } return $data_headers; }
/** * Returns minifier options * * @param string $engine * @return array */ function get_options($engine) { $options = array(); switch ($engine) { case 'js': $options = array('preserveComments' => !$this->_config->get_boolean('minify.js.strip.comments'), 'stripCrlf' => $this->_config->get_boolean('minify.js.strip.crlf')); break; case 'css': $options = array('preserveComments' => !$this->_config->get_boolean('minify.css.strip.comments'), 'stripCrlf' => $this->_config->get_boolean('minify.css.strip.crlf')); $symlinks = $this->_config->get_array('minify.symlinks'); foreach ($symlinks as $link => $target) { $link = str_replace('//', realpath($_SERVER['DOCUMENT_ROOT']), $link); $link = strtr($link, '/', DIRECTORY_SEPARATOR); $options['symlinks'][$link] = realpath($target); } break; case 'yuijs': $options = array('line-break' => $this->_config->get_integer('minify.yuijs.options.line-break'), 'nomunge' => $this->_config->get_boolean('minify.yuijs.options.nomunge'), 'preserve-semi' => $this->_config->get_boolean('minify.yuijs.options.preserve-semi'), 'disable-optimizations' => $this->_config->get_boolean('minify.yuijs.options.disable-optimizations')); break; case 'yuicss': $options = array('line-break' => $this->_config->get_integer('minify.yuicss.options.line-break')); break; case 'ccjs': $options = array('compilation_level' => $this->_config->get_string('minify.ccjs.options.compilation_level'), 'formatting' => $this->_config->get_string('minify.ccjs.options.formatting')); break; case 'csstidy': $options = array('remove_bslash' => $this->_config->get_boolean('minify.csstidy.options.remove_bslash'), 'compress_colors' => $this->_config->get_boolean('minify.csstidy.options.compress_colors'), 'compress_font-weight' => $this->_config->get_boolean('minify.csstidy.options.compress_font-weight'), 'lowercase_s' => $this->_config->get_boolean('minify.csstidy.options.lowercase_s'), 'optimise_shorthands' => $this->_config->get_integer('minify.csstidy.options.optimise_shorthands'), 'remove_last_;' => $this->_config->get_boolean('minify.csstidy.options.remove_last_;'), 'case_properties' => $this->_config->get_integer('minify.csstidy.options.case_properties'), 'sort_properties' => $this->_config->get_boolean('minify.csstidy.options.sort_properties'), 'sort_selectors' => $this->_config->get_boolean('minify.csstidy.options.sort_selectors'), 'merge_selectors' => $this->_config->get_integer('minify.csstidy.options.merge_selectors'), 'discard_invalid_properties' => $this->_config->get_boolean('minify.csstidy.options.discard_invalid_properties'), 'css_level' => $this->_config->get_string('minify.csstidy.options.css_level'), 'preserve_css' => $this->_config->get_boolean('minify.csstidy.options.preserve_css'), 'timestamp' => $this->_config->get_boolean('minify.csstidy.options.timestamp'), 'template' => $this->_config->get_string('minify.csstidy.options.template')); break; case 'html': case 'htmlxml': $options = array('xhtml' => true, 'stripCrlf' => $this->_config->get_boolean('minify.html.strip.crlf'), 'ignoredComments' => $this->_config->get_array('minify.html.comments.ignore')); break; case 'htmltidy': case 'htmltidyxml': $options = array('clean' => $this->_config->get_boolean('minify.htmltidy.options.clean'), 'hide-comments' => $this->_config->get_boolean('minify.htmltidy.options.hide-comments'), 'wrap' => $this->_config->get_integer('minify.htmltidy.options.wrap')); break; } if ($this->_config->get_boolean('browsercache.enabled') && ($this->_config->get_boolean('browsercache.cssjs.replace') || $this->_config->get_boolean('browsercache.html.replace') || $this->_config->get_boolean('browsercache.other.replace'))) { $w3_plugin_browsercache = w3_instance('W3_Plugin_BrowserCache'); $options = array_merge($options, array('browserCacheId' => $w3_plugin_browsercache->get_replace_id(), 'browserCacheExtensions' => $w3_plugin_browsercache->get_replace_extensions())); } if ($this->_config->get_boolean('cdn.enabled') && $this->_config->get_boolean('cdn.minify.enable')) { $w3_plugin_cdn = w3_instance('W3_Plugin_CdnCommon'); $cdn = $w3_plugin_cdn->get_cdn(); $options = array_merge($options, array('prependAbsolutePathCallback' => array(&$cdn, 'get_prepend_path'))); } return $options; }
/** * Uncompresses a minify auto filename into an array of files. * @param $compressed * @param $type * @return array */ function uncompress_minify_files($compressed, $type) { $no_type_files = array(); $compressed = basename($compressed, '.' . $type); $uncompressed = $this->_uncompress(base64_decode(strtr($compressed, '-_', '+/'))); $exploded = explode(',', $uncompressed); $replacements = $this->_minify_path_replacements(); foreach ($exploded as $file) { if (!w3_is_url($file)) { $prefix = substr($file, 0, 1); $after_pre = substr($file, 1, 1); if (isset($replacements[$prefix]) && $after_pre == '/') { $file = $replacements[$prefix] . substr($file, 1); $no_type_files[] = $file; } else { $no_type_files[] = $file; } } else { $no_type_files[] = $file; } } $files = array(); foreach ($no_type_files as $no_type_file) { $file = !w3_is_url($no_type_file) ? $no_type_file . '.' . $type : $no_type_file; $verified = false; if (w3_is_url($file)) { $external = $this->_config->get_array('minify.cache.files'); foreach ($external as $ext) { if (preg_match('#' . w3_get_url_regexp($ext) . '#', $file) && !$verified) { $verified = true; } } if (!$verified) { $this->error(sprintf('Remote file not in external files/libraries list: "%s"', $file)); } } elseif (strpos($file, '..') != false || strpos($file, '//') !== false || strpos($file, '\\') !== false && strtoupper(substr(PHP_OS, 0, 3)) != 'WIN' || preg_match('/(?:^|[^\\.])\\.\\//', $file) || !preg_match('/^[a-zA-Z0-9_.\\/-]|[\\\\]+$/', $file)) { $verified = false; $this->error(sprintf('File path invalid: "%s"', $file)); } else { $verified = true; } if ($verified) { $files[] = $file; } } return $files; }
/** * Check request URI * * @return boolean */ function _check_request_uri() { $auto_reject_uri = array('wp-login', 'wp-register'); foreach ($auto_reject_uri as $uri) { if (strstr($_SERVER['REQUEST_URI'], $uri) !== false) { return false; } } $reject_uri = $this->_config->get_array('objectcache.reject.uri'); $reject_uri = array_map('w3_parse_path', $reject_uri); foreach ($reject_uri as $expr) { $expr = trim($expr); if ($expr != '' && preg_match('~' . $expr . '~i', $_SERVER['REQUEST_URI'])) { return false; } } return true; }
/** * Checks for WordPress cookies * * @return boolean */ function _check_cookies() { foreach (array_keys($_COOKIE) as $cookie_name) { if ($cookie_name == 'wordpress_test_cookie') { continue; } if (preg_match('/^wp-postpass|^comment_author/', $cookie_name)) { return false; } } foreach ($this->_config->get_array('dbcache.reject.cookie') as $reject_cookie) { foreach (array_keys($_COOKIE) as $cookie_name) { if (strstr($cookie_name, $reject_cookie) !== false) { return false; } } } return true; }
/** * Returns cache object * * @return W3_Cache_Base */ function &_get_cache() { static $cache = array(); if (!isset($cache[0])) { $engine = $this->_config->get_string('objectcache.engine'); switch ($engine) { case 'memcached': $engineConfig = array('servers' => $this->_config->get_array('objectcache.memcached.servers'), 'persistant' => $this->_config->get_boolean('objectcache.memcached.persistant')); break; case 'file': $engineConfig = array('cache_dir' => W3TC_CACHE_FILE_OBJECTCACHE_DIR, 'locking' => $this->_config->get_boolean('objectcache.file.locking'), 'flush_timelimit' => $this->_config->get_integer('timelimit.cache_flush')); break; default: $engineConfig = array(); } require_once W3TC_LIB_W3_DIR . '/Cache.php'; @($cache[0] =& W3_Cache::instance($engine, $engineConfig)); } return $cache[0]; }
/** * Create a NetDNA or MaxCDN pull zone automatically */ function action_cdn_auto_create_netdna_maxcdn_pull_zone() { w3_require_once(W3TC_LIB_NETDNA_DIR . '/NetDNA.php'); w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/admin.php'); $cdn_engine = W3_Request::get_string('type'); $this->validate_cdnengine_is_netdna_maxcdn($cdn_engine); $authorization_key = W3_Request::get_string('authorization_key'); $this->validate_authorization_key($authorization_key); $keys = explode('+', $authorization_key); list($alias, $consumerkey, $consumersecret) = $keys; $url = w3_get_home_url(); try { $api = new NetDNA($alias, $consumerkey, $consumersecret); $disable_cooker_header = $this->_config->get_boolean('browsercache.other.nocookies') || $this->_config->get_boolean('browsercache.cssjs.nocookies'); $zone = $api->create_default_pull_zone($url, null, null, array('ignore_setcookie_header' => $disable_cooker_header)); $name = $zone['name']; $temporary_url = "{$name}.{$alias}.netdna-cdn.com"; $test_result = -1; if (!$this->_config->get_array("cdn.{$cdn_engine}.domain")) { $test_result = $this->test_cdn_url($temporary_url) ? 1 : 0; $this->_config->set("cdn.{$cdn_engine}.zone_id", $zone['id']); if ($test_result) { $this->_config->set("cdn.enabled", true); } $this->_config->set("cdn.{$cdn_engine}.domain", array($temporary_url)); } $this->_config->save(); $config_admin = w3_instance('W3_ConfigAdmin'); $zones = $api->get_pull_zones(); $zone_count = sizeof($zones); w3tc_make_track_call(array('type' => 'cdn', 'data' => array('cdn' => $cdn_engine, 'action' => 'zonecreation', 'creation' => 'manual', 'creationtime' => time(), 'signupclick' => $config_admin->get_integer('track.maxcdn_signup'), 'authorizeclick' => $config_admin->get_integer('track.maxcdn_authorize'), 'validationclick' => $config_admin->get_integer('track.maxcdn_validation'), 'total_zones' => $zone_count, 'test' => $test_result))); $result = array('result' => 'single', 'cnames' => array($temporary_url)); } catch (Exception $ex) { $result = array('result' => 'error', 'message' => sprintf(__('Could not create default zone.' . $ex->getMessage(), 'w3-total-cache'))); } echo json_encode($result); exit; }
/** * Create NetDNA/MaxCDN pullzone */ function action_cdn_create_netdna_maxcdn_pull_zone() { w3_require_once(W3TC_LIB_W3_DIR . '/Request.php'); $type = W3_Request::get_string('type'); $name = W3_Request::get_string('name'); $label = W3_Request::get_string('label'); w3_require_once(W3TC_LIB_NETDNA_DIR . '/NetDNA.php'); $cdn_engine = $this->_config->get_string('cdn.engine'); $authorization_key = $this->_config->get_string("cdn.{$cdn_engine}.authorization_key"); $alias = $consumerkey = $consumersecret = ''; if ($authorization_key) { $keys = explode('+', $authorization_key); if (sizeof($keys) == 3) { list($alias, $consumerkey, $consumersecret) = $keys; } } $api = new NetDNA($alias, $consumerkey, $consumersecret); $url = w3_get_home_url(); $zone = array(); $zone['name'] = $name; $zone['label'] = $label; $zone['url'] = $url; try { $response = $api->create_pull_zone($zone); try { $this->_config->set('cdn.enabled', true); if (!$this->_config->get_array("cdn.{$cdn_engine}.domain")) { $this->_config->set("cdn.{$cdn_engine}.domain", array("{$name}.{$alias}.netdna-cdn.com")); } $this->_config->save(); } catch (Exception $ex) { } echo json_encode(array('status' => 'success', 'message' => 'Pull Zone created.', 'temporary_url' => "{$name}.{$alias}.netdna-cdn.com", 'data' => $response)); } catch (Exception $ex) { echo json_encode(array('status' => 'error', 'message' => $ex->getMessage())); } }
/** * Returns minify cache object * * @return object */ function &_get_cache() { static $cache = array(); if (!isset($cache[0])) { switch ($this->_config->get_string('minify.engine')) { case 'memcached': require_once W3TC_LIB_W3_DIR . '/Cache/Memcached.php'; require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/Memcache.php'; @($w3_cache_memcached =& new W3_Cache_Memcached(array('servers' => $this->_config->get_array('minify.memcached.servers'), 'persistant' => $this->_config->get_boolean('minify.memcached.persistant')))); @($cache[0] =& new Minify_Cache_Memcache($w3_cache_memcached)); break; case 'apc': require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/APC.php'; @($cache[0] =& new Minify_Cache_APC()); break; case 'eaccelerator': require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/Eaccelerator.php'; @($cache[0] =& new Minify_Cache_Eaccelerator()); break; case 'xcache': require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/XCache.php'; @($cache[0] =& new Minify_Cache_XCache()); break; case 'wincache': require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/Wincache.php'; @($cache[0] =& new Minify_Cache_Wincache()); break; case 'file': default: require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/File.php'; @($cache[0] =& new Minify_Cache_File(W3TC_CACHE_FILE_MINIFY_DIR, array('.htaccess', 'index.php'), $this->_config->get_boolean('minify.file.locking'), $this->_config->get_integer('timelimit.cache_flush'))); break; } } return $cache[0]; }
/** * Constructor * * @param $config * @param $buffer * @param $minify_helpers */ function __construct($config, $buffer, $minify_helpers) { $this->config = $config; $this->buffer = $buffer; $this->minify_helpers = $minify_helpers; // ignored files $this->ignore_js_files = $this->config->get_array('minify.reject.files.js'); $this->ignore_js_files = array_map('w3_normalize_file', $this->ignore_js_files); // define embed type $this->embed_type = $this->config->get_string('minify.js.header.embed_type'); if ($this->embed_type != 'extsrc' && $this->embed_type != 'asyncsrc') { $this->embed_type = 'blocking'; } }
/** * 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; }
public function is_cache_configured() { $cache_configured = true; if ($this->is_wp_super_cache_detected()) { return $this->is_wp_super_cache_active() && $this->does_wp_super_cache_have_configured_uas() || !$this->is_wp_super_cache_active(); } // Check W3 if ($this->is_w3_plugin_detected()) { $w3_config = new W3_Config(true); if ($w3_config) { // Check to see if the Page Cache is enabled if ($w3_config->get_cache_option('pgcache.enabled')) { // If it's enabled, we need to make sure the user agents have been updated $rejected_user_agents = $w3_config->get_cache_option('pgcache.reject.ua'); if (!$this->find_in_array_no_case('iphone', $rejected_user_agents)) { $cache_configured = false; } if (!$cache_configured && ($user_groups = $w3_config->get_array('mobile.rgroups')) && is_array($user_groups) && count($user_groups) > 0) { foreach ($user_groups as $group) { if ($group['enabled'] && $this->find_in_array_no_case('iphone', $group['agents']) && $group['theme'] == '' && $group['redirect'] == '') { $cache_configured = true; add_filter('wptouch_show_mobile_switch_link', '__return_false'); } } } } } return $cache_configured; } if ($this->is_wordfence_detected()) { $cache_type = wfConfig::get('cacheType', false); if (!$cache_type) { $cache_configured = true; } else { $cookie_set = false; $user_agents_set = false; $exclusions = wfConfig::get('cacheExclusions', false); if ($exclusions) { $exclusions = unserialize($exclusions); if ($exclusions) { foreach ($exclusions as $exclusion) { if ($exclusion['pt'] == 'cc' && ($exclusion['p'] = 'wptouch_switch_toggle')) { $cookie_set = true; } else { if ($exclusion['pt'] == 'uac' && strtolower($exclusion['p']) == 'iphone') { $user_agents_set = true; } } if ($cookie_set && $user_agents_set) { break; } } } } $cache_configured = $cookie_set && $user_agents_set; } return $cache_configured; } return $cache_configured; }
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; } /** * Check for page cache availability */ $wp_config_edit = false; /** * 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.', 'w3-total-cache'), 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.', 'w3-total-cache'), 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.', 'w3-total-cache'), 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.', 'w3-total-cache'), implode(', ', $objectcache_memcached_servers)); } } if (count($memcaches_errors)) { $memcache_error = __('The following memcached servers are not responding or not running:</p><ul>', 'w3-total-cache'); 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.', 'w3-total-cache'); $this->_errors[] = $memcache_error; } /** * 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', 'w3-total-cache'), w3_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', 'w3-total-cache'), w3_button_hide_note(__('Hide this message', 'w3-total-cache'), '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', 'w3-total-cache'), w3_button_hide_note(__('Hide this message', 'w3-total-cache'), 'zlib_output_compression')); } /** * Check wp-content permissions */ if (!W3TC_WIN && $this->_config->get_boolean('notes.wp_content_perms')) { w3_require_once(W3TC_INC_DIR . '/functions/file.php'); $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', 'w3-total-cache'), WP_CONTENT_DIR, WP_CONTENT_DIR, base_convert(w3_get_file_permissions(WP_CONTENT_DIR), 10, 8), w3_button_hide_note(__('Hide this message', 'w3-total-cache'), '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', 'w3-total-cache'), WP_CONTENT_DIR, base_convert($current_perm, 10, 8), $perm, WP_CONTENT_DIR, w3_button_hide_note(__('Hide this message', 'w3-total-cache'), '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', 'w3-total-cache'), w3_button_hide_note(__('Hide this message', 'w3-total-cache'), '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>.', 'w3-total-cache'), $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.', 'w3-total-cache'), $upload_path, w3_button_link(__('update the path', 'w3-total-cache'), wp_nonce_url(sprintf('admin.php?page=%s&w3tc_config_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>', 'w3-total-cache'); 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.', 'w3-total-cache'); 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.', 'w3-total-cache'); 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.', 'w3-total-cache'); 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.', 'w3-total-cache'); 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.', 'w3-total-cache'); 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.', 'w3-total-cache'); break; case $cdn_engine == 'netdna': $fields = array(); if ($this->_config->get_string('cdn.netdna.authorization_key') == '') { $fields[] = '"' . __('Authorization key', 'w3-total-cache') . '"'; } if (!count($this->_config->get_array('cdn.netdna.domain'))) { $fields[] = '"' . __('Replace default hostname with', 'w3-total-cache') . '"'; } if ($fields) { $error = sprintf(__('The <strong>%s</strong> field(s) cannot be empty.', 'w3-total-cache'), implode(__(' and ', 'w3-total-cache'), $fields)); } if ($this->_config->get_string('cdn.netdna.authorization_key') != '' && sizeof(explode('+', $this->_config->get_string('cdn.netdna.authorization_key'))) != 3) { $error .= __('The <strong>"Authorization key"</strong> is not correct.', 'w3-total-cache'); } elseif ($this->_config->get_integer('cdn.netdna.zone_id', 0) <= 0) { $error .= __('You need to select / create a pull zone.', 'w3-total-cache'); } break; case $cdn_engine == 'maxcdn': $fields = array(); if ($this->_config->get_string('cdn.maxcdn.authorization_key') == '') { $fields[] = '"' . __('Authorization key', 'w3-total-cache') . '"'; } if (!count($this->_config->get_array('cdn.maxcdn.domain'))) { $fields[] = '"' . __('Replace default hostname with', 'w3-total-cache') . '"'; } if ($fields) { $error = sprintf(__('The <strong>%s</strong> field(s) cannot be empty.', 'w3-total-cache'), implode(__(' and ', 'w3-total-cache'), $fields)); } if ($this->_config->get_string('cdn.maxcdn.authorization_key') != '' && sizeof(explode('+', $this->_config->get_string('cdn.maxcdn.authorization_key'))) != 3) { $error .= __('The <strong>"Authorization key"</strong> is not correct.', 'w3-total-cache'); } elseif ($this->_config->get_integer('cdn.maxcdn.zone_id', 0) <= 0) { $error .= __('You need to select / create a pull zone.', 'w3-total-cache'); } 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.', 'w3-total-cache'); 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.', 'w3-total-cache'); 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.', 'w3-total-cache'); break; case $cdn_engine == 'akamai' && !count($this->_config->get_array('cdn.akamai.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: ', 'w3-total-cache') . $error . __(' <a href="?page=w3tc_cdn#configuration">Specify it here</a>.', 'w3-total-cache'); } } /** * 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.', 'w3-total-cache'), w3_button_link(__('deploy', 'w3-total-cache'), wp_nonce_url(sprintf('admin.php?page=%s&w3tc_config_preview_deploy', $this->_page), 'w3tc')), w3_button_link(__('disable', 'w3-total-cache'), wp_nonce_url(sprintf('admin.php?page=%s&w3tc_config_preview_disable', $this->_page), 'w3tc'))) . '<br /><span class="description">' . sprintf(__('To preview any changed settings (without deploying): %s', 'w3-total-cache'), w3tc_get_preview_link()) . '</span>'; } /** * */ if ($this->_config->get_boolean('notes.root_rules') && count($this->_rule_errors_root) > 0) { $this->_rule_errors_root_hide = w3_button_hide_note(__('Hide this message', 'w3-total-cache'), '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>.', 'w3-total-cache'), base_convert(w3_get_file_permissions(w3_get_wp_config_path()), 10, 8)); } else { $core_config_perms = sprintf(__('File permissions are <strong>%s</strong>', 'w3-total-cache'), 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>.', 'w3-total-cache'), 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>', 'w3-total-cache'), 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>.', 'w3-total-cache'), base_convert(w3_get_file_permissions(WP_CONTENT_DIR), 10, 8)); } $tech_message .= '<li>' . sprintf(__('File: <strong>%s</strong> %s File owner: %s', 'w3-total-cache'), 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-total-cache'), 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', 'w3-total-cache'), WP_CONTENT_DIR, $wp_content_perms, w3_get_file_owner(WP_CONTENT_DIR)) . '</li>'; $tech_message .= '<li>' . sprintf(__('Owner of current file: %s', 'w3-total-cache'), 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>', 'w3-total-cache'); } $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', 'w3-total-cache'), $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, w3_button(__('View technical information', 'w3-total-cache'), '', '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. ', 'w3-total-cache'); $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; } $this->view(); }
/** * Generates rules for WP dir * * @param W3_Config $config * @return string */ private function rules_core_generate_nginx($config) { $is_network = w3_is_network(); $base_path = w3_get_base_path(); $cache_dir = w3_path(W3TC_CACHE_PAGE_ENHANCED_DIR); $permalink_structure = get_option('permalink_structure'); /** * Auto reject cookies */ $reject_cookies = array('comment_author', 'wp-postpass'); if ($config->get_string('pgcache.engine') == 'file_generic') { $reject_cookies[] = 'w3tc_logged_out'; } /** * Reject cache for logged in users * OR * Reject cache for roles if any */ if ($config->get_boolean('pgcache.reject.logged')) { $reject_cookies = array_merge($reject_cookies, array('wordpress_logged_in')); } elseif ($config->get_boolean('pgcache.reject.logged_roles')) { $new_cookies = array(); foreach ($config->get_array('pgcache.reject.roles') as $role) { $new_cookies[] = 'w3tc_logged_' . md5(NONCE_KEY . $role); } $reject_cookies = array_merge($reject_cookies, $new_cookies); } /** * Custom config */ $reject_cookies = array_merge($reject_cookies, $config->get_array('pgcache.reject.cookie')); w3_array_trim($reject_cookies); $reject_user_agents = $config->get_array('pgcache.reject.ua'); if ($config->get_boolean('pgcache.compatibility')) { $reject_user_agents = array_merge(array(W3TC_POWERED_BY), $reject_user_agents); } w3_array_trim($reject_user_agents); /** * Generate rules */ $env_w3tc_ua = ''; $env_w3tc_ref = ''; $env_w3tc_ssl = ''; $env_w3tc_ext = ''; $env_w3tc_enc = ''; $rules = ''; $rules .= W3TC_MARKER_BEGIN_PGCACHE_CORE . "\n"; if ($config->get_boolean('pgcache.debug')) { $rules .= "rewrite ^(.*\\/)?w3tc_rewrite_test/?\$ \$1?w3tc_rewrite_test=1 last;\n"; } /** * Check for mobile redirect */ if ($config->get_boolean('mobile.enabled')) { $mobile_groups = $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 ($config->get_boolean('referrer.enabled')) { $referrer_groups = $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 permalink structure trailing slash */ if (substr($permalink_structure, -1) == '/') { $rules .= "if (\$request_uri !~ \\/\$) {\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"; } /** * Check mobile groups */ if ($config->get_boolean('mobile.enabled')) { $mobile_groups = array_reverse($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 .= "set \$w3tc_ua \"\";\n"; $rules .= "if (\$http_user_agent ~* \"(" . implode('|', $mobile_agents) . ")\") {\n"; $rules .= " set \$w3tc_ua _" . $mobile_group . ";\n"; $rules .= "}\n"; $env_w3tc_ua = "\$w3tc_ua"; } } } /** * Check referrer groups */ if ($config->get_boolean('referrer.enabled')) { $referrer_groups = array_reverse($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 .= "set \$w3tc_ref \"\";\n"; $rules .= "if (\$http_cookie ~* \"w3tc_referrer=.*(" . implode('|', $referrer_referrers) . ")\") {\n"; $rules .= " set \$w3tc_ref _" . $referrer_group . ";\n"; $rules .= "}\n"; $env_w3tc_ref = "\$w3tc_ref"; } } } if ($config->get_boolean('pgcache.cache.ssl')) { $rules .= "set \$w3tc_ssl \"\";\n"; $rules .= "if (\$scheme = https) {\n"; $rules .= " set \$w3tc_ssl _ssl;\n"; $rules .= "}\n"; $env_w3tc_ssl = "\$w3tc_ssl"; } if ($config->get_boolean('browsercache.enabled') && $config->get_boolean('browsercache.html.compression')) { $rules .= "set \$w3tc_enc \"\";\n"; $rules .= "if (\$http_accept_encoding ~ gzip) {\n"; $rules .= " set \$w3tc_enc _gzip;\n"; $rules .= "}\n"; $env_w3tc_enc = "\$w3tc_enc"; } $cache_path = str_replace(w3_get_document_root(), '', $cache_dir); $uri_prefix = $cache_path . "/\$http_host/" . "\$request_uri/_index" . $env_w3tc_ua . $env_w3tc_ref . $env_w3tc_ssl; if (!$config->get_boolean('pgcache.cache.nginx_handle_xml')) { $env_w3tc_ext = '.html'; $rules .= "if (!-f \"\$document_root" . $uri_prefix . ".html" . $env_w3tc_enc . "\") {\n"; $rules .= " set \$w3tc_rewrite 0;\n"; $rules .= "}\n"; } else { $env_w3tc_ext = "\$w3tc_ext"; $rules .= "set \$w3tc_ext \"\";\n"; $rules .= "if (-f \"\$document_root" . $uri_prefix . ".html" . $env_w3tc_enc . "\") {\n"; $rules .= " set \$w3tc_ext .html;\n"; $rules .= "}\n"; $rules .= "if (-f \"\$document_root" . $uri_prefix . ".xml" . $env_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 .* \"" . $uri_prefix . $env_w3tc_ext . $env_w3tc_enc . "\" last;\n"; $rules .= "}\n"; $rules .= W3TC_MARKER_END_PGCACHE_CORE . "\n"; return $rules; }
/** * Generate rules related to prevent for media 404 error by WP * * @param W3_Config $config * @return string */ private function rules_no404wp_generate_nginx($config) { $a = $this->get_mime_types(); $cssjs_types = $a['cssjs']; $html_types = $a['html']; $other_types = $a['other']; $extensions = array_merge(array_keys($cssjs_types), array_keys($html_types), array_keys($other_types)); $permalink_structure = get_option('permalink_structure'); $permalink_structure_ext = ltrim(strrchr($permalink_structure, '.'), '.'); if ($permalink_structure_ext != '') { foreach ($extensions as $index => $extension) { if (strstr($extension, $permalink_structure_ext) !== false) { $extensions[$index] = preg_replace('~\\|?' . w3_preg_quote($permalink_structure_ext) . '\\|?~', '', $extension); } } } $exceptions = $config->get_array('browsercache.no404wp.exceptions'); $rules = ''; $rules .= W3TC_MARKER_BEGIN_BROWSERCACHE_NO404WP . "\n"; $rules .= "if (-f \$request_filename) {\n"; $rules .= " break;\n"; $rules .= "}\n"; $rules .= "if (-d \$request_filename) {\n"; $rules .= " break;\n"; $rules .= "}\n"; if (count($exceptions)) { $rules .= "if (\$request_uri ~ \"(" . implode('|', $exceptions) . ")\") {\n"; $rules .= " break;\n"; $rules .= "}\n"; } $rules .= "if (\$request_uri ~* \\.(" . implode('|', $extensions) . ")\$) {\n"; $rules .= " return 404;\n"; $rules .= "}\n"; $rules .= W3TC_MARKER_END_BROWSERCACHE_NO404WP . "\n"; return $rules; }
/** * Purges cdn mirror post cache * * @param integer $post_id * @return boolean */ function purge_post($post_id) { if (!$post_id) { $post_id = $this->_detect_post_id(); } if ($post_id) { $full_urls = array(); $global_urls = array(); $post = null; $terms = array(); $feeds = $this->_config->get_array('pgcache.purge.feed.types'); $limit_post_pages = $this->_config->get_integer('pgcache.purge.postpages_limit'); if ($this->_config->get_boolean('pgcache.purge.terms') || $this->_config->get_boolean('varnish.pgcache.feed.terms')) { $taxonomies = get_post_taxonomies($post_id); $terms = wp_get_post_terms($post_id, $taxonomies); } $purge_urls = w3_instance('W3_PageUrls'); switch (true) { case $this->_config->get_boolean('pgcache.purge.author'): case $this->_config->get_boolean('pgcache.purge.archive.daily'): case $this->_config->get_boolean('pgcache.purge.archive.monthly'): case $this->_config->get_boolean('pgcache.purge.archive.yearly'): case $this->_config->get_boolean('pgcache.purge.feed.author'): $post = get_post($post_id); } $front_page = get_option('show_on_front'); /** * Home (Frontpage) URL */ if ($this->_config->get_boolean('pgcache.purge.home') && $front_page == 'posts' || $this->_config->get_boolean('pgcache.purge.front_page')) { $global_urls = array_merge($global_urls, $purge_urls->get_frontpage_urls($limit_post_pages)); } /** * Home (Post page) URL */ if ($this->_config->get_boolean('pgcache.purge.home') && $front_page != 'posts') { $global_urls = array_merge($global_urls, $purge_urls->get_postpage_urls($limit_post_pages)); } /** * Post URL */ if ($this->_config->get_boolean('pgcache.purge.post')) { $full_urls = array_merge($full_urls, $purge_urls->get_post_urls($post_id)); } /** * Post comments URLs */ if ($this->_config->get_boolean('pgcache.purge.comments') && function_exists('get_comments_pagenum_link')) { $full_urls = array_merge($full_urls, $purge_urls->get_post_comments_urls($post_id)); } /** * Post author URLs */ if ($this->_config->get_boolean('pgcache.purge.author') && $post) { $full_urls = array_merge($full_urls, $purge_urls->get_post_author_urls($post->post_author, $limit_post_pages)); } /** * Post terms URLs */ if ($this->_config->get_boolean('pgcache.purge.terms')) { $full_urls = array_merge($full_urls, $purge_urls->get_post_terms_urls($terms, $limit_post_pages)); } /** * Daily archive URLs */ if ($this->_config->get_boolean('pgcache.purge.archive.daily') && $post) { $full_urls = array_merge($full_urls, $purge_urls->get_daily_archive_urls($post, $limit_post_pages)); } /** * Monthly archive URLs */ if ($this->_config->get_boolean('pgcache.purge.archive.monthly') && $post) { $full_urls = array_merge($full_urls, $purge_urls->get_montly_archive_urls($post, $limit_post_pages)); } /** * Yearly archive URLs */ if ($this->_config->get_boolean('pgcache.purge.archive.yearly') && $post) { $full_urls = array_merge($full_urls, $purge_urls->get_yearly_archive_urls($post, $limit_post_pages)); } /** * Feed URLs */ if ($this->_config->get_boolean('pgcache.purge.feed.blog')) { $global_urls = array_merge($global_urls, $purge_urls->get_feed_urls($feeds)); } if ($this->_config->get_boolean('pgcache.purge.feed.comments')) { $full_urls = array_merge($full_urls, $purge_urls->get_feed_comments_urls($post_id, $feeds)); } if ($this->_config->get_boolean('pgcache.purge.feed.author') && $post) { $full_urls = array_merge($full_urls, $purge_urls->get_feed_author_urls($post->post_author, $feeds)); } if ($this->_config->get_boolean('pgcache.purge.feed.terms')) { $full_urls = array_merge($full_urls, $purge_urls->get_feed_terms_urls($terms, $feeds)); } /** * Purge selected pages */ if ($this->_config->get_array('pgcache.purge.pages')) { $pages = $this->_config->get_array('pgcache.purge.pages'); $global_urls = array_merge($global_urls, $purge_urls->get_pages_urls($pages)); } if ($this->_do_flush_global_urls()) { $full_urls = array_merge($global_urls, $full_urls); } elseif ($this->_flushes == 0) { $this->_repeated_urls = $global_urls; } /** * Flush cache */ if (count($full_urls)) { $this->_flushes++; $w3_plugin_cdncommon = w3_instance('W3_Plugin_CdnCommon'); $results = array(); $files = array(); foreach ($full_urls as $url) { if (!in_array($url, $this->_repeated_urls) && !in_array($url, $this->_flushed_urls)) { $parsed = parse_url($url); $local_site_path = isset($parsed['path']) ? ltrim($parsed['path'], '/') : ''; $remote_path = $w3_plugin_cdncommon->uri_to_cdn_uri($local_site_path); $files[] = $w3_plugin_cdncommon->build_file_descriptor($local_site_path, $remote_path); $this->_flushed_urls[] = $url; } elseif (!in_array($url, $this->_repeated_urls)) { $this->_repeated_urls[] = $url; } } return $w3_plugin_cdncommon->purge($files, false, $results); } } return false; }
/** * @param $extension * @param W3_Config $config * @param bool $dont_save_config * @return bool */ function w3tc_deactivate_extension($extension, $config, $dont_save_config = false) { $extensions = $config->get_array('extensions.active'); if (array_key_exists($extension, $extensions)) { unset($extensions[$extension]); ksort($extensions, SORT_STRING); $config->set('extensions.active', $extensions); try { if (!$dont_save_config) { $config->save(); } do_action("w3tc_deactivate_extension-{$extension}"); return true; } catch (Exception $ex) { } } return false; }
/** * Options save action * * @return void */ function action_save_options() { if (!current_user_can('manage_options')) { wp_die(__('You do not have the rights to perform this action.', 'w3-total-cache')); } /** * Redirect params */ $params = array(); /** * Store error message regarding permalink not enabled */ $redirect_permalink_error = ''; /** * Read config * We should use new instance of WP_Config object here */ $config = new W3_Config(); $this->read_request($config); $config_admin = new W3_ConfigAdmin(); $this->read_request($config_admin); if ($this->_page == 'w3tc_dashboard') { if (W3_Request::get_boolean('maxcdn')) { $config->set('cdn.enabled', true); $config->set('cdn.engine', 'maxcdn'); } } /** * General tab */ if ($this->_page == 'w3tc_general') { $file_nfs = W3_Request::get_boolean('file_nfs'); $file_locking = W3_Request::get_boolean('file_locking'); $config->set('pgcache.file.nfs', $file_nfs); $config->set('minify.file.nfs', $file_nfs); $config->set('dbcache.file.locking', $file_locking); $config->set('objectcache.file.locking', $file_locking); $config->set('pgcache.file.locking', $file_locking); $config->set('minify.file.locking', $file_locking); if (is_network_admin()) { if ($this->_config->get_boolean('common.force_master') !== $config->get_boolean('common.force_master') || !w3_force_master() && $this->_config->get_boolean('common.force_master') && $config->get_boolean('common.force_master') || w3_force_master() && !$this->_config->get_boolean('common.force_master') && !$config->get_boolean('common.force_master')) { @unlink(W3TC_CACHE_BLOGMAP_FILENAME); $blogmap_dir = dirname(W3TC_CACHE_BLOGMAP_FILENAME) . '/' . basename(W3TC_CACHE_BLOGMAP_FILENAME, '.php') . '/'; if (@is_dir($blogmap_dir)) { w3_rmdir($blogmap_dir); } } if ($config->get_boolean('common.force_master')) { $config_admin->set('common.visible_by_master_only', true); } } /** * Check permalinks for page cache */ if ($config->get_boolean('pgcache.enabled') && $config->get_string('pgcache.engine') == 'file_generic' && !get_option('permalink_structure')) { $config->set('pgcache.enabled', false); $redirect_permalink_error = 'fancy_permalinks_disabled_pgcache'; } /** * Get New Relic application id */ if ($config->get_boolean('newrelic.enabled')) { $method = W3_Request::get_string('application_id_method'); $newrelic_prefix = ''; if (w3_is_network() && w3_get_blog_id() != 0) { $newrelic_prefix = $this->_config->get_string('newrelic.appname_prefix'); } if (($newrelic_api_key = $config->get_string('newrelic.api_key')) && !$config->get_string('newrelic.account_id')) { $nerser = w3_instance('W3_NewRelicService'); $account_id = $nerser->get_account_id($newrelic_api_key); $config->set('newrelic.account_id', $account_id); } if ($method == 'dropdown' && $config->get_string('newrelic.application_id')) { $application_id = $config->get_string('newrelic.application_id'); if ($config->get_string('newrelic.api_key') && $config->get_string('newrelic.account_id')) { w3_require_once(W3TC_LIB_W3_DIR . '/NewRelicService.php'); $nerser = new W3_NewRelicService($config->get_string('newrelic.api_key'), $config->get_string('newrelic.account_id')); $appname = $nerser->get_application_name($application_id); $config->set('newrelic.appname', $appname); } } else { if ($method == 'manual' && $config->get_string('newrelic.appname')) { if ($newrelic_prefix != '' && strpos($config->get_string('newrelic.appname'), $newrelic_prefix) === false) { $application_name = $newrelic_prefix . $config->get_string('newrelic.appname'); $config->set('newrelic.appname', $application_name); } else { $application_name = $config->get_string('newrelic.appname'); } if ($config->get_string('newrelic.api_key') && $config->get_string('newrelic.account_id')) { w3_require_once(W3TC_LIB_W3_DIR . '/NewRelicService.php'); $nerser = new W3_NewRelicService($config->get_string('newrelic.api_key'), $config->get_string('newrelic.account_id')); $application_id = $nerser->get_application_id($application_name); if ($application_id) { $config->set('newrelic.application_id', $application_id); } } } } } if ($config->get_boolean('minify.enabled') && !$this->_config->get_boolean('minify.enabled') || $config->get_boolean('minify.enabled') && $config->get_boolean('browsercache.enabled') && !$this->_config->get_boolean('browsercache.enabled') || $config->get_boolean('minify.enabled') && $config->get_boolean('minify.auto') && !$this->_config->get_boolean('minify.auto') || $config->get_boolean('minify.enabled') && $config->get_string('minify.engine') != $this->_config->get_string('minify.engine')) { delete_transient('w3tc_minify_tested_filename_length'); } if (!w3_is_pro($this->_config)) { delete_transient('w3tc_license_status'); } } /** * Minify tab */ if ($this->_page == 'w3tc_minify' && !$this->_config->get_boolean('minify.auto')) { $js_groups = array(); $css_groups = array(); $js_files = W3_Request::get_array('js_files'); $css_files = W3_Request::get_array('css_files'); foreach ($js_files as $theme => $templates) { foreach ($templates as $template => $locations) { foreach ((array) $locations as $location => $types) { foreach ((array) $types as $files) { foreach ((array) $files as $file) { if (!empty($file)) { $js_groups[$theme][$template][$location]['files'][] = w3_normalize_file_minify($file); } } } } } } foreach ($css_files as $theme => $templates) { foreach ($templates as $template => $locations) { foreach ((array) $locations as $location => $files) { foreach ((array) $files as $file) { if (!empty($file)) { $css_groups[$theme][$template][$location]['files'][] = w3_normalize_file_minify($file); } } } } } $config->set('minify.js.groups', $js_groups); $config->set('minify.css.groups', $css_groups); $js_theme = W3_Request::get_string('js_theme'); $css_theme = W3_Request::get_string('css_theme'); $params = array_merge($params, array('js_theme' => $js_theme, 'css_theme' => $css_theme)); } if ($this->_page == 'w3tc_minify') { if ($config->get_integer('minify.auto.filename_length') > 246) { $config->set('minify.auto.filename_length', 246); } delete_transient('w3tc_minify_tested_filename_length'); } /** * Browser Cache tab */ if ($this->_page == 'w3tc_browsercache') { if ($config->get_boolean('browsercache.enabled') && $config->get_boolean('browsercache.no404wp') && !get_option('permalink_structure')) { $config->set('browsercache.no404wp', false); $redirect_permalink_error = 'fancy_permalinks_disabled_browsercache'; } $config->set('browsercache.timestamp', time()); if (in_array($engine = $this->_config->get_string('cdn.engine'), array('netdna', 'maxcdn'))) { w3_require_once(W3TC_LIB_NETDNA_DIR . '/NetDNA.php'); $keys = explode('+', $this->_config->get_string('cdn.' . $engine . '.authorization_key')); if (sizeof($keys) == 3) { list($alias, $consumerkey, $consumersecret) = $keys; try { $api = new NetDNA($alias, $consumerkey, $consumersecret); $disable_cooker_header = $config->get_boolean('browsercache.other.nocookies') || $config->get_boolean('browsercache.cssjs.nocookies'); $api->update_pull_zone($this->_config->get_string('cdn.' . $engine . '.zone_id'), array('ignore_setcookie_header' => $disable_cooker_header)); } catch (Exception $ex) { } } } } /** * Mobile tab */ if ($this->_page == 'w3tc_mobile') { $groups = W3_Request::get_array('mobile_groups'); $mobile_groups = array(); $cached_mobile_groups = array(); foreach ($groups as $group => $group_config) { $group = strtolower($group); $group = preg_replace('~[^0-9a-z_]+~', '_', $group); $group = trim($group, '_'); if ($group) { $theme = isset($group_config['theme']) ? trim($group_config['theme']) : 'default'; $enabled = isset($group_config['enabled']) ? (bool) $group_config['enabled'] : true; $redirect = isset($group_config['redirect']) ? trim($group_config['redirect']) : ''; $agents = isset($group_config['agents']) ? explode("\r\n", trim($group_config['agents'])) : array(); $mobile_groups[$group] = array('theme' => $theme, 'enabled' => $enabled, 'redirect' => $redirect, 'agents' => $agents); $cached_mobile_groups[$group] = $agents; } } /** * Allow plugins modify WPSC mobile groups */ $cached_mobile_groups = apply_filters('cached_mobile_groups', $cached_mobile_groups); /** * Merge existent and delete removed groups */ foreach ($mobile_groups as $group => $group_config) { if (isset($cached_mobile_groups[$group])) { $mobile_groups[$group]['agents'] = (array) $cached_mobile_groups[$group]; } else { unset($mobile_groups[$group]); } } /** * Add new groups */ foreach ($cached_mobile_groups as $group => $agents) { if (!isset($mobile_groups[$group])) { $mobile_groups[$group] = array('theme' => '', 'enabled' => true, 'redirect' => '', 'agents' => $agents); } } /** * Allow plugins modify W3TC mobile groups */ $mobile_groups = apply_filters('w3tc_mobile_groups', $mobile_groups); /** * Sanitize mobile groups */ foreach ($mobile_groups as $group => $group_config) { $mobile_groups[$group] = array_merge(array('theme' => '', 'enabled' => true, 'redirect' => '', 'agents' => array()), $group_config); $mobile_groups[$group]['agents'] = array_unique($mobile_groups[$group]['agents']); $mobile_groups[$group]['agents'] = array_map('strtolower', $mobile_groups[$group]['agents']); sort($mobile_groups[$group]['agents']); } $enable_mobile = false; foreach ($mobile_groups as $group_config) { if ($group_config['enabled']) { $enable_mobile = true; break; } } $config->set('mobile.enabled', $enable_mobile); $config->set('mobile.rgroups', $mobile_groups); } /** * Referrer tab */ if ($this->_page == 'w3tc_referrer') { $groups = W3_Request::get_array('referrer_groups'); $referrer_groups = array(); foreach ($groups as $group => $group_config) { $group = strtolower($group); $group = preg_replace('~[^0-9a-z_]+~', '_', $group); $group = trim($group, '_'); if ($group) { $theme = isset($group_config['theme']) ? trim($group_config['theme']) : 'default'; $enabled = isset($group_config['enabled']) ? (bool) $group_config['enabled'] : true; $redirect = isset($group_config['redirect']) ? trim($group_config['redirect']) : ''; $referrers = isset($group_config['referrers']) ? explode("\r\n", trim($group_config['referrers'])) : array(); $referrer_groups[$group] = array('theme' => $theme, 'enabled' => $enabled, 'redirect' => $redirect, 'referrers' => $referrers); } } /** * Allow plugins modify W3TC referrer groups */ $referrer_groups = apply_filters('w3tc_referrer_groups', $referrer_groups); /** * Sanitize mobile groups */ foreach ($referrer_groups as $group => $group_config) { $referrer_groups[$group] = array_merge(array('theme' => '', 'enabled' => true, 'redirect' => '', 'referrers' => array()), $group_config); $referrer_groups[$group]['referrers'] = array_unique($referrer_groups[$group]['referrers']); $referrer_groups[$group]['referrers'] = array_map('strtolower', $referrer_groups[$group]['referrers']); sort($referrer_groups[$group]['referrers']); } $enable_referrer = false; foreach ($referrer_groups as $group_config) { if ($group_config['enabled']) { $enable_referrer = true; break; } } $config->set('referrer.enabled', $enable_referrer); $config->set('referrer.rgroups', $referrer_groups); } /** * CDN tab */ if ($this->_page == 'w3tc_cdn') { $cdn_cnames = W3_Request::get_array('cdn_cnames'); $cdn_domains = array(); foreach ($cdn_cnames as $cdn_cname) { $cdn_cname = trim($cdn_cname); /** * Auto expand wildcard domain to 10 subdomains */ $matches = null; if (preg_match('~^\\*\\.(.*)$~', $cdn_cname, $matches)) { $cdn_domains = array(); for ($i = 1; $i <= 10; $i++) { $cdn_domains[] = sprintf('cdn%d.%s', $i, $matches[1]); } break; } if ($cdn_cname) { $cdn_domains[] = $cdn_cname; } } switch ($this->_config->get_string('cdn.engine')) { case 'ftp': $config->set('cdn.ftp.domain', $cdn_domains); break; case 's3': $config->set('cdn.s3.cname', $cdn_domains); break; case 'cf': $config->set('cdn.cf.cname', $cdn_domains); break; case 'cf2': $config->set('cdn.cf2.cname', $cdn_domains); break; case 'rscf': $config->set('cdn.rscf.cname', $cdn_domains); break; case 'azure': $config->set('cdn.azure.cname', $cdn_domains); break; case 'mirror': $config->set('cdn.mirror.domain', $cdn_domains); break; case 'maxcdn': $config->set('cdn.maxcdn.domain', $cdn_domains); break; case 'netdna': $config->set('cdn.netdna.domain', $cdn_domains); break; case 'cotendo': $config->set('cdn.cotendo.domain', $cdn_domains); break; case 'edgecast': $config->set('cdn.edgecast.domain', $cdn_domains); break; case 'att': $config->set('cdn.att.domain', $cdn_domains); break; case 'akamai': $config->set('cdn.akamai.domain', $cdn_domains); break; } } w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/extensions.php'); w3_extensions_admin_init(); $all_extensions = w3_get_extensions($config); $old_extensions = $this->_config->get_array('extensions.settings', array()); foreach ($all_extensions as $extension => $descriptor) { $extension_values = W3_Request::get_as_array('extensions.settings.'); $extension_keys = array(); $extension_settings = array(); $tmp_grp = str_replace('.', '_', $extension) . '_'; foreach ($extension_values as $key => $value) { if (strpos($key, $tmp_grp) !== false) { $extension_settings[str_replace($tmp_grp, '', $key)] = $value; } } if ($extension_settings) { $old_extension_settings = isset($old_extensions[$extension]) ? $old_extensions[$extension] : array(); if (!isset($old_extensions[$extension])) { $old_extensions[$extension] = array(); } $extension_keys[$extension] = apply_filters("w3tc_save_extension_settings-{$extension}", $extension_settings, $old_extension_settings); $new_settings = array_merge($old_extensions, $extension_keys); $config->set("extensions.settings", $new_settings); $old_extensions = $config->get_array('extensions.settings', array()); } } //CloudFront does not support expires header. So disable it when its used if ($config->get_string('cdn.engine') == 'cf2') { $config->set('browsercache.cssjs.expires', false); $config->set('browsercache.html.expires', false); $config->set('browsercache.other.expires', false); } $config = apply_filters('w3tc_save_options', $config, $this->_config, $config_admin); $config = apply_filters("w3tc_save_options-{$this->_page}", $config, $this->_config, $config_admin); do_action('w3tc_saving_options', $config, $this->_config, $config_admin); do_action("w3tc_saving_options-{$this->_page}", $config, $this->_config, $config_admin); w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/admin.php'); w3_config_save($this->_config, $config, $config_admin); switch ($this->_page) { case 'w3tc_cdn': /** * Handle Set Cookie Domain */ $set_cookie_domain_old = W3_Request::get_boolean('set_cookie_domain_old'); $set_cookie_domain_new = W3_Request::get_boolean('set_cookie_domain_new'); if ($set_cookie_domain_old != $set_cookie_domain_new) { if ($set_cookie_domain_new) { if (!$this->enable_cookie_domain()) { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'enable_cookie_domain'))); } } else { if (!$this->disable_cookie_domain()) { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'disable_cookie_domain'))); } } } break; case 'w3tc_general': break; } $notes[] = 'config_save'; if ($redirect_permalink_error) { w3_admin_redirect(array('w3tc_error' => $redirect_permalink_error, 'w3tc_note' => 'config_save')); } w3_admin_redirect_with_custom_messages($params, null, $notes, true); }
/** * Save config, can't decline save process. (difference from action_save) * * Do some actions on config keys update * Used in several places such as: * * 1. common config save * 2. import settings * * @param W3_Config $current_config * @param W3_Config $new_config * @param W3_ConfigAdmin $new_config_admin * @return bool * @throws Exception */ function w3_config_save($current_config, $new_config, $new_config_admin) { $master_config = $new_config->is_master() ? $new_config : new W3_Config(true); if ($master_config->get_integer('common.instance_id', 0) == 0) { $master_config->set('common.instance_id', mt_rand()); if (!$new_config->is_master()) { $master_config->save(); } } $old_config = new W3_Config(); $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', '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.engine', 'minify.css.groups', 'minify.js.enable', 'minify.js.engine', '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')); } /** * @var W3_ModuleStatus $modules */ $modules = w3_instance('W3_ModuleStatus'); if ($modules->is_running('cdn')) { $pgcache_dependencies = array_merge($pgcache_dependencies, array('cdn.enabled', '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.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.mirror.domain', 'cdn.mirror.ssl', 'cdn.netdna.domain', 'cdn.netdna.ssl', 'cdn.cotendo.domain', 'cdn.cotendo.ssl', 'cdn.edgecast.domain', 'cdn.edgecast.ssl', 'cdn.att.domain', 'cdn.att.ssl', 'cdn.reject.logged_roles', 'cdn.reject.roles', 'cdn.reject.ua', 'cdn.reject.uri', 'cdn.reject.files')); } elseif ($old_config->get_boolean('cdn.enabled') && !$new_config->get_boolean('cdn.enabled')) { $pgcache_dependencies = array_merge($pgcache_dependencies, array('cdn.enabled')); } 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')); } if ($new_config->get_boolean('browsercache.enabled') && $new_config->get_string('pgcache.engine') == 'file_generic') { $pgcache_dependencies = array_merge($pgcache_dependencies, array('browsercache.html.last_modified', 'browsercache.other.last_modified')); } $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 ($current_config->get_boolean('minify.enabled') && $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')); } /** * @var W3_ModuleStatus $modules */ $modules = w3_instance('W3_ModuleStatus'); if ($modules->is_running('cdn')) { $minify_dependencies = array_merge($minify_dependencies, array('cdn.engine', 'cdn.enabled')); } elseif ($old_config->get_boolean('cdn.enabled') && !$new_config->get_boolean('cdn.enabled')) { $minify_dependencies = array_merge($minify_dependencies, array('cdn.enabled')); } $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 ($current_config->get_boolean('objectcache.enabled')) { $objectcache_dependencies = array('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); } } if ($current_config->get_boolean('newrelic.enabled')) { if ($current_config->get_boolean('pgcache.enabled')) { if (w3_is_network() && $current_config->get_boolean('common.force_master')) { $new_config->set('pgcache.late_init', true); } } } do_action('w3tc_saved_options', $new_config, $new_config_admin); /** * Save config */ try { $new_config_admin->save(); $new_config->save(); } catch (Exception $ex) { // try to fix environment, it potentially can be fixed silently // dont show error here, it will be called again later // in admin_notices try { $environment = w3_instance('W3_AdminEnvironment'); $environment->fix_in_wpadmin($new_config); } catch (Exception $ex) { } // retry save process and complain now on failure try { $new_config_admin->save(); $new_config->save(); } catch (Exception $ex) { throw new Exception('<strong>Can\'t change configuration</strong>: ' . $ex->getMessage()); } } $w3_plugin_cdn = w3_instance('W3_Plugin_CdnAdmin'); /** * 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')) { w3tc_pgcache_flush(); } 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')) { w3tc_dbcache_flush(); } 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')) { w3tc_objectcache_flush(); } 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')) { w3tc_minify_flush(); } /** * 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 */ $current_config->load(); /** * React to config changes */ $environment = w3_instance('W3_AdminEnvironment'); $environment->fix_on_event($new_config, 'config_change', $old_config); /** * Update support us option */ w3_instance('W3_AdminLinks')->link_update($current_config); /** * 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'))) { w3_cdn_upload_minify(); } /** * Auto upload browsercache files to CDN */ if ($new_config->get_boolean('cdn.enabled') && $new_config->get_string('cdn.engine') == 'ftp') { w3_cdn_delete_browsercache($current_config); w3_cdn_upload_browsercache($current_config); } /** * Update CloudFront CNAMEs */ if ($update_cf_cnames) { $error = null; $w3_plugin_cdn->update_cnames($error); } return true; }