Exemplo n.º 1
0
 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);
     }
 }
Exemplo n.º 2
0
 public function init(Website $website, Request $request)
 {
     $userId = $request->getParamInt(0);
     if ($userId === 0) {
         // Use current user
         $this->user = $website->getAuth()->getCurrentUser();
         if ($this->user == null) {
             throw new NotFoundException();
         }
     } else {
         // Use provided user
         $this->user = $website->getAuth()->getUserRepository()->getById($userId);
     }
     if ($this->user !== null) {
         // Don't display banned/deleted users
         if (!$this->user->canLogIn()) {
             if (!$website->isLoggedInAsStaff()) {
                 // Staff can view everyone
                 $this->user = null;
             }
         }
     }
     if ($this->user === null) {
         // Trigger 404
         throw new NotFoundException();
     }
 }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
 public function init(Website $website, Request $request)
 {
     $this->installedWidgets = $website->getWidgets();
     $widgetRepo = new WidgetRepository($website);
     $widgetId = $request->getParamInt(0);
     if ($widgetId === 0) {
         // New widget
         $this->placedWidget = $this->getNewWidget($website, $request);
     } else {
         $this->placedWidget = $widgetRepo->getPlacedWidget($widgetId);
     }
     if ($request->hasRequestValue("submit") && Validate::requestToken($request)) {
         // Use incoming data
         $widgetDefinition = $this->installedWidgets->getDefinition($this->placedWidget);
         $data = $widgetDefinition->parseData($website, $widgetId);
         $this->placedWidget->setData($data);
         if ($this->isValid($data)) {
             // Save widget
             $widgetRepo->savePlacedWidget($this->placedWidget);
             $this->addSaveMessage($this->placedWidget, $website->getText());
         }
     }
     $this->requestToken = RequestToken::generateNew();
     $this->requestToken->saveToSession();
 }
Exemplo n.º 5
0
 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();
 }
Exemplo n.º 6
0
    public function getPageContent(Website $website, Request $request)
    {
        // Don't allow to edit your own rank (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("rank")) {
            // Sent
            $rank = $request->getRequestInt("rank");
            $oAuth = $website->getAuth();
            if ($oAuth->isValidRankForAccounts($rank)) {
                // Valid rank id
                $this->user->setRank($rank);
                $userRepo = $website->getAuth()->getUserRepository();
                $userRepo->save($this->user);
                // Saved
                $textToDisplay .= '<p>' . $website->t("users.rank") . ' ' . $website->t("editor.is_changed") . '</p>';
                // Don't show form
                $show_form = false;
            } else {
                // Invalid rank
                $website->addError($website->t("users.rank") . ' ' . $website->t("errors.not_found"));
                $textToDisplay .= '<p><em>' . $website->tReplacedKey("errors.your_input_has_not_been_changed", "users.rank", true) . '</em></p>';
            }
        }
        // Show form
        if ($show_form) {
            // Variables
            $rank = $request->getRequestInt("rank", $this->user->getRank());
            $ranks = array(Authentication::RANK_USER, Authentication::RANK_MODERATOR, Authentication::RANK_ADMIN);
            // Form itself
            $textToDisplay .= <<<EOT
                <p>
                    {$website->t("users.rank.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="post">
                    <p>
                        <label for="rank">{$website->t("users.rank")}</label>:<span class="required">*</span><br />
                        {$this->get_ranks_box_html($website, $ranks, $rank)}
                    </p>
                    <p>
                        <input type="hidden" name="p" value="edit_rank" />
                        <input type="hidden" name="id" value="{$this->user->getId()}" />
                        <input type="submit" value="{$website->t('users.rank.edit')} " class="button" />
                    </p>
                </form>
EOT;
        }
        // Links
        $textToDisplay .= $this->get_account_links_html($website);
        return $textToDisplay;
    }
Exemplo n.º 7
0
 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);
 }
Exemplo n.º 8
0
 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);
 }
Exemplo n.º 9
0
 private function updateCommentFromRequest(Comment $comment, Request $request)
 {
     $comment->setBodyRaw($request->getRequestString("comment", ""));
     if ($comment->isByVisitor()) {
         $name = $request->getRequestString("name", "");
         $email = $request->getRequestString("email", "");
         $comment->setByVisitor($name, $email);
     }
 }
Exemplo n.º 10
0
 public function init(Website $website, Request $request)
 {
     $this->requestToken = RequestToken::generateNew();
     $this->menuName = $request->getRequestString("menu_name", "");
     if (Validate::requestToken($request)) {
         $this->handleSubmitedForm($website, $request);
     }
     $this->requestToken->saveToSession();
 }
Exemplo n.º 11
0
 public function init(Website $website, Request $request)
 {
     $categoryId = $request->getParamInt(0, 0);
     $categoriesRepo = new CategoryRepository($website->getDatabase());
     $this->category = $categoriesRepo->getCategory($categoryId);
     $articlesRepo = new ArticleRepository($website);
     $this->articles = $articlesRepo->getArticlesData($categoryId);
     $this->showArticleEditLinks = $website->isLoggedInAsStaff();
     $this->showCategoryEditLinks = $website->isLoggedInAsStaff(true);
 }
Exemplo n.º 12
0
 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();
 }
Exemplo n.º 13
0
 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;
 }
Exemplo n.º 14
0
 private function fetchComment(Request $request, Article $article, User $user = null)
 {
     $commentText = $request->getRequestString("comment", "");
     if ($user !== null) {
         return Comment::createForUser($user, $article, $commentText);
     } else {
         $displayName = $request->getRequestString("name", "");
         $email = $request->getRequestString("email", "");
         return Comment::createForVisitor($displayName, $email, $article, $commentText);
     }
 }
Exemplo n.º 15
0
 public function init(Website $website, Request $request)
 {
     $oArticles = new ArticleRepository($website);
     $yearNumber = $request->getParamInt(0, date('Y'));
     if ($yearNumber < self::MIN_YEAR || $yearNumber > self::MAX_YEAR) {
         $yearNumber = date('Y');
     }
     $this->year = DateTime::createFromFormat('Y', $yearNumber);
     $this->yearNumber = $yearNumber;
     $this->articlesInYear = $oArticles->getArticlesDataCalendarYear($this->year);
     $this->showCreateLinks = $website->isLoggedInAsStaff();
 }
Exemplo n.º 16
0
 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();
 }
Exemplo n.º 17
0
 public function init(Website $website, Request $request)
 {
     $menuId = $request->getParamInt(0, 0);
     $menuRepo = new MenuRepository($website->getDatabase());
     $this->menu = $menuRepo->getMenu($menuId);
     $this->linkName = $request->getRequestString("link_text", "");
     $this->linkUrl = $request->getRequestString("link_url", "");
     if (Validate::requestToken($request)) {
         $this->saveLink($website);
     }
     $this->requestToken = RequestToken::generateNew();
     $this->requestToken->saveToSession();
 }
Exemplo n.º 18
0
 public function init(Website $website, Request $request)
 {
     $isStaff = $website->isLoggedInAsStaff();
     $id = $request->getParamInt(0);
     $this->editLinks = $website->isLoggedInAsStaff(true);
     // Load document
     $documentRepo = new DocumentRepository($website->getDatabase(), $isStaff);
     $this->document = $documentRepo->getDocument($id);
     // Load document widgets
     $this->widgetLoader = $website->getWidgets();
     $widgetRepo = new WidgetRepository($website);
     $this->widgets = $widgetRepo->getWidgetsInDocumentWithId($id);
 }
Exemplo n.º 19
0
    public function getPageContent(Website $website, Request $request)
    {
        $show_form = true;
        $textToDisplay = "";
        if (isset($_REQUEST["display_name"])) {
            // Sent
            $display_name = $request->getRequestString("display_name");
            if (Validate::displayName($display_name)) {
                // Valid display_name
                $this->user->setDisplayName($display_name);
                $userRepo = $website->getAuth()->getUserRepository();
                $userRepo->save($this->user);
                // Saved
                $textToDisplay .= '<p>' . $website->t("users.display_name") . ' ' . $website->t("editor.is_changed") . '</p>';
                // Don't show form
                $show_form = false;
            } else {
                // Invalid display_name
                $website->addError($website->t("users.display_name") . ' ' . Validate::getLastError($website));
                $textToDisplay .= '<p><em>' . $website->tReplacedKey("errors.your_input_has_not_been_changed", "users.display_name", true) . '</em></p>';
            }
        }
        // Show form
        if ($show_form) {
            // Text above form
            $textToDisplay .= "<p>" . $website->t("users.display_name.edit.explained") . "</p>\n";
            if ($this->editing_someone_else) {
                $textToDisplay .= "<p><em>" . $website->tReplaced("users.edit_other", $this->user->getDisplayName()) . "</em></p>\n";
            }
            // Form itself
            $display_name = isset($_POST['display_name']) ? htmlSpecialChars($_POST['display_name']) : $this->user->getDisplayName();
            $textToDisplay .= <<<EOT
                <p>{$website->t("main.fields_required")}</p>
                <form action="{$website->getUrlMain()}" method="post">
                    <p>
                        <label for="display_name">{$website->t('users.display_name')}:</label><span class="required">*</span><br />
                            <input type="text" id="display_name" name="display_name" value="{$display_name}"/><br />
                    </p>
                    <p>
                        <input type="hidden" name="id" value="{$this->user->getId()}" />
                        <input type="hidden" name="p" value="edit_display_name" />
                        <input type="submit" value="{$website->t('users.display_name.edit')} " class="button" />
                    </p>
                </form>
EOT;
        }
        // Links
        $textToDisplay .= $this->get_account_links_html($website);
        return $textToDisplay;
    }
Exemplo n.º 20
0
 public function init(Website $website, Request $request)
 {
     $userId = $request->getParamInt(0);
     // Fetch user
     $userRepo = $website->getAuth()->getUserRepository();
     $user = $userRepo->getById($userId);
     if (!$user->canLogIn()) {
         // Can't log in to deleted or banned users
         throw new NotFoundException();
     }
     // Set user
     $this->newUser = $user;
     $website->getAuth()->setCurrentUser($user);
 }
Exemplo n.º 21
0
 public function init(Website $website, Request $request)
 {
     $articleId = $request->getParamInt(0);
     $oArticles = new ArticleRepository($website);
     $this->article = $oArticles->getArticleOrFail($articleId);
     $this->editLinks = $website->isLoggedInAsStaff();
     $this->currentUser = $website->getAuth()->getCurrentUser();
     if ($this->article->showComments) {
         $oComments = new CommentRepository($website->getDatabase());
         $this->comments = $oComments->getCommentsArticle($this->article->getId());
     } else {
         $this->comments = [];
     }
 }
Exemplo n.º 22
0
 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();
 }
Exemplo n.º 23
0
 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();
     }
 }
Exemplo n.º 24
0
    public function getPageContent(Website $website, Request $request)
    {
        $show_form = true;
        $textToDisplay = "";
        if ($request->hasRequestValue("email")) {
            // Sent
            $email = $request->getRequestString("email");
            if (Validate::email($email)) {
                // Valid email
                $this->user->setEmail($email);
                $userRepo = $website->getAuth()->getUserRepository();
                $userRepo->save($this->user);
                // Saved
                $textToDisplay .= '<p>' . $website->t("users.email") . ' ' . $website->t("editor.is_changed") . '</p>';
                // Don't show form
                $show_form = false;
            } else {
                // Invalid email
                $website->addError($website->t("users.email") . ' ' . Validate::getLastError($website));
                $textToDisplay .= '<p><em>' . $website->tReplacedKey("errors.your_input_has_not_been_changed", "users.email", true) . '</em></p>';
            }
        }
        // Show form
        if ($show_form) {
            // Text above form
            $textToDisplay .= "<p>" . $website->t("users.email.edit.explained") . "</p>\n";
            if ($this->editing_someone_else) {
                $textToDisplay .= "<p><em>" . $website->tReplaced("users.edit_other", $this->user->getDisplayName()) . "</em></p>\n";
            }
            // Form itself
            $email = htmlSpecialChars($request->getRequestString("email", $this->user->getEmail()));
            $textToDisplay .= <<<EOT
                <form action="{$website->getUrlMain()}" method="post">
                    <p>
                        <label for="email">{$website->t('users.email')}:</label><br /><input type="text" id="email" name="email" value="{$email}"/><br />
                    </p>
                    <p>
                        <input type="hidden" name="id" value="{$this->user->getId()}" />
                        <input type="hidden" name="p" value="edit_email" />
                        <input type="submit" value="{$website->t('users.email.edit')} " class="button" />
                    </p>
                </form>
EOT;
        }
        // Links
        $textToDisplay .= $this->get_account_links_html($website);
        return $textToDisplay;
    }
Exemplo n.º 25
0
 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"));
     }
 }
Exemplo n.º 26
0
 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();
         }
     }
 }
Exemplo n.º 27
0
 public function init(Website $website, Request $request)
 {
     $this->showEditLinks = $website->isLoggedInAsStaff();
     $this->selectedYear = $request->getRequestInt("year", 0);
     $this->selectedCategory = $request->getParamInt(0);
     // Fetch all categories
     $categories = new CategoryRepository($website->getDatabase());
     $this->allCategories = $categories->getCategoriesArray();
     // Check if valid category
     if ($this->selectedCategory != 0 && !array_key_exists($this->selectedCategory, $this->allCategories)) {
         $website->addError($website->t("main.category") . " " . $website->t("errors.not_found"));
         $this->selectedCategory = 0;
     }
     // Fetch all articles
     $articles = new ArticleRepository($website);
     $this->articleCountInYears = $articles->getArticleCountInYears($this->selectedCategory);
     $this->foundArticles = $articles->getArticlesDataArchive($this->selectedYear, $this->selectedCategory);
 }
Exemplo n.º 28
0
 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();
 }
Exemplo n.º 29
0
 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();
 }
Exemplo n.º 30
0
 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();
     }
 }