Skip to content
Permalink
Browse files

feature 2080 added: add methods pwg.images.delete and pwg.categories.…

…delete from

pwg.images.addSimple plugin. pwg.categories.delete implements the new
photo_deletion_mode (see feature:2081) and set it to "delete_orphans" by default.


git-svn-id: http://piwigo.org/svn/trunk@8266 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information...
plegall committed Dec 23, 2010
1 parent 877a4e6 commit 130c83652ecb198347fb79a30df1596308f18d52
Showing with 130 additions and 1 deletion.
  1. +107 −0 include/ws_functions.inc.php
  2. +23 −1 ws.php
@@ -1989,6 +1989,45 @@ function ws_images_setInfo($params, &$service)
invalidate_user_cache();
}
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($image_ids, true);
}
function ws_add_image_category_relations($image_id, $categories_string, $replace_mode=false)
{
// let's add links between the image and the categories
@@ -2201,6 +2240,74 @@ function ws_categories_setInfo($params, &$service)
}
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');
}
$modes = array('no_delete', 'delete_orphans', 'force_delete');
if (!in_array($params['photo_deletion_mode'], $modes))
{
return new PwgError(
500,
'[ws_categories_delete]'
.' invalid parameter photo_deletion_mode "'.$params['photo_deletion_mode'].'"'
.', possible values are {'.implode(', ', $modes).'}.'
);
}
$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);
}
}
if (count($category_ids) == 0)
{
return;
}
$query = '
SELECT id
FROM '.CATEGORIES_TABLE.'
WHERE id IN ('.implode(',', $category_ids).')
;';
$category_ids = array_from_query($query, 'id');
if (count($category_ids) == 0)
{
return;
}
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
delete_categories($category_ids, $params['photo_deletion_mode']);
update_global_rank();
}
function ws_logfile($string)
{
global $conf;
24 ws.php
@@ -236,7 +236,17 @@ function ws_addDefaultMethods( $arr )
),
'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.getAdminList',
'ws_categories_getAdminList',
@@ -254,6 +264,18 @@ function ws_addDefaultMethods( $arr )
'administration method only'
);
$service->addMethod(
'pwg.categories.delete',
'ws_categories_delete',
array(
'category_id'=>array('default'=>0),
'pwg_token' => array('default' => null),
'photo_deletion_mode' => array('default' => 'delete_orphans'),
),
'Delete categories. You can give several category_ids, comma separated.
<br><b>photo_deletion_mode</b> can be "no_delete" (may create orphan photos), "delete_orphans" (default mode, only deletes photos linked to no other album) or "force_delete" (delete all photos, even those linked to other albums)'
);
$service->addMethod(
'pwg.tags.getAdminList',
'ws_tags_getAdminList',

0 comments on commit 130c836

Please sign in to comment.
You can’t perform that action at this time.