/**
 * W3 writable error
 *
 * @param string $path
 * @return string
 */
function w3_writable_error($path)
{
    $reactivate_url = wp_nonce_url('plugins.php?action=activate&plugin=' . W3TC_FILE, 'activate-plugin_' . W3TC_FILE);
    $reactivate_button = sprintf('<input type="button" value="re-activate plugin" onclick="top.location.href = \'%s\'" />', addslashes($reactivate_url));
    try {
        w3_throw_on_write_error($path);
    } catch (Exception $e) {
        w3_activation_error_on_exception($e);
    }
}
 /**
  * Save dbcluster config action
  *
  * @return void
  */
 function action_config_dbcluster_config_save()
 {
     $params = array('page' => 'w3tc_general');
     if (!file_put_contents(W3TC_FILE_DB_CLUSTER_CONFIG, stripslashes($_REQUEST['newcontent']))) {
         w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
         try {
             w3_throw_on_write_error(W3TC_FILE_DB_CLUSTER_CONFIG);
         } catch (Exception $e) {
             $error = $e->getMessage();
             w3_admin_redirect_with_custom_messages($params, array($error));
         }
     }
     w3_admin_redirect_with_custom_messages($params, null, array(__('Database Cluster configuration file has been successfully saved', 'w3-total-cache')));
 }
 /**
  * Writes rules to file cache .htaccess
  * Throw exceptions
  *
  */
 function write_rules_cache()
 {
     w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
     $path = w3_get_minify_rules_cache_path();
     if (!file_exists(dirname($path))) {
         w3_mkdir_from(dirname($path), W3TC_CACHE_DIR);
     }
     if (file_exists($path)) {
         $data = @file_get_contents($path);
         if ($data !== false) {
             $data = $this->erase_rules_legacy($data);
         } else {
             w3_throw_on_read_error($path);
         }
     } else {
         $data = '';
     }
     $replace_start = strpos($data, W3TC_MARKER_BEGIN_MINIFY_CACHE);
     $replace_end = strpos($data, W3TC_MARKER_END_MINIFY_CACHE);
     if ($replace_start !== false && $replace_end !== false && $replace_start < $replace_end) {
         $replace_length = $replace_end - $replace_start + strlen(W3TC_MARKER_END_MINIFY_CACHE) + 1;
     } else {
         $replace_start = false;
         $replace_length = 0;
         $search = array(W3TC_MARKER_BEGIN_PGCACHE_CACHE => 0, W3TC_MARKER_BEGIN_BROWSERCACHE_CACHE => 0, W3TC_MARKER_BEGIN_MINIFY_CORE => 0, W3TC_MARKER_BEGIN_PGCACHE_CORE => 0, W3TC_MARKER_BEGIN_BROWSERCACHE_NO404WP => 0, W3TC_MARKER_BEGIN_WORDPRESS => 0);
         foreach ($search as $string => $length) {
             $replace_start = strpos($data, $string);
             if ($replace_start !== false) {
                 $replace_start += $length;
                 break;
             }
         }
     }
     $rules = $this->generate_rules_cache();
     if ($replace_start !== false) {
         $data = w3_trim_rules(substr_replace($data, $rules, $replace_start, $replace_length));
     } else {
         $data = w3_trim_rules($data . $rules);
     }
     if (!@file_put_contents($path, $data)) {
         w3_throw_on_write_error($path);
     }
 }
 /**
  * Saves modified config
  */
 function save()
 {
     $filename = $this->_get_config_filename();
     if (!is_dir(dirname($filename))) {
         w3_require_once(W3TC_INC_DIR . '/functions/file.php');
         w3_mkdir_from(dirname($filename), WP_CONTENT_DIR);
     }
     if (!is_dir(dirname(W3TC_CACHE_TMP_DIR))) {
         w3_require_once(W3TC_INC_DIR . '/functions/file.php');
         w3_mkdir_from(dirname(W3TC_CACHE_TMP_DIR), WP_CONTENT_DIR);
     }
     if (!$this->_data_object->write($filename)) {
         if (is_dir(W3TC_CONFIG_DIR)) {
             w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
             w3_throw_on_write_error($filename, array(dirname($filename), W3TC_CACHE_TMP_DIR));
         }
     }
 }
Example #5
0
 /**
  * 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
  */
 function preview_production_copy($direction, $remove_source)
 {
     $preview_filename = $this->_get_config_filename(false, true);
     $production_filename = $this->_get_config_filename(false, false);
     if ($direction > 0) {
         $src = $preview_filename;
         $dest = $production_filename;
     } else {
         $src = $production_filename;
         $dest = $preview_filename;
     }
     if (!@copy($src, $dest)) {
         w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
         w3_throw_on_write_error($dest);
     }
     if ($remove_source) {
         @unlink($src);
     }
 }