File indexing completed on 2025-01-19 05:21:04
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 /** 0025 * An entry of a custom build feed 0026 * 0027 * Classes implementing the Zend_Feed_Builder_Interface interface 0028 * uses this class to describe an entry of a feed 0029 * 0030 * @category Zend 0031 * @package Zend_Feed 0032 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0033 * @license http://framework.zend.com/license/new-bsd New BSD License 0034 */ 0035 class Zend_Feed_Builder_Entry extends ArrayObject 0036 { 0037 /** 0038 * Create a new builder entry 0039 * 0040 * @param string $title 0041 * @param string $link 0042 * @param string $description short version of the entry, no html 0043 * @return void 0044 */ 0045 public function __construct($title, $link, $description) 0046 { 0047 $this->offsetSet('title', $title); 0048 $this->offsetSet('link', $link); 0049 $this->offsetSet('description', $description); 0050 $this->setLastUpdate(time()); 0051 } 0052 0053 /** 0054 * Read only properties accessor 0055 * 0056 * @param string $name property to read 0057 * @return mixed 0058 */ 0059 public function __get($name) 0060 { 0061 if (!$this->offsetExists($name)) { 0062 return NULL; 0063 } 0064 0065 return $this->offsetGet($name); 0066 } 0067 0068 /** 0069 * Write properties accessor 0070 * 0071 * @param string $name name of the property to set 0072 * @param mixed $value value to set 0073 * @return void 0074 */ 0075 public function __set($name, $value) 0076 { 0077 $this->offsetSet($name, $value); 0078 } 0079 0080 /** 0081 * Isset accessor 0082 * 0083 * @param string $key 0084 * @return boolean 0085 */ 0086 public function __isset($key) 0087 { 0088 return $this->offsetExists($key); 0089 } 0090 0091 /** 0092 * Unset accessor 0093 * 0094 * @param string $key 0095 * @return void 0096 */ 0097 public function __unset($key) 0098 { 0099 if ($this->offsetExists($key)) { 0100 $this->offsetUnset($key); 0101 } 0102 } 0103 0104 /** 0105 * Sets the author of the entry 0106 * 0107 * @param string $author 0108 * @return Zend_Feed_Builder_Entry 0109 */ 0110 public function setAuthor($author) 0111 { 0112 $this->offsetSet('author', $author); 0113 return $this; 0114 } 0115 0116 /** 0117 * Sets the id/guid of the entry 0118 * 0119 * @param string $id 0120 * @return Zend_Feed_Builder_Entry 0121 */ 0122 public function setId($id) 0123 { 0124 $this->offsetSet('guid', $id); 0125 return $this; 0126 } 0127 0128 /** 0129 * Sets the full html content of the entry 0130 * 0131 * @param string $content 0132 * @return Zend_Feed_Builder_Entry 0133 */ 0134 public function setContent($content) 0135 { 0136 $this->offsetSet('content', $content); 0137 return $this; 0138 } 0139 0140 /** 0141 * Timestamp of the update date 0142 * 0143 * @param int $lastUpdate 0144 * @return Zend_Feed_Builder_Entry 0145 */ 0146 public function setLastUpdate($lastUpdate) 0147 { 0148 $this->offsetSet('lastUpdate', $lastUpdate); 0149 return $this; 0150 } 0151 0152 /** 0153 * Sets the url of the commented page associated to the entry 0154 * 0155 * @param string $comments 0156 * @return Zend_Feed_Builder_Entry 0157 */ 0158 public function setCommentsUrl($comments) 0159 { 0160 $this->offsetSet('comments', $comments); 0161 return $this; 0162 } 0163 0164 /** 0165 * Sets the url of the comments feed link 0166 * 0167 * @param string $commentRss 0168 * @return Zend_Feed_Builder_Entry 0169 */ 0170 public function setCommentsRssUrl($commentRss) 0171 { 0172 $this->offsetSet('commentRss', $commentRss); 0173 return $this; 0174 } 0175 0176 /** 0177 * Defines a reference to the original source 0178 * 0179 * @param string $title 0180 * @param string $url 0181 * @return Zend_Feed_Builder_Entry 0182 */ 0183 public function setSource($title, $url) 0184 { 0185 $this->offsetSet('source', array('title' => $title, 0186 'url' => $url)); 0187 return $this; 0188 } 0189 0190 /** 0191 * Sets the categories of the entry 0192 * Format of the array: 0193 * <code> 0194 * array( 0195 * array( 0196 * 'term' => 'first category label', 0197 * 'scheme' => 'url that identifies a categorization scheme' // optional 0198 * ), 0199 * // second category and so one 0200 * ) 0201 * </code> 0202 * 0203 * @param array $categories 0204 * @return Zend_Feed_Builder_Entry 0205 */ 0206 public function setCategories(array $categories) 0207 { 0208 foreach ($categories as $category) { 0209 $this->addCategory($category); 0210 } 0211 return $this; 0212 } 0213 0214 /** 0215 * Add a category to the entry 0216 * 0217 * @param array $category see Zend_Feed_Builder_Entry::setCategories() for format 0218 * @return Zend_Feed_Builder_Entry 0219 * @throws Zend_Feed_Builder_Exception 0220 */ 0221 public function addCategory(array $category) 0222 { 0223 if (empty($category['term'])) { 0224 /** 0225 * @see Zend_Feed_Builder_Exception 0226 */ 0227 // require_once 'Zend/Feed/Builder/Exception.php'; 0228 throw new Zend_Feed_Builder_Exception("you have to define the name of the category"); 0229 } 0230 0231 if (!$this->offsetExists('category')) { 0232 $categories = array($category); 0233 } else { 0234 $categories = $this->offsetGet('category'); 0235 $categories[] = $category; 0236 } 0237 $this->offsetSet('category', $categories); 0238 return $this; 0239 } 0240 0241 /** 0242 * Sets the enclosures of the entry 0243 * Format of the array: 0244 * <code> 0245 * array( 0246 * array( 0247 * 'url' => 'url of the linked enclosure', 0248 * 'type' => 'mime type of the enclosure' // optional 0249 * 'length' => 'length of the linked content in octets' // optional 0250 * ), 0251 * // second enclosure and so one 0252 * ) 0253 * </code> 0254 * 0255 * @param array $enclosures 0256 * @return Zend_Feed_Builder_Entry 0257 * @throws Zend_Feed_Builder_Exception 0258 */ 0259 public function setEnclosures(array $enclosures) 0260 { 0261 foreach ($enclosures as $enclosure) { 0262 if (empty($enclosure['url'])) { 0263 /** 0264 * @see Zend_Feed_Builder_Exception 0265 */ 0266 // require_once 'Zend/Feed/Builder/Exception.php'; 0267 throw new Zend_Feed_Builder_Exception("you have to supply an url for your enclosure"); 0268 } 0269 $type = isset($enclosure['type']) ? $enclosure['type'] : ''; 0270 $length = isset($enclosure['length']) ? $enclosure['length'] : ''; 0271 $this->addEnclosure($enclosure['url'], $type, $length); 0272 } 0273 return $this; 0274 } 0275 0276 /** 0277 * Add an enclosure to the entry 0278 * 0279 * @param string $url 0280 * @param string $type 0281 * @param string $length 0282 * @return Zend_Feed_Builder_Entry 0283 */ 0284 public function addEnclosure($url, $type = '', $length = '') 0285 { 0286 if (!$this->offsetExists('enclosure')) { 0287 $enclosure = array(); 0288 } else { 0289 $enclosure = $this->offsetGet('enclosure'); 0290 } 0291 $enclosure[] = array('url' => $url, 0292 'type' => $type, 0293 'length' => $length); 0294 $this->offsetSet('enclosure', $enclosure); 0295 return $this; 0296 } 0297 }