/**
  * Fixes folders
  *
  * @param W3_Config $config
  * @param SelfTestExceptions $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)) {
             w3_wp_delete_folder($dir, '', $_SERVER['REQUEST_URI']);
         }
     } catch (FilesystemRmdirException $ex) {
         $exs->push($ex);
     }
 }
 /**
  * Checks if addins in wp-content is available and correct version.
  * @throws SelfTestExceptions
  */
 private function create_required_folders($exs)
 {
     // folders that we create if not exists
     $directories = array(W3TC_CACHE_DIR, W3TC_CONFIG_DIR);
     foreach ($directories as $directory) {
         try {
             w3_wp_create_writeable_folder($directory, WP_CONTENT_DIR);
         } catch (FilesystemOperationException $ex) {
             $exs->push($ex);
         }
     }
     // folders that we delete if exists and not writeable
     $directories = array(W3TC_CACHE_CONFIG_DIR, W3TC_CACHE_TMP_DIR, W3TC_CACHE_BLOGMAP_FILENAME, W3TC_CACHE_DIR . '/object', W3TC_CACHE_DIR . '/db');
     foreach ($directories as $directory) {
         try {
             if (file_exists($directory) && !is_writeable($directory)) {
                 w3_wp_delete_folder($directory);
             }
         } catch (FilesystemRmdirException $ex) {
             $exs->push($ex);
         }
     }
 }
 /**
  * Fixes folders
  * @param W3_Config $config
  * @param SelfTestExceptions $exs
  **/
 private function fix_folders($config, $exs)
 {
     // folder that we delete if exists and not writeable
     if ($config->get_boolean('minify.enabled') && $config->get_string('minify.engine') == 'file') {
         $dir = W3TC_CACHE_MINIFY_DIR;
         try {
             if (file_exists($dir) && !is_writeable($dir)) {
                 w3_wp_delete_folder($dir, '', $_SERVER['REQUEST_URI']);
             }
         } catch (FilesystemRmdirException $ex) {
             $exs->push($ex);
         }
     }
 }
Exemplo n.º 4
0
/**
 * @param SelfTestExceptions $exs
 * @param string $path
 * @param string $rules
 * @param string $start
 * @param string $end
 * @param array $order
 */
function w3_add_rules($exs, $path, $rules, $start, $end, $order)
{
    $data = @file_get_contents($path);
    if ($data === false) {
        $data = '';
    }
    $rules_missing = !empty($rules) && strstr(w3_clean_rules($data), w3_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 = w3_trim_rules(substr_replace($data, $rules, $replace_start, $replace_length));
    } else {
        $data = w3_trim_rules($data . $rules);
    }
    if (strpos($path, W3TC_CACHE_DIR) === false || w3_is_nginx()) {
        try {
            w3_wp_write_to_file($path, $data);
        } catch (FilesystemOperationException $ex) {
            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-caceh'), $path, $start, $end), $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:', 'w3-total-cache'), $path), $path, $rules));
            }
        }
    } else {
        if (!@file_exists(dirname($path))) {
            w3_mkdir_from(dirname($path), W3TC_CACHE_DIR);
        }
        if (!@file_put_contents($path, $data)) {
            try {
                w3_wp_delete_folder(dirname($path), '', $_SERVER['REQUEST_URI']);
            } catch (FilesystemOperationException $ex) {
                $exs->push($ex);
            }
        }
    }
}