From e42f791f52c502c00d095d6bf9aa3e3989423e98 Mon Sep 17 00:00:00 2001 From: rvelices Date: Tue, 27 Dec 2011 20:26:49 +0000 Subject: feature 2541 multisize - nicer presentation on picture.php - added a maintenance purge derivatives action git-svn-id: http://piwigo.org/svn/trunk@12797 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/include/functions.php | 79 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 'admin/include') diff --git a/admin/include/functions.php b/admin/include/functions.php index 6acc7ab98..85ee0f4f2 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -2246,4 +2246,83 @@ SELECT return array_from_query($query, 'user_id'); } + +function clear_derivative_cache($type='all') +{ + $pattern='#.*-'; + if ($type == 'all') + { + $type_urls = array(); + foreach(ImageStdParams::get_all_types() as $dtype) + { + $type_urls[] = derivative_to_url($dtype); + } + $type_urls[] = derivative_to_url(IMG_CUSTOM); + $pattern .= '(' . implode('|',$type_urls) . ')'; + } + else + { + $pattern .= derivative_to_url($type); + } + $pattern.='(_[a-zA-Z0-9]+)*\.[a-zA-Z0-9]{3,4}$#'; + if ($contents = opendir(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR)) + { + while (($node = readdir($contents)) !== false) + { + if ($node != '.' + and $node != '..' + and is_dir(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR.$node)) + { + clear_derivative_cache_rec(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR.$node, $pattern); + } + } + closedir($contents); + } +} + +function clear_derivative_cache_rec($path, $pattern) +{ + $rmdir = true; + $rm_index = false; + + if ($contents = opendir($path)) + { + while (($node = readdir($contents)) !== false) + { + if ($node == '.' or $node == '..') + continue; + if (is_dir($path.'/'.$node)) + { + $rmdir &= clear_derivative_cache_rec($path.'/'.$node, $pattern); + } + else + { + if (preg_match($pattern, $node)) + { + unlink($path.'/'.$node); + } + elseif ($node=='index.htm') + { + $rm_index = true; + } + else + { + $rmdir = false; + } + } + } + closedir($contents); + + if ($rmdir) + { + if ($rm_index) + { + unlink($path.'/index.htm'); + } + clearstatcache(); + rmdir($path); + } + return $rmdir; + } +} ?> \ No newline at end of file -- cgit v1.2.3