Beispiel #1
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);
 }
Beispiel #2
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;
    }
Beispiel #3
0
    private function getNotice(Website $website)
    {
        return <<<WIDGET
            <p><em>
                {$website->tReplaced("widgets.missing_definition", $this->directoryName)}
            </em></p>
WIDGET;
    }
Beispiel #4
0
 /**
  * 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;
 }
Beispiel #5
0
 public function parseData(Website $website, $id)
 {
     $data = [];
     $data["title"] = $website->getRequestString("title_" . $id, "");
     if (strLen($data["title"]) > self::MAX_TITLE_LENGTH) {
         // Limit title length
         $website->addError($website->t("widgets.title") . " " . $website->tReplaced("errors.too_long_num", self::MAX_TITLE_LENGTH));
         $data["valid"] = false;
     }
     return $data;
 }
 public function get_menu_bar(Website $website, $page, $users)
 {
     $pages = ceil($users / self::USERS_PER_PAGE);
     // No need for a menu when there is only one page
     if ($pages <= 1) {
         return "";
     }
     $returnValue = '<p class="result_selector_menu">';
     // Link to previous page
     if ($page > 0) {
         $returnValue .= '<a class="arrow" href="' . $website->getUrlPage("account_management", $page - 1);
         $returnValue .= '">' . $website->t("articles.page.previous") . '</a> ';
     }
     $returnValue .= $website->tReplaced('articles.page.current', $page + 1, $pages);
     // Link to next page
     if ($page + 1 < $pages) {
         $returnValue .= ' <a class="arrow" href="' . $website->getUrlPage("account_management", $page + 1);
         $returnValue .= '">' . $website->t("articles.page.next") . '</a>';
     }
     $returnValue .= '</p>';
     return $returnValue;
 }
Beispiel #7
0
    /** Gets the links for the bottom of the page */
    public function get_account_links_html(Website $website)
    {
        $textToDisplay = "";
        if ($this->editing_someone_else) {
            // Editing someone else, don't show "My account" link
            $textToDisplay .= <<<EOT
            <p>
                <a class="arrow" href="{$website->getUrlPage("account", $this->user->getId())}">
                    {$website->tReplaced("users.profile_page_of", $this->user->getDisplayName())}
                </a><br />
                <a class="arrow" href="{$website->getUrlPage("account_management")}">
                    {$website->t("main.account_management")}
                </a>
EOT;
        } else {
            $textToDisplay .= '<p><a class="arrow" href="' . $website->getUrlPage("account") . '">' . $website->t("main.my_account") . "</a>\n";
            if ($website->isLoggedInAsStaff(true)) {
                $textToDisplay .= '<br /><a class="arrow" href="' . $website->getUrlPage("account_management") . '">' . $website->t("main.account_management") . "</a>\n";
            }
            $textToDisplay .= "</p>";
        }
        return $textToDisplay;
    }
Beispiel #8
0
    /**
     * Returns links to edit the profile, based on the permissions of the user
     * that is viewing this page. 
     */
    public function get_edit_links_html(Website $website)
    {
        $viewing_user = $website->getAuth()->getCurrentUser();
        $returnValue = "";
        // Get privileges
        $is_viewing_themselves = false;
        $is_viewing_as_moderator = false;
        $is_viewing_as_admin = false;
        if ($viewing_user != null) {
            $is_viewing_themselves = $this->user->getId() == $viewing_user->getId();
            if ($website->isLoggedInAsStaff(false)) {
                $is_viewing_as_moderator = true;
            }
            if ($website->isLoggedInAsStaff(true)) {
                $is_viewing_as_admin = true;
            }
        }
        // Gravatar link + help
        if ($is_viewing_themselves) {
            // No way that other admins can edit someone's avatar, so only display help text for owner
            $returnValue .= <<<EOT
                <p>
                     {$website->tReplaced("users.gravatar.explained", '<a href="http://gravatar.com/">gravatar.com</a>')}
                </p>
EOT;
        }
        // Add all account edit links
        $edit_links = [];
        if (!$is_viewing_themselves && $is_viewing_as_moderator) {
            // Accessed by a moderator that isn't viewing his/her own account
            // Add (un)ban link
            $edit_links[] = $this->get_edit_link($website, "edit_account_status", "users.status.edit");
        }
        if ($is_viewing_themselves || $is_viewing_as_admin) {
            // Accessed by the user themselves or an admin
            // Display links to edit profile
            $edit_links[] = $this->get_edit_link($website, "edit_email", "users.email.edit");
            $edit_links[] = $this->get_edit_link($website, "edit_password", "users.password.edit");
            $edit_links[] = $this->get_edit_link($website, "edit_display_name", "users.display_name.edit");
        }
        if (!$is_viewing_themselves && $is_viewing_as_admin) {
            // Accessed by an admin that isn't viewing his/her own account
            // Add rank edit link and login link
            $edit_links[] = $this->get_edit_link($website, "edit_rank", "users.rank.edit");
            // Only display login link if account is not deleted/banned
            if ($this->user->canLogIn()) {
                $edit_links[] = $this->get_edit_link($website, "login_other", "main.log_in");
            }
        }
        if (count($edit_links) > 0) {
            $returnValue .= "<p>\n" . implode($edit_links) . "</p>\n";
        }
        return $returnValue;
    }
Beispiel #9
0
 public function parseData(Website $website, $id)
 {
     $data = [];
     $data["title"] = isset($_REQUEST["title_" . $id]) ? trim($_REQUEST["title_" . $id]) : "";
     if (strLen($data["title"]) > self::TITLE_MAX_LENGTH) {
         $website->addError($website->t("widgets.title") . " " . $website->tReplaced("errors.too_long_num", self::TITLE_MAX_LENGTH));
         $data["valid"] = false;
     }
     $data["menu_id"] = isset($_REQUEST["menu_id_" . $id]) ? (int) $_REQUEST["menu_id_" . $id] : 0;
     $oMenu = new MenuRepository($website->getDatabase());
     try {
         $oMenu->getMenu($data["menu_id"]);
     } catch (NotFoundException $e) {
         $website->addError($website->t("widgets.menu") . " " . $website->t("errors.not_found"));
         $data["valid"] = false;
     }
     return $data;
 }
Beispiel #10
0
 /**
  * The function should return an array (id=>name) with all places for widgets.
  * Ids must be a whole number larger than 1. (Id 0 is unused, id 1 is used on homepage)
  * @param Website $website The website object, used for translations.
  */
 public function getWidgetAreas(Website $website)
 {
     // Get the number of widgets
     $areas = $this->infoFile->getInteger("widget_areas", 1);
     if ($areas == 0) {
         // No widgets in this theme
         return [];
     } elseif ($areas == 1) {
         // One widget area on position 2
         return [2 => $website->t("widgets.the_sidebar")];
     } else {
         // More widget areas, starting on position 2
         $widgetAreas = [];
         for ($i = 0; $i < $areas; $i++) {
             $widgetAreas[$i + 2] = $website->tReplaced("widgets.sidebar_n", $i + 1);
         }
         return $widgetAreas;
     }
 }