8
* This source file is subject to the new BSD license that is bundled
9
* with this package in the file LICENSE.txt.
10
* It is also available through the world-wide-web at this URL:
11
* http://framework.zend.com/license/new-bsd
12
* If you did not receive a copy of the license and are unable to
13
* obtain it through the world-wide-web, please send an email
14
* to license@zend.com so we can send you a copy immediately.
18
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
19
* @license http://framework.zend.com/license/new-bsd New BSD License
20
* @version $Id: Header.php 8064 2008-02-16 10:58:39Z thomas $
27
require_once 'Zend/Loader.php';
30
* @see Zend_Feed_Builder_Header_Itunes
32
require_once 'Zend/Feed/Builder/Header/Itunes.php';
37
require_once 'Zend/Uri.php';
41
* Header of a custom build feed
43
* Classes implementing the Zend_Feed_Builder_Interface interface
44
* uses this class to describe the header of a feed
48
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
49
* @license http://framework.zend.com/license/new-bsd New BSD License
51
class Zend_Feed_Builder_Header extends ArrayObject
56
* @param string $title title of the feed
57
* @param string $link canonical url of the feed
58
* @param string $charset charset of the textual data
61
public function __construct($title, $link, $charset = 'utf-8')
63
$this->offsetSet('title', $title);
64
$this->offsetSet('link', $link);
65
$this->offsetSet('charset', $charset);
66
$this->setLastUpdate(time())
67
->setGenerator('Zend_Feed');
71
* Read only properties accessor
73
* @param string $name property to read
76
public function __get($name)
78
if (!$this->offsetExists($name)) {
82
return $this->offsetGet($name);
86
* Write properties accessor
88
* @param string $name name of the property to set
89
* @param mixed $value value to set
92
public function __set($name, $value)
94
$this->offsetSet($name, $value);
103
public function __isset($key)
105
return $this->offsetExists($key);
114
public function __unset($key)
116
if ($this->offsetExists($key)) {
117
$this->offsetUnset($key);
122
* Timestamp of the update date
124
* @param int $lastUpdate
125
* @return Zend_Feed_Builder_Header
127
public function setLastUpdate($lastUpdate)
129
$this->offsetSet('lastUpdate', $lastUpdate);
134
* Timestamp of the publication date
136
* @param int $published
137
* @return Zend_Feed_Builder_Header
139
public function setPublishedDate($published)
141
$this->offsetSet('published', $published);
146
* Short description of the feed
148
* @param string $description
149
* @return Zend_Feed_Builder_Header
151
public function setDescription($description)
153
$this->offsetSet('description', $description);
158
* Sets the author of the feed
160
* @param string $author
161
* @return Zend_Feed_Builder_Header
163
public function setAuthor($author)
165
$this->offsetSet('author', $author);
170
* Sets the author's email
172
* @param string $email
173
* @return Zend_Feed_Builder_Header
174
* @throws Zend_Feed_Builder_Exception
176
public function setEmail($email)
178
Zend_Loader::loadClass('Zend_Validate_EmailAddress');
179
$validate = new Zend_Validate_EmailAddress();
180
if (!$validate->isValid($email)) {
182
* @see Zend_Feed_Builder_Exception
184
require_once 'Zend/Feed/Builder/Exception.php';
185
throw new Zend_Feed_Builder_Exception("you have to set a valid email address into the email property");
187
$this->offsetSet('email', $email);
192
* Sets the copyright notice
194
* @param string $copyright
195
* @return Zend_Feed_Builder_Header
197
public function setCopyright($copyright)
199
$this->offsetSet('copyright', $copyright);
204
* Sets the image of the feed
206
* @param string $image
207
* @return Zend_Feed_Builder_Header
209
public function setImage($image)
211
$this->offsetSet('image', $image);
216
* Sets the generator of the feed
218
* @param string $generator
219
* @return Zend_Feed_Builder_Header
221
public function setGenerator($generator)
223
$this->offsetSet('generator', $generator);
228
* Sets the language of the feed
230
* @param string $language
231
* @return Zend_Feed_Builder_Header
233
public function setLanguage($language)
235
$this->offsetSet('language', $language);
240
* Email address for person responsible for technical issues
241
* Ignored if atom is used
243
* @param string $webmaster
244
* @return Zend_Feed_Builder_Header
245
* @throws Zend_Feed_Builder_Exception
247
public function setWebmaster($webmaster)
249
Zend_Loader::loadClass('Zend_Validate_EmailAddress');
250
$validate = new Zend_Validate_EmailAddress();
251
if (!$validate->isValid($webmaster)) {
253
* @see Zend_Feed_Builder_Exception
255
require_once 'Zend/Feed/Builder/Exception.php';
256
throw new Zend_Feed_Builder_Exception("you have to set a valid email address into the webmaster property");
258
$this->offsetSet('webmaster', $webmaster);
263
* How long in minutes a feed can be cached before refreshing
264
* Ignored if atom is used
267
* @return Zend_Feed_Builder_Header
268
* @throws Zend_Feed_Builder_Exception
270
public function setTtl($ttl)
272
Zend_Loader::loadClass('Zend_Validate_Int');
273
$validate = new Zend_Validate_Int();
274
if (!$validate->isValid($ttl)) {
276
* @see Zend_Feed_Builder_Exception
278
require_once 'Zend/Feed/Builder/Exception.php';
279
throw new Zend_Feed_Builder_Exception("you have to set an integer value to the ttl property");
281
$this->offsetSet('ttl', $ttl);
286
* PICS rating for the feed
287
* Ignored if atom is used
289
* @param string $rating
290
* @return Zend_Feed_Builder_Header
292
public function setRating($rating)
294
$this->offsetSet('rating', $rating);
299
* Cloud to be notified of updates of the feed
300
* Ignored if atom is used
302
* @param string|Zend_Uri_Http $uri
303
* @param string $procedure procedure to call, e.g. myCloud.rssPleaseNotify
304
* @param string $protocol protocol to use, e.g. soap or xml-rpc
305
* @return Zend_Feed_Builder_Header
306
* @throws Zend_Feed_Builder_Exception
308
public function setCloud($uri, $procedure, $protocol)
310
if (is_string($uri) && Zend_Uri_Http::check($uri)) {
311
$uri = Zend_Uri::factory($uri);
313
if (!$uri instanceof Zend_Uri_Http) {
315
* @see Zend_Feed_Builder_Exception
317
require_once 'Zend/Feed/Builder/Exception.php';
318
throw new Zend_Feed_Builder_Exception('Passed parameter is not a valid HTTP URI');
320
if (!$uri->getPort()) {
323
$this->offsetSet('cloud', array('uri' => $uri,
324
'procedure' => $procedure,
325
'protocol' => $protocol));
330
* A text input box that can be displayed with the feed
331
* Ignored if atom is used
333
* @param string $title the label of the Submit button in the text input area
334
* @param string $description explains the text input area
335
* @param string $name the name of the text object in the text input area
336
* @param string $link the URL of the CGI script that processes text input requests
337
* @return Zend_Feed_Builder_Header
339
public function setTextInput($title, $description, $name, $link)
341
$this->offsetSet('textInput', array('title' => $title,
342
'description' => $description,
349
* Hint telling aggregators which hours they can skip
350
* Ignored if atom is used
352
* @param array $hours list of hours in 24 format
353
* @return Zend_Feed_Builder_Header
354
* @throws Zend_Feed_Builder_Exception
356
public function setSkipHours(array $hours)
358
if (count($hours) > 24) {
360
* @see Zend_Feed_Builder_Exception
362
require_once 'Zend/Feed/Builder/Exception.php';
363
throw new Zend_Feed_Builder_Exception("you can not have more than 24 rows in the skipHours property");
365
foreach ($hours as $hour) {
366
if ($hour < 0 || $hour > 23) {
368
* @see Zend_Feed_Builder_Exception
370
require_once 'Zend/Feed/Builder/Exception.php';
371
throw new Zend_Feed_Builder_Exception("$hour has te be between 0 and 23");
374
$this->offsetSet('skipHours', $hours);
379
* Hint telling aggregators which days they can skip
380
* Ignored if atom is used
382
* @param array $days list of days to skip, e.g. Monday
383
* @return Zend_Feed_Builder_Header
384
* @throws Zend_Feed_Builder_Exception
386
public function setSkipDays(array $days)
388
if (count($days) > 7) {
390
* @see Zend_Feed_Builder_Exception
392
require_once 'Zend/Feed/Builder/Exception.php';
393
throw new Zend_Feed_Builder_Exception("you can not have more than 7 days in the skipDays property");
395
$valid = array('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday');
396
foreach ($days as $day) {
397
if (!in_array(strtolower($day), $valid)) {
399
* @see Zend_Feed_Builder_Exception
401
require_once 'Zend/Feed/Builder/Exception.php';
402
throw new Zend_Feed_Builder_Exception("$day is not a valid day");
405
$this->offsetSet('skipDays', $days);
410
* Sets the iTunes rss extension
412
* @param Zend_Feed_Builder_Header_Itunes $itunes
413
* @return Zend_Feed_Builder_Header
415
public function setITunes(Zend_Feed_Builder_Header_Itunes $itunes)
417
$this->offsetSet('itunes', $itunes);