示例#1
0
 public function init(Website $website, Request $request)
 {
     $text = $website->getText();
     $this->requestToken = RequestToken::generateNew();
     $articleId = $request->getParamInt(0, 0);
     $articleRepo = new ArticleRepository($website);
     $article = $articleRepo->getArticleOrFail($articleId);
     if (!$article->showComments) {
         $text->addError($text->t("comments.commenting_not_allowed_on_article"));
         return;
     }
     $user = $website->getAuth()->getCurrentUser();
     $this->comment = $this->fetchComment($request, $article, $user);
     if ($request->hasRequestValue("submit") && Validate::requestToken($request)) {
         // Validate and save comment
         $repo = new CommentRepository($website->getDatabase());
         if ($repo->validateComment($this->comment, $text)) {
             $repo->saveComment($this->comment);
             $this->redirectLink = $this->comment->getUrl($text);
         }
     }
     $this->requestToken->saveToSession();
 }
示例#2
0
 public function init(Website $website, Request $request)
 {
     $text = $website->getText();
     $this->requestToken = RequestToken::generateNew();
     $commentId = $request->getParamInt(0, 0);
     $auth = $website->getAuth();
     $user = $auth->getCurrentUser();
     $repo = new CommentRepository($website->getDatabase());
     $this->comment = $repo->getCommentOrFail($commentId);
     if ($user->getId() !== $this->comment->getUserId() && !$user->hasRank(Authentication::RANK_MODERATOR)) {
         // Can only edit own comment unless moderator
         throw new NotFoundException();
     }
     if ($request->hasRequestValue("submit") && Validate::requestToken($request)) {
         // Validate and save comment
         $this->updateCommentFromRequest($this->comment, $request);
         if ($repo->validateComment($this->comment, $text)) {
             $repo->saveComment($this->comment);
             $this->redirectLink = $this->comment->getUrl($text);
         }
     }
     $this->requestToken->saveToSession();
 }