public function writeText(StreamInterface $stream, Website $website, $id, $data) { $title = htmlSpecialChars($data["title"]); $amount = (int) $data["amount"]; $commentLookup = new CommentRepository($website->getDatabase()); $latestComments = $commentLookup->getCommentsLatest($amount); $view = new CommentsSmallTemplate($website->getText(), $latestComments); $stream->write('<h2>' . $title . "</h2>\n"); $view->writeText($stream); }
public function init(Website $website, Request $request) { $articleId = $request->getParamInt(0); $oArticles = new ArticleRepository($website); $this->article = $oArticles->getArticleOrFail($articleId); $this->editLinks = $website->isLoggedInAsStaff(); $this->currentUser = $website->getAuth()->getCurrentUser(); if ($this->article->showComments) { $oComments = new CommentRepository($website->getDatabase()); $this->comments = $oComments->getCommentsArticle($this->article->getId()); } else { $this->comments = []; } }
public function init(Website $website, Request $request) { $commentId = $request->getParamInt(0, 0); $repo = new CommentRepository($website->getDatabase()); $this->comment = $repo->getCommentOrFail($commentId); $user = $website->getAuth()->getCurrentUser(); // Check if user is allowed to delete this comment if ($user->getId() !== $this->comment->getUserId() && !$user->hasRank(Authentication::RANK_MODERATOR)) { throw new NotFoundException(); } // Check if form was submitted if (Validate::requestToken($request)) { $repo->deleteComment($commentId); $text = $website->getText(); $articleLink = $text->getUrlPage("article", $this->comment->getArticleId()); $text->addMessage($text->t("comments.comment") . ' ' . $text->t("editor.is_deleted"), Link::of($articleLink, $text->t("main.ok"))); } else { $this->requestToken = RequestToken::generateNew(); $this->requestToken->saveToSession(); } }
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(); }
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(); }
/** Returns the HTML of the comments of the user, including the header */ public function get_comments_html(Website $website) { $oComments = new CommentRepository($website->getDatabase()); $comments = $oComments->getCommentsUser($this->user->getId()); $returnValue = '<h3 class="notable">' . $website->t("comments.comments") . "</h3>\n"; if (count($comments) > 0) { $commentsTemplate = new CommentsTreeTemplate($website->getText(), $comments, true, $this->user); $returnValue .= $commentsTemplate->getText(); } else { $returnValue .= "<p><em>" . $website->t("comments.no_comments_found_user") . "</em></p>"; } return $returnValue; }
public function init(Website $website, Request $request) { $oComments = new CommentRepository($website->getDatabase()); $this->comments = $oComments->getCommentsLatest(); $this->viewingUser = $website->getAuth()->getCurrentUser(); }