PageRenderTime 25ms CodeModel.GetById 20ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/zf/library/Zend/Feed/Writer/Extension/ITunes/Renderer/Entry.php

http://github.com/eryx/php-framework-benchmark
PHP | 216 lines | 111 code | 11 blank | 94 comment | 10 complexity | 2f9ab216d00ae30f4b1a08806cb8c9c6 MD5 | raw file
Possible License(s): MIT, BSD-3-Clause, Apache-2.0, LGPL-2.1, LGPL-3.0, BSD-2-Clause
  1<?php
  2/**
  3 * Zend Framework
  4 *
  5 * LICENSE
  6 *
  7 * This source file is subject to the new BSD license that is bundled
  8 * with this package in the file LICENSE.txt.
  9 * It is also available through the world-wide-web at this URL:
 10 * http://framework.zend.com/license/new-bsd
 11 * If you did not receive a copy of the license and are unable to
 12 * obtain it through the world-wide-web, please send an email
 13 * to license@zend.com so we can send you a copy immediately.
 14 *
 15 * @category   Zend
 16 * @package    Zend_Feed_Writer
 17 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 18 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 19 * @version    $Id: Entry.php 23775 2011-03-01 17:25:24Z ralph $
 20 */
 21
 22/**
 23 * @see Zend_Feed_Writer_Extension_RendererAbstract
 24 */
 25require_once 'Zend/Feed/Writer/Extension/RendererAbstract.php';
 26
 27/**
 28 * @category   Zend
 29 * @package    Zend_Feed_Writer
 30 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 31 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 32 */
 33class Zend_Feed_Writer_Extension_ITunes_Renderer_Entry
 34    extends Zend_Feed_Writer_Extension_RendererAbstract
 35{
 36    /**
 37     * Set to TRUE if a rendering method actually renders something. This
 38     * is used to prevent premature appending of a XML namespace declaration
 39     * until an element which requires it is actually appended.
 40     *
 41     * @var bool
 42     */
 43    protected $_called = false;
 44
 45    /**
 46     * Render entry
 47     *
 48     * @return void
 49     */
 50    public function render()
 51    {
 52        $this->_setAuthors($this->_dom, $this->_base);
 53        $this->_setBlock($this->_dom, $this->_base);
 54        $this->_setDuration($this->_dom, $this->_base);
 55        $this->_setExplicit($this->_dom, $this->_base);
 56        $this->_setKeywords($this->_dom, $this->_base);
 57        $this->_setSubtitle($this->_dom, $this->_base);
 58        $this->_setSummary($this->_dom, $this->_base);
 59        if ($this->_called) {
 60            $this->_appendNamespaces();
 61        }
 62    }
 63
 64    /**
 65     * Append namespaces to entry root
 66     *
 67     * @return void
 68     */
 69    protected function _appendNamespaces()
 70    {
 71        $this->getRootElement()->setAttribute('xmlns:itunes',
 72            'http://www.itunes.com/dtds/podcast-1.0.dtd');
 73    }
 74
 75    /**
 76     * Set entry authors
 77     *
 78     * @param  DOMDocument $dom
 79     * @param  DOMElement $root
 80     * @return void
 81     */
 82    protected function _setAuthors(DOMDocument $dom, DOMElement $root)
 83    {
 84        $authors = $this->getDataContainer()->getItunesAuthors();
 85        if (!$authors || empty($authors)) {
 86            return;
 87        }
 88        foreach ($authors as $author) {
 89            $el = $dom->createElement('itunes:author');
 90            $text = $dom->createTextNode($author);
 91            $el->appendChild($text);
 92            $root->appendChild($el);
 93            $this->_called = true;
 94        }
 95    }
 96
 97    /**
 98     * Set itunes block
 99     *
100     * @param  DOMDocument $dom
101     * @param  DOMElement $root
102     * @return void
103     */
104    protected function _setBlock(DOMDocument $dom, DOMElement $root)
105    {
106        $block = $this->getDataContainer()->getItunesBlock();
107        if ($block === null) {
108            return;
109        }
110        $el = $dom->createElement('itunes:block');
111        $text = $dom->createTextNode($block);
112        $el->appendChild($text);
113        $root->appendChild($el);
114        $this->_called = true;
115    }
116
117    /**
118     * Set entry duration
119     *
120     * @param  DOMDocument $dom
121     * @param  DOMElement $root
122     * @return void
123     */
124    protected function _setDuration(DOMDocument $dom, DOMElement $root)
125    {
126        $duration = $this->getDataContainer()->getItunesDuration();
127        if (!$duration) {
128            return;
129        }
130        $el = $dom->createElement('itunes:duration');
131        $text = $dom->createTextNode($duration);
132        $el->appendChild($text);
133        $root->appendChild($el);
134        $this->_called = true;
135    }
136
137    /**
138     * Set explicit flag
139     *
140     * @param  DOMDocument $dom
141     * @param  DOMElement $root
142     * @return void
143     */
144    protected function _setExplicit(DOMDocument $dom, DOMElement $root)
145    {
146        $explicit = $this->getDataContainer()->getItunesExplicit();
147        if ($explicit === null) {
148            return;
149        }
150        $el = $dom->createElement('itunes:explicit');
151        $text = $dom->createTextNode($explicit);
152        $el->appendChild($text);
153        $root->appendChild($el);
154        $this->_called = true;
155    }
156
157    /**
158     * Set entry keywords
159     *
160     * @param  DOMDocument $dom
161     * @param  DOMElement $root
162     * @return void
163     */
164    protected function _setKeywords(DOMDocument $dom, DOMElement $root)
165    {
166        $keywords = $this->getDataContainer()->getItunesKeywords();
167        if (!$keywords || empty($keywords)) {
168            return;
169        }
170        $el = $dom->createElement('itunes:keywords');
171        $text = $dom->createTextNode(implode(',', $keywords));
172        $el->appendChild($text);
173        $root->appendChild($el);
174        $this->_called = true;
175    }
176
177    /**
178     * Set entry subtitle
179     *
180     * @param  DOMDocument $dom
181     * @param  DOMElement $root
182     * @return void
183     */
184    protected function _setSubtitle(DOMDocument $dom, DOMElement $root)
185    {
186        $subtitle = $this->getDataContainer()->getItunesSubtitle();
187        if (!$subtitle) {
188            return;
189        }
190        $el = $dom->createElement('itunes:subtitle');
191        $text = $dom->createTextNode($subtitle);
192        $el->appendChild($text);
193        $root->appendChild($el);
194        $this->_called = true;
195    }
196
197    /**
198     * Set entry summary
199     *
200     * @param  DOMDocument $dom
201     * @param  DOMElement $root
202     * @return void
203     */
204    protected function _setSummary(DOMDocument $dom, DOMElement $root)
205    {
206        $summary = $this->getDataContainer()->getItunesSummary();
207        if (!$summary) {
208            return;
209        }
210        $el = $dom->createElement('itunes:summary');
211        $text = $dom->createTextNode($summary);
212        $el->appendChild($text);
213        $root->appendChild($el);
214        $this->_called = true;
215    }
216}