Skip to content

Commit e11d7cd

Browse files
committed
Fix #2 adds "tags", "comment", "author" on webservice
1 parent 5d4e515 commit e11d7cd

1 file changed

Lines changed: 52 additions & 6 deletions

File tree

include/ws_functions.inc.php

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ function urluploader_ws_add_methods($arr)
1313
'file_url' => array(),
1414
'category' => array('type' => WS_TYPE_ID),
1515
'name' => array('default' => null),
16+
'author' => array('default' => null),
17+
'comment' => array('default' => null),
18+
'tags' => array(
19+
'default' => null,
20+
'flags' => WS_PARAM_ACCEPT_ARRAY,
21+
),
1622
'level' => array(
17-
'default' => 0,
23+
'default' => null,
1824
'maxValue' => $conf['available_permission_levels'],
1925
'type' => WS_TYPE_INT | WS_TYPE_POSITIVE,
2026
),
@@ -90,20 +96,34 @@ function ws_images_addRemote($params, &$service)
9096
$image_id = add_uploaded_file(
9197
$temp_filename,
9298
basename($temp_filename),
93-
array($params['category']),
94-
$params['level']
99+
array($params['category'])
95100
);
96101

102+
103+
// set properties
97104
$updates = array();
98-
if (!empty($params['name']))
105+
foreach (array('level', 'name', 'author', 'comment') as $key)
99106
{
100-
$updates['name'] = $params['name'];
107+
if (!empty($params[ $key ]))
108+
{
109+
$updates[ $key ] = $params[ $key ];
110+
}
101111
}
112+
102113
if ($params['url_in_comment'] == 'true')
103114
{
104115
$url = parse_url($params['file_url']);
105116
$url = $url['scheme'] . '://' . $url['host'];
106-
$updates['comment'] = '<a href="' . $url . '">' . $url . '</a>';
117+
$link = '<a href="' . $url . '">' . $url . '</a>';
118+
119+
if (!isset($updates['comment']))
120+
{
121+
$updates['comment'] = $link;
122+
}
123+
else
124+
{
125+
$updates['comment'] .= '<br>' . $link;
126+
}
107127
}
108128

109129
single_update(
@@ -113,6 +133,32 @@ function ws_images_addRemote($params, &$service)
113133
);
114134

115135

136+
// set tags
137+
if (!empty($params['tags']))
138+
{
139+
include_once(PHPWG_ROOT_PATH . 'admin/include/functions.php');
140+
141+
$tag_ids = array();
142+
if (is_array($params['tags']))
143+
{
144+
foreach ($params['tags'] as $tag_name)
145+
{
146+
$tag_ids[] = tag_id_from_tag_name($tag_name);
147+
}
148+
}
149+
else
150+
{
151+
$tag_names = preg_split('~(?<!\\\),~', $params['tags']);
152+
foreach ($tag_names as $tag_name)
153+
{
154+
$tag_ids[] = tag_id_from_tag_name(preg_replace('#\\\\*,#', ',', $tag_name));
155+
}
156+
}
157+
158+
add_tags($tag_ids, array($image_id));
159+
}
160+
161+
116162
// return infos
117163
$query = '
118164
SELECT id, name, permalink

0 commit comments

Comments
 (0)