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); }
public function init(Website $website, Request $request) { $linkRepo = new LinkRepository($website->getDatabase()); $menuRepo = new MenuRepository($website->getDatabase()); $this->allLinks = $linkRepo->getAllLinksByMenu(); $this->allMenus = $menuRepo->getAllMenus(); $this->requestToken = RequestToken::generateNew(); $this->requestToken->saveToSession(); }
public function init(Website $website, Request $request) { $this->keyword = trim($request->getRequestString("searchbox")); $this->pageNumber = $request->getRequestInt("page", 0); $this->showEditLinks = $website->isLoggedInAsStaff(); if (strLen($this->keyword) < self::MIN_SEARCH_LENGTH) { // Don't search for too short words if (!empty($this->keyword)) { $website->addError($website->t("articles.search_term") . " " . $website->tReplaced("errors.is_too_short_num", self::MIN_SEARCH_LENGTH)); } return; } // Fetch article count $articles = new ArticleRepository($website); $this->totalResults = $articles->getMatchesFor($this->keyword); // Count total number of pages, limit current page number $this->highestPageNumber = floor($this->totalResults / self::ARTICLES_PER_PAGE); if ($this->pageNumber < 0 || $this->pageNumber > $this->highestPageNumber) { $this->pageNumber = 0; } // Fetch articles $this->displayedArticles = $articles->getArticlesDataMatch($this->keyword, self::ARTICLES_PER_PAGE, $this->pageNumber * self::ARTICLES_PER_PAGE); // Fetch links $menus = new LinkRepository($website->getDatabase()); $this->links = $menus->getLinksBySearch($this->keyword); }
public function init(Website $website, Request $request) { $isStaff = $website->isLoggedInAsStaff(true); $documentRepo = new DocumentRepository($website->getDatabase(), $isStaff); $this->documents = $documentRepo->getAll(); $this->editLinks = $isStaff; }
private function handleRequest(Website $website, Request $request) { $text = $website->getText(); $menuId = $request->getRequestInt("main_menu_id", 0); if ($menuId === 0) { $this->menu = null; $website->getConfig()->set($website->getDatabase(), Config::OPTION_MAIN_MENU_ID, 0); $text->addMessage($text->t("links.main_menu.now_using_categories"), Link::of($text->getUrlPage("category_list"), $text->t("categories.edit_categories")), Link::of($text->getUrlMain(), $text->t("main.home"))); } else { if (isset($this->menus[$menuId])) { $this->menu = $this->menus[$menuId]; $website->getConfig()->set($website->getDatabase(), Config::OPTION_MAIN_MENU_ID, $this->menu->getId()); $text->addMessage($text->tReplaced("links.main_menu.now_using_this_menu", $this->menu->getName()), Link::of($text->getUrlPage("edit_menu", $this->menu->getId()), $text->t("links.menu.edit")), Link::of($text->getUrlMain(), $text->t("main.home"))); } else { throw new NotFoundException(); } } }
public function __construct(Website $website) { parent::__construct($website->getDatabase()); $this->widgetDirectory = $website->getUriWidgets(); $this->documentIdField = new Field(Field::TYPE_INT, "documentId", "sidebar_id"); $this->widgetDataField = new Field(Field::TYPE_JSON, "widgetData", "widget_data"); $this->widgetIdField = new Field(Field::TYPE_PRIMARY_KEY, "id", "widget_id"); $this->widgetNameField = new Field(Field::TYPE_STRING, "widgetName", "widget_naam"); $this->widgetPriorityField = new Field(Field::TYPE_INT, "priority", "widget_priority"); }
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) { $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); }
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) { // 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(); }
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(); }
private function handleSubmitedForm(Website $website, Request $request) { $text = $website->getText(); if (Validate::stringLength($this->menuName, 1, MenuRepository::NAME_MAX_LENGTH)) { $menuRepo = new MenuRepository($website->getDatabase()); $this->menu = Menu::createNew($this->menuName); $menuRepo->saveMenu($this->menu); $text->addMessage($text->t("links.menu.created")); } else { $text->addError($text->t("links.menu.name") . ' ' . Validate::getLastError($text)); } }
/** * Creates a new widget based on the request paramaters, or throws an * exception on error. * @param Website $website The website object. * @param Request $request The request. * @return PlacedWidget A new widget, still needs to be saved in the database. * @throws NotFoundException If the document or widget type in the request * is non-existant. */ private function getNewWidget(Website $website, Request $request) { $directoryName = $request->getRequestString("directory_name", ""); if ($directoryName === "") { throw new NotFoundException(); } // Get document $documentRepo = new DocumentRepository($website->getDatabase(), true); $documentId = $request->getRequestInt("document_id", 0); $document = $documentRepo->getDocumentOrWidgetArea($website->getWidgets(), $website->getText(), $documentId); return PlacedWidget::newPlacedWidget($website->getUriWidgets(), $directoryName, $document); }
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); }
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) { $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) { $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()); }
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(); }
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); }
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(); $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(); $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(); }
/** * Constructs the article displayer. * @param Website $website The website to use. */ public function __construct(Website $website) { parent::__construct($website->getDatabase()); $this->website = $website; $this->primaryField = new Field(Field::TYPE_PRIMARY_KEY, "id", "artikel_id"); $this->titleField = new Field(Field::TYPE_STRING, "title", "artikel_titel"); $this->createdField = new Field(Field::TYPE_DATE, "created", "artikel_gemaakt"); $this->editedField = new Field(Field::TYPE_DATE, "lastEdited", "artikel_bewerkt"); $this->introField = new Field(Field::TYPE_STRING, "intro", "artikel_intro"); $this->bodyField = new Field(Field::TYPE_STRING, "body", "artikel_inhoud"); $this->featuredImageField = new Field(Field::TYPE_STRING, "featuredImage", "artikel_afbeelding"); $this->categoryIdField = new Field(Field::TYPE_INT, "categoryId", "categorie_id"); $this->categoryNameField = new Field(Field::TYPE_STRING, "category", "category_name"); $categoryIdInCategoryTable = new Field(Field::TYPE_INT, "category", "category_id"); $this->categoryNameField->createLink(CategoryRepository::TABLE_NAME, $this->categoryIdField, $categoryIdInCategoryTable); $this->authorIdField = new Field(Field::TYPE_INT, "authorId", "gebruiker_id"); $this->authorNameField = new Field(Field::TYPE_STRING, "author", "user_display_name"); $authorIdInUsersTable = new Field(Field::TYPE_INT, "authorId", "user_id"); $this->authorNameField->createLink(UserRepository::TABLE_NAME, $this->authorIdField, $authorIdInUsersTable); $this->pinnedField = new Field(Field::TYPE_BOOLEAN, "pinned", "artikel_gepind"); $this->hiddenField = new Field(Field::TYPE_BOOLEAN, "hidden", "artikel_verborgen"); $this->showCommentsField = new Field(Field::TYPE_BOOLEAN, "showComments", "artikel_reacties"); $this->calendarField = new Field(Field::TYPE_DATE, "onCalendar", "artikel_verwijsdatum"); }
/** * Creates a new authentication checker. * @param Website $website The website object. * @param UserRepository $userRepo The user repository, or null if the * website is not connected to a database (happens when the website is not * installed yet). * * For backwards compatibility, if this parameter is null, it is tried to * create a UserRepository instance anyways if the website reports that it * is connected to a database. This behaviour will be removed in a future * version. */ public function __construct(Website $website, UserRepository $userRepo = null) { $this->website = $website; if ($website->getConfig()->isDatabaseUpToDate()) { $this->userRepo = $userRepo ?: new UserRepository($website->getDatabase()); } // Check session and cookie if (isset($_SESSION["user_id"])) { if (!$this->setCurrentUserFromId($_SESSION["user_id"])) { // Invalid session variable $this->logOut(); } } else { // Try to log in with cookie $user = $this->getUserFromCookie(); if ($user != null && $this->setCurrentUser($user)) { // Log in and refresh cookie $this->setLoginCookie(); } else { // Cookie is corrupted/account is deleted $this->deleteLoginCookie(); } } }
private function saveLink(Website $website) { $text = $website->getText(); $valid = true; if (!Validate::url($this->linkUrl)) { $text->addError($text->t("links.url") . " " . Validate::getLastError($text)); $valid = false; } if (!Validate::stringLength($this->linkName, 1, LinkRepository::MAX_LINK_TEXT_LENGTH)) { $text->addError($text->t("links.text") . " " . Validate::getLastError($text)); $valid = false; } if (!$valid) { return; } $link = Link::createSaveable(0, $this->menu->getId(), new Uri($this->linkUrl), $this->linkName); $linkRepo = new LinkRepository($website->getDatabase()); $linkRepo->saveLink($link); $text->addMessage($text->t("main.link") . " " . $text->t("editor.is_created"), Link::of($text->getUrlPage("add_link", $this->menu->getId()), $text->t("links.create_another"))); $this->addedLink = true; }
protected function save_string(Website $website, $name, $optional) { $value = trim($website->getRequestString("option_{$name}", $this->{$name})); if ($optional || !empty($value)) { $this->{$name} = substr($value, 0, Website::MAX_SITE_OPTION_LENGTH); $website->getConfig()->set($website->getDatabase(), $name, $this->{$name}); } else { $website->addError($website->t("site_settings.{$name}") . " " . $website->t("errors.not_found")); } }