diff options
author | rvelices <rv-github@modusoptimus.com> | 2011-12-27 20:26:49 +0000 |
---|---|---|
committer | rvelices <rv-github@modusoptimus.com> | 2011-12-27 20:26:49 +0000 |
commit | e42f791f52c502c00d095d6bf9aa3e3989423e98 (patch) | |
tree | 965cbd888b954302e4652fefa7d56ef2e074eb66 /admin/include/functions.php | |
parent | 753f58d6a966a1051dcd62a3eeab8fc18798bcac (diff) |
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
Diffstat (limited to 'admin/include/functions.php')
-rw-r--r-- | admin/include/functions.php | 79 |
1 files changed, 79 insertions, 0 deletions
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 |