/** * {@inheritdoc} */ public function initialize() { parent::initialize(); $encoding = $this->feed->get('encoding'); $this->dom = new \DOMDocument('1.0', $encoding); $root = $this->dom->createElement('rss'); $root->setAttribute('version', '2.0'); $root = $this->dom->appendChild($root); $channel = $this->dom->createElement('channel'); $channel = $root->appendChild($channel); $title = $this->translate($this->feed->get('title')); $title = $this->dom->createElement('title', $title); $channel->appendChild($title); $description = $this->translate($this->feed->get('description')); $description = $this->dom->createElement('description', $description); $channel->appendChild($description); $link = $this->dom->createElement('link', $this->feed->get('link')); $channel->appendChild($link); $date = new \DateTime(); $lastBuildDate = $this->dom->createElement('lastBuildDate', $date->format(\DateTime::RSS)); $channel->appendChild($lastBuildDate); // Add custom channel fields $this->addChannelFields($channel); // Add feed items $items = $this->feed->getItems(); foreach ($items as $item) { $this->addItem($channel, $item); } }
/** * Construct a formatter with given feed * * @param Feed $feed A feed instance */ public function __construct(Feed $feed) { $this->fields = array(new Field('id', 'getFeedItemLink', array('cdata' => false)), new Field('title', 'getFeedItemTitle', array('cdata' => true)), new Field('summary', 'getFeedItemDescription', array('cdata' => true)), new Field('link', 'getFeedItemLink', array('attribute' => true, 'attribute_name' => 'href')), new Field('updated', 'getFeedItemPubDate', array('date_format' => \DateTime::ATOM))); $author = $feed->get('author'); if (empty($author)) { throw new \InvalidArgumentException('Atom formatter requires an "author" parameter in configuration.'); } parent::__construct($feed); $this->initialize(); }
/** * {@inheritdoc} */ public function initialize() { parent::initialize(); $encoding = $this->feed->get('encoding'); $this->dom = new \DOMDocument('1.0', $encoding); $channel = $this->dom->createElement('feed'); $channel->setAttribute('xmlns', 'http://www.w3.org/2005/Atom'); $channel = $this->dom->appendChild($channel); $identifier = $this->dom->createElement('id', $this->feed->get('link')); $title = $this->translate($this->feed->get('title')); $title = $this->dom->createElement('title', $title); $description = $this->translate($this->feed->get('description')); $subtitle = $this->dom->createElement('subtitle', $description); $name = $this->dom->createElement('name', $this->feed->get('author')); $link = $this->dom->createElement('link'); $link->setAttribute('href', $this->feed->get('link')); $link->setAttribute('rel', 'self'); $link->setAttribute('type', 'application/rss+xml'); $date = new \DateTime(); $updated = $this->dom->createElement('updated', $date->format(\DateTime::ATOM)); $author = $this->dom->createElement('author'); $author->appendChild($name); $channel->appendChild($title); $channel->appendChild($subtitle); $channel->appendChild($link); $channel->appendChild($updated); $channel->appendChild($identifier); $channel->appendChild($author); // Add custom channel fields $this->addChannelFields($channel); // Add field items $items = $this->feed->getItems(); foreach ($items as $item) { if (null === $item) { continue; } $this->addItem($channel, $item); } }
/** * Construct a formatter with given feed * * @param Feed $feed A feed instance */ public function __construct(Feed $feed) { $this->fields = array(new Field('title', 'getFeedItemTitle', array('cdata' => true)), new Field('description', 'getFeedItemDescription', array('cdata' => true)), new Field('link', 'getFeedItemLink'), new Field('pubDate', 'getFeedItemPubDate', array('date_format' => \DateTime::RSS))); parent::__construct($feed); $this->initialize(); }