diff options
-rw-r--r-- | admin/include/functions.php | 54 | ||||
-rw-r--r-- | admin/include/languages.class.php | 63 | ||||
-rw-r--r-- | admin/include/plugins.class.php | 63 | ||||
-rw-r--r-- | admin/include/themes.class.php | 63 | ||||
-rw-r--r-- | admin/include/updates.class.php | 57 |
5 files changed, 68 insertions, 232 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 diff --git a/admin/include/languages.class.php b/admin/include/languages.class.php index 6a7262bb0..c024d881b 100644 --- a/admin/include/languages.class.php +++ b/admin/include/languages.class.php @@ -112,10 +112,7 @@ UPDATE '.USER_INFOS_TABLE.' ;'; pwg_query($query); - if (!$this->deltree(PHPWG_ROOT_PATH.'language/'.$language_id)) - { - $this->send_to_trash(PHPWG_ROOT_PATH.'language/'.$language_id); - } + deltree(PHPWG_ROOT_PATH.'language/'.$language_id, PHPWG_ROOT_PATH.'language/trash'); break; case 'set_default': @@ -381,10 +378,7 @@ UPDATE '.USER_INFOS_TABLE.' } elseif (is_dir($path)) { - if (!$this->deltree($path)) - { - $this->send_to_trash($path); - } + deltree($path, PHPWG_ROOT_PATH.'language/trash'); } } } @@ -406,59 +400,6 @@ UPDATE '.USER_INFOS_TABLE.' } /** - * delete $path directory - * @param string - path - */ - function deltree($path) - { - if (is_dir($path)) - { - $fh = opendir($path); - while ($file = readdir($fh)) - { - if ($file != '.' and $file != '..') - { - $pathfile = $path . '/' . $file; - if (is_dir($pathfile)) - { - $this->deltree($pathfile); - } - else - { - @unlink($pathfile); - } - } - } - closedir($fh); - return @rmdir($path); - } - } - - /** - * send $path to trash directory - * @param string - path - */ - function send_to_trash($path) - { - $trash_path = PHPWG_ROOT_PATH . 'language/trash'; - if (!is_dir($trash_path)) - { - @mkdir($trash_path); - $file = @fopen($trash_path . '/.htaccess', 'w'); - @fwrite($file, 'deny from all'); - @fclose($file); - } - while ($r = $trash_path . '/' . md5(uniqid(rand(), true))) - { - if (!is_dir($r)) - { - @rename($path, $r); - break; - } - } - } - - /** * Sort functions */ function language_version_compare($a, $b) diff --git a/admin/include/plugins.class.php b/admin/include/plugins.class.php index 3c0cb6ffa..36f47924b 100644 --- a/admin/include/plugins.class.php +++ b/admin/include/plugins.class.php @@ -166,10 +166,7 @@ DELETE FROM ' . PLUGINS_TABLE . ' WHERE id=\'' . $plugin_id . '\''; { break; } - if (!$this->deltree(PHPWG_PLUGINS_PATH . $plugin_id)) - { - $this->send_to_trash(PHPWG_PLUGINS_PATH . $plugin_id); - } + deltree(PHPWG_PLUGINS_PATH . $plugin_id, PHPWG_PLUGINS_PATH . 'trash'); break; } return $errors; @@ -514,10 +511,7 @@ DELETE FROM ' . PLUGINS_TABLE . ' WHERE id=\'' . $plugin_id . '\''; } elseif (is_dir($path)) { - if (!$this->deltree($path)) - { - $this->send_to_trash($path); - } + deltree($path, PHPWG_PLUGINS_PATH . 'trash'); } } } @@ -553,59 +547,6 @@ DELETE FROM ' . PLUGINS_TABLE . ' WHERE id=\'' . $plugin_id . '\''; } return $merged_extensions; } - - /** - * delete $path directory - * @param string - path - */ - function deltree($path) - { - if (is_dir($path)) - { - $fh = opendir($path); - while ($file = readdir($fh)) - { - if ($file != '.' and $file != '..') - { - $pathfile = $path . '/' . $file; - if (is_dir($pathfile)) - { - $this->deltree($pathfile); - } - else - { - @unlink($pathfile); - } - } - } - closedir($fh); - return @rmdir($path); - } - } - - /** - * send $path to trash directory - * @param string - path - */ - function send_to_trash($path) - { - $trash_path = PHPWG_PLUGINS_PATH . 'trash'; - if (!is_dir($trash_path)) - { - @mkdir($trash_path); - $file = @fopen($trash_path . '/.htaccess', 'w'); - @fwrite($file, 'deny from all'); - @fclose($file); - } - while ($r = $trash_path . '/' . md5(uniqid(rand(), true))) - { - if (!is_dir($r)) - { - @rename($path, $r); - break; - } - } - } /** * Sort functions diff --git a/admin/include/themes.class.php b/admin/include/themes.class.php index c639aed7d..dbc0d1c92 100644 --- a/admin/include/themes.class.php +++ b/admin/include/themes.class.php @@ -221,10 +221,7 @@ DELETE } } - if (!$this->deltree(PHPWG_THEMES_PATH.$theme_id)) - { - $this->send_to_trash(PHPWG_THEMES_PATH.$theme_id); - } + deltree(PHPWG_THEMES_PATH.$theme_id, PHPWG_THEMES_PATH . 'trash'); break; case 'set_default': @@ -641,10 +638,7 @@ SELECT } elseif (is_dir($path)) { - if (!$this->deltree($path)) - { - $this->send_to_trash($path); - } + deltree($path, PHPWG_THEMES_PATH . 'trash'); } } } @@ -664,59 +658,6 @@ SELECT } /** - * delete $path directory - * @param string - path - */ - function deltree($path) - { - if (is_dir($path)) - { - $fh = opendir($path); - while ($file = readdir($fh)) - { - if ($file != '.' and $file != '..') - { - $pathfile = $path . '/' . $file; - if (is_dir($pathfile)) - { - $this->deltree($pathfile); - } - else - { - @unlink($pathfile); - } - } - } - closedir($fh); - return @rmdir($path); - } - } - - /** - * send $path to trash directory - * @param string - path - */ - function send_to_trash($path) - { - $trash_path = PHPWG_THEMES_PATH . 'trash'; - if (!is_dir($trash_path)) - { - @mkdir($trash_path); - $file = @fopen($trash_path . '/.htaccess', 'w'); - @fwrite($file, 'deny from all'); - @fclose($file); - } - while ($r = $trash_path . '/' . md5(uniqid(rand(), true))) - { - if (!is_dir($r)) - { - @rename($path, $r); - break; - } - } - } - - /** * Sort functions */ function theme_version_compare($a, $b) diff --git a/admin/include/updates.class.php b/admin/include/updates.class.php index 0ec0e0c40..d25a75af7 100644 --- a/admin/include/updates.class.php +++ b/admin/include/updates.class.php @@ -33,7 +33,7 @@ class updates }
}
- function check_piwigo_upgrade()
+ static function check_piwigo_upgrade()
{
$_SESSION['need_update'] = null;
@@ -242,48 +242,7 @@ class updates return $this->$type->$version_compare($a, $b);
}
- function deltree($path, $move_to_trash=false)
- {
- if (is_dir($path))
- {
- $fh = opendir($path);
- while ($file = readdir($fh))
- {
- if ($file != '.' and $file != '..')
- {
- $pathfile = $path . '/' . $file;
- if (is_dir($pathfile))
- {
- self::deltree($pathfile, $move_to_trash);
- }
- else
- {
- @unlink($pathfile);
- }
- }
- }
- closedir($fh);
- if (@rmdir($path))
- {
- return true;
- }
- elseif ($move_to_trash)
- {
- $trash = PHPWG_ROOT_PATH.'_trash';
- if (!is_dir($trash))
- {
- @mkgetdir($trash);
- }
- return @rename($path, $trash . '/'.md5(uniqid(rand(), true)));
- }
- else
- {
- return false;
- }
- }
- }
-
- function process_obsolete_list($file)
+ static function process_obsolete_list($file)
{
if (file_exists(PHPWG_ROOT_PATH.$file)
and $old_files = file(PHPWG_ROOT_PATH.$file, FILE_IGNORE_NEW_LINES)
@@ -299,13 +258,13 @@ class updates }
elseif (is_dir($path))
{
- self::deltree($path, true);
+ deltree($path, PHPWG_ROOT_PATH.'_trash');
}
}
}
}
- function dump_database($include_history=false)
+ static function dump_database($include_history=false)
{
global $page, $conf, $cfgBase;
@@ -350,7 +309,7 @@ class updates }
@readfile($backupFile);
- self::deltree(PHPWG_ROOT_PATH.$conf['data_location'].'update');
+ deltree(PHPWG_ROOT_PATH.$conf['data_location'].'update');
exit();
}
else
@@ -359,7 +318,7 @@ class updates }
}
- function upgrade_to($upgrade_to, &$step, $check_current_version=true)
+ static function upgrade_to($upgrade_to, &$step, $check_current_version=true)
{
global $page, $conf, $template;
@@ -449,7 +408,7 @@ class updates if (empty($error))
{
self::process_obsolete_list($obsolete_list);
- self::deltree(PHPWG_ROOT_PATH.$conf['data_location'].'update');
+ deltree(PHPWG_ROOT_PATH.$conf['data_location'].'update');
invalidate_user_cache(true);
$template->delete_compiled_templates();
unset($_SESSION['need_update']);
@@ -477,7 +436,7 @@ class updates }
else
{
- self::deltree(PHPWG_ROOT_PATH.$conf['data_location'].'update');
+ deltree(PHPWG_ROOT_PATH.$conf['data_location'].'update');
array_push($page['errors'], l10n('An error has occured during upgrade.'));
}
}
|