Exemple #1
0
 public function init(Website $website, Request $request)
 {
     $this->installedWidgets = $website->getWidgets();
     $widgetRepo = new WidgetRepository($website);
     $widgetId = $request->getParamInt(0);
     if ($widgetId === 0) {
         // New widget
         $this->placedWidget = $this->getNewWidget($website, $request);
     } else {
         $this->placedWidget = $widgetRepo->getPlacedWidget($widgetId);
     }
     if ($request->hasRequestValue("submit") && Validate::requestToken($request)) {
         // Use incoming data
         $widgetDefinition = $this->installedWidgets->getDefinition($this->placedWidget);
         $data = $widgetDefinition->parseData($website, $widgetId);
         $this->placedWidget->setData($data);
         if ($this->isValid($data)) {
             // Save widget
             $widgetRepo->savePlacedWidget($this->placedWidget);
             $this->addSaveMessage($this->placedWidget, $website->getText());
         }
     }
     $this->requestToken = RequestToken::generateNew();
     $this->requestToken->saveToSession();
 }
Exemple #2
0
 public function init(Website $website, Request $request)
 {
     $isStaff = $website->isLoggedInAsStaff(true);
     $documentRepo = new DocumentRepository($website->getDatabase(), $isStaff);
     $this->documents = $documentRepo->getAll();
     $this->editLinks = $isStaff;
 }
Exemple #3
0
 public function __construct(Website $website, Request $request, Page $page)
 {
     $this->website = $website;
     $this->request = $request;
     $this->themeDirectoryName = $website->getConfig()->get(Config::OPTION_THEME);
     $this->page = $page;
 }
Exemple #4
0
 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();
 }
Exemple #5
0
    private function getNotice(Website $website)
    {
        return <<<WIDGET
            <p><em>
                {$website->tReplaced("widgets.missing_definition", $this->directoryName)}
            </em></p>
WIDGET;
    }
Exemple #6
0
 public function init(Website $website, Request $request)
 {
     $menuId = $request->getParamInt(0, 0);
     $menuRepo = new MenuRepository($website->getDatabase());
     $linkRepo = new LinkRepository($website->getDatabase());
     $this->menu = $menuRepo->getMenu($menuId);
     $this->links = $linkRepo->getLinksByMenu($menuId);
 }
Exemple #7
0
 public function init(Website $website, Request $request)
 {
     $this->installedWidgets = $website->getWidgets();
     $this->siteTitle = $website->getConfig()->get(Config::OPTION_SITE_TITLE);
     $widgetsRepo = new WidgetRepository($website);
     $this->widgets = $widgetsRepo->getWidgetsInDocumentWithId(self::DOCUMENT_ID);
     $this->editLinks = $website->isLoggedInAsStaff(true);
 }
 public function init(Website $website, Request $request)
 {
     $this->errorMessage = $website->getAuth()->getLoginError($this->minimumRank);
     $psrRequest = $request->toPsr();
     $this->targetUrl = $psrRequest->getUri();
     $this->postVars = (array) $psrRequest->getParsedBody();
     $this->canCreateAccounts = $website->getConfig()->get(Config::OPTION_USER_ACCOUNT_CREATION);
 }
Exemple #9
0
 public function init(Website $website, Request $request)
 {
     $linkRepo = new LinkRepository($website->getDatabase());
     $menuRepo = new MenuRepository($website->getDatabase());
     $this->allLinks = $linkRepo->getAllLinksByMenu();
     $this->allMenus = $menuRepo->getAllMenus();
     $this->requestToken = RequestToken::generateNew();
     $this->requestToken->saveToSession();
 }
Exemple #10
0
 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);
 }
Exemple #11
0
 public function __construct(Website $website)
 {
     parent::__construct($website->getDatabase());
     $this->widgetDirectory = $website->getUriWidgets();
     $this->documentIdField = new Field(Field::TYPE_INT, "documentId", "sidebar_id");
     $this->widgetDataField = new Field(Field::TYPE_JSON, "widgetData", "widget_data");
     $this->widgetIdField = new Field(Field::TYPE_PRIMARY_KEY, "id", "widget_id");
     $this->widgetNameField = new Field(Field::TYPE_STRING, "widgetName", "widget_naam");
     $this->widgetPriorityField = new Field(Field::TYPE_INT, "priority", "widget_priority");
 }
Exemple #12
0
 /**
  * Returns the localized error message of the last error.
  * @param Website|Text $websiteOrText The Website object or Text object.
  * @return string The localized error message
  */
 public static function getLastError($websiteOrText)
 {
     if (Validate::$replaceInLastError === "") {
         $message = $websiteOrText->t("errors." . Validate::$lastError);
     } else {
         $message = $websiteOrText->tReplaced("errors." . Validate::$lastError, Validate::$replaceInLastError);
     }
     Validate::$lastError = "";
     Validate::$replaceInLastError = "";
     return $message;
 }
Exemple #13
0
 public function init(Website $website, Request $request)
 {
     $linkId = $request->getParamInt(0, 0);
     $linkRepo = new LinkRepository($website->getDatabase());
     $this->link = $linkRepo->getLink($linkId);
     if (Validate::requestToken($request)) {
         $this->deleteLink($linkRepo, $website->getText());
     }
     $this->requestToken = RequestToken::generateNew();
     $this->requestToken->saveToSession();
 }
Exemple #14
0
 public function parseData(Website $website, $id)
 {
     $data = [];
     $data["title"] = $website->getRequestString("title_" . $id, "");
     if (strLen($data["title"]) > self::MAX_TITLE_LENGTH) {
         // Limit title length
         $website->addError($website->t("widgets.title") . " " . $website->tReplaced("errors.too_long_num", self::MAX_TITLE_LENGTH));
         $data["valid"] = false;
     }
     return $data;
 }
Exemple #15
0
 public function init(Website $website, Request $request)
 {
     $oArticles = new ArticleRepository($website);
     $yearNumber = $request->getParamInt(0, date('Y'));
     if ($yearNumber < self::MIN_YEAR || $yearNumber > self::MAX_YEAR) {
         $yearNumber = date('Y');
     }
     $this->year = DateTime::createFromFormat('Y', $yearNumber);
     $this->yearNumber = $yearNumber;
     $this->articlesInYear = $oArticles->getArticlesDataCalendarYear($this->year);
     $this->showCreateLinks = $website->isLoggedInAsStaff();
 }
Exemple #16
0
 private function handleSubmitedForm(Website $website, Request $request)
 {
     $text = $website->getText();
     if (Validate::stringLength($this->menuName, 1, MenuRepository::NAME_MAX_LENGTH)) {
         $menuRepo = new MenuRepository($website->getDatabase());
         $this->menu = Menu::createNew($this->menuName);
         $menuRepo->saveMenu($this->menu);
         $text->addMessage($text->t("links.menu.created"));
     } else {
         $text->addError($text->t("links.menu.name") . ' ' . Validate::getLastError($text));
     }
 }
Exemple #17
0
 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();
 }
Exemple #18
0
 public function init(Website $website, Request $request)
 {
     $isStaff = $website->isLoggedInAsStaff();
     $id = $request->getParamInt(0);
     $this->editLinks = $website->isLoggedInAsStaff(true);
     // Load document
     $documentRepo = new DocumentRepository($website->getDatabase(), $isStaff);
     $this->document = $documentRepo->getDocument($id);
     // Load document widgets
     $this->widgetLoader = $website->getWidgets();
     $widgetRepo = new WidgetRepository($website);
     $this->widgets = $widgetRepo->getWidgetsInDocumentWithId($id);
 }
Exemple #19
0
 public function init(Website $website, Request $request)
 {
     $articleId = $request->getParamInt(0);
     $oArticles = new ArticleRepository($website);
     $this->article = $oArticles->getArticleOrFail($articleId);
     $this->editLinks = $website->isLoggedInAsStaff();
     $this->currentUser = $website->getAuth()->getCurrentUser();
     if ($this->article->showComments) {
         $oComments = new CommentRepository($website->getDatabase());
         $this->comments = $oComments->getCommentsArticle($this->article->getId());
     } else {
         $this->comments = [];
     }
 }
Exemple #20
0
 public function init(Website $website, Request $request)
 {
     $userId = $request->getParamInt(0);
     // Fetch user
     $userRepo = $website->getAuth()->getUserRepository();
     $user = $userRepo->getById($userId);
     if (!$user->canLogIn()) {
         // Can't log in to deleted or banned users
         throw new NotFoundException();
     }
     // Set user
     $this->newUser = $user;
     $website->getAuth()->setCurrentUser($user);
 }
Exemple #21
0
 public function init(Website $website, Request $request)
 {
     $documentId = $request->getParamInt(0, 0);
     $documentRepo = new DocumentRepository($website->getDatabase(), true);
     $this->document = $documentRepo->getDocument($documentId);
     if (Validate::requestToken($request)) {
         $widgetRepo = new WidgetRepository($website);
         $documentRepo->deleteDocument($this->document, $widgetRepo);
         $text = $website->getText();
         $text->addMessage($text->t("main.document") . ' ' . $text->t("editor.is_deleted"));
         $this->deleted = true;
     }
     $this->requestToken = RequestToken::generateNew();
     $this->requestToken->saveToSession();
 }
Exemple #22
0
 public function init(Website $website, Request $request)
 {
     $this->installedWidgets = $website->getWidgets();
     $widgetId = $request->getParamInt(0, 0);
     $widgetRepo = new WidgetRepository($website);
     $this->placedWidget = $widgetRepo->getPlacedWidget($widgetId);
     if (Validate::requestToken($request)) {
         $widgetRepo->deletePlacedWidget($this->placedWidget);
         $text = $website->getText();
         $text->addMessage($text->t("main.widget") . ' ' . $text->t("editor.is_deleted"), Link::of($text->getUrlPage("edit_document", $this->placedWidget->getDocumentId()), $text->t("main.ok")));
     } else {
         $this->requestToken = RequestToken::generateNew();
         $this->requestToken->saveToSession();
     }
 }
Exemple #23
0
 protected function get_ranks_box_html(Website $website, $ranks, $selected)
 {
     $oAuth = $website->getAuth();
     $text = $website->getText();
     $selection_box = '<select name="rank" id="rank">';
     foreach ($ranks as $id) {
         $label = $text->t($oAuth->getRankName($id));
         $selection_box .= '<option value="' . $id . '"';
         if ($selected == $id) {
             $selection_box .= ' selected="selected"';
         }
         $selection_box .= '>' . $label . "</option>\n";
     }
     $selection_box .= "</select>\n";
     return $selection_box;
 }
Exemple #24
0
 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"));
     }
 }
Exemple #25
0
 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;
 }
 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;
 }
Exemple #27
0
 public function init(Website $website, Request $request)
 {
     $categoriesRepo = new CategoryRepository($website->getDatabase());
     $categoryId = $request->getParamInt(0, 0);
     $this->category = $categoriesRepo->getCategory($categoryId);
     if ($this->category->isStandardCategory()) {
         $text = $website->getText();
         $editCategory = Link::of($text->getUrlPage("edit_category", $this->category->getId()), $text->t("categories.edit"));
         $viewAll = Link::of($text->getUrlPage("category_list"), $text->t("categories.view_all"));
         $text->addError($text->t("categories.delete.cannot_remove_default"), $editCategory, $viewAll);
         return;
     }
     if (Validate::requestToken($request)) {
         $articlesRepo = new ArticleRepository($website);
         $this->deleteCategory($categoriesRepo, $articlesRepo, $website->getText());
     }
     $this->requestToken = RequestToken::generateNew();
     $this->requestToken->saveToSession();
 }
Exemple #28
0
 public function init(Website $website, Request $request)
 {
     // Retrieve menus
     $menuRepo = new MenuRepository($website->getDatabase());
     $this->allMenus = $menuRepo->getAllMenus();
     // Retrieve the menu to be deleted
     $menuId = $request->getParamInt(0, 0);
     if (!isset($this->allMenus[$menuId])) {
         // Asking to delete non-existing menu
         throw new NotFoundException();
     }
     $this->menu = $this->allMenus[$menuId];
     // Retrieve links
     $linkRepo = new LinkRepository($website->getDatabase());
     $this->linkCount = $linkRepo->getLinkCountByMenu($this->menu->getId());
     $this->respondToRequest($linkRepo, $menuRepo, $website->getText(), $request);
     // Request token
     $this->requestToken = RequestToken::generateNew();
     $this->requestToken->saveToSession();
 }
    /** 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;
    }
Exemple #30
0
 private function saveLink(Website $website)
 {
     $text = $website->getText();
     $valid = true;
     if (!Validate::url($this->linkUrl)) {
         $text->addError($text->t("links.url") . " " . Validate::getLastError($text));
         $valid = false;
     }
     if (!Validate::stringLength($this->linkName, 1, LinkRepository::MAX_LINK_TEXT_LENGTH)) {
         $text->addError($text->t("links.text") . " " . Validate::getLastError($text));
         $valid = false;
     }
     if (!$valid) {
         return;
     }
     $link = Link::createSaveable(0, $this->menu->getId(), new Uri($this->linkUrl), $this->linkName);
     $linkRepo = new LinkRepository($website->getDatabase());
     $linkRepo->saveLink($link);
     $text->addMessage($text->t("main.link") . " " . $text->t("editor.is_created"), Link::of($text->getUrlPage("add_link", $this->menu->getId()), $text->t("links.create_another")));
     $this->addedLink = true;
 }