Index: /extensions/autoupdate/autoupdate.php
===================================================================
--- /extensions/autoupdate/autoupdate.php	(revision 4698)
+++ /extensions/autoupdate/autoupdate.php	(revision 4699)
@@ -1,140 +1,11 @@
 <?php
 
-/* Fetch remote function with timeout */
-function autoupdate_fetchRemote($src, &$dest, $timeout=15, $user_agent='Piwigo', $step=0)
+load_language('plugin.lang', dirname(__FILE__).'/');
+
+if (isset($_GET['action']) and $_GET['action'] == 'check_autoupdate')
 {
-  // Try to retrieve data from local file?
-  if (!url_is_remote($src))
-  {
-    $content = @file_get_contents($src);
-    if ($content !== false)
-    {
-      is_resource($dest) ? @fwrite($dest, $content) : $dest = $content;
-      return true;
-    }
-    else
-    {
-      return false;
-    }
-  }
-
-  // After 3 redirections, return false
-  if ($step > 3) return false;
-
-  // Initialize $dest
-  is_resource($dest) or $dest = '';
-
-  // Try curl to read remote file
-  if (function_exists('curl_init'))
-  {
-    $ch = @curl_init();
-    @curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
-    @curl_setopt($ch, CURLOPT_URL, $src);
-    @curl_setopt($ch, CURLOPT_HEADER, 1);
-    @curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
-    @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-    $content = @curl_exec($ch);
-    $header_length = @curl_getinfo($ch, CURLINFO_HEADER_SIZE);
-    $status = @curl_getinfo($ch, CURLINFO_HTTP_CODE);
-    @curl_close($content);
-    if ($content !== false and $status >= 200 and $status < 400)
-    {
-      if (preg_match('/Location:\s+?(.+)/', substr($content, 0, $header_length), $m))
-      {
-        return autoupdate_fetchRemote($m[1], $dest, $user_agent, $step+1);
-      }
-      $content = substr($content, $header_length);
-      is_resource($dest) ? @fwrite($dest, $content) : $dest = $content;
-      return true;
-    }
-  }
-
-  // Try file_get_contents to read remote file
-  if (ini_get('allow_url_fopen'))
-  {
-    $opts['http'] = array('timeout' => $timeout);
-    $ctx = stream_context_create($opts);
-    $content = @file_get_contents($src, 0, $ctx);
-    if ($content !== false)
-    {
-      is_resource($dest) ? @fwrite($dest, $content) : $dest = $content;
-      return true;
-    }
-  }
-
-  return false;
+  unset($_SESSION['need_update']);
+  unset($_SESSION['plugins_need_update']);
 }
-
-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))
-        {
-          autoupdate_deltree($pathfile);
-        }
-        else
-        {
-          @unlink($pathfile);
-        }
-      }
-    }
-    closedir($fh);
-    return @rmdir($path);
-  }
-}
-
-function check_version_for_autoupdate($version=PHPWG_VERSION)
-{
-  global $conf, $header_notes;
-
-  if (preg_match('/(\d+\.\d+)\.(\d+)/', $version, $matches) and @autoupdate_fetchRemote(PHPWG_URL.'/download/latest_version', $result, 1))
-  {
-    $lines = @explode("\r\n", $result);
-    $new_version = trim($lines[1]);
-    $new_branch = preg_replace('/(\d+\.\d+)\.\d+/', '$1', $new_version);
-    $actual_branch = $matches[1];
-    $update_to =  $actual_branch . '.' . ($matches[2]+1);
-
-    if (version_compare($version, $new_version) < 0
-      and $actual_branch == $new_branch)
-    {
-      $path = $conf['local_data_dir'].'/autoupdate/';
-      $code = $version.'_to_'.$update_to;
-      $filename = $path.$version.'_to_'.$update_to.'.zip';
-      mkgetdir($path);
-
-      if (!file_exists($filename) or !filesize($filename))
-      {
-        $zip = @fopen($filename, 'w+');
-        @autoupdate_fetchRemote(PHPWG_URL.'/download/dlcounter.php?code='.str_replace(array('.', '_'), '', $code), $zip);
-        @fclose($zip);
-      }
-
-      if (file_exists($filename) and filesize($filename))
-      {
-        if (isset($_GET['autoupdate']) and preg_match('/\d+\.\d+\.\d+_to_'.preg_quote($version).'/', $_GET['autoupdate']))
-        {
-          redirect('admin.php?autoupdate='.$code);
-        }
-        else
-        {
-          array_push($header_notes,
-            '<p>'.l10n('A new version of Piwigo is available.').'<br>',
-            '<a href="admin.php?autoupdate='.$code.'" onClick="return confirm(\''.l10n('autoupdate_alert').'\');">'.l10n('Click here to upgrade automatically').'</a></p>'
-          );
-        }
-      }
-    }
-  }
-}
-
-load_language('plugin.lang', dirname(__FILE__).'/');
 
 if (isset($_GET['autoupdate']))
@@ -146,5 +17,7 @@
   elseif ($file = $conf['local_data_dir'].'/autoupdate/'.$_GET['autoupdate'].'.zip' and file_exists($file))
   {
+    include(dirname(__FILE__).'/class.inc.php');
     include_once(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php');
+    $autoupdate = new autoupdate();
     $zip = new PclZip($file);
     if ($result = $zip->extract(PCLZIP_OPT_PATH, PHPWG_ROOT_PATH,
@@ -194,5 +67,5 @@
             elseif (is_dir($path))
             {
-              autoupdate_deltree($path);
+              $autoupdate->deltree($path);
             }
           }
@@ -200,7 +73,8 @@
         if (preg_match('/\d+\.\d+\.\d+_to_(\d+\.\d+\.\d+)/', $_GET['autoupdate'], $matches))
         {
-          check_version_for_autoupdate($matches[1]);
+          unset($_SESSION['need_update']);
+          $autoupdate->check_version($matches[1]);
         }
-        autoupdate_deltree($conf['local_data_dir'].'/autoupdate');
+        $autoupdate->deltree($conf['local_data_dir'].'/autoupdate');
         invalidate_user_cache(true);
         $template->delete_compiled_templates();
@@ -216,5 +90,5 @@
     else
     {
-      autoupdate_deltree($conf['local_data_dir'].'/autoupdate');
+      $autoupdate->deltree($conf['local_data_dir'].'/autoupdate');
       array_push($page['errors'], l10n('autoupdate_fail'));
     }
@@ -226,8 +100,7 @@
   }
 }
-else
-{
-  check_version_for_autoupdate();
-}
+
+$template->set_filename('autoupdate_head', realpath(dirname(__FILE__).'/head.tpl'));
+array_push($header_notes, $template->parse('autoupdate_head', true));
 
 ?>
Index: /extensions/autoupdate/class.inc.php
===================================================================
--- /extensions/autoupdate/class.inc.php	(revision 4699)
+++ /extensions/autoupdate/class.inc.php	(revision 4699)
@@ -0,0 +1,164 @@
+<?php
+
+class autoupdate
+{
+  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);
+    }
+  }
+
+  function check_version($version=PHPWG_VERSION)
+  {
+    global $conf;
+
+    if (!isset($_SESSION['need_update']))
+    {
+      $_SESSION['need_update'] = null;
+
+      if (preg_match('/(\d+\.\d+)\.(\d+)/', $version, $matches)
+        and @fetchRemote(PHPWG_URL.'/download/latest_version', $result))
+      {
+        $lines = @explode("\r\n", $result);
+        $new_version = trim($lines[1]);
+        $new_branch = preg_replace('/(\d+\.\d+)\.\d+/', '$1', $new_version);
+        $actual_branch = $matches[1];
+        $update_to =  $actual_branch . '.' . ($matches[2]+1);
+
+        if (version_compare($version, $new_version) < 0 and $actual_branch == $new_branch)
+        {
+          $_SESSION['need_update'] = $new_version;
+        }
+        else
+        {
+          $_SESSION['need_update'] = false;
+        }
+      }
+    }
+
+    if ($_SESSION['need_update'])
+    {
+      preg_match('/(\d+\.\d+)\.(\d+)/', $version, $matches);
+      $update_to =  $matches[1] . '.' . ($matches[2]+1);
+      $path = $conf['local_data_dir'].'/autoupdate/';
+      $code = $version.'_to_'.$update_to;
+      $filename = $path.$version.'_to_'.$update_to.'.zip';
+      mkgetdir($path);
+
+      if (!file_exists($filename) or !filesize($filename))
+      {
+        $zip = @fopen($filename, 'w+');
+        @fetchRemote(PHPWG_URL.'/download/dlcounter.php?code='.str_replace(array('.', '_'), '', $code), $zip);
+        @fclose($zip);
+      }
+
+      if (file_exists($filename) and filesize($filename))
+      {
+        if (isset($_GET['autoupdate']) and preg_match('/\d+\.\d+\.\d+_to_'.preg_quote($version).'/', $_GET['autoupdate']))
+        {
+          redirect('admin.php?autoupdate='.$code);
+        }
+        else
+        {
+          return rtrim(l10n('A new version of Piwigo is available.'), '.').' ('.$_SESSION['need_update'].')<br>'
+            . '<a href="admin.php?autoupdate='.$code.'" onClick="return confirm_autoupdate();">'.l10n('Click here to upgrade automatically').'</a>';
+        }
+      }
+      else
+      {
+        @unlink($filename);
+        return rtrim(l10n('A new version of Piwigo is available.'), '.').' ('.$_SESSION['need_update'].')<br>'
+          . l10n('Piwigo cannot retrieve upgrade file from server').'<br>'
+          . '<a href="'.PHPWG_URL.'/releases/'.$_SESSION['need_update'].'" onclick="window.open(this.href, \'\'); return false;">'
+          . sprintf(l10n('Click here to see Piwigo %s release notes'), $_SESSION['need_update']).'</a>';
+      }
+    }
+    else
+    {
+      // Gallery is up to date
+      // Check plugins upgrade
+      include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php');
+      $plugins = new plugins();
+
+      if (!isset($_SESSION['plugins_need_update']))
+      {
+        $_SESSION['plugins_need_update'] = null;
+        $this->check_plugins_upgrade($plugins);
+      }
+      elseif (!empty($_SESSION['plugins_need_update']))
+      {
+        // Check if plugins have been upgraded since last check
+        foreach($plugins->fs_plugins as $plugin_id => $fs_plugin)
+        {
+          if (isset($_SESSION['plugins_need_update'][$plugin_id])
+            and $plugins->plugin_version_compare($fs_plugin['version'], $_SESSION['plugins_need_update'][$plugin_id]))
+          {
+            // Plugin have been updated
+            $this->check_plugins_upgrade($plugins);
+          }
+        }
+      }
+
+      if (!empty($_SESSION['plugins_need_update']))
+      {
+        return l10n('Some upgrades are available for you plugins').'<br>'
+          . '<a href="admin.php?page=plugins_update">'.l10n('Click here see upgrade plugins page').'</a>';
+      }
+    }
+
+    if ($_SESSION['need_update'] === false and $_SESSION['plugins_need_update'] === array())
+    {
+      return l10n('Gallery and plugins are up to date')
+        . '<br><a href="admin.php?action=check_autoupdate">'
+        . l10n('Click here to check again') . '</a>';
+    }
+    else
+    {
+      return l10n('Unable to check upgrades...')
+        . '<br><a href="admin.php?action=check_autoupdate">'
+        . l10n('Click here to check upgrades now') . '</a>';
+    }
+  }
+
+  function check_plugins_upgrade($plugins)
+  {
+    if ($plugins->get_server_plugins())
+    {
+      $_SESSION['plugins_need_update'] = array();
+
+      foreach($plugins->fs_plugins as $plugin_id => $fs_plugin)
+      {
+        if (isset($fs_plugin['extension']) and isset($plugins->server_plugins[$fs_plugin['extension']]))
+        {
+          $plugin_info = $plugins->server_plugins[$fs_plugin['extension']];
+
+          if (!$plugins->plugin_version_compare($fs_plugin['version'], $plugin_info['revision_name']))
+          {
+            // Plugin need upgrade
+            $_SESSION['plugins_need_update'][$plugin_id] = $plugin_info['revision_name'];
+          }
+        }
+      }
+    }
+  }
+}
+?>
Index: /extensions/autoupdate/head.tpl
===================================================================
--- /extensions/autoupdate/head.tpl	(revision 4699)
+++ /extensions/autoupdate/head.tpl	(revision 4699)
@@ -0,0 +1,31 @@
+{html_head}
+<script type="text/javascript">
+var mess_error = '{'Unable to check upgrades...'|@translate}<br><a href="admin.php?action=check_autoupdate">{'Click here to check upgrades now'|@translate}</a>';
+
+window.onload = function () {ldelim}
+  jQuery.ajax({ldelim}
+    type: 'GET',
+    url: '{$ROOT_URL|@cat:"plugins/autoupdate/remote.php"}',
+    dataType: 'text',
+    timeout: 10000,  // 10 sec timeout
+    success: function (data) {ldelim}
+      var reg = new RegExp("(warning|notice)","i");
+      if (data.match(reg)) {ldelim}
+        data = mess_error;
+      }
+      jQuery('#autoupdate').html(data);
+    },
+    error: function() {ldelim}
+     jQuery('#autoupdate').html(mess_error);
+    }
+  });
+}
+
+function confirm_autoupdate() {ldelim}
+  conf = confirm('{'autoupdate_alert'|@translate}');
+  if (conf) jQuery('#autoupdate').html('Upgrade in progress... Please wait.');
+  return conf;
+}
+</script>
+{/html_head}
+<p id="autoupdate"><img src="plugins/autoupdate/ajax-loader.gif"> &nbsp; {'Checking upgrades for gallery and plugins upgrades...'|@translate}</p>
Index: /extensions/autoupdate/language/en_UK/plugin.lang.php
===================================================================
--- /extensions/autoupdate/language/en_UK/plugin.lang.php	(revision 4698)
+++ /extensions/autoupdate/language/en_UK/plugin.lang.php	(revision 4699)
@@ -8,3 +8,12 @@
 $lang['autoupdate_extract_fail'] = 'An error occured during extract. Please check files permissions of your piwigo installation.<br><a href="%s">Click here to show log error</a>.';
 
+$lang['Piwigo cannot retrieve upgrade file from server'] = 'Piwigo cannot retrieve upgrade file from server';
+$lang['Click here to see Piwigo %s release notes'] = 'Click here to see Piwigo %s release notes';
+$lang['Some upgrades are available for you plugins'] = 'Some upgrades are available for you plugins';
+$lang['Click here see upgrade plugins page'] = 'Click here see upgrade plugins page';
+$lang['Gallery and plugins are up to date'] = 'Gallery and plugins are up to date';
+$lang['Unable to check upgrades...'] = 'Unable to check upgrades...';
+$lang['Piwigo will automaticaly try again later.'] = 'Piwigo will automaticaly try again later.';
+$lang['Click here to check upgrades now'] = 'Click here to check upgrades now';
+
 ?>
Index: /extensions/autoupdate/language/es_ES/plugin.lang.php
===================================================================
--- /extensions/autoupdate/language/es_ES/plugin.lang.php	(revision 4698)
+++ /extensions/autoupdate/language/es_ES/plugin.lang.php	(revision 4699)
@@ -8,3 +8,12 @@
 $lang['autoupdate_extract_fail'] = 'Imposible extraer los ficheros. Por favor, verifique los permisos de los ficheros de su instalación. <Br> <a href="%s"> Haga clic aquí para ver el informe de error</a>.';
 
+/*TODO*/$lang['Piwigo cannot retrieve upgrade file from server'] = 'Piwigo cannot retrieve upgrade file from server';
+/*TODO*/$lang['Click here to see Piwigo %s release notes'] = 'Click here to see Piwigo %s release notes';
+/*TODO*/$lang['Some upgrades are available for you plugins'] = 'Some upgrades are available for you plugins';
+/*TODO*/$lang['Click here see upgrade plugins page'] = 'Click here see upgrade plugins page';
+/*TODO*/$lang['Gallery and plugins are up to date'] = 'Gallery and plugins are up to date';
+/*TODO*/$lang['Unable to check upgrades...'] = 'Unable to check upgrades...';
+/*TODO*/$lang['Piwigo will automaticaly try again later.'] = 'Piwigo will automaticaly try again later.';
+/*TODO*/$lang['Click here to check upgrades now'] = 'Click here to check upgrades now';
+
 ?>
Index: /extensions/autoupdate/language/fr_FR/plugin.lang.php
===================================================================
--- /extensions/autoupdate/language/fr_FR/plugin.lang.php	(revision 4698)
+++ /extensions/autoupdate/language/fr_FR/plugin.lang.php	(revision 4699)
@@ -8,3 +8,10 @@
 $lang['autoupdate_extract_fail'] = 'Impossible d\'extraire les fichiers. Veuillez vérifier les permissions des fichiers de votre installation.<br><a href="%s">Cliquez ici pour voir le rapport d\'erreur</a>.';
 
+$lang['Piwigo cannot retrieve upgrade file from server'] = 'Piwigo ne peut pas récupérer le fichier de mise à jour depuis le serveur';
+$lang['Click here to see Piwigo %s release notes'] = 'Cliquez ici pour afficher les informations relatives à Piwigo %s';
+$lang['Some upgrades are available for you plugins'] = 'Des mises à jour sont disponibles pour vos plugins';
+$lang['Click here see upgrade plugins page'] = 'Cliquez ici pour afficher la page de mise à jour des plugins';
+$lang['Gallery and plugins are up to date'] = 'Votre galerie et vos plugins sont à jour';
+$lang['Unable to check upgrades...'] = 'Impossible de vérifier les mises à jour...';
+$lang['Click here to check upgrades now'] = 'Cliquez ici pour vérifier les mises à jour maintenant';
 ?>
Index: /extensions/autoupdate/language/hu_HU/plugin.lang.php
===================================================================
--- /extensions/autoupdate/language/hu_HU/plugin.lang.php	(revision 4698)
+++ /extensions/autoupdate/language/hu_HU/plugin.lang.php	(revision 4699)
@@ -8,3 +8,12 @@
 $lang['autoupdate_extract_fail'] = 'Hibajelentés (Információ). Kérjük ellenőrizze a telepített fájlok jogosultságait.<br><a href="%s">További információkért kattintson ide</a>.';
 
+/*TODO*/$lang['Piwigo cannot retrieve upgrade file from server'] = 'Piwigo cannot retrieve upgrade file from server';
+/*TODO*/$lang['Click here to see Piwigo %s release notes'] = 'Click here to see Piwigo %s release notes';
+/*TODO*/$lang['Some upgrades are available for you plugins'] = 'Some upgrades are available for you plugins';
+/*TODO*/$lang['Click here see upgrade plugins page'] = 'Click here see upgrade plugins page';
+/*TODO*/$lang['Gallery and plugins are up to date'] = 'Gallery and plugins are up to date';
+/*TODO*/$lang['Unable to check upgrades...'] = 'Unable to check upgrades...';
+/*TODO*/$lang['Piwigo will automaticaly try again later.'] = 'Piwigo will automaticaly try again later.';
+/*TODO*/$lang['Click here to check upgrades now'] = 'Click here to check upgrades now';
+
 ?>
Index: /extensions/autoupdate/language/it_IT/plugin.lang.php
===================================================================
--- /extensions/autoupdate/language/it_IT/plugin.lang.php	(revision 4698)
+++ /extensions/autoupdate/language/it_IT/plugin.lang.php	(revision 4699)
@@ -8,3 +8,12 @@
 $lang['autoupdate_extract_fail'] = 'Non è stato possibile estrarre i file. Verificare i permessi dei file della vostra installazione.<br><a href="%s">Cliccare qui per visualizzare il rapporto degli errori</a>.';
 
+/*TODO*/$lang['Piwigo cannot retrieve upgrade file from server'] = 'Piwigo cannot retrieve upgrade file from server';
+/*TODO*/$lang['Click here to see Piwigo %s release notes'] = 'Click here to see Piwigo %s release notes';
+/*TODO*/$lang['Some upgrades are available for you plugins'] = 'Some upgrades are available for you plugins';
+/*TODO*/$lang['Click here see upgrade plugins page'] = 'Click here see upgrade plugins page';
+/*TODO*/$lang['Gallery and plugins are up to date'] = 'Gallery and plugins are up to date';
+/*TODO*/$lang['Unable to check upgrades...'] = 'Unable to check upgrades...';
+/*TODO*/$lang['Piwigo will automaticaly try again later.'] = 'Piwigo will automaticaly try again later.';
+/*TODO*/$lang['Click here to check upgrades now'] = 'Click here to check upgrades now';
+
 ?>
Index: /extensions/autoupdate/language/pl_PL/plugin.lang.php
===================================================================
--- /extensions/autoupdate/language/pl_PL/plugin.lang.php	(revision 4698)
+++ /extensions/autoupdate/language/pl_PL/plugin.lang.php	(revision 4699)
@@ -8,3 +8,12 @@
 $lang['autoupdate_extract_fail'] = 'Wystąpił błąd podczas rozpokowywania. Sprawdź uprawnienia do plików w katalogu gdize jest zainstalowane piwigo.<br><a href="%s">Kliknij aby zobaczyć błędy</a>.';
 
+/*TODO*/$lang['Piwigo cannot retrieve upgrade file from server'] = 'Piwigo cannot retrieve upgrade file from server';
+/*TODO*/$lang['Click here to see Piwigo %s release notes'] = 'Click here to see Piwigo %s release notes';
+/*TODO*/$lang['Some upgrades are available for you plugins'] = 'Some upgrades are available for you plugins';
+/*TODO*/$lang['Click here see upgrade plugins page'] = 'Click here see upgrade plugins page';
+/*TODO*/$lang['Gallery and plugins are up to date'] = 'Gallery and plugins are up to date';
+/*TODO*/$lang['Unable to check upgrades...'] = 'Unable to check upgrades...';
+/*TODO*/$lang['Piwigo will automaticaly try again later.'] = 'Piwigo will automaticaly try again later.';
+/*TODO*/$lang['Click here to check upgrades now'] = 'Click here to check upgrades now';
+
 ?>
Index: /extensions/autoupdate/main.inc.php
===================================================================
--- /extensions/autoupdate/main.inc.php	(revision 4698)
+++ /extensions/autoupdate/main.inc.php	(revision 4699)
@@ -16,5 +16,10 @@
 {
   global $template, $page, $conf, $header_notes;
-  if ($page['page'] == 'intro') include(dirname(__FILE__).'/autoupdate.php');
+
+  if ($page['page'] == 'intro')
+  {
+    include(dirname(__FILE__).'/autoupdate.php');
+  }
+
   return $plugin_menu_links;
 }
Index: /extensions/autoupdate/remote.php
===================================================================
--- /extensions/autoupdate/remote.php	(revision 4699)
+++ /extensions/autoupdate/remote.php	(revision 4699)
@@ -0,0 +1,17 @@
+<?php
+
+define('PHPWG_ROOT_PATH','../../');
+define('IN_ADMIN', true);
+include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
+include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
+
+check_status(ACCESS_ADMINISTRATOR);
+
+load_language('plugin.lang', dirname(__FILE__).'/');
+
+include(dirname(__FILE__).'/class.inc.php');
+$autoupdate = new autoupdate();
+
+echo $autoupdate->check_version();
+
+?>
