private function saveData(Text $text, Request $request, Document $document, DocumentRepository $documentRepo) { if (!$request->hasRequestValue("intro") || !$request->hasRequestValue("title")) { return; } if ($document->isForWidgetArea()) { $text->addError($text->t("main.document") . ' ' . $text->t("errors.not_editable")); return; } $document->setIntro($request->getRequestString("intro", '')); $document->setTitle($request->getRequestString("title", '')); $valid = true; if (!Validate::requestToken($request)) { $valid = false; } if (!Validate::stringLength($document->getIntro(), Document::INTRO_MIN_LENGTH, Document::INTRO_MAX_LENGTH)) { $text->addError($text->t("documents.intro") . ' ' . Validate::getLastError($text)); $valid = false; } if (!Validate::stringLength($document->getTitle(), Document::TITLE_MIN_LENGTH, Document::TITLE_MAX_LENGTH)) { $text->addError($text->t("documents.title") . ' ' . Validate::getLastError($text)); $valid = false; } if (!$valid) { return; } $isNew = $document->getId() == 0; $documentRepo->saveDocument($document); if ($isNew) { $text->addMessage($text->t("main.document") . ' ' . $text->t("editor.is_created")); } else { $text->addMessage($text->t("main.document") . ' ' . $text->t("editor.is_edited")); } }
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(); }
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) { $this->requestToken = RequestToken::generateNew(); $this->menuName = $request->getRequestString("menu_name", ""); if (Validate::requestToken($request)) { $this->handleSubmitedForm($website, $request); } $this->requestToken->saveToSession(); }
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(); }
public function init(Website $website, Request $request) { $menuId = (int) $website->getConfig()->get(Config::OPTION_MAIN_MENU_ID); $menuRepo = new MenuRepository($website->getDatabase()); $this->menus = $menuRepo->getAllMenus(); $this->menu = isset($this->menus[$menuId]) ? $this->menus[$menuId] : null; if (Validate::requestToken($request)) { $this->handleRequest($website, $request); } $this->requestToken = RequestToken::generateNew(); $this->requestToken->saveToSession(); }
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(); }
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(); }
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(); }
public function init(Website $website, Request $request) { parent::init($website, $request); $themeManager = $website->getThemeManager(); if (!$themeManager->canSwitchThemes()) { $this->sendThemeSwitchError($website->getText()); } else { if (Validate::requestToken($request)) { $this->trySwitchTheme($themeManager, $website->getText(), $request); } } $this->availableThemes = $themeManager->getAllThemes(); $this->requestToken = RequestToken::generateNew(); $this->requestToken->saveToSession(); }
private function respondToRequest(LinkRepository $linkRepo, MenuRepository $menuRepo, Text $text, Request $request) { if (!Validate::requestToken($request)) { return; } $moveLinksToMenuId = $request->getRequestInt("move_option", 0); if ($moveLinksToMenuId === 0) { $linkRepo->deleteLinksInMenu($this->menu); } else { $linkRepo->moveLinks($this->menu, $this->allMenus[$moveLinksToMenuId]); } $menuRepo->deleteMenu($this->menu->getId()); $text->addMessage($text->t("links.menu") . " " . $text->t("editor.is_deleted"), Link::of($text->getUrlPage("links"), $text->t("links.overview"))); $this->deleted = true; }
public function init(Website $website, Request $request) { $this->title = $website->getConfig()->get("title"); $this->copyright = $website->getConfig()->get("copyright"); $this->password = $website->getConfig()->get("password"); $this->language = $website->getConfig()->get("language"); $this->user_account_creation = $website->getConfig()->get("user_account_creation"); if (isset($_REQUEST["submit"]) && Validate::requestToken($request)) { $this->save_values($website); $this->saved = true; } // Refresh token $this->token = RequestToken::generateNew(); $this->token->saveToSession(); }
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(); } }
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()); }
private function handleUserRequest(Website $website, Request $request) { $username = $request->getRequestString("creating_username", ""); $displayName = $request->getRequestString("creating_display_name", ""); $password1 = $request->getRequestString("creating_password1", ""); $password2 = $request->getRequestString("creating_password2", ""); $email = $request->getRequestString("creating_email", ""); $newUser = User::createNewUser($username, $displayName, $password1); $newUser->setEmail($email); $text = $website->getText(); $userRepo = new UserRepository($website->getDatabase()); if (Validate::requestToken($request) && $this->validateInput($newUser, $password1, $password2, $userRepo, $text)) { $userRepo->save($newUser); $this->accountCreated = true; $text->addMessage($text->t("users.create.done")); } return $newUser; }
private function handleUserRequest(Website $website, Request $request) { $username = $request->getRequestString("creating_username", ""); $displayName = $request->getRequestString("creating_display_name", ""); $password = $request->getRequestString("creating_password", ""); $email = $request->getRequestString("creating_email", ""); $rank = $request->getRequestInt("creating_rank", 0); $newUser = User::createNewUser($username, $displayName, $password); $newUser->setEmail($email); $newUser->setRank($rank); $text = $website->getText(); $userRepo = new UserRepository($website->getDatabase()); if (Validate::requestToken($request) && $this->validateInput($newUser, $password, $website->getAuth(), $userRepo, $text)) { $userRepo->save($newUser); $this->accountCreated = true; $text->addMessage($text->t("users.create.other.done"), Link::of($text->getUrlPage("create_account_admin"), $text->t("users.create_another")), Link::of($text->getUrlPage("account_management"), $text->t("main.account_management"))); } return $newUser; }
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(); }
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(); $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()); } } } }
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(); }
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(); } }