public function saveCommentAction()
 {
     if (!Config::get('commentsEnabled')) {
         $this->return404();
     }
     $this->viewClass = "JsonView";
     $siteId = $this->request->itemId;
     $site = $this->site->findByPk($siteId);
     if (empty($site)) {
         return $this->return404();
     }
     $errorMessage = $this->comment->validate($this->request);
     if (Config::get('captchaEnabledOnComments') && !$errorMessage && !$this->captchaCode->validatePublicAndPrivateCodes($this->request)) {
         $errorMessage = 'You did not guess the security code.';
     }
     if (empty($errorMessage)) {
         $comment = new CommentRecord();
         $comment->fromArray($this->request->getArray(array("pseudo", "text", "rating")));
         $comment->siteId = $site->siteId;
         $comment->validated = Config::get("automaticCommentValidation") ? 1 : 0;
         $comment->remoteIp = $this->request->getIp();
         $comment->save();
         if (Config::get("sendEmailsOnComment")) {
             Mailer::getInstance()->sendNewCommentNotificationToAdmin($site);
         }
         $this->comment->setSiteCookie($site->siteId);
         $this->set("status", "ok");
         if (Config::get("automaticCommentValidation")) {
             $this->set("message", _t('Your comment was saved'));
         } else {
             $this->set("message", _t('Your comment was saved. He is awaiting moderation and will be published if it is useful for surfers'));
         }
     } else {
         $this->set("status", "error");
         $this->set("message", _t($errorMessage));
     }
 }