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()); } } } }
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; }