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\ITunes\Renderer;
14 use Zend\Feed\Writer\Extension;
18 class Entry 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()
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);
49 $this->_appendNamespaces();
54 * Append namespaces to entry root
58 // @codingStandardsIgnoreStart
59 protected function _appendNamespaces()
61 // @codingStandardsIgnoreEnd
62 $this->getRootElement()->setAttribute(
64 'http://www.itunes.com/dtds/podcast-1.0.dtd'
71 * @param DOMDocument $dom
72 * @param DOMElement $root
75 // @codingStandardsIgnoreStart
76 protected function _setAuthors(DOMDocument $dom, DOMElement $root)
78 // @codingStandardsIgnoreEnd
79 $authors = $this->getDataContainer()->getItunesAuthors();
80 if (! $authors || empty($authors)) {
83 foreach ($authors as $author) {
84 $el = $dom->createElement('itunes:author');
85 $text = $dom->createTextNode($author);
86 $el->appendChild($text);
87 $root->appendChild($el);
95 * @param DOMDocument $dom
96 * @param DOMElement $root
99 // @codingStandardsIgnoreStart
100 protected function _setBlock(DOMDocument $dom, DOMElement $root)
102 // @codingStandardsIgnoreEnd
103 $block = $this->getDataContainer()->getItunesBlock();
104 if ($block === null) {
107 $el = $dom->createElement('itunes:block');
108 $text = $dom->createTextNode($block);
109 $el->appendChild($text);
110 $root->appendChild($el);
111 $this->called = true;
117 * @param DOMDocument $dom
118 * @param DOMElement $root
121 // @codingStandardsIgnoreStart
122 protected function _setDuration(DOMDocument $dom, DOMElement $root)
124 // @codingStandardsIgnoreEnd
125 $duration = $this->getDataContainer()->getItunesDuration();
129 $el = $dom->createElement('itunes:duration');
130 $text = $dom->createTextNode($duration);
131 $el->appendChild($text);
132 $root->appendChild($el);
133 $this->called = true;
137 * Set feed image (icon)
139 * @param DOMDocument $dom
140 * @param DOMElement $root
143 // @codingStandardsIgnoreStart
144 protected function _setImage(DOMDocument $dom, DOMElement $root)
146 // @codingStandardsIgnoreEnd
147 $image = $this->getDataContainer()->getItunesImage();
151 $el = $dom->createElement('itunes:image');
152 $el->setAttribute('href', $image);
153 $root->appendChild($el);
154 $this->called = true;
160 * @param DOMDocument $dom
161 * @param DOMElement $root
164 // @codingStandardsIgnoreStart
165 protected function _setExplicit(DOMDocument $dom, DOMElement $root)
167 // @codingStandardsIgnoreEnd
168 $explicit = $this->getDataContainer()->getItunesExplicit();
169 if ($explicit === null) {
172 $el = $dom->createElement('itunes:explicit');
173 $text = $dom->createTextNode($explicit);
174 $el->appendChild($text);
175 $root->appendChild($el);
176 $this->called = true;
182 * @param DOMDocument $dom
183 * @param DOMElement $root
186 // @codingStandardsIgnoreStart
187 protected function _setKeywords(DOMDocument $dom, DOMElement $root)
189 // @codingStandardsIgnoreEnd
190 $keywords = $this->getDataContainer()->getItunesKeywords();
191 if (! $keywords || empty($keywords)) {
194 $el = $dom->createElement('itunes:keywords');
195 $text = $dom->createTextNode(implode(',', $keywords));
196 $el->appendChild($text);
197 $root->appendChild($el);
198 $this->called = true;
204 * @param DOMDocument $dom
205 * @param DOMElement $root
208 // @codingStandardsIgnoreStart
209 protected function _setSubtitle(DOMDocument $dom, DOMElement $root)
211 // @codingStandardsIgnoreEnd
212 $subtitle = $this->getDataContainer()->getItunesSubtitle();
216 $el = $dom->createElement('itunes:subtitle');
217 $text = $dom->createTextNode($subtitle);
218 $el->appendChild($text);
219 $root->appendChild($el);
220 $this->called = true;
226 * @param DOMDocument $dom
227 * @param DOMElement $root
230 // @codingStandardsIgnoreStart
231 protected function _setSummary(DOMDocument $dom, DOMElement $root)
233 // @codingStandardsIgnoreEnd
234 $summary = $this->getDataContainer()->getItunesSummary();
238 $el = $dom->createElement('itunes:summary');
239 $text = $dom->createTextNode($summary);
240 $el->appendChild($text);
241 $root->appendChild($el);
242 $this->called = true;
246 * Set entry episode number
248 * @param DOMDocument $dom
249 * @param DOMElement $root
252 // @codingStandardsIgnoreStart
253 protected function _setEpisode(DOMDocument $dom, DOMElement $root)
255 // @codingStandardsIgnoreEnd
256 $episode = $this->getDataContainer()->getItunesEpisode();
260 $el = $dom->createElement('itunes:episode');
261 $text = $dom->createTextNode($episode);
262 $el->appendChild($text);
263 $root->appendChild($el);
264 $this->called = true;
268 * Set entry episode type
270 * @param DOMDocument $dom
271 * @param DOMElement $root
274 // @codingStandardsIgnoreStart
275 protected function _setEpisodeType(DOMDocument $dom, DOMElement $root)
277 // @codingStandardsIgnoreEnd
278 $type = $this->getDataContainer()->getItunesEpisodeType();
282 $el = $dom->createElement('itunes:episodeType');
283 $text = $dom->createTextNode($type);
284 $el->appendChild($text);
285 $root->appendChild($el);
286 $this->called = true;
290 * Set closed captioning status for episode
292 * @param DOMDocument $dom
293 * @param DOMElement $root
296 // @codingStandardsIgnoreStart
297 protected function _setClosedCaptioned(DOMDocument $dom, DOMElement $root)
299 // @codingStandardsIgnoreEnd
300 $status = $this->getDataContainer()->getItunesIsClosedCaptioned();
304 $el = $dom->createElement('itunes:isClosedCaptioned');
305 $text = $dom->createTextNode('Yes');
306 $el->appendChild($text);
307 $root->appendChild($el);
308 $this->called = true;
312 * Set entry season number
314 * @param DOMDocument $dom
315 * @param DOMElement $root
318 // @codingStandardsIgnoreStart
319 protected function _setSeason(DOMDocument $dom, DOMElement $root)
321 // @codingStandardsIgnoreEnd
322 $season = $this->getDataContainer()->getItunesSeason();
326 $el = $dom->createElement('itunes:season');
327 $text = $dom->createTextNode($season);
328 $el->appendChild($text);
329 $root->appendChild($el);
330 $this->called = true;