Example #1
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 #2
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 #3
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";
    }