|
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-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
18 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
19 * @version $Id: RendererAbstract.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
20 */ |
|
21 |
|
22 /** @see Zend_Feed_Writer */ |
|
23 require_once 'Zend/Feed/Writer.php'; |
|
24 |
|
25 /** @see Zend_Version */ |
|
26 require_once 'Zend/Version.php'; |
|
27 |
|
28 /** |
|
29 * @category Zend |
|
30 * @package Zend_Feed_Writer |
|
31 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
32 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
33 */ |
|
34 class Zend_Feed_Writer_Renderer_RendererAbstract |
|
35 { |
|
36 /** |
|
37 * Extensions |
|
38 * @var array |
|
39 */ |
|
40 protected $_extensions = array(); |
|
41 |
|
42 /** |
|
43 * @var mixed |
|
44 */ |
|
45 protected $_container = null; |
|
46 |
|
47 /** |
|
48 * @var DOMDocument |
|
49 */ |
|
50 protected $_dom = null; |
|
51 |
|
52 /** |
|
53 * @var bool |
|
54 */ |
|
55 protected $_ignoreExceptions = false; |
|
56 |
|
57 /** |
|
58 * @var array |
|
59 */ |
|
60 protected $_exceptions = array(); |
|
61 |
|
62 /** |
|
63 * Encoding of all text values |
|
64 * |
|
65 * @var string |
|
66 */ |
|
67 protected $_encoding = 'UTF-8'; |
|
68 |
|
69 /** |
|
70 * Holds the value "atom" or "rss" depending on the feed type set when |
|
71 * when last exported. |
|
72 * |
|
73 * @var string |
|
74 */ |
|
75 protected $_type = null; |
|
76 |
|
77 /** |
|
78 * @var DOMElement |
|
79 */ |
|
80 protected $_rootElement = null; |
|
81 |
|
82 /** |
|
83 * Constructor |
|
84 * |
|
85 * @param mixed $container |
|
86 * @return void |
|
87 */ |
|
88 public function __construct($container) |
|
89 { |
|
90 $this->_container = $container; |
|
91 $this->setType($container->getType()); |
|
92 $this->_loadExtensions(); |
|
93 } |
|
94 |
|
95 /** |
|
96 * Save XML to string |
|
97 * |
|
98 * @return string |
|
99 */ |
|
100 public function saveXml() |
|
101 { |
|
102 return $this->getDomDocument()->saveXml(); |
|
103 } |
|
104 |
|
105 /** |
|
106 * Get DOM document |
|
107 * |
|
108 * @return DOMDocument |
|
109 */ |
|
110 public function getDomDocument() |
|
111 { |
|
112 return $this->_dom; |
|
113 } |
|
114 |
|
115 /** |
|
116 * Get document element from DOM |
|
117 * |
|
118 * @return DOMElement |
|
119 */ |
|
120 public function getElement() |
|
121 { |
|
122 return $this->getDomDocument()->documentElement; |
|
123 } |
|
124 |
|
125 /** |
|
126 * Get data container of items being rendered |
|
127 * |
|
128 * @return mixed |
|
129 */ |
|
130 public function getDataContainer() |
|
131 { |
|
132 return $this->_container; |
|
133 } |
|
134 |
|
135 /** |
|
136 * Set feed encoding |
|
137 * |
|
138 * @param string $enc |
|
139 * @return Zend_Feed_Writer_Renderer_RendererAbstract |
|
140 */ |
|
141 public function setEncoding($enc) |
|
142 { |
|
143 $this->_encoding = $enc; |
|
144 return $this; |
|
145 } |
|
146 |
|
147 /** |
|
148 * Get feed encoding |
|
149 * |
|
150 * @return string |
|
151 */ |
|
152 public function getEncoding() |
|
153 { |
|
154 return $this->_encoding; |
|
155 } |
|
156 |
|
157 /** |
|
158 * Indicate whether or not to ignore exceptions |
|
159 * |
|
160 * @param bool $bool |
|
161 * @return Zend_Feed_Writer_Renderer_RendererAbstract |
|
162 */ |
|
163 public function ignoreExceptions($bool = true) |
|
164 { |
|
165 if (!is_bool($bool)) { |
|
166 require_once 'Zend/Feed/Exception.php'; |
|
167 throw new Zend_Feed_Exception('Invalid parameter: $bool. Should be TRUE or FALSE (defaults to TRUE if null)'); |
|
168 } |
|
169 $this->_ignoreExceptions = $bool; |
|
170 return $this; |
|
171 } |
|
172 |
|
173 /** |
|
174 * Get exception list |
|
175 * |
|
176 * @return array |
|
177 */ |
|
178 public function getExceptions() |
|
179 { |
|
180 return $this->_exceptions; |
|
181 } |
|
182 |
|
183 /** |
|
184 * Set the current feed type being exported to "rss" or "atom". This allows |
|
185 * other objects to gracefully choose whether to execute or not, depending |
|
186 * on their appropriateness for the current type, e.g. renderers. |
|
187 * |
|
188 * @param string $type |
|
189 */ |
|
190 public function setType($type) |
|
191 { |
|
192 $this->_type = $type; |
|
193 } |
|
194 |
|
195 /** |
|
196 * Retrieve the current or last feed type exported. |
|
197 * |
|
198 * @return string Value will be "rss" or "atom" |
|
199 */ |
|
200 public function getType() |
|
201 { |
|
202 return $this->_type; |
|
203 } |
|
204 |
|
205 /** |
|
206 * Sets the absolute root element for the XML feed being generated. This |
|
207 * helps simplify the appending of namespace declarations, but also ensures |
|
208 * namespaces are added to the root element - not scattered across the entire |
|
209 * XML file - may assist namespace unsafe parsers and looks pretty ;). |
|
210 * |
|
211 * @param DOMElement $root |
|
212 */ |
|
213 public function setRootElement(DOMElement $root) |
|
214 { |
|
215 $this->_rootElement = $root; |
|
216 } |
|
217 |
|
218 /** |
|
219 * Retrieve the absolute root element for the XML feed being generated. |
|
220 * |
|
221 * @return DOMElement |
|
222 */ |
|
223 public function getRootElement() |
|
224 { |
|
225 return $this->_rootElement; |
|
226 } |
|
227 |
|
228 /** |
|
229 * Load extensions from Zend_Feed_Writer |
|
230 * |
|
231 * @return void |
|
232 */ |
|
233 protected function _loadExtensions() |
|
234 { |
|
235 Zend_Feed_Writer::registerCoreExtensions(); |
|
236 $all = Zend_Feed_Writer::getExtensions(); |
|
237 if (stripos(get_class($this), 'entry')) { |
|
238 $exts = $all['entryRenderer']; |
|
239 } else { |
|
240 $exts = $all['feedRenderer']; |
|
241 } |
|
242 foreach ($exts as $extension) { |
|
243 $className = Zend_Feed_Writer::getPluginLoader()->getClassName($extension); |
|
244 $this->_extensions[$extension] = new $className( |
|
245 $this->getDataContainer() |
|
246 ); |
|
247 $this->_extensions[$extension]->setEncoding($this->getEncoding()); |
|
248 } |
|
249 } |
|
250 } |