Index: /extensions/pwg_images_addSimple/main.inc.php
===================================================================
--- /extensions/pwg_images_addSimple/main.inc.php	(revision 7532)
+++ /extensions/pwg_images_addSimple/main.inc.php	(revision 7533)
@@ -37,4 +37,24 @@
     'POST method only.<br>Use the <b>image</b> field for uploading file.<br>Set the form encoding to "form-data"<br><b>category</b> is the numeric identifier of the destination category.'
     );
+
+  $service->addMethod(
+    'pwg.images.delete',
+    'ws_images_delete',
+    array(
+      'image_id'=>array('default'=>0),
+      'pwg_token' => array('default' => null),
+      ),
+    'Delete photos. You can give several image_ids, comma separated'
+    );
+
+  $service->addMethod(
+    'pwg.categories.delete',
+    'ws_categories_delete',
+    array(
+      'category_id'=>array('default'=>0),
+      'pwg_token' => array('default' => null),
+      ),
+    'Delete categories. You can give several category_ids, comma separated'
+    );
 }
 
@@ -132,3 +152,121 @@
     );
 }
+
+function ws_images_delete($params, &$service)
+{
+  global $conf;
+  if (!is_admin() || is_adviser() )
+  {
+    return new PwgError(401, 'Access denied');
+  }
+
+  if (!$service->isPost())
+  {
+    return new PwgError(405, "This method requires HTTP POST");
+  }
+
+  if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token'])
+  {
+    return new PwgError(403, 'Invalid security token');
+  }
+
+  $params['image_id'] = preg_split(
+    '/[\s,;\|]/',
+    $params['image_id'],
+    -1,
+    PREG_SPLIT_NO_EMPTY
+    );
+  $params['image_id'] = array_map('intval', $params['image_id']);
+
+  $image_ids = array();
+  foreach ($params['image_id'] as $image_id)
+  {
+    if ($image_id > 0)
+    {
+      array_push($image_ids, $image_id);
+    }
+  }
+
+  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
+  delete_elements($params['image_id'], true);
+}
+
+function ws_categories_delete($params, &$service)
+{
+  global $conf;
+  if (!is_admin() || is_adviser() )
+  {
+    return new PwgError(401, 'Access denied');
+  }
+
+  if (!$service->isPost())
+  {
+    return new PwgError(405, "This method requires HTTP POST");
+  }
+
+  if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token'])
+  {
+    return new PwgError(403, 'Invalid security token');
+  }
+
+  $params['category_id'] = preg_split(
+    '/[\s,;\|]/',
+    $params['category_id'],
+    -1,
+    PREG_SPLIT_NO_EMPTY
+    );
+  $params['category_id'] = array_map('intval', $params['category_id']);
+
+  $category_ids = array();
+  foreach ($params['category_id'] as $category_id)
+  {
+    if ($category_id > 0)
+    {
+      array_push($category_ids, $category_id);
+    }
+  }
+
+  // We don't want to create orphans. If a photo is belonging to a category
+  // that will be deleted and to no other category, we must delete the photo
+  // as well.
+  //
+  // In the future, this algorithm must be integrated into the
+  // delete_categories function.
+  
+  if (count($category_ids) == 0)
+  {
+    return;
+  }
+
+  // add sub-category ids to the given ids : if a category is deleted, all
+  // sub-categories must be so
+  $all_category_ids = get_subcat_ids($category_ids);
+
+  $query = '
+SELECT
+    DISTINCT(image_id)
+  FROM '.IMAGE_CATEGORY_TABLE.'
+  WHERE category_id IN ('.implode(',', $all_category_ids).')
+;';
+  $image_ids_linked = array_from_query($query, 'image_id');
+
+  $query = '
+SELECT
+    DISTINCT(image_id)
+  FROM '.IMAGE_CATEGORY_TABLE.'
+  WHERE image_id IN ('.implode(',', $image_ids_linked).')
+    AND category_id NOT IN ('.implode(',', $all_category_ids).')
+;';
+  $image_ids_not_orphans = array_from_query($query, 'image_id');
+
+  $image_ids_orphans = array_diff($image_ids_linked, $image_ids_not_orphans);
+  
+  // print_r($image_ids_not_orphans); exit();
+
+  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
+  delete_categories($category_ids);
+  update_global_rank();
+
+  delete_elements($image_ids_orphans, true);
+}
 ?>
