e066ab8a097a0b3c93a0859cf14183502ff965de
[yaffs-website] / vendor / zendframework / zend-feed / src / Writer / Extension / Atom / Renderer / Feed.php
1 <?php
2 /**
3  * Zend Framework (http://framework.zend.com/)
4  *
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
8  */
9
10 namespace Zend\Feed\Writer\Extension\Atom\Renderer;
11
12 use DOMDocument;
13 use DOMElement;
14 use Zend\Feed\Writer\Extension;
15
16 /**
17 */
18 class Feed extends Extension\AbstractRenderer
19 {
20     /**
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.
24      *
25      * @var bool
26      */
27     protected $called = false;
28
29     /**
30      * Render feed
31      *
32      * @return void
33      */
34     public function render()
35     {
36         /**
37          * RSS 2.0 only. Used mainly to include Atom links and
38          * Pubsubhubbub Hub endpoint URIs under the Atom namespace
39          */
40         if (strtolower($this->getType()) == 'atom') {
41             return;
42         }
43         $this->_setFeedLinks($this->dom, $this->base);
44         $this->_setHubs($this->dom, $this->base);
45         if ($this->called) {
46             $this->_appendNamespaces();
47         }
48     }
49
50     /**
51      * Append namespaces to root element of feed
52      *
53      * @return void
54      */
55     // @codingStandardsIgnoreStart
56     protected function _appendNamespaces()
57     {
58         // @codingStandardsIgnoreEnd
59         $this->getRootElement()->setAttribute(
60             'xmlns:atom',
61             'http://www.w3.org/2005/Atom'
62         );
63     }
64
65     /**
66      * Set feed link elements
67      *
68      * @param  DOMDocument $dom
69      * @param  DOMElement $root
70      * @return void
71      */
72     // @codingStandardsIgnoreStart
73     protected function _setFeedLinks(DOMDocument $dom, DOMElement $root)
74     {
75         // @codingStandardsIgnoreEnd
76         $flinks = $this->getDataContainer()->getFeedLinks();
77         if (! $flinks || empty($flinks)) {
78             return;
79         }
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);
88             }
89         }
90         $this->called = true;
91     }
92
93     /**
94      * Set PuSH hubs
95      *
96      * @param  DOMDocument $dom
97      * @param  DOMElement $root
98      * @return void
99      */
100     // @codingStandardsIgnoreStart
101     protected function _setHubs(DOMDocument $dom, DOMElement $root)
102     {
103         // @codingStandardsIgnoreEnd
104         $hubs = $this->getDataContainer()->getHubs();
105         if (! $hubs || empty($hubs)) {
106             return;
107         }
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);
113         }
114         $this->called = true;
115     }
116 }