protected function _validate($comment) { // get params $require_author = $this->params->get('require_name_and_mail', 0); $registered = $this->params->get('registered_users_only', 0); $time_between_user_posts = $this->params->get('time_between_user_posts', 120); $blacklist = $this->params->get('blacklist', ''); // check if related item exists if (YTable::getInstance('item')->get($comment->item_id) === null) { throw new CommentControllerException('Related item does not exists.'); } // check if content is empty if (empty($comment->content)) { throw new CommentControllerException('Please enter a comment.'); } // only registered users can comment if ($registered && $this->author->isGuest()) { throw new CommentControllerException('LOGIN_TO_LEAVE_OMMENT'); } // validate required name/email if ($this->author->isGuest() && $require_author && (empty($comment->author) || empty($comment->email))) { throw new CommentControllerException('Please enter the required fields author and email.'); } // validate email format if (!empty($comment->email) && !CommentHelper::validateEmail($comment->email)) { throw new CommentControllerException('Please enter a valid email address.'); } // validate url format if (!empty($comment->url) && !CommentHelper::validateURL($comment->url)) { throw new CommentControllerException('Please enter a valid website link.'); } // check quick multiple posts if ($last = YTable::getInstance('comment')->getLastComment($comment->ip, $this->author)) { if (JFactory::getDate($comment->created)->toUnix() < JFactory::getDate($last->created)->toUnix() + $time_between_user_posts) { throw new CommentControllerException('You are posting comments too quickly. Slow down a bit.'); } } // check against spam blacklist if (CommentHelper::matchWords($comment, $blacklist) && $comment->state != Comment::STATE_SPAM) { $comment->state = Comment::STATE_SPAM; } // check comment for spam (akismet) if ($this->params->get('akismet_enable', 0) && $comment->state != Comment::STATE_SPAM) { try { CommentHelper::akismet($comment, $this->params->get('akismet_api_key')); } catch (Exception $e) { // re-throw exception, for super administrators only if ($this->user->superadmin) { throw new YException($e->getMessage()); } } } // check comment for spam (mollom) if ($this->params->get('mollom_enable', 0) && $comment->state != Comment::STATE_SPAM) { try { CommentHelper::mollom($comment, $this->params->get('mollom_public_key'), $this->params->get('mollom_private_key')); } catch (Exception $e) { // re-throw exception, for super administrators only if ($this->user->superadmin) { throw new YException($e->getMessage()); } } } }