/**
  * Add keyword
  */
 function editTags()
 {
     JRequest::checkToken() or die('Invalid Token');
     //$user =& JFactory::getUser();
     //$model =& $this->getModel('akseo');
     $id = JRequest::getInt('artid');
     $newTag = JRequest::getWord('newTag');
     $tagArray = JRequest::getVar('tags', '', 'post', 'array');
     $tagEdit = JRequest::getInt('tagEdit');
     $row =& JTable::getInstance('content');
     $row->load($id);
     //if tags selected, remove from keywords
     if (isset($tagArray) and !empty($tagArray)) {
         $keywordArray = explode(",", $row->metakey);
         $newKeys = array_diff($keywordArray, $tagArray);
         $row->metakey = implode(",", $newKeys);
     }
     if (isset($newTag)) {
         $row->metakey = $row->metakey . ', ' . $newTag;
     }
     if (isset($newTag) or isset($newKeys)) {
         if (!$row->save($row)) {
             return JError::raiseWarning(500, $row->getError());
         }
     }
     //$article = $model->getOptions($user->id);
     return plgSystemAddKeywords::tagList($row, $addkeyParams = null, $tagEdit, $ajax = 1);
 }
 public function onPrepareContent(&$article, &$params, $limitstart = 0)
 {
     $app =& JFactory::getApplication();
     $doc =& JFactory::getDocument();
     $user =& JFactory::getUser();
     if ($app->isAdmin()) {
         return true;
     }
     $docType = $doc->getType();
     if ($docType != 'html') {
         return true;
     }
     if (isset($article) and (!isset($article->id) or is_null($article->id))) {
         return true;
     }
     if (!$this->addkeyParams->tags and !$this->addkeyParams->relatedItems) {
         return true;
     }
     $view = JRequest::getWord('view');
     $layout = JRequest::getWord('layout');
     $Itemid = JRequest::getInt('Itemid');
     if (($view == 'frontpage' or $view == 'newsportal') and !$this->addkeyParams->frontTag) {
         return true;
     }
     if ($layout == 'blog' and !$this->addkeyParams->blogTag) {
         return true;
     }
     if ($layout != 'blog' and ($view == 'category' or $view == 'section')) {
         return true;
     }
     //exclude certain sections/categories/menus and/or articles
     if (isset($this->addkeyParams->frontMenuid)) {
         if (plgSystemAddKeywords::exclude($Itemid, $this->addkeyParams->frontMenuid)) {
             return true;
         }
     }
     if (isset($this->addkeyParams->frontSecid) and isset($article->sectionid)) {
         if (plgSystemAddKeywords::exclude($article->sectionid, $this->addkeyParams->frontSecid)) {
             return true;
         }
     }
     if (isset($this->addkeyParams->frontCatid) and isset($article->catid)) {
         if (plgSystemAddKeywords::exclude($article->catid, $this->addkeyParams->frontCatid)) {
             return true;
         }
     }
     //looks like we're finally doing it...
     $html = '';
     if ($this->addkeyParams->tags) {
         $tagEdit = 0;
         $tagButton = '';
         //Ajax stuff for front-end editing
         if ($this->addkeyParams->addTag and $user->id and $user->gid >= $this->addkeyParams->addTagUsers and $view != 'frontpage' and $layout != 'blog') {
             $script = "\n\t\t\t\twindow.addEvent( 'domready', function() {\n\t\t\t\t\t\$('ak_addForm').addEvent('submit', function(e) {\n\t\t\t\t\t\tnew Event(e).stop();\n\t\t\t\t\t\t\$('ak_addFormDiv').setStyle('display', 'none');\n\t\t\t\t\t\t\$('ak_addButton').setStyle('display', '');\n\t\t\t\t\t\tvar tagproc = \$('ak_tagDiv').empty().addClass('ajax-loading').setStyle('display', 'block');\n\t\t\t\t\t\tthis.send({\n\t\t\t\t\t\t\tupdate: tagproc,\n\t\t\t\t\t\t\tonComplete: function() {\n\t\t\t\t\t\t\t\ttagproc.removeClass('ajax-loading');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t\t\$('ak_addButton').addEvent('submit', function(e) {\n\t\t\t\t\t\tnew Event(e).stop();\n\t\t\t\t\t\t\$('ak_addButton').setStyle('display', 'none');\n\t\t\t\t\t\t\$('ak_tagDiv').setStyle('display', 'none');\n\t\t\t\t\t\tvar myClone = \$('ak_addForm').clone().cloneEvents(\$('ak_addForm'));\n\t\t\t\t\t\tvar formproc = \$('ak_addFormDiv').addClass('ajax-loading').setStyle('display', 'block');\n\t\t\t\t\t\tthis.send({\n\t\t\t\t\t\t\tupdate: formproc,\n\t\t\t\t\t\t\tonComplete: function() {\n\t\t\t\t\t\t\t\tformproc.removeClass('ajax-loading');\n\t\t\t\t\t\t\t\t\$\$('#ak_addForm').each(function(el) {\n\t\t\t\t\t\t\t\t\tel.cloneEvents(myClone);\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t});";
             $doc->addScriptDeclaration($script);
             $tagButton = '<form id="ak_addButton" method="post" action="' . JURI::base() . 'index.php">' . '<input type="image" style="float:right;" src="images/M_images/edit.png" alt="Edit Tags" />' . '<input type="hidden" name="ak_id" value="' . $article->id . '" />' . '<input type="hidden" name="ak_tagEdit" value="1" />' . '<input type="hidden" name="check" value="post" />' . '<input type="hidden" name="option" value="com_akseo" />' . '<input type="hidden" name="controller" value="akseo" />' . '<input type="hidden" name="task" value="editTags" />' . JHTML::_('form.token') . '</form>';
             $tagEdit = 1;
         }
         $akstyle = 'ul#ak_tagList { ' . $this->addkeyParams->ulStyle . ' }';
         $akstyle .= 'ul#ak_tagList li { ' . $this->addkeyParams->liStyle . ' }';
         $doc->addStyleDeclaration($akstyle);
         $html = '<br /><div id="ak_tags">';
         if ($this->addkeyParams->tagFieldset) {
             $html .= '<fieldset><legend>' . $this->addkeyParams->tagTitle . '</legend>';
         }
         $html .= $tagButton;
         $tags = plgSystemAddKeywords::tagList($article, $this->addkeyParams, 0, $ajax = 0);
         $tagEdit ? $tagForm = plgSystemAddKeywords::tagList($article, $this->addkeyParams, 1, $ajax = 0) : ($tagForm = '');
         $html .= '<div id="ak_tagDiv">' . $tags . '</div><div id="ak_addFormDiv" style="display:none;">' . $tagForm . '</div>';
         if ($this->addkeyParams->tagFieldset) {
             $html .= '</fieldset>';
         }
         $html .= '</div>';
     }
     //add a related items module
     if ($this->addkeyParams->relatedItems) {
         $module = plgSystemAddKeywords::_load($this->addkeyParams->modName, $this->addkeyParams->modStyle);
         $html .= '<br /><div id="ak_related">';
         if ($this->addkeyParams->modFieldset) {
             $html .= '<fieldset><legend>' . $this->addkeyParams->modTitle . '</legend>';
         }
         $html .= $module;
         if ($this->addkeyParams->modFieldset) {
             $html .= '</fieldset>';
         }
         $html .= '</div>';
     }
     $article->text .= $html;
     return true;
 }