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; }
<?php defined('_JEXEC') or die('Restricted access'); ?> <div id="phocagallery-comments"> <?php echo '<div style="font-size:1px;height:1px;margin:0px;padding:0px;"> </div>'; //because of IE bug if (!empty($this->commentitem)) { $userImage = JHTML::_('image.site', 'components/com_phocagallery/assets/images/icon-user.' . $this->tmpl['formaticon'], '', '', '', '', ''); $smileys = PhocaGalleryHelperComment::getSmileys(); foreach ($this->commentitem as $itemValue) { $date = JHTML::_('date', $itemValue->date, JText::_('DATE_FORMAT_LC2')); $comment = $itemValue->comment; $comment = PhocaGalleryHelperComment::bbCodeReplace($comment); foreach ($smileys as $smileyKey => $smileyValue) { $comment = str_replace($smileyKey, JHTML::_('image.site', 'components/com_phocagallery/assets/images/' . $smileyValue . '.' . $this->tmpl['formaticon'], '', '', '', '', ''), $comment); } echo '<fieldset>' . '<legend>' . $userImage . ' ' . $itemValue->username . '</legend>' . '<p><strong>' . PhocaGalleryHelperFront::wordDelete($itemValue->title, 50, '...') . '</strong></p>' . '<p style="overflow:auto;width:' . $this->tmpl['commentwidth'] . 'px;">' . $comment . '</p>' . '<p style="text-align:right"><small>' . $date . '</small></p>' . '</fieldset>'; } } echo '<fieldset>' . '<legend>' . JText::_('Add comment') . '</legend>'; if ($this->tmpl['alreadycommented']) { echo '<p>' . JText::_('You have already submitted comment') . '</p>'; } else { if ($this->tmpl['notregistered']) { echo '<p>' . JText::_('Only registered and logged in user can submit a comment') . '</p>'; } else { ?> <form action="<?php
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); }