private function updateCategory(CategoryRepository $categoryRepo, Request $request, Text $text) { $this->category->setName($request->getRequestString("category_name", "")); $this->category->setDescriptionHtml($request->getRequestString("category_description", "")); $valid = true; if (!Validate::stringLength($this->category->getName(), CategoryRepository::NAME_MIN_LENGTH, CategoryRepository::NAME_MAX_LENGTH)) { $text->addError($text->t("categories.name") . ' ' . Validate::getLastError($text)); $valid = false; } if (!Validate::stringLength($this->category->getDescriptionHtml(), CategoryRepository::DESCRIPTION_MIN_LENGTH, CategoryRepository::DESCRIPTION_MAX_LENGTH)) { $text->addError($text->t("categories.description") . ' ' . Validate::getLastError($text)); $valid = false; } if ($valid) { $newCategory = $this->category->getId() === 0; $categoryRepo->saveCategory($this->category); // Add a confirmation $confirmation = $text->t("main.category") . " " . $text->t("editor.is_edited"); if ($newCategory) { $confirmation = $text->t("main.category") . " " . $text->t("editor.is_created"); } $viewCategory = Link::of($text->getUrlPage("category", $this->category->getId()), $text->t("categories.view_category")); $viewCategories = Link::of($text->getUrlpage("category_list"), $text->t("categories.view_all_categories")); $text->addMessage($confirmation, $viewCategory, $viewCategories); } }
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")); } }
private function trySaveMenu(MenuRepository $menuRepo, Text $text) { if (!Validate::stringLength($this->menu->getName(), 1, MenuRepository::NAME_MAX_LENGTH)) { $text->addError($text->t("links.menu") . " " . Validate::getLastError($text)); return; } $menuRepo->saveMenu($this->menu); $text->addMessage($text->t("links.menu") . " " . $text->t("editor.is_changed"), Link::of($text->getUrlPage("edit_menu", $this->menu->getId()), $text->t("links.menu.go_back"))); }
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)); } }
/** * 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 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 getPageContent(Website $website, Request $request) { // Don't allow to edit your own status (why would admins want to downgrade // themselves?) if (!$this->editing_someone_else) { $website->addError($website->t("users.account") . " " . $website->t("errors.not_editable")); return ""; } $show_form = true; $textToDisplay = ""; if ($request->hasRequestValue("status")) { // Sent $status = $request->getRequestInt("status"); $status_text = $request->getRequestString("status_text"); $oAuth = $website->getAuth(); $valid = true; // Check status id if (!$oAuth->isValidStatus($status)) { $website->addError($website->t("users.status") . ' ' . $website->t("errors.not_found")); $valid = false; } // Check status text if (!Validate::stringLength($status_text, 1, self::MAXIMUM_STATUS_TEXT_LENGTH)) { $website->addError($website->t("users.status_text") . " " . Validate::getLastError($website)); $valid = false; } if ($valid) { // Valid status $this->user->setStatus($status); $this->user->setStatusText($status_text); $oAuth->getUserRepository()->save($this->user); // Saved $textToDisplay .= '<p>' . $website->t("users.status") . ' ' . $website->t("editor.is_changed") . '</p>'; // Don't show form $show_form = false; } else { // Invalid status $textToDisplay .= '<p><em>' . $website->tReplacedKey("errors.your_input_has_not_been_changed", "users.status", true) . '</em></p>'; } } // Show form if ($show_form) { // Variables $status = $website->getRequestInt("status", $this->user->getStatus()); $statuses = array(Authentication::STATUS_NORMAL, Authentication::STATUS_BANNED, Authentication::STATUS_DELETED); $status_text = htmlSpecialChars($request->getRequestString("status_text", $this->user->getStatusText())); // Form itself $textToDisplay .= <<<EOT <p> {$website->t("users.status.edit.explained")} {$website->tReplaced("accounts.edit_other", "<strong>" . $this->user->getDisplayName() . "</strong>")} </p> <p> {$website->t("main.fields_required")} </p> <form action="{$website->getUrlMain()}" method="get"> <p> <label for="status">{$website->t("users.status")}</label>:<span class="required">*</span><br /> {$this->get_statuses_box_html($website->getAuth(), $statuses, $status)} </p> <p> <label for="status_text">{$website->t("users.status_text")}</label>:<span class="required">*</span><br /> <input type="text" name="status_text" id="status_text" size="80" value="{$status_text}" /> </p> <p> <input type="hidden" name="p" value="edit_account_status" /> <input type="hidden" name="id" value="{$this->user->getId()}" /> <input type="submit" value="{$website->t('editor.save')} " class="button" /> </p> </form> EOT; } // Links $textToDisplay .= $this->get_account_links_html($website); return $textToDisplay; }