Skip to content

Commit

Permalink
Added Apache Optimization panel and features, edited Pro Features label
Browse files Browse the repository at this point in the history
  • Loading branch information
renzms committed Jun 21, 2016
1 parent 0e9c5f4 commit b0629bf
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 3,062 deletions.
3,040 changes: 1 addition & 3,039 deletions src/client-s/css/menu-pages.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/client-s/css/menu-pages.min.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/client-s/css/menu-pages/_panels.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
&::after {
font-variant: small-caps !important;
font-family: sans-serif !important;
content: 'additional pro version only features' !important;
content: 'additional pro features' !important;
margin-left: 15px;
background: #216095;
color: #FFFFFF;
Expand Down
74 changes: 53 additions & 21 deletions src/includes/classes/MenuPageOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -897,27 +897,6 @@ public function __construct()
}
/* ----------------------------------------------------------------------------------------- */

echo '<div class="plugin-menu-page-panel">'."\n";

echo ' <a href="#" class="plugin-menu-page-panel-heading">'."\n";
echo ' <i class="si si-file-archive-o"></i> '.__('GZIP Compression', SLUG_TD)."\n";
echo ' </a>'."\n";

echo ' <div class="plugin-menu-page-panel-body clearfix">'."\n";
echo ' <img src="'.esc_attr($this->plugin->url('/src/client-s/images/gzip.png')).'" class="screenshot" />'."\n";
echo ' <h3>'.__('<a href="https://developers.google.com/speed/articles/gzip" target="_blank">GZIP Compression</a> (Optional; Highly Recommended)', SLUG_TD).'</h3>'."\n";
echo ' <p>'.__('You don\'t have to use an <code>.htaccess</code> file to enjoy the performance enhancements provided by this plugin; caching is handled automatically by WordPress/PHP alone. That being said, if you want to take advantage of the additional speed enhancements associated w/ GZIP compression (and we do recommend this), then you WILL need an <code>.htaccess</code> file to accomplish that part.', SLUG_TD).'</p>'."\n";
echo ' <p>'.sprintf(__('%1$s fully supports GZIP compression on its output. However, it does not handle GZIP compression directly. We purposely left GZIP compression out of this plugin, because GZIP compression is something that should really be enabled at the Apache level or inside your <code>php.ini</code> file. GZIP compression can be used for things like JavaScript and CSS files as well, so why bother turning it on for only WordPress-generated pages when you can enable GZIP at the server level and cover all the bases!', SLUG_TD), esc_html(NAME)).'</p>'."\n";
echo ' <p>'.__('If you want to enable GZIP, create an <code>.htaccess</code> file in your WordPress® installation directory, and put the following few lines in it. Alternatively, if you already have an <code>.htaccess</code> file, just add these lines to it, and that is all there is to it. GZIP is now enabled in the recommended way! See also: <a href="https://developers.google.com/speed/articles/gzip" target="_blank"><i class="si si-youtube-play"></i> video about GZIP Compression</a>.', SLUG_TD).'</p>'."\n";
echo ' <pre class="code"><code>'.esc_html(file_get_contents(dirname(__DIR__).'/templates/gzip-htaccess.txt')).'</code></pre>'."\n";
echo ' <hr />'."\n";
echo ' <p class="info" style="display:block;"><strong>Or</strong>, if your server is missing <code>mod_deflate</code>/<code>mod_filter</code>; open your <strong>php.ini</strong> file and add this line: <a href="http://php.net/manual/en/zlib.configuration.php" target="_blank" style="text-decoration:none;"><code>zlib.output_compression = on</code></a></p>'."\n";
echo ' </div>'."\n";

echo '</div>'."\n";

/* ----------------------------------------------------------------------------------------- */

if (IS_PRO || $this->plugin->isProPreview()) {
echo '<div class="plugin-menu-page-panel'.(!IS_PRO ? ' pro-preview' : '').'">'."\n";

Expand Down Expand Up @@ -1018,6 +997,59 @@ public function __construct()
}
/* ----------------------------------------------------------------------------------------- */

echo '<div class="plugin-menu-page-panel'.(!IS_PRO && $this->plugin->isProPreview() ? ' pro-preview' : '').'">'."\n";

echo ' <a href="#" class="plugin-menu-page-panel-heading'.((!IS_PRO && $this->plugin->isProPreview()) ? ' pro-preview-additional-features' : '').'">'."\n";
echo ' <i class="si si-feat-server"></i> '.__('Apache Optimizations', SLUG_TD)."\n";
echo ' </a>'."\n";

echo ' <div class="plugin-menu-page-panel-body clearfix">'."\n";
echo ' <img src="'.esc_attr($this->plugin->url('/src/client-s/images/gzip.png')).'" class="screenshot" />'."\n";
echo ' <h3>'.__('<a href="https://developers.google.com/speed/articles/gzip" target="_blank">GZIP Compression</a> (Optional; Highly Recommended)', SLUG_TD).'</h3>'."\n";
echo ' <p>'.__('You don\'t have to use an <code>.htaccess</code> file to enjoy the performance enhancements provided by this plugin; caching is handled automatically by WordPress/PHP alone. That being said, if you want to take advantage of the additional speed enhancements associated w/ GZIP compression (and we do recommend this), then you WILL need an <code>.htaccess</code> file to accomplish that part.', SLUG_TD).'</p>'."\n";
echo ' <p>'.sprintf(__('%1$s fully supports GZIP compression on its output. However, it does not handle GZIP compression directly. We purposely left GZIP compression out of this plugin, because GZIP compression is something that should really be enabled at the Apache level or inside your <code>php.ini</code> file. GZIP compression can be used for things like JavaScript and CSS files as well, so why bother turning it on for only WordPress-generated pages when you can enable GZIP at the server level and cover all the bases!', SLUG_TD), esc_html(NAME)).'</p>'."\n";
echo ' <p>'.__('If you want to enable GZIP, create an <code>.htaccess</code> file in your WordPress® installation directory, and put the following few lines in it. Alternatively, if you already have an <code>.htaccess</code> file, just add these lines to it, and that is all there is to it. GZIP is now enabled in the recommended way! See also: <a href="https://developers.google.com/speed/articles/gzip" target="_blank"><i class="si si-youtube-play"></i> video about GZIP Compression</a>.', SLUG_TD).'</p>'."\n";
echo ' <pre class="code"><code>'.esc_html(file_get_contents(dirname(__DIR__).'/templates/gzip-htaccess.txt')).'</code></pre>'."\n";
echo ' <hr />'."\n";
echo ' <p class="info" style="display:block;"><strong>Or</strong>, if your server is missing <code>mod_deflate</code>/<code>mod_filter</code>; open your <strong>php.ini</strong> file and add this line: <a href="http://php.net/manual/en/zlib.configuration.php" target="_blank" style="text-decoration:none;"><code>zlib.output_compression = on</code></a></p>'."\n";

if (IS_PRO || $this->plugin->isProPreview()) {
echo ' <hr />'."\n";
echo ' <h3 class="'.(!IS_PRO ? 'pro-preview-feature' : '').'">'.__('Automatic GZIP Compression via <code>.htaccess</code>', SLUG_TD).'</h3>'."\n";
echo ' <p>'.__('Comet Cache will automatically add the appropriate code snippet to tweak the <code>.htaccess</code> file in your WordPress® installation directory. GZIP is now enabled in the recommended way! See also: <a href="https://developers.google.com/speed/articles/gzip" target="_blank"><i class="si si-youtube-play"></i> video about GZIP Compression</a>.', SLUG_TD).'</p>'."\n";
echo ' <p><select name="'.esc_attr(GLOBAL_NS).'[saveOptions][htaccess_gzip_enable]" data-target=".-htaccess-gzip-enable-options">'."\n";
echo ' <option value="0"'.(!IS_PRO ? '' : selected($this->plugin->options['htaccess_gzip_enable'], '0', false)).'>'.__('No, do NOT enable Automatic GZIP Compression via .htaccess.', SLUG_TD).'</option>'."\n";
echo ' <option value="1"'.(!IS_PRO ? '' : selected($this->plugin->options['htaccess_gzip_enable'], '1', false)).'>'.__('Yes, I want to enable Automatic GZIP Compression via .htaccess', SLUG_TD).'</option>'."\n";
echo ' </select></p>'."\n";
}

if (IS_PRO || $this->plugin->isProPreview()) {
echo ' <hr />'."\n";
echo ' <h3 class="'.(!IS_PRO ? 'pro-preview-feature' : '').'">'.__('Leverage browser caching via <code>.htaccess</code> and enable client side cache?', SLUG_TD).'</h3>'."\n";
echo ' <p>'.__('Comet Cache will add the appropriate code snippet to tweak the <code>.htaccess</code> file in your WordPress® installation directory to detect if any resources are set to be cached for a specific period of time or if the response from the server does not include caching headers.', SLUG_TD).'</p>'."\n";
echo ' <p><select name="'.esc_attr(GLOBAL_NS).'[saveOptions][htaccess_client_side_cache_enable]" data-target=".-htaccess-client-side-cache-enable-options">'."\n";
echo ' <option value="0"'.(!IS_PRO ? '' : selected($this->plugin->options['htaccess_client_side_cache_enable'], '0', false)).'>'.__('No, do NOT enable client side cache via .htaccess.', SLUG_TD).'</option>'."\n";
echo ' <option value="1"'.(!IS_PRO ? '' : selected($this->plugin->options['htaccess_client_side_cache_enable'], '1', false)).'>'.__('Yes, I want to enable client side cache via .htaccess', SLUG_TD).'</option>'."\n";
echo ' </select></p>'."\n";
echo ' <p class="info" style="display:block;">Using <code>ETags</code> will provide a revalidation token sent by the browser to verify if the resource has been updated since the last time it was requested. See this <a href="https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching#validating-cached-responses-with-etags" target="_blank">article</a> regarding validating cached responses with <code>ETags</code>.'."\n";
}

if (IS_PRO || $this->plugin->isProPreview()) {
echo ' <hr />'."\n";
echo ' <h3 class="'.(!IS_PRO ? 'pro-preview-feature' : '').'">'.__('Enable permalink structure via <code>.htaccess</code>?', SLUG_TD).'</h3>'."\n";
echo ' <p>'.__('Comet Cache will detect the permalink settings that either requires or does not require a trailing slash and add the appropriate code snippet to tweak the <code>.htaccess</code>file in your WordPress® installation directory. This will allow redirection from <code>example.com/test</code> to <code>example.com/test/</code> (with the slash). ', SLUG_TD).'</p>'."\n";
echo ' <p><select name="'.esc_attr(GLOBAL_NS).'[saveOptions][htaccess_permalink_structure_enable]" data-target=".-htaccess-permalink-structure-options">'."\n";
echo ' <option value="0"'.(!IS_PRO ? '' : selected($this->plugin->options['htaccess_permalink_structure_enable'], '0', false)).'>'.__('No, do NOT enable permalink structure via .htaccess.', SLUG_TD).'</option>'."\n";
echo ' <option value="1"'.(!IS_PRO ? '' : selected($this->plugin->options['htaccess_permalink_structure_enable'], '1', false)).'>'.__('Yes, I want to enable permalink structure via .htaccess', SLUG_TD).'</option>'."\n";
echo ' </select></p>'."\n";
echo ' <p class="info" style="display:block;">If you configure your Permalink structure with a trailing <code>/</code>, WordPress generates all permalinks that way. Moreover, by default, the <code>redirect_canonical()</code> function in WordPress enforces that behavior. The issue here is that <code>redirect_canonical()</code> is bypassed whenever caching is enabled; i.e., whenever Comet Cache is running.'."\n";
echo ' </div>'."\n";
}

echo '</div>'."\n";

/* ----------------------------------------------------------------------------------------- */

if (IS_PRO || $this->plugin->isProPreview()) {
echo '<div class="plugin-menu-page-panel'.(!IS_PRO ? ' pro-preview' : '').'">'."\n";

Expand Down
10 changes: 10 additions & 0 deletions src/includes/classes/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ public function setup()
'auto_cache_other_urls',
'auto_cache_user_agent',

'htaccess_client_side_cache_enable',
'htaccess_gzip_enable',
'htaccess_permalink_structure_enable',

'cdn_enable',
'cdn_host',
'cdn_hosts',
Expand Down Expand Up @@ -404,6 +408,12 @@ public function setup()
'auto_cache_other_urls' => '', // A line-delimited list of any other URLs.
'auto_cache_user_agent' => 'WordPress',

/* Related to .htaccess tweaks. */

'htaccess_client_side_cache_enable' => '0', // `0|1`; enable client-side caching via .htaccess?
'htaccess_gzip_enable' => '0', // `0|1`; enable GZIP via .htaccess?
'htaccess_permalink_structure_enable' => '0', // `0|1`; enable permalink structure via .htaccess?
/* Related to CDN functionality. */

'cdn_enable' => '0', // `0|1`; enable CDN filters?
Expand Down
8 changes: 8 additions & 0 deletions src/includes/templates/htaccess/client-side-cache-enable.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Client-side caching.

FileETag mtime size

<IfModule expires_module>
ExpiresActive on
ExpiresDefault "access plus 5 days"
</IfModule>
17 changes: 17 additions & 0 deletions src/includes/templates/htaccess/gzip-enable.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# GZIP compression.

<IfModule deflate_module>
<IfModule filter_module>
AddOutputFilterByType DEFLATE text/plain text/html
AddOutputFilterByType DEFLATE text/xml application/xml application/xhtml+xml application/xml-dtd
AddOutputFilterByType DEFLATE application/rdf+xml application/rss+xml application/atom+xml image/svg+xml
AddOutputFilterByType DEFLATE text/css text/javascript application/javascript application/x-javascript
AddOutputFilterByType DEFLATE font/opentype application/font-otf application/x-font-otf
AddOutputFilterByType DEFLATE font/truetype application/font-ttf application/x-font-ttf
<IfModule headers_module>
<FilesMatch \.(?:js|css|xml|svg|xhtml|html|txt|ttf|otf|gz)$>
Header append vary: accept-encoding
</FilesMatch>
</IfModule>
</IfModule>
</IfModule>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<IfModule rewrite_module>
RewriteEngine On
RewriteBase /

# If not a real file or directory.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Not a part of the WP admin area.
RewriteCond %{REQUEST_URI} !(?:^|/)wp\-admin(?:/|$)

# If there is a trailing slash.
RewriteCond %{REQUEST_URI} /$

# Force NO trailing slash on all virtual requests.
RewriteRule ^(.*)/$ /$1 [QSA,L,R=301]
</IfModule>
17 changes: 17 additions & 0 deletions src/includes/templates/htaccess/permalink-structure-ts-enable.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<IfModule rewrite_module>
RewriteEngine On
RewriteBase /

# If not a real file or directory.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Not a part of the WP admin area.
RewriteCond %{REQUEST_URI} !(?:^|/)wp\-admin(?:/|$)

# If there is no trailing slash.
RewriteCond %{REQUEST_URI} !/$

# Force a trailing slash on all virtual requests.
RewriteRule ^(.*)$ /$1/ [QSA,L,R=301]
</IfModule>
24 changes: 24 additions & 0 deletions src/includes/traits/Plugin/HtaccessUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,30 @@ public function addWpHtaccess()
$template_blocks .= trim(file_get_contents($templates_dir.'/'.$_template_file))."\n";
} // Only if CDN filters are enabled at this time.
break;

case 'client-side-cache-enable.txt':
if ($this->options['htaccess_client_side_cache_enable']) {
$template_blocks .= trim(file_get_contents($templates_dir.'/'.$_template_file))."\n";
} // Only if client-side caching is enabled via .htaccess at this time.
break;

case 'gzip-enable.txt':
if ($this->options['htaccess_gzip_enable']) {
$template_blocks .= trim(file_get_contents($templates_dir.'/'.$_template_file))."\n";
} // Only if GZIP is enabled via .htaccess at this time.
break;

case 'permalink-structure-ts-enable.txt':
if ($this->options['htaccess_permalink_structure_enable'] && $GLOBALS['wp_rewrite']->use_trailing_slashes) {
$template_blocks .= trim(file_get_contents($templates_dir.'/'.$_template_file))."\n";
} // Only if permalink structure is enabled via .htaccess at this time.
break;

case 'permalink-structure-no-ts-enable.txt':
if ($this->options['htaccess_permalink_structure_enable'] && !$GLOBALS['wp_rewrite']->use_trailing_slashes) {
$template_blocks .= trim(file_get_contents($templates_dir.'/'.$_template_file))."\n";
} // Only if permalink structure is enabled via .htaccess at this time.
break;
/*[/pro]*/
}
}
Expand Down

0 comments on commit b0629bf

Please sign in to comment.