aboutsummaryrefslogtreecommitdiffstats
path: root/admin
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2011-12-27 20:26:49 +0000
committerrvelices <rv-github@modusoptimus.com>2011-12-27 20:26:49 +0000
commite42f791f52c502c00d095d6bf9aa3e3989423e98 (patch)
tree965cbd888b954302e4652fefa7d56ef2e074eb66 /admin
parent753f58d6a966a1051dcd62a3eeab8fc18798bcac (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 '')
-rw-r--r--admin/include/functions.php79
-rw-r--r--admin/maintenance.php8
-rw-r--r--admin/rating.php2
-rw-r--r--admin/themes/default/template/maintenance.tpl1
4 files changed, 88 insertions, 2 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
diff --git a/admin/maintenance.php b/admin/maintenance.php
index 886739efc..65cb125fa 100644
--- a/admin/maintenance.php
+++ b/admin/maintenance.php
@@ -121,12 +121,17 @@ DELETE
pwg_query($query);
break;
}
- case 'compiled-templates' :
+ case 'compiled-templates':
{
$template->delete_compiled_templates();
FileCombiner::clear_combined_files();
break;
}
+ case 'derivatives':
+ {
+ clear_derivative_cache();
+ break;
+ }
default :
{
break;
@@ -154,6 +159,7 @@ $template->assign(
'U_MAINT_C13Y' => sprintf($url_format, 'c13y'),
'U_MAINT_SEARCH' => sprintf($url_format, 'search'),
'U_MAINT_COMPILED_TEMPLATES' => sprintf($url_format, 'compiled-templates'),
+ 'U_MAINT_DERIVATIVES' => sprintf($url_format, 'derivatives'),
'U_HELP' => get_root_url().'admin/popuphelp.php?page=maintenance',
)
);
diff --git a/admin/rating.php b/admin/rating.php
index 559d48523..91b0ab8da 100644
--- a/admin/rating.php
+++ b/admin/rating.php
@@ -172,7 +172,7 @@ $query = '
SELECT i.id,
i.path,
i.file,
- i.tn_ext,
+ i.representative_ext,
i.rating_score AS score,
MAX(r.date) AS recently_rated,
ROUND(AVG(r.rate),2) AS avg_rates,
diff --git a/admin/themes/default/template/maintenance.tpl b/admin/themes/default/template/maintenance.tpl
index 3b61eb0af..2c5f59713 100644
--- a/admin/themes/default/template/maintenance.tpl
+++ b/admin/themes/default/template/maintenance.tpl
@@ -29,4 +29,5 @@
<li><a href="{$U_MAINT_FEEDS}">{'Purge never used notification feeds'|@translate}</a></li>
<li><a href="{$U_MAINT_SEARCH}"onclick="return confirm('{'Purge search history'|@translate|@escape:'javascript'}');">{'Purge search history'|@translate}</a></li>
<li><a href="{$U_MAINT_COMPILED_TEMPLATES}">{'Purge compiled templates'|@translate}</a></li>
+ <li><a href="{$U_MAINT_DERIVATIVES}">{'Purge derivative image cache'|@translate}</a></li>
</ul>