Exemplo n.º 1
0
<?php

require_once 'vendor/autoload.php';
require_once 'config.php';
$feed_type = 'rss';
if (isset($_GET['type']) && in_array($_GET['type'], ['rss', 'atom'])) {
    $feed_type = $_GET['type'];
}
$db = new medoo(['database_type' => $db_database_type, 'database_name' => $db_database_name, 'server' => $db_server, 'username' => $db_username, 'password' => $db_password, 'charset' => $db_charset]);
$feed = new FeedIo\Feed();
// entries
$articles = $db->select($db_tables['article'], '*', ['ORDER' => 'lastModification DESC', 'LIMIT' => [0, 15]]);
// meta data
$feed->setTitle('katsuo49 - Libriste mais pas extrémiste.');
$feed->setLastModified(new DateTime($articles[0]['lastModification']));
$feed->setPublicId(sha1($articles[0]['lastModification']));
$feed->setLink($base_url . '/' . $feed_type . '.xml');
foreach ($articles as $a) {
    $item = new FeedIo\Feed\Item();
    $item->setTitle($a['title']);
    $item->setLastModified(new DateTime($a['lastModification']));
    $item->setLink($base_url . '/#/' . $a['id']);
    $item->setPublicId($a['id']);
    $item->setDescription($a['content']);
    $feed->add($item);
}
// generate rss/atom feed
$guzzle = new GuzzleHttp\Client();
$client = new FeedIo\Adapter\Guzzle\Client($guzzle);
$logger = new Psr\Log\NullLogger();
$feedIo = new FeedIo\FeedIo($client, $logger);
Exemplo n.º 2
0
 /**
  * @param BSONDocument $document
  * @param string $format
  * @return \DomDocument
  */
 protected function toXml(BSONDocument $document, string $format)
 {
     $xmlFeed = new \FeedIo\Feed();
     $dbFeed = $document->feed;
     $xmlFeed->setPublicId($dbFeed->publicId)->setLink($dbFeed->link)->setTitle($dbFeed->title)->setDescription($dbFeed->description)->setLastModified(new \DateTime($dbFeed->lastModified));
     $this->addItems($document, $xmlFeed);
     return $this->getFeedIo()->format($xmlFeed, $format);
 }