/** * * */ public function ajaxAddTag($element, $id, $tagString) { $filter = JFilterInput::getInstance(); $id = $filter->clean($id, 'int'); $tagString = $filter->clean($tagString, 'string'); $element = $filter->clean($element, 'string'); $objResponse = new JAXResponse(); // @todo: make sure user has the permission CFactory::load('libraries', 'tags'); $tags = new CTags(); $tagString = JString::trim($tagString); // If there is only 1 word, add a space so thet the next 'explode' call works $tagStrings = explode(',', $tagString); // @todo: limit string lenght foreach ($tagStrings as $row) { // Need to trim unwanted char $row = JString::trim($row, " ,;:"); // For each tag, we ucwords them for consistency $row = ucwords($row); // @todo: Send out warning or error message that the string is too short if (JString::strlen($row) >= CTags::MIN_LENGTH) { // Only add to the tag list if add is successful if ($tags->add($element, $id, $row)) { // @todo: get last tag id inserted $tagid = $tags->lastInsertId(); // urlescape the string $row = CTemplate::escape($row); $objResponse->addScriptCall("joms.jQuery('#tag-list').append", "<li id=\"tag-" . $tagid . "\"><span class=\"tag-token\"><a href=\"javascript:void(0);\" onclick=\"joms.tag.list('" . $row . "')\">{$row}</a><a href=\"javascript:void(0);\" style=\"display:block\" class=\"tag-delete\" onclick=\"joms.tag.remove('" . $tagid . "')\">x</a></span></li>"); } } } $objResponse->addScriptCall('joms.jQuery(\'#tag-addbox\').val', ''); return $objResponse->sendResponse(); }