Example #1
0
 public function init(Website $website, Request $request)
 {
     $userId = $request->getParamInt(0);
     if ($userId === 0) {
         // Use current user
         $this->user = $website->getAuth()->getCurrentUser();
         if ($this->user == null) {
             throw new NotFoundException();
         }
     } else {
         // Use provided user
         $this->user = $website->getAuth()->getUserRepository()->getById($userId);
     }
     if ($this->user !== null) {
         // Don't display banned/deleted users
         if (!$this->user->canLogIn()) {
             if (!$website->isLoggedInAsStaff()) {
                 // Staff can view everyone
                 $this->user = null;
             }
         }
     }
     if ($this->user === null) {
         // Trigger 404
         throw new NotFoundException();
     }
 }
Example #2
0
 public function init(Website $website, Request $request)
 {
     $this->installedWidgets = $website->getWidgets();
     $widgetRepo = new WidgetRepository($website);
     $widgetId = $request->getParamInt(0);
     if ($widgetId === 0) {
         // New widget
         $this->placedWidget = $this->getNewWidget($website, $request);
     } else {
         $this->placedWidget = $widgetRepo->getPlacedWidget($widgetId);
     }
     if ($request->hasRequestValue("submit") && Validate::requestToken($request)) {
         // Use incoming data
         $widgetDefinition = $this->installedWidgets->getDefinition($this->placedWidget);
         $data = $widgetDefinition->parseData($website, $widgetId);
         $this->placedWidget->setData($data);
         if ($this->isValid($data)) {
             // Save widget
             $widgetRepo->savePlacedWidget($this->placedWidget);
             $this->addSaveMessage($this->placedWidget, $website->getText());
         }
     }
     $this->requestToken = RequestToken::generateNew();
     $this->requestToken->saveToSession();
 }
Example #3
0
 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();
 }
Example #4
0
 public function init(Website $website, Request $request)
 {
     $menuId = $request->getParamInt(0, 0);
     $menuRepo = new MenuRepository($website->getDatabase());
     $linkRepo = new LinkRepository($website->getDatabase());
     $this->menu = $menuRepo->getMenu($menuId);
     $this->links = $linkRepo->getLinksByMenu($menuId);
 }
Example #5
0
 public function init(Website $website, Request $request)
 {
     $categoryId = $request->getParamInt(0, 0);
     $categoriesRepo = new CategoryRepository($website->getDatabase());
     $this->category = $categoriesRepo->getCategory($categoryId);
     $articlesRepo = new ArticleRepository($website);
     $this->articles = $articlesRepo->getArticlesData($categoryId);
     $this->showArticleEditLinks = $website->isLoggedInAsStaff();
     $this->showCategoryEditLinks = $website->isLoggedInAsStaff(true);
 }
Example #6
0
 public function init(Website $website, Request $request)
 {
     $linkId = $request->getParamInt(0, 0);
     $linkRepo = new LinkRepository($website->getDatabase());
     $this->link = $linkRepo->getLink($linkId);
     if (Validate::requestToken($request)) {
         $this->deleteLink($linkRepo, $website->getText());
     }
     $this->requestToken = RequestToken::generateNew();
     $this->requestToken->saveToSession();
 }
Example #7
0
 public function init(Website $website, Request $request)
 {
     $oArticles = new ArticleRepository($website);
     $yearNumber = $request->getParamInt(0, date('Y'));
     if ($yearNumber < self::MIN_YEAR || $yearNumber > self::MAX_YEAR) {
         $yearNumber = date('Y');
     }
     $this->year = DateTime::createFromFormat('Y', $yearNumber);
     $this->yearNumber = $yearNumber;
     $this->articlesInYear = $oArticles->getArticlesDataCalendarYear($this->year);
     $this->showCreateLinks = $website->isLoggedInAsStaff();
 }
Example #8
0
 public function init(Website $website, Request $request)
 {
     $menuId = $request->getParamInt(0, 0);
     $menuRepo = new MenuRepository($website->getDatabase());
     $this->menu = $menuRepo->getMenu($menuId);
     $this->menu->setName($request->getRequestString("menu_name", $this->menu->getName()));
     if (Validate::requestToken($request)) {
         $this->trySaveMenu($menuRepo, $website->getText());
     }
     $this->requestToken = RequestToken::generateNew();
     $this->requestToken->saveToSession();
 }
Example #9
0
 public function init(Website $website, Request $request)
 {
     $menuId = $request->getParamInt(0, 0);
     $menuRepo = new MenuRepository($website->getDatabase());
     $this->menu = $menuRepo->getMenu($menuId);
     $this->linkName = $request->getRequestString("link_text", "");
     $this->linkUrl = $request->getRequestString("link_url", "");
     if (Validate::requestToken($request)) {
         $this->saveLink($website);
     }
     $this->requestToken = RequestToken::generateNew();
     $this->requestToken->saveToSession();
 }
Example #10
0
 public function init(Website $website, Request $request)
 {
     $isStaff = $website->isLoggedInAsStaff();
     $id = $request->getParamInt(0);
     $this->editLinks = $website->isLoggedInAsStaff(true);
     // Load document
     $documentRepo = new DocumentRepository($website->getDatabase(), $isStaff);
     $this->document = $documentRepo->getDocument($id);
     // Load document widgets
     $this->widgetLoader = $website->getWidgets();
     $widgetRepo = new WidgetRepository($website);
     $this->widgets = $widgetRepo->getWidgetsInDocumentWithId($id);
 }
Example #11
0
 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 = [];
     }
 }
Example #12
0
 public function init(Website $website, Request $request)
 {
     $userId = $request->getParamInt(0);
     // Fetch user
     $userRepo = $website->getAuth()->getUserRepository();
     $user = $userRepo->getById($userId);
     if (!$user->canLogIn()) {
         // Can't log in to deleted or banned users
         throw new NotFoundException();
     }
     // Set user
     $this->newUser = $user;
     $website->getAuth()->setCurrentUser($user);
 }
Example #13
0
 public function init(Website $website, Request $request)
 {
     $this->installedWidgets = $website->getWidgets();
     $widgetId = $request->getParamInt(0, 0);
     $widgetRepo = new WidgetRepository($website);
     $this->placedWidget = $widgetRepo->getPlacedWidget($widgetId);
     if (Validate::requestToken($request)) {
         $widgetRepo->deletePlacedWidget($this->placedWidget);
         $text = $website->getText();
         $text->addMessage($text->t("main.widget") . ' ' . $text->t("editor.is_deleted"), Link::of($text->getUrlPage("edit_document", $this->placedWidget->getDocumentId()), $text->t("main.ok")));
     } else {
         $this->requestToken = RequestToken::generateNew();
         $this->requestToken->saveToSession();
     }
 }
Example #14
0
 public function init(Website $website, Request $request)
 {
     $documentId = $request->getParamInt(0, 0);
     $documentRepo = new DocumentRepository($website->getDatabase(), true);
     $this->document = $documentRepo->getDocument($documentId);
     if (Validate::requestToken($request)) {
         $widgetRepo = new WidgetRepository($website);
         $documentRepo->deleteDocument($this->document, $widgetRepo);
         $text = $website->getText();
         $text->addMessage($text->t("main.document") . ' ' . $text->t("editor.is_deleted"));
         $this->deleted = true;
     }
     $this->requestToken = RequestToken::generateNew();
     $this->requestToken->saveToSession();
 }
Example #15
0
 public function init(Website $website, Request $request)
 {
     $categoryId = $request->getParamInt(0, 0);
     $categoriesRepo = new CategoryRepository($website->getDatabase());
     if ($categoryId === 0) {
         $this->category = new Category(0, "");
     } else {
         $this->category = $categoriesRepo->getCategory($categoryId);
     }
     if (Validate::requestToken($request)) {
         $this->updateCategory($categoriesRepo, $request, $website->getText());
     }
     $this->requestToken = RequestToken::generateNew();
     $this->requestToken->saveToSession();
     $this->richEditor = new CKEditor($website->getText(), $website->getConfig(), $website->getThemeManager());
 }
Example #16
0
 public function init(Website $website, Request $request)
 {
     $id = $request->getParamInt(0, 0);
     // Load document
     $documentRepo = new DocumentRepository($website->getDatabase(), true);
     $user = $website->getAuth()->getCurrentUser();
     // ^ this is never null, as the required rank for this page is moderator
     $this->document = $this->retrieveDocument($website, $documentRepo, $id, $user);
     // Load document widgets
     $this->widgetLoader = $website->getWidgets();
     $widgetRepo = new WidgetRepository($website);
     $this->widgets = $widgetRepo->getWidgetsInDocumentWithId($id);
     // Check for edits
     $this->saveData($website->getText(), $request, $this->document, $documentRepo);
     // Store new request token
     $this->requestToken = RequestToken::generateNew();
     $this->requestToken->saveToSession();
 }
Example #17
0
 public function init(Website $website, Request $request)
 {
     $this->showEditLinks = $website->isLoggedInAsStaff();
     $this->selectedYear = $request->getRequestInt("year", 0);
     $this->selectedCategory = $request->getParamInt(0);
     // Fetch all categories
     $categories = new CategoryRepository($website->getDatabase());
     $this->allCategories = $categories->getCategoriesArray();
     // Check if valid category
     if ($this->selectedCategory != 0 && !array_key_exists($this->selectedCategory, $this->allCategories)) {
         $website->addError($website->t("main.category") . " " . $website->t("errors.not_found"));
         $this->selectedCategory = 0;
     }
     // Fetch all articles
     $articles = new ArticleRepository($website);
     $this->articleCountInYears = $articles->getArticleCountInYears($this->selectedCategory);
     $this->foundArticles = $articles->getArticlesDataArchive($this->selectedYear, $this->selectedCategory);
 }
Example #18
0
 public function init(Website $website, Request $request)
 {
     $categoriesRepo = new CategoryRepository($website->getDatabase());
     $categoryId = $request->getParamInt(0, 0);
     $this->category = $categoriesRepo->getCategory($categoryId);
     if ($this->category->isStandardCategory()) {
         $text = $website->getText();
         $editCategory = Link::of($text->getUrlPage("edit_category", $this->category->getId()), $text->t("categories.edit"));
         $viewAll = Link::of($text->getUrlPage("category_list"), $text->t("categories.view_all"));
         $text->addError($text->t("categories.delete.cannot_remove_default"), $editCategory, $viewAll);
         return;
     }
     if (Validate::requestToken($request)) {
         $articlesRepo = new ArticleRepository($website);
         $this->deleteCategory($categoriesRepo, $articlesRepo, $website->getText());
     }
     $this->requestToken = RequestToken::generateNew();
     $this->requestToken->saveToSession();
 }
Example #19
0
 public function init(Website $website, Request $request)
 {
     // Retrieve menus
     $menuRepo = new MenuRepository($website->getDatabase());
     $this->allMenus = $menuRepo->getAllMenus();
     // Retrieve the menu to be deleted
     $menuId = $request->getParamInt(0, 0);
     if (!isset($this->allMenus[$menuId])) {
         // Asking to delete non-existing menu
         throw new NotFoundException();
     }
     $this->menu = $this->allMenus[$menuId];
     // Retrieve links
     $linkRepo = new LinkRepository($website->getDatabase());
     $this->linkCount = $linkRepo->getLinkCountByMenu($this->menu->getId());
     $this->respondToRequest($linkRepo, $menuRepo, $website->getText(), $request);
     // Request token
     $this->requestToken = RequestToken::generateNew();
     $this->requestToken->saveToSession();
 }
Example #20
0
 /**
  * Gets the user that will be edited.
  * @param Website $website The website.
  * @param Request $request The request.
  * @return User The user to edit.
  * @throws NotFoundException If the id in the request is invalid or if the user can only edit him/herself.
  */
 private function getEditingUser(Website $website, Request $request)
 {
     // Will always have a value - minimum rank of this page is user rank
     $loggedInUser = $website->getAuth()->getCurrentUser();
     // Check if editing another user
     if (!$request->hasParameter(0)) {
         return $loggedInUser;
     }
     $userId = $request->getParamInt(0);
     if ($userId === 0 || $userId === $loggedInUser->getId()) {
         return $loggedInUser;
     }
     if ($this->can_user_edit_someone_else($website)) {
         $userRepo = $website->getAuth()->getUserRepository();
         return $userRepo->getById($userId);
     } else {
         $website->addError($website->t("users.account") . " " . $website->t("errors.not_editable"));
         throw new NotFoundException();
     }
 }
Example #21
0
 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();
     }
 }
Example #22
0
 public function init(Website $website, Request $request)
 {
     $text = $website->getText();
     $currentUser = $website->getAuth()->getCurrentUser();
     $articleId = $request->getParamInt(0);
     $articleRepository = new ArticleRepository($website);
     $article = $this->getArticle($articleRepository, $currentUser, $articleId);
     $articleEditor = new ArticleEditor($article);
     $this->articleEditor = $articleEditor;
     $categoryRepository = new CategoryRepository($website->getDatabase());
     $this->allCategories = $categoryRepository->getCategories();
     $this->richEditor = new CKEditor($website->getText(), $website->getConfig(), $website->getThemeManager());
     // Validate token, then save new one to session
     $validToken = Validate::requestToken($request);
     $this->token = RequestToken::generateNew();
     $this->token->saveToSession();
     // Now check input
     if (!$articleEditor->processInput($website->getText(), $request, $categoryRepository)) {
         return;
     }
     if ($request->hasRequestValue("submit") && $validToken) {
         // Try to save
         $article = $articleEditor->getArticle();
         if ($articleRepository->saveArticle($article)) {
             $viewArticleLink = Link::of($website->getUrlPage("article", $article->getId()), $website->t("articles.view"));
             if ($articleId == 0) {
                 // New article created
                 $text->addMessage($text->t("main.article") . " " . $text->t("editor.is_created"), $viewArticleLink);
             } else {
                 // Article updated
                 $text->addMessage($text->t("main.article") . " " . $text->t("editor.is_edited"), $viewArticleLink);
             }
             // Check for redirect
             if ($request->getRequestString("submit") == $website->t("editor.save_and_quit")) {
                 $this->redirectUrl = $website->getUrlPage("article", $article->getId());
             }
         }
     }
 }
Example #23
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();
 }
Example #24
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();
 }
Example #25
0
 public function init(Website $website, Request $request)
 {
     $text = $website->getText();
     $widgetId = $request->getParamInt(0);
     $moveUp = $request->getRequestString("direction", "up") === "up";
     $widgetRepository = new WidgetRepository($website);
     $this->placedWidget = $widgetRepository->getPlacedWidget($widgetId);
     $this->installedWidgets = $website->getWidgets();
     if (Validate::requestToken($request)) {
         // move
         $this->moveWidget($widgetRepository, $moveUp);
         $this->redirectUrl = $text->getUrlPage("edit_document", $this->placedWidget->getDocumentId());
     } else {
         $text->addError(Validate::getLastError($text));
         $linkText = $text->t("widgets.move_down");
         if ($moveUp) {
             $linkText = $text->t("widgets.move_up");
         }
         // Generate new request token, allowing user to perform action again
         $newRequestToken = RequestToken::generateNew();
         $this->moveLink = Link::of($text->getUrlPage("move_widget", $widgetId, ["direction" => $moveUp ? "up" : "down", RequestToken::FIELD_NAME => $newRequestToken->getTokenString()]), $linkText);
         $newRequestToken->saveToSession();
     }
 }
Example #26
0
 public function init(Website $website, Request $request)
 {
     $id = $request->getParamInt(0, 0);
     $this->articleUrl = $website->getUrlPage("article", $id);
 }