} if ($CGDb->where('ponyid', $Appearance['id'])->where('tid', $Tag['tid'])->has('tagged')) { Response::fail('This appearance already has this tag'); } if (!$CGDb->insert('tagged', array('ponyid' => $Appearance['id'], 'tid' => $Tag['tid']))) { Response::dbError(); } break; case "untag": $tag_id = (new Input('tag', 'int', array(Input::CUSTOM_ERROR_MESSAGES => array(Input::ERROR_MISSING => 'Tag ID is missing', Input::ERROR_INVALID => 'Tag ID (@value) is invalid'))))->out(); $Tag = $CGDb->where('tid', $tag_id)->getOne('tags'); if (empty($Tag)) { Response::fail('This tag does not exist'); } if (!empty($Tag['synonym_of'])) { $Syn = Tags::getSynonymOf($Tag, 'name'); Response::fail('Synonym tags cannot be removed from appearances directly. ' . "If you want to remove this tag you must remove <strong>{$Syn['name']}</strong> or the synonymization."); } if ($CGDb->where('ponyid', $Appearance['id'])->where('tid', $Tag['tid'])->has('tagged')) { if (!$CGDb->where('ponyid', $Appearance['id'])->where('tid', $Tag['tid'])->delete('tagged')) { Response::dbError(); } } break; } Appearances::updateIndex($Appearance['id']); Tags::updateUses($Tag['tid']); if (!empty(CGUtils::GROUP_TAG_IDS_ASSOC[$Tag['tid']])) { Appearances::getSortReorder($EQG); } $response = array('tags' => Appearances::getTagsHTML($Appearance['id'], NOWRAP));