/** * 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; } }
/** * @param W3_Config $config * @param W3_Config $config_master * @param bool $do_merge if to merge with network main site * @return string */ public static function get_wordpress_appname($config, $config_master, $do_merge = true) { if (w3_is_network()) { if ($config_master->get_boolean('newrelic.use_network_wide_id')) { $appname = $config_master->get_string('newrelic.appname'); } else { $merge = $config->get_boolean('newrelic.merge_with_network'); $merge_name = ''; if ($do_merge && $merge && w3_get_blog_id() != 0) { $merge_name = ';' . $config_master->get_string('newrelic.appname'); } if (w3_get_blog_id() != 0 && !$config->get_boolean('common.force_master')) { $appname = $config->get_string('newrelic.appname', ''); if (empty($appname)) { $prefix = $config->get_string('newrelic.appname_prefix'); $appname = $prefix . trim(w3_get_home_domain() . w3_get_site_path(), '/'); } } else { if (w3_get_blog_id() != 0) { $prefix = $config->get_string('newrelic.appname_prefix'); $appname = $prefix . trim(w3_get_home_domain() . w3_get_site_path(), '/'); } else { $appname = $config->get_string('newrelic.appname'); } } $appname = $appname . $merge_name; } } else { $appname = $config->get_string('newrelic.appname'); } return $appname; }
/** * @param W3_Config $config * @param W3_Config $old_config */ function possible_state_change($config, $old_config) { if ($old_config->get_string('plugin.license_key') != '' && $config->get_string('plugin.license_key') == '') { $result = edd_w3edge_w3tc_deactivate_license($old_config->get_string('plugin.license_key')); if ($result) { $this->site_inactivated = true; } delete_transient('w3tc_license_status'); } else { if ($old_config->get_string('plugin.license_key') == '' && $config->get_string('plugin.license_key') != '') { $result = edd_w3edge_w3tc_activate_license($config->get_string('plugin.license_key')); if ($result) { $this->site_activated = true; } delete_transient('w3tc_license_status'); } else { if ($old_config->get_string('plugin.license_key') != $config->get_string('plugin.license_key')) { $result = edd_w3edge_w3tc_activate_license($config->get_string('plugin.license_key')); if ($result) { $this->site_activated = true; } delete_transient('w3tc_license_status'); } } } }
/** * PHP5-style constructor * * @param array $config */ function __construct($config = array()) { $this->_config = w3_instance('W3_Config'); if (empty($config)) { $this->_cf_config = array('email' => $this->_config->get_string('cloudflare.email'), 'key' => $this->_config->get_string('cloudflare.key'), 'zone' => $this->_config->get_string('cloudflare.zone')); } else { $this->_cf_config = array_merge(array('email' => '', 'key' => '', 'zone' => ''), $config); } }
/** * @param W3_Config $config * @param W3_ConfigAdmin|null $config_admin * @return array */ function notifications($config, $config_admin) { w3_require_once(W3TC_LIB_W3_DIR . '/Request.php'); $page = W3_Request::get_string('page'); $notes = array(); if (!w3_is_cdn_mirror($config->get_string('cdn.engine'))) { /** * Show notification after theme change */ if ($config->get_boolean('notes.theme_changed')) { $notes[] = sprintf(__('The active theme has changed, please %s now to ensure proper operation. %s', 'w3-total-cache'), w3_button_popup(__('upload active theme files', 'w3-total-cache'), 'cdn_export', 'cdn_export_type=theme'), w3_button_hide_note(__('Hide this message', 'w3-total-cache'), 'theme_changed')); } /** * Show notification after WP upgrade */ if ($config->get_boolean('notes.wp_upgraded')) { $notes[] = sprintf(__('Upgraded WordPress? Please %s files now to ensure proper operation. %s', 'w3-total-cache'), w3_button_popup('upload wp-includes', 'cdn_export', 'cdn_export_type=includes'), w3_button_hide_note(__('Hide this message', 'w3-total-cache'), 'wp_upgraded')); } /** * Show notification after CDN enable */ if ($config->get_boolean('notes.cdn_upload') || $config->get_boolean('notes.cdn_reupload')) { $cdn_upload_buttons = array(); if ($config->get_boolean('cdn.includes.enable')) { $cdn_upload_buttons[] = w3_button_popup('wp-includes', 'cdn_export', 'cdn_export_type=includes'); } if ($config->get_boolean('cdn.theme.enable')) { $cdn_upload_buttons[] = w3_button_popup('theme files', 'cdn_export', 'cdn_export_type=theme'); } if ($config->get_boolean('minify.enabled') && $config->get_boolean('cdn.minify.enable') && !$config->get_boolean('minify.auto')) { $cdn_upload_buttons[] = w3_button_popup('minify files', 'cdn_export', 'cdn_export_type=minify'); } if ($config->get_boolean('cdn.custom.enable')) { $cdn_upload_buttons[] = w3_button_popup('custom files', 'cdn_export', 'cdn_export_type=custom'); } if ($config->get_boolean('notes.cdn_upload')) { $notes[] = sprintf(__('Make sure to %s and upload the %s, files to the <acronym title="Content Delivery Network">CDN</acronym> to ensure proper operation. %s', 'w3-total-cache'), w3_button_popup('export the media library', 'cdn_export_library'), implode(', ', $cdn_upload_buttons), w3_button_hide_note('Hide this message', 'cdn_upload')); } if ($config->get_boolean('notes.cdn_reupload')) { $notes[] = sprintf(__('Settings that affect Browser Cache settings for files hosted by the CDN have been changed. To apply the new settings %s and %s. %s', 'w3-total-cache'), w3_button_popup(__('export the media library', 'w3-total-cache'), 'cdn_export_library'), implode(', ', $cdn_upload_buttons), w3_button_hide_note(__('Hide this message', 'w3-total-cache'), 'cdn_reupload')); } } } if (in_array($config->get_string('cdn.engine'), array('netdna', 'maxcdn')) && $config_admin->get_boolean('notes.maxcdn_whitelist_ip') && $config_admin->get_integer('track.maxcdn_authorize') == 0 && $config->get_string('cdn.' . $config->get_string('cdn.engine') . '.authorization_key')) { $notes[] = sprintf(__('Make sure to whitelist your servers IPs. Follow the instructions on %s. The IP for this server is %s. %s', 'w3-total-cache'), '<a href="http://support.maxcdn.com/tutorials/how-to-whitelist-your-server-ip-to-use-the-api/">MaxCDN</a>', $_SERVER['SERVER_ADDR'], w3_button_hide_note('Hide this message', 'maxcdn_whitelist_ip', '', true)); } return $notes; }
private function _criteria_matched($criteria) { if (is_array($criteria)) { $enabled = true; $compare = '&&'; foreach ($criteria as $val) { if (is_array($val)) { if ($val[1] == '!=') { $enabled = $this->_compare_criteria_values($enabled, $this->_config->get_string($val[0]) != $val[2], $compare); } elseif ($val[1] == '==') { $enabled = $this->_compare_criteria_values($enabled, $this->_config->get_string($val[0]) == $val[2], $compare); } else { $enabled = $enabled || $this->_criteria_matched($val); } } elseif ($val != '||' && $val != '&&') { $enabled = $this->_compare_criteria_values($enabled, $this->_config->get_boolean($val), $compare); } else { $compare = $val; } } } else { $enabled = is_null($criteria) || $this->_config->get_boolean($criteria); } return $enabled; }
/** * 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]; }
public function run() { $this->_config = w3_instance('W3_Config'); $this->_config_admin = w3_instance('W3_ConfigAdmin'); w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/admin.php'); w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/admin_ui.php'); $this->_page = w3tc_get_current_page(); if (is_network_admin() || !w3_is_multisite()) { $this->edge_notification(); } if (is_w3tc_admin_page()) { add_action('admin_head', array($this, 'admin_head')); add_action('w3tc_hide_button_custom-edge_mode', array($this, 'hide_edge_mode_notification')); $support_reminder = $this->_config->get_boolean('notes.support_us') && $this->_config_admin->get_integer('common.install') < time() - W3TC_SUPPORT_US_TIMEOUT && $this->_config->get_string('common.support') == '' && !$this->_config->get_boolean('common.tweeted'); if ($support_reminder || w3tc_show_notification('support_us_popup')) { add_action('w3tc-dashboard-head', array($this, 'support_us_nag')); } add_action('w3tc-dashboard-head', array($this, 'edge_nag')); } }
/** * Create NetDNA/MaxCDN pullzone */ function action_cdn_create_netdna_maxcdn_pull_zone() { w3_require_once(W3TC_LIB_W3_DIR . '/Request.php'); w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/admin.php'); w3_require_once(W3TC_LIB_NETDNA_DIR . '/NetDNA.php'); $type = W3_Request::get_string('type'); $name = W3_Request::get_string('name'); $label = W3_Request::get_string('label'); $cdn_engine = $type; $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; $zone['use_stale'] = 1; $zone['queries'] = 1; $zone['compress'] = 1; $zone['backend_compress'] = 1; try { $response = $api->create_pull_zone($zone); try { $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}.domain", array($temporary_url)); if ($test_result) { $this->_config->set("cdn.enabled", true); } } $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' => $type, '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))); } 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())); } }
/** * Purge the CloudFlare cache * @return void */ function flush_cloudflare() { $response = null; w3_require_once(W3TC_LIB_W3_DIR . '/Request.php'); $email = $this->_config->get_string('email'); $key = $this->_config->get_string('key'); $zone = $this->_config->get_string('zone'); if ($email && $key && $zone) { $config = array('email' => $email, 'key' => $key, 'zone' => $zone); w3_require_once(W3TC_LIB_W3_DIR . '/CloudFlare.php'); @($w3_cloudflare = new W3_CloudFlare($config)); $w3_cloudflare->purge(); } }
/** * If BrowserCache should generate rules specific for CDN. Used with CDN FTP * @return boolean; */ public function should_browsercache_generate_rules_for_cdn() { if ($this->_config->get_boolean('cdn.enabled') && $this->_config->get_string('cdn.engine') == 'ftp') { if (is_null($this->_cdncommon)) { $this->_cdncommon = w3_instance('W3_Plugin_CdnCommon'); } $cdn = $this->_cdncommon->get_cdn(); $domain = $cdn->get_domain(); if ($domain) { return true; } } return false; }
/** * 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; }
/** * Returns debug info * * @return string */ function _get_debug_info() { $debug_info = "<!-- W3 Total Cache: Object Cache debug info:\r\n"; $debug_info .= sprintf("%s%s\r\n", str_pad('Engine: ', 20), w3_get_engine_name($this->_config->get_string('objectcache.engine'))); $debug_info .= sprintf("%s%d\r\n", str_pad('Total calls: ', 20), $this->cache_total); $debug_info .= sprintf("%s%d\r\n", str_pad('Cache hits: ', 20), $this->cache_hits); $debug_info .= sprintf("%s%d\r\n", str_pad('Cache misses: ', 20), $this->cache_misses); $debug_info .= sprintf("%s%.4f\r\n", str_pad('Total time: ', 20), $this->time_total); $debug_info .= "W3TC Object Cache info:\r\n"; $debug_info .= sprintf("%s | %s | %s | %s | %s | %s | %s\r\n", str_pad('#', 5, ' ', STR_PAD_LEFT), str_pad('Caching (Reject reason)', 30, ' ', STR_PAD_BOTH), str_pad('Status', 15, ' ', STR_PAD_BOTH), str_pad('Source', 15, ' ', STR_PAD_BOTH), str_pad('Data size (b)', 13, ' ', STR_PAD_LEFT), str_pad('Query time (s)', 14, ' ', STR_PAD_LEFT), 'ID:Group'); foreach ($this->debug_info as $index => $debug) { $debug_info .= sprintf("%s | %s | %s | %s | %s | %s | %s\r\n", str_pad($index + 1, 5, ' ', STR_PAD_LEFT), str_pad($debug['caching'] ? 'enabled' : sprintf('disabled (%s)', $debug['reason']), 30, ' ', STR_PAD_BOTH), str_pad($debug['cached'] ? 'cached' : 'not cached', 15, ' ', STR_PAD_BOTH), str_pad($debug['internal'] ? 'internal' : 'persistent', 15, ' ', STR_PAD_BOTH), str_pad($debug['data_size'], 13, ' ', STR_PAD_LEFT), str_pad(round($debug['time'], 4), 14, ' ', STR_PAD_LEFT), sprintf('%s:%s', $debug['id'], $debug['group'])); } $debug_info .= '-->'; return $debug_info; }
/** * Generates file ID * * @param array $sources * @param string $type * @return string */ function _generate_id($sources, $type) { $values = $sources; foreach ($sources as $source) { if (file_exists($source)) { $data = @file_get_contents($source); if ($data !== false) { $values[] = md5($data); } else { return false; } } } $keys = array('minify.debug', 'minify.engine', 'minify.options', 'minify.symlinks'); if ($type == 'js') { $engine = $this->_config->get_string('minify.js.engine'); switch ($engine) { case 'js': $keys = array_merge($keys, array('minify.js.combine.header', 'minify.js.combine.body', 'minify.js.combine.footer', 'minify.js.strip.comments', 'minify.js.strip.crlf')); break; case 'yuijs': $keys = array_merge($keys, array('minify.yuijs.options.line-break', 'minify.yuijs.options.nomunge', 'minify.yuijs.options.preserve-semi', 'minify.yuijs.options.disable-optimizations')); break; case 'ccjs': $keys = array_merge($keys, array('minify.ccjs.options.compilation_level', 'minify.ccjs.options.formatting')); break; } } elseif ($type == 'css') { $engine = $this->_config->get_string('minify.css.engine'); switch ($engine) { case 'css': $keys = array_merge($keys, array('minify.css.combine', 'minify.css.strip.comments', 'minify.css.strip.crlf', 'minify.css.imports')); break; case 'yuicss': $keys = array_merge($keys, array('minify.yuicss.options.line-break')); break; case 'csstidy': $keys = array_merge($keys, array('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')); break; } } foreach ($keys as $key) { $values[] = $this->_config->get($key); } $id = substr(md5(implode('', $values)), 0, 6); return $id; }
/** * Returns debug info * * @return string */ function _get_debug_info() { $debug_info = "<!-- W3 Total Cache: Db cache debug info:\r\n"; $debug_info .= sprintf("%s%s\r\n", str_pad('Engine: ', 20), w3_get_engine_name($this->_config->get_string('dbcache.engine'))); $debug_info .= sprintf("%s%d\r\n", str_pad('Total queries: ', 20), $this->query_total); $debug_info .= sprintf("%s%d\r\n", str_pad('Cached queries: ', 20), $this->query_hits); $debug_info .= sprintf("%s%.4f\r\n", str_pad('Total query time: ', 20), $this->time_total); if (count($this->query_stats)) { $debug_info .= "SQL info:\r\n"; $debug_info .= sprintf("%s | %s | %s | % s | %s | %s\r\n", str_pad('#', 5, ' ', STR_PAD_LEFT), str_pad('Time (s)', 8, ' ', STR_PAD_LEFT), str_pad('Caching (Reject reason)', 30, ' ', STR_PAD_BOTH), str_pad('Status', 10, ' ', STR_PAD_BOTH), str_pad('Data size (b)', 13, ' ', STR_PAD_LEFT), 'Query'); foreach ($this->query_stats as $index => $query) { $debug_info .= sprintf("%s | %s | %s | %s | %s | %s\r\n", str_pad($index + 1, 5, ' ', STR_PAD_LEFT), str_pad(round($query['time_total'], 4), 8, ' ', STR_PAD_LEFT), str_pad($query['caching'] ? 'enabled' : sprintf('disabled (%s)', $query['reason']), 30, ' ', STR_PAD_BOTH), str_pad($query['cached'] ? 'cached' : 'not cached', 10, ' ', STR_PAD_BOTH), str_pad($query['data_size'], 13, ' ', STR_PAD_LEFT), w3_escape_comment(trim($query['query']))); } } $debug_info .= '-->'; return $debug_info; }
/** * Returns debug info * * @return string */ function _get_debug_info() { $debug_info = "<!-- W3 Total Cache: Fragment Cache debug info:\r\n"; $debug_info .= sprintf("%s%s\r\n", str_pad('Engine: ', 20), w3_get_engine_name($this->_config->get_string('fragmentcache.engine'))); $debug_info .= sprintf("%s%s\r\n", str_pad('Caching: ', 20), $this->_caching ? 'enabled' : 'disabled'); if (!$this->_caching) { $debug_info .= sprintf("%s%s\r\n", str_pad('Reject reason: ', 20), $this->cache_reject_reason); } $debug_info .= sprintf("%s%d\r\n", str_pad('Total calls: ', 20), $this->cache_total); $debug_info .= sprintf("%s%d\r\n", str_pad('Cache hits: ', 20), $this->cache_hits); $debug_info .= sprintf("%s%d\r\n", str_pad('Cache misses: ', 20), $this->cache_misses); $debug_info .= sprintf("%s%.4f\r\n", str_pad('Total time: ', 20), $this->time_total); $debug_info .= "W3TC Fragment Cache info:\r\n"; $debug_info .= sprintf("%s | %s | %s | %s | %s | %s| %s| %s\r\n", str_pad('#', 5, ' ', STR_PAD_LEFT), str_pad('Status', 15, ' ', STR_PAD_BOTH), str_pad('Source', 15, ' ', STR_PAD_BOTH), str_pad('Data size (b)', 13, ' ', STR_PAD_LEFT), str_pad('Query time (s)', 14, ' ', STR_PAD_LEFT), str_pad('Group', 14, ' ', STR_PAD_LEFT), str_pad('Accessible', 10, ' ', STR_PAD_LEFT), 'Transient ID'); foreach ($this->debug_info as $index => $debug) { $debug_info .= sprintf("%s | %s | %s | %s | %s | %s| %s| %s\r\n", str_pad($index + 1, 5, ' ', STR_PAD_LEFT), str_pad($debug['cached'] ? 'cached' : 'not cached', 15, ' ', STR_PAD_BOTH), str_pad($debug['internal'] ? 'internal' : 'persistent', 15, ' ', STR_PAD_BOTH), str_pad($debug['data_size'], 13, ' ', STR_PAD_LEFT), str_pad(round($debug['time'], 4), 14, ' ', STR_PAD_LEFT), str_pad($this->_fragment_group($debug['id']), 14, ' ', STR_PAD_LEFT), str_pad($debug['group'] == 'transient' ? 'site' : 'network', 10, ' ', STR_PAD_LEFT), $debug['id']); } $debug_info .= '-->'; return $debug_info; }
/** * Returns debug info * * @param string $page_key * @param boolean $cache * @param string $reason * @param boolean $status * @param double $time * @return string */ function _get_debug_info($page_key, $cache, $reason, $status, $time) { $debug_info = "<!-- W3 Total Cache: Page cache debug info:\r\n"; $debug_info .= sprintf("%s%s\r\n", str_pad('Engine: ', 20), w3_get_engine_name($this->_config->get_string('pgcache.engine'))); $debug_info .= sprintf("%s%s\r\n", str_pad('Key: ', 20), $page_key); $debug_info .= sprintf("%s%s\r\n", str_pad('Caching: ', 20), $cache ? 'enabled' : 'disabled'); if (!$cache) { $debug_info .= sprintf("%s%s\r\n", str_pad('Reject reason: ', 20), $reason); } $debug_info .= sprintf("%s%s\r\n", str_pad('Status: ', 20), $status ? 'cached' : 'not cached'); $debug_info .= sprintf("%s%.3fs\r\n", str_pad('Creation Time: ', 20), $time); $headers = $this->_get_response_headers(); if (count($headers)) { $debug_info .= "Header info:\r\n"; foreach ($headers as $header_name => $header_value) { $debug_info .= sprintf("%s%s\r\n", str_pad($header_name . ': ', 20), $header_value); } } $debug_info .= '-->'; return $debug_info; }
/** * Flush specified cache * * @param string $type * @return void */ function flush($type) { if ($this->_config->get_string('pgcache.engine') == $type && $this->_config->get_boolean('pgcache.enabled')) { $this->_config->set('notes.need_empty_pgcache', false); $this->_config->set('notes.plugins_updated', false); $this->_config->save(); $this->flush_pgcache(); } if ($this->_config->get_string('dbcache.engine') == $type && $this->_config->get_boolean('dbcache.enabled')) { $this->flush_dbcache(); } if ($this->_config->get_string('objectcache.engine') == $type && $this->_config->get_boolean('objectcache.enabled')) { $this->flush_objectcache(); } if ($this->_config->get_string('fragmentcache.engine') == $type && $this->_config->get_boolean('fragmentcache.enabled')) { $this->flush_fragmentcache(); } if ($this->_config->get_string('minify.engine') == $type && $this->_config->get_boolean('minify.enabled')) { $this->_config->set('notes.need_empty_minify', false); $this->_config->save(); $this->flush_minify(); } }
/** * 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())); } }
/** * @param W3_Config $config */ private function _setup($config) { $this->authorized = $config->get_string('cdn.netdna.authorization_key') != '' && $config->get_string('cdn.engine') == 'netdna'; $keys = explode('+', $config->get_string('cdn.netdna.authorization_key')); $this->authorized = $this->authorized && sizeof($keys) == 3; $this->have_zone = $config->get_string('cdn.netdna.zone_id') != 0; }
/** * 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(); }
/** * 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"; } }
/** * @param $module * @return mixed */ public function get_module_engine($module) { return $this->_config->get_string("{$module}.engine"); }
/** * 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; }
/** * @param $buffer * @param $has_dynamic * @return array */ private function _can_cache_buffer(&$buffer, $has_dynamic) { $mobile_group = $this->_get_mobile_group(); $referrer_group = $this->_get_referrer_group(); $encryption = $this->_get_encryption(); $compression = $this->_get_compression(); $compressions = $this->_get_compressions(); /** * Don't use compression for debug mode or dynamic tags * because we need to modify buffer before send it to client */ $raw = $this->_debug || $has_dynamic; if ($raw) { $compression = false; $compressions = array(false); } $content_type = ''; $is_404 = function_exists('is_404') ? is_404() : false; $headers = $this->_get_cached_headers(); if ($this->_enhanced_mode && !$this->_late_init) { $this->_check_rules_present(); if (isset($headers['Content-Type'])) { $content_type = $headers['Content-Type']; } } $time = time(); $cache = $this->_get_cache(); /** * Store different versions of cache */ $buffers = array(); $group = '0'; if (!isset($this->_sitemap_matched)) { $sitemap_regex = $this->_config->get_string('pgcache.purge.sitemap_regex'); if ($sitemap_regex && preg_match('/' . $sitemap_regex . '/', basename($this->_request_uri))) { $group = 'sitemaps'; $this->_sitemap_matched = true; } } elseif ($this->_sitemap_matched) { $group = 'sitemaps'; } foreach ($compressions as $_compression) { $_page_key = $this->_get_page_key($mobile_group, $referrer_group, $encryption, $_compression, $content_type); /** * Compress content */ $buffers[$_compression] = $buffer; $this->_compress($buffers[$_compression], $_compression); /** * Store cache data */ $_data = array('404' => $is_404, 'headers' => $headers, 'time' => $time, 'content' => &$buffers[$_compression]); $cache->set($_page_key, $_data, $this->_lifetime, $group); } /** * Change buffer if using compression */ if ($compression && isset($buffers[$compression])) { $buffer =& $buffers[$compression]; } /** * Calculate content etag */ $etag = md5($buffer); /** * Send headers */ $this->_send_headers($is_404, $time, $etag, $compression, $headers); if ($raw) { if ($this->_debug && w3_can_print_comment($buffer)) { $buffer = $this->_debugging_caching($buffer, $mobile_group, $referrer_group, $encryption, $compression, $content_type); } /** * Don't use shutdown function below */ if (!$has_dynamic) { $this->_compress($buffer, $compression); return array($compression, $buffer); } return array($compression, $buffer); } return array($compression, $buffer); }
/** * @param W3_Config $config */ private function _setup($config) { $this->authorized = $config->get_string('cdn.maxcdn.authorization_key') != '' && $config->get_string('cdn.engine') == 'maxcdn'; $this->have_zone = $config->get_string('cdn.maxcdn.zone_id') != 0; }
/** * Generates file ID * * @param array $sources * @param string $type * @return string */ function _generate_id($sources, $type) { $values = array(); foreach ($sources as $source) { if (is_string($source)) { $values[] = $source; } else { $values[] = $source->filepath; } } foreach ($sources as $source) { if (is_string($source) && file_exists($source)) { $data = @file_get_contents($source); if ($data !== false) { $values[] = md5($data); } else { return false; } } else { $headers = @get_headers($source->minifyOptions['prependRelativePath']); if (strpos($headers[0], '200') !== false) { $segments = explode('.', $source->minifyOptions['prependRelativePath']); $ext = strtolower(array_pop($segments)); $pc_source = $this->_precache_file($source->minifyOptions['prependRelativePath'], $ext); $data = @file_get_contents($pc_source->filepath); if ($data !== false) { $values[] = md5($data); } else { return false; } } else { return false; } } } $keys = array('minify.debug', 'minify.engine', 'minify.options', 'minify.symlinks'); if ($type == 'js') { $engine = $this->_config->get_string('minify.js.engine'); switch ($engine) { case 'js': $keys = array_merge($keys, array('minify.js.combine.header', 'minify.js.combine.body', 'minify.js.combine.footer', 'minify.js.strip.comments', 'minify.js.strip.crlf')); break; case 'yuijs': $keys = array_merge($keys, array('minify.yuijs.options.line-break', 'minify.yuijs.options.nomunge', 'minify.yuijs.options.preserve-semi', 'minify.yuijs.options.disable-optimizations')); break; case 'ccjs': $keys = array_merge($keys, array('minify.ccjs.options.compilation_level', 'minify.ccjs.options.formatting')); break; } } elseif ($type == 'css') { $engine = $this->_config->get_string('minify.css.engine'); switch ($engine) { case 'css': $keys = array_merge($keys, array('minify.css.combine', 'minify.css.strip.comments', 'minify.css.strip.crlf', 'minify.css.imports')); break; case 'yuicss': $keys = array_merge($keys, array('minify.yuicss.options.line-break')); break; case 'csstidy': $keys = array_merge($keys, array('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')); break; } } foreach ($keys as $key) { $values[] = $this->_config->get($key); } $id = substr(md5(implode('', $this->_flatten_array($values))), 0, 6); return $id; }
/** * Retrieves applications. Used in AJAX requests. * Requires request param api_key with the API key and account_id with the Account id. */ function get_newrelic_applications() { w3_require_once(W3TC_LIB_W3_DIR . '/NewRelicService.php'); $api_key = W3_Request::get_string('api_key'); $account_id = W3_Request::get_string('account_id'); if ($api_key == '0') { $config_master = new W3_Config(true); $api_key = $config_master->get_string('newrelic.api_key'); } $nerser = new W3_NewRelicService($api_key); $newrelic_applications = array(); try { if (empty($account_id) || $account_id == '') { $account_id = $nerser->get_account_id(); } $newrelic_applications = $nerser->get_applications($account_id); } catch (Exception $ex) { } echo json_encode($newrelic_applications); die; }