Skip to content

Commit

Permalink
Add new UI Config panel for Host Exclusion Patterns; See: wpsharks/co…
Browse files Browse the repository at this point in the history
  • Loading branch information
kristineds committed May 15, 2016
1 parent fbff9f2 commit 266cdf5
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/includes/classes/MenuPageOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,28 @@ public function __construct()

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

if (is_multisite() && $this->plugin->applyWpFilters(GLOBAL_NS.'_exclude_hosts_option_enable', is_multisite())) {
// Display option panel for Host Exclusion Patterns.

echo ' <a href="#" class="plugin-menu-page-panel-heading">'."\n";
echo ' <i class="si si-ban"></i> '.__('Host Exclusion Patterns', SLUG_TD)."\n";
echo ' </a>'."\n";

echo ' <div class="plugin-menu-page-panel-body clearfix">'."\n";
echo ' <h3>'.__('Don\'t Cache These Special Host Exclusion Patterns?', SLUG_TD).'</h3>'."\n";
echo ' <p>'.__('Sometimes there are certain cases where a particular file, or a particular group of files, should never be cached. This is where you will enter those if you need to (one per line). Searches are performed against the <a href="https://gist.github.com/jaswsinc/338b6eb03a36c048c26f" target="_blank" style="text-decoration:none;"><code>HTTP_HOST</code></a>; i.e., <code>/path/?query</code> (caSe insensitive). So, don\'t put in full URLs here, just word fragments found in the file path (or query string) is all you need, excluding the http:// and domain name. A wildcard <code>*</code> character can also be used when necessary; e.g., <code>/category/abc-followed-by-*</code> (where <code>*</code> = 0 or more characters that are NOT a slash <code>/</code>). Other special characters include: <code>**</code> = 0 or more characters of any kind, including <code>/</code> slashes; <code>^</code> = beginning of the string; <code>$</code> = end of the string. To learn more about this syntax, please see <a href ="http://cometcache.com/r/watered-down-regex-syntax/" target="_blank">this KB article</a>.', SLUG_TD).'</p>'."\n";
echo ' <p><textarea name="'.esc_attr(GLOBAL_NS).'[saveOptions][exclude_hosts]" rows="5" spellcheck="false" class="monospace">'.format_to_edit($this->plugin->options['exclude_hosts']).'</textarea></p>'."\n";

echo ' <p class="info">'.__('<strong>Tip:</strong> let\'s use this example child site that uses a sub-domain: <code>http://www.child-blog.main.com</code>. To exclude this child site, you would put this line into the field above: <code>www.child-blog.main.com</code>. Or, you could also just put in a small fragment, like: <code>^child-blog.*$</code> and that would exclude any host containing that word fragment.', SLUG_TD).'</p>'."\n";
echo ' <p class="info">'.__('<strong>Note:</strong> please remember that your entries here should be formatted as a line-delimited list; e.g., one exclusion pattern per line.', SLUG_TD).'</p>'."\n";
echo ' </div>'."\n";
}
echo '</div>'."\n";

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

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

echo ' <a href="#" class="plugin-menu-page-panel-heading">'."\n";
echo ' <i class="si si-ban"></i> '.__('URI Exclusion Patterns', SLUG_TD)."\n";
echo ' </a>'."\n";
Expand Down
1 change: 1 addition & 0 deletions src/includes/classes/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ public function setup()

/* Related to exclusions. */

'exclude_hosts' => '', // Empty string or line-delimited patterns.
'exclude_uris' => '', // Empty string or line-delimited patterns.
'exclude_client_side_uris' => '', // Line-delimited list of URIs.
'exclude_refs' => '', // Empty string or line-delimited patterns.
Expand Down
9 changes: 9 additions & 0 deletions src/includes/interfaces/Shared/NcDebugConsts.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@ interface NcDebugConsts
*/
const NC_DEBUG_PREVIEW = 'nc_debug_preview';

/**
* No-cache because the current request is excluded by its host name.
*
* @since 16xxxx Host exclusions.
*
* @type string A unique string identifier in the set of `NC_DEBUG_` constants.
*/
const NC_DEBUG_EXCLUDED_HOSTS = 'nc_debug_excluded_hosts';

/**
* No-cache because the current request excluded by its URI.
*
Expand Down
10 changes: 10 additions & 0 deletions src/includes/templates/advanced-cache.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ if (!defined('COMET_CACHE_MAX_AGE_DISABLE_IF_LOAD_AVERAGE_IS_GTE')) {
define('COMET_CACHE_MAX_AGE_DISABLE_IF_LOAD_AVERAGE_IS_GTE', '%%COMET_CACHE_MAX_AGE_DISABLE_IF_LOAD_AVERAGE_IS_GTE%%');
}
/*[/pro]*/
if (!defined('COMET_CACHE_EXCLUDE_HOSTS')) {
/**
* Host exclusions.
*
* @since 16xxxx Adding host exclusions.
*
* @var string A regular expression; else an empty string.
*/
define('COMET_CACHE_EXCLUDE_HOSTS', '%%COMET_CACHE_EXCLUDE_HOSTS%%');
}
if (!defined('COMET_CACHE_EXCLUDE_URIS')) {
/**
* URI exclusions.
Expand Down
4 changes: 4 additions & 0 deletions src/includes/traits/Ac/NcDebugUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ public function maybeGetNcDebugInfo($reason_code = '', $reason = '')
$reason = __('because `$_REQUEST` indicates this is simply a preview of something to come.', SLUG_TD);
break; // Break switch handler.

case $this::NC_DEBUG_EXCLUDED_HOSTS:
$reason = __('because `$_SERVER[\'HTTP_HOST\']` matches a configured Host Exclusion Pattern on this installation.', SLUG_TD);
break; // Break switch handler.

case $this::NC_DEBUG_EXCLUDED_URIS:
$reason = __('because `$_SERVER[\'REQUEST_URI\']` matches a configured URI Exclusion Pattern on this installation.', SLUG_TD);
break; // Break switch handler.
Expand Down
3 changes: 3 additions & 0 deletions src/includes/traits/Ac/ObUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ public function maybeStartOutputBuffering()
if (!empty($_REQUEST['preview'])) {
return $this->maybeSetDebugInfo($this::NC_DEBUG_PREVIEW);
}
if (COMET_CACHE_EXCLUDE_HOSTS && preg_match(COMET_CACHE_EXCLUDE_HOSTS, $_SERVER['HTTP_HOST'])) {
return $this->maybeSetDebugInfo($this::NC_DEBUG_EXCLUDED_HOSTS);
}
if (COMET_CACHE_EXCLUDE_URIS && preg_match(COMET_CACHE_EXCLUDE_URIS, $_SERVER['REQUEST_URI'])) {
return $this->maybeSetDebugInfo($this::NC_DEBUG_EXCLUDED_URIS);
}
Expand Down
1 change: 1 addition & 0 deletions src/includes/traits/Plugin/InstallUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ public function addAdvancedCache()
$_value = (string) $_value; // Force string.

switch ($_option) {
case 'exclude_hosts': // Converts to regex (caSe insensitive).
case 'exclude_uris': // Converts to regex (caSe insensitive).
case 'exclude_client_side_uris': // Converts to regex (caSe insensitive).
case 'exclude_refs': // Converts to regex (caSe insensitive).
Expand Down

0 comments on commit 266cdf5

Please sign in to comment.