Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / zendframework / zend-feed / src / Writer / Extension / ITunes / Renderer / Entry.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\ITunes\Renderer;
11
12 use DOMDocument;
13 use DOMElement;
14 use Zend\Feed\Writer\Extension;
15
16 /**
17 */
18 class Entry 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 entry
31      *
32      * @return void
33      */
34     public function render()
35     {
36         $this->_setAuthors($this->dom, $this->base);
37         $this->_setBlock($this->dom, $this->base);
38         $this->_setDuration($this->dom, $this->base);
39         $this->_setImage($this->dom, $this->base);
40         $this->_setExplicit($this->dom, $this->base);
41         $this->_setKeywords($this->dom, $this->base);
42         $this->_setSubtitle($this->dom, $this->base);
43         $this->_setSummary($this->dom, $this->base);
44         $this->_setEpisode($this->dom, $this->base);
45         $this->_setEpisodeType($this->dom, $this->base);
46         $this->_setClosedCaptioned($this->dom, $this->base);
47         $this->_setSeason($this->dom, $this->base);
48         if ($this->called) {
49             $this->_appendNamespaces();
50         }
51     }
52
53     /**
54      * Append namespaces to entry root
55      *
56      * @return void
57      */
58     // @codingStandardsIgnoreStart
59     protected function _appendNamespaces()
60     {
61         // @codingStandardsIgnoreEnd
62         $this->getRootElement()->setAttribute(
63             'xmlns:itunes',
64             'http://www.itunes.com/dtds/podcast-1.0.dtd'
65         );
66     }
67
68     /**
69      * Set entry authors
70      *
71      * @param  DOMDocument $dom
72      * @param  DOMElement $root
73      * @return void
74      */
75     // @codingStandardsIgnoreStart
76     protected function _setAuthors(DOMDocument $dom, DOMElement $root)
77     {
78         // @codingStandardsIgnoreEnd
79         $authors = $this->getDataContainer()->getItunesAuthors();
80         if (! $authors || empty($authors)) {
81             return;
82         }
83         foreach ($authors as $author) {
84             $el = $dom->createElement('itunes:author');
85             $text = $dom->createTextNode($author);
86             $el->appendChild($text);
87             $root->appendChild($el);
88             $this->called = true;
89         }
90     }
91
92     /**
93      * Set itunes block
94      *
95      * @param  DOMDocument $dom
96      * @param  DOMElement $root
97      * @return void
98      */
99     // @codingStandardsIgnoreStart
100     protected function _setBlock(DOMDocument $dom, DOMElement $root)
101     {
102         // @codingStandardsIgnoreEnd
103         $block = $this->getDataContainer()->getItunesBlock();
104         if ($block === null) {
105             return;
106         }
107         $el = $dom->createElement('itunes:block');
108         $text = $dom->createTextNode($block);
109         $el->appendChild($text);
110         $root->appendChild($el);
111         $this->called = true;
112     }
113
114     /**
115      * Set entry duration
116      *
117      * @param  DOMDocument $dom
118      * @param  DOMElement $root
119      * @return void
120      */
121     // @codingStandardsIgnoreStart
122     protected function _setDuration(DOMDocument $dom, DOMElement $root)
123     {
124         // @codingStandardsIgnoreEnd
125         $duration = $this->getDataContainer()->getItunesDuration();
126         if (! $duration) {
127             return;
128         }
129         $el = $dom->createElement('itunes:duration');
130         $text = $dom->createTextNode($duration);
131         $el->appendChild($text);
132         $root->appendChild($el);
133         $this->called = true;
134     }
135
136     /**
137      * Set feed image (icon)
138      *
139      * @param  DOMDocument $dom
140      * @param  DOMElement $root
141      * @return void
142      */
143     // @codingStandardsIgnoreStart
144     protected function _setImage(DOMDocument $dom, DOMElement $root)
145     {
146         // @codingStandardsIgnoreEnd
147         $image = $this->getDataContainer()->getItunesImage();
148         if (! $image) {
149             return;
150         }
151         $el = $dom->createElement('itunes:image');
152         $el->setAttribute('href', $image);
153         $root->appendChild($el);
154         $this->called = true;
155     }
156
157     /**
158      * Set explicit flag
159      *
160      * @param  DOMDocument $dom
161      * @param  DOMElement $root
162      * @return void
163      */
164     // @codingStandardsIgnoreStart
165     protected function _setExplicit(DOMDocument $dom, DOMElement $root)
166     {
167         // @codingStandardsIgnoreEnd
168         $explicit = $this->getDataContainer()->getItunesExplicit();
169         if ($explicit === null) {
170             return;
171         }
172         $el = $dom->createElement('itunes:explicit');
173         $text = $dom->createTextNode($explicit);
174         $el->appendChild($text);
175         $root->appendChild($el);
176         $this->called = true;
177     }
178
179     /**
180      * Set entry keywords
181      *
182      * @param  DOMDocument $dom
183      * @param  DOMElement $root
184      * @return void
185      */
186     // @codingStandardsIgnoreStart
187     protected function _setKeywords(DOMDocument $dom, DOMElement $root)
188     {
189         // @codingStandardsIgnoreEnd
190         $keywords = $this->getDataContainer()->getItunesKeywords();
191         if (! $keywords || empty($keywords)) {
192             return;
193         }
194         $el = $dom->createElement('itunes:keywords');
195         $text = $dom->createTextNode(implode(',', $keywords));
196         $el->appendChild($text);
197         $root->appendChild($el);
198         $this->called = true;
199     }
200
201     /**
202      * Set entry subtitle
203      *
204      * @param  DOMDocument $dom
205      * @param  DOMElement $root
206      * @return void
207      */
208     // @codingStandardsIgnoreStart
209     protected function _setSubtitle(DOMDocument $dom, DOMElement $root)
210     {
211         // @codingStandardsIgnoreEnd
212         $subtitle = $this->getDataContainer()->getItunesSubtitle();
213         if (! $subtitle) {
214             return;
215         }
216         $el = $dom->createElement('itunes:subtitle');
217         $text = $dom->createTextNode($subtitle);
218         $el->appendChild($text);
219         $root->appendChild($el);
220         $this->called = true;
221     }
222
223     /**
224      * Set entry summary
225      *
226      * @param  DOMDocument $dom
227      * @param  DOMElement $root
228      * @return void
229      */
230     // @codingStandardsIgnoreStart
231     protected function _setSummary(DOMDocument $dom, DOMElement $root)
232     {
233         // @codingStandardsIgnoreEnd
234         $summary = $this->getDataContainer()->getItunesSummary();
235         if (! $summary) {
236             return;
237         }
238         $el = $dom->createElement('itunes:summary');
239         $text = $dom->createTextNode($summary);
240         $el->appendChild($text);
241         $root->appendChild($el);
242         $this->called = true;
243     }
244
245     /**
246      * Set entry episode number
247      *
248      * @param  DOMDocument $dom
249      * @param  DOMElement $root
250      * @return void
251      */
252     // @codingStandardsIgnoreStart
253     protected function _setEpisode(DOMDocument $dom, DOMElement $root)
254     {
255         // @codingStandardsIgnoreEnd
256         $episode = $this->getDataContainer()->getItunesEpisode();
257         if (! $episode) {
258             return;
259         }
260         $el = $dom->createElement('itunes:episode');
261         $text = $dom->createTextNode($episode);
262         $el->appendChild($text);
263         $root->appendChild($el);
264         $this->called = true;
265     }
266
267     /**
268      * Set entry episode type
269      *
270      * @param  DOMDocument $dom
271      * @param  DOMElement $root
272      * @return void
273      */
274     // @codingStandardsIgnoreStart
275     protected function _setEpisodeType(DOMDocument $dom, DOMElement $root)
276     {
277         // @codingStandardsIgnoreEnd
278         $type = $this->getDataContainer()->getItunesEpisodeType();
279         if (! $type) {
280             return;
281         }
282         $el = $dom->createElement('itunes:episodeType');
283         $text = $dom->createTextNode($type);
284         $el->appendChild($text);
285         $root->appendChild($el);
286         $this->called = true;
287     }
288
289     /**
290      * Set closed captioning status for episode
291      *
292      * @param  DOMDocument $dom
293      * @param  DOMElement $root
294      * @return void
295      */
296     // @codingStandardsIgnoreStart
297     protected function _setClosedCaptioned(DOMDocument $dom, DOMElement $root)
298     {
299         // @codingStandardsIgnoreEnd
300         $status = $this->getDataContainer()->getItunesIsClosedCaptioned();
301         if (! $status) {
302             return;
303         }
304         $el = $dom->createElement('itunes:isClosedCaptioned');
305         $text = $dom->createTextNode('Yes');
306         $el->appendChild($text);
307         $root->appendChild($el);
308         $this->called = true;
309     }
310
311     /**
312      * Set entry season number
313      *
314      * @param  DOMDocument $dom
315      * @param  DOMElement $root
316      * @return void
317      */
318     // @codingStandardsIgnoreStart
319     protected function _setSeason(DOMDocument $dom, DOMElement $root)
320     {
321         // @codingStandardsIgnoreEnd
322         $season = $this->getDataContainer()->getItunesSeason();
323         if (! $season) {
324             return;
325         }
326         $el = $dom->createElement('itunes:season');
327         $text = $dom->createTextNode($season);
328         $el->appendChild($text);
329         $root->appendChild($el);
330         $this->called = true;
331     }
332 }