function closeTags($comment, $tag, $endTag) { if (substr_count(strtolower($comment), $tag) > substr_count(strtolower($comment), $endTag)) { $comment .= $endTag; $comment = PhocaGalleryHelperComment::closeTags($comment, $tag, $endTag); } return $comment; }
function comment() { JRequest::checkToken() or jexit('Invalid Token'); global $mainframe; $user =& JFactory::getUser(); $view = JRequest::getVar('view', '', 'post', '', 0); $catid = JRequest::getVar('catid', '', 'post', 'string', 0); $post['title'] = JRequest::getVar('phocagallerycommentstitle', '', 'post', 'string', 0); $post['comment'] = JRequest::getVar('phocagallerycommentseditor', '', 'post', 'string', 0); $Itemid = JRequest::getVar('Itemid', 0, '', 'int'); $limitStart = JRequest::getVar('limitstart', 0, '', 'int'); $tab = JRequest::getVar('tab', 0, '', 'int'); $paramsC = JComponentHelper::getParams('com_phocagallery'); $maxCommentChar = $paramsC->get('max_comment_char', 1000); // Maximum of character, they will be saved in database $post['comment'] = substr($post['comment'], 0, (int) $maxCommentChar); // Close Tags $post['comment'] = PhocaGalleryHelperComment::closeTags($post['comment'], '[u]', '[/u]'); $post['comment'] = PhocaGalleryHelperComment::closeTags($post['comment'], '[i]', '[/i]'); $post['comment'] = PhocaGalleryHelperComment::closeTags($post['comment'], '[b]', '[/b]'); $post['catid'] = (int) $catid; $post['userid'] = $user->id; $catidAlias = $catid; //Itemid if ($view != 'category') { $this->setRedirect(JRoute::_('index.php?option=com_phocagallery', false)); } $model = $this->getModel('category'); $checkUserComment = $model->checkUserComment($post['catid'], $post['userid']); // User has already submitted a comment if ($checkUserComment) { $msg = JText::_('You have already submitted comment'); } else { // If javascript will not protect the empty form $msg = ''; $emptyForm = 0; if ($post['title'] == '') { $msg .= JText::_('Error Comment Phoca Gallery - Title') . ' '; $emtyForm = 1; } if ($post['comment'] == '') { $msg .= JText::_('Error Comment Phoca Gallery - Comment'); $emtyForm = 1; } if ($emptyForm == 0) { if ($user->aid > 0 && $user->id > 0) { if (!$model->comment($post)) { $msg = JText::_('Error Comment Phoca Gallery'); } else { $msg = JText::_('Phoca Gallery Comment Submitted'); } } else { $mainframe->redirect(JRoute::_('index.php?option=com_user&view=login', false), JText::_("NOT AUTHORISED TO DO ACTION")); exit; } } } // Limit Start $countItem = $model->countItem((int) $catid); if ($countItem) { if ((int) $countItem[0] == $limitStart) { $limitStart = 0; } } else { $limitStart = 0; } if ($limitStart > 0) { $limitStartUrl = '&limitstart=' . $limitStart; } else { $limitStartUrl = ''; } $this->setRedirect(JRoute::_('index.php?option=com_phocagallery&view=category&id=' . $catidAlias . '&tab=' . $tab . '&Itemid=' . $Itemid . $limitStartUrl, false), $msg); }