コード例 #1
0
ファイル: EditDocumentPage.php プロジェクト: rutgerkok/rCMS
 private function saveData(Text $text, Request $request, Document $document, DocumentRepository $documentRepo)
 {
     if (!$request->hasRequestValue("intro") || !$request->hasRequestValue("title")) {
         return;
     }
     if ($document->isForWidgetArea()) {
         $text->addError($text->t("main.document") . ' ' . $text->t("errors.not_editable"));
         return;
     }
     $document->setIntro($request->getRequestString("intro", ''));
     $document->setTitle($request->getRequestString("title", ''));
     $valid = true;
     if (!Validate::requestToken($request)) {
         $valid = false;
     }
     if (!Validate::stringLength($document->getIntro(), Document::INTRO_MIN_LENGTH, Document::INTRO_MAX_LENGTH)) {
         $text->addError($text->t("documents.intro") . ' ' . Validate::getLastError($text));
         $valid = false;
     }
     if (!Validate::stringLength($document->getTitle(), Document::TITLE_MIN_LENGTH, Document::TITLE_MAX_LENGTH)) {
         $text->addError($text->t("documents.title") . ' ' . Validate::getLastError($text));
         $valid = false;
     }
     if (!$valid) {
         return;
     }
     $isNew = $document->getId() == 0;
     $documentRepo->saveDocument($document);
     if ($isNew) {
         $text->addMessage($text->t("main.document") . ' ' . $text->t("editor.is_created"));
     } else {
         $text->addMessage($text->t("main.document") . ' ' . $text->t("editor.is_edited"));
     }
 }
コード例 #2
0
ファイル: EditCategoryPage.php プロジェクト: rutgerkok/rCMS
 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);
     }
 }
コード例 #3
0
ファイル: EditCommentPage.php プロジェクト: rutgerkok/rCMS
 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);
     }
 }
コード例 #4
0
ファイル: AddCommentPage.php プロジェクト: rutgerkok/rCMS
 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);
     }
 }
コード例 #5
0
ファイル: AddLinkPage.php プロジェクト: rutgerkok/rCMS
 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();
 }
コード例 #6
0
ファイル: EditEmailPage.php プロジェクト: rutgerkok/rCMS
    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;
    }
コード例 #7
0
ファイル: DeleteArticlePage.php プロジェクト: rutgerkok/rCMS
 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();
 }
コード例 #8
0
ファイル: SearchPage.php プロジェクト: rutgerkok/rCMS
 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);
 }
コード例 #9
0
ファイル: CreateAccountPage.php プロジェクト: rutgerkok/rCMS
 private function handleUserRequest(Website $website, Request $request)
 {
     $username = $request->getRequestString("creating_username", "");
     $displayName = $request->getRequestString("creating_display_name", "");
     $password1 = $request->getRequestString("creating_password1", "");
     $password2 = $request->getRequestString("creating_password2", "");
     $email = $request->getRequestString("creating_email", "");
     $newUser = User::createNewUser($username, $displayName, $password1);
     $newUser->setEmail($email);
     $text = $website->getText();
     $userRepo = new UserRepository($website->getDatabase());
     if (Validate::requestToken($request) && $this->validateInput($newUser, $password1, $password2, $userRepo, $text)) {
         $userRepo->save($newUser);
         $this->accountCreated = true;
         $text->addMessage($text->t("users.create.done"));
     }
     return $newUser;
 }
コード例 #10
0
ファイル: AddMenuPage.php プロジェクト: rutgerkok/rCMS
 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();
 }
コード例 #11
0
 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;
 }
コード例 #12
0
ファイル: SwitchThemePage.php プロジェクト: rutgerkok/rCMS
 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;
 }
コード例 #13
0
ファイル: EditWidgetPage.php プロジェクト: rutgerkok/rCMS
 /**
  * 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);
 }
コード例 #14
0
ファイル: EditLinkPage.php プロジェクト: rutgerkok/rCMS
 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")));
     }
 }
コード例 #15
0
ファイル: RenameMenuPage.php プロジェクト: rutgerkok/rCMS
 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();
 }
コード例 #16
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;
    }
コード例 #17
0
ファイル: InstallPage.php プロジェクト: rutgerkok/rCMS
 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"));
     }
 }
コード例 #18
0
ファイル: MoveWidgetPage.php プロジェクト: rutgerkok/rCMS
 public function init(Website $website, Request $request)
 {
     $text = $website->getText();
     $widgetId = $request->getParamInt(0);
     $moveUp = $request->getRequestString("direction", "up") === "up";
     $widgetRepository = new WidgetRepository($website);
     $this->placedWidget = $widgetRepository->getPlacedWidget($widgetId);
     $this->installedWidgets = $website->getWidgets();
     if (Validate::requestToken($request)) {
         // move
         $this->moveWidget($widgetRepository, $moveUp);
         $this->redirectUrl = $text->getUrlPage("edit_document", $this->placedWidget->getDocumentId());
     } else {
         $text->addError(Validate::getLastError($text));
         $linkText = $text->t("widgets.move_down");
         if ($moveUp) {
             $linkText = $text->t("widgets.move_up");
         }
         // Generate new request token, allowing user to perform action again
         $newRequestToken = RequestToken::generateNew();
         $this->moveLink = Link::of($text->getUrlPage("move_widget", $widgetId, ["direction" => $moveUp ? "up" : "down", RequestToken::FIELD_NAME => $newRequestToken->getTokenString()]), $linkText);
         $newRequestToken->saveToSession();
     }
 }
コード例 #19
0
ファイル: EditPasswordPage.php プロジェクト: rutgerkok/rCMS
    public function getPageContent(Website $website, Request $request)
    {
        $show_form = true;
        $textToDisplay = "";
        if ($request->hasRequestValue("password")) {
            // Sent
            $old_password = $request->getRequestString("old_password");
            if ($this->editing_someone_else || $this->user->verifyPassword($old_password)) {
                // Old password entered correctly
                $password = $request->getRequestString("password");
                $password2 = $request->getRequestString("password2");
                if (Validate::password($password, $password2)) {
                    // Valid password
                    $this->user->setPassword($password);
                    $userRepo = $website->getAuth()->getUserRepository();
                    $userRepo->save($this->user);
                    // Saved
                    $textToDisplay .= '<p>' . $website->t("users.password") . ' ' . $website->t("editor.is_changed") . '</p>';
                    // Update login cookie (only when changing your own password)
                    if (!$this->editing_someone_else) {
                        $website->getAuth()->setLoginCookie();
                    }
                    // Don't show form
                    $show_form = false;
                } else {
                    // Invalid new password
                    $website->addError($website->t("users.password") . ' ' . Validate::getLastError($website));
                    $textToDisplay .= '<p><em>' . $website->tReplacedKey("errors.your_input_has_not_been_changed", "users.password", true) . '</em></p>';
                }
            } else {
                // Invalid old password
                $website->addError($website->t("users.old_password") . ' ' . $website->t("errors.not_correct"));
                $textToDisplay .= '<p><em>' . $website->tReplacedKey("errors.your_input_has_not_been_changed", "users.password", true) . '</em></p>';
            }
        }
        // Show form
        if ($show_form) {
            // Text above form
            $textToDisplay .= "<p>" . $website->tReplaced("users.password.edit.explained", Validate::$MIN_PASSWORD_LENGHT) . "</p>\n";
            if ($this->editing_someone_else) {
                $textToDisplay .= "<p><em>" . $website->tReplaced("users.edit_other", $this->user->getDisplayName()) . "</em></p>\n";
            }
            // Form itself
            $old_password_text = "";
            if (!$this->editing_someone_else) {
                // Add field to verify old password when editing yourself
                $old_password_text = <<<EOT
                    <label for="old_password">{$website->t('users.old_password')}:</label><span class="required">*</span><br />
                    <input type="password" id="old_password" name="old_password" value=""/><br />
EOT;
            }
            $textToDisplay .= <<<EOT
                <p>{$website->t("main.fields_required")}</p>
                <form action="{$website->getUrlMain()}" method="post">
                    <p>
                        {$old_password_text}
                        <label for="password">{$website->t('users.password')}:</label><span class="required">*</span><br />
                        <input type="password" id="password" name="password" value=""/><br />
                        <label for="password2">{$website->t('users.password.repeat')}:</label><span class="required">*</span><br />
                        <input type="password" id="password2" name="password2" value=""/><br />
                    </p>
                    <p>
                        <input type="hidden" name="p" value="edit_password" />
                        <input type="hidden" name="id" value="{$this->user->getId()}" />
                        <input type="submit" value="{$website->t('users.password.edit')} " class="button" />
                    </p>
                </form>
EOT;
        }
        // Links
        $textToDisplay .= $this->get_account_links_html($website);
        return $textToDisplay;
    }
コード例 #20
0
ファイル: RequestToken.php プロジェクト: rutgerkok/rCMS
 /**
  * Creates the request token passed to this page. If nothing was stored in
  * the request a token of an empty string is returned.
  * @param Request $request The request.
  * @return RequestToken The token.
  */
 public static final function fromRequest(Request $request)
 {
     return new RequestToken($request->getRequestString(self::FIELD_NAME, ""));
 }
コード例 #21
0
ファイル: ArticleEditor.php プロジェクト: rutgerkok/rCMS
 public function processInput(Text $text, Request $request, CategoryRepository $oCategories)
 {
     $article = $this->articleObject;
     $noErrors = true;
     // Title
     if ($request->hasRequestValue("article_title")) {
         $title = trim($request->getRequestString('article_title'));
         if (strLen($title) > Article::MAX_TITLE_LENGTH) {
             $text->addError($text->t("articles.title") . " " . $text->tReplaced("errors.is_too_long_num", Article::MAX_TITLE_LENGTH));
             $noErrors = false;
         }
         if (strLen($title) < Article::MIN_TITLE_LENGTH) {
             $text->addError($text->tReplacedKey("errors.please_enter_this", "articles.title", true));
             $noErrors = false;
         }
         $article->setTitle($title);
     }
     // Intro
     if ($request->hasRequestValue("article_intro")) {
         $intro = trim($request->getRequestString("article_intro"));
         if (strLen($intro) < Article::MIN_INTRO_LENGTH) {
             $text->addError($text->tReplacedKey("errors.please_enter_this", "articles.intro", true));
             $noErrors = false;
         }
         if (strLen($intro) > Article::MAX_INTRO_LENGTH) {
             $text->addError($text->t("articles.intro") . " " . $text->tReplaced("errors.is_too_long_num", Article::MAX_INTRO_LENGTH));
             $noErrors = false;
         }
         $article->setIntro($intro);
     }
     // Body
     if ($request->hasRequestValue("article_body")) {
         $body = trim($request->getRequestString("article_body"));
         if (strLen($body) < Article::MIN_BODY_LENGTH) {
             $text->addError($text->tReplacedKey("errors.please_enter_this", "articles.body", true));
             $noErrors = false;
         }
         if (strLen($body) > Article::MAX_BODY_LENGTH) {
             $text->addError($text->t("articles.body") . " " . $text->tReplaced("errors.is_too_long_num", Article::MAX_BODY_LENGTH));
             $noErrors = false;
         }
         $article->setBody($body);
     }
     // Category
     if ($request->hasRequestValue("article_category")) {
         $categoryId = (int) $request->getRequestString('article_category', 0);
         if ($categoryId == 0) {
             // Silent failure when category id is set to 0, as it is a default value
             $noErrors = false;
         } elseif (!$this->categoryExists($oCategories, $categoryId)) {
             $text->addError($text->t("main.category") . " " . $website->t("errors.not_found"));
             $noErrors = false;
         }
         $article->categoryId = $categoryId;
     }
     // Featured image
     if ($request->hasRequestValue("article_featured_image")) {
         $featuredImage = trim($request->getRequestString("article_featured_image"));
         if (strLen($featuredImage) > Article::MAX_FEATURED_IMAGE_URL_LENGTH) {
             $text->addError($text->t("articles.featured_image") . " " . $text->tReplaced("ërrors.is_too_long_num", Article::MAX_FEATURED_IMAGE_URL_LENGTH));
             $noErrors = false;
         }
         $article->featuredImage = $featuredImage;
     }
     // Pinned, hidden, comments
     if ($request->hasRequestValue("submit")) {
         $article->pinned = $request->hasRequestValue("article_pinned");
         $article->setHidden($request->hasRequestValue("article_hidden"));
         $article->showComments = $request->hasRequestValue("article_comments");
     }
     // Event date
     $eventDate = "";
     $eventTime = "";
     if ($request->hasRequestValue("article_eventdate")) {
         $eventDate = trim($request->getRequestString("article_eventdate"));
     }
     if ($request->hasRequestValue("article_eventtime") && $eventDate) {
         $eventTime = trim($request->getRequestString("article_eventtime"));
     }
     if (empty($eventDate) && $request->hasRequestValue("article_eventdate")) {
         // Field was made empty, so delete date on article
         $article->onCalendar = null;
     }
     if (!empty($eventDate)) {
         if (strtotime($eventDate) === false) {
             $text->addError($text->t("articles.event_date") . " " . $text->t("errors.not_correct"));
             $noErrors = false;
         } else {
             // Add date to article
             $article->onCalendar = new DateTime($eventDate . " " . $eventTime);
         }
     }
     return $noErrors;
 }
コード例 #22
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;
    }