feature 874 added: new Web API method pwg.tags.add.
git-svn-id: http://piwigo.org/svn/trunk@2634 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
parent
610e5ada6e
commit
600e2d87ec
4 changed files with 88 additions and 0 deletions
|
|
@ -1816,4 +1816,49 @@ function get_extents($start='')
|
|||
return $extents;
|
||||
}
|
||||
|
||||
function create_tag($tag_name)
|
||||
{
|
||||
$tag_name = mysql_real_escape_string($tag_name);
|
||||
|
||||
// does the tag already exists?
|
||||
$query = '
|
||||
SELECT id
|
||||
FROM '.TAGS_TABLE.'
|
||||
WHERE name = \''.$tag_name.'\'
|
||||
;';
|
||||
$existing_tags = array_from_query($query, 'id');
|
||||
|
||||
if (count($existing_tags) == 0)
|
||||
{
|
||||
mass_inserts(
|
||||
TAGS_TABLE,
|
||||
array('name', 'url_name'),
|
||||
array(
|
||||
array(
|
||||
'name' => $tag_name,
|
||||
'url_name' => str2url($tag_name),
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$inserted_id = mysql_insert_id();
|
||||
|
||||
return array(
|
||||
'info' => sprintf(
|
||||
l10n('Tag "%s" was added'),
|
||||
stripslashes($tag_name)
|
||||
),
|
||||
'id' => $inserted_id,
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
return array(
|
||||
'error' => sprintf(
|
||||
l10n('Tag "%s" already exists'),
|
||||
stripslashes($tag_name)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1397,4 +1397,23 @@ function ws_categories_add($params, &$service)
|
|||
|
||||
return $creation_output;
|
||||
}
|
||||
|
||||
function ws_tags_add($params, &$service)
|
||||
{
|
||||
if (!is_admin() or is_adviser())
|
||||
{
|
||||
return new PwgError(401, 'Access denied');
|
||||
}
|
||||
|
||||
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
||||
|
||||
$creation_output = create_tag($params['name']);
|
||||
|
||||
if (isset($creation_output['error']))
|
||||
{
|
||||
return new PwgError(500, $creation_output['error']);
|
||||
}
|
||||
|
||||
return $creation_output;
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -152,6 +152,21 @@ if ($opt{action} eq 'pwg.categories.add') {
|
|||
print Dumper(from_json($response->content));
|
||||
}
|
||||
|
||||
if ($opt{action} eq 'pwg.tags.add') {
|
||||
$form = {
|
||||
method => 'pwg.tags.add',
|
||||
name => $opt{define}{name},
|
||||
};
|
||||
|
||||
my $response = $ua->post(
|
||||
$conf{base_url}.'/ws.php?format=json',
|
||||
$form
|
||||
);
|
||||
|
||||
use Data::Dumper;
|
||||
print Dumper(from_json($response->content));
|
||||
}
|
||||
|
||||
$query = pwg_ws_get_query(
|
||||
method => 'pwg.session.logout'
|
||||
);
|
||||
|
|
|
|||
9
ws.php
9
ws.php
|
|
@ -218,6 +218,15 @@ function ws_addDefaultMethods( $arr )
|
|||
array(),
|
||||
'administration method only'
|
||||
);
|
||||
|
||||
$service->addMethod(
|
||||
'pwg.tags.add',
|
||||
'ws_tags_add',
|
||||
array(
|
||||
'name' => array(),
|
||||
),
|
||||
'administration method only'
|
||||
);
|
||||
}
|
||||
|
||||
add_event_handler('ws_add_methods', 'ws_addDefaultMethods');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue