public function init(Website $website, Request $request) { $text = $website->getText(); $articleId = $request->getParamInt(0); $showAdminPageLink = $website->isLoggedInAsStaff(true); $oArticles = new ArticleRepository($website); $article = $oArticles->getArticleOrFail($articleId); $this->article = $article; $formToken = RequestToken::generateNew(); $action = $request->getRequestString("action"); if ($action == "delete" && Validate::requestToken($request)) { // Bye bye article if ($oArticles->delete($article)) { $this->view = new ArticleDeleteTemplate($text, $article, $formToken, $showAdminPageLink, ArticleDeleteTemplate::STATE_DELETED); } else { $this->view = new ArticleDeleteTemplate($text, $article, $formToken, $showAdminPageLink, ArticleDeleteTemplate::STATE_ERROR); } return; } elseif ($action == "make_private" && Validate::requestToken($request)) { // Hide article for visitors $article->setHidden(true); if ($oArticles->saveArticle($article)) { $this->view = new ArticleDeleteTemplate($text, $article, $formToken, $showAdminPageLink, ArticleDeleteTemplate::STATE_HIDDEN); } else { $this->view = new ArticleDeleteTemplate($text, $article, $formToken, $showAdminPageLink, ArticleDeleteTemplate::STATE_ERROR); } return; } else { // Ask what to do $this->view = new ArticleDeleteTemplate($text, $article, $formToken, $showAdminPageLink, ArticleDeleteTemplate::STATE_CONFIRMATION); } $formToken->saveToSession(); }
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) { $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(); }
/** * Gets the article with the given id. If the id is 0, a new article is * created. * @param ArticleRepository $repository Repository to fetch articles from. * @param User $currentUser Becomes the author if a new article is created. * @param int $id Id of the article. Use 0 to create a new article. * @return Article The article. * @throws NotFoundException If no article exists with the given id. */ protected function getArticle(ArticleRepository $repository, User $currentUser, $id) { if ($id === 0) { $article = new Article(); $article->setAuthor($currentUser); return $article; } else { $article = $repository->getArticleOrFail($id); if ($article->authorId === 0) { // There was a bug in previous versions of the CMS where the // author wasn't saved $article->setAuthor($currentUser); } return $article; } }