3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Feed\Writer\Extension\Atom\Renderer;
14 use Zend\Feed\Writer\Extension;
18 class Feed extends Extension\AbstractRenderer
21 * Set to TRUE if a rendering method actually renders something. This
22 * is used to prevent premature appending of a XML namespace declaration
23 * until an element which requires it is actually appended.
27 protected $called = false;
34 public function render()
37 * RSS 2.0 only. Used mainly to include Atom links and
38 * Pubsubhubbub Hub endpoint URIs under the Atom namespace
40 if (strtolower($this->getType()) == 'atom') {
43 $this->_setFeedLinks($this->dom, $this->base);
44 $this->_setHubs($this->dom, $this->base);
46 $this->_appendNamespaces();
51 * Append namespaces to root element of feed
55 // @codingStandardsIgnoreStart
56 protected function _appendNamespaces()
58 // @codingStandardsIgnoreEnd
59 $this->getRootElement()->setAttribute(
61 'http://www.w3.org/2005/Atom'
66 * Set feed link elements
68 * @param DOMDocument $dom
69 * @param DOMElement $root
72 // @codingStandardsIgnoreStart
73 protected function _setFeedLinks(DOMDocument $dom, DOMElement $root)
75 // @codingStandardsIgnoreEnd
76 $flinks = $this->getDataContainer()->getFeedLinks();
77 if (! $flinks || empty($flinks)) {
80 foreach ($flinks as $type => $href) {
81 if (strtolower($type) == $this->getType()) { // issue 2605
82 $mime = 'application/' . strtolower($type) . '+xml';
83 $flink = $dom->createElement('atom:link');
84 $root->appendChild($flink);
85 $flink->setAttribute('rel', 'self');
86 $flink->setAttribute('type', $mime);
87 $flink->setAttribute('href', $href);
96 * @param DOMDocument $dom
97 * @param DOMElement $root
100 // @codingStandardsIgnoreStart
101 protected function _setHubs(DOMDocument $dom, DOMElement $root)
103 // @codingStandardsIgnoreEnd
104 $hubs = $this->getDataContainer()->getHubs();
105 if (! $hubs || empty($hubs)) {
108 foreach ($hubs as $hubUrl) {
109 $hub = $dom->createElement('atom:link');
110 $hub->setAttribute('rel', 'hub');
111 $hub->setAttribute('href', $hubUrl);
112 $root->appendChild($hub);
114 $this->called = true;