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, $id, $data) { $title = isset($data["title"]) ? htmlSpecialChars($data["title"]) : ""; $menu_id = isset($data["menu_id"]) ? (int) $data["menu_id"] : 0; $returnValue = ""; $title_max_length = self::TITLE_MAX_LENGTH; // Herodoc doesn't support constants // Build menu options $oMenu = new MenuRepository($website->getDatabase()); $menus = $oMenu->getAllMenus(); $menu_options = ""; if (count($menus) > 0) { $menu_options .= "<select name=\"menu_id_{$id}\" id=\"menu_id_{$id}\">\n"; foreach ($menus as $menu) { $menu_options .= '<option value="' . $menu->getId() . '"'; if ($menu->getId() == $menu_id) { $menu_options .= ' selected="selected"'; } $menu_options .= '>' . htmlSpecialChars($menu->getName()) . "</option>\n"; } $menu_options .= "</select>\n"; } else { $menu_options .= "<p><em>" . $website->t("errors.nothing_found") . "</em> "; $menu_options .= '<a class="arrow" href="' . $website->getUrlPage("links") . '">' . $website->t("links.menu.add") . "</a></p>\n"; } unset($menus, $oMenu, $available_menu_id, $menu_name); // Return form $returnValue .= <<<EOT <p> <label for="title_{$id}">{$website->t("widgets.title")}:</label><br /> <input type="text" name="title_{$id}" id="title_{$id}" value="{$title}" maxlength="{$title_max_length}" /> </p> <p> <label for="menu_id_{$id}">{$website->t("links.menu")}:</label><span class="required">*</span><br /> {$menu_options} </p> EOT; return $returnValue; }
/** 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; }
require __DIR__ . "/environment.php"; // Objects $website = new Website(); $oArticles = new ArticleRepository($website); // Get category $category_id = $website->getRequestInt("category"); // Get the data $articles = $oArticles->getArticlesData($category_id, 15); // Parse it $textToDisplay = ''; if ($articles) { foreach ($articles as $article) { $pubdate = $article->getDateCreated()->format(DateTime::RSS); $textToDisplay .= "<item>\n"; $textToDisplay .= " <title>" . htmlSpecialChars($article->getTitle()) . "</title>\n"; $textToDisplay .= " <link>" . $website->getUrlPage('article', $article->getId()) . "</link>\n"; $textToDisplay .= " <description>" . htmlSpecialChars($article->getIntro()) . "</description>\n"; $textToDisplay .= " <pubDate>" . htmlSpecialChars($pubdate) . "</pubDate>\n"; $textToDisplay .= " <author>" . htmlSpecialChars($article->author) . "</author>\n"; $textToDisplay .= " <image>" . htmlSpecialChars($article->featuredImage) . "</image>\n"; $textToDisplay .= " <category>" . htmlSpecialChars($article->category) . "</category>\n"; $textToDisplay .= "</item>\n\n"; } } unset($article, $articles); // Show it echo '<?xml version="1.0" encoding="UTF-8" ?>'; ?> <rss version="2.0"> <channel>
public function getPageContent(Website $website, Request $request) { $languages = $this->get_sub_directory_names($website->getUriTranslations()); $user_account_creation_checked = $this->user_account_creation ? 'checked="checked"' : ''; $top_message = $website->t("site_settings.editing_site_settings.explained"); $tokenName = RequestToken::FIELD_NAME; $tokenHtml = htmlSpecialChars($this->token->getTokenString()); if ($this->saved) { $top_message = <<<EOT <em>{$website->t("site_settings.site_settings")} {$website->t("editor.are_changed")}</em> <a class="arrow" href="{$website->getUrlPage("admin")}"> {$website->t("main.admin")} </a> EOT; } return <<<EOT <p> {$top_message} </p> <p> {$website->t("main.fields_required")} </p> <form action="{$website->getUrlPage("site_settings")}" method="post"> <p> <label for="option_title">{$website->t("site_settings.title")}</label>:<span class="required">*</span> <br /> <input type="text" name="option_title" id="option_title" value="{$this->title}" /> <br /> <em>{$website->t("site_settings.title.explained")}</em> </p> <p> <label for="option_copyright">{$website->t("site_settings.copyright")}</label>: <br /> <input type="text" name="option_copyright" id="option_copyright" value="{$this->copyright}" /> <br /> <em>{$website->t("site_settings.copyright.explained")}</em> </p> <p> <label for="option_password">{$website->t("site_settings.password")}</label>: <br /> <input type="text" name="option_password" id="option_password" value="{$this->password}" /> <br /> <em>{$website->t("site_settings.password.explained")}</em> </p> <p> <label for="option_language">{$website->t("site_settings.language")}</label>:<span class="required">*</span> <br /> {$this->get_dropdown_list("option_language", $languages, $this->language, true)} <br /> <em>{$website->t("site_settings.language.explained")}</em> </p> <p> <label for="option_user_account_creation"> <input class="checkbox" type="checkbox" name="option_user_account_creation" id="option_user_account_creation" {$user_account_creation_checked} /> {$website->t("site_settings.user_account_creation")} </label> <br /> <em>{$website->t("site_settings.user_account_creation.explained")}</em> </p> <p> <input type="hidden" name="{$tokenName}" value="{$tokenHtml}" /> <input type="submit" name="submit" class="button primary_button" value="{$website->t("editor.save")}" /> </p> </form> <p> <a class="arrow" href="{$website->getUrlPage("admin")}"> {$website->t("main.admin")} </a> </p> EOT; }
/** Gets a table of all users */ public function get_users_table(Website $website, $start) { $start = (int) $start; $oAuth = $website->getAuth(); $users = $oAuth->getUserRepository()->getRegisteredUsers($start, self::USERS_PER_PAGE); $current_user_id = $oAuth->getCurrentUser()->getId(); // Start table $returnValue = "<table>\n"; $returnValue .= "<tr><th>" . $website->t("users.username") . "</th><th>" . $website->t("users.display_name") . "</th><th>" . $website->t("users.email") . "</th><th>" . $website->t("users.rank") . "</th><th>" . $website->t("main.edit") . "</th></tr>\n"; //login-naam-email-admin-bewerk $returnValue .= '<tr><td colspan="5"><a class="arrow" href="' . $website->getUrlPage("create_account_admin") . '">' . $website->t("users.create") . "...</a></td></tr>\n"; //maak nieuwe account if (count($users) > 0) { foreach ($users as $user) { // Email $email_link = '<em>' . $website->t("main.not_set") . '</em>'; $email = $user->getEmail(); if ($email) { $email = htmlSpecialChars($email); $email_link = '<a href="mailto:' . $email . '">' . $email . '</a>'; } // Others $username = $user->getUsername(); // Usernames are severly restricted, so no need to escape $display_name = htmlSpecialChars($user->getDisplayName()); $rank_name = $website->t($oAuth->getRankName($user->getRank())); if ($user->getStatus() == Authentication::STATUS_BANNED) { $rank_name = $website->t("users.status.banned"); } if ($user->getStatus() == Authentication::STATUS_DELETED) { $rank_name = $website->t("users.status.deleted"); } $username_link = '<a href="' . $website->getUrlPage("account", $user->getId()) . '">' . $username . '</a>'; $login_link = '<a class="arrow" href="' . $website->getUrlPage("login_other", $user->getId()) . '">' . $website->t("main.log_in") . '</a>'; if ($user->getId() == $current_user_id || !$user->canLogIn()) { // No need to log in as that account $login_link = ""; } // Rest of row $returnValue .= <<<EOT <tr> <td>{$username_link}</td> <td>{$display_name}</td> <td>{$email_link}</td> <td>{$rank_name}</td> <td>{$login_link}</td> </tr> EOT; } } $returnValue .= "</table>"; return $returnValue; }
/** * Gets a link with the specified url and text. User id and link class will * be added. * @param Website $website The website object. * @param string $page_id The id of the page. * @param string $translation_id The translation id of the text to display. * @return string The link. */ public function get_edit_link(Website $website, $page_id, $translation_id) { return <<<EOT <a class="arrow" href="{$website->getUrlPage($page_id, $this->user->getId())}"> {$website->t($translation_id)} </a><br /> EOT; }
public function init(Website $website, Request $request) { $id = $request->getParamInt(0, 0); $this->articleUrl = $website->getUrlPage("article", $id); }