Пример #1
0
 /**
  * Save config action
  *
  * Do some actions on config keys update
  * Used in several places such as:
  *
  * 1. common config save
  * 2. import settings
  * 3. enable/disable preview mode
  *
  * @param W3_Config $old_config
  * @param W3_Config $new_config
  * @param boolean $preview
  * @return void
  */
 function config_save(&$old_config, &$new_config, $preview = null)
 {
     $browsercache_dependencies = array();
     if ($new_config->get_boolean('browsercache.enabled')) {
         $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.cssjs.replace', 'browsercache.html.replace', 'browsercache.other.replace'));
         if ($new_config->get_boolean('browsercache.cssjs.replace')) {
             $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.cssjs.compression', 'browsercache.cssjs.expires', 'browsercache.cssjs.lifetime', 'browsercache.cssjs.cache.control', 'browsercache.cssjs.cache.policy', 'browsercache.cssjs.etag', 'browsercache.cssjs.w3tc'));
         }
         if ($new_config->get_boolean('browsercache.html.replace')) {
             $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.html.compression', 'browsercache.html.expires', 'browsercache.html.lifetime', 'browsercache.html.cache.control', 'browsercache.html.cache.policy', 'browsercache.html.etag', 'browsercache.html.w3tc'));
         }
         if ($new_config->get_boolean('browsercache.other.replace')) {
             $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.other.compression', 'browsercache.other.expires', 'browsercache.other.lifetime', 'browsercache.other.cache.control', 'browsercache.other.cache.policy', 'browsercache.other.etag', 'browsercache.other.w3tc'));
         }
     }
     /**
      * Show need empty page cache notification
      */
     if ($new_config->get_boolean('pgcache.enabled')) {
         $pgcache_dependencies = array_merge($browsercache_dependencies, array('pgcache.debug', 'dbcache.enabled', 'objectcache.enabled', 'minify.enabled', 'cdn.enabled', 'mobile.enabled', 'referrer.enabled'));
         if ($new_config->get_boolean('dbcache.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('dbcache.debug'));
         }
         if ($new_config->get_boolean('objectcache.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('objectcache.debug'));
         }
         if ($new_config->get_boolean('minify.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('minify.auto', 'minify.debug', 'minify.rewrite', 'minify.html.enable', 'minify.html.engine', 'minify.html.inline.css', 'minify.html.inline.js', 'minify.html.strip.crlf', 'minify.html.comments.ignore', 'minify.css.enable', 'minify.css.groups', 'minify.js.enable', 'minify.js.groups', 'minify.htmltidy.options.clean', 'minify.htmltidy.options.hide-comments', 'minify.htmltidy.options.wrap', 'minify.reject.logged', 'minify.reject.ua', 'minify.reject.uri'));
         }
         if ($new_config->get_boolean('cdn.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('cdn.debug', 'cdn.engine', 'cdn.uploads.enable', 'cdn.includes.enable', 'cdn.includes.files', 'cdn.theme.enable', 'cdn.theme.files', 'cdn.minify.enable', 'cdn.custom.enable', 'cdn.custom.files', 'cdn.mirror.domain', 'cdn.mirror.ssl', 'cdn.netdna.domain', 'cdn.netdna.ssl', 'cdn.cotendo.domain', 'cdn.cotendo.ssl', 'cdn.ftp.domain', 'cdn.ftp.ssl', 'cdn.s3.cname', 'cdn.s3.ssl', 'cdn.cf.cname', 'cdn.cf.ssl', 'cdn.cf2.cname', 'cdn.cf2.ssl', 'cdn.rscf.cname', 'cdn.rscf.ssl', 'cdn.azure.cname', 'cdn.azure.ssl', 'cdn.reject.admins', 'cdn.reject.ua', 'cdn.reject.uri', 'cdn.reject.files'));
         }
         if ($new_config->get_boolean('mobile.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('mobile.rgroups'));
         }
         if ($new_config->get_boolean('referrer.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('referrer.rgroups'));
         }
         $old_pgcache_dependencies_values = array();
         $new_pgcache_dependencies_values = array();
         foreach ($pgcache_dependencies as $pgcache_dependency) {
             $old_pgcache_dependencies_values[] = $old_config->get($pgcache_dependency);
             $new_pgcache_dependencies_values[] = $new_config->get($pgcache_dependency);
         }
         if (serialize($old_pgcache_dependencies_values) != serialize($new_pgcache_dependencies_values)) {
             $new_config->set('notes.need_empty_pgcache', true);
         }
     }
     /**
      * Show need empty minify notification
      */
     if ($new_config->get_boolean('minify.enabled') && ($new_config->get_boolean('minify.css.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.css.groups'))) || $new_config->get_boolean('minify.js.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.js.groups'))))) {
         $minify_dependencies = array_merge($browsercache_dependencies, array('minify.auto', 'minify.debug', 'minify.options', 'minify.symlinks', 'minify.css.enable', 'minify.js.enable'));
         if ($new_config->get_boolean('minify.css.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.css.groups')))) {
             $minify_dependencies = array_merge($minify_dependencies, array('minify.css.engine', 'minify.css.combine', 'minify.css.strip.comments', 'minify.css.strip.crlf', 'minify.css.imports', 'minify.css.groups', 'minify.yuicss.path.java', 'minify.yuicss.path.jar', 'minify.yuicss.options.line-break', 'minify.csstidy.options.remove_bslash', 'minify.csstidy.options.compress_colors', 'minify.csstidy.options.compress_font-weight', 'minify.csstidy.options.lowercase_s', 'minify.csstidy.options.optimise_shorthands', 'minify.csstidy.options.remove_last_;', 'minify.csstidy.options.case_properties', 'minify.csstidy.options.sort_properties', 'minify.csstidy.options.sort_selectors', 'minify.csstidy.options.merge_selectors', 'minify.csstidy.options.discard_invalid_properties', 'minify.csstidy.options.css_level', 'minify.csstidy.options.preserve_css', 'minify.csstidy.options.timestamp', 'minify.csstidy.options.template'));
         }
         if ($new_config->get_boolean('minify.js.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.js.groups')))) {
             $minify_dependencies = array_merge($minify_dependencies, array('minify.js.engine', 'minify.js.combine.header', 'minify.js.combine.body', 'minify.js.combine.footer', 'minify.js.strip.comments', 'minify.js.strip.crlf', 'minify.js.groups', 'minify.yuijs.path.java', 'minify.yuijs.path.jar', 'minify.yuijs.options.line-break', 'minify.yuijs.options.nomunge', 'minify.yuijs.options.preserve-semi', 'minify.yuijs.options.disable-optimizations', 'minify.ccjs.path.java', 'minify.ccjs.path.jar', 'minify.ccjs.options.compilation_level', 'minify.ccjs.options.formatting'));
         }
         $old_minify_dependencies_values = array();
         $new_minify_dependencies_values = array();
         foreach ($minify_dependencies as $minify_dependency) {
             $old_minify_dependencies_values[] = $old_config->get($minify_dependency);
             $new_minify_dependencies_values[] = $new_config->get($minify_dependency);
         }
         if (serialize($old_minify_dependencies_values) != serialize($new_minify_dependencies_values)) {
             $new_config->set('notes.need_empty_minify', true);
         }
     }
     if ($new_config->get_boolean('cdn.enabled') && !w3_is_cdn_mirror($new_config->get_string('cdn.engine'))) {
         /**
          * Show notification when CDN enabled
          */
         if (!$old_config->get_boolean('cdn.enabled')) {
             $new_config->set('notes.cdn_upload', true);
         }
         /**
          * Show notification when Browser Cache settings changes
          */
         $cdn_dependencies = array('browsercache.enabled');
         if ($new_config->get_boolean('cdn.enabled')) {
             $cdn_dependencies = array('browsercache.cssjs.compression', 'browsercache.cssjs.expires', 'browsercache.cssjs.lifetime', 'browsercache.cssjs.cache.control', 'browsercache.cssjs.cache.policy', 'browsercache.cssjs.etag', 'browsercache.cssjs.w3tc', 'browsercache.html.compression', 'browsercache.html.expires', 'browsercache.html.lifetime', 'browsercache.html.cache.control', 'browsercache.html.cache.policy', 'browsercache.html.etag', 'browsercache.html.w3tc', 'browsercache.other.compression', 'browsercache.other.expires', 'browsercache.other.lifetime', 'browsercache.other.cache.control', 'browsercache.other.cache.policy', 'browsercache.other.etag', 'browsercache.other.w3tc');
         }
         $old_cdn_dependencies_values = array();
         $new_cdn_dependencies_values = array();
         foreach ($cdn_dependencies as $cdn_dependency) {
             $old_cdn_dependencies_values[] = $old_config->get($cdn_dependency);
             $new_cdn_dependencies_values[] = $new_config->get($cdn_dependency);
         }
         if (serialize($old_cdn_dependencies_values) != serialize($new_cdn_dependencies_values)) {
             $new_config->set('notes.cdn_reupload', true);
         }
     }
     /**
      * Show need empty object cache notification
      */
     if ($this->_config->get_boolean('objectcache.enabled')) {
         $objectcache_dependencies = array('objectcache.reject.admin', 'objectcache.reject.uri', 'objectcache.groups.global', 'objectcache.groups.nonpersistent');
         $old_objectcache_dependencies_values = array();
         $new_objectcache_dependencies_values = array();
         foreach ($objectcache_dependencies as $objectcache_dependency) {
             $old_objectcache_dependencies_values[] = $old_config->get($objectcache_dependency);
             $new_objectcache_dependencies_values[] = $new_config->get($objectcache_dependency);
         }
         if (serialize($old_objectcache_dependencies_values) != serialize($new_objectcache_dependencies_values)) {
             $new_config->set('notes.need_empty_objectcache', true);
         }
     }
     /**
      * Save config
      */
     if ($new_config->save($preview)) {
         require_once W3TC_LIB_W3_DIR . '/Plugin/PgCache.php';
         require_once W3TC_LIB_W3_DIR . '/Plugin/DbCache.php';
         require_once W3TC_LIB_W3_DIR . '/Plugin/ObjectCache.php';
         require_once W3TC_LIB_W3_DIR . '/Plugin/BrowserCache.php';
         require_once W3TC_LIB_W3_DIR . '/Plugin/Cdn.php';
         $w3_plugin_pgcache =& W3_Plugin_PgCache::instance();
         $w3_plugin_dbcache =& W3_Plugin_DbCache::instance();
         $w3_plugin_objectcache =& W3_Plugin_ObjectCache::instance();
         $w3_plugin_browsercache =& W3_Plugin_BrowserCache::instance();
         $w3_plugin_cdn =& W3_Plugin_Cdn::instance();
         if (W3TC_PHP5) {
             require_once W3TC_LIB_W3_DIR . '/Plugin/Minify.php';
             $w3_plugin_minify =& W3_Plugin_Minify::instance();
         }
         /**
          * Empty caches on engine change or cache enable/disable
          */
         if ($old_config->get_string('pgcache.engine') != $new_config->get_string('pgcache.engine') || $old_config->get_string('pgcache.enabled') != $new_config->get_string('pgcache.enabled')) {
             $this->flush_pgcache();
         }
         if ($old_config->get_string('dbcache.engine') != $new_config->get_string('dbcache.engine') || $old_config->get_string('dbcache.enabled') != $new_config->get_string('dbcache.enabled')) {
             $this->flush_dbcache();
         }
         if ($old_config->get_string('objectcache.engine') != $new_config->get_string('objectcache.engine') || $old_config->get_string('objectcache.enabled') != $new_config->get_string('objectcache.enabled')) {
             $this->flush_objectcache();
         }
         if ($old_config->get_string('minify.engine') != $new_config->get_string('minify.engine') || $old_config->get_string('minify.enabled') != $new_config->get_string('minify.enabled')) {
             $this->flush_minify();
         }
         /**
          * Unschedule events if changed file gc interval
          */
         if ($old_config->get_integer('pgcache.file.gc') != $new_config->get_integer('pgcache.file.gc')) {
             $w3_plugin_pgcache->unschedule();
         }
         if ($old_config->get_integer('pgcache.prime.interval') != $new_config->get_integer('pgcache.prime.interval')) {
             $w3_plugin_pgcache->unschedule_prime();
         }
         if ($old_config->get_integer('dbcache.file.gc') != $new_config->get_integer('dbcache.file.gc')) {
             $w3_plugin_dbcache->unschedule();
         }
         if ($old_config->get_integer('objectcache.file.gc') != $new_config->get_integer('objectcache.file.gc')) {
             $w3_plugin_objectcache->unschedule();
         }
         if ($old_config->get_integer('cdn.autoupload.interval') != $new_config->get_integer('cdn.autoupload.interval')) {
             $w3_plugin_cdn->unschedule_upload();
         }
         if (W3TC_PHP5 && $old_config->get_integer('minify.file.gc') != $new_config->get_integer('minify.file.gc')) {
             $w3_plugin_minify->unschedule();
         }
         /**
          * Create CDN queue table
          */
         if (($old_config->get_boolean('cdn.enabled') != $new_config->get_boolean('cdn.enabled') || $old_config->get_string('cdn.engine') != $new_config->get_string('cdn.engine')) && $new_config->get_boolean('cdn.enabled') && !w3_is_cdn_mirror($new_config->get_string('cdn.engine'))) {
             $w3_plugin_cdn->table_create();
         }
         /**
          * Update CloudFront CNAMEs
          */
         $update_cf_cnames = false;
         if ($new_config->get_boolean('cdn.enabled') && in_array($new_config->get_string('cdn.engine'), array('cf', 'cf2'))) {
             if ($new_config->get_string('cdn.engine') == 'cf') {
                 $old_cnames = $old_config->get_array('cdn.cf.cname');
                 $new_cnames = $new_config->get_array('cdn.cf.cname');
             } else {
                 $old_cnames = $old_config->get_array('cdn.cf2.cname');
                 $new_cnames = $new_config->get_array('cdn.cf2.cname');
             }
             if (count($old_cnames) != count($new_cnames) || count(array_diff($old_cnames, $new_cnames))) {
                 $update_cf_cnames = true;
             }
         }
         /**
          * Refresh config
          */
         $old_config->load();
         /**
          * Schedule events
          */
         $w3_plugin_pgcache->schedule();
         $w3_plugin_pgcache->schedule_prime();
         $w3_plugin_dbcache->schedule();
         $w3_plugin_objectcache->schedule();
         $w3_plugin_cdn->schedule();
         $w3_plugin_cdn->schedule_upload();
         if (W3TC_PHP5) {
             $w3_plugin_minify->schedule();
         }
         /**
          * Update support us option
          */
         $this->link_update();
         /**
          * Write page cache rewrite rules
          */
         if ($new_config->get_boolean('pgcache.enabled') && $new_config->get_string('pgcache.engine') == 'file_generic') {
             if (w3_can_modify_rules(w3_get_pgcache_rules_core_path())) {
                 $w3_plugin_pgcache->write_rules_core();
             }
             if (w3_can_modify_rules(w3_get_pgcache_rules_cache_path())) {
                 $w3_plugin_pgcache->write_rules_cache();
             }
         } else {
             if (w3_can_modify_rules(w3_get_pgcache_rules_core_path())) {
                 $w3_plugin_pgcache->remove_rules_core();
             }
             if (w3_can_modify_rules(w3_get_pgcache_rules_cache_path())) {
                 $w3_plugin_pgcache->remove_rules_cache();
             }
         }
         /**
          * Write browsercache rules
          */
         if ($new_config->get_boolean('browsercache.enabled')) {
             if (w3_can_modify_rules(w3_get_browsercache_rules_cache_path())) {
                 $w3_plugin_browsercache->write_rules_cache();
             }
             if ($new_config->get_boolean('browsercache.no404wp')) {
                 if (w3_can_modify_rules(w3_get_browsercache_rules_no404wp_path())) {
                     $w3_plugin_browsercache->write_rules_no404wp();
                 }
             } else {
                 if (w3_can_modify_rules(w3_get_browsercache_rules_no404wp_path())) {
                     $w3_plugin_browsercache->remove_rules_no404wp();
                 }
             }
         } else {
             if (w3_can_modify_rules(w3_get_browsercache_rules_cache_path())) {
                 $w3_plugin_browsercache->remove_rules_cache();
             }
             if (w3_can_modify_rules(w3_get_browsercache_rules_no404wp_path())) {
                 $w3_plugin_browsercache->remove_rules_no404wp();
             }
         }
         /**
          * Write minify rewrite rules
          */
         if (W3TC_PHP5) {
             if ($new_config->get_boolean('minify.enabled') && $new_config->get_boolean('minify.rewrite')) {
                 if (w3_can_modify_rules(w3_get_minify_rules_core_path())) {
                     $w3_plugin_minify->write_rules_core();
                 }
                 if ($this->_config->get_string('minify.engine') == 'file') {
                     if (w3_can_modify_rules(w3_get_minify_rules_cache_path())) {
                         $w3_plugin_minify->write_rules_cache();
                     }
                 } else {
                     if (w3_can_modify_rules(w3_get_minify_rules_cache_path())) {
                         $w3_plugin_minify->remove_rules_cache();
                     }
                 }
             } else {
                 if (w3_can_modify_rules(w3_get_minify_rules_core_path())) {
                     $w3_plugin_minify->remove_rules_core();
                 }
                 if (w3_can_modify_rules(w3_get_minify_rules_cache_path())) {
                     $w3_plugin_minify->remove_rules_cache();
                 }
             }
         }
         /**
          * Auto upload minify files to CDN
          */
         if ($new_config->get_boolean('minify.enabled') && $new_config->get_boolean('minify.upload') && $new_config->get_boolean('cdn.enabled') && !w3_is_cdn_mirror($new_config->get_string('cdn.engine'))) {
             $this->cdn_upload_minify();
         }
         /**
          * Auto upload browsercache files to CDN
          */
         if ($new_config->get_boolean('cdn.enabled') && $new_config->get_string('cdn.engine') == 'ftp') {
             $this->cdn_delete_browsercache();
             if ($new_config->get_boolean('browsercache.enabled')) {
                 $this->cdn_upload_browsercache();
             }
         }
         /**
          * Update CloudFront CNAMEs
          */
         if ($update_cf_cnames) {
             $error = null;
             $cdn = $w3_plugin_cdn->get_cdn();
             $cdn->update_cnames($error);
         }
         /**
          * Save blognames into file
          */
         if (w3_is_network() && !w3_is_subdomain_install()) {
             w3_save_blognames();
         }
         return true;
     }
     return false;
 }
Пример #2
0
/**
 * 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;
}
Пример #3
0
 /**
  * Check config cache is in sync with config
  * @param W3_Config $config
  * @param SelfTestExceptions $exs
  **/
 private function notify_config_cache_not_writeable($config, $exs)
 {
     try {
         $config->validate_cache_actual();
     } catch (Exception $ex) {
         // we could just create cache folder, so try again
         $config->load(true);
         try {
             $config->validate_cache_actual();
         } catch (Exception $ex) {
             $exs->push(new SelfTestFailedException('<strong>W3 Total Cache Error:</strong> ' . $ex->getMessage()));
         }
     }
 }