diff options
-rw-r--r-- | include/ws_functions.inc.php | 107 | ||||
-rw-r--r-- | ws.php | 24 |
2 files changed, 130 insertions, 1 deletions
diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php index 91e73e8a2..d685fb24c 100644 --- a/include/ws_functions.inc.php +++ b/include/ws_functions.inc.php @@ -1989,6 +1989,45 @@ SELECT * 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; @@ -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', @@ -255,6 +265,18 @@ function ws_addDefaultMethods( $arr ) ); $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', array(), |