Ejemplo n.º 1
0
 /**
  * @throws FilesystemWriteException
  * @throws FilesystemWriteException
  */
 public function create()
 {
     $path = trim(w3_get_wp_sitepath(), "/");
     if ($path) {
         $path .= '/';
     }
     $file_data = "\n<?php\n    if (W3TC_WP_LOADING)\n        require_once '" . w3_get_document_root() . '/' . $path . "wp-load.php';\n";
     $filename = W3TC_WP_LOADER;
     $data = $file_data;
     w3_require_once(W3TC_INC_DIR . '/functions/rule.php');
     $current_data = @file_get_contents($filename);
     if (strstr(w3_clean_rules($current_data), w3_clean_rules($data)) !== false) {
         return;
     }
     w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
     w3_wp_write_to_file($filename, $data, '', $_SERVER['REQUEST_URI']);
 }
Ejemplo n.º 2
0
 public function action_edge_mode_disable()
 {
     w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/activation.php');
     $config_path = w3_get_wp_config_path();
     $config_data = @file_get_contents($config_path);
     if ($config_data === false) {
         return;
     }
     $new_config_data = $this->wp_config_evaluation_mode_remove_from_content($config_data);
     if ($new_config_data != $config_data) {
         try {
             w3_wp_write_to_file($config_path, $new_config_data);
         } catch (FilesystemOperationException $ex) {
             throw new FilesystemModifyException($ex->getMessage(), $ex->credentials_form(), 'Edit file <strong>' . $config_path . '</strong> and remove next lines:', $config_path, $this->wp_config_evaluation_mode());
         }
     }
     w3_admin_redirect(array('w3tc_note' => 'disabled_edge'));
 }
 /**
  * Writes directives to WP .htaccess
  *
  * @param W3_Config $config
  * @param SelfTestExceptions $exs
  * @throws FilesystemOperationException with S/FTP form if it can't get the required filesystem credentials
  * @throws FileOperationException
  */
 private function rules_core_add($config, $exs)
 {
     $path = w3_get_pgcache_rules_core_path();
     if ($path === false) {
         return;
     }
     $original_data = @file_get_contents($path);
     if ($original_data === false) {
         $original_data = '';
     }
     $data = $original_data;
     $new_data = w3_erase_rules($data, W3TC_MARKER_BEGIN_PGCACHE_LEGACY, W3TC_MARKER_END_PGCACHE_LEGACY);
     $has_legacy = strlen($new_data) < strlen($data);
     $data = $new_data;
     $new_data = w3_erase_rules($data, W3TC_MARKER_BEGIN_PGCACHE_WPSC, W3TC_MARKER_END_PGCACHE_WPSC);
     $has_wpsc = strlen($new_data) < strlen($data);
     $data = $new_data;
     $rules = $this->rules_core_generate($config);
     $rules_missing = strstr(w3_clean_rules($data), w3_clean_rules($rules)) === false;
     if (!$has_legacy && !$has_wpsc && !$rules_missing) {
         return;
     }
     // modification of file not required
     $replace_start = strpos($data, W3TC_MARKER_BEGIN_PGCACHE_CORE);
     $replace_end = strpos($data, W3TC_MARKER_END_PGCACHE_CORE);
     if ($replace_start !== false && $replace_end !== false && $replace_start < $replace_end) {
         $replace_length = $replace_end - $replace_start + strlen(W3TC_MARKER_END_PGCACHE_CORE) + 1;
     } else {
         $replace_start = false;
         $replace_length = 0;
         $search = array(W3TC_MARKER_BEGIN_BROWSERCACHE_NO404WP => 0, W3TC_MARKER_BEGIN_WORDPRESS => 0, W3TC_MARKER_END_MINIFY_CORE => strlen(W3TC_MARKER_END_MINIFY_CORE) + 1, W3TC_MARKER_END_BROWSERCACHE_CACHE => strlen(W3TC_MARKER_END_BROWSERCACHE_CACHE) + 1, W3TC_MARKER_END_PGCACHE_CACHE => strlen(W3TC_MARKER_END_PGCACHE_CACHE) + 1, W3TC_MARKER_END_MINIFY_CACHE => strlen(W3TC_MARKER_END_MINIFY_CACHE) + 1);
         foreach ($search as $string => $length) {
             $replace_start = strpos($data, $string);
             if ($replace_start !== false) {
                 $replace_start += $length;
                 break;
             }
         }
     }
     if ($replace_start !== false) {
         $data = w3_trim_rules(substr_replace($data, $rules, $replace_start, $replace_length));
     } else {
         $data = w3_trim_rules($data . $rules);
     }
     try {
         w3_wp_write_to_file($path, $data);
     } catch (FilesystemOperationException $ex) {
         if ($has_legacy) {
             $exs->push(new FilesystemModifyException($ex->getMessage(), $ex->credentials_form(), sprintf(__('Edit file <strong>%s</strong> and remove all lines between and including <strong>
                             %s</strong> and <strong>%s</strong> markers.', 'w3-total-cache'), $path, W3TC_MARKER_BEGIN_PGCACHE_LEGACY, W3TC_MARKER_END_PGCACHE_LEGACY), $path));
         }
         if ($has_wpsc) {
             $exs->push(new FilesystemModifyException($ex->getMessage(), $ex->credentials_form(), sprintf(__('Edit file <strong>%s</strong> and remove all lines between and including
                             <strong>%s</strong> and <strong>%s</strong> markers.', 'w3-total-cache'), $path, W3TC_MARKER_BEGIN_PGCACHE_WPSC, W3TC_MARKER_END_PGCACHE_WPSC), $path));
         }
         if ($rules_missing) {
             if ($replace_start !== false) {
                 $exs->push(new 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-cache'), $path, W3TC_MARKER_BEGIN_PGCACHE_CORE, W3TC_MARKER_END_PGCACHE_CORE), $path, $rules));
             } else {
                 $exs->push(new FilesystemModifyException($ex->getMessage(), $ex->credentials_form(), sprintf(__('Edit file <strong>%s</strong> and add the following rules above the WordPress
                                 directives:'), $path), $path, $rules));
             }
         }
     }
 }
 /**
  * Removes no404wp rules
  *
  * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
  * @throws FileOperationException
  */
 function remove_rules_no404wp()
 {
     $path = w3_get_browsercache_rules_no404wp_path();
     if (file_exists($path)) {
         if (($data = @file_get_contents($path)) !== false) {
             $data = $this->erase_rules_no404wp($data);
             w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
             w3_wp_write_to_file($path, $data);
         }
     }
 }
Ejemplo n.º 5
0
/**
 * @param SelfTestExceptions $exs
 * @param string $path
 * @param string $start
 * @param string $end
 */
function w3_remove_rules($exs, $path, $start, $end)
{
    if (!file_exists($path)) {
        return;
    }
    $data = @file_get_contents($path);
    if ($data === false) {
        return;
    }
    if (strstr($data, $start) === false) {
        return;
    }
    $data = w3_erase_rules($data, $start, $end);
    try {
        w3_wp_write_to_file($path, $data);
    } catch (FilesystemOperationException $ex) {
        $exs->push(new FilesystemModifyException($ex->getMessage(), $ex->credentials_form(), sprintf(__('Edit file <strong>%s</strong> and remove all lines between and including <strong>%s</strong>
            and <strong>%s</strong> markers.', 'w3-total-cache'), $path, $start, $end), $path));
    }
}
Ejemplo n.º 6
0
 /**
  * @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;
 }
 /**
  * Writes rules to file cache .htaccess
  *
  * @return boolean
  */
 function write_rules_core()
 {
     $path = w3_get_new_relic_rules_core_path();
     if (file_exists($path)) {
         $data = @file_get_contents($path);
     } else {
         $data = '';
     }
     $replace_start = strpos($data, W3TC_MARKER_BEGIN_NEW_RELIC_CORE);
     $replace_end = strpos($data, W3TC_MARKER_END_NEW_RELIC_CORE);
     if ($replace_start !== false && $replace_end !== false && $replace_start < $replace_end) {
         $replace_length = $replace_end - $replace_start + strlen(W3TC_MARKER_END_MINIFY_CORE) + 1;
     } else {
         $replace_start = false;
         $replace_length = 0;
         $search = array(W3TC_MARKER_BEGIN_PGCACHE_CORE => 0, W3TC_MARKER_BEGIN_BROWSERCACHE_NO404WP => 0, W3TC_MARKER_BEGIN_WORDPRESS => 0, W3TC_MARKER_END_BROWSERCACHE_CACHE => strlen(W3TC_MARKER_END_BROWSERCACHE_CACHE) + 1, W3TC_MARKER_END_PGCACHE_CACHE => strlen(W3TC_MARKER_END_PGCACHE_CACHE) + 1, W3TC_MARKER_END_MINIFY_CACHE => strlen(W3TC_MARKER_END_MINIFY_CACHE) + 1);
         foreach ($search as $string => $length) {
             $replace_start = strpos($data, $string);
             if ($replace_start !== false) {
                 $replace_start += $length;
                 break;
             }
         }
     }
     $rules = $this->generate_rules_core();
     if (!$rules) {
         return;
     }
     if ($replace_start !== false) {
         $data = w3_trim_rules(substr_replace($data, $rules, $replace_start, $replace_length));
     } else {
         $data = w3_trim_rules($data . $rules);
     }
     w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
     w3_wp_write_to_file($path, $data);
 }
Ejemplo n.º 8
0
/**
 * Creates maintenance mode file
 * @param $time
 */
function w3_enable_maintenance_mode($time = null)
{
    if (is_null($time)) {
        $time = 'time()';
    }
    w3_wp_write_to_file(w3_get_site_root() . '/.maintenance', "<?php \$upgrading = {$time}; ?>");
}