/**
  * Validator to check that mail is valid
  *
  * @param Comment $comment Comment model to validate
  * @return bool
  */
 protected function mailIsValid(Comment $comment)
 {
     return $GLOBALS['TSFE']->fe_user->user['uid'] || is_string($comment->getAuthorMail()) && GeneralUtility::validEmail($comment->getAuthorMail());
 }
 /**
  * Create action
  *
  * @param Comment $newComment
  * @return bool
  * @dontverifyrequesthash
  */
 public function createAction(Comment $newComment = NULL)
 {
     // Hidden field Spam-Protection
     if ($this->settings['hiddenFieldSpamProtection'] && $this->request->hasArgument($this->settings['hiddenFieldName']) && $this->request->getArgument($this->settings['hiddenFieldName'])) {
         $this->redirectToURI($this->buildUriByUid($this->pageUid) . '#' . $this->settings['writeCommentAnchor']);
         return FALSE;
     }
     if ($newComment === NULL) {
         $this->redirectToURI($this->buildUriByUid($this->pageUid));
         return FALSE;
     }
     $this->createAuthorIdent();
     $newComment->setPid($this->pageUid);
     $newComment->setEntryUid($this->entryUid);
     $newComment->setAuthorIdent($this->currentAuthorIdent);
     $author = NULL;
     if ($this->currentUser['uid']) {
         $author = $this->frontendUserRepository->findByUid($this->currentUser['uid']);
     }
     if ($author !== NULL) {
         $newComment->setAuthor($author);
     } else {
         $newComment->setAuthor(NULL);
         $GLOBALS['TSFE']->fe_user->setKey('ses', 'tx_pwcomments_unregistredUserName', $newComment->getAuthorName());
         $GLOBALS['TSFE']->fe_user->setKey('ses', 'tx_pwcomments_unregistredUserMail', $newComment->getAuthorMail());
     }
     $GLOBALS['TSFE']->fe_user->setKey('ses', 'tx_pwcomments_lastComment', time());
     $translateArguments = array('name' => $newComment->getAuthorName(), 'email' => $newComment->getAuthorMail(), 'message' => $newComment->getMessage());
     // Modify comment if moderation is active
     if ($this->settings['moderateNewComments']) {
         $newComment->setHidden(TRUE);
         $this->addFlashMessage(LocalizationUtility::translate('tx_pwcomments.moderationNotice', 'PwComments', $translateArguments));
     } else {
         $this->addFlashMessage(LocalizationUtility::translate('tx_pwcomments.thanks', 'PwComments', $translateArguments));
     }
     $this->commentRepository->add($newComment);
     $this->getPersistenceManager()->persistAll();
     if ($this->settings['sendMailOnNewCommentsTo']) {
         $this->mailUtility->setSettings($this->settings);
         $this->mailUtility->setFluidTemplate($this->makeFluidTemplateObject());
         $this->mailUtility->setControllerContext($this->controllerContext);
         $this->mailUtility->setReceivers($this->settings['sendMailOnNewCommentsTo']);
         $this->mailUtility->setTemplatePath($this->settings['sendMailTemplate']);
         $this->mailUtility->sendMail($newComment);
     }
     if ($this->settings['sendMailToAuthorAfterSubmit'] && $newComment->hasCommentAuthorMailAddress()) {
         $this->mailUtility->setSettings($this->settings);
         $this->mailUtility->setFluidTemplate($this->makeFluidTemplateObject());
         $this->mailUtility->setControllerContext($this->controllerContext);
         $this->mailUtility->setReceivers($newComment->getCommentAuthorMailAddress());
         $this->mailUtility->setTemplatePath($this->settings['sendMailToAuthorAfterSubmitTemplate']);
         $this->mailUtility->sendMail($newComment);
     }
     if ($this->settings['moderateNewComments']) {
         $anchor = '#' . $this->settings['successfulAnchor'];
     } else {
         $anchor = '#' . $this->settings['commentAnchorPrefix'] . $newComment->getUid();
     }
     $this->redirectToURI($this->buildUriByUid($this->pageUid, TRUE) . $anchor);
     return FALSE;
 }