File indexing completed on 2024-12-22 05:36:38
0001 <?php 0002 0003 /** 0004 * Zend Framework 0005 * 0006 * LICENSE 0007 * 0008 * This source file is subject to the new BSD license that is bundled 0009 * with this package in the file LICENSE.txt. 0010 * It is also available through the world-wide-web at this URL: 0011 * http://framework.zend.com/license/new-bsd 0012 * If you did not receive a copy of the license and are unable to 0013 * obtain it through the world-wide-web, please send an email 0014 * to license@zend.com so we can send you a copy immediately. 0015 * 0016 * @category Zend 0017 * @package Zend_Feed 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** 0024 * @see Zend_Feed_Builder_Header_Itunes 0025 */ 0026 // require_once 'Zend/Feed/Builder/Header/Itunes.php'; 0027 0028 /** 0029 * @see Zend_Uri 0030 */ 0031 // require_once 'Zend/Uri.php'; 0032 0033 0034 /** 0035 * Header of a custom build feed 0036 * 0037 * Classes implementing the Zend_Feed_Builder_Interface interface 0038 * uses this class to describe the header of a feed 0039 * 0040 * @category Zend 0041 * @package Zend_Feed 0042 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0043 * @license http://framework.zend.com/license/new-bsd New BSD License 0044 */ 0045 class Zend_Feed_Builder_Header extends ArrayObject 0046 { 0047 /** 0048 * Constructor 0049 * 0050 * @param string $title title of the feed 0051 * @param string $link canonical url of the feed 0052 * @param string $charset charset of the textual data 0053 * @return void 0054 */ 0055 public function __construct($title, $link, $charset = 'utf-8') 0056 { 0057 $this->offsetSet('title', $title); 0058 $this->offsetSet('link', $link); 0059 $this->offsetSet('charset', $charset); 0060 $this->setLastUpdate(time()) 0061 ->setGenerator('Zend_Feed'); 0062 } 0063 0064 /** 0065 * Read only properties accessor 0066 * 0067 * @param string $name property to read 0068 * @return mixed 0069 */ 0070 public function __get($name) 0071 { 0072 if (!$this->offsetExists($name)) { 0073 return NULL; 0074 } 0075 0076 return $this->offsetGet($name); 0077 } 0078 0079 /** 0080 * Write properties accessor 0081 * 0082 * @param string $name name of the property to set 0083 * @param mixed $value value to set 0084 * @return void 0085 */ 0086 public function __set($name, $value) 0087 { 0088 $this->offsetSet($name, $value); 0089 } 0090 0091 /** 0092 * Isset accessor 0093 * 0094 * @param string $key 0095 * @return boolean 0096 */ 0097 public function __isset($key) 0098 { 0099 return $this->offsetExists($key); 0100 } 0101 0102 /** 0103 * Unset accessor 0104 * 0105 * @param string $key 0106 * @return void 0107 */ 0108 public function __unset($key) 0109 { 0110 if ($this->offsetExists($key)) { 0111 $this->offsetUnset($key); 0112 } 0113 } 0114 0115 /** 0116 * Timestamp of the update date 0117 * 0118 * @param int $lastUpdate 0119 * @return Zend_Feed_Builder_Header 0120 */ 0121 public function setLastUpdate($lastUpdate) 0122 { 0123 $this->offsetSet('lastUpdate', $lastUpdate); 0124 return $this; 0125 } 0126 0127 /** 0128 * Timestamp of the publication date 0129 * 0130 * @param int $published 0131 * @return Zend_Feed_Builder_Header 0132 */ 0133 public function setPublishedDate($published) 0134 { 0135 $this->offsetSet('published', $published); 0136 return $this; 0137 } 0138 0139 /** 0140 * Short description of the feed 0141 * 0142 * @param string $description 0143 * @return Zend_Feed_Builder_Header 0144 */ 0145 public function setDescription($description) 0146 { 0147 $this->offsetSet('description', $description); 0148 return $this; 0149 } 0150 0151 /** 0152 * Sets the author of the feed 0153 * 0154 * @param string $author 0155 * @return Zend_Feed_Builder_Header 0156 */ 0157 public function setAuthor($author) 0158 { 0159 $this->offsetSet('author', $author); 0160 return $this; 0161 } 0162 0163 /** 0164 * Sets the author's email 0165 * 0166 * @param string $email 0167 * @return Zend_Feed_Builder_Header 0168 * @throws Zend_Feed_Builder_Exception 0169 */ 0170 public function setEmail($email) 0171 { 0172 /** 0173 * @see Zend_Validate_EmailAddress 0174 */ 0175 // require_once 'Zend/Validate/EmailAddress.php'; 0176 $validate = new Zend_Validate_EmailAddress(); 0177 if (!$validate->isValid($email)) { 0178 /** 0179 * @see Zend_Feed_Builder_Exception 0180 */ 0181 // require_once 'Zend/Feed/Builder/Exception.php'; 0182 throw new Zend_Feed_Builder_Exception("you have to set a valid email address into the email property"); 0183 } 0184 $this->offsetSet('email', $email); 0185 return $this; 0186 } 0187 0188 /** 0189 * Sets the copyright notice 0190 * 0191 * @param string $copyright 0192 * @return Zend_Feed_Builder_Header 0193 */ 0194 public function setCopyright($copyright) 0195 { 0196 $this->offsetSet('copyright', $copyright); 0197 return $this; 0198 } 0199 0200 /** 0201 * Sets the image of the feed 0202 * 0203 * @param string $image 0204 * @return Zend_Feed_Builder_Header 0205 */ 0206 public function setImage($image) 0207 { 0208 $this->offsetSet('image', $image); 0209 return $this; 0210 } 0211 0212 /** 0213 * Sets the generator of the feed 0214 * 0215 * @param string $generator 0216 * @return Zend_Feed_Builder_Header 0217 */ 0218 public function setGenerator($generator) 0219 { 0220 $this->offsetSet('generator', $generator); 0221 return $this; 0222 } 0223 0224 /** 0225 * Sets the language of the feed 0226 * 0227 * @param string $language 0228 * @return Zend_Feed_Builder_Header 0229 */ 0230 public function setLanguage($language) 0231 { 0232 $this->offsetSet('language', $language); 0233 return $this; 0234 } 0235 0236 /** 0237 * Email address for person responsible for technical issues 0238 * Ignored if atom is used 0239 * 0240 * @param string $webmaster 0241 * @return Zend_Feed_Builder_Header 0242 * @throws Zend_Feed_Builder_Exception 0243 */ 0244 public function setWebmaster($webmaster) 0245 { 0246 /** 0247 * @see Zend_Validate_EmailAddress 0248 */ 0249 // require_once 'Zend/Validate/EmailAddress.php'; 0250 $validate = new Zend_Validate_EmailAddress(); 0251 if (!$validate->isValid($webmaster)) { 0252 /** 0253 * @see Zend_Feed_Builder_Exception 0254 */ 0255 // require_once 'Zend/Feed/Builder/Exception.php'; 0256 throw new Zend_Feed_Builder_Exception("you have to set a valid email address into the webmaster property"); 0257 } 0258 $this->offsetSet('webmaster', $webmaster); 0259 return $this; 0260 } 0261 0262 /** 0263 * How long in minutes a feed can be cached before refreshing 0264 * Ignored if atom is used 0265 * 0266 * @param int $ttl 0267 * @return Zend_Feed_Builder_Header 0268 * @throws Zend_Feed_Builder_Exception 0269 */ 0270 public function setTtl($ttl) 0271 { 0272 /** 0273 * @see Zend_Validate_Int 0274 */ 0275 // require_once 'Zend/Validate/Int.php'; 0276 $validate = new Zend_Validate_Int(); 0277 if (!$validate->isValid($ttl)) { 0278 /** 0279 * @see Zend_Feed_Builder_Exception 0280 */ 0281 // require_once 'Zend/Feed/Builder/Exception.php'; 0282 throw new Zend_Feed_Builder_Exception("you have to set an integer value to the ttl property"); 0283 } 0284 $this->offsetSet('ttl', $ttl); 0285 return $this; 0286 } 0287 0288 /** 0289 * PICS rating for the feed 0290 * Ignored if atom is used 0291 * 0292 * @param string $rating 0293 * @return Zend_Feed_Builder_Header 0294 */ 0295 public function setRating($rating) 0296 { 0297 $this->offsetSet('rating', $rating); 0298 return $this; 0299 } 0300 0301 /** 0302 * Cloud to be notified of updates of the feed 0303 * Ignored if atom is used 0304 * 0305 * @param string|Zend_Uri_Http $uri 0306 * @param string $procedure procedure to call, e.g. myCloud.rssPleaseNotify 0307 * @param string $protocol protocol to use, e.g. soap or xml-rpc 0308 * @return Zend_Feed_Builder_Header 0309 * @throws Zend_Feed_Builder_Exception 0310 */ 0311 public function setCloud($uri, $procedure, $protocol) 0312 { 0313 if (is_string($uri) && Zend_Uri_Http::check($uri)) { 0314 $uri = Zend_Uri::factory($uri); 0315 } 0316 if (!$uri instanceof Zend_Uri_Http) { 0317 /** 0318 * @see Zend_Feed_Builder_Exception 0319 */ 0320 // require_once 'Zend/Feed/Builder/Exception.php'; 0321 throw new Zend_Feed_Builder_Exception('Passed parameter is not a valid HTTP URI'); 0322 } 0323 if (!$uri->getPort()) { 0324 $uri->setPort(80); 0325 } 0326 $this->offsetSet('cloud', array('uri' => $uri, 0327 'procedure' => $procedure, 0328 'protocol' => $protocol)); 0329 return $this; 0330 } 0331 0332 /** 0333 * A text input box that can be displayed with the feed 0334 * Ignored if atom is used 0335 * 0336 * @param string $title the label of the Submit button in the text input area 0337 * @param string $description explains the text input area 0338 * @param string $name the name of the text object in the text input area 0339 * @param string $link the URL of the CGI script that processes text input requests 0340 * @return Zend_Feed_Builder_Header 0341 */ 0342 public function setTextInput($title, $description, $name, $link) 0343 { 0344 $this->offsetSet('textInput', array('title' => $title, 0345 'description' => $description, 0346 'name' => $name, 0347 'link' => $link)); 0348 return $this; 0349 } 0350 0351 /** 0352 * Hint telling aggregators which hours they can skip 0353 * Ignored if atom is used 0354 * 0355 * @param array $hours list of hours in 24 format 0356 * @return Zend_Feed_Builder_Header 0357 * @throws Zend_Feed_Builder_Exception 0358 */ 0359 public function setSkipHours(array $hours) 0360 { 0361 if (count($hours) > 24) { 0362 /** 0363 * @see Zend_Feed_Builder_Exception 0364 */ 0365 // require_once 'Zend/Feed/Builder/Exception.php'; 0366 throw new Zend_Feed_Builder_Exception("you can not have more than 24 rows in the skipHours property"); 0367 } 0368 foreach ($hours as $hour) { 0369 if ($hour < 0 || $hour > 23) { 0370 /** 0371 * @see Zend_Feed_Builder_Exception 0372 */ 0373 // require_once 'Zend/Feed/Builder/Exception.php'; 0374 throw new Zend_Feed_Builder_Exception("$hour has te be between 0 and 23"); 0375 } 0376 } 0377 $this->offsetSet('skipHours', $hours); 0378 return $this; 0379 } 0380 0381 /** 0382 * Hint telling aggregators which days they can skip 0383 * Ignored if atom is used 0384 * 0385 * @param array $days list of days to skip, e.g. Monday 0386 * @return Zend_Feed_Builder_Header 0387 * @throws Zend_Feed_Builder_Exception 0388 */ 0389 public function setSkipDays(array $days) 0390 { 0391 if (count($days) > 7) { 0392 /** 0393 * @see Zend_Feed_Builder_Exception 0394 */ 0395 // require_once 'Zend/Feed/Builder/Exception.php'; 0396 throw new Zend_Feed_Builder_Exception("you can not have more than 7 days in the skipDays property"); 0397 } 0398 $valid = array('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'); 0399 foreach ($days as $day) { 0400 if (!in_array(strtolower($day), $valid)) { 0401 /** 0402 * @see Zend_Feed_Builder_Exception 0403 */ 0404 // require_once 'Zend/Feed/Builder/Exception.php'; 0405 throw new Zend_Feed_Builder_Exception("$day is not a valid day"); 0406 } 0407 } 0408 $this->offsetSet('skipDays', $days); 0409 return $this; 0410 } 0411 0412 /** 0413 * Sets the iTunes rss extension 0414 * 0415 * @param Zend_Feed_Builder_Header_Itunes $itunes 0416 * @return Zend_Feed_Builder_Header 0417 */ 0418 public function setITunes(Zend_Feed_Builder_Header_Itunes $itunes) 0419 { 0420 $this->offsetSet('itunes', $itunes); 0421 return $this; 0422 } 0423 }