/**
  * Activate plugin action
  *
  * @param bool    $network_wide
  * @return void
  */
 public static function activate($network_wide)
 {
     // decline non-network activation at WPMU
     if (Util_Environment::is_wpmu()) {
         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 = Dispatcher::component('Root_Environment');
         $config = Dispatcher::config();
         $e->fix_on_event($config, 'activate');
         Generic_AdminLinks::link_update($config);
         // try to save config file if needed, optional thing so exceptions
         // hidden
         if (!file_exists(Config::util_config_filename(0, false))) {
             try {
                 // create folders
                 $e->fix_in_wpadmin($config);
             } catch (\Exception $ex) {
             }
             try {
                 Util_Admin::config_save(Dispatcher::config(), $config);
             } catch (\Exception $ex) {
             }
         }
     } catch (\Exception $e) {
         Util_Activation::error_on_exception($e);
     }
 }
 public function save()
 {
     $data = array('version' => $this->_data['version']);
     if ($this->is_master()) {
         foreach ($this->_data as $key => $value) {
             $data[$key] = $this->_data[$key];
         }
     } else {
         // write only overwrited keys
         $master = new ConfigCompiler(0, $this->_preview);
         $master->load();
         foreach ($this->_data as $key => $value) {
             if (!ConfigCompiler::child_key_sealed($key, $master->_data, $this->_data)) {
                 $data[$key] = $this->_data[$key];
             }
         }
     }
     $filename = Config::util_config_filename($this->_blog_id, $this->_preview);
     if (defined('JSON_PRETTY_PRINT')) {
         $config = json_encode($data, JSON_PRETTY_PRINT);
     } else {
         // for older php versions
         $config = json_encode($data);
     }
     Util_File::file_put_contents_atomic($filename, $config);
 }
 /**
  * Check config file
  *
  * @param Config  $config
  * @param Util_Environment_Exceptions $exs
  */
 private function notify_no_config_present($config, $exs)
 {
     if ((file_exists(Config::util_config_filename(0, false)) || file_exists(Config::util_config_filename_legacy(0, false))) && $config->get_integer('common.instance_id', 0) != 0) {
         return;
     }
     $onclick = 'document.location.href=\'' . addslashes(wp_nonce_url('admin.php?page=w3tc_general&w3tc_save_options', 'w3tc')) . '\';';
     $button = '<input type="button" class="button w3tc" ' . 'value="save the settings" onclick="' . $onclick . '" />';
     $exs->push(new Util_Environment_Exception('<strong>W3 Total Cache:</strong> ' . 'Default settings are in use. The configuration file could ' . 'not be read or doesn\'t exist. Please ' . $button . ' to create the file.'));
 }
Example #4
0
 /**
  * Loads config.
  * In a case it finds out config files are of older version - uses slower
  * loader which takes all possible bloglevel-overloads into account
  * correctly
  */
 public function load()
 {
     $master_filename = Config::util_config_filename(0, $this->_preview);
     $data = Config::util_array_from_file($master_filename);
     // config file assumed is not up to date, use slow version
     if (!isset($data['version']) || $data['version'] != W3TC_VERSION) {
         return $this->load_full();
     }
     if (!$this->is_master()) {
         $child_filename = Config::util_config_filename($this->_blog_id, $this->_preview);
         $child_data = Config::util_array_from_file($child_filename);
         if (!is_null($child_data)) {
             if (!isset($data['version']) || $data['version'] != W3TC_VERSION) {
                 return $this->load_full();
             }
             foreach ($child_data as $key => $value) {
                 $data[$key] = $value;
             }
         }
     }
     $this->_data = $data;
 }
 /**
  * Deploys the config file from a preview config file
  *
  * @param integer $direction     +1: preview->production
  *                           -1: production->preview
  * @param boolean $remove_source remove source file
  */
 private function preview_production_copy($direction = 1)
 {
     $blog_id = Util_Environment::blog_id();
     $preview_filename = Config::util_config_filename($blog_id, true);
     $production_filename = Config::util_config_filename($blog_id, false);
     if ($direction > 0) {
         $src = $preview_filename;
         $dest = $production_filename;
     } else {
         $src = $production_filename;
         $dest = $preview_filename;
     }
     if (!@copy($src, $dest)) {
         Util_Activation::throw_on_write_error($dest);
     }
 }