File indexing completed on 2025-03-09 05:21:31
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Feed_Writer 0017 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0018 * @license http://framework.zend.com/license/new-bsd New BSD License 0019 * @version $Id$ 0020 */ 0021 0022 /** 0023 * @see Zend_Feed_Writer_Extension_RendererAbstract 0024 */ 0025 // require_once 'Zend/Feed/Writer/Extension/RendererAbstract.php'; 0026 0027 /** 0028 * @category Zend 0029 * @package Zend_Feed_Writer 0030 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0031 * @license http://framework.zend.com/license/new-bsd New BSD License 0032 */ 0033 class Zend_Feed_Writer_Extension_ITunes_Renderer_Entry 0034 extends Zend_Feed_Writer_Extension_RendererAbstract 0035 { 0036 /** 0037 * Set to TRUE if a rendering method actually renders something. This 0038 * is used to prevent premature appending of a XML namespace declaration 0039 * until an element which requires it is actually appended. 0040 * 0041 * @var bool 0042 */ 0043 protected $_called = false; 0044 0045 /** 0046 * Render entry 0047 * 0048 * @return void 0049 */ 0050 public function render() 0051 { 0052 $this->_setAuthors($this->_dom, $this->_base); 0053 $this->_setBlock($this->_dom, $this->_base); 0054 $this->_setDuration($this->_dom, $this->_base); 0055 $this->_setExplicit($this->_dom, $this->_base); 0056 $this->_setKeywords($this->_dom, $this->_base); 0057 $this->_setSubtitle($this->_dom, $this->_base); 0058 $this->_setSummary($this->_dom, $this->_base); 0059 if ($this->_called) { 0060 $this->_appendNamespaces(); 0061 } 0062 } 0063 0064 /** 0065 * Append namespaces to entry root 0066 * 0067 * @return void 0068 */ 0069 protected function _appendNamespaces() 0070 { 0071 $this->getRootElement()->setAttribute('xmlns:itunes', 0072 'http://www.itunes.com/dtds/podcast-1.0.dtd'); 0073 } 0074 0075 /** 0076 * Set entry authors 0077 * 0078 * @param DOMDocument $dom 0079 * @param DOMElement $root 0080 * @return void 0081 */ 0082 protected function _setAuthors(DOMDocument $dom, DOMElement $root) 0083 { 0084 $authors = $this->getDataContainer()->getItunesAuthors(); 0085 if (!$authors || empty($authors)) { 0086 return; 0087 } 0088 foreach ($authors as $author) { 0089 $el = $dom->createElement('itunes:author'); 0090 $text = $dom->createTextNode($author); 0091 $el->appendChild($text); 0092 $root->appendChild($el); 0093 $this->_called = true; 0094 } 0095 } 0096 0097 /** 0098 * Set itunes block 0099 * 0100 * @param DOMDocument $dom 0101 * @param DOMElement $root 0102 * @return void 0103 */ 0104 protected function _setBlock(DOMDocument $dom, DOMElement $root) 0105 { 0106 $block = $this->getDataContainer()->getItunesBlock(); 0107 if ($block === null) { 0108 return; 0109 } 0110 $el = $dom->createElement('itunes:block'); 0111 $text = $dom->createTextNode($block); 0112 $el->appendChild($text); 0113 $root->appendChild($el); 0114 $this->_called = true; 0115 } 0116 0117 /** 0118 * Set entry duration 0119 * 0120 * @param DOMDocument $dom 0121 * @param DOMElement $root 0122 * @return void 0123 */ 0124 protected function _setDuration(DOMDocument $dom, DOMElement $root) 0125 { 0126 $duration = $this->getDataContainer()->getItunesDuration(); 0127 if (!$duration) { 0128 return; 0129 } 0130 $el = $dom->createElement('itunes:duration'); 0131 $text = $dom->createTextNode($duration); 0132 $el->appendChild($text); 0133 $root->appendChild($el); 0134 $this->_called = true; 0135 } 0136 0137 /** 0138 * Set explicit flag 0139 * 0140 * @param DOMDocument $dom 0141 * @param DOMElement $root 0142 * @return void 0143 */ 0144 protected function _setExplicit(DOMDocument $dom, DOMElement $root) 0145 { 0146 $explicit = $this->getDataContainer()->getItunesExplicit(); 0147 if ($explicit === null) { 0148 return; 0149 } 0150 $el = $dom->createElement('itunes:explicit'); 0151 $text = $dom->createTextNode($explicit); 0152 $el->appendChild($text); 0153 $root->appendChild($el); 0154 $this->_called = true; 0155 } 0156 0157 /** 0158 * Set entry keywords 0159 * 0160 * @param DOMDocument $dom 0161 * @param DOMElement $root 0162 * @return void 0163 */ 0164 protected function _setKeywords(DOMDocument $dom, DOMElement $root) 0165 { 0166 $keywords = $this->getDataContainer()->getItunesKeywords(); 0167 if (!$keywords || empty($keywords)) { 0168 return; 0169 } 0170 $el = $dom->createElement('itunes:keywords'); 0171 $text = $dom->createTextNode(implode(',', $keywords)); 0172 $el->appendChild($text); 0173 $root->appendChild($el); 0174 $this->_called = true; 0175 } 0176 0177 /** 0178 * Set entry subtitle 0179 * 0180 * @param DOMDocument $dom 0181 * @param DOMElement $root 0182 * @return void 0183 */ 0184 protected function _setSubtitle(DOMDocument $dom, DOMElement $root) 0185 { 0186 $subtitle = $this->getDataContainer()->getItunesSubtitle(); 0187 if (!$subtitle) { 0188 return; 0189 } 0190 $el = $dom->createElement('itunes:subtitle'); 0191 $text = $dom->createTextNode($subtitle); 0192 $el->appendChild($text); 0193 $root->appendChild($el); 0194 $this->_called = true; 0195 } 0196 0197 /** 0198 * Set entry summary 0199 * 0200 * @param DOMDocument $dom 0201 * @param DOMElement $root 0202 * @return void 0203 */ 0204 protected function _setSummary(DOMDocument $dom, DOMElement $root) 0205 { 0206 $summary = $this->getDataContainer()->getItunesSummary(); 0207 if (!$summary) { 0208 return; 0209 } 0210 $el = $dom->createElement('itunes:summary'); 0211 $text = $dom->createTextNode($summary); 0212 $el->appendChild($text); 0213 $root->appendChild($el); 0214 $this->_called = true; 0215 } 0216 }