aboutsummaryrefslogtreecommitdiffstats
path: root/admin/include/functions.php
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2008-10-01 21:08:51 +0000
committerplegall <plg@piwigo.org>2008-10-01 21:08:51 +0000
commit600e2d87ecc359b3bd202c4b471c042f319e1e2b (patch)
treee3c09337a0e31213fa12b6233ec74a4f01259852 /admin/include/functions.php
parent610e5ada6e8e5876a7275e827abf45b849dba06b (diff)
feature 874 added: new Web API method pwg.tags.add.
git-svn-id: http://piwigo.org/svn/trunk@2634 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--admin/include/functions.php45
1 files changed, 45 insertions, 0 deletions
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