3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 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->_setExplicit($this->dom
, $this->base
);
40 $this->_setKeywords($this->dom
, $this->base
);
41 $this->_setSubtitle($this->dom
, $this->base
);
42 $this->_setSummary($this->dom
, $this->base
);
44 $this->_appendNamespaces();
49 * Append namespaces to entry root
53 protected function _appendNamespaces()
55 $this->getRootElement()->setAttribute('xmlns:itunes',
56 'http://www.itunes.com/dtds/podcast-1.0.dtd');
62 * @param DOMDocument $dom
63 * @param DOMElement $root
66 protected function _setAuthors(DOMDocument
$dom, DOMElement
$root)
68 $authors = $this->getDataContainer()->getItunesAuthors();
69 if (!$authors ||
empty($authors)) {
72 foreach ($authors as $author) {
73 $el = $dom->createElement('itunes:author');
74 $text = $dom->createTextNode($author);
75 $el->appendChild($text);
76 $root->appendChild($el);
84 * @param DOMDocument $dom
85 * @param DOMElement $root
88 protected function _setBlock(DOMDocument
$dom, DOMElement
$root)
90 $block = $this->getDataContainer()->getItunesBlock();
91 if ($block === null) {
94 $el = $dom->createElement('itunes:block');
95 $text = $dom->createTextNode($block);
96 $el->appendChild($text);
97 $root->appendChild($el);
104 * @param DOMDocument $dom
105 * @param DOMElement $root
108 protected function _setDuration(DOMDocument
$dom, DOMElement
$root)
110 $duration = $this->getDataContainer()->getItunesDuration();
114 $el = $dom->createElement('itunes:duration');
115 $text = $dom->createTextNode($duration);
116 $el->appendChild($text);
117 $root->appendChild($el);
118 $this->called
= true;
124 * @param DOMDocument $dom
125 * @param DOMElement $root
128 protected function _setExplicit(DOMDocument
$dom, DOMElement
$root)
130 $explicit = $this->getDataContainer()->getItunesExplicit();
131 if ($explicit === null) {
134 $el = $dom->createElement('itunes:explicit');
135 $text = $dom->createTextNode($explicit);
136 $el->appendChild($text);
137 $root->appendChild($el);
138 $this->called
= true;
144 * @param DOMDocument $dom
145 * @param DOMElement $root
148 protected function _setKeywords(DOMDocument
$dom, DOMElement
$root)
150 $keywords = $this->getDataContainer()->getItunesKeywords();
151 if (!$keywords ||
empty($keywords)) {
154 $el = $dom->createElement('itunes:keywords');
155 $text = $dom->createTextNode(implode(',', $keywords));
156 $el->appendChild($text);
157 $root->appendChild($el);
158 $this->called
= true;
164 * @param DOMDocument $dom
165 * @param DOMElement $root
168 protected function _setSubtitle(DOMDocument
$dom, DOMElement
$root)
170 $subtitle = $this->getDataContainer()->getItunesSubtitle();
174 $el = $dom->createElement('itunes:subtitle');
175 $text = $dom->createTextNode($subtitle);
176 $el->appendChild($text);
177 $root->appendChild($el);
178 $this->called
= true;
184 * @param DOMDocument $dom
185 * @param DOMElement $root
188 protected function _setSummary(DOMDocument
$dom, DOMElement
$root)
190 $summary = $this->getDataContainer()->getItunesSummary();
194 $el = $dom->createElement('itunes:summary');
195 $text = $dom->createTextNode($summary);
196 $el->appendChild($text);
197 $root->appendChild($el);
198 $this->called
= true;