コード例 #1
0
ファイル: DeleteCategoryPage.php プロジェクト: rutgerkok/rCMS
 private function deleteCategory(CategoryRepository $categoryRepo, ArticleRepository $articleRepo, Text $text)
 {
     $categoryRepo->deleteCategory($articleRepo, $this->category);
     $viewAll = Link::of($text->getUrlPage("category_list"), $text->t("categories.view_all"));
     $text->addMessage($text->t("main.category") . " " . $text->t("editor.is_deleted"), $viewAll);
     $this->deleted = true;
 }
コード例 #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
ファイル: CategoryListPage.php プロジェクト: rutgerkok/rCMS
 public function init(Website $website, Request $request)
 {
     parent::init($website, $request);
     $categoryRepo = new CategoryRepository($website->getDatabase());
     $this->categories = $categoryRepo->getCategoriesComplete();
     $this->editLinks = $website->isLoggedInAsStaff(true);
 }
コード例 #4
0
ファイル: CategoryPage.php プロジェクト: rutgerkok/rCMS
 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);
 }
コード例 #5
0
ファイル: ArchivePage.php プロジェクト: rutgerkok/rCMS
 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);
 }
コード例 #6
0
ファイル: EditArticlePage.php プロジェクト: rutgerkok/rCMS
 public function init(Website $website, Request $request)
 {
     $text = $website->getText();
     $currentUser = $website->getAuth()->getCurrentUser();
     $articleId = $request->getParamInt(0);
     $articleRepository = new ArticleRepository($website);
     $article = $this->getArticle($articleRepository, $currentUser, $articleId);
     $articleEditor = new ArticleEditor($article);
     $this->articleEditor = $articleEditor;
     $categoryRepository = new CategoryRepository($website->getDatabase());
     $this->allCategories = $categoryRepository->getCategories();
     $this->richEditor = new CKEditor($website->getText(), $website->getConfig(), $website->getThemeManager());
     // Validate token, then save new one to session
     $validToken = Validate::requestToken($request);
     $this->token = RequestToken::generateNew();
     $this->token->saveToSession();
     // Now check input
     if (!$articleEditor->processInput($website->getText(), $request, $categoryRepository)) {
         return;
     }
     if ($request->hasRequestValue("submit") && $validToken) {
         // Try to save
         $article = $articleEditor->getArticle();
         if ($articleRepository->saveArticle($article)) {
             $viewArticleLink = Link::of($website->getUrlPage("article", $article->getId()), $website->t("articles.view"));
             if ($articleId == 0) {
                 // New article created
                 $text->addMessage($text->t("main.article") . " " . $text->t("editor.is_created"), $viewArticleLink);
             } else {
                 // Article updated
                 $text->addMessage($text->t("main.article") . " " . $text->t("editor.is_edited"), $viewArticleLink);
             }
             // Check for redirect
             if ($request->getRequestString("submit") == $website->t("editor.save_and_quit")) {
                 $this->redirectUrl = $website->getUrlPage("article", $article->getId());
             }
         }
     }
 }
コード例 #7
0
ファイル: ArticleEditor.php プロジェクト: rutgerkok/rCMS
 private function categoryExists(CategoryRepository $repo, $id)
 {
     try {
         $repo->getCategory($id);
         return true;
     } catch (NotFoundException $ex) {
         return false;
     }
 }
コード例 #8
0
ファイル: ThemeElements.php プロジェクト: rutgerkok/rCMS
 public function writeTopMenu(StreamInterface $stream)
 {
     $website = $this->website;
     $text = $website->getText();
     $config = $website->getConfig();
     $links = [];
     $links[] = Link::of($text->getUrlMain(), $text->t("main.home"));
     if ($config->isDatabaseUpToDate()) {
         $menuId = (int) $config->get(Config::OPTION_MAIN_MENU_ID, 0);
         if ($menuId === 0) {
             $categoriesRepo = new CategoryRepository($website->getDatabase());
             $links = array_merge($links, $categoriesRepo->getCategoryLinks($text));
         } else {
             $linkRepo = new LinkRepository($website->getDatabase());
             $links = array_merge($links, $linkRepo->getLinksByMenu($menuId));
         }
     }
     $menuTemplate = new MenuTemplate($website->getText(), $links);
     $menuTemplate->writeText($stream);
 }
コード例 #9
0
ファイル: main.php プロジェクト: rutgerkok/rCMS
    public function getEditor(Website $website, $widget_id, $data)
    {
        $title = isset($data["title"]) ? $data["title"] : "";
        $categories = isset($data["categories"]) ? $data["categories"] : [];
        $count = isset($data["count"]) ? $data["count"] : 4;
        $display_type = isset($data["display_type"]) ? $data["display_type"] : self::TYPE_WITHOUT_METADATA;
        $order = isset($data["order"]) ? $data["order"] : self::SORT_NEWEST_TOP;
        $archive = isset($data["archive"]) ? $data["archive"] : true;
        // Title
        $textToDisplay = "<p>\n";
        $textToDisplay .= '<label for="title_' . $widget_id . '">';
        $textToDisplay .= $website->t("widgets.title") . "</label>:<br />\n";
        $textToDisplay .= '<input type="text" name="title_' . $widget_id . '" id="title_' . $widget_id . '"';
        $textToDisplay .= 'value="' . htmlSpecialChars($title) . '" />' . "\n";
        $textToDisplay .= "</p>\n";
        // Categories
        $oCategories = new CategoryRepository($website->getDatabase());
        $textToDisplay .= "<p>" . $website->t("main.categories") . ':';
        $textToDisplay .= '<span class="required">*</span><br />' . "\n";
        foreach ($oCategories->getCategories() as $category) {
            $checkbox_id = 'categories_' . $category->getId() . "_" . $widget_id;
            $textToDisplay .= '<input type="checkbox" class="checkbox" ';
            $textToDisplay .= 'name="categories_' . $widget_id . '[]" ';
            if (array_search($category->getId(), $categories) !== false) {
                $textToDisplay .= 'checked="checked" ';
            }
            $textToDisplay .= 'id="' . $checkbox_id . '" value="' . $category->getId() . '" />';
            $textToDisplay .= '<label for="' . $checkbox_id . '">' . htmlSpecialChars($category->getName()) . "</label><br />" . "\n";
        }
        $textToDisplay .= "</p>\n";
        // Count
        $textToDisplay .= '<p><label for="count_' . $widget_id . '">' . $website->t("articles.count") . ':';
        $textToDisplay .= '<span class="required">*</span><br />' . "\n";
        $textToDisplay .= '<input type="number" id="count_' . $widget_id . '" ';
        $textToDisplay .= 'name="count_' . $widget_id . '" value="' . $count . '" />';
        $textToDisplay .= "</p>";
        // Display type
        $textToDisplay .= '<p><label for="display_type_' . $widget_id . '">' . $website->t("articles.display_type") . ':';
        $textToDisplay .= '<span class="required">*</span><br />' . "\n";
        $textToDisplay .= '<select name="display_type_' . $widget_id . '" id="display_type_' . $widget_id . '">';
        $textToDisplay .= $this->getSelectOption($website->t("articles.display_type.without_metadata"), self::TYPE_WITHOUT_METADATA, $display_type);
        $textToDisplay .= $this->getSelectOption($website->t("articles.display_type.with_metadata"), self::TYPE_WITH_METADATA, $display_type);
        $textToDisplay .= $this->getSelectOption($website->t("articles.display_type.list"), self::TYPE_LIST, $display_type);
        $textToDisplay .= $this->getSelectOption($website->t("articles.display_type.list_with_images"), self::TYPE_LIST_WITH_IMAGES, $display_type);
        $textToDisplay .= "</select>\n";
        $textToDisplay .= "</p>\n";
        // Order
        $textToDisplay .= '<p><label for="order_' . $widget_id . '">' . $website->t("articles.order") . ':';
        $textToDisplay .= '<span class="required">*</span><br />' . "\n";
        $textToDisplay .= '<select name="order_' . $widget_id . '" id="dorder_' . $widget_id . '">';
        $textToDisplay .= $this->getSelectOption($website->t("articles.order.newest_top"), self::SORT_NEWEST_TOP, $order);
        $textToDisplay .= $this->getSelectOption($website->t("articles.order.oldest_top"), self::SORT_OLDEST_TOP, $order);
        $textToDisplay .= "</select>\n";
        $textToDisplay .= "</p>\n";
        // Archive
        $checked = $archive ? 'checked="checked"' : "";
        $textToDisplay .= <<<EOT
            <p>
                <label for="archive_{$widget_id}">{$website->t("articles.archive")}:</label>
                <input class="checkbox" type="checkbox" name="archive_{$widget_id}" id="archive_{$widget_id}" {$checked} />
            </p>
EOT;
        return $textToDisplay;
    }