Ejemplo n.º 1
0
 /**
  * Request-Handler
  * @return boolean
  */
 public function request()
 {
     if (!$this->maintenanceMode()) {
         return false;
     }
     $this->isUtf8 = defined('FPCM_PUB_OUTPUT_UTF8') ? FPCM_PUB_OUTPUT_UTF8 : true;
     $this->crons->registerCron('postponedArticles');
     if ($this->iplist->ipIsLocked()) {
         $this->view->addErrorMessage('ERROR_IP_LOCKED');
         $this->view->assign('showToolbars', false);
         $this->view->render();
         return false;
     }
     if (is_null($this->getRequestVar('id'))) {
         $this->view->addErrorMessage('LOAD_FAILED_ARTICLE');
         return true;
     }
     $this->articleId = $this->getRequestVar('id');
     $srcData = explode('-', $this->articleId, 2);
     $this->articleId = (int) $srcData[0];
     $this->article = new \fpcm\model\articles\article($this->articleId);
     if (!$this->article->exists()) {
         $this->view->addErrorMessage('LOAD_FAILED_ARTICLE');
         $this->article = false;
         return true;
     }
     $this->cache = new \fpcm\classes\cache(\fpcm\model\articles\article::CACHE_ARTICLE_SINGLE . $this->article, \fpcm\model\articles\article::CACHE_ARTICLE_MODULE);
     $this->articleTemplate = new \fpcm\model\pubtemplates\article($this->config->article_template_active);
     if ($this->config->system_comments_enabled && $this->article->getComments()) {
         $this->initSpamCaptcha();
         $this->newComment = new \fpcm\model\comments\comment();
         $this->commentTemplate = new \fpcm\model\pubtemplates\comment($this->config->comments_template_active);
         $this->commentFormTemplate = new \fpcm\model\pubtemplates\commentform();
         if ($this->buttonClicked('sendComment') && !is_null($this->getRequestVar('newcomment')) && !$this->iplist->ipIsLocked() && !$this->iplist->ipIsLocked('nocomments')) {
             $newCommentData = $this->getRequestVar('newcomment');
             $timer = time();
             if ($timer <= $this->commentList->getLastCommentTimeByIP() + $this->config->comments_flood) {
                 $this->view->addErrorMessage('PUBLIC_FAILED_FLOOD', array('{{seconds}}' => $this->config->comments_flood));
                 return true;
             }
             if (!$this->captcha->checkAnswer()) {
                 $this->view->addErrorMessage('PUBLIC_FAILED_CAPTCHA');
                 return true;
             }
             if (!$newCommentData['name']) {
                 $this->view->addErrorMessage('PUBLIC_FAILED_NAME');
                 return true;
             }
             $newCommentData['email'] = filter_var($newCommentData['email'], FILTER_VALIDATE_EMAIL);
             if ($this->config->comments_email_optional && !$newCommentData['email']) {
                 $this->view->addErrorMessage('PUBLIC_FAILED_EMAIL');
                 return true;
             }
             $newCommentData['website'] = filter_var($newCommentData['website'], FILTER_VALIDATE_URL);
             $newCommentData['website'] = $newCommentData['website'] ? $newCommentData['website'] : '';
             $this->newComment->setName($newCommentData['name']);
             $this->newComment->setEmail($newCommentData['email']);
             $this->newComment->setWebsite($newCommentData['website']);
             $this->newComment->setText(nl2br(strip_tags($newCommentData['text'], \fpcm\model\comments\comment::COMMENT_TEXT_HTMLTAGS_CHECK)));
             $this->newComment->setPrivate(isset($newCommentData['private']));
             $this->newComment->setIpaddress(\fpcm\classes\http::getIp());
             $this->newComment->setApproved($this->config->comments_confirm ? false : true);
             $this->newComment->setArticleid($this->articleId);
             $this->newComment->setCreatetime($timer);
             $this->newComment->setSpammer(!$this->session->exists() && $this->captcha->checkExtras() ? true : false);
             if (!$this->newComment->save()) {
                 $this->view->addErrorMessage('SAVE_FAILED_COMMENT');
                 return true;
             }
             $this->view->addNoticeMessage('SAVE_SUCCESS_COMMENT');
             $text = $this->lang->translate('PUBLIC_COMMENT_EMAIL_TEXT', array('{{name}}' => $this->newComment->getName(), '{{email}}' => $this->newComment->getEmail(), '{{commenttext}}' => strip_tags($this->newComment->getText()), '{{articleurl}}' => $this->article->getArticleLink(), '{{systemurl}}' => \fpcm\classes\baseconfig::$rootPath));
             $to = array();
             if ($this->config->comments_notify != 1) {
                 $to[] = $this->config->system_email;
             }
             if ($this->config->comments_notify > 0 && !$this->session->exists()) {
                 $to[] = $this->userList->getEmailByUserId($this->article->getCreateuser());
             }
             if (!count($to) || $this->session->exists()) {
                 return true;
             }
             $email = new \fpcm\classes\email(implode(',', array_unique($to)), $this->lang->translate('PUBLIC_COMMENT_EMAIL_SUBJECT'), $text);
             $email->submit();
         }
     }
     return true;
 }