Example #1
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();
 }
Example #2
0
 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);
 }
Example #3
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);
 }
Example #4
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();
 }
Example #5
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 = [];
     }
 }
Example #6
0
 /** Returns the HTML of the articles of the user, including the header */
 public function get_articles_html(Website $website)
 {
     $oArticles = new ArticleRepository($website);
     $articles = $oArticles->getArticlesDataUser($this->user->getId());
     $loggedInStaff = $website->isLoggedInAsStaff();
     $oArticleTemplate = new ArticleListTemplate($website->getText(), $articles, 0, true, false, $loggedInStaff);
     if (count($articles) > 0) {
         $returnValue = '<h3 class="notable">' . $website->t("main.articles") . "</h3>\n";
         $returnValue .= $oArticleTemplate->getText();
         return $returnValue;
     } else {
         return "";
     }
 }
Example #7
0
 public function writeText(StreamInterface $stream, Website $website, $id, $data)
 {
     $text = $website->getText();
     $editLinks = $website->isLoggedInAsStaff();
     // Title
     $title = "";
     if (isset($data["title"]) && strLen($data["title"]) > 0) {
         $title = "<h2>" . $text->e($data["title"]) . "</h2>";
     }
     $stream->write($title);
     $oArticles = new ArticleRepository($website);
     $articles = $oArticles->getArticlesDataUpcomingEvents();
     $articlesTemplate = new ArticleEventListTemplate($text, $articles, $editLinks, 0, true);
     // Articles
     $articlesTemplate->writeText($stream);
 }
Example #8
0
 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);
 }
Example #9
0
 public function init(Website $website, Request $request)
 {
     $text = $website->getText();
     $this->requestToken = RequestToken::generateNew();
     $articleId = $request->getParamInt(0, 0);
     $articleRepo = new ArticleRepository($website);
     $article = $articleRepo->getArticleOrFail($articleId);
     if (!$article->showComments) {
         $text->addError($text->t("comments.commenting_not_allowed_on_article"));
         return;
     }
     $user = $website->getAuth()->getCurrentUser();
     $this->comment = $this->fetchComment($request, $article, $user);
     if ($request->hasRequestValue("submit") && Validate::requestToken($request)) {
         // Validate and save comment
         $repo = new CommentRepository($website->getDatabase());
         if ($repo->validateComment($this->comment, $text)) {
             $repo->saveComment($this->comment);
             $this->redirectLink = $this->comment->getUrl($text);
         }
     }
     $this->requestToken->saveToSession();
 }
Example #10
0
 public function writeText(StreamInterface $stream, Website $website, $id, $data)
 {
     // Check variables
     if (!isset($data["title"]) || !isset($data["count"]) || !isset($data["display_type"]) || !isset($data["categories"])) {
         // The order variable is not checked, as older configurations may
         // not have it. The default value will be used instead.
         return;
     }
     // Title
     if (strLen($data["title"]) > 0) {
         $stream->write("<h2>" . htmlSpecialChars($data["title"]) . "</h2>");
     }
     // Get options
     $categories = $data["categories"];
     $articlesCount = (int) $data["count"];
     $displayType = (int) $data["display_type"];
     // Sorting
     $oldestTop = false;
     if (isset($data["order"]) && $data["order"] == self::SORT_OLDEST_TOP) {
         $oldestTop = true;
     }
     // Archive link
     $showArchiveLink = false;
     if (!isset($data["archive"]) || $data["archive"] == true) {
         $showArchiveLink = true;
     }
     $oArticles = new ArticleRepository($website);
     $articles = $oArticles->getArticlesData($categories, $articlesCount, $oldestTop);
     if ($displayType >= self::TYPE_LIST) {
         // Small <ul> list
         $oArticlesTemplate = new ArticleSmallListTemplate($website->getText(), $articles, $website->isLoggedInAsStaff(), $categories[0], $displayType == self::TYPE_LIST_WITH_IMAGES, $showArchiveLink);
     } else {
         // Real paragraphs
         $oArticlesTemplate = new ArticleListTemplate($website->getText(), $articles, $categories[0], $displayType == self::TYPE_WITH_METADATA, $showArchiveLink, $website->isLoggedInAsStaff());
     }
     $oArticlesTemplate->writeText($stream);
 }
Example #11
0
 /**
  * Gets the article with the given id. If the id is 0, a new article is
  * created.
  * @param ArticleRepository $repository Repository to fetch articles from.
  * @param User $currentUser Becomes the author if a new article is created.
  * @param int $id Id of the article. Use 0 to create a new article.
  * @return Article The article.
  * @throws NotFoundException If no article exists with the given id.
  */
 protected function getArticle(ArticleRepository $repository, User $currentUser, $id)
 {
     if ($id === 0) {
         $article = new Article();
         $article->setAuthor($currentUser);
         return $article;
     } else {
         $article = $repository->getArticleOrFail($id);
         if ($article->authorId === 0) {
             // There was a bug in previous versions of the CMS where the
             // author wasn't saved
             $article->setAuthor($currentUser);
         }
         return $article;
     }
 }
Example #12
0
namespace Rcms\Core;

use DateTime;
use Rcms\Template\DatePickerTemplate;
use Zend\Diactoros\Stream;
// Setup environment
require __DIR__ . "/environment.php";
$website = new Website();
//JAAR- EN MAANDLIJST
$selectedMonth = $website->getRequestInt("month", date('n'));
//geselecteerd of huidig
$selectedYear = $website->getRequestInt("year", date('Y'));
//geselecteerd of huidig
$dateTime = DateTime::createFromFormat("n Y", $selectedMonth . " " . $selectedYear);
//OBJECTEN
$oArticles = new ArticleRepository($website);
$articles = $oArticles->getArticlesDataCalendarMonth($dateTime);
$calendarTemplate = new DatePickerTemplate($website->getText(), $dateTime, $articles);
?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link href="<?php 
echo $website->getUrlActiveTheme();
?>
main.css" rel="stylesheet" type="text/css" />
        <link href="<?php 
echo $website->getUrlMain();
?>
whitebackground.css" rel="stylesheet" type="text/css" />
Example #13
0
<?php

namespace Rcms\Core;

use DateTime;
// Correct header
header("Content-type: application/rss+xml");
// Setup environment
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";
    }
Example #14
0
 /**
  * Deletes the given category. All articles are moved to the standard category.
  * @param ArticleRepository $articleRepo Repo for moving the articles.
  * @param Category $category The category that must be deleted.
  * @throws NotFoundException If this category doesn't exist in the database.
  * @throws PDOException If a database error occurs.
  * @throws InvalidArgumentException If the category is a standard category.
  */
 public function deleteCategory(ArticleRepository $articleRepo, Category $category)
 {
     if ($category->isStandardCategory()) {
         throw new InvalidArgumentException("cannot delete standard category");
     }
     $articleRepo->changeCategories($category->getId(), 1);
     $this->where($this->idField, '=', $category->getId())->deleteOneOrFail();
 }