aboutsummaryrefslogtreecommitdiffstats
path: root/admin/include/functions.php
diff options
context:
space:
mode:
authormistic100 <mistic@piwigo.org>2013-07-07 11:28:12 +0000
committermistic100 <mistic@piwigo.org>2013-07-07 11:28:12 +0000
commitd95425b9bba002fa2817a4e0fa61edf721c88c45 (patch)
treebbd91ca40665256adcf76fb85eacfe705701e8eb /admin/include/functions.php
parent718ef5a670ea0b69e946b182a812ad81e6772396 (diff)
bug:2898 make some updates methods static + factorize code from plugins, themes & languages
git-svn-id: http://piwigo.org/svn/trunk@23821 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'admin/include/functions.php')
-rw-r--r--admin/include/functions.php54
1 files changed, 54 insertions, 0 deletions
diff --git a/admin/include/functions.php b/admin/include/functions.php
index 2a6084f8d..3a81372a0 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -2527,4 +2527,58 @@ function get_dirs($directory)
}
return $sub_dirs;
}
+
+/**
+ * recursively delete a directory
+ * @param string $path
+ * @param string $trash_path, try to move the directory to this path if it cannot be delete
+ */
+function deltree($path, $trash_path=null)
+{
+ if (is_dir($path))
+ {
+ $fh = opendir($path);
+ while ($file = readdir($fh))
+ {
+ if ($file != '.' and $file != '..')
+ {
+ $pathfile = $path . '/' . $file;
+ if (is_dir($pathfile))
+ {
+ deltree($pathfile, $trash_path);
+ }
+ else
+ {
+ @unlink($pathfile);
+ }
+ }
+ }
+ closedir($fh);
+
+ if (@rmdir($path))
+ {
+ return true;
+ }
+ elseif (!empty($trash_path))
+ {
+ if (!is_dir($trash_path))
+ {
+ @mkgetdir($trash_path, MKGETDIR_RECURSIVE|MKGETDIR_DIE_ON_ERROR|MKGETDIR_PROTECT_HTACCESS);
+ }
+ while ($r = $trash_path . '/' . md5(uniqid(rand(), true)))
+ {
+ if (!is_dir($r))
+ {
+ @rename($path, $r);
+ break;
+ }
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+}
+
?> \ No newline at end of file