Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/182 #73

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9ce3be3
Auto-purge feeds (just getting started); see websharks/quick-cache#182
Aug 6, 2014
1ecaf51
Configuration feed purging event handlers. See websharks/quick-cache#182
Aug 7, 2014
4b13283
Reverse conditional logic for comment status transition testing. See …
Aug 8, 2014
418f0ab
Setup XML feed purging switch handler. See websharks/quick-cache#182
Aug 8, 2014
12f4abf
XML feed purging; static cache and blog/comments feed URLs. See websh…
Aug 8, 2014
06bd2d3
XML feed purging; additional feed URLs to purge. See websharks/quick-…
Aug 8, 2014
d318135
XML feed purging; term feed URLs to purge. See websharks/quick-cache#182
Aug 8, 2014
1cb807d
XML feed purging; dedupe feed URLs to purge. See websharks/quick-cach…
Aug 8, 2014
08c43f9
XML feed purging; cleanup/tweaks. See websharks/quick-cache#182
Aug 8, 2014
3350910
XML feed purging; wildcarded term feed links. See websharks/quick-cac…
Aug 8, 2014
acf3243
XML feed purging; refactor. See websharks/quick-cache#182
Aug 8, 2014
4bc84c5
XML feed purging; refactor. See websharks/quick-cache#182
Aug 8, 2014
4eab126
XML feed purging; check config flags. See websharks/quick-cache#182
Aug 8, 2014
364773a
XML feed purging; refactor variations. See websharks/quick-cache#182
Aug 9, 2014
14ccd1a
XML feed purging; ready for initial testing. See websharks/quick-cach…
Aug 9, 2014
a5ddd0e
XML feed purging; dashboard notices. See websharks/quick-cache#182
Aug 9, 2014
fbd9a5f
XML feed purging; regex improvements. See websharks/quick-cache#182
Aug 9, 2014
04b88a1
XML feed purging; split processing and UI option control. See webshar…
Aug 9, 2014
c157873
XML feed purging; improve UI related to Feed Purging. See websharks/q…
Aug 9, 2014
71a158a
XML feed purging; type and refactoring. See websharks/quick-cache#182
Aug 9, 2014
b5c9d66
XML feed purging; query string variations, refactoring, and `build_ca…
Aug 10, 2014
3440217
XML feed purging; fix brackets related to `urlencode_deep()`. See web…
Aug 10, 2014
24df751
XML feed purging; update query string variations when running SEO-fri…
Aug 10, 2014
b946d49
XML feed purging; fix typos. See websharks/quick-cache#182
Aug 10, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion quick-cache-pro/includes/menu-pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ public function options()
echo ' <option value="0"'.selected($this->plugin->options['cache_purge_term_other_enable'], '0', FALSE).'>'.__('No, my site doesn\'t use any custom Terms and/or I don\'t have any custom Term archive views.', $this->plugin->text_domain).'</option>'."\n";
echo ' </select></p>'."\n";
echo ' <hr />'."\n";
echo ' <h3>'.__('Auto-Purge "RSS/RDF/ATOM Feeds" Too?', $this->plugin->text_domain).'</h3>'."\n";
echo ' <p>'.__('If you enable Feed Caching (below), this can be quite handy. If enabled, when you update a Post/Page, approve a Comment, or make other changes where Quick Cache can detect that certain types of Feeds should be purged to keep your site up-to-date, then Quick Cache will do this for you automatically. For instance, the blog\'s master feed, the blog\'s master comments feed, feeds associated with comments on a Post/Page, term-related feeds (including mixed term-related feeds), author-related feeds, etc. Under various circumstances (i.e. as you work in the Dashboard) these can be purged automatically to keep your site up-to-date.', $this->plugin->text_domain).'</p>'."\n";
echo ' <p><select name="'.esc_attr(__NAMESPACE__).'[save_options][cache_purge_xml_feeds_enable]">'."\n";
echo ' <option value="1"'.selected($this->plugin->options['cache_purge_xml_feeds_enable'], '1', FALSE).'>'.__('Yes, automatically purge RSS/RDF/ATOM Feeds from the cache when certain changes occur.', $this->plugin->text_domain).'</option>'."\n";
echo ' <option value="0"'.selected($this->plugin->options['cache_purge_xml_feeds_enable'], '0', FALSE).'>'.__('No, I don\'t have Feed Caching enabled, or I prefer not to automatically purge Feeds.', $this->plugin->text_domain).'</option>'."\n";
echo ' </select></p>'."\n";
echo ' <hr />'."\n";
echo ' <h3>'.__('Auto-Purge "XML Sitemaps" Too?', $this->plugin->text_domain).'</h3>'."\n";
echo ' <p>'.__('If you\'re generating XML Sitemaps with a plugin like <a href="http://wordpress.org/plugins/google-sitemap-generator/" target="_blank">Google XML Sitemaps</a>, you can tell Quick Cache to automatically purge the cache of any XML Sitemaps whenever it purges a Post/Page. Note; this does NOT purge the XML Sitemap itself of course, only the cache. The point being, to clear the cache and allow changes to a Post/Page to be reflected by a fresh copy of your XML Sitemap; sooner rather than later.', $this->plugin->text_domain).'</p>'."\n";
echo ' <p><select name="'.esc_attr(__NAMESPACE__).'[save_options][cache_purge_xml_sitemaps_enable]">'."\n";
Expand Down Expand Up @@ -354,7 +361,7 @@ public function options()
echo ' <div class="plugin-menu-page-panel-body clearfix">'."\n";
echo ' <i class="fa fa-question-circle fa-4x" style="float:right; margin: 0 0 0 25px;"></i>'."\n";
echo ' <h3>'.__('Caching Enabled for RSS, RDF, Atom Feeds?', $this->plugin->text_domain).'</h3>'."\n";
echo ' <p>'.__('This should almost ALWAYS be set to <code>No</code>. UNLESS, you\'re sure that you want to cache your feeds. If you use a web feed management provider like Google® Feedburner and you set this option to <code>Yes</code>, you may experience delays in the detection of new posts.', $this->plugin->text_domain).'</p>'."\n";
echo ' <p>'.__('This should almost ALWAYS be set to <code>No</code>. UNLESS, you\'re sure that you want to cache your feeds. If you use a web feed management provider like Google® Feedburner and you set this option to <code>Yes</code>, you may experience delays in the detection of new posts. <strong>NOTE:</strong> If you do enable this, it is highly recommended that you also enable automatic Feed Purging too. Please see the section above: "Clearing the Cache". Find the sub-section titled: "Auto-Purge RSS/RDF/ATOM Feeds".', $this->plugin->text_domain).'</p>'."\n";
echo ' <p><select name="'.esc_attr(__NAMESPACE__).'[save_options][feeds_enable]">'."\n";
echo ' <option value="0"'.selected($this->plugin->options['feeds_enable'], '0', FALSE).'>'.__('No, do NOT cache (or serve a cache file) when displaying a feed.', $this->plugin->text_domain).'</option>'."\n";
echo ' <option value="1"'.selected($this->plugin->options['feeds_enable'], '1', FALSE).'>'.__('Yes, I would like to cache feed URLs.', $this->plugin->text_domain).'</option>'."\n";
Expand Down
99 changes: 99 additions & 0 deletions quick-cache-pro/includes/share.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ public function build_cache_path($url, $with_user_token = '', $with_version_salt
if($url && strpos($url, '://') === FALSE)
$url = '//'.ltrim($url, '/');

if($url && strpos($url, '&amp;') !== FALSE)
$url = str_replace('&amp;', '&', $url);

if(!$url || !($url = parse_url($url)))
return ''; // Invalid URL.

Expand Down Expand Up @@ -902,6 +905,42 @@ public function esc_sq($string, $times = 1)
return str_replace("'", str_repeat('\\', abs($times))."'", (string)$string);
}

/**
* Normalizes directory/file separators.
*
* @since 14xxxx Implementing XML/RSS feed purging.
*
* @param string $dir_file Directory/file path.
*
* @param boolean $allow_trailing_slash Defaults to FALSE.
* If TRUE; and `$dir_file` contains a trailing slash; we'll leave it there.
*
* @return string Normalized directory/file path.
*/
public function n_dir_seps($dir_file, $allow_trailing_slash = FALSE)
{
$dir_file = (string)$dir_file; // Force string value.
if(!isset($dir_file[0])) return ''; // Catch empty string.

if(strpos($dir_file, '://' !== FALSE)) // A possible stream wrapper?
{
if(preg_match('/^(?P<stream_wrapper>[a-zA-Z0-9]+)\:\/\//', $dir_file, $stream_wrapper))
$dir_file = preg_replace('/^(?P<stream_wrapper>[a-zA-Z0-9]+)\:\/\//', '', $dir_file);
}
if(strpos($dir_file, ':' !== FALSE)) // Might have a Windows® drive letter?
{
if(preg_match('/^(?P<drive_letter>[a-zA-Z])\:[\/\\\\]/', $dir_file)) // It has a Windows® drive letter?
$dir_file = preg_replace_callback('/^(?P<drive_letter>[a-zA-Z])\:[\/\\\\]/', create_function('$m', 'return strtoupper($m[0]);'), $dir_file);
}
$dir_file = preg_replace('/\/+/', '/', str_replace(array(DIRECTORY_SEPARATOR, '\\', '/'), '/', $dir_file));
$dir_file = ($allow_trailing_slash) ? $dir_file : rtrim($dir_file, '/'); // Strip trailing slashes.

if(!empty($stream_wrapper[0])) // Stream wrapper (force lowercase).
$dir_file = strtolower($stream_wrapper[0]).$dir_file;

return $dir_file; // Normalized now.
}

/**
* Recursive directory iterator based on a regex pattern.
*
Expand All @@ -922,6 +961,66 @@ public function dir_regex_iteration($dir, $regex)
return $regex_iterator;
}

/**
* Deletes files from the cache directory (for the current host) that match a regex pattern.
*
* @since 14xxxx Implementing XML/RSS feed purging.
*
* @param string $regex A regex pattern; compares to each full file path.
*
* @return integer Total files deleted by this routine (if any).
*
* @throws \exception If unable to delete a file for any reason.
*
* @TODO @raamdev I think we could take the same concept introduced by this routine and use it to build others
* that deal with purging/clearing/wiping; thereby centralizing this sort of job, making QC DRYer.
* Also, this type of routine works to improve speed when running on a large MS network.
*
* Suggested class members to come in a future release of QC.
* - `purge_files_from_host_cache_dir()`
* - `clear_files_from_host_cache_dir()`
*
* Also, this class member (i.e. `delete_files_from_host_cache_dir()`) could be
* used by many of the existing auto-purge routines. Thereby requiring less code
* and speeding QC up overall; i.e. making it faster on large MS networks.
*/
public function delete_files_from_host_cache_dir($regex)
{
$counter = 0; // Initialize.

if(!($regex = (string)$regex))
return $counter; // Nothing to do.

if(!is_dir($cache_dir = $this->cache_dir()))
return $counter; // Nothing to do.

$host = $_SERVER['HTTP_HOST'];
$host_base_dir_tokens = $this->host_base_dir_tokens();
$cache_dir = $this->n_dir_seps($cache_dir);

foreach(array('http', 'https') as $_host_scheme) // Consider all possible schemes.
{
$_host_url = $_host_scheme.'://'.$host.$host_base_dir_tokens; // Base URL for this host (w/ MS support).
$_host_cache_path = $this->build_cache_path($_host_url, '', '', $this::CACHE_PATH_NO_PATH_INDEX | $this::CACHE_PATH_NO_QUV | $this::CACHE_PATH_NO_EXT);
$_host_cache_dir = $this->n_dir_seps($cache_dir.'/'.$_host_cache_path);

/** @var $_dir_file \RecursiveDirectoryIterator For IDEs. */
if($_host_cache_dir && is_dir($_host_cache_dir)) foreach($this->dir_regex_iteration($_host_cache_dir, $regex) as $_dir_file)
{
if(($_dir_file->isFile() || $_dir_file->isLink()) && ($_host_cache_dir !== $cache_dir || strpos($_dir_file->getSubpathname(), '/') !== FALSE))
// Don't delete files in the immediate directory; e.g. `qc-advanced-cache` or `.htaccess`, etc.
// Actual `http|https/...` cache files are nested. Files in the immediate directory are for other purposes.
if(!unlink($_dir_file->getPathname())) // Throw exception if unable to delete.
throw new \exception(sprintf(__('Unable to delete file: `%1$s`.', $this->text_domain), $_dir_file->getPathname()));
else $counter++; // Increment counter for each file we purge.
}
unset($_dir_file); // Housekeeping.
}
unset($_host_scheme, $_host_url, $_host_cache_path, $_host_cache_dir); // Housekeeping.

return $counter; // Total files deleted by this routine.
}

/* --------------------------------------------------------------------------------------
* Hook/filter API for Quick Cache.
-------------------------------------------------------------------------------------- */
Expand Down
Loading