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); }
private function deleteLink(LinkRepository $linkRepo, Text $text) { $linkRepo->deleteLink($this->link); $text->addMessage($text->t("main.link") . " " . $text->t("editor.is_deleted"), Link::of($text->getUrlPage("edit_menu", $this->link->getMenuId()), $text->t("links.menu.go_back"))); $this->link = null; // mark as deleted }
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(); }
private function handleRequest(Text $text, Request $request, LinkRepository $linkRepo) { $valid = true; $linkText = $request->getRequestString("link_text", ""); $this->link->setText($linkText); if (!Validate::nameOfLink($linkText)) { $text->addError($this->t("links.text") . " " . Validate::getLastError($text)); $valid = false; } $url = $request->getRequestString("link_url", ""); if (Validate::url($url)) { $this->link->setUrl(new Uri($url)); } else { $text->addError($text->t("links.url") . " " . Validate::getLastError($text)); $valid = false; } if ($valid) { $linkRepo->saveLink($this->link); $text->addMessage($text->t("main.link") . ' ' . $text->t("editor.is_edited"), Link::of($text->getUrlPage("edit_menu", $this->link->getMenuId()), $text->t("links.menu.go_back"))); } }
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>'); } }
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 writeTopMenu(StreamInterface $stream) { $website = $this->website; $text = $website->getText(); $config = $website->getConfig(); $links = []; $links[] = Link::of($text->getUrlMain(), $text->t("main.home")); if ($config->isDatabaseUpToDate()) { $menuId = (int) $config->get(Config::OPTION_MAIN_MENU_ID, 0); if ($menuId === 0) { $categoriesRepo = new CategoryRepository($website->getDatabase()); $links = array_merge($links, $categoriesRepo->getCategoryLinks($text)); } else { $linkRepo = new LinkRepository($website->getDatabase()); $links = array_merge($links, $linkRepo->getLinksByMenu($menuId)); } } $menuTemplate = new MenuTemplate($website->getText(), $links); $menuTemplate->writeText($stream); }
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; }