public function getPageTitle(Text $text) { if ($this->menu !== null) { return $this->menu->getName(); } return $text->t("links.menu.add"); }
public function getTemplate(Text $text) { if ($this->loggedIn) { return new LoggedInTemplate($text, $this->loggedInAsAdmin); } else { // Return a login view, but without the "Must be logged in" message // at the top. return new LoginFormTemplate($text, $text->getUrlPage("login"), [], $this->errorMessage, $this->canCreateAccounts); } }
private function trySwitchTheme(ThemeManager $themeManager, Text $text, Request $request) { $themeDirectory = $request->getRequestString("theme", ""); if (!$themeManager->themeExists($themeDirectory)) { $text->addError($text->t("themes.does_not_exist")); return false; } $themeManager->setActiveTheme($themeDirectory); $text->addMessage($text->t("themes.successfully_switched")); return true; }
/** * Returns the localized error message of the last error. * @param Website|Text $websiteOrText The Website object or Text object. * @return string The localized error message */ public static function getLastError($websiteOrText) { if (Validate::$replaceInLastError === "") { $message = $websiteOrText->t("errors." . Validate::$lastError); } else { $message = $websiteOrText->tReplaced("errors." . Validate::$lastError, Validate::$replaceInLastError); } Validate::$lastError = ""; Validate::$replaceInLastError = ""; return $message; }
/** * Gets an array of links to all categories. * @param Text $text The text object, of URL structure. * @return Link[] The array of links. */ public function getCategoryLinks(Text $text) { $categories = $this->getCategories(); $links = []; foreach ($categories as $category) { if ($category->isStandardCategory()) { continue; // Don't display "No categories" } $links[] = Link::of($text->getUrlPage("category", $category->getId()), $category->getName()); } return $links; }
public function getPageTitle(Text $text) { if ($this->category->getId() === 0) { return $text->t("categories.create"); } return $text->t("categories.edit_a_category"); }
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")); } }
/** * Validates a comment for saving to the database. * @param Comment $comment The comment. * @param Text $text Errors go here. * @return boolean True if the comment is valid, false otherwise. */ public function validateComment(Comment $comment, Text $text) { $valid = true; if (!Validate::stringLength($comment->getBodyRaw(), Comment::BODY_MIN_LENGTH, Comment::BODY_MAX_LENGTH)) { $text->addError($text->t("comments.comment") . " " . Validate::getLastError($text)); $valid = false; } if ($comment->isByVisitor()) { if (!Validate::email($comment->getUserEmail())) { $text->addError($text->t("users.email") . " " . Validate::getLastError($text)); $valid = false; } if (!Validate::displayName($comment->getUserDisplayName())) { $text->addError($text->t("users.name") . " " . Validate::getLastError($text)); $valid = false; } } return $valid; }
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 getShortPageTitle(Text $text) { return $text->t("articles.delete"); }
public function getPageTitle(Text $text) { return $text->t("main.admin"); }
public function processInput(Text $text, Request $request, CategoryRepository $oCategories) { $article = $this->articleObject; $noErrors = true; // Title if ($request->hasRequestValue("article_title")) { $title = trim($request->getRequestString('article_title')); if (strLen($title) > Article::MAX_TITLE_LENGTH) { $text->addError($text->t("articles.title") . " " . $text->tReplaced("errors.is_too_long_num", Article::MAX_TITLE_LENGTH)); $noErrors = false; } if (strLen($title) < Article::MIN_TITLE_LENGTH) { $text->addError($text->tReplacedKey("errors.please_enter_this", "articles.title", true)); $noErrors = false; } $article->setTitle($title); } // Intro if ($request->hasRequestValue("article_intro")) { $intro = trim($request->getRequestString("article_intro")); if (strLen($intro) < Article::MIN_INTRO_LENGTH) { $text->addError($text->tReplacedKey("errors.please_enter_this", "articles.intro", true)); $noErrors = false; } if (strLen($intro) > Article::MAX_INTRO_LENGTH) { $text->addError($text->t("articles.intro") . " " . $text->tReplaced("errors.is_too_long_num", Article::MAX_INTRO_LENGTH)); $noErrors = false; } $article->setIntro($intro); } // Body if ($request->hasRequestValue("article_body")) { $body = trim($request->getRequestString("article_body")); if (strLen($body) < Article::MIN_BODY_LENGTH) { $text->addError($text->tReplacedKey("errors.please_enter_this", "articles.body", true)); $noErrors = false; } if (strLen($body) > Article::MAX_BODY_LENGTH) { $text->addError($text->t("articles.body") . " " . $text->tReplaced("errors.is_too_long_num", Article::MAX_BODY_LENGTH)); $noErrors = false; } $article->setBody($body); } // Category if ($request->hasRequestValue("article_category")) { $categoryId = (int) $request->getRequestString('article_category', 0); if ($categoryId == 0) { // Silent failure when category id is set to 0, as it is a default value $noErrors = false; } elseif (!$this->categoryExists($oCategories, $categoryId)) { $text->addError($text->t("main.category") . " " . $website->t("errors.not_found")); $noErrors = false; } $article->categoryId = $categoryId; } // Featured image if ($request->hasRequestValue("article_featured_image")) { $featuredImage = trim($request->getRequestString("article_featured_image")); if (strLen($featuredImage) > Article::MAX_FEATURED_IMAGE_URL_LENGTH) { $text->addError($text->t("articles.featured_image") . " " . $text->tReplaced("ërrors.is_too_long_num", Article::MAX_FEATURED_IMAGE_URL_LENGTH)); $noErrors = false; } $article->featuredImage = $featuredImage; } // Pinned, hidden, comments if ($request->hasRequestValue("submit")) { $article->pinned = $request->hasRequestValue("article_pinned"); $article->setHidden($request->hasRequestValue("article_hidden")); $article->showComments = $request->hasRequestValue("article_comments"); } // Event date $eventDate = ""; $eventTime = ""; if ($request->hasRequestValue("article_eventdate")) { $eventDate = trim($request->getRequestString("article_eventdate")); } if ($request->hasRequestValue("article_eventtime") && $eventDate) { $eventTime = trim($request->getRequestString("article_eventtime")); } if (empty($eventDate) && $request->hasRequestValue("article_eventdate")) { // Field was made empty, so delete date on article $article->onCalendar = null; } if (!empty($eventDate)) { if (strtotime($eventDate) === false) { $text->addError($text->t("articles.event_date") . " " . $text->t("errors.not_correct")); $noErrors = false; } else { // Add date to article $article->onCalendar = new DateTime($eventDate . " " . $eventTime); } } return $noErrors; }
public function getShortPageTitle(Text $text) { return $text->t("main.log_out"); }
public function getPageTitle(Text $text) { return $text->t("users.account_management"); }
public function getPageTitle(Text $text) { return $text->t("users.password.edit"); }
public function getPageTitle(Text $text) { return $text->tReplaced("documents.delete.title", $this->document->getTitle()); }
public function getPageTitle(Text $text) { return $text->t("widgets.edit"); }
public function getPageTitle(Text $text) { return $text->t("documents.list.title"); }
public function getPageTitle(Text $text) { return $text->t("comments.comments"); }
public function getPageTitle(Text $text) { return $text->t("links.menu.rename"); }
public function getShortPageTitle(Text $text) { if ($this->articleEditor != null) { $articleTitle = $this->articleEditor->getArticle()->getTitle(); if (empty($articleTitle)) { // New article return $text->t("articles.create"); } } return $text->t("articles.edit"); }
public function getShortPageTitle(Text $text) { return $text->t("main.search"); }
public function getPageTitle(Text $text) { return $text->t("links.delete"); }
public function getPageTitle(Text $text) { return $text->t("users.rank.edit"); }
public function getUrl(Text $text) { return $text->getUrlPage("article", $this->getArticleId())->withFragment("comment_" . $this->getId()); }
public function getPageTitle(Text $text) { return $text->t("widgets.moving_a_widget"); }
public function getPageTitle(Text $text) { return $text->t("access_key.key_required"); }
public function getShortPageTitle(Text $text) { return $text->t("main.site_settings"); }
public function getPageTitle(Text $text) { return $text->t("categories.delete_a_category"); }
public function getShortPageTitle(Text $text) { return $text->t("users.profile_page"); }