From 600e2d87ecc359b3bd202c4b471c042f319e1e2b Mon Sep 17 00:00:00 2001 From: plegall Date: Wed, 1 Oct 2008 21:08:51 +0000 Subject: feature 874 added: new Web API method pwg.tags.add. git-svn-id: http://piwigo.org/svn/trunk@2634 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/include/functions.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'admin/include/functions.php') diff --git a/admin/include/functions.php b/admin/include/functions.php index b239b08a1..8f6514d19 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -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) + ) + ); + } +} ?> \ No newline at end of file -- cgit v1.2.3