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) { $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) { $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 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) { $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 = $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) { $this->request = $request; // Handle login ourselves // (Using the provided getMinimumRank helper gives an ugly // "You need to be logged in to view this page" message.) $this->loggedIn = $website->getAuth()->check(Authentication::RANK_USER, false); $this->loggedInAsAdmin = $website->isLoggedInAsStaff(true); if (!$this->loggedIn) { $this->errorMessage = $this->getLoginErrorMessage($website->getText(), $website->getAuth()); } $this->canCreateAccounts = (bool) $website->getConfig()->get(Config::OPTION_USER_ACCOUNT_CREATION); }
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 writeText(StreamInterface $stream, Website $website, $id, $data) { // Check variables if (!isset($data["title"]) || !isset($data["count"]) || !isset($data["display_type"]) || !isset($data["categories"])) { // The order variable is not checked, as older configurations may // not have it. The default value will be used instead. return; } // Title if (strLen($data["title"]) > 0) { $stream->write("<h2>" . htmlSpecialChars($data["title"]) . "</h2>"); } // Get options $categories = $data["categories"]; $articlesCount = (int) $data["count"]; $displayType = (int) $data["display_type"]; // Sorting $oldestTop = false; if (isset($data["order"]) && $data["order"] == self::SORT_OLDEST_TOP) { $oldestTop = true; } // Archive link $showArchiveLink = false; if (!isset($data["archive"]) || $data["archive"] == true) { $showArchiveLink = true; } $oArticles = new ArticleRepository($website); $articles = $oArticles->getArticlesData($categories, $articlesCount, $oldestTop); if ($displayType >= self::TYPE_LIST) { // Small <ul> list $oArticlesTemplate = new ArticleSmallListTemplate($website->getText(), $articles, $website->isLoggedInAsStaff(), $categories[0], $displayType == self::TYPE_LIST_WITH_IMAGES, $showArchiveLink); } else { // Real paragraphs $oArticlesTemplate = new ArticleListTemplate($website->getText(), $articles, $categories[0], $displayType == self::TYPE_WITH_METADATA, $showArchiveLink, $website->isLoggedInAsStaff()); } $oArticlesTemplate->writeText($stream); }
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) { $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 writeText(StreamInterface $stream, Website $website, $id, $data) { $text = $website->getText(); $editLinks = $website->isLoggedInAsStaff(); // Title $title = ""; if (isset($data["title"]) && strLen($data["title"]) > 0) { $title = "<h2>" . $text->e($data["title"]) . "</h2>"; } $stream->write($title); $oArticles = new ArticleRepository($website); $articles = $oArticles->getArticlesDataUpcomingEvents(); $articlesTemplate = new ArticleEventListTemplate($text, $articles, $editLinks, 0, true); // Articles $articlesTemplate->writeText($stream); }
protected function get_ranks_box_html(Website $website, $ranks, $selected) { $oAuth = $website->getAuth(); $text = $website->getText(); $selection_box = '<select name="rank" id="rank">'; foreach ($ranks as $id) { $label = $text->t($oAuth->getRankName($id)); $selection_box .= '<option value="' . $id . '"'; if ($selected == $id) { $selection_box .= ' selected="selected"'; } $selection_box .= '>' . $label . "</option>\n"; } $selection_box .= "</select>\n"; return $selection_box; }
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 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(); } } }
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) { // 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 getEditor(Website $website, $id, $data) { $title = isset($data["title"]) ? $data["title"] : ""; $text = isset($data["text"]) ? $data["text"] : ""; $oEditor = new CKEditor($website->getText(), $website->getConfig(), $website->getThemeManager()); // Title $textToDisplay = "<p>\n"; $textToDisplay .= '<label for="title_' . $id . '">'; $textToDisplay .= $website->t("widgets.title") . "</label>:<br />\n"; $textToDisplay .= '<input type="text" name="title_' . $id . '" id="title_' . $id . '"'; $textToDisplay .= 'value="' . htmlSpecialChars($title) . '" />' . "\n"; $textToDisplay .= "</p>\n"; // Text input $textToDisplay .= "<p>\n"; $textToDisplay .= '<label for="text_' . $id . '">' . $website->t("editor.message") . "</label>:"; $textToDisplay .= '<span class="required">*</span><br />' . "\n"; $textToDisplay .= $oEditor->getEditor("text_" . $id, $text); $textToDisplay .= "</p>\n"; return $textToDisplay; }
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; }
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 writeText(StreamInterface $stream, Website $website, $id, $data) { if (!isset($data["menu_id"]) || !isset($data["title"])) { return; } $loggedInStaff = $website->isLoggedInAsStaff(true); $menuId = (int) $data["menu_id"]; // Title if (strLen($data["title"]) > 0) { $stream->write("<h2>" . htmlSpecialChars($data["title"]) . "</h2>\n"); } // Links $oMenu = new LinkRepository($website->getDatabase()); $links = $oMenu->getLinksByMenu($menuId); $linkTemplate = new LinkListTemplate($website->getText(), $links, $loggedInStaff); $linkTemplate->writeText($stream); // Link to add link if ($loggedInStaff) { $stream->write('<p><a class="arrow" href="' . $website->getUrlPage("create_link", $menuId)); $stream->write('">' . $website->t("links.create") . '</a></p>'); } }
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(); }
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(); } }
use DateTime; use Rcms\Template\DatePickerTemplate; use Zend\Diactoros\Stream; // Setup environment require __DIR__ . "/environment.php"; $website = new Website(); //JAAR- EN MAANDLIJST $selectedMonth = $website->getRequestInt("month", date('n')); //geselecteerd of huidig $selectedYear = $website->getRequestInt("year", date('Y')); //geselecteerd of huidig $dateTime = DateTime::createFromFormat("n Y", $selectedMonth . " " . $selectedYear); //OBJECTEN $oArticles = new ArticleRepository($website); $articles = $oArticles->getArticlesDataCalendarMonth($dateTime); $calendarTemplate = new DatePickerTemplate($website->getText(), $dateTime, $articles); ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="<?php echo $website->getUrlActiveTheme(); ?> main.css" rel="stylesheet" type="text/css" /> <link href="<?php echo $website->getUrlMain(); ?> whitebackground.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="<?php echo $website->getUrlJavaScripts();
private function retrieveDocument(Website $website, DocumentRepository $documentRepo, $id, User $user) { if ($id === 0) { // New document return Document::createNew("", "", $user); } return $documentRepo->getDocumentOrWidgetArea($website->getWidgets(), $website->getText(), $id); }
/** 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; }