Example #1
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;
    }
Example #2
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);
 }
Example #3
0
 /**
  * Creates a new widget based on the request paramaters, or throws an
  * exception on error.
  * @param Website $website The website object.
  * @param Request $request The request.
  * @return PlacedWidget A new widget, still needs to be saved in the database.
  * @throws NotFoundException If the document or widget type in the request
  * is non-existant.
  */
 private function getNewWidget(Website $website, Request $request)
 {
     $directoryName = $request->getRequestString("directory_name", "");
     if ($directoryName === "") {
         throw new NotFoundException();
     }
     // Get document
     $documentRepo = new DocumentRepository($website->getDatabase(), true);
     $documentId = $request->getRequestInt("document_id", 0);
     $document = $documentRepo->getDocumentOrWidgetArea($website->getWidgets(), $website->getText(), $documentId);
     return PlacedWidget::newPlacedWidget($website->getUriWidgets(), $directoryName, $document);
 }
Example #4
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);
 }
Example #5
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();
         }
     }
 }
 private function handleUserRequest(Website $website, Request $request)
 {
     $username = $request->getRequestString("creating_username", "");
     $displayName = $request->getRequestString("creating_display_name", "");
     $password = $request->getRequestString("creating_password", "");
     $email = $request->getRequestString("creating_email", "");
     $rank = $request->getRequestInt("creating_rank", 0);
     $newUser = User::createNewUser($username, $displayName, $password);
     $newUser->setEmail($email);
     $newUser->setRank($rank);
     $text = $website->getText();
     $userRepo = new UserRepository($website->getDatabase());
     if (Validate::requestToken($request) && $this->validateInput($newUser, $password, $website->getAuth(), $userRepo, $text)) {
         $userRepo->save($newUser);
         $this->accountCreated = true;
         $text->addMessage($text->t("users.create.other.done"), Link::of($text->getUrlPage("create_account_admin"), $text->t("users.create_another")), Link::of($text->getUrlPage("account_management"), $text->t("main.account_management")));
     }
     return $newUser;
 }
Example #7
0
    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;
    }