Exemplo n.º 1
0
 /**
  * Minify tab
  *
  * @return void
  */
 function view()
 {
     $minify_enabled = $this->_config->get_boolean('minify.enabled');
     $config_state = Dispatcher::config_state();
     $minify_rewrite_disabled = !Util_Rule::can_check_rules() || $this->_config->is_sealed('minify.rewrite');
     $themes = Util_Theme::get_themes_by_key();
     $templates = array();
     $current_theme = Util_Theme::get_current_theme_name();
     $current_theme_key = '';
     foreach ($themes as $theme_key => $theme_name) {
         if ($theme_name == $current_theme) {
             $current_theme_key = $theme_key;
         }
         $templates[$theme_key] = Util_Theme::get_theme_templates($theme_name);
     }
     $css_imports_values = array('' => 'None', 'bubble' => 'Bubble', 'process' => 'Process');
     $auto = $this->_config->get_boolean('minify.auto');
     $js_theme = Util_Request::get_string('js_theme', $current_theme_key);
     $js_groups = $this->_config->get_array('minify.js.groups');
     $css_theme = Util_Request::get_string('css_theme', $current_theme_key);
     $css_groups = $this->_config->get_array('minify.css.groups');
     $js_engine = $this->_config->get_string('minify.js.engine');
     $css_engine = $this->_config->get_string('minify.css.engine');
     $html_engine = $this->_config->get_string('minify.html.engine');
     $css_imports = $this->_config->get_string('minify.css.imports');
     // Required for Update Media Query String button
     $browsercache_enabled = $this->_config->get_boolean('browsercache.enabled');
     $browsercache_update_media_qs = $this->_config->get_boolean('browsercache.cssjs.replace');
     include W3TC_INC_DIR . '/options/minify.php';
 }
 /**
  * General tab
  *
  * @return void
  */
 function view()
 {
     global $current_user;
     $config_master = $this->_config_master;
     /**
      *
      *
      * @var $modules W3_ModuleStatus
      */
     $modules = Dispatcher::component('ModuleStatus');
     $pgcache_enabled = $modules->is_enabled('pgcache');
     $dbcache_enabled = $modules->is_enabled('dbcache');
     $objectcache_enabled = $modules->is_enabled('objectcache');
     $browsercache_enabled = $modules->is_enabled('browsercache');
     $minify_enabled = $modules->is_enabled('minify');
     $cdn_enabled = $modules->is_enabled('cdn');
     $varnish_enabled = $modules->is_enabled('varnish');
     $enabled = $modules->plugin_is_enabled();
     $enabled_checkbox = $modules->all_modules_enabled();
     $check_rules = Util_Rule::can_check_rules();
     $disc_enhanced_enabled = !(!$check_rules || !$this->is_master() && Util_Environment::is_wpmu() && $config_master->get_string('pgcache.engine') != 'file_generic');
     $can_empty_file = $modules->can_empty_file();
     $can_empty_varnish = $modules->can_empty_varnish();
     $cdn_mirror_purge = Cdn_Util::can_purge_all($modules->get_module_engine('cdn'));
     $file_nfs = $this->_config->get_boolean('pgcache.file.nfs') || $this->_config->get_boolean('minify.file.nfs');
     $file_locking = $this->_config->get_boolean('dbcache.file.locking') || $this->_config->get_boolean('objectcache.file.locking') || $this->_config->get_boolean('pgcache.file.locking') || $this->_config->get_boolean('minify.file.locking');
     $licensing_visible = (!Util_Environment::is_wpmu() || is_network_admin()) && !ini_get('w3tc.license_key') && get_transient('w3tc_license_status') != 'host_valid';
     $custom_areas = apply_filters("w3tc_settings_general_anchors", array());
     include W3TC_INC_DIR . '/options/general.php';
 }
Exemplo n.º 3
0
 public static function minified_url($minify_filename)
 {
     $path = Util_Environment::cache_blog_minify_dir();
     $filename = $path . '/' . $minify_filename;
     $c = Dispatcher::config();
     if (Util_Rule::can_check_rules() && $c->get_boolean('minify.rewrite')) {
         return Util_Environment::filename_to_url($filename);
     }
     return network_site_url('?w3tc_minify=' . $minify_filename);
 }
 /**
  * Install tab
  *
  * @return void
  */
 function view()
 {
     $rewrite_rules_descriptors = array();
     if (Util_Rule::can_check_rules()) {
         $e = Dispatcher::component('Root_Environment');
         $rewrite_rules_descriptors = $e->get_required_rules($this->_config);
         $other_areas = $e->get_other_instructions($this->_config);
     }
     include W3TC_INC_DIR . '/options/install.php';
 }
Exemplo n.º 5
0
 /**
  * CDN tab
  *
  * @return void
  */
 function view()
 {
     $config = Dispatcher::config();
     $cdn_engine = $config->get_string('cdn.engine');
     if (Cdn_Util::is_engine_fsd($cdn_engine)) {
         do_action('w3tc_settings_cdn');
         return;
     }
     $cdn_enabled = $config->get_boolean('cdn.enabled');
     $cdn_mirror = Cdn_Util::is_engine_mirror($cdn_engine);
     $cdn_mirror_purge_all = Cdn_Util::can_purge_all($cdn_engine);
     $cdn_common = Dispatcher::component('Cdn_Core');
     $cdn = $cdn_common->get_cdn();
     $cdn_supports_header = $cdn->headers_support() == W3TC_CDN_HEADER_MIRRORING;
     $minify_enabled = $config->get_boolean('minify.enabled') && Util_Rule::can_check_rules() && $config->get_boolean('minify.rewrite') && (!$config->get_boolean('minify.auto') || Cdn_Util::is_engine_mirror($config->get_string('cdn.engine')));
     $cookie_domain = $this->get_cookie_domain();
     $set_cookie_domain = $this->is_cookie_domain_enabled();
     // Required for Update Media Query String button
     $browsercache_enabled = $config->get_boolean('browsercache.enabled');
     $browsercache_update_media_qs = $config->get_boolean('browsercache.cssjs.replace') || $config->get_boolean('browsercache.other.replace');
     if (in_array($cdn_engine, array('netdna', 'maxcdn'))) {
         $pull_zones = array();
         $authorization_key = $config->get_string("cdn.{$cdn_engine}.authorization_key");
         $zone_id = $config->get_integer("cdn.{$cdn_engine}.zone_id");
         $alias = $consumerkey = $consumersecret = '';
         if ($authorization_key) {
             $keys = explode('+', $authorization_key);
             if (sizeof($keys) == 3) {
                 list($alias, $consumerkey, $consumersecret) = $keys;
             }
         }
         $authorized = $authorization_key != '' && $alias && $consumerkey && $consumersecret;
         $have_zone = $zone_id != 0;
         if ($authorized) {
             require_once W3TC_LIB_NETDNA_DIR . '/NetDNA.php';
             try {
                 $api = new \NetDNA($alias, $consumerkey, $consumersecret);
                 $pull_zones = $api->get_zones_by_url(get_home_url());
             } catch (\Exception $ex) {
                 Util_Ui::error_box('<p>There is an error with your CDN settings: ' . $ex->getMessage() . '</p>');
             }
         }
     }
     include W3TC_INC_DIR . '/options/cdn.php';
 }
 /**
  * Plugin action links filter
  *
  * @param array   $links
  * @return array
  */
 function plugin_action_links($links)
 {
     array_unshift($links, '<a class="edit" href="admin.php?page=w3tc_general">Settings</a>');
     array_unshift($links, '<a class="delete" href="admin.php?page=w3tc_support">Premium Support</a>');
     if (!is_writable(WP_CONTENT_DIR) || !is_writable(Util_Rule::get_browsercache_rules_cache_path())) {
         $delete_link = '<a href="' . wp_nonce_url(admin_url('plugins.php?action=w3tc_deactivate_plugin'), 'w3tc') . '">Uninstall</a>';
         array_unshift($links, $delete_link);
     }
     return $links;
 }
checked($browsercache_nocookies, true);
?>
 /> <?php 
_e("Don't set cookies for static files", 'w3-total-cache');
?>
</label>
                    <br /><span class="description"><?php 
_e('Removes Set-Cookie header for responses.');
?>
</span>
                </th>
            </tr>
            <tr>
                <th colspan="2">
                    <?php 
$this->checkbox('browsercache.no404wp', !Util_Rule::can_check_rules());
?>
 <?php 
Util_Ui::e_config_label('browsercache.no404wp');
?>
</label>
                    <br /><span class="description"><?php 
_e('Reduce server load by allowing the web server to handle 404 (not found) errors for static files (images etc).', 'w3-total-cache');
?>
</span>
                    <br /><span class="description"><?php 
_e('If enabled - you may get 404 File Not Found response for some files generated on-the-fly by WordPress plugins. You may add those file URIs to 404 error exception list below to avoid that.', 'w3-total-cache');
?>
</span>
                </th>
            </tr>
Exemplo n.º 8
0
    </p>
</form>

<form id="minify_form" action="admin.php?page=<?php 
echo $this->_page;
?>
" method="post">
    <div class="metabox-holder">
        <?php 
Util_Ui::postbox_header(__('General', 'w3-total-cache'), '', 'general');
?>
        <table class="form-table">
            <tr>
                <th colspan="2">
                    <?php 
$this->checkbox('minify.rewrite', $minify_rewrite_disabled, '', true, !Util_Rule::can_check_rules() ? false : null);
?>
 <?php 
Util_Ui::e_config_label('minify.rewrite');
?>
</label><br />
                    <span class="description"><?php 
_e('If disabled, <acronym title="Cascading Style Sheet">CSS</acronym> and <acronym title="JavaScript">JS</acronym> embeddings will use GET variables instead of "fancy" links.', 'w3-total-cache');
?>
</span>
                </th>
            </tr>
            <tr>
                <th colspan="2">
                    <?php 
$this->checkbox('minify.reject.logged');
Exemplo n.º 9
0
 public function w3tc_errors($errors)
 {
     $state = Dispatcher::config_state();
     $c = Dispatcher::config();
     /**
      * Check permalinks
      */
     if (!$state->get_boolean('common.hide_note_no_permalink_rules') && ($c->get_boolean('pgcache.enabled') && $c->get_string('pgcache.engine') == 'file_generic' || $c->get_boolean('browsercache.enabled') && $c->get_boolean('browsercache.no404wp')) && !Util_Rule::is_permalink_rules()) {
         $errors['generic_no_permalinks'] = sprintf(__('The required directives for fancy permalinks could not be detected, please confirm they are available: <a href="http://codex.wordpress.org/Using_Permalinks#Creating_and_editing_.28.htaccess.29">Creating and editing</a> %s', 'w3-total-cache'), Util_Ui::button_hide_note2(array('w3tc_default_config_state_master' => 'y', 'key' => 'common.hide_note_no_permalink_rules', 'value' => 'true')));
     }
     /**
      * Check memcached
      */
     if (isset($errors['memcache_not_responding.details'])) {
         $memcache_error = __('The following memcached servers are not responding or not running:</p><ul>', 'w3-total-cache');
         foreach ($errors['memcache_not_responding.details'] as $memcaches_error) {
             $memcache_error .= '<li>' . $memcaches_error . '</li>';
         }
         $memcache_error .= __('</ul><p>This message will automatically disappear once the issue is resolved.', 'w3-total-cache');
         $errors['memcache_not_responding'] = $memcache_error;
         unset($errors['memcache_not_responding.details']);
     }
     return $errors;
 }
Exemplo n.º 10
0
    ?>
            <code><?php 
    _e('Not defined', 'w3-total-cache');
    ?>
</code>
            <?php 
}
?>
        </li>

        <li>
            <?php 
_e('URL rewrite:', 'w3-total-cache');
?>
            <?php 
if (Util_Rule::can_check_rules()) {
    ?>
            <code><?php 
    _e('Enabled', 'w3-total-cache');
    ?>
</code>
            <?php 
} else {
    ?>
            <code><?php 
    _e('Disabled', 'w3-total-cache');
    ?>
</code>
            <?php 
}
?>
 /**
  * Generate rules related to prevent for media 404 error by WP
  *
  * @param Config  $config
  * @return string
  */
 private function rules_no404wp_generate_apache($config)
 {
     $a = $this->get_mime_types();
     $cssjs_types = $a['cssjs'];
     $html_types = $a['html'];
     $other_types = $a['other'];
     $extensions = array_merge(array_keys($cssjs_types), array_keys($html_types), array_keys($other_types));
     $permalink_structure = get_option('permalink_structure');
     $permalink_structure_ext = ltrim(strrchr($permalink_structure, '.'), '.');
     if ($permalink_structure_ext != '') {
         foreach ($extensions as $index => $extension) {
             if (strstr($extension, $permalink_structure_ext) !== false) {
                 $extensions[$index] = preg_replace('~\\|?' . Util_Environment::preg_quote($permalink_structure_ext) . '\\|?~', '', $extension);
             }
         }
     }
     $exceptions = $config->get_array('browsercache.no404wp.exceptions');
     $wp_uri = network_home_url('', 'relative');
     $wp_uri = rtrim($wp_uri, '/');
     $rules = '';
     $rules .= W3TC_MARKER_BEGIN_BROWSERCACHE_NO404WP . "\n";
     $rules .= "<IfModule mod_rewrite.c>\n";
     $rules .= "    RewriteEngine On\n";
     // in subdir - rewrite theme files and similar to upper folder if file exists
     if (Util_Environment::is_wpmu() && !Util_Environment::is_wpmu_subdomain()) {
         $rules .= "    RewriteCond %{REQUEST_FILENAME} !-f\n";
         $rules .= "    RewriteCond %{REQUEST_FILENAME} !-d\n";
         $rules .= "    RewriteCond %{REQUEST_URI} ^{$wp_uri}/([_0-9a-zA-Z-]+/)(.*\\.)(" . implode('|', $extensions) . ")\$ [NC]\n";
         $document_root = Util_Rule::apache_docroot_variable();
         $rules .= '    RewriteCond "' . $document_root . $wp_uri . '/%2%3" -f' . "\n";
         $rules .= "    RewriteRule .* {$wp_uri}/%2%3 [L]\n\n";
     }
     $rules .= "    RewriteCond %{REQUEST_FILENAME} !-f\n";
     $rules .= "    RewriteCond %{REQUEST_FILENAME} !-d\n";
     $imploded = implode('|', $exceptions);
     if (!empty($imploded)) {
         $rules .= "    RewriteCond %{REQUEST_URI} !(" . $imploded . ")\n";
     }
     $rules .= "    RewriteCond %{REQUEST_URI} \\.(" . implode('|', $extensions) . ")\$ [NC]\n";
     $rules .= "    RewriteRule .* - [L]\n";
     $rules .= "</IfModule>\n";
     $rules .= W3TC_MARKER_END_BROWSERCACHE_NO404WP . "\n";
     return $rules;
 }
 /**
  * Checks if rules file present and creates it if not
  */
 function _check_rules_present()
 {
     if (Util_Environment::is_nginx()) {
         return;
     }
     // nginx store it in a single file
     $filename = Util_Rule::get_pgcache_rules_cache_path();
     if (file_exists($filename)) {
         return;
     }
     // we call it as little times as possible
     // its expensive, but have to restore lost .htaccess file
     $e = Dispatcher::component('PgCache_Environment');
     try {
         $e->fix_on_wpadmin_request($this->_config, true);
     } catch (\Exception $ex) {
     }
 }
 /**
  * Removes Page Cache core directives
  *
  * @param Util_Environment_Exceptions $exs
  * @throws Util_WpFile_FilesystemOperationException with S/FTP form if it can't get the required filesystem credentials
  */
 private static function rules_remove($exs)
 {
     Util_Rule::remove_rules($exs, Util_Rule::get_pgcache_rules_core_path(), W3TC_MARKER_BEGIN_FEEDBURNER, W3TC_MARKER_END_FEEDBURNER);
 }
Exemplo n.º 14
0
 /**
  * Send support request action
  *
  * @return void
  */
 function w3tc_support_send_details()
 {
     $c = Dispatcher::config();
     $post = array();
     foreach ($_GET as $p => $v) {
         $post[$p] = $v;
     }
     $post['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
     $post['version'] = W3TC_VERSION;
     $license_level = 'community';
     if (Util_Environment::is_w3tc_pro($c)) {
         $license_level = 'pro';
     } elseif (Util_Environment::is_w3tc_enterprise($c)) {
         $license_level = 'enterprise';
     }
     $post['license_level'] = $license_level . ' ' . $c->get_string('plugin.license_key');
     /**
      * Add attachments
      */
     $attachments = array();
     $attach_files = array(Util_Environment::wp_config_path(), Util_Rule::get_pgcache_rules_core_path(), Util_Rule::get_pgcache_rules_cache_path(), Util_Rule::get_browsercache_rules_cache_path(), Util_Rule::get_browsercache_rules_no404wp_path(), Util_Rule::get_minify_rules_core_path(), Util_Rule::get_minify_rules_cache_path());
     /**
      * Attach config files
      */
     if ($handle = opendir(W3TC_CONFIG_DIR)) {
         while (($entry = @readdir($handle)) !== false) {
             if ($entry == '.' || $entry == '..' || $entry == 'index.html') {
                 continue;
             }
             $attach_file[] = W3TC_CONFIG_DIR . '/' . $entry;
         }
         closedir($handle);
     }
     foreach ($attach_files as $attach_file) {
         if ($attach_file && file_exists($attach_file) && !in_array($attach_file, $attachments)) {
             $attachments[] = array('filename' => basename($attach_file), 'content' => file_get_contents($attach_file));
         }
     }
     /**
      * Attach server info
      */
     $server_info = print_r($this->get_server_info(), true);
     $server_info = str_replace("\n", "\r\n", $server_info);
     $attachments[] = array('filename' => 'server_info.txt', 'content' => $server_info);
     /**
      * Attach phpinfo
      */
     ob_start();
     phpinfo();
     $php_info = ob_get_contents();
     ob_end_clean();
     $attachments[] = array('filename' => 'php_info.html', 'content' => $php_info);
     /**
      * Attach self-test
      */
     ob_start();
     $this->self_test();
     $self_test = ob_get_contents();
     ob_end_clean();
     $attachments[] = array('filename' => 'self_test.html', 'content' => $self_test);
     $post['attachments'] = $attachments;
     $response = wp_remote_post(W3TC_SUPPORT_REQUEST_URL, array('body' => $post, 'timeout' => $c->get_integer('timelimit.email_send')));
     if (!is_wp_error($response)) {
         $result = $response['response']['code'] == 200 && $response['body'] == 'ok';
     } else {
         $result = false;
     }
     echo $result ? 'ok' : 'error';
 }
Exemplo n.º 15
0
 /**
  * Exports min files to CDN
  *
  * @return array
  */
 function get_files_minify()
 {
     $files = array();
     if ($this->_config->get_boolean('minify.rewrite') && Util_Rule::can_check_rules() && (!$this->_config->get_boolean('minify.auto') || Cdn_Util::is_engine_mirror($this->_config->get_string('cdn.engine')))) {
         $minify = Dispatcher::component('Minify_Plugin');
         $document_root = Util_Environment::document_root();
         $minify_root = Util_Environment::cache_blog_dir('minify');
         $minify_path = ltrim(str_replace($document_root, '', $minify_root), '/');
         $urls = $minify->get_urls();
         // in WPMU + network admin (this code used for minify manual only)
         // common minify files are stored under context of main blog (i.e. 1)
         // but have urls of 0 blog, so download has to be used
         if ($this->_config->get_string('minify.engine') == 'file' && !(Util_Environment::is_wpmu() && is_network_admin())) {
             foreach ($urls as $url) {
                 Util_Http::get($url);
             }
             $files = Cdn_Util::search_files($minify_root, $minify_path, '*.css;*.js');
         } else {
             foreach ($urls as $url) {
                 $file = Util_Environment::normalize_file_minify($url);
                 $file = Util_Environment::translate_file($file);
                 if (!Util_Environment::is_url($file)) {
                     $file = $document_root . '/' . $file;
                     $file = ltrim(str_replace($minify_root, '', $file), '/');
                     $dir = dirname($file);
                     if ($dir) {
                         Util_File::mkdir($dir, 0777, $minify_root);
                     }
                     if (Util_Http::download($url, $minify_root . '/' . $file) !== false) {
                         $files[] = $minify_path . '/' . $file;
                     }
                 }
             }
         }
     }
     return $files;
 }
Exemplo n.º 16
0
 /**
  * Deletes Browser Cache .htaccess from FTP
  *
  * @return void
  */
 public static function cdn_delete_browsercache()
 {
     $common = Dispatcher::component('Cdn_Core');
     $cdn_path = Util_Rule::get_cdn_rules_path();
     $tmp_path = W3TC_CACHE_TMP_DIR . '/' . $cdn_path;
     $results = array();
     $delete = array($common->build_file_descriptor($tmp_path, $cdn_path));
     $common->delete($delete, false, $results);
 }
Exemplo n.º 17
0
 /**
  * Removes Page Cache core directives
  *
  * @param Util_Environment_Exceptions $exs
  * @throws Util_WpFile_FilesystemOperationException with S/FTP form if it can't get the required filesystem credentials
  */
 private function rules_remove($exs)
 {
     Util_Rule::remove_rules($exs, Util_Rule::get_browsercache_rules_cache_path(), W3TC_MARKER_BEGIN_CDN, W3TC_MARKER_END_CDN);
 }
 /**
  * Returns path of pgcache cache rules file
  * Moved to separate file to not load rule.php for each disk enhanced request
  *
  * @return string
  */
 public static function get_pgcache_rules_cache_path()
 {
     switch (true) {
         case Util_Environment::is_apache():
         case Util_Environment::is_litespeed():
             if (Util_Environment::is_wpmu()) {
                 $url = get_home_url();
                 $match = null;
                 if (preg_match('~http(s)?://(.+?)(/)?$~', $url, $match)) {
                     $home_path = $match[2];
                     return W3TC_CACHE_PAGE_ENHANCED_DIR . '/' . $home_path . '/.htaccess';
                 }
             }
             return W3TC_CACHE_PAGE_ENHANCED_DIR . '/.htaccess';
         case Util_Environment::is_nginx():
             return Util_Rule::get_nginx_rules_path();
     }
     return false;
 }
 /**
  * Generates directives for file cache dir
  *
  * @param Config  $config
  * @return string
  */
 private function rules_cache_generate_nginx($config)
 {
     $cache_dir = Util_Rule::filename_to_uri(W3TC_CACHE_MINIFY_DIR);
     $browsercache = $config->get_boolean('browsercache.enabled');
     $compression = $browsercache && $config->get_boolean('browsercache.cssjs.compression');
     $expires = $browsercache && $config->get_boolean('browsercache.cssjs.expires');
     $lifetime = $browsercache ? $config->get_integer('browsercache.cssjs.lifetime') : 0;
     $cache_control = $browsercache && $config->get_boolean('browsercache.cssjs.cache.control');
     $w3tc = $browsercache && $config->get_integer('browsercache.cssjs.w3tc');
     $rules = '';
     $rules .= W3TC_MARKER_BEGIN_MINIFY_CACHE . "\n";
     $common_rules = '';
     if ($expires) {
         $common_rules .= "    expires modified " . $lifetime . "s;\n";
     }
     if ($w3tc) {
         $common_rules .= "    add_header X-Powered-By \"" . Util_Environment::w3tc_header($config) . "\";\n";
     }
     if ($compression) {
         $common_rules .= "    add_header Vary \"Accept-Encoding\";\n";
     }
     if ($cache_control) {
         $cache_policy = $config->get_string('browsercache.cssjs.cache.policy');
         switch ($cache_policy) {
             case 'cache':
                 $common_rules .= "    add_header Pragma \"public\";\n";
                 $common_rules .= "    add_header Cache-Control \"public\";\n";
                 break;
             case 'cache_public_maxage':
                 $common_rules .= "    add_header Pragma \"public\";\n";
                 $common_rules .= "    add_header Cache-Control \"max-age=" . $lifetime . ", public\";\n";
                 break;
             case 'cache_validation':
                 $common_rules .= "    add_header Pragma \"public\";\n";
                 $common_rules .= "    add_header Cache-Control \"public, must-revalidate, proxy-revalidate\";\n";
                 break;
             case 'cache_noproxy':
                 $common_rules .= "    add_header Pragma \"public\";\n";
                 $common_rules .= "    add_header Cache-Control \"private, must-revalidate\";\n";
                 break;
             case 'cache_maxage':
                 $common_rules .= "    add_header Pragma \"public\";\n";
                 $common_rules .= "    add_header Cache-Control \"max-age=" . $lifetime . ", public, must-revalidate, proxy-revalidate\";\n";
                 break;
             case 'no_cache':
                 $common_rules .= "    add_header Pragma \"no-cache\";\n";
                 $common_rules .= "    add_header Cache-Control \"max-age=0, private, no-store, no-cache, must-revalidate\";\n";
                 break;
         }
     }
     $rules .= "location ~ " . $cache_dir . ".*\\.js\$ {\n";
     $rules .= "    types {}\n";
     $rules .= "    default_type application/x-javascript;\n";
     $rules .= $common_rules;
     $rules .= "}\n";
     $rules .= "location ~ " . $cache_dir . ".*\\.css\$ {\n";
     $rules .= "    types {}\n";
     $rules .= "    default_type text/css;\n";
     $rules .= $common_rules;
     $rules .= "}\n";
     if ($compression) {
         $rules .= "location ~ " . $cache_dir . ".*js\\.gzip\$ {\n";
         $rules .= "    gzip off;\n";
         $rules .= "    types {}\n";
         $rules .= "    default_type application/x-javascript;\n";
         $rules .= $common_rules;
         $rules .= "    add_header Content-Encoding gzip;\n";
         $rules .= "}\n";
         $rules .= "location ~ " . $cache_dir . ".*css\\.gzip\$ {\n";
         $rules .= "    gzip off;\n";
         $rules .= "    types {}\n";
         $rules .= "    default_type text/css;\n";
         $rules .= $common_rules;
         $rules .= "    add_header Content-Encoding gzip;\n";
         $rules .= "}\n";
     }
     $rules .= W3TC_MARKER_END_MINIFY_CACHE . "\n";
     return $rules;
 }
 /**
  * Removes Page Cache cache directives
  *
  * @param Util_Environment_Exceptions $exs
  * @throws Util_WpFile_FilesystemOperationException with S/FTP form if it can't get the required filesystem credentials
  */
 private function rules_cache_remove($exs)
 {
     // apache's cache files are not used when core rules disabled
     if (!Util_Environment::is_nginx()) {
         return;
     }
     Util_Rule::remove_rules($exs, Util_Rule::get_pgcache_rules_cache_path(), W3TC_MARKER_BEGIN_PGCACHE_CACHE, W3TC_MARKER_END_PGCACHE_CACHE);
 }