Index: /extensions/autoupdate/autoupdate.php
===================================================================
--- /extensions/autoupdate/autoupdate.php	(revision 3575)
+++ /extensions/autoupdate/autoupdate.php	(revision 3575)
@@ -0,0 +1,87 @@
+<?php
+
+function autoupdate_deltree($path)
+{
+  if (is_dir($path))
+  {
+    $fh = opendir($path);
+    while ($file = readdir($fh))
+    {
+      if ($file != '.' and $file != '..')
+      {
+        $pathfile = $path . '/' . $file;
+        if (is_dir($pathfile))
+        {
+          deltree($pathfile);
+        }
+        else
+        {
+          @unlink($pathfile);
+        }
+      }
+    }
+    closedir($fh);
+    return @rmdir($path);
+  }
+}
+
+load_language('plugin.lang', dirname(__FILE__).'/');
+
+if (isset($_GET['autoupdate']))
+{
+  if ($_GET['autoupdate'] == 'success')
+  {
+    array_push($page['infos'], sprintf(l10n('autoupdate_success'), PHPWG_VERSION));
+  }
+  elseif ($file = $conf['local_data_dir'].'/autoupdate/'.$_GET['autoupdate'].'.zip' and file_exists($file))
+  {
+    include_once(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php');
+    $zip = new PclZip($file);
+    if ($result = $zip->extract(PCLZIP_OPT_PATH, PHPWG_ROOT_PATH, PCLZIP_OPT_REMOVE_PATH, $_GET['autoupdate'], PCLZIP_OPT_REPLACE_NEWER))
+    {
+      autoupdate_deltree($conf['local_data_dir'].'/autoupdate');
+      redirect('admin.php?autoupdate=success');
+    }
+    else
+    {
+      autoupdate_deltree($conf['local_data_dir'].'/autoupdate');
+      array_push($page['errors'], l10n('autoupdate_fail'));
+    }
+  }
+  else
+  {
+    array_push($page['errors'], l10n('autoupdate_fail'));
+  }
+}
+elseif (preg_match('/\d+\.\d+\.\d+/', PHPWG_VERSION) and fetchRemote(PHPWG_URL.'/download/latest_version', $result))
+{
+  $lines = @explode("\r\n", $result);
+  $new_version = trim($lines[1]);
+  $new_branch = substr($new_version, 0, 3);
+  $actual_branch = substr(PHPWG_VERSION, 0, 3);
+  $actual_version = $actual_branch . '.x';
+
+  if (version_compare(PHPWG_VERSION, $new_version) < 0
+    and $actual_branch == $new_branch)
+  {
+    $path = $conf['local_data_dir'].'/autoupdate/';
+    $filename = $path.$actual_version.'_to_'.$new_version.'.zip';
+    mkgetdir($path);
+
+    if (!file_exists($filename) or !filesize($filename))
+    {
+      $zip = @fopen($filename, 'w+');
+      @fetchRemote(PHPWG_URL.'/download/dlcounter.php?code='.str_replace('.', '', $actual_version).'to'.str_replace('.', '', $new_version), $zip);
+      @fclose($zip);
+    }
+
+    if (file_exists($filename) and filesize($filename))
+    {
+      array_push($header_notes,
+        l10n('A new version of Piwigo is available.').'<br>',
+        '<a href="admin.php?autoupdate='.$actual_version.'_to_'.$new_version.'" onClick="return confirm(\''.l10n('autoupdate_alert').'\');">'.l10n('Click here to upgrade automatically').'</a>'
+      );
+    }
+  }
+}
+?>
Index: /extensions/autoupdate/index.php
===================================================================
--- /extensions/autoupdate/index.php	(revision 3575)
+++ /extensions/autoupdate/index.php	(revision 3575)
@@ -0,0 +1,33 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | PhpWebGallery - a PHP based picture gallery                           |
+// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
+// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
+// +-----------------------------------------------------------------------+
+// | file          : $Id: index.php 1912 2007-03-16 06:30:07Z rub $
+// | last update   : $Date: 2007-03-16 07:30:07 +0100 (ven, 16 mar 2007) $
+// | last modifier : $Author: rub $
+// | revision      : $Revision: 1912 $
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/autoupdate/language/en_UK/index.php
===================================================================
--- /extensions/autoupdate/language/en_UK/index.php	(revision 3575)
+++ /extensions/autoupdate/language/en_UK/index.php	(revision 3575)
@@ -0,0 +1,33 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | PhpWebGallery - a PHP based picture gallery                           |
+// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
+// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
+// +-----------------------------------------------------------------------+
+// | file          : $Id: index.php 1912 2007-03-16 06:30:07Z rub $
+// | last update   : $Date: 2007-03-16 07:30:07 +0100 (ven, 16 mar 2007) $
+// | last modifier : $Author: rub $
+// | revision      : $Revision: 1912 $
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/autoupdate/language/en_UK/plugin.lang.php
===================================================================
--- /extensions/autoupdate/language/en_UK/plugin.lang.php	(revision 3575)
+++ /extensions/autoupdate/language/en_UK/plugin.lang.php	(revision 3575)
@@ -0,0 +1,8 @@
+<?php
+
+$lang['Click here to upgrade automatically'] = 'Click here to upgrade automatically';
+$lang['autoupdate_alert'] = 'Are you sure you want to autmatically upgrade piwigo?\nWarning!!! Files manually modified could be overwritten.';
+$lang['autoupdate_success'] = 'Piwigo has been successfully upgraded (version %s)';
+$lang['autoupdate_fail'] = 'An error occured during upgrade.';
+
+?>
Index: /extensions/autoupdate/language/fr_FR/index.php
===================================================================
--- /extensions/autoupdate/language/fr_FR/index.php	(revision 3575)
+++ /extensions/autoupdate/language/fr_FR/index.php	(revision 3575)
@@ -0,0 +1,33 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | PhpWebGallery - a PHP based picture gallery                           |
+// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
+// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
+// +-----------------------------------------------------------------------+
+// | file          : $Id: index.php 1912 2007-03-16 06:30:07Z rub $
+// | last update   : $Date: 2007-03-16 07:30:07 +0100 (ven, 16 mar 2007) $
+// | last modifier : $Author: rub $
+// | revision      : $Revision: 1912 $
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/autoupdate/language/fr_FR/plugin.lang.php
===================================================================
--- /extensions/autoupdate/language/fr_FR/plugin.lang.php	(revision 3575)
+++ /extensions/autoupdate/language/fr_FR/plugin.lang.php	(revision 3575)
@@ -0,0 +1,8 @@
+<?php
+
+$lang['Click here to upgrade automatically'] = 'Cliquez ici pour une mise à jour automatique';
+$lang['autoupdate_alert'] = 'Etes-vous sûr de vouloir mettre à jour piwigo automatiquement?\nAttention!!! Les fichiers modifiés manuellement pourront être écrasés.';
+$lang['autoupdate_success'] = 'Piwigo a été mis à jour avec succès (version %s)';
+$lang['autoupdate_fail'] = 'Une erreur est survenue pendant la mise à jour.';
+
+?>
Index: /extensions/autoupdate/language/index.php
===================================================================
--- /extensions/autoupdate/language/index.php	(revision 3575)
+++ /extensions/autoupdate/language/index.php	(revision 3575)
@@ -0,0 +1,33 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | PhpWebGallery - a PHP based picture gallery                           |
+// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
+// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
+// +-----------------------------------------------------------------------+
+// | file          : $Id: index.php 1912 2007-03-16 06:30:07Z rub $
+// | last update   : $Date: 2007-03-16 07:30:07 +0100 (ven, 16 mar 2007) $
+// | last modifier : $Author: rub $
+// | revision      : $Revision: 1912 $
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/autoupdate/main.inc.php
===================================================================
--- /extensions/autoupdate/main.inc.php	(revision 3575)
+++ /extensions/autoupdate/main.inc.php	(revision 3575)
@@ -0,0 +1,21 @@
+<?php
+/*
+Plugin Name: Piwigo AutoUpgrade
+Version: 2.0.a
+Description: Upgrade your gallery automatically.
+Plugin URI: http://piwigo.org/ext/extension_view.php?eid=302
+Author: P@t
+Author URI: http://www.gauchon.com
+*/
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+if (script_basename() == 'admin') add_event_handler('get_admin_plugin_menu_links', 'check_for_auto_upgrade');
+
+function check_for_auto_upgrade($plugin_menu_links)
+{
+  global $page, $conf, $header_notes;
+  if ($page['page'] == 'intro') include(dirname(__FILE__).'/autoupdate.php');
+  return $plugin_menu_links;
+}
+?>
