Ejemplo n.º 1
0
 /**
  * Fixes environment once event occurs
  *
  * @param Config  $config
  * @param string  $event
  * @param Config|null $old_config
  * @throws Util_Environment_Exceptions
  */
 public function fix_on_event($config, $event, $old_config = null)
 {
     if ($config->get_boolean('cdn.enabled') && !Cdn_Util::is_engine_mirror($config->get_string('cdn.engine'))) {
         if ($old_config != null && $config->get_integer('cdn.queue.interval') != $old_config->get_integer('cdn.queue.interval')) {
             $this->unschedule_queue_process();
         }
         if (!wp_next_scheduled('w3_cdn_cron_queue_process')) {
             wp_schedule_event(time(), 'w3_cdn_cron_queue_process', 'w3_cdn_cron_queue_process');
         }
     } else {
         $this->unschedule_queue_process();
     }
     if ($config->get_boolean('cdn.enabled') && $config->get_boolean('cdn.autoupload.enabled') && !Cdn_Util::is_engine_mirror($config->get_string('cdn.engine'))) {
         if ($old_config != null && $config->get_integer('cdn.autoupload.interval') != $old_config->get_integer('cdn.autoupload.interval')) {
             $this->unschedule_upload();
         }
         if (!wp_next_scheduled('w3_cdn_cron_upload')) {
             wp_schedule_event(time(), 'w3_cdn_cron_upload', 'w3_cdn_cron_upload');
         }
     } else {
         $this->unschedule_upload();
     }
     $exs = new Util_Environment_Exceptions();
     if ($config->get_boolean('cdn.enabled')) {
         try {
             $this->table_create($event == 'activate');
         } catch (\Exception $ex) {
             $exs->push($ex);
         }
     }
     if (count($exs->exceptions()) > 0) {
         throw $exs;
     }
 }
Ejemplo n.º 2
0
 /**
  * Fixes environment after plugin deactivation
  *
  * @throws Util_Environment_Exceptions
  * @return array
  */
 public function fix_after_deactivation()
 {
     $exs = new Util_Environment_Exceptions();
     try {
         $this->delete_addin();
     } catch (Util_WpFile_FilesystemOperationException $ex) {
         $exs->push($ex);
     }
     $this->unschedule();
     if (count($exs->exceptions()) > 0) {
         throw $exs;
     }
 }
Ejemplo n.º 3
0
 /**
  * Fixes environment after plugin deactivation
  *
  * @param Config  $config
  * @throws Util_Environment_Exceptions
  */
 public function fix_after_deactivation($config)
 {
     $exs = new Util_Environment_Exceptions();
     // call plugin-related handlers
     foreach ($this->get_handlers($config) as $h) {
         try {
             $h->fix_after_deactivation();
         } catch (Util_Environment_Exceptions $ex) {
             $exs->push($ex);
         }
     }
     try {
         do_action('w3tc_environment_fix_after_deactivation', $config);
     } catch (Util_Environment_Exceptions $ex) {
         $exs->push($ex);
     }
     if (count($exs->exceptions()) > 0) {
         throw $exs;
     }
 }
 /**
  * Minifiers availability error handling
  *
  * @param Config  $config
  * @param Util_Environment_Exceptions $exs
  */
 private function verify_engine_working($config, $exs)
 {
     $minifiers_errors = array();
     if ($config->get_string('minify.js.engine') == 'yuijs') {
         $path_java = $config->get_string('minify.yuijs.path.java');
         $path_jar = $config->get_string('minify.yuijs.path.jar');
         if (!file_exists($path_java)) {
             $minifiers_errors[] = sprintf('YUI Compressor (JS): JAVA executable path was not found. The default minifier JSMin will be used instead.');
         } elseif (!file_exists($path_jar)) {
             $minifiers_errors[] = sprintf('YUI Compressor (JS): JAR file path was not found. The default minifier JSMin will be used instead.');
         }
     }
     if ($config->get_string('minify.css.engine') == 'yuicss') {
         $path_java = $config->get_string('minify.yuicss.path.java');
         $path_jar = $config->get_string('minify.yuicss.path.jar');
         if (!file_exists($path_java)) {
             $minifiers_errors[] = sprintf('YUI Compressor (CSS): JAVA executable path was not found. The default CSS minifier will be used instead.');
         } elseif (!file_exists($path_jar)) {
             $minifiers_errors[] = sprintf('YUI Compressor (CSS): JAR file path was not found. The default CSS minifier will be used instead.');
         }
     }
     if ($config->get_string('minify.js.engine') == 'ccjs') {
         $path_java = $config->get_string('minify.ccjs.path.java');
         $path_jar = $config->get_string('minify.ccjs.path.jar');
         if (!file_exists($path_java)) {
             $minifiers_errors[] = sprintf('Closure Compiler: JAVA executable path was not found. The default minifier JSMin will be used instead.');
         } elseif (!file_exists($path_jar)) {
             $minifiers_errors[] = sprintf('Closure Compiler: JAR file path was not found. The default minifier JSMin will be used instead.');
         }
     }
     if (count($minifiers_errors)) {
         $minify_error = 'The following minifiers cannot be found or are no longer working:</p><ul>';
         foreach ($minifiers_errors as $minifiers_error) {
             $minify_error .= '<li>' . $minifiers_error . '</li>';
         }
         $minify_error .= '</ul><p>This message will automatically disappear once the issue is resolved.';
         $exs->push(new Util_Environment_Exception($minify_error));
     }
 }
 /**
  * Fixes folders
  *
  * @param Config  $config
  * @param Util_Environment_Exceptions $exs
  */
 private function fix_folders($config, $exs)
 {
     if (!$config->get_boolean('pgcache.enabled')) {
         return;
     }
     // folder that we delete if exists and not writeable
     if ($config->get_string('pgcache.engine') == 'file_generic') {
         $dir = W3TC_CACHE_PAGE_ENHANCED_DIR;
     } else {
         if ($config->get_string('pgcache.engine') != 'file') {
             $dir = W3TC_CACHE_DIR . '/page';
         } else {
             return;
         }
     }
     try {
         if (file_exists($dir) && !is_writeable($dir)) {
             Util_WpFile::delete_folder($dir, '', $_SERVER['REQUEST_URI']);
         }
     } catch (Util_WpFile_FilesystemRmdirException $ex) {
         $exs->push($ex);
     }
 }
Ejemplo n.º 6
0
 /**
  * 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.'));
 }
 /**
  *
  *
  * @param Util_Environment_Exceptions $exs
  * @param string  $path
  * @param string  $rules
  * @param string  $start
  * @param string  $end
  * @param array   $order
  */
 public static function add_rules($exs, $path, $rules, $start, $end, $order)
 {
     if (empty($path)) {
         return;
     }
     $data = @file_get_contents($path);
     if ($data === false) {
         $data = '';
     }
     $rules_missing = !empty($rules) && strstr(Util_Rule::clean_rules($data), Util_Rule::clean_rules($rules)) === false;
     if (!$rules_missing) {
         return;
     }
     $replace_start = strpos($data, $start);
     $replace_end = strpos($data, $end);
     if ($replace_start !== false && $replace_end !== false && $replace_start < $replace_end) {
         $replace_length = $replace_end - $replace_start + strlen($end) + 1;
     } else {
         $replace_start = false;
         $replace_length = 0;
         $search = $order;
         foreach ($search as $string => $length) {
             $replace_start = strpos($data, $string);
             if ($replace_start !== false) {
                 $replace_start += $length;
                 break;
             }
         }
     }
     if ($replace_start !== false) {
         $data = Util_Rule::trim_rules(substr_replace($data, $rules, $replace_start, $replace_length));
     } else {
         $data = Util_Rule::trim_rules($data . $rules);
     }
     if (strpos($path, W3TC_CACHE_DIR) === false || Util_Environment::is_nginx()) {
         try {
             Util_WpFile::write_to_file($path, $data);
         } catch (Util_WpFile_FilesystemOperationException $ex) {
             if ($replace_start !== false) {
                 $exs->push(new Util_WpFile_FilesystemModifyException($ex->getMessage(), $ex->credentials_form(), sprintf(__('Edit file <strong>%s
                         </strong> and replace all lines between and including <strong>%s</strong> and
                         <strong>%s</strong> markers with:', 'w3-total-caceh'), $path, $start, $end), $path, $rules));
             } else {
                 $exs->push(new Util_WpFile_FilesystemModifyException($ex->getMessage(), $ex->credentials_form(), sprintf(__('Edit file <strong>%s</strong> and add the following rules
                                 above the WordPress directives:', 'w3-total-cache'), $path), $path, $rules));
             }
             return;
         }
     } else {
         if (!@file_exists(dirname($path))) {
             Util_File::mkdir_from(dirname($path), W3TC_CACHE_DIR);
         }
         if (!@file_put_contents($path, $data)) {
             try {
                 Util_WpFile::delete_folder(dirname($path), '', $_SERVER['REQUEST_URI']);
             } catch (Util_WpFile_FilesystemOperationException $ex) {
                 $exs->push($ex);
                 return;
             }
         }
     }
     Util_Rule::after_rules_modified();
 }