public function addTag()
{
global $injector, $registry;
$gallery = $this->vars->gallery;
$tags = $this->vars->tags;
$image = $this->vars->image;
if ($image) {
$id = $image;
$type = 'image';
} else {
$id = $gallery;
$type = 'gallery';
}
if (!is_numeric($id)) {
throw new Ansel_Exception(_("Invalid input %s"), $id);
}
// Get the resource owner
$storage = $injector->getInstance('Ansel_Storage');
if ($type == 'gallery') {
$resource = $storage->getGallery($id);
$parent = $resource;
} else {
$resource = $storage->getImage($id);
$parent = $storage->getGallery($resource->gallery);
}
$tagger = $injector->getInstance('Ansel_Tagger');
$tagger->tag($id, $tagger->split(rawurldecode($tags)), $registry->getAuth(), $type);
// Get the tags again since we need the newly added tag_ids
$newTags = $tagger->getTags($id, $type);
if (count($newTags)) {
$newTags = $tagger->getTagInfo(array_keys($newTags));
}
$links = Ansel::getTagLinks($newTags, 'add');
foreach ($newTags as &$tag_info) {
$tag_info['link'] = strval($links[$tag_info['tag_id']]);
}
return $newTags;
}