1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Feed_Writer
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Writer.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @category Zend
* @package Zend_Feed_Writer
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Feed_Writer
{
/**
* Namespace constants
*/
const NAMESPACE_ATOM_03 = 'http://purl.org/atom/ns#';
const NAMESPACE_ATOM_10 = 'http://www.w3.org/2005/Atom';
const NAMESPACE_RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
const NAMESPACE_RSS_090 = 'http://my.netscape.com/rdf/simple/0.9/';
const NAMESPACE_RSS_10 = 'http://purl.org/rss/1.0/';
/**
* Feed type constants
*/
const TYPE_ANY = 'any';
const TYPE_ATOM_03 = 'atom-03';
const TYPE_ATOM_10 = 'atom-10';
const TYPE_ATOM_ANY = 'atom';
const TYPE_RSS_090 = 'rss-090';
const TYPE_RSS_091 = 'rss-091';
const TYPE_RSS_091_NETSCAPE = 'rss-091n';
const TYPE_RSS_091_USERLAND = 'rss-091u';
const TYPE_RSS_092 = 'rss-092';
const TYPE_RSS_093 = 'rss-093';
const TYPE_RSS_094 = 'rss-094';
const TYPE_RSS_10 = 'rss-10';
const TYPE_RSS_20 = 'rss-20';
const TYPE_RSS_ANY = 'rss';
/**
* PluginLoader instance used by component
*
* @var Zend_Loader_PluginLoader_Interface
*/
protected static $_pluginLoader = null;
/**
* Path on which to search for Extension classes
*
* @var array
*/
protected static $_prefixPaths = array();
/**
* Array of registered extensions by class postfix (after the base class
* name) across four categories - data containers and renderers for entry
* and feed levels.
*
* @var array
*/
protected static $_extensions = array(
'entry' => array(),
'feed' => array(),
'entryRenderer' => array(),
'feedRenderer' => array(),
);
/**
* Set plugin loader for use with Extensions
*
* @param Zend_Loader_PluginLoader_Interface
*/
public static function setPluginLoader(Zend_Loader_PluginLoader_Interface $loader)
{
self::$_pluginLoader = $loader;
}
/**
* Get plugin loader for use with Extensions
*
* @return Zend_Loader_PluginLoader_Interface
*/
public static function getPluginLoader()
{
if (!isset(self::$_pluginLoader)) {
// require_once 'Zend/Loader/PluginLoader.php';
self::$_pluginLoader = new Zend_Loader_PluginLoader(array(
'Zend_Feed_Writer_Extension_' => 'Zend/Feed/Writer/Extension/',
));
}
return self::$_pluginLoader;
}
/**
* Add prefix path for loading Extensions
*
* @param string $prefix
* @param string $path
* @return void
*/
public static function addPrefixPath($prefix, $path)
{
$prefix = rtrim($prefix, '_');
$path = rtrim($path, DIRECTORY_SEPARATOR);
self::getPluginLoader()->addPrefixPath($prefix, $path);
}
/**
* Add multiple Extension prefix paths at once
*
* @param array $spec
* @return void
*/
public static function addPrefixPaths(array $spec)
{
if (isset($spec['prefix']) && isset($spec['path'])) {
self::addPrefixPath($spec['prefix'], $spec['path']);
}
foreach ($spec as $prefixPath) {
if (isset($prefixPath['prefix']) && isset($prefixPath['path'])) {
self::addPrefixPath($prefixPath['prefix'], $prefixPath['path']);
}
}
}
/**
* Register an Extension by name
*
* @param string $name
* @return void
* @throws Zend_Feed_Exception if unable to resolve Extension class
*/
public static function registerExtension($name)
{
$feedName = $name . '_Feed';
$entryName = $name . '_Entry';
$feedRendererName = $name . '_Renderer_Feed';
$entryRendererName = $name . '_Renderer_Entry';
if (self::isRegistered($name)) {
if (self::getPluginLoader()->isLoaded($feedName)
|| self::getPluginLoader()->isLoaded($entryName)
|| self::getPluginLoader()->isLoaded($feedRendererName)
|| self::getPluginLoader()->isLoaded($entryRendererName)
) {
return;
}
}
try {
self::getPluginLoader()->load($feedName);
self::$_extensions['feed'][] = $feedName;
} catch (Zend_Loader_PluginLoader_Exception $e) {
}
try {
self::getPluginLoader()->load($entryName);
self::$_extensions['entry'][] = $entryName;
} catch (Zend_Loader_PluginLoader_Exception $e) {
}
try {
self::getPluginLoader()->load($feedRendererName);
self::$_extensions['feedRenderer'][] = $feedRendererName;
} catch (Zend_Loader_PluginLoader_Exception $e) {
}
try {
self::getPluginLoader()->load($entryRendererName);
self::$_extensions['entryRenderer'][] = $entryRendererName;
} catch (Zend_Loader_PluginLoader_Exception $e) {
}
if (!self::getPluginLoader()->isLoaded($feedName)
&& !self::getPluginLoader()->isLoaded($entryName)
&& !self::getPluginLoader()->isLoaded($feedRendererName)
&& !self::getPluginLoader()->isLoaded($entryRendererName)
) {
// require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Could not load extension: ' . $name
. 'using Plugin Loader. Check prefix paths are configured and extension exists.');
}
}
/**
* Is a given named Extension registered?
*
* @param string $extensionName
* @return boolean
*/
public static function isRegistered($extensionName)
{
$feedName = $extensionName . '_Feed';
$entryName = $extensionName . '_Entry';
$feedRendererName = $extensionName . '_Renderer_Feed';
$entryRendererName = $extensionName . '_Renderer_Entry';
if (in_array($feedName, self::$_extensions['feed'])
|| in_array($entryName, self::$_extensions['entry'])
|| in_array($feedRendererName, self::$_extensions['feedRenderer'])
|| in_array($entryRendererName, self::$_extensions['entryRenderer'])
) {
return true;
}
return false;
}
/**
* Get a list of extensions
*
* @return array
*/
public static function getExtensions()
{
return self::$_extensions;
}
/**
* Reset class state to defaults
*
* @return void
*/
public static function reset()
{
self::$_pluginLoader = null;
self::$_prefixPaths = array();
self::$_extensions = array(
'entry' => array(),
'feed' => array(),
'entryRenderer' => array(),
'feedRenderer' => array(),
);
}
/**
* Register core (default) extensions
*
* @return void
*/
public static function registerCoreExtensions()
{
self::registerExtension('DublinCore');
self::registerExtension('Content');
self::registerExtension('Atom');
self::registerExtension('Slash');
self::registerExtension('WellFormedWeb');
self::registerExtension('Threading');
self::registerExtension('ITunes');
}
public static function lcfirst($str)
{
$str[0] = strtolower($str[0]);
return $str;
}
}
|