コード例 #1
0
ファイル: EditRankPage.php プロジェクト: rutgerkok/rCMS
    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;
    }
コード例 #2
0
ファイル: main.php プロジェクト: rutgerkok/rCMS
 public function parseData(Website $website, $id)
 {
     $data = [];
     // Title
     $data["title"] = trim($website->getRequestString("title_" . $id, ""));
     if (strLen($data["title"]) > 200) {
         $website->addError($website->t("widgets.title") . " " . $website->t("errors.is_too_long_num", 200));
         $data["valid"] = false;
     }
     // Categories
     $categories = isset($_REQUEST["categories_" . $id]) ? $_REQUEST["categories_" . $id] : [];
     if (!is_array($categories)) {
         // Check for valid array
         $website->addError($website->tReplacedKey("errors.none_set", "main.categories", true));
         $data["valid"] = false;
         $categories = [];
     }
     // Add all categories to the real array
     $data["categories"] = [];
     foreach ($categories as $category_id) {
         $category_id = (int) $category_id;
         if ($category_id > 0) {
             $data["categories"][] = $category_id;
         }
     }
     // Check the real array
     if (count($data["categories"]) == 0) {
         $website->addError($website->tReplacedKey("errors.none_set", "main.categories", true));
         $data["valid"] = false;
     }
     // Count
     if (isset($_REQUEST["count_" . $id])) {
         $data["count"] = (int) $_REQUEST["count_" . $id];
         if (!Validate::range($data["count"], 1, 20)) {
             $website->addError($website->t("articles.count") . " " . Validate::getLastError($website));
             $data["valid"] = false;
         }
     } else {
         $website->addError($website->t("articles.count") . " " . $website->t("errors.not_found"));
         $data["valid"] = false;
     }
     // Display type
     if (isset($_REQUEST["display_type_" . $id])) {
         $data["display_type"] = (int) $_REQUEST["display_type_" . $id];
         if ($data["display_type"] != self::TYPE_LIST && $data["display_type"] != self::TYPE_WITHOUT_METADATA && $data["display_type"] != self::TYPE_WITH_METADATA && $data["display_type"] != self::TYPE_LIST_WITH_IMAGES) {
             $website->addError($website->t("articles.count") . " " . $website->t("errors.not_found"));
             $data["valid"] = false;
         }
     } else {
         $website->addError($website->t("articles.count") . " " . $website->t("errors.not_found"));
         $data["valid"] = false;
     }
     // Order
     if (isset($_REQUEST["order_" . $id])) {
         $data["order"] = (int) $_REQUEST["order_" . $id];
         if ($data["order"] != self::SORT_NEWEST_TOP && $data["order"] != self::SORT_OLDEST_TOP) {
             $website->addError($website->t("articles.order") . " " . $website->t("errors.not_found"));
             $data["valid"] = false;
         }
     } else {
         $website->addError($website->t("articles.order") . " " . $website->t("errors.not_found"));
         $data["valid"] = false;
     }
     // Archive
     if (isset($_REQUEST["archive_" . $id])) {
         $data["archive"] = true;
     } else {
         $data["archive"] = false;
     }
     return $data;
 }