function run() { add_action('w3tc_dashboard_setup', array(&$this, 'wp_dashboard_setup')); add_action('w3tc_network_dashboard_setup', array(&$this, 'wp_dashboard_setup')); // Configure authorize and have_zone $this->_setup($this->_config); /** * Retry setup with main blog */ if (w3_is_network() && is_network_admin() && !$this->authorized) { $this->_config = new W3_Config(false, 1); $this->_setup($this->_config); } if (w3_is_network()) { $conig_admin = w3_instance('W3_ConfigAdmin'); $this->_sealed = $conig_admin->get_boolean('cdn.configuration_sealed'); } if ($this->have_zone && $this->authorized && isset($_GET['page']) && strpos($_GET['page'], 'w3tc_dashboard') !== false) { w3_require_once(W3TC_LIB_NETDNA_DIR . '/NetDNA.php'); w3_require_once(W3TC_LIB_NETDNA_DIR . '/NetDNAPresentation.php'); $authorization_key = $this->_config->get_string('cdn.maxcdn.authorization_key'); $alias = $consumerkey = $consumersecret = ''; $keys = explode('+', $authorization_key); if (sizeof($keys) == 3) { list($alias, $consumerkey, $consumersecret) = $keys; } $this->api = new NetDNA($alias, $consumerkey, $consumersecret); add_action('admin_head', array(&$this, 'admin_head')); } }
/** * Activate plugin action * * @return void */ function activate($network_wide) { w3_require_once(W3TC_INC_DIR . '/functions/activation.php'); if (w3_is_network()) { if ($network_wide) { // we are in network activation } else { if ($_GET['action'] == 'error_scrape' && strpos($_SERVER['REQUEST_URI'], '/network/') !== false) { // workaround for error_scrape page called after error // really we are in network activation and going to throw some error } else { echo 'Please <a href="' . network_admin_url('plugins.php') . '">network activate</a> W3 Total Cache when using WordPress Multisite.'; die; } } } /** * Create cache folder and extension files */ try { w3_activation_create_required_files(); if (!$this->_config->own_config_exists()) { $this->_config->save(); } // save admin config $admin_config = w3_instance('W3_ConfigAdmin'); if (!$admin_config->own_config_exists()) { $admin_config->save(); } } catch (Exception $e) { w3_activation_error_on_exception($e); } delete_option('w3tc_request_data'); add_option('w3tc_request_data', '', null, 'no'); }
/** * @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; }
/** * Minify tab * * @return void */ function view() { $minify_enabled = $this->_config->get_boolean('minify.enabled'); $minify_rewrite_disabled = w3_is_network() && !$this->is_master() && !$this->_config_master->get_boolean('minify.rewrite'); $themes = w3_get_themes(); $templates = array(); $current_theme = w3tc_get_current_theme_name(); $current_theme_key = ''; foreach ($themes as $theme_key => $theme_name) { if ($theme_name == $current_theme) { $current_theme_key = $theme_key; } $templates[$theme_key] = w3_get_theme_templates($theme_name); } $css_imports_values = array('' => 'None', 'bubble' => 'Bubble', 'process' => 'Process'); $auto = $this->_config->get_boolean('minify.auto'); w3_require_once(W3TC_LIB_W3_DIR . '/Request.php'); $js_theme = W3_Request::get_string('js_theme', $current_theme_key); $js_groups = $this->_config->get_array('minify.js.groups'); $css_theme = W3_Request::get_string('css_theme', $current_theme_key); $css_groups = $this->_config->get_array('minify.css.groups'); $js_engine = $this->_config->get_string('minify.js.engine'); $css_engine = $this->_config->get_string('minify.css.engine'); $html_engine = $this->_config->get_string('minify.html.engine'); $css_imports = $this->_config->get_string('minify.css.imports'); // Required for Update Media Query String button $browsercache_enabled = $this->_config->get_boolean('browsercache.enabled'); $browsercache_update_media_qs = $this->_config->get_boolean('browsercache.cssjs.replace'); include W3TC_INC_DIR . '/options/minify.php'; }
/** * General tab * * @return void */ function view() { w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/ui.php'); global $current_user; $config_master = $this->_config_master; /** * @var $modules W3_ModuleStatus */ $modules = w3_instance('W3_ModuleStatus'); $pgcache_enabled = $modules->is_enabled('pgcache'); $dbcache_enabled = $modules->is_enabled('dbcache'); $objectcache_enabled = $modules->is_enabled('objectcache'); $browsercache_enabled = $modules->is_enabled('browsercache'); $minify_enabled = $modules->is_enabled('minify'); $cdn_enabled = $modules->is_enabled('cdn'); $varnish_enabled = $modules->is_enabled('varnish'); $fragmentcache_enabled = $modules->is_enabled('fragmentcache'); $enabled = $modules->plugin_is_enabled(); $enabled_checkbox = $modules->all_modules_enabled(); $check_rules = w3_can_check_rules(); $check_apc = function_exists('apc_store'); $check_eaccelerator = function_exists('eaccelerator_put'); $check_xcache = function_exists('xcache_set'); $check_wincache = function_exists('wincache_ucache_set'); $check_curl = function_exists('curl_init'); $check_memcached = class_exists('Memcache'); $check_ftp = function_exists('ftp_connect'); $check_tidy = class_exists('tidy'); $disc_enhanced_enabled = !(!$check_rules || !$this->is_master() && w3_is_network() && $config_master->get_string('pgcache.engine') != 'file_generic'); $can_empty_file = $modules->can_empty_file(); $can_empty_varnish = $modules->can_empty_varnish(); $cdn_mirror_purge = w3_cdn_can_purge_all($modules->get_module_engine('cdn')); $file_nfs = $this->_config->get_boolean('pgcache.file.nfs') || $this->_config->get_boolean('minify.file.nfs'); $file_locking = $this->_config->get_boolean('dbcache.file.locking') || $this->_config->get_boolean('objectcache.file.locking') || $this->_config->get_boolean('pgcache.file.locking') || $this->_config->get_boolean('minify.file.locking'); w3_require_once(W3TC_LIB_NEWRELIC_DIR . '/NewRelicWrapper.php'); $newrelic_conf_appname = NewRelicWrapper::get_wordpress_appname($this->_config, $this->_config_master, false); $newrelic_applications = array(); $nerser = w3_instance('W3_NewRelicService'); $new_relic_installed = $nerser->module_is_enabled(); $new_relic_running = true; if ($this->_config->get_boolean('newrelic.enabled')) { $new_relic_configured = $this->_config->get_string('newrelic.api_key') && $this->_config->get_string('newrelic.account_id'); $newrelic_prefix = ''; if ($new_relic_configured) { if (w3_is_network()) { $newrelic_prefix = $this->_config->get_string('newrelic.appname_prefix'); } try { $newrelic_applications = $nerser->get_applications(); } catch (Exception $ex) { } $newrelic_application = $this->_config->get_string('newrelic.application_id'); } } $licensing_visible = (!w3_is_multisite() || is_network_admin()) && !ini_get('w3tc.license_key') && get_transient('w3tc_license_status') != 'host_valid'; $custom_areas = apply_filters("{$this->_page}_anchors", array()); include W3TC_INC_DIR . '/options/general.php'; }
function run() { $appname = NewRelicWrapper::get_wordpress_appname($this->_config, new W3_Config(true)); if ($this->_config->get_boolean('newrelic.use_php_function') || w3_is_network()) { $enable_xmit = $this->_config->get_boolean('newrelic.enable_xmit'); NewRelicWrapper::set_appname($appname, '', $enable_xmit); } if (defined('DOING_CRON') && DOING_CRON) { $this->background_task(); } add_action('init', array($this, 'init')); }
/** * Register actions on init */ function on_init() { do_action('w3tc_register_fragment_groups'); $actions = $this->get_registered_actions(); foreach ($actions as $action => $groups) { add_action($action, array($this, 'on_action'), 0, 0); } if (w3_is_network()) { $global_actions = $this->get_registered_global_actions(); foreach ($global_actions as $action => $groups) { add_action($action, array($this, 'on_action_global'), 0, 0); } } }
/** * Activate plugin action * * @param bool $network_wide * @return void */ function activate($network_wide) { w3_require_once(W3TC_INC_DIR . '/functions/activation.php'); // decline non-network activation at WPMU if (w3_is_network()) { if ($network_wide) { // we are in network activation } else { if ($_GET['action'] == 'error_scrape' && strpos($_SERVER['REQUEST_URI'], '/network/') !== false) { // workaround for error_scrape page called after error // really we are in network activation and going to throw some error } else { echo 'Please <a href="' . network_admin_url('plugins.php') . '">network activate</a> W3 Total Cache when using WordPress Multisite.'; die; } } } try { $e = w3_instance('W3_AdminEnvironment'); /** * @var W3_Config $config */ $config = w3_instance('W3_Config'); $e->fix_on_event($config, 'activate'); w3_instance('W3_AdminLinks')->link_update($config); // try to save config file if needed, optional thing so exceptions // hidden if (!$config->own_config_exists()) { try { // create folders $e->fix_in_wpadmin($config); } catch (Exception $ex) { } try { $config_admin = w3_instance('W3_ConfigAdmin'); $config->import_legacy_config(); w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/admin.php'); w3_config_save(w3_instance('W3_Config'), $config, $config_admin); } catch (Exception $ex) { } } } catch (Exception $e) { w3_activation_error_on_exception($e); } }
public function fix_on_wpadmin_request($config, $force_all_checks) { $exs = new SelfTestExceptions(); $this->fix_folders($config, $exs); /** * @var W3_Config $config */ if ($config->get_boolean('config.check') || $force_all_checks) { if ($config->get_boolean('minify.enabled') && $config->get_boolean('minify.rewrite')) { $this->rules_core_add($config, $exs); } else { $this->rules_core_remove($exs); } if ((w3_is_apache() || w3_is_litespeed()) && w3_is_network() && !w3_is_subdomain_install()) { if ($config->get_boolean('minify.enabled') && $config->get_boolean('minify.rewrite')) { $this->rules_wpmu_subfolder_add($config, $exs); } else { $this->rules_wpmu_subfolder_remove($exs); } } if ($config->get_boolean('minify.enabled') && $config->get_string('minify.engine') == 'file') { $this->rules_cache_add($config, $exs); } else { $this->rules_cache_remove($exs); } } // if no errors so far - check if rewrite actually works if (count($exs->exceptions()) <= 0 || true) { try { if ($config->get_boolean('minify.enabled') && $config->get_string('minify.engine') == 'file' && $config->get_boolean('minify.debug')) { $this->verify_rewrite_working(); } } catch (Exception $ex) { $exs->push($ex); } if ($config->get_boolean('minify.enabled')) { $this->verify_engine_working($config, $exs); } } if (count($exs->exceptions()) > 0) { throw $exs; } }
/** * Returns path of pgcache cache rules file * Moved to separate file to not load rule.php for each disk enhanced request * * @return string */ function w3_get_pgcache_rules_cache_path() { switch (true) { case w3_is_apache(): case w3_is_litespeed(): if (w3_is_network()) { $url = w3_get_home_url(); $match = null; if (preg_match('~http(s)?://(.+?)(/)?$~', $url, $match)) { $home_path = $match[2]; return W3TC_CACHE_PAGE_ENHANCED_DIR . '/' . $home_path . '/.htaccess'; } } return W3TC_CACHE_PAGE_ENHANCED_DIR . '/.htaccess'; case w3_is_nginx(): return w3_get_nginx_rules_path(); } return false; }
/** * Check if plugin is locked * * @return boolean */ function locked() { static $locked = null; if ($locked === null) { if (w3_is_network() && function_exists('get_blog_list')) { global $blog_id; $blogs = get_blog_list(); foreach ($blogs as $blog) { if ($blog['blog_id'] != $blog_id) { $active_plugins = get_blog_option($blog['blog_id'], 'active_plugins'); if (in_array(W3TC_FILE, $active_plugins)) { $locked = true; break; } } } } else { $locked = false; } } return $locked; }
/** * Returns true if config section is sealed * @param string $section * @return boolean */ protected function is_sealed($section) { if ($this->is_master()) { return false; } if (w3_is_network() && !$this->is_master() && w3_force_master()) { return true; } // browsercache settings change rules, so not available in child settings if ($section == 'browsercache') { return true; } if ($section == 'minify' && !$this->_config_master->get_boolean('minify.enabled')) { return true; } return $this->_config_admin->get_boolean($section . '.configuration_sealed'); }
public function set_appname() { static $appname_set; if (!$appname_set && ($this->_config->get_boolean('newrelic.use_php_function') || w3_is_network())) { $appname_set = true; $appname = NewRelicWrapper::get_wordpress_appname($this->_config, new W3_Config(true)); $enable_xmit = $this->_config->get_boolean('newrelic.enable_xmit'); NewRelicWrapper::set_appname($appname, '', $enable_xmit); } }
/** * Convert local uri path to CDN type specific path * @param $local_uri_path * @return string */ function uri_to_cdn_uri($local_uri_path) { if (w3_is_network() && defined('DOMAIN_MAPPING') && DOMAIN_MAPPING) { $local_uri_path = str_replace(w3_get_site_url(), '', $local_uri_path); } $engine = $this->_config->get_string('cdn.engine'); if (w3_is_cdn_mirror($engine)) { if (w3_is_network() && strpos($local_uri_path, 'files') === 0) { $upload_dir = wp_upload_dir(); return ltrim($this->abspath_to_relative_path(dirname($upload_dir['basedir'])) . '/' . $local_uri_path, '/'); } } $remote_path = $local_uri_path; return ltrim($remote_path, "/"); }
/** * @throws TryException * @throws W3TCErrorException * @return bool */ public function try_create_wp_loader() { $file_data = $this->w3tc_loader_file_data(); $filename = $file_data['filename']; $data = $file_data['data']; w3_require_once(W3TC_INC_DIR . '/functions/rule.php'); if (($current_data = @file_get_contents($filename)) && strstr(w3_clean_rules($current_data), w3_clean_rules($data)) !== false) { return true; } $url = w3_is_network() ? network_admin_url('admin.php?page=w3tc_general') : admin_url('admin.php?page=w3tc_general'); try { w3_require_once(W3TC_INC_DIR . '/functions/activation.php'); $result = w3_wp_write_to_file($filename, $data, $url); } catch (Exception $ex) { if ($ex instanceof FilesystemCredentialException) { throw new TryException('Could not create file', array($filename), $ex->ftp_form()); } else { throw new W3TCErrorException(sprintf('<strong>W3 Total Cache Error:</strong>Could not create file <strong>%s</strong> with content: <pre>%s</pre><br />You need to do this manually.', $filename, esc_textarea($data))); } } return true; }
/** * Overloads the current ConfigWriter with found legacy values and saves to config file. */ public function import_legacy_config_and_save() { if ($this->own_config_exists()) { return; } /** * defines $keys with descriptors * @var array $keys config keys */ include W3TC_LIB_W3_DIR . '/ConfigKeys.php'; $compiled_config = new W3_ConfigData($keys); $compiled_config->set_defaults(); $config_admin = w3_instance('W3_ConfigAdmin'); $data = $this->_import_legacy_config($compiled_config); if (!is_null($data)) { $master_data = array(); if ($this->_blog_id != 0 && w3_is_network()) { $master_config = new W3_ConfigData($keys); $master_config->read($this->_get_config_filename(true)); $master_data = $master_config->data; } foreach ($data as $key => $value) { if ($master_data && isset($master_data[$key]) && $master_data[$key] === $value) { continue; } if (!$this->_key_sealed($key, $this->_data->data, $config_admin, $value)) { $this->_data->set($key, $value); } } // Since configs don't exist create them. $this->save(); $config_admin->save(); } }
<td> <ul> <?php foreach ($registered_groups as $group => $descriptor) { echo '<li>', $group, ' (', $descriptor['expiration'], ' secs): ', implode(',', $descriptor['actions']), '</li>'; } ?> </ul> <span class="description"><?php _e('The groups above will be flushed upon setting changes.', 'w3-total-cache'); ?> </span> </td> </tr> <?php if (w3_is_network()) { ?> <tr> <th><?php _e('Registered site-wide fragment groups:', 'w3-total-cache'); ?> </th> <td> <ul> <?php foreach ($registered_global_groups as $group => $descriptor) { echo '<li>', $group, ' (', $descriptor['expiration'], ' secs): ', implode(',', $descriptor['actions']), '</li>'; } ?> </ul> <span class="description"><?php
/** * Paths used to minify minifyfile paths * @return array */ private function _minify_path_replacements() { if (w3_is_network()) { $theme = get_theme_root(); } else { $theme = get_stylesheet_directory(); } return array(ltrim(str_replace(w3_get_document_root(), '', w3_path($theme)), '/'), ltrim(str_replace(w3_get_document_root(), '', w3_path(WP_PLUGIN_DIR)), '/'), ltrim(str_replace(w3_get_document_root(), '', w3_path(WPMU_PLUGIN_DIR)), '/'), WPINC . '/js/jquery', WPINC . '/js', WPINC . '/css', WPINC); }
/** * 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; }
/** * General tab * * @return void */ function view() { global $current_user; $config_master = $this->_config_master; /** * @var $modules W3_ModuleStatus */ $modules = w3_instance('W3_ModuleStatus'); $pgcache_enabled = $modules->is_enabled('pgcache'); $dbcache_enabled = $modules->is_enabled('dbcache'); $objectcache_enabled = $modules->is_enabled('objectcache'); $browsercache_enabled = $modules->is_enabled('browsercache'); $minify_enabled = $modules->is_enabled('minify'); $cdn_enabled = $modules->is_enabled('cdn'); $cloudflare_enabled = $modules->is_enabled('cloudflare'); $varnish_enabled = $modules->is_enabled('varnish'); $fragmentcache_enabled = $modules->is_enabled('fragmentcache'); $enabled = $modules->plugin_is_enabled(); $enabled_checkbox = $modules->all_modules_enabled(); $check_rules = w3_can_check_rules(); $check_apc = function_exists('apc_store'); $check_eaccelerator = function_exists('eaccelerator_put'); $check_xcache = function_exists('xcache_set'); $check_wincache = function_exists('wincache_ucache_set'); $check_curl = function_exists('curl_init'); $check_memcached = class_exists('Memcache'); $check_ftp = function_exists('ftp_connect'); $check_tidy = class_exists('tidy'); $disc_enhanced_enabled = !(!$check_rules || !$this->is_master() && w3_is_network() && $config_master->get_string('pgcache.engine') != 'file_generic'); $can_empty_file = $modules->can_empty_file(); $can_empty_varnish = $modules->can_empty_varnish(); $cdn_mirror_purge = w3_cdn_can_purge_all($modules->get_module_engine('cdn')); $cloudflare_signup_email = ''; $cloudflare_signup_user = ''; if (is_a($current_user, 'WP_User')) { if ($current_user->user_email) { $cloudflare_signup_email = $current_user->user_email; } if ($current_user->user_login && $current_user->user_login != 'admin') { $cloudflare_signup_user = $current_user->user_login; } } /** * @var $w3_cloudflare W3_CloudFlare */ $w3_cloudflare = w3_instance('W3_CloudFlare'); $cf_options = $w3_cloudflare->get_options(); $cloudflare_seclvls = $cf_options['sec_lvl']; $cloudflare_devmodes = $cf_options['dev_mode']; $cloudflare_rocket_loaders = $cf_options['async']; $cloudflare_minifications = $cf_options['minify']; $cloudflare_seclvl = 'med'; $cloudflare_devmode_expire = 0; $cloudflare_devmode = 0; $cloudflare_rocket_loader = 0; $cloudflare_minify = 0; if ($cloudflare_enabled && $this->_config->get_string('cloudflare.email') && $this->_config->get_string('cloudflare.key')) { $settings = $w3_cloudflare->get_settings(); $cloudflare_seclvl = $settings['sec_lvl']; $cloudflare_devmode_expire = $settings['devmode']; $cloudflare_rocket_loader = $settings['async']; $cloudflare_devmode = $cloudflare_devmode_expire ? 1 : 0; $cloudflare_minify = $settings['minify']; $can_empty_cloudflare = true; } else { $can_empty_cloudflare = false; } $file_nfs = $this->_config->get_boolean('pgcache.file.nfs') || $this->_config->get_boolean('minify.file.nfs'); $file_locking = $this->_config->get_boolean('dbcache.file.locking') || $this->_config->get_boolean('objectcache.file.locking') || $this->_config->get_boolean('pgcache.file.locking') || $this->_config->get_boolean('minify.file.locking'); w3_require_once(W3TC_LIB_NEWRELIC_DIR . '/NewRelicWrapper.php'); $newrelic_conf_appname = NewRelicWrapper::get_wordpress_appname($this->_config, $this->_config_master, false); $newrelic_applications = array(); $nerser = w3_instance('W3_NewRelicService'); $new_relic_installed = $nerser->module_is_enabled(); $new_relic_running = true; if ($this->_config->get_boolean('newrelic.enabled')) { $new_relic_configured = $this->_config->get_string('newrelic.api_key') && $this->_config->get_string('newrelic.account_id'); $newrelic_prefix = ''; if ($new_relic_configured) { if (w3_is_network()) { $newrelic_prefix = $this->_config->get_string('newrelic.appname_prefix'); } try { $newrelic_applications = $nerser->get_applications(); } catch (Exception $ex) { } $newrelic_application = $this->_config->get_string('newrelic.application_id'); } } $licensing_visible = (!w3_is_multisite() || is_network_admin()) && !ini_get('w3tc.license_key') && get_transient('w3tc_license_status') != 'host_valid'; include W3TC_INC_DIR . '/options/general.php'; }
/** * Returns true if config section is sealed * @param string $section * @param W3_Config $config_master * @param W3_ConfigAdmin $config_admin * @return boolean */ private function is_sealed($section, $config_master, $config_admin) { if (w3_get_blog_id() == 0) { return false; } if (w3_is_network() && w3_get_blog_id() != 0 && w3_force_master()) { return true; } // browsercache settings change rules, so not available in child settings if ($section == 'browsercache') { return true; } if ($section == 'minify' && !$config_master->get_boolean('minify.enabled')) { return true; } return $config_admin->get_boolean($section . '.configuration_sealed'); }
/** * 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; }
/** * Activate plugin action * * @return void */ function activate() { require_once W3TC_INC_DIR . '/functions/activation.php'; /** * Disable buggy sitewide activation in WPMU and WP 3.0 */ if (w3_is_wpmu() && isset($_GET['sitewide']) || w3_is_multisite() && isset($_GET['networkwide'])) { w3_network_activate_error(); } /** * Check installation files */ $files = array(W3TC_INSTALL_FILE_ADVANCED_CACHE, W3TC_INSTALL_FILE_DB, W3TC_INSTALL_FILE_OBJECT_CACHE); $nonexistent_files = array(); foreach ($files as $file) { if (!file_exists($file)) { $nonexistent_files[] = $file; } } if (count($nonexistent_files)) { $error = sprintf('Unfortunately core file(s): (<strong>%s</strong>) are missing, so activation will fail. Please re-start the installation process from the beginning.', implode(', ', $nonexistent_files)); w3_activate_error($error); } if (!@is_dir(W3TC_CONTENT_DIR) && !@mkdir(W3TC_CONTENT_DIR)) { w3_writable_error(W3TC_CONTENT_DIR); } if (!@is_dir(W3TC_CACHE_FILE_DBCACHE_DIR) && !@mkdir(W3TC_CACHE_FILE_DBCACHE_DIR)) { w3_writable_error(W3TC_CACHE_FILE_DBCACHE_DIR); } if (!@is_dir(W3TC_CACHE_FILE_OBJECTCACHE_DIR) && !@mkdir(W3TC_CACHE_FILE_OBJECTCACHE_DIR)) { w3_writable_error(W3TC_CACHE_FILE_OBJECTCACHE_DIR); } if (!@is_dir(W3TC_CACHE_FILE_PGCACHE_DIR) && !@mkdir(W3TC_CACHE_FILE_PGCACHE_DIR)) { w3_writable_error(W3TC_CACHE_FILE_PGCACHE_DIR); } if (!@is_dir(W3TC_CACHE_FILE_MINIFY_DIR) && !@mkdir(W3TC_CACHE_FILE_MINIFY_DIR)) { w3_writable_error(W3TC_CACHE_FILE_MINIFY_DIR); } if (!@is_dir(W3TC_LOG_DIR) && !@mkdir(W3TC_LOG_DIR)) { w3_writable_error(W3TC_LOG_DIR); } if (!@is_dir(W3TC_TMP_DIR) && !@mkdir(W3TC_TMP_DIR)) { w3_writable_error(W3TC_TMP_DIR); } if (w3_is_network() && file_exists(W3TC_CONFIG_MASTER_PATH)) { /** * For multisite load master config */ $this->_config->load_master(); if (!$this->_config->save(false)) { w3_writable_error(W3TC_CONFIG_PATH); } } elseif (!file_exists(W3TC_CONFIG_PATH)) { /** * Set default settings */ $this->_config->set_defaults(); /** * If config doesn't exist enable preview mode */ if (!$this->_config->save(true)) { w3_writable_error(W3TC_CONFIG_PREVIEW_PATH); } } /** * Save blognames into file */ if (w3_is_network() && !w3_is_subdomain_install()) { if (!w3_save_blognames()) { w3_writable_error(W3TC_BLOGNAMES_PATH); } } delete_option('w3tc_request_data'); add_option('w3tc_request_data', '', null, 'no'); }
/** * Reads legacy config file * * @param bool $force_master * @return array */ public function get_imported_legacy_config_keys($force_master = false) { $suffix = ''; if ($force_master) { } else { if ($this->_blog_id > 0) { if (w3_is_network()) { if (w3_is_subdomain_install()) { $suffix = '-' . w3_get_domain(w3_get_host()); } else { // try subdir blog $request_uri = rtrim($_SERVER['REQUEST_URI'], '/'); $site_home_uri = w3_get_base_path(); if (substr($request_uri, 0, strlen($site_home_uri)) == $site_home_uri) { $request_path_in_wp = '/' . substr($request_uri, strlen($site_home_uri)); $n = strpos($request_path_in_wp, '/', 1); if ($n === false) { $blog_path_in_wp = substr($request_path_in_wp, 1); } else { $blog_path_in_wp = substr($request_path_in_wp, 1, $n - 1); } $suffix = '-' . ($blog_path_in_wp != 'wp-admin' ? $blog_path_in_wp . '.' : '') . w3_get_domain(w3_get_host()); } } } } } $filename = WP_CONTENT_DIR . '/w3-total-cache-config' . $suffix . '.php'; $legacy_config = W3_ConfigData::get_array_from_file($filename); if (is_array($legacy_config) && isset($legacy_config['pgcache.engine']) && $legacy_config['pgcache.engine'] == 'file_pgcache') { $legacy_config['pgcache.engine'] = 'file_generic'; } return $legacy_config; }
/** * Returns absolute path to home directory * * Example: * * DOCUMENT_ROOT=/var/www/vhosts/domain.com * Install dir=/var/www/vhosts/domain.com/site/blog * home=http://domain.com/site * siteurl=http://domain.com/site/blog * return /var/www/vhosts/domain.com/site * * No trailing slash! * * @return string */ function w3_get_home_root() { if (w3_is_network()) { $path = w3_get_base_path(); } else { $path = w3_get_home_path(); } $home_root = w3_get_document_root() . $path; $home_root = realpath($home_root); $home_root = w3_path($home_root); return $home_root; }
/** * Returns true if we can modify rules * * @param string $path * @return boolean */ function w3_can_modify_rules($path) { if (w3_is_network()) { if (w3_is_apache()) { switch ($path) { case w3_get_pgcache_rules_cache_path(): case w3_get_minify_rules_core_path(): case w3_get_minify_rules_cache_path(): return true; } } return false; } return true; }
/** * Returns true if config section is sealed * @param string $section * @return boolean */ function w3tc_is_sealed($section) { $config = w3_instance('W3_Config'); $config_master = new W3_Config(true); $config_admin = w3_instance('W3_ConfigAdmin'); if ($config->is_master()) { return false; } if (w3_is_network() && !$config->is_master() && w3_force_master()) { return true; } // browsercache settings change rules, so not available in child settings if ($section == 'browsercache') { return true; } if ($section == 'minify' && !$config_master->get_boolean('minify.enabled')) { return true; } return $config_admin->get_boolean($section . '.configuration_sealed'); }
/** * 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; }
/** * Remove script tags from the source * * @param string $content * @param array $files * @return void */ function remove_scripts(&$content, $files) { $regexps = array(); $home_url_regexp = w3_get_home_url_regexp(); $path = ''; if (w3_is_network() && !w3_is_subdomain_install()) { $path = ltrim(w3_get_home_path(), '/'); } foreach ($files as $file) { if ($path && strpos($file, $path) === 0) { $file = substr($file, strlen($path)); } $this->replaced_scripts[] = $file; if (w3_is_url($file) && !preg_match('~' . $home_url_regexp . '~i', $file)) { // external JS files $regexps[] = w3_preg_quote($file); } else { // local JS files $file = ltrim($file, '/'); if (ltrim(w3_get_site_path(), '/') && strpos($file, ltrim(w3_get_site_path(), '/')) === 0) { $file = str_replace(ltrim(w3_get_site_path(), '/'), '', $file); } $file = ltrim(preg_replace('~' . $home_url_regexp . '~i', '', $file), '/\\'); $regexps[] = '(' . $home_url_regexp . ')?/?' . w3_preg_quote($file); } } foreach ($regexps as $regexp) { $content = preg_replace('~<script\\s+[^<>]*src=["\']?' . $regexp . '["\']?[^<>]*>\\s*</script>~Uis', '', $content); } }
/** * Options save action * * @return void */ function action_save_options() { /** * Redirect params */ $params = array(); /** * Store error message regarding permalink not enabled */ $redirect_permalink_error = ''; /** * Read config * We should use new instance of WP_Config object here */ @($config = new W3_Config()); $this->read_request($config); $config_admin = new W3_ConfigAdmin(); $this->read_request($config_admin); /** * General tab */ if ($this->_page == 'w3tc_general') { $file_nfs = W3_Request::get_boolean('file_nfs'); $file_locking = W3_Request::get_boolean('file_locking'); $config->set('pgcache.file.nfs', $file_nfs); $config->set('minify.file.nfs', $file_nfs); $config->set('dbcache.file.locking', $file_locking); $config->set('objectcache.file.locking', $file_locking); $config->set('pgcache.file.locking', $file_locking); $config->set('minify.file.locking', $file_locking); if ($this->is_network_and_master()) { if ($this->_config->get_boolean('common.force_master') !== $config->get_boolean('common.force_master') || !w3_force_master() && $this->_config->get_boolean('common.force_master') && $config->get_boolean('common.force_master') || w3_force_master() && !$this->_config->get_boolean('common.force_master') && !$config->get_boolean('common.force_master')) { $blog_home_url = w3_generate_request_uri(); $blogmap_file = w3_blogmap_filename($blog_home_url); @unlink($blogmap_file); $blogmap_dir = dirname(W3TC_CACHE_BLOGMAP_FILENAME) . '/' . basename(W3TC_CACHE_BLOGMAP_FILENAME, '.php') . '/'; if (is_dir($blogmap_dir)) { w3_rmdir($blogmap_dir); } } if ($config->get_boolean('common.force_master')) { $config_admin->set('common.visible_by_master_only', true); } } /** * Check permalinks for page cache */ if ($config->get_boolean('pgcache.enabled') && $config->get_string('pgcache.engine') == 'file_generic' && !get_option('permalink_structure')) { $config->set('pgcache.enabled', false); $redirect_permalink_error = 'fancy_permalinks_disabled_pgcache'; } $w3_cloudflare = w3_instance('W3_CloudFlare'); $w3_cloudflare->reset_settings_cache(); if ($config->get_boolean('cloudflare.enabled') && $w3_cloudflare->minify_enabled() && $config->get_boolean('minify.enabled')) { $config->set('minify.enabled', false); } /** * Get New Relic application id */ if ($config->get_boolean('newrelic.enabled')) { $method = W3_Request::get_string('application_id_method'); $newrelic_prefix = ''; if (w3_is_network() && w3_get_blog_id() != 0) { $newrelic_prefix = $this->_config->get_string('newrelic.appname_prefix'); } if (($newrelic_api_key = $config->get_string('newrelic.api_key')) && !$config->get_string('newrelic.account_id')) { $nerser = w3_instance('W3_NewRelicService'); $account_id = $nerser->get_account_id($newrelic_api_key); $config->set('newrelic.account_id', $account_id); } if ($method == 'dropdown' && $config->get_string('newrelic.application_id')) { $application_id = $config->get_string('newrelic.application_id'); if ($config->get_string('newrelic.api_key') && $config->get_string('newrelic.account_id')) { w3_require_once(W3TC_LIB_W3_DIR . '/NewRelicService.php'); $nerser = new W3_NewRelicService($config->get_string('newrelic.api_key'), $config->get_string('newrelic.account_id')); $appname = $nerser->get_application_name($application_id); $config->set('newrelic.appname', $appname); } } else { if ($method == 'manual' && $config->get_string('newrelic.appname')) { if ($newrelic_prefix != '' && strpos($config->get_string('newrelic.appname'), $newrelic_prefix) === false) { $application_name = $newrelic_prefix . $config->get_string('newrelic.appname'); $config->set('newrelic.appname', $application_name); } else { $application_name = $config->get_string('newrelic.appname'); } if ($config->get_string('newrelic.api_key') && $config->get_string('newrelic.account_id')) { w3_require_once(W3TC_LIB_W3_DIR . '/NewRelicService.php'); $nerser = new W3_NewRelicService($config->get_string('newrelic.api_key'), $config->get_string('newrelic.account_id')); $application_id = $nerser->get_application_id($application_name); if ($application_id) { $config->set('newrelic.application_id', $application_id); } } } } } } /** * Minify tab */ if ($this->_page == 'w3tc_minify' && !$this->_config->get_boolean('minify.auto')) { $js_groups = array(); $css_groups = array(); $js_files = W3_Request::get_array('js_files'); $css_files = W3_Request::get_array('css_files'); foreach ($js_files as $theme => $templates) { foreach ($templates as $template => $locations) { foreach ((array) $locations as $location => $types) { foreach ((array) $types as $type => $files) { foreach ((array) $files as $file) { if (!empty($file)) { $js_groups[$theme][$template][$location]['files'][] = w3_normalize_file_minify($file); } } } } } } foreach ($css_files as $theme => $templates) { foreach ($templates as $template => $locations) { foreach ((array) $locations as $location => $files) { foreach ((array) $files as $file) { if (!empty($file)) { $css_groups[$theme][$template][$location]['files'][] = w3_normalize_file_minify($file); } } } } } $config->set('minify.js.groups', $js_groups); $config->set('minify.css.groups', $css_groups); $js_theme = W3_Request::get_string('js_theme'); $css_theme = W3_Request::get_string('css_theme'); $params = array_merge($params, array('js_theme' => $js_theme, 'css_theme' => $css_theme)); } /** * Browser Cache tab */ if ($this->_page == 'w3tc_browsercache') { if ($config->get_boolean('browsercache.enabled') && $config->get_boolean('browsercache.no404wp') && !get_option('permalink_structure')) { $config->set('browsercache.no404wp', false); $redirect_permalink_error = 'fancy_permalinks_disabled_browsercache'; } $config->set('browsercache.timestamp', time()); } /** * Mobile tab */ if ($this->_page == 'w3tc_mobile') { $groups = W3_Request::get_array('mobile_groups'); $mobile_groups = array(); $cached_mobile_groups = array(); foreach ($groups as $group => $group_config) { $group = strtolower($group); $group = preg_replace('~[^0-9a-z_]+~', '_', $group); $group = trim($group, '_'); if ($group) { $theme = isset($group_config['theme']) ? trim($group_config['theme']) : 'default'; $enabled = isset($group_config['enabled']) ? (bool) $group_config['enabled'] : true; $redirect = isset($group_config['redirect']) ? trim($group_config['redirect']) : ''; $agents = isset($group_config['agents']) ? explode("\r\n", trim($group_config['agents'])) : array(); $mobile_groups[$group] = array('theme' => $theme, 'enabled' => $enabled, 'redirect' => $redirect, 'agents' => $agents); $cached_mobile_groups[$group] = $agents; } } /** * Allow plugins modify WPSC mobile groups */ $cached_mobile_groups = apply_filters('cached_mobile_groups', $cached_mobile_groups); /** * Merge existent and delete removed groups */ foreach ($mobile_groups as $group => $group_config) { if (isset($cached_mobile_groups[$group])) { $mobile_groups[$group]['agents'] = (array) $cached_mobile_groups[$group]; } else { unset($mobile_groups[$group]); } } /** * Add new groups */ foreach ($cached_mobile_groups as $group => $agents) { if (!isset($mobile_groups[$group])) { $mobile_groups[$group] = array('theme' => '', 'enabled' => true, 'redirect' => '', 'agents' => $agents); } } /** * Allow plugins modify W3TC mobile groups */ $mobile_groups = apply_filters('w3tc_mobile_groups', $mobile_groups); /** * Sanitize mobile groups */ foreach ($mobile_groups as $group => $group_config) { $mobile_groups[$group] = array_merge(array('theme' => '', 'enabled' => true, 'redirect' => '', 'agents' => array()), $group_config); $mobile_groups[$group]['agents'] = array_unique($mobile_groups[$group]['agents']); $mobile_groups[$group]['agents'] = array_map('strtolower', $mobile_groups[$group]['agents']); sort($mobile_groups[$group]['agents']); } $enable_mobile = false; foreach ($mobile_groups as $group => $group_config) { if ($group_config['enabled']) { $enable_mobile = true; break; } } $config->set('mobile.enabled', $enable_mobile); $config->set('mobile.rgroups', $mobile_groups); } /** * Referrer tab */ if ($this->_page == 'w3tc_referrer') { $groups = W3_Request::get_array('referrer_groups'); $referrer_groups = array(); foreach ($groups as $group => $group_config) { $group = strtolower($group); $group = preg_replace('~[^0-9a-z_]+~', '_', $group); $group = trim($group, '_'); if ($group) { $theme = isset($group_config['theme']) ? trim($group_config['theme']) : 'default'; $enabled = isset($group_config['enabled']) ? (bool) $group_config['enabled'] : true; $redirect = isset($group_config['redirect']) ? trim($group_config['redirect']) : ''; $referrers = isset($group_config['referrers']) ? explode("\r\n", trim($group_config['referrers'])) : array(); $referrer_groups[$group] = array('theme' => $theme, 'enabled' => $enabled, 'redirect' => $redirect, 'referrers' => $referrers); } } /** * Allow plugins modify W3TC referrer groups */ $referrer_groups = apply_filters('w3tc_referrer_groups', $referrer_groups); /** * Sanitize mobile groups */ foreach ($referrer_groups as $group => $group_config) { $referrer_groups[$group] = array_merge(array('theme' => '', 'enabled' => true, 'redirect' => '', 'referrers' => array()), $group_config); $referrer_groups[$group]['referrers'] = array_unique($referrer_groups[$group]['referrers']); $referrer_groups[$group]['referrers'] = array_map('strtolower', $referrer_groups[$group]['referrers']); sort($referrer_groups[$group]['referrers']); } $enable_referrer = false; foreach ($referrer_groups as $group => $group_config) { if ($group_config['enabled']) { $enable_referrer = true; break; } } $config->set('referrer.enabled', $enable_referrer); $config->set('referrer.rgroups', $referrer_groups); } /** * CDN tab */ if ($this->_page == 'w3tc_cdn') { $cdn_cnames = W3_Request::get_array('cdn_cnames'); $cdn_domains = array(); foreach ($cdn_cnames as $cdn_cname) { $cdn_cname = trim($cdn_cname); /** * Auto expand wildcard domain to 10 subdomains */ $matches = null; if (preg_match('~^\\*\\.(.*)$~', $cdn_cname, $matches)) { $cdn_domains = array(); for ($i = 1; $i <= 10; $i++) { $cdn_domains[] = sprintf('cdn%d.%s', $i, $matches[1]); } break; } if ($cdn_cname) { $cdn_domains[] = $cdn_cname; } } switch ($this->_config->get_string('cdn.engine')) { case 'ftp': $config->set('cdn.ftp.domain', $cdn_domains); break; case 's3': $config->set('cdn.s3.cname', $cdn_domains); break; case 'cf': $config->set('cdn.cf.cname', $cdn_domains); break; case 'cf2': $config->set('cdn.cf2.cname', $cdn_domains); break; case 'rscf': $config->set('cdn.rscf.cname', $cdn_domains); break; case 'azure': $config->set('cdn.azure.cname', $cdn_domains); break; case 'mirror': $config->set('cdn.mirror.domain', $cdn_domains); break; case 'netdna': $config->set('cdn.netdna.domain', $cdn_domains); break; case 'cotendo': $config->set('cdn.cotendo.domain', $cdn_domains); break; case 'edgecast': $config->set('cdn.edgecast.domain', $cdn_domains); break; case 'att': $config->set('cdn.att.domain', $cdn_domains); break; case 'akamai': $config->set('cdn.akamai.domain', $cdn_domains); break; } } $this->config_save($config, $config_admin); switch ($this->_page) { case 'w3tc_cdn': /** * Handle Set Cookie Domain */ $set_cookie_domain_old = W3_Request::get_boolean('set_cookie_domain_old'); $set_cookie_domain_new = W3_Request::get_boolean('set_cookie_domain_new'); if ($set_cookie_domain_old != $set_cookie_domain_new) { if ($set_cookie_domain_new) { if (!$this->enable_cookie_domain()) { $this->redirect(array_merge($params, array('w3tc_error' => 'enable_cookie_domain'))); } } else { if (!$this->disable_cookie_domain()) { $this->redirect(array_merge($params, array('w3tc_error' => 'disable_cookie_domain'))); } } } break; case 'w3tc_general': /** * Handle CloudFlare changes */ if ($this->_config->get_boolean('cloudflare.enabled') && (w3_get_blog_id() == 0 || w3_get_blog_id() != 0 && !$this->is_sealed('cloudflare'))) { /** * @var $w3_cloudflare W3_CloudFlare */ $w3_cloudflare = w3_instance('W3_CloudFlare'); W3_CloudFlare::clear_last_error(''); $cf_values = W3_Request::get_as_array('cloudflare_'); if (!$w3_cloudflare->save_settings($cf_values)) { $this->redirect(array_merge($params, array('w3tc_error' => 'cloudflare_api_request'))); } } break; } $this->_notes[] = 'config_save'; if ($redirect_permalink_error) { $this->redirect(array('w3tc_error' => $redirect_permalink_error, 'w3tc_note' => 'config_save')); } $this->redirect_with_custom_messages($params); }