Index: /trunk/admin/include/functions.php
===================================================================
--- /trunk/admin/include/functions.php	(revision 23820)
+++ /trunk/admin/include/functions.php	(revision 23821)
@@ -2528,3 +2528,57 @@
   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;
+    }
+  }
+}
+
 ?>
Index: /trunk/admin/include/languages.class.php
===================================================================
--- /trunk/admin/include/languages.class.php	(revision 23820)
+++ /trunk/admin/include/languages.class.php	(revision 23821)
@@ -113,8 +113,5 @@
         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;
 
@@ -382,8 +379,5 @@
                     elseif (is_dir($path))
                     {
-                      if (!$this->deltree($path))
-                      {
-                        $this->send_to_trash($path);
-                      }
+                      deltree($path, PHPWG_ROOT_PATH.'language/trash');
                     }
                   }
@@ -407,57 +401,4 @@
 
   /**
-   * 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
    */
Index: /trunk/admin/include/plugins.class.php
===================================================================
--- /trunk/admin/include/plugins.class.php	(revision 23820)
+++ /trunk/admin/include/plugins.class.php	(revision 23821)
@@ -167,8 +167,5 @@
           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;
     }
@@ -515,8 +512,5 @@
                   elseif (is_dir($path))
                   {
-                    if (!$this->deltree($path))
-                    {
-                      $this->send_to_trash($path);
-                    }
+                    deltree($path, PHPWG_PLUGINS_PATH . 'trash');
                   }
                 }
@@ -554,57 +548,4 @@
     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;
-      }
-    }
-  }
 
   /**
Index: /trunk/admin/include/themes.class.php
===================================================================
--- /trunk/admin/include/themes.class.php	(revision 23820)
+++ /trunk/admin/include/themes.class.php	(revision 23821)
@@ -222,8 +222,5 @@
         }
 
-        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;
 
@@ -642,8 +639,5 @@
                   elseif (is_dir($path))
                   {
-                    if (!$this->deltree($path))
-                    {
-                      $this->send_to_trash($path);
-                    }
+                    deltree($path, PHPWG_THEMES_PATH . 'trash');
                   }
                 }
@@ -665,57 +659,4 @@
 
   /**
-   * 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
    */
Index: /trunk/admin/include/updates.class.php
===================================================================
--- /trunk/admin/include/updates.class.php	(revision 23820)
+++ /trunk/admin/include/updates.class.php	(revision 23821)
@@ -34,5 +34,5 @@
   }
 
-  function check_piwigo_upgrade()
+  static function check_piwigo_upgrade()
   {
     $_SESSION['need_update'] = null;
@@ -243,46 +243,5 @@
   }
 
-  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)
@@ -300,11 +259,11 @@
         elseif (is_dir($path))
         {
-          self::deltree($path, true);
-        }
-      }
-    }
-  }
-
-  function dump_database($include_history=false)
+          deltree($path, PHPWG_ROOT_PATH.'_trash');
+        }
+      }
+    }
+  }
+
+  static function dump_database($include_history=false)
   {
     global $page, $conf, $cfgBase;
@@ -351,5 +310,5 @@
 
       @readfile($backupFile);
-      self::deltree(PHPWG_ROOT_PATH.$conf['data_location'].'update');
+      deltree(PHPWG_ROOT_PATH.$conf['data_location'].'update');
       exit();
     }
@@ -360,5 +319,5 @@
   }
 
-  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;
@@ -450,5 +409,5 @@
           {
             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();
@@ -478,5 +437,5 @@
         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.'));
         }
