From e11d7cd428f0a6eefc3f71f4b6996cce5d77dd72 Mon Sep 17 00:00:00 2001 From: mistic100 Date: Sun, 10 Apr 2016 14:36:21 +0200 Subject: [PATCH] Fix #2 adds "tags", "comment", "author" on webservice --- include/ws_functions.inc.php | 58 ++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php index 39a2ddf..78eeba7 100644 --- a/include/ws_functions.inc.php +++ b/include/ws_functions.inc.php @@ -13,8 +13,14 @@ function urluploader_ws_add_methods($arr) 'file_url' => array(), 'category' => array('type' => WS_TYPE_ID), 'name' => array('default' => null), + 'author' => array('default' => null), + 'comment' => array('default' => null), + 'tags' => array( + 'default' => null, + 'flags' => WS_PARAM_ACCEPT_ARRAY, + ), 'level' => array( - 'default' => 0, + 'default' => null, 'maxValue' => $conf['available_permission_levels'], 'type' => WS_TYPE_INT | WS_TYPE_POSITIVE, ), @@ -90,20 +96,34 @@ function ws_images_addRemote($params, &$service) $image_id = add_uploaded_file( $temp_filename, basename($temp_filename), - array($params['category']), - $params['level'] + array($params['category']) ); + + // set properties $updates = array(); - if (!empty($params['name'])) + foreach (array('level', 'name', 'author', 'comment') as $key) { - $updates['name'] = $params['name']; + if (!empty($params[ $key ])) + { + $updates[ $key ] = $params[ $key ]; + } } + if ($params['url_in_comment'] == 'true') { $url = parse_url($params['file_url']); $url = $url['scheme'] . '://' . $url['host']; - $updates['comment'] = '' . $url . ''; + $link = '' . $url . ''; + + if (!isset($updates['comment'])) + { + $updates['comment'] = $link; + } + else + { + $updates['comment'] .= '
' . $link; + } } single_update( @@ -113,6 +133,32 @@ function ws_images_addRemote($params, &$service) ); + // set tags + if (!empty($params['tags'])) + { + include_once(PHPWG_ROOT_PATH . 'admin/include/functions.php'); + + $tag_ids = array(); + if (is_array($params['tags'])) + { + foreach ($params['tags'] as $tag_name) + { + $tag_ids[] = tag_id_from_tag_name($tag_name); + } + } + else + { + $tag_names = preg_split('~(?