Skip to content

Commit

Permalink
Merge branch 'release/150121'
Browse files Browse the repository at this point in the history
  • Loading branch information
raamdev committed Jan 30, 2015
2 parents b21e939 + 90e8e60 commit 2f6cbae
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 76 deletions.
2 changes: 1 addition & 1 deletion quick-cache/includes/menu-pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ public function options()
echo ' <option value="0">'.__('No, do NOT compress HTML/CSS/JS code at runtime.', $this->plugin->text_domain).'</option>'."\n";
echo ' <option value="1" selected="selected">'.__('Yes, I want to compress HTML/CSS/JS for blazing fast speeds.', $this->plugin->text_domain).'</option>'."\n";
echo ' </select></p>'."\n";
echo ' <p class="info" style="display:block;">'.__('<strong>Note:</strong> This is experimental. Please <a href="https://github.com/websharks/html-compressor/issues" target="_blank">report issues here</a>.', $this->plugin->text_domain).'</p>'."\n";
echo ' <p class="info" style="display:block;">'.__('<strong>Note:</strong> This is experimental. Please <a href="https://github.com/websharks/quick-cache/issues" target="_blank">report issues here</a>.', $this->plugin->text_domain).'</p>'."\n";
echo ' <hr />'."\n";
echo ' <div class="plugin-menu-page-panel-if-enabled">'."\n";
echo ' <h3>'.__('HTML Compression Options', $this->plugin->text_domain).'</h3>'."\n";
Expand Down
191 changes: 137 additions & 54 deletions quick-cache/includes/share.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ abstract class share // Shared between {@link advanced_cache} and {@link plugin}
*
* @var string Current version of the software.
*/
public $version = '141231';
public $version = '150129';

/**
* Plugin slug; based on `__NAMESPACE__`.
Expand Down Expand Up @@ -1532,32 +1532,63 @@ public function delete_files_from_cache_dir($regex, $check_max_age = FALSE)
if(!rename($cache_dir, $cache_dir_tmp)) // Work from tmp directory so deletions are atomic.
throw new \exception(sprintf(__('Unable to delete files. Rename failure on directory: `%1$s`.', $this->text_domain), $cache_dir));

/** @var $_file_dir \RecursiveDirectoryIterator Regex iterator reference for IDEs. */
foreach(($_dir_regex_iteration = $this->dir_regex_iteration($cache_dir_tmp, $cache_dir_tmp_regex)) as $_file_dir)
/** @var $_resource \RecursiveDirectoryIterator Regex iterator reference for IDEs. */
foreach(($_dir_regex_iteration = $this->dir_regex_iteration($cache_dir_tmp, $cache_dir_tmp_regex)) as $_resource)
{
if(($_file_dir->isFile() || $_file_dir->isLink()) // Files and/or symlinks only.
$_resource_type = $_resource->getType();
$_sub_path_name = $_resource->getSubpathname();
$_path_name = $_resource->getPathname();

// 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.
&& (strpos($_file_dir->getSubpathname(), '/') !== FALSE)
if($_resource_type !== 'dir' && strpos($_sub_path_name, '/') === FALSE)
continue; // Don't delete links/files in the immediate directory; e.g. `qc-advanced-cache` or `.htaccess`, etc.
// Actual `http|https/...` cache links/files are nested. Links/files in the immediate directory are for other purposes.

// If NOT checking max age; or if we ARE, and the file has expired now.
&& (!$check_max_age || (!empty($max_age) && $_file_dir->getMTime() < $max_age))

) // Throw an exception if a deletion failure occurs.
{
if(!unlink($_file_dir->getPathname())) // Throw exception if unable to delete.
throw new \exception(sprintf(__('Unable to delete file: `%1$s`.', $this->text_domain), $_file_dir->getPathname()));
$counter++; // Increment counter for each file we delete.
}
else if(!$check_max_age && $regex === '/^.+/i' && $_file_dir->isDir()) // Directories too?
switch($_resource_type) // Based on type; i.e. `link`, `file`, `dir`.
{
if(!rmdir($_file_dir->getPathname())) // Throw exception if unable to delete the directory itself.
throw new \exception(sprintf(__('Unable to delete dir: `%1$s`.', $this->text_domain), $_file_dir->getPathname()));
# $counter++; // Increment counter for each directory we delete. ~ NO don't do that here.
case 'link': // Symbolic links; i.e. 404 errors.

if($check_max_age && !empty($max_age) && is_file($_resource->getLinkTarget()))
if(($_lstat = lstat($_path_name)) && !empty($_lstat['mtime']))
if($_lstat['mtime'] >= $max_age) // Still valid?
break; // Break switch handler.

if(!unlink($_path_name)) // Throw exception if unable to delete.
throw new \exception(sprintf(__('Unable to delete symlink: `%1$s`.', $this->text_domain), $_path_name));
$counter++; // Increment counter for each link we delete.

break; // Break switch handler.

case 'file': // Regular files; i.e. not symlinks.

if($check_max_age && !empty($max_age)) // Should check max age?
if($_resource->getMTime() >= $max_age) // Still valid?
break; // Break switch handler.

if(!unlink($_path_name)) // Throw exception if unable to delete.
throw new \exception(sprintf(__('Unable to delete file: `%1$s`.', $this->text_domain), $_path_name));
$counter++; // Increment counter for each file we delete.

break; // Break switch handler.

case 'dir': // A regular directory; i.e. not a symlink.

if($regex !== '/^.+/i') // Deleting everything?
break; // Break switch handler. Not deleting everything.

if($check_max_age && !empty($max_age)) // Should check max age?
break; // Break switch handler. Not deleting everything in this case.

if(!rmdir($_path_name)) // Throw exception if unable to delete the directory itself.
throw new \exception(sprintf(__('Unable to delete dir: `%1$s`.', $this->text_domain), $_path_name));
# $counter++; // Increment counter for each directory we delete. ~ NO don't do that here.

break; // Break switch handler.

default: // Something else that is totally unexpected here.
throw new \exception(sprintf(__('Unexpected resource type: `%1$s`.', $this->text_domain), $_resource_type));
}
}
unset($_dir_regex_iteration, $_file_dir); // Housekeeping after this `foreach()` loop.
unset($_dir_regex_iteration, $_resource, $_resource_type, $_sub_path_name, $_path_name, $_lstat); // Housekeeping.

if(!rename($cache_dir_tmp, $cache_dir)) // Deletions are atomic; restore original directory now.
throw new \exception(sprintf(__('Unable to delete files. Rename failure on tmp directory: `%1$s`.', $this->text_domain), $cache_dir_tmp));
Expand Down Expand Up @@ -1663,31 +1694,62 @@ public function delete_files_from_host_cache_dir($regex, $check_max_age = FALSE)
throw new \exception(sprintf(__('Unable to delete files. Rename failure on tmp directory: `%1$s`.', $this->text_domain), $_host_cache_dir));

/** @var $_file_dir \RecursiveDirectoryIterator Regex iterator reference for IDEs. */
foreach(($_dir_regex_iteration = $this->dir_regex_iteration($_host_cache_dir_tmp, $_host_cache_dir_tmp_regex)) as $_file_dir)
foreach(($_dir_regex_iteration = $this->dir_regex_iteration($_host_cache_dir_tmp, $_host_cache_dir_tmp_regex)) as $_resource)
{
if(($_file_dir->isFile() || $_file_dir->isLink()) // Files and/or symlinks only.

// 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.
&& ($_host_cache_dir !== $cache_dir || strpos($_file_dir->getSubpathname(), '/') !== FALSE)
$_resource_type = $_resource->getType();
$_sub_path_name = $_resource->getSubpathname();
$_path_name = $_resource->getPathname();

// If NOT checking max age; or if we ARE, and the file has expired now.
&& (!$check_max_age || (!empty($max_age) && $_file_dir->getMTime() < $max_age))
if($_host_cache_dir === $cache_dir && $_resource_type !== 'dir' && strpos($_sub_path_name, '/') === FALSE)
continue; // Don't delete links/files in the immediate directory; e.g. `qc-advanced-cache` or `.htaccess`, etc.
// Actual `http|https/...` cache links/files are nested. Links/files in the immediate directory are for other purposes.

) // Throw an exception if a deletion failure occurs.
switch($_resource_type) // Based on type; i.e. `link`, `file`, `dir`.
{
if(!unlink($_file_dir->getPathname())) // Throw exception if unable to delete.
throw new \exception(sprintf(__('Unable to delete file: `%1$s`.', $this->text_domain), $_file_dir->getPathname()));
$counter++; // Increment counter for each file we delete.
}
else if(!$check_max_age && $regex === '/^.+/i' && $_file_dir->isDir()) // Directories too?
{
if(!rmdir($_file_dir->getPathname())) // Throw exception if unable to delete the directory itself.
throw new \exception(sprintf(__('Unable to delete dir: `%1$s`.', $this->text_domain), $_file_dir->getPathname()));
# $counter++; // Increment counter for each directory we delete. ~ NO don't do that here.
case 'link': // Symbolic links; i.e. 404 errors.

if($check_max_age && !empty($max_age) && is_file($_resource->getLinkTarget()))
if(($_lstat = lstat($_path_name)) && !empty($_lstat['mtime']))
if($_lstat['mtime'] >= $max_age) // Still valid?
break; // Break switch handler.

if(!unlink($_path_name)) // Throw exception if unable to delete.
throw new \exception(sprintf(__('Unable to delete symlink: `%1$s`.', $this->text_domain), $_path_name));
$counter++; // Increment counter for each link we delete.

break; // Break switch handler.

case 'file': // Regular files; i.e. not symlinks.

if($check_max_age && !empty($max_age)) // Should check max age?
if($_resource->getMTime() >= $max_age) // Still valid?
break; // Break switch handler.

if(!unlink($_path_name)) // Throw exception if unable to delete.
throw new \exception(sprintf(__('Unable to delete file: `%1$s`.', $this->text_domain), $_path_name));
$counter++; // Increment counter for each file we delete.

break; // Break switch handler.

case 'dir': // A regular directory; i.e. not a symlink.

if($regex !== '/^.+/i') // Deleting everything?
break; // Break switch handler. Not deleting everything.

if($check_max_age && !empty($max_age)) // Should check max age?
break; // Break switch handler. Not deleting everything in this case.

if(!rmdir($_path_name)) // Throw exception if unable to delete the directory itself.
throw new \exception(sprintf(__('Unable to delete dir: `%1$s`.', $this->text_domain), $_path_name));
# $counter++; // Increment counter for each directory we delete. ~ NO don't do that here.

break; // Break switch handler.

default: // Something else that is totally unexpected here.
throw new \exception(sprintf(__('Unexpected resource type: `%1$s`.', $this->text_domain), $_resource_type));
}
}
unset($_dir_regex_iteration, $_file_dir); // Housekeeping after this `foreach()` loop.
unset($_dir_regex_iteration, $_resource, $_resource_type, $_sub_path_name, $_path_name, $_lstat); // Housekeeping.

if(!rename($_host_cache_dir_tmp, $_host_cache_dir)) // Deletions are atomic; restore original directory now.
throw new \exception(sprintf(__('Unable to delete files. Rename failure on tmp directory: `%1$s`.', $this->text_domain), $_host_cache_dir_tmp));
Expand Down Expand Up @@ -1747,22 +1809,43 @@ public function delete_all_files_dirs_in($dir, $delete_dir_too = FALSE)
throw new \exception(sprintf(__('Unable to delete all files/dirs. Rename failure on tmp directory: `%1$s`.', $this->text_domain), $dir));

/** @var $_file_dir \RecursiveDirectoryIterator for IDEs. */
foreach(($_dir_regex_iteration = $this->dir_regex_iteration($dir_temp, '/.+/')) as $_file_dir)
foreach(($_dir_regex_iteration = $this->dir_regex_iteration($dir_temp, '/.+/')) as $_resource)
{
if(($_file_dir->isFile() || $_file_dir->isLink())) // Files and/or symlinks.
{
if(!unlink($_file_dir->getPathname())) // Throw exception if unable to delete.
throw new \exception(sprintf(__('Unable to delete file: `%1$s`.', $this->text_domain), $_file_dir->getPathname()));
$counter++; // Increment counter for each file we delete.
}
else if($_file_dir->isDir()) // Directories are last in the iteration; it should be empty now.
$_resource_type = $_resource->getType();
$_sub_path_name = $_resource->getSubpathname();
$_path_name = $_resource->getPathname();

switch($_resource_type) // Based on type; i.e. `link`, `file`, `dir`.
{
if(!rmdir($_file_dir->getPathname())) // Throw exception if unable to delete the directory itself.
throw new \exception(sprintf(__('Unable to delete dir: `%1$s`.', $this->text_domain), $_file_dir->getPathname()));
$counter++; // Increment counter for each directory we delete.
case 'link': // Symbolic links; i.e. 404 errors.

if(!unlink($_path_name)) // Throw exception if unable to delete.
throw new \exception(sprintf(__('Unable to delete symlink: `%1$s`.', $this->text_domain), $_path_name));
$counter++; // Increment counter for each link we delete.

break; // Break switch handler.

case 'file': // Regular files; i.e. not symlinks.

if(!unlink($_path_name)) // Throw exception if unable to delete.
throw new \exception(sprintf(__('Unable to delete file: `%1$s`.', $this->text_domain), $_path_name));
$counter++; // Increment counter for each file we delete.

break; // Break switch handler.

case 'dir': // A regular directory; i.e. not a symlink.

if(!rmdir($_path_name)) // Throw exception if unable to delete the directory itself.
throw new \exception(sprintf(__('Unable to delete dir: `%1$s`.', $this->text_domain), $_path_name));
$counter++; // Increment counter for each directory we delete.

break; // Break switch handler.

default: // Something else that is totally unexpected here.
throw new \exception(sprintf(__('Unexpected resource type: `%1$s`.', $this->text_domain), $_resource_type));
}
}
unset($_dir_regex_iteration, $_file_dir); // Housekeeping after this `foreach()` loop.
unset($_dir_regex_iteration, $_resource, $_resource_type, $_sub_path_name, $_path_name); // Housekeeping.

if(!rename($dir_temp, $dir)) // Deletions are atomic; restore original directory now.
throw new \exception(sprintf(__('Unable to delete all files/dirs. Rename failure on tmp directory: `%1$s`.', $this->text_domain), $dir_temp));
Expand Down Expand Up @@ -1802,7 +1885,7 @@ public function delete_all_files_dirs_in($dir, $delete_dir_too = FALSE)
public function cache_lock()
{
if($this->apply_filters(__CLASS__.'_disable_cache_locking', FALSE))
return false;
return FALSE;

if(!($wp_config_file = $this->find_wp_config_file()))
throw new \exception(__('Unable to find the wp-config.php file.', $this->text_domain));
Expand All @@ -1824,7 +1907,7 @@ public function cache_lock()
throw new \exception(__('No writable tmp directory.', $this->text_domain));

$inode_key = fileinode($wp_config_file);
$mutex = $tmp_dir.'/'.$this->slug.'-'.$inode_key.'.lock';
$mutex = $tmp_dir.'/'.$this->slug.'-'.$inode_key.'.lock';
if(!($resource = fopen($mutex, 'w')) || !flock($resource, LOCK_EX))
throw new \exception(__('Unable to obtain an exclusive lock.', $this->text_domain));

Expand Down
46 changes: 27 additions & 19 deletions quick-cache/includes/translations/quick-cache.pot
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Copyright (C) 2014 Quick Cache
# Copyright (C) 2015 Quick Cache
# This file is distributed under the same license as the Quick Cache package.
msgid ""
msgstr ""
"Project-Id-Version: Quick Cache 141231\n"
"Project-Id-Version: Quick Cache 150129\n"
"Report-Msgid-Bugs-To: http://wordpress.org/tag/quick-cache\n"
"POT-Creation-Date: 2014-12-31 22:32:49+00:00\n"
"POT-Creation-Date: 2015-01-30 01:26:09+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"PO-Revision-Date: 2014-MO-DA HO:MI+ZONE\n"
"PO-Revision-Date: 2015-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"

Expand Down Expand Up @@ -813,7 +813,7 @@ msgid "Yes, I want to compress HTML/CSS/JS for blazing fast speeds."
msgstr ""

#: includes/menu-pages.php:484
msgid "<strong>Note:</strong> This is experimental. Please <a href=\"https://github.com/websharks/html-compressor/issues\" target=\"_blank\">report issues here</a>."
msgid "<strong>Note:</strong> This is experimental. Please <a href=\"https://github.com/websharks/quick-cache/issues\" target=\"_blank\">report issues here</a>."
msgstr ""

#: includes/menu-pages.php:487
Expand Down Expand Up @@ -1036,65 +1036,73 @@ msgstr ""
msgid "Unable to determine cache directory location."
msgstr ""

#: includes/share.php:1507 includes/share.php:1618
#: includes/share.php:1507 includes/share.php:1649
msgid "The `options` property w/ a `cache_max_age` key is not defined in this class."
msgstr ""

#: includes/share.php:1533
msgid "Unable to delete files. Rename failure on directory: `%1$s`."
msgstr ""

#: includes/share.php:1550 includes/share.php:1680 includes/share.php:1755
#: includes/share.php:1556 includes/share.php:1717 includes/share.php:1823
msgid "Unable to delete symlink: `%1$s`."
msgstr ""

#: includes/share.php:1568 includes/share.php:1729 includes/share.php:1831
msgid "Unable to delete file: `%1$s`."
msgstr ""

#: includes/share.php:1556 includes/share.php:1686 includes/share.php:1761
#: includes/share.php:1582 includes/share.php:1743 includes/share.php:1839
msgid "Unable to delete dir: `%1$s`."
msgstr ""

#: includes/share.php:1563 includes/share.php:1663 includes/share.php:1693
#: includes/share.php:1588 includes/share.php:1749 includes/share.php:1845
msgid "Unexpected resource type: `%1$s`."
msgstr ""

#: includes/share.php:1594 includes/share.php:1694 includes/share.php:1755
msgid "Unable to delete files. Rename failure on tmp directory: `%1$s`."
msgstr ""

#: includes/share.php:1747 includes/share.php:1768
#: includes/share.php:1809 includes/share.php:1851
msgid "Unable to delete all files/dirs. Rename failure on tmp directory: `%1$s`."
msgstr ""

#: includes/share.php:1773
#: includes/share.php:1856
msgid "Unable to delete directory: `%1$s`."
msgstr ""

#: includes/share.php:1808
#: includes/share.php:1891
msgid "Unable to find the wp-config.php file."
msgstr ""

#: includes/share.php:1824
#: includes/share.php:1907
msgid "No writable tmp directory."
msgstr ""

#: includes/share.php:1829
#: includes/share.php:1912
msgid "Unable to obtain an exclusive lock."
msgstr ""

#: includes/share.php:1882
#: includes/share.php:1965
msgid "%1$s file"
msgid_plural "%1$s files"
msgstr[0] ""
msgstr[1] ""

#: includes/share.php:1898
#: includes/share.php:1981
msgid "%1$s directory"
msgid_plural "%1$s directories"
msgstr[0] ""
msgstr[1] ""

#: includes/share.php:1914
#: includes/share.php:1997
msgid "%1$s file/directory"
msgid_plural "%1$s files/directories"
msgstr[0] ""
msgstr[1] ""

#: includes/share.php:1947
#: includes/share.php:2030
msgid "Invalid hook."
msgstr ""

Expand Down Expand Up @@ -1142,7 +1150,7 @@ msgstr ""
msgid "<strong>Quick Cache:</strong> detected a new version of itself. Recompiling w/ latest version... wiping the cache... all done :-)"
msgstr ""

#. #-#-#-#-# quick-cache.pot (Quick Cache 141231) #-#-#-#-#
#. #-#-#-#-# quick-cache.pot (Quick Cache 150129) #-#-#-#-#
#. Plugin Name of the plugin/theme
#: quick-cache.inc.php:551 quick-cache.inc.php:567
msgid "Quick Cache"
Expand Down
2 changes: 1 addition & 1 deletion quick-cache/quick-cache.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
Version: 141231
Version: 150129
Text Domain: quick-cache
Plugin Name: Quick Cache
Network: true
Expand Down
Loading

0 comments on commit 2f6cbae

Please sign in to comment.