/** * Fixes environment once event occurs * * @param W3_Config $config * @param string $event * @param W3_Config|null $old_config * @throws SelfTestExceptions **/ public function fix_on_event($config, $event, $old_config = null) { if ($config->get_boolean('cdn.enabled') && !w3_is_cdn_mirror($config->get_string('cdn.engine'))) { if ($old_config != null && $config->get_integer('cdn.queue.interval') != $old_config->get_integer('cdn.queue.interval')) { $this->unschedule_queue_process(); } if (!wp_next_scheduled('w3_cdn_cron_queue_process')) { wp_schedule_event(current_time('timestamp'), 'w3_cdn_cron_queue_process', 'w3_cdn_cron_queue_process'); } } else { $this->unschedule_queue_process(); } if ($config->get_boolean('cdn.enabled') && $config->get_boolean('cdn.autoupload.enabled') && !w3_is_cdn_mirror($config->get_string('cdn.engine'))) { if ($old_config != null && $config->get_integer('cdn.autoupload.interval') != $old_config->get_integer('cdn.autoupload.interval')) { $this->unschedule_upload(); } if (!wp_next_scheduled('w3_cdn_cron_upload')) { wp_schedule_event(current_time('timestamp'), 'w3_cdn_cron_upload', 'w3_cdn_cron_upload'); } } else { $this->unschedule_upload(); } $exs = new SelfTestExceptions(); if ($config->get_boolean('cdn.enabled')) { try { $this->table_create($event == 'activate'); } catch (Exception $ex) { $exs->push($ex); } } if (count($exs->exceptions()) > 0) { throw $exs; } }
/** * 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'); }
/** * PHP5 Constructor */ function __construct() { require_once W3TC_LIB_W3_DIR . '/Config.php'; $this->_config =& W3_Config::instance(); $this->_debug = $this->_config->get_boolean('pgcache.debug'); $this->_lifetime = $this->_config->get_integer('pgcache.lifetime'); $this->_enhanced_mode = $this->_config->get_string('pgcache.engine') == 'file_pgcache'; }
/** * PHP5 constructor * * @param string $dbuser * @param string $dbpassword * @param string $dbname * @param string $dbhost */ function __construct($dbuser, $dbpassword, $dbname, $dbhost) { require_once W3TC_LIB_W3_DIR . '/Config.php'; $this->_config =& W3_Config::instance(); $this->_lifetime = $this->_config->get_integer('dbcache.lifetime'); if ($this->_config->get_boolean('dbcache.enabled') && $this->_config->get_boolean('dbcache.debug')) { ob_start(array(&$this, 'ob_callback')); } parent::__construct($dbuser, $dbpassword, $dbname, $dbhost); }
/** * Create container action * * @return void */ function action_cdn_create_container() { w3_require_once(W3TC_LIB_W3_DIR . '/Request.php'); w3_require_once(W3TC_LIB_W3_DIR . '/Cdn.php'); $engine = W3_Request::get_string('engine'); $config = W3_Request::get_array('config'); $config = array_merge($config, array('debug' => false)); $result = false; $error = __('Incorrect type.', 'w3-total-cache'); $container_id = ''; switch ($engine) { case 's3': case 'cf': case 'cf2': case 'rscf': case 'azure': $result = true; break; } if ($result) { $w3_cdn = W3_Cdn::instance($engine, $config); @set_time_limit($this->_config->get_integer('timelimit.cdn_container_create')); if ($w3_cdn->create_container($container_id, $error)) { $result = true; $error = __('Created successfully.', 'w3-total-cache'); } else { $result = false; $error = sprintf(__('Error: %s', 'w3-total-cache'), $error); } } $response = array('result' => $result, 'error' => $error, 'container_id' => $container_id); echo json_encode($response); }
/** * 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]; }
/** * Precaches external file * * @param string $url * @param string $type * @return string */ function _precache_file($url, $type) { $lifetime = $this->_config->get_integer('minify.lifetime'); $file_path = sprintf('%s/minify_%s.%s', W3TC_CACHE_FILE_MINIFY_DIR, md5($url), $type); $file_exists = file_exists($file_path); if (file_exists($file_path) && @filemtime($file_path) >= time() - $lifetime) { return $this->_get_minify_source($file_path, $url); } if (is_dir(W3TC_CACHE_FILE_MINIFY_DIR)) { if ($file_data = w3_url_get($url)) { if ($fp = @fopen($file_path, 'w')) { @fputs($fp, $file_data); @fclose($fp); return $this->_get_minify_source($file_path, $url); } else { $this->log(sprintf('Unable to open file %s for writing', $file_path)); } } else { $this->log(sprintf('Unable to download URL: %s', $url)); } } else { $this->log(sprintf('The cache directory %s does not exist', W3TC_CACHE_FILE_MINIFY_DIR)); } return $file_exists ? $this->_get_minify_source($file_path, $url) : false; }
/** * Send E-mail notification when error occurred * * @return boolean */ function _send_notification() { $from_email = 'wordpress@' . w3_get_domain($_SERVER['SERVER_NAME']); $from_name = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); $to_name = $to_email = get_option('admin_email'); $body = @file_get_contents(W3TC_INC_DIR . '/email/minify_error_notification.php'); $headers = array(sprintf('From: "%s" <%s>', addslashes($from_name), $from_email), sprintf('Reply-To: "%s" <%s>', addslashes($to_name), $to_email), 'Content-Type: text/html; charset=UTF-8'); @set_time_limit($this->_config->get_integer('timelimit.email_send')); $result = @wp_mail($to_email, 'W3 Total Cache Error Notification', $body, implode("\n", $headers)); return $result; }
/** * 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; }
/** * @param $cf_values * @return bool */ public function save_settings($cf_values) { @set_time_limit($this->_config->get_integer('timelimit.cloudflare_api_request')); ksort($cf_values); $cf_values = $this->_cleanup_settings($cf_values); foreach ($cf_values as $key => $settings) { if ($settings['old'] != $settings['new']) { $response = $this->api_request($key, $settings['new']); if (!$response || $response && $response->result != 'success') { return false; } } } delete_transient('w3tc_cloudflare_settings'); return true; }
/** * Precaches external file * * @param string $url * @param string $type * @return string */ function _precache_file($url, $type) { $lifetime = $this->_config->get_integer('minify.lifetime'); $file_path = sprintf('%s/minify_%s.%s', W3TC_CACHE_FILE_MINIFY_DIR, md5($url), $type); $file_exists = file_exists($file_path); if ($file_exists && @filemtime($file_path) >= time() - $lifetime) { return $this->_get_minify_source($file_path, $url); } if (is_dir(W3TC_CACHE_FILE_MINIFY_DIR)) { if (w3_download($url, $file_path) !== false) { return $this->_get_minify_source($file_path, $url); } else { $this->log(sprintf('Unable to download URL: %s', $url)); } } else { $this->log(sprintf('The cache directory %s does not exist', W3TC_CACHE_FILE_MINIFY_DIR)); } return $file_exists ? $this->_get_minify_source($file_path, $url) : false; }
/** * Returns cache object * * @return W3_Cache_Base */ function &_get_cache() { static $cache = array(); if (!isset($cache[0])) { $engine = $this->_config->get_string('dbcache.engine'); switch ($engine) { case 'memcached': $engineConfig = array('servers' => $this->_config->get_array('dbcache.memcached.servers'), 'persistant' => $this->_config->get_boolean('dbcache.memcached.persistant')); break; case 'file': $engineConfig = array('cache_dir' => W3TC_CACHE_FILE_DBCACHE_DIR, 'locking' => $this->_config->get_boolean('dbcache.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]; }
/** * Returns cache object * * @return W3_Cache_Base */ function _get_cache() { static $cache = array(); if (!isset($cache[0])) { $engine = $this->_config->get_string('dbcache.engine'); switch ($engine) { case 'memcached': $engineConfig = array('servers' => $this->_config->get_array('dbcache.memcached.servers'), 'persistant' => $this->_config->get_boolean('dbcache.memcached.persistant')); break; case 'file': $engineConfig = array('use_wp_hash', true, 'section' => 'db', 'locking' => $this->_config->get_boolean('dbcache.file.locking'), 'flush_timelimit' => $this->_config->get_integer('timelimit.cache_flush')); break; default: $engineConfig = array(); } $engineConfig['module'] = 'dbcache'; $engineConfig['host'] = w3_get_host(); $engineConfig['instance_id'] = w3_get_instance_id(); w3_require_once(W3TC_LIB_W3_DIR . '/Cache.php'); $cache[0] = W3_Cache::instance($engine, $engineConfig); } return $cache[0]; }
/** * Sends headers * @param boolean $is_404 * @param string $etag * @param integer $time * @param string $compression * @param array $custom_headers * @return boolean */ function _send_headers($is_404, $time, $etag, $compression, $custom_headers = array()) { $exit = false; $headers = array(); $curr_time = time(); $bc_lifetime = $this->_config->get_integer('browsercache.html.lifetime'); $expires = (is_null($time) ? $curr_time : $time) + $bc_lifetime; $max_age = $expires > $curr_time ? $expires - $curr_time : 0; if ($is_404) { /** * Add 404 header */ $headers = array_merge($headers, array('Status' => 'HTTP/1.1 404 Not Found')); } elseif (!is_null($time) && $this->_check_modified_since($time) || $this->_check_match($etag)) { /** * Add 304 header */ $headers = array_merge($headers, array('Status' => 'HTTP/1.1 304 Not Modified')); /** * Don't send content if it isn't modified */ $exit = true; } if ($this->_config->get_boolean('browsercache.enabled')) { if ($this->_config->get_boolean('browsercache.html.last_modified')) { $headers = array_merge($headers, array('Last-Modified' => w3_http_date($time))); } if ($this->_config->get_boolean('browsercache.html.expires')) { $headers = array_merge($headers, array('Expires' => w3_http_date($expires))); } if ($this->_config->get_boolean('browsercache.html.cache.control')) { switch ($this->_config->get_string('browsercache.html.cache.policy')) { case 'cache': $headers = array_merge($headers, array('Pragma' => 'public', 'Cache-Control' => 'public')); break; case 'cache_public_maxage': $headers = array_merge($headers, array('Pragma' => 'public', 'Cache-Control' => sprintf('max-age=%d, public', $max_age))); break; case 'cache_validation': $headers = array_merge($headers, array('Pragma' => 'public', 'Cache-Control' => 'public, must-revalidate, proxy-revalidate')); break; case 'cache_noproxy': $headers = array_merge($headers, array('Pragma' => 'public', 'Cache-Control' => 'private, must-revalidate')); break; case 'cache_maxage': $headers = array_merge($headers, array('Pragma' => 'public', 'Cache-Control' => sprintf('max-age=%d, public, must-revalidate, proxy-revalidate', $max_age))); break; case 'no_cache': $headers = array_merge($headers, array('Pragma' => 'no-cache', 'Cache-Control' => 'max-age=0, private, no-store, no-cache, must-revalidate')); break; } } if ($this->_config->get_boolean('browsercache.html.etag')) { $headers = array_merge($headers, array('Etag' => $etag)); } if ($this->_config->get_boolean('browsercache.html.w3tc')) { $headers = array_merge($headers, array('X-Powered-By' => W3TC_POWERED_BY)); } } $vary = ''; //compressed && UAG if ($compression && $this->_get_mobile_group()) { $vary = 'Accept-Encoding,User-Agent,Cookie'; $headers = array_merge($headers, array('Content-Encoding' => $compression)); //compressed } elseif ($compression) { $vary = 'Accept-Encoding'; $headers = array_merge($headers, array('Content-Encoding' => $compression)); //uncompressed && UAG } elseif ($this->_get_mobile_group()) { $vary = 'User-Agent,Cookie'; } //Add Cookie to vary if user logged in and not previously set if (!$this->_check_logged_in() && strpos($vary, 'Cookie') === false) { if ($vary) { $vary .= ',Cookie'; } else { $vary = 'Cookie'; } } /** * Add vary header */ if ($vary) { $headers = array_merge($headers, array('Vary' => $vary)); } /** * Add custom headers */ $headers = array_merge($headers, $custom_headers); /** * Disable caching for preview mode */ if (w3_is_preview_mode()) { $headers = array_merge($headers, array('Pragma' => 'private', 'Cache-Control' => 'private')); } /** * Send headers to client */ $result = $this->_headers($headers); if ($exit) { exit; } return $result; }
/** * Generates directives for file cache dir * * @param W3_Config $config * @return string */ private function rules_cache_generate_nginx($config) { $cache_root = w3_path(W3TC_CACHE_PAGE_ENHANCED_DIR); $cache_dir = rtrim(str_replace(w3_get_document_root(), '', $cache_root), '/'); if (w3_is_network()) { $cache_dir = preg_replace('~/w3tc.*?/~', '/w3tc.*?/', $cache_dir, 1); } $browsercache = $config->get_boolean('browsercache.enabled'); $compression = $browsercache && $config->get_boolean('browsercache.html.compression'); $expires = $browsercache && $config->get_boolean('browsercache.html.expires'); $lifetime = $browsercache ? $config->get_integer('browsercache.html.lifetime') : 0; $cache_control = $browsercache && $config->get_boolean('browsercache.html.cache.control'); $w3tc = $browsercache && $config->get_integer('browsercache.html.w3tc'); $common_rules = ''; if ($expires) { $common_rules .= " expires modified " . $lifetime . "s;\n"; } if ($w3tc) { $common_rules .= " add_header X-Powered-By \"" . W3TC_POWERED_BY . "\";\n"; } if ($compression) { $common_rules .= " add_header Vary \"Accept-Encoding, Cookie\";\n"; } else { $common_rules .= " add_header Vary Cookie;\n"; } if ($cache_control) { $cache_policy = $config->get_string('browsercache.html.cache.policy'); switch ($cache_policy) { case 'cache': $common_rules .= " add_header Pragma \"public\";\n"; $common_rules .= " add_header Cache-Control \"public\";\n"; break; case 'cache_public_maxage': $common_rules .= " add_header Pragma \"public\";\n"; $common_rules .= " add_header Cache-Control \"max-age=" . $lifetime . ", public\";\n"; break; case 'cache_validation': $common_rules .= " add_header Pragma \"public\";\n"; $common_rules .= " add_header Cache-Control \"public, must-revalidate, proxy-revalidate\";\n"; break; case 'cache_noproxy': $common_rules .= " add_header Pragma \"public\";\n"; $common_rules .= " add_header Cache-Control \"private, must-revalidate\";\n"; break; case 'cache_maxage': $common_rules .= " add_header Pragma \"public\";\n"; $common_rules .= " add_header Cache-Control \"max-age=" . $lifetime . ", public, must-revalidate, proxy-revalidate\";\n"; break; case 'no_cache': $common_rules .= " add_header Pragma \"no-cache\";\n"; $common_rules .= " add_header Cache-Control \"max-age=0, private, no-store, no-cache, must-revalidate\";\n"; break; } } $rules = ''; $rules .= W3TC_MARKER_BEGIN_PGCACHE_CACHE . "\n"; $rules .= "location ~ " . $cache_dir . ".*html\$ {\n"; $rules .= $common_rules; $rules .= "}\n"; if ($compression) { $rules .= "location ~ " . $cache_dir . ".*gzip\$ {\n"; $rules .= " gzip off;\n"; $rules .= " types {}\n"; $rules .= " default_type text/html;\n"; $rules .= $common_rules; $rules .= " add_header Content-Encoding gzip;\n"; $rules .= "}\n"; } $rules .= W3TC_MARKER_END_PGCACHE_CACHE . "\n"; return $rules; }
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(); }
/** * Send support request action * * @return void */ function action_support_request() { w3_require_once(W3TC_LIB_W3_DIR . '/Request.php'); $request_type = W3_Request::get_string('request_type'); $payment = W3_Request::get_boolean('payment'); $request_id = W3_Request::get_string('request_id'); $url = W3_Request::get_string('url'); $name = W3_Request::get_string('name'); $email = W3_Request::get_string('email'); $twitter = W3_Request::get_string('twitter'); $phone = W3_Request::get_string('phone'); $subject = W3_Request::get_string('subject'); $description = W3_Request::get_string('description'); $templates = W3_Request::get_array('templates'); $forum_url = W3_Request::get_string('forum_url'); $wp_login = W3_Request::get_string('wp_login'); $wp_password = W3_Request::get_string('wp_password'); $ftp_host = W3_Request::get_string('ftp_host'); $ftp_login = W3_Request::get_string('ftp_login'); $ftp_password = W3_Request::get_string('ftp_password'); $subscribe_releases = W3_Request::get_string('subscribe_releases'); $subscribe_customer = W3_Request::get_string('subscribe_customer'); $params = array('request_type' => $request_type, 'payment' => $payment, 'url' => $url, 'name' => $name, 'email' => $email, 'twitter' => $twitter, 'phone' => $phone, 'subject' => $subject, 'description' => $description, 'forum_url' => $forum_url, 'wp_login' => $wp_login, 'wp_password' => $wp_password, 'ftp_host' => $ftp_host, 'ftp_login' => $ftp_login, 'ftp_password' => $ftp_password, 'subscribe_releases' => $subscribe_releases, 'subscribe_customer' => $subscribe_customer); $post = $params; foreach ($templates as $template_index => $template) { $template_key = sprintf('templates[%d]', $template_index); $params[$template_key] = $template; } if (!isset($this->_request_types[$request_type])) { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_type')), false); } $required = array('bug_report' => 'url,name,email,subject,description', 'new_feature' => 'url,name,email,subject,description', 'email_support' => 'url,name,email,subject,description', 'phone_support' => 'url,name,email,subject,description,phone', 'plugin_config' => 'url,name,email,subject,description,wp_login,wp_password', 'theme_config' => 'url,name,email,subject,description,wp_login,wp_password,ftp_host,ftp_login,ftp_password', 'linux_config' => 'url,name,email,subject,description,wp_login,wp_password,ftp_host,ftp_login,ftp_password'); if (strstr($required[$request_type], 'url') !== false && $url == '') { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_url')), false); } if (strstr($required[$request_type], 'name') !== false && $name == '') { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_name')), false); } if (strstr($required[$request_type], 'email') !== false && !preg_match('~^[a-z0-9_\\-\\.]+@[a-z0-9-\\.]+\\.[a-z]{2,5}$~', $email)) { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_email')), false); } if (strstr($required[$request_type], 'phone') !== false && !preg_match('~^[0-9\\-\\.\\ \\(\\)\\+]+$~', $phone)) { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_phone')), false); } if (strstr($required[$request_type], 'subject') !== false && $subject == '') { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_subject')), false); } if (strstr($required[$request_type], 'description') !== false && $description == '') { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_description')), false); } if (strstr($required[$request_type], 'wp_login') !== false && $wp_login == '') { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_wp_login')), false); } if (strstr($required[$request_type], 'wp_password') !== false && $wp_password == '') { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_wp_password')), false); } if (strstr($required[$request_type], 'ftp_host') !== false && $ftp_host == '') { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_ftp_host')), false); } if (strstr($required[$request_type], 'ftp_login') !== false && $ftp_login == '') { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_ftp_login')), false); } if (strstr($required[$request_type], 'ftp_password') !== false && $ftp_password == '') { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_ftp_password')), false); } /** * Add attachments */ $attachments = array(); $attach_files = array(w3_get_wp_config_path(), w3_cache_blog_dir('log') . '/minify.log', w3_get_pgcache_rules_core_path(), w3_get_pgcache_rules_cache_path(), w3_get_browsercache_rules_cache_path(), w3_get_browsercache_rules_no404wp_path(), w3_get_minify_rules_core_path(), w3_get_minify_rules_cache_path()); /** * Attach config files */ if ($handle = opendir(W3TC_CONFIG_DIR)) { while (($entry = @readdir($handle)) !== false) { if ($entry == '.' || $entry == '..' || $entry == 'index.html') { continue; } $attachments[] = W3TC_CONFIG_DIR . '/' . $entry; } closedir($handle); } foreach ($attach_files as $attach_file) { if ($attach_file && file_exists($attach_file) && !in_array($attach_file, $attachments)) { $attachments[] = $attach_file; } } /** * Attach server info */ $server_info = print_r($this->get_server_info(), true); $server_info = str_replace("\n", "\r\n", $server_info); $server_info_path = W3TC_CACHE_TMP_DIR . '/server_info.txt'; if (@file_put_contents($server_info_path, $server_info)) { $attachments[] = $server_info_path; } /** * Attach phpinfo */ ob_start(); phpinfo(); $php_info = ob_get_contents(); ob_end_clean(); $php_info_path = W3TC_CACHE_TMP_DIR . '/php_info.html'; if (@file_put_contents($php_info_path, $php_info)) { $attachments[] = $php_info_path; } /** * Attach self-test */ ob_start(); $this->action_self_test(); $self_test = ob_get_contents(); ob_end_clean(); $self_test_path = W3TC_CACHE_TMP_DIR . '/self_test.html'; if (@file_put_contents($self_test_path, $self_test)) { $attachments[] = $self_test_path; } /** * Attach templates */ foreach ($templates as $template) { if (!empty($template)) { $attachments[] = $template; } } /** * Attach other files */ if (!empty($_FILES['files'])) { $files = (array) $_FILES['files']; for ($i = 0, $l = count($files); $i < $l; $i++) { if (isset($files['tmp_name'][$i]) && isset($files['name'][$i]) && isset($files['error'][$i]) && $files['error'][$i] == UPLOAD_ERR_OK) { $path = W3TC_CACHE_TMP_DIR . '/' . $files['name'][$i]; if (@move_uploaded_file($files['tmp_name'][$i], $path)) { $attachments[] = $path; } } } } $data = array(); if (!empty($wp_login) && !empty($wp_password)) { $data['WP Admin login'] = $wp_login; $data['WP Admin password'] = $wp_password; } if (!empty($ftp_host) && !empty($ftp_login) && !empty($ftp_password)) { $data['SSH / FTP host'] = $ftp_host; $data['SSH / FTP login'] = $ftp_login; $data['SSH / FTP password'] = $ftp_password; } /** * Store request data for future access */ if (count($data)) { $hash = md5(microtime()); $request_data = get_option('w3tc_request_data', array()); $request_data[$hash] = $data; update_option('w3tc_request_data', $request_data); $request_data_url = sprintf('%s/w3tc_request_data/%s', w3_get_home_url(), $hash); } else { $request_data_url = ''; } $nonce = wp_create_nonce('w3tc_support_request'); if (is_network_admin()) { update_site_option('w3tc_support_request', $nonce); } else { update_option('w3tc_support_request', $nonce); } $file_access = WP_PLUGIN_URL . '/' . dirname(W3TC_FILE) . '/pub/files.php'; if (w3_get_domain(w3_get_home_url()) != w3_get_domain(w3_get_site_url())) { $file_access = str_replace(w3_get_domain(w3_get_home_url()), w3_get_domain(w3_get_site_url()), $file_access); } $post['file_access'] = $file_access; $post['nonce'] = $nonce; $post['request_data_url'] = $request_data_url; $post['ip'] = $_SERVER['REMOTE_ADDR']; $post['user_agent'] = $_SERVER['HTTP_USER_AGENT']; $post['version'] = W3TC_VERSION; $post['plugin'] = 'W3 Total Cache'; $post['request_id'] = $request_id; $license_level = 'community'; if (w3_is_pro($this->_config)) { $license_level = 'pro'; } elseif (w3_is_enterprise($this->_config)) { $license_level = 'enterprise'; } $post['license_level'] = $license_level; $unset = array('wp_login', 'wp_password', 'ftp_host', 'ftp_login', 'ftp_password'); foreach ($unset as $key) { unset($post[$key]); } foreach ($attachments as $attachment) { if (is_network_admin()) { update_site_option('attachment_' . md5($attachment), $attachment); } else { update_option('attachment_' . md5($attachment), $attachment); } } $post = array_merge($post, array('files' => $attachments)); if (defined('W3_SUPPORT_DEBUG') && W3_SUPPORT_DEBUG) { $data = sprintf("[%s] Post support request\n", date('r')); foreach ($post as $key => $value) { $data .= sprintf("%s => %s\n", $key, is_array($value) ? implode(',', $value) : $value); } $filename = w3_cache_blog_dir('log') . '/support.log'; if (!is_dir(dirname($filename))) { w3_mkdir_from(dirname($filename), W3TC_CACHE_DIR); } @file_put_contents($filename, $data, FILE_APPEND); } $response = wp_remote_post(W3TC_SUPPORT_REQUEST_URL, array('body' => $post, 'timeout' => $this->_config->get_integer('timelimit.email_send'))); if (defined('W3_SUPPORT_DEBUG') && W3_SUPPORT_DEBUG) { $filename = w3_cache_blog_dir('log') . '/support.log'; $data = sprintf("[%s] Post response \n%s\n", date('r'), print_r($response, true)); @file_put_contents($filename, $data, FILE_APPEND); } if (!is_wp_error($response)) { $result = $response['response']['code'] == 200 && $response['body'] == 'Ok'; } else { $result = false; } /** * Remove temporary files */ foreach ($attachments as $attachment) { if (strstr($attachment, W3TC_CACHE_TMP_DIR) !== false) { @unlink($attachment); } if (is_network_admin()) { delete_site_option('attachment_' . md5($attachment)); } else { delete_option('attachment_' . md5($attachment)); } } if (is_network_admin()) { delete_site_option('w3tc_support_request'); } else { delete_option('w3tc_support_request'); } if ($result) { w3_admin_redirect(array('tab' => 'general', 'w3tc_note' => 'support_request'), false); } else { w3_admin_redirect(array_merge($params, array('request_type' => $request_type, 'w3tc_error' => 'support_request')), false); } }
/** * Generates directives for file cache dir * * @param W3_Config $config * @return string */ private function rules_cache_generate_nginx($config) { $cache_dir = w3_filename_to_uri(W3TC_CACHE_MINIFY_DIR); $browsercache = $config->get_boolean('browsercache.enabled'); $compression = $browsercache && $config->get_boolean('browsercache.cssjs.compression'); $expires = $browsercache && $config->get_boolean('browsercache.cssjs.expires'); $lifetime = $browsercache ? $config->get_integer('browsercache.cssjs.lifetime') : 0; $cache_control = $browsercache && $config->get_boolean('browsercache.cssjs.cache.control'); $w3tc = $browsercache && $config->get_integer('browsercache.cssjs.w3tc'); $rules = ''; $rules .= W3TC_MARKER_BEGIN_MINIFY_CACHE . "\n"; $common_rules = ''; if ($expires) { $common_rules .= " expires modified " . $lifetime . "s;\n"; } if ($w3tc) { $common_rules .= " add_header X-Powered-By \"" . W3TC_POWERED_BY . "\";\n"; } if ($compression) { $common_rules .= " add_header Vary \"Accept-Encoding\";\n"; } if ($cache_control) { $cache_policy = $config->get_string('browsercache.cssjs.cache.policy'); switch ($cache_policy) { case 'cache': $common_rules .= " add_header Pragma \"public\";\n"; $common_rules .= " add_header Cache-Control \"public\";\n"; break; case 'cache_public_maxage': $common_rules .= " add_header Pragma \"public\";\n"; $common_rules .= " add_header Cache-Control \"max-age=" . $lifetime . ", public\";\n"; break; case 'cache_validation': $common_rules .= " add_header Pragma \"public\";\n"; $common_rules .= " add_header Cache-Control \"public, must-revalidate, proxy-revalidate\";\n"; break; case 'cache_noproxy': $common_rules .= " add_header Pragma \"public\";\n"; $common_rules .= " add_header Cache-Control \"private, must-revalidate\";\n"; break; case 'cache_maxage': $common_rules .= " add_header Pragma \"public\";\n"; $common_rules .= " add_header Cache-Control \"max-age=" . $lifetime . ", public, must-revalidate, proxy-revalidate\";\n"; break; case 'no_cache': $common_rules .= " add_header Pragma \"no-cache\";\n"; $common_rules .= " add_header Cache-Control \"max-age=0, private, no-store, no-cache, must-revalidate\";\n"; break; } } $rules .= "location ~ " . $cache_dir . ".*\\.js\$ {\n"; $rules .= " types {}\n"; $rules .= " default_type application/x-javascript;\n"; $rules .= $common_rules; $rules .= "}\n"; $rules .= "location ~ " . $cache_dir . ".*\\.css\$ {\n"; $rules .= " types {}\n"; $rules .= " default_type text/css;\n"; $rules .= $common_rules; $rules .= "}\n"; if ($compression) { $rules .= "location ~ " . $cache_dir . ".*js\\.gzip\$ {\n"; $rules .= " gzip off;\n"; $rules .= " types {}\n"; $rules .= " default_type application/x-javascript;\n"; $rules .= $common_rules; $rules .= " add_header Content-Encoding gzip;\n"; $rules .= "}\n"; $rules .= "location ~ " . $cache_dir . ".*css\\.gzip\$ {\n"; $rules .= " gzip off;\n"; $rules .= " types {}\n"; $rules .= " default_type text/css;\n"; $rules .= $common_rules; $rules .= " add_header Content-Encoding gzip;\n"; $rules .= "}\n"; } $rules .= W3TC_MARKER_END_MINIFY_CACHE . "\n"; return $rules; }
/** * Adds cache rules for type to &$rules * * @param W3_Config $config * @param string $rules * @param array $mime_types * @param string $section * @param boolean $write_location * @param boolean $cdnftp * @return void */ private function _rules_cache_generate_nginx_for_type($config, &$rules, $mime_types, $section, $write_location = false, $cdnftp = false) { $expires = $config->get_boolean('browsercache.' . $section . '.expires'); $cache_control = $config->get_boolean('browsercache.' . $section . '.cache.control'); $w3tc = $config->get_boolean('browsercache.' . $section . '.w3tc'); if ($expires || $cache_control || $w3tc) { $lifetime = $config->get_integer('browsercache.' . $section . '.lifetime'); $extensions = array_keys($mime_types); // Remove ext from filesmatch if its the same as permalink extension $pext = strtolower(pathinfo(get_option('permalink_structure'), PATHINFO_EXTENSION)); if ($pext) { $extensions = $this->_remove_extension_from_list($extensions, $pext); } $rules .= "location ~ \\.(" . implode('|', $extensions) . ")\$ {\n"; if ($expires) { $rules .= " expires " . $lifetime . "s;\n"; } if ($cache_control) { $cache_policy = $config->get_string('browsercache.cssjs.cache.policy'); switch ($cache_policy) { case 'cache': $rules .= " add_header Pragma \"public\";\n"; $rules .= " add_header Cache-Control \"public\";\n"; break; case 'cache_public_maxage': $rules .= " add_header Pragma \"public\";\n"; $rules .= " add_header Cache-Control \"max-age=" . $lifetime . ", public\";\n"; break; case 'cache_validation': $rules .= " add_header Pragma \"public\";\n"; $rules .= " add_header Cache-Control \"public, must-revalidate, proxy-revalidate\";\n"; break; case 'cache_noproxy': $rules .= " add_header Pragma \"public\";\n"; $rules .= " add_header Cache-Control \"private, must-revalidate\";\n"; break; case 'cache_maxage': $rules .= " add_header Pragma \"public\";\n"; $rules .= " add_header Cache-Control \"max-age=" . $lifetime . ", public, must-revalidate, proxy-revalidate\";\n"; break; case 'no_cache': $rules .= " add_header Pragma \"no-cache\";\n"; $rules .= " add_header Cache-Control \"max-age=0, private, no-store, no-cache, must-revalidate\";\n"; break; } } $w3_dispatcher = w3_instance('W3_Dispatcher'); $rules .= $w3_dispatcher->on_browsercache_rules_generation_for_section($config, $cdnftp, $section); if ($w3tc) { $rules .= " add_header X-Powered-By \"" . W3TC_POWERED_BY . "\";\n"; } if ($write_location) { $rules .= ' try_files $uri $uri/ $uri.html /index.php?$args;' . "\n"; } $rules .= "}\n"; } }
/** * 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; }
/** * Check config file * @param W3_Config $config * @param SelfTestExceptions $exs */ private function notify_no_config_present($config, $exs) { if ($config->own_config_exists() && $config->get_integer('common.instance_id', 0) != 0) { return; } $onclick = 'document.location.href=\'' . addslashes(wp_nonce_url('admin.php?page=w3tc_general&w3tc_save_options')) . '\';'; $button = '<input type="button" class="button w3tc" ' . 'value="save the settings" onclick="' . $onclick . '" />'; $exs->push(new SelfTestFailedException('<strong>W3 Total Cache:</strong> ' . 'Default settings are in use. The configuration file could ' . 'not be read or doesn\'t exist. Please ' . $button . ' to create the file.')); }
/** * 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; }