File indexing completed on 2024-12-29 05:27:38

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 /** @see Zend_Feed_Writer */
0023 // require_once 'Zend/Feed/Writer.php';
0024 
0025 /** @see Zend_Version */
0026 // require_once 'Zend/Version.php';
0027 
0028 /**
0029  * @category   Zend
0030  * @package    Zend_Feed_Writer
0031  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0032  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0033  */
0034 class Zend_Feed_Writer_Renderer_RendererAbstract
0035 {
0036     /**
0037      * Extensions
0038      * @var array
0039      */
0040     protected $_extensions = array();
0041 
0042     /**
0043      * @var mixed
0044      */
0045     protected $_container = null;
0046 
0047     /**
0048      * @var DOMDocument
0049      */
0050     protected $_dom = null;
0051 
0052     /**
0053      * @var bool
0054      */
0055     protected $_ignoreExceptions = false;
0056 
0057     /**
0058      * @var array
0059      */
0060     protected $_exceptions = array();
0061 
0062     /**
0063      * Encoding of all text values
0064      *
0065      * @var string
0066      */
0067     protected $_encoding = 'UTF-8';
0068 
0069     /**
0070      * Holds the value "atom" or "rss" depending on the feed type set when
0071      * when last exported.
0072      *
0073      * @var string
0074      */
0075     protected $_type = null;
0076 
0077     /**
0078      * @var DOMElement
0079      */
0080     protected $_rootElement = null;
0081 
0082     /**
0083      * Constructor
0084      *
0085      * @param  mixed $container
0086      * @return void
0087      */
0088     public function __construct($container)
0089     {
0090         $this->_container = $container;
0091         $this->setType($container->getType());
0092         $this->_loadExtensions();
0093     }
0094 
0095     /**
0096      * Save XML to string
0097      *
0098      * @return string
0099      */
0100     public function saveXml()
0101     {
0102         return $this->getDomDocument()->saveXml();
0103     }
0104 
0105     /**
0106      * Get DOM document
0107      *
0108      * @return DOMDocument
0109      */
0110     public function getDomDocument()
0111     {
0112         return $this->_dom;
0113     }
0114 
0115     /**
0116      * Get document element from DOM
0117      *
0118      * @return DOMElement
0119      */
0120     public function getElement()
0121     {
0122         return $this->getDomDocument()->documentElement;
0123     }
0124 
0125     /**
0126      * Get data container of items being rendered
0127      *
0128      * @return mixed
0129      */
0130     public function getDataContainer()
0131     {
0132         return $this->_container;
0133     }
0134 
0135     /**
0136      * Set feed encoding
0137      *
0138      * @param  string $enc
0139      * @return Zend_Feed_Writer_Renderer_RendererAbstract
0140      */
0141     public function setEncoding($enc)
0142     {
0143         $this->_encoding = $enc;
0144         return $this;
0145     }
0146 
0147     /**
0148      * Get feed encoding
0149      *
0150      * @return string
0151      */
0152     public function getEncoding()
0153     {
0154         return $this->_encoding;
0155     }
0156 
0157     /**
0158      * Indicate whether or not to ignore exceptions
0159      *
0160      * @param  bool $bool
0161      * @return Zend_Feed_Writer_Renderer_RendererAbstract
0162      */
0163     public function ignoreExceptions($bool = true)
0164     {
0165         if (!is_bool($bool)) {
0166             // require_once 'Zend/Feed/Exception.php';
0167             throw new Zend_Feed_Exception('Invalid parameter: $bool. Should be TRUE or FALSE (defaults to TRUE if null)');
0168         }
0169         $this->_ignoreExceptions = $bool;
0170         return $this;
0171     }
0172 
0173     /**
0174      * Get exception list
0175      *
0176      * @return array
0177      */
0178     public function getExceptions()
0179     {
0180         return $this->_exceptions;
0181     }
0182 
0183     /**
0184      * Set the current feed type being exported to "rss" or "atom". This allows
0185      * other objects to gracefully choose whether to execute or not, depending
0186      * on their appropriateness for the current type, e.g. renderers.
0187      *
0188      * @param string $type
0189      */
0190     public function setType($type)
0191     {
0192         $this->_type = $type;
0193     }
0194 
0195     /**
0196      * Retrieve the current or last feed type exported.
0197      *
0198      * @return string Value will be "rss" or "atom"
0199      */
0200     public function getType()
0201     {
0202         return $this->_type;
0203     }
0204 
0205     /**
0206      * Sets the absolute root element for the XML feed being generated. This
0207      * helps simplify the appending of namespace declarations, but also ensures
0208      * namespaces are added to the root element - not scattered across the entire
0209      * XML file - may assist namespace unsafe parsers and looks pretty ;).
0210      *
0211      * @param DOMElement $root
0212      */
0213     public function setRootElement(DOMElement $root)
0214     {
0215         $this->_rootElement = $root;
0216     }
0217 
0218     /**
0219      * Retrieve the absolute root element for the XML feed being generated.
0220      *
0221      * @return DOMElement
0222      */
0223     public function getRootElement()
0224     {
0225         return $this->_rootElement;
0226     }
0227 
0228     /**
0229      * Load extensions from Zend_Feed_Writer
0230      *
0231      * @return void
0232      */
0233     protected function _loadExtensions()
0234     {
0235         Zend_Feed_Writer::registerCoreExtensions();
0236         $all = Zend_Feed_Writer::getExtensions();
0237         if (stripos(get_class($this), 'entry')) {
0238             $exts = $all['entryRenderer'];
0239         } else {
0240             $exts = $all['feedRenderer'];
0241         }
0242         foreach ($exts as $extension) {
0243             $className = Zend_Feed_Writer::getPluginLoader()->getClassName($extension);
0244             $this->_extensions[$extension] = new $className(
0245                 $this->getDataContainer()
0246             );
0247             $this->_extensions[$extension]->setEncoding($this->getEncoding());
0248         }
0249     }
0250 }