Index: /extensions/autoupdate/trunk/main.inc.php
===================================================================
--- /extensions/autoupdate/trunk/main.inc.php	(revision 9934)
+++ /extensions/autoupdate/trunk/main.inc.php	(revision 9935)
@@ -23,6 +23,6 @@
 }
 
-if (script_basename() == 'admin')
- add_event_handler('get_admin_plugin_menu_links', 'check_for_auto_upgrade');
+add_event_handler('get_admin_plugin_menu_links', 'check_for_auto_upgrade');
+add_event_handler('ws_add_methods', 'add_ws_autoupdate_methods');
 
 function check_for_auto_upgrade($plugin_menu_links)
@@ -56,3 +56,8 @@
   return $plugin_menu_links;
 }
+
+function add_ws_autoupdate_methods($arr)
+{
+  include_once(AUTOUPDATE_PATH.'ws_functions.inc.php');
+}
 ?>
Index: /extensions/autoupdate/trunk/template/autoupdate.js
===================================================================
--- /extensions/autoupdate/trunk/template/autoupdate.js	(revision 9934)
+++ /extensions/autoupdate/trunk/template/autoupdate.js	(revision 9935)
@@ -12,9 +12,11 @@
 
 function resetIgnored() {
-  jQuery.post(
-    "plugins/autoupdate/ajax/ignore_list.php",
-    { reset: true, pwg_token: pwg_token },
-    function(data) {
-      if (data == "ok") {
+  jQuery.ajax({
+    type: 'GET',
+    url: 'ws.php',
+    dataType: 'json',
+    data: { method: 'pwg.extensions.ignoreUpdates', reset: true, pwg_token: pwg_token, format: 'json' },
+    success: function(data) {
+      if (data['stat'] == 'ok') {
         jQuery(".pluginBox, fieldset").show();
         jQuery("#update_all").show();
@@ -25,5 +27,5 @@
       }
     }
-  );
+  });
 };
 
@@ -57,13 +59,13 @@
   jQuery('.autoupdate_bar').toggle();
   jQuery.ajax({
-    type: 'POST',
-    url: 'plugins/autoupdate/ajax/update_'+type+'.php',
-    data: { id: id, revision: revision, pwg_token: pwg_token },
+    type: 'GET',
+    url: 'ws.php',
+    data: { method: 'pwg.'+type+'s.update', id: id, revision: revision, pwg_token: pwg_token, format: 'json' },
     success: function(data) {
-      if (data['result']) {
+      if (data['stat'] == 'ok') {
         jQuery("#"+type+"_"+id).remove();
         checkFieldsets();
         jQuery.jGrowl(
-          data['msg'],
+          data['result'],
           {
             theme:  'success',
@@ -77,5 +79,5 @@
       } else {
         jQuery.jGrowl(
-          data['msg'],
+          data['result'],
           {
             theme:  'error',
@@ -105,9 +107,11 @@
 
 function ignoreExtension(type, id) {
-  jQuery.post(
-    "plugins/autoupdate/ajax/ignore_list.php",
-    { type: type+'s', id: id, pwg_token: pwg_token },
-    function(data) {
-      if (data == "ok") {
+  jQuery.ajax({
+    type: 'GET',
+    url: 'ws.php',
+    dataType: 'json',
+    data: { method: 'pwg.extensions.ignoreUpdates', type: type+'s', id: id, pwg_token: pwg_token, format: 'json' },
+    success: function(data) {
+      if (data['stat'] == 'ok') {
         jQuery("#"+type+"_"+id).hide();
         jQuery("#reset_ignore").show();
@@ -115,4 +119,4 @@
       }
     }
-  );
+  });
 };
Index: /extensions/autoupdate/trunk/template/head.tpl
===================================================================
--- /extensions/autoupdate/trunk/template/head.tpl	(revision 9934)
+++ /extensions/autoupdate/trunk/template/head.tpl	(revision 9935)
@@ -5,22 +5,23 @@
 var up_to_date = '{"Gallery and extensions are up to date"|@translate|@escape:"javascript"}';
 
-window.onload = function () {ldelim}
-  jQuery.ajax({ldelim}
+{literal}
+window.onload = function () {
+  jQuery.ajax({
     type: 'GET',
-    url: 'plugins/autoupdate/ajax/check_updates.php',
-    dataType: 'text',
+    url: 'ws.php',
+    dataType: 'json',
+    data: { method: 'pwg.extensions.checkUpdates', format: 'json' },
     timeout: 10000,  // 10 sec timeout
-    success: function (data) {ldelim}
-      var reg = new RegExp("^(error|piwigo_upgrade|ext_upgrade|up_to_date)$","i");
-      if (!data.match(reg))
+    success: function (data) {
+      if (data['stat'] == 'ok')
+        jQuery('#autoupdate').html(eval(data['result']));
+      else
         jQuery('#autoupdate').html(error);
-      else
-        jQuery('#autoupdate').html(eval(data));
     },
-    error: function() {ldelim}
+    error: function() {
      jQuery('#autoupdate').html(error);
     }
   });
 }
-{/footer_script}
+{/literal}{/footer_script}
 <p id="autoupdate"><img src="plugins/autoupdate/template/ajax-loader.gif"> &nbsp; {'Checking upgrades for gallery and plugins...'|@translate}</p>
Index: /extensions/autoupdate/trunk/ws_functions.inc.php
===================================================================
--- /extensions/autoupdate/trunk/ws_functions.inc.php	(revision 9935)
+++ /extensions/autoupdate/trunk/ws_functions.inc.php	(revision 9935)
@@ -0,0 +1,311 @@
+<?php
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+global $conf;
+
+$service = &$arr[0];
+
+$service->addMethod(
+  'pwg.plugins.update',
+  'ws_plugins_update',
+  array(
+    'id' => array(),
+    'revision' => array(),
+    'pwg_token' => array(),
+  ),
+  'Update a plugin. Webmaster only.'
+);
+
+$service->addMethod(
+  'pwg.themes.update',
+  'ws_themes_update',
+  array(
+    'id' => array(),
+    'revision' => array(),
+    'pwg_token' => array(),
+  ),
+  'Update a theme. Webmaster only.'
+);
+
+$service->addMethod(
+  'pwg.languages.update',
+  'ws_languages_update',
+  array(
+    'id' => array(),
+    'revision'=> array(),
+    'pwg_token' => array(),
+  ),
+  'Update a language. Webmaster only.'
+);
+
+$service->addMethod(
+  'pwg.extensions.checkUpdates',
+  'ws_extensions_checkupdates',
+  array(),
+  'Check if piwigo or extensions are up to date.'
+);
+
+$service->addMethod(
+  'pwg.extensions.ignoreUpdates',
+  'ws_extensions_ignoreupdates',
+  array(
+    'type' => array('default'=>null),
+    'id' => array('default'=>null),
+    'reset' => array('default'=>null),
+    'pwg_token' => array(),
+  ),
+  'Ignore an extension if it need update.'
+);
+
+function ws_plugins_update($params, &$service)
+{
+  if (!is_webmaster())
+  {
+    return new PwgError(401, l10n('Webmaster status is required.'));
+  }
+
+  if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token'])
+  {
+    return new PwgError(403, 'Invalid security token');
+  }
+
+  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
+  include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php');
+  $plugins = new plugins();
+
+  if (isset($params['upgradestatus']) and isset($params['id']))
+  {
+    switch ($params['upgradestatus'])
+    {
+      case 'ok':
+        return sprintf(l10n('%s has been successfully upgraded.'), $plugins->fs_plugins[$params['id']]['name']);
+
+      case 'temp_path_error':
+        return new PwgError(null, l10n('Can\'t create temporary file.'));
+
+      case 'dl_archive_error':
+        return new PwgError(null, l10n('Can\'t download archive.'));
+
+      case 'archive_error':
+        return new PwgError(null, l10n('Can\'t read or extract archive.'));
+
+      default:
+        return new PwgError(null, sprintf(l10n('An error occured during extraction (%s).'), $params['upgradestatus']));
+    }
+  }
+
+  if (empty($params['id']) or empty($params['revision']))
+  {
+    return new PwgError(null, 'Wrong parameters');
+  }
+
+  $plugin_id = $params['id'];
+  $revision = $params['revision'];
+
+  if (isset($plugins->db_plugins_by_id[$plugin_id])
+    and $plugins->db_plugins_by_id[$plugin_id]['state'] == 'active')
+  {
+    $plugins->perform_action('deactivate', $plugin_id);
+
+    redirect(PHPWG_ROOT_PATH
+      . 'ws.php'
+      . '?method=pwg.plugins.update'
+      . '&revision=' . $revision
+      . '&id=' . $plugin_id
+      . '&reactivate=true'
+      . '&pwg_token=' . get_pwg_token()
+      . '&format=json'
+    );
+  }
+
+  $upgrade_status = $plugins->extract_plugin_files('upgrade', $revision, $plugin_id);
+
+  if (isset($params['reactivate']))
+  {
+    $plugins->perform_action('activate', $plugin_id);
+  }
+
+  global $template;
+  $template->delete_compiled_templates();
+
+  redirect(PHPWG_ROOT_PATH
+    . 'ws.php'
+    . '?method=pwg.plugins.update'
+    . '&revision=' . $revision
+    . '&id=' . $plugin_id
+    . '&upgradestatus='.$upgrade_status
+    . '&pwg_token=' . get_pwg_token()
+    . '&format=json'
+  );
+}
+
+function ws_themes_update($params, &$service)
+{
+  if (!is_webmaster())
+  {
+    return new PwgError(401, l10n('Webmaster status is required.'));
+  }
+
+  if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token'])
+  {
+    return new PwgError(403, 'Invalid security token');
+  }
+
+  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
+  include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php');
+  $themes = new themes();
+
+  $theme_id = $params['id'];
+  $revision = $params['revision'];
+
+  $upgrade_status = $themes->extract_theme_files('upgrade', $revision, $theme_id);
+
+  global $template;
+  $template->delete_compiled_templates();
+
+  switch ($upgrade_status)
+  {
+    case 'ok':
+      return sprintf(l10n('%s has been successfully upgraded.'), $themes->fs_themes[$theme_id]['name']);
+
+    case 'temp_path_error':
+      return new PwgError(null, l10n('Can\'t create temporary file.'));
+
+    case 'dl_archive_error':
+      return new PwgError(null, l10n('Can\'t download archive.'));
+
+    case 'archive_error':
+      return new PwgError(null, l10n('Can\'t read or extract archive.'));
+
+    default:
+      return new PwgError(null, sprintf(l10n('An error occured during extraction (%s).'), $upgrade_status));
+  }
+}
+
+function ws_languages_update($params, &$service)
+{
+  if (!is_webmaster())
+  {
+    return new PwgError(401, l10n('Webmaster status is required.'));
+  }
+
+  if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token'])
+  {
+    return new PwgError(403, 'Invalid security token');
+  }
+
+  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
+  include_once(PHPWG_ROOT_PATH.'admin/include/languages.class.php');
+  $languages = new languages();
+
+  $language_id = $params['id'];
+  $revision = $params['revision'];
+
+  $upgrade_status = $languages->extract_language_files('upgrade', $revision, $language_id);
+
+  global $template;
+  $template->delete_compiled_templates();
+
+  switch ($upgrade_status)
+  {
+    case 'ok':
+      return sprintf(l10n('%s has been successfully upgraded.'), $languages->fs_languages[$language_id]['name']);
+
+    case 'temp_path_error':
+      return new PwgError(null, l10n('Can\'t create temporary file.'));
+
+    case 'dl_archive_error':
+      return new PwgError(null, l10n('Can\'t download archive.'));
+
+    case 'archive_error':
+      return new PwgError(null, l10n('Can\'t read or extract archive.'));
+
+    default:
+      return new PwgError(null, sprintf(l10n('An error occured during extraction (%s).'), $upgrade_status));
+  }
+}
+
+function ws_extensions_checkupdates($params, &$service)
+{
+  define('IN_ADMIN', true);
+  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
+  include_once(AUTOUPDATE_PATH.'include/autoupdate.class.php');
+  $autoupdate = new autoupdate();
+
+  if (!is_webmaster())
+  {
+    return new PwgError(401, 'Access denied');
+  }
+
+  // Check if gallery or plugins are up to date
+  load_language('plugin.lang', dirname(dirname(__FILE__)).'/');
+
+  function autoupdate_error()
+  {
+    unset($_SESSION['extensions_need_update']);
+    return new PwgError(null, 'An error occured');
+  }
+
+  if (!isset($_SESSION['need_update']))
+    $autoupdate->check_piwigo_upgrade();
+
+  if ($_SESSION['need_update'])
+    return 'piwigo_upgrade';
+
+  // Gallery is up to date -> check extensions
+  if (!isset($_SESSION['extensions_need_update']))
+    $autoupdate->check_extensions();
+  else
+    $autoupdate->check_updated_extensions();
+
+  if (!empty($_SESSION['extensions_need_update']))
+    return 'ext_upgrade';
+  elseif ($_SESSION['need_update'] === false and $_SESSION['extensions_need_update'] === array())
+    return 'up_to_date';
+
+  autoupdate_error();
+}
+
+function ws_extensions_ignoreupdates($params, &$service)
+{
+  global $conf;
+
+  define('IN_ADMIN', true);
+  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
+
+  if (!is_webmaster())
+  {
+    return new PwgError(401, 'Access denied');
+  }
+
+  if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token'])
+  {
+    return new PwgError(403, 'Invalid security token');
+  }
+
+  if ($params['reset'])
+  {
+    $conf['AU_ignore'] = array('plugins'=>array(),'themes'=>array(),'languages'=>array());
+    conf_update_param('autoupdate_ignore_list', pwg_db_real_escape_string(serialize($conf['AU_ignore'])));
+    unset($_SESSION['extensions_need_update']);
+    return true;
+  }
+
+  if (empty($params['id']) or empty($params['type'])
+    or !in_array($params['type'], array('plugins', 'themes', 'languages')))
+  {
+    return new PwgError(null, 'Invalid parameters');
+  }
+
+  // Add or remove plugin from ignore list
+  if (!in_array($params['id'], $conf['AU_ignore'][$params['type']]))
+  {
+    array_push($conf['AU_ignore'][$params['type']], $params['id']);
+  }
+  conf_update_param('autoupdate_ignore_list', pwg_db_real_escape_string(serialize($conf['AU_ignore'])));
+  unset($_SESSION['extensions_need_update']);
+  return true;
+}
+
+?>
