public function __construct(Website $website, Request $request, Page $page) { $this->website = $website; $this->request = $request; $this->themeDirectoryName = $website->getConfig()->get(Config::OPTION_THEME); $this->page = $page; }
public function init(Website $website, Request $request) { $this->installedWidgets = $website->getWidgets(); $this->siteTitle = $website->getConfig()->get(Config::OPTION_SITE_TITLE); $widgetsRepo = new WidgetRepository($website); $this->widgets = $widgetsRepo->getWidgetsInDocumentWithId(self::DOCUMENT_ID); $this->editLinks = $website->isLoggedInAsStaff(true); }
public function init(Website $website, Request $request) { $this->errorMessage = $website->getAuth()->getLoginError($this->minimumRank); $psrRequest = $request->toPsr(); $this->targetUrl = $psrRequest->getUri(); $this->postVars = (array) $psrRequest->getParsedBody(); $this->canCreateAccounts = $website->getConfig()->get(Config::OPTION_USER_ACCOUNT_CREATION); }
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 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) { $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) { if ($website->getConfig()->isDatabaseUpToDate()) { // Pretend page does not exist if database is already installed throw new NotFoundException(); } $installer = new DatabaseInstaller(); $this->databaseState = $installer->getDatabaseState($website); if ($this->databaseState == DatabaseInstaller::STATE_OUTDATED || $this->databaseState == DatabaseInstaller::STATE_NOT_INSTALLED && $request->getRequestString("action") === "install_database") { $installer->createOrUpdateTables($website); $this->justInstalled = true; } if ($this->databaseState == DatabaseInstaller::STATE_FROM_FUTURE) { $text = $website->getText(); $text->addError($text->t("install.database_version_from_future")); } }
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; }
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()); } } } }
/** * 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(); } } }
$textToDisplay .= " <title>" . htmlSpecialChars($article->getTitle()) . "</title>\n"; $textToDisplay .= " <link>" . $website->getUrlPage('article', $article->getId()) . "</link>\n"; $textToDisplay .= " <description>" . htmlSpecialChars($article->getIntro()) . "</description>\n"; $textToDisplay .= " <pubDate>" . htmlSpecialChars($pubdate) . "</pubDate>\n"; $textToDisplay .= " <author>" . htmlSpecialChars($article->author) . "</author>\n"; $textToDisplay .= " <image>" . htmlSpecialChars($article->featuredImage) . "</image>\n"; $textToDisplay .= " <category>" . htmlSpecialChars($article->category) . "</category>\n"; $textToDisplay .= "</item>\n\n"; } } unset($article, $articles); // Show it echo '<?xml version="1.0" encoding="UTF-8" ?>'; ?> <rss version="2.0"> <channel> <title><?php echo htmlSpecialChars($website->getConfig()->get('title')); ?> </title> <link><?php echo htmlSpecialChars($website->getUrlMain()); ?> </link> <?php echo $textToDisplay; ?> </channel> </rss> <?php
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")); } }