From e79538be5ce50fe552c0180c169cfb275aa4ec07 Mon Sep 17 00:00:00 2001 From: plegall Date: Fri, 11 Feb 2011 22:57:23 +0000 Subject: feature 2189 added: ability to update a photo (the JPEG/PNG file) with pwg.images.addSimple, simply by adding an $image_id as argument. git-svn-id: http://piwigo.org/svn/trunk@9191 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/ws_functions.inc.php | 47 ++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php index d0b550a2a..be453b6f7 100644 --- a/include/ws_functions.inc.php +++ b/include/ws_functions.inc.php @@ -1352,10 +1352,28 @@ function ws_images_addSimple($params, &$service) { return new PwgError(405, "This method requires HTTP POST"); } + + $params['image_id'] = (int)$params['image_id']; + if ($params['image_id'] > 0) + { + include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); + + $query=' +SELECT * + FROM '.IMAGES_TABLE.' + WHERE id = '.$params['image_id'].' +;'; + + $image_row = pwg_db_fetch_assoc(pwg_query($query)); + if ($image_row == null) + { + return new PwgError(404, "image_id not found"); + } + } // category $params['category'] = (int)$params['category']; - if ($params['category'] <= 0) + if ($params['category'] <= 0 and $params['image_id'] <= 0) { return new PwgError(WS_ERR_INVALID_PARAM, "Invalid category_id"); } @@ -1366,8 +1384,9 @@ function ws_images_addSimple($params, &$service) $image_id = add_uploaded_file( $_FILES['image']['tmp_name'], $_FILES['image']['name'], - array($params['category']), - 8 + $params['category'] > 0 ? array($params['category']) : null, + 8, + $params['image_id'] > 0 ? $params['image_id'] : null ); $info_columns = array( @@ -1415,23 +1434,25 @@ function ws_images_addSimple($params, &$service) add_tags($tag_ids, array($image_id)); } - $query = ' + $url_params = array('image_id' => $image_id); + + if ($params['category'] > 0) + { + $query = ' SELECT id, name, permalink FROM '.CATEGORIES_TABLE.' WHERE id = '.$params['category'].' ;'; - $result = pwg_query($query); - $category = pwg_db_fetch_assoc($result); + $result = pwg_query($query); + $category = pwg_db_fetch_assoc($result); + + $url_params['section'] = 'categories'; + $url_params['category'] = $category; + } return array( 'image_id' => $image_id, - 'url' => make_picture_url( - array( - 'image_id' => $image_id, - 'section' => 'categories', - 'category' => $category - ) - ), + 'url' => make_picture_url($url_params), ); } -- cgit v1.2.3