PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/tine20/library/Zend/Feed/Builder/Header.php

https://gitlab.com/rsilveira1987/Expresso
PHP | 423 lines | 174 code | 27 blank | 222 comment | 14 complexity | 80a7632bbcb83a9626bd4a4a87c32c5a MD5 | raw file
  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
  17. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id: Header.php 10020 2009-08-18 14:34:09Z j.fischer@metaways.de $
  20. */
  21. /**
  22. * @see Zend_Feed_Builder_Header_Itunes
  23. */
  24. require_once 'Zend/Feed/Builder/Header/Itunes.php';
  25. /**
  26. * @see Zend_Uri
  27. */
  28. require_once 'Zend/Uri.php';
  29. /**
  30. * Header of a custom build feed
  31. *
  32. * Classes implementing the Zend_Feed_Builder_Interface interface
  33. * uses this class to describe the header of a feed
  34. *
  35. * @category Zend
  36. * @package Zend_Feed
  37. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  38. * @license http://framework.zend.com/license/new-bsd New BSD License
  39. */
  40. class Zend_Feed_Builder_Header extends ArrayObject
  41. {
  42. /**
  43. * Constructor
  44. *
  45. * @param string $title title of the feed
  46. * @param string $link canonical url of the feed
  47. * @param string $charset charset of the textual data
  48. * @return void
  49. */
  50. public function __construct($title, $link, $charset = 'utf-8')
  51. {
  52. $this->offsetSet('title', $title);
  53. $this->offsetSet('link', $link);
  54. $this->offsetSet('charset', $charset);
  55. $this->setLastUpdate(time())
  56. ->setGenerator('Zend_Feed');
  57. }
  58. /**
  59. * Read only properties accessor
  60. *
  61. * @param string $name property to read
  62. * @return mixed
  63. */
  64. public function __get($name)
  65. {
  66. if (!$this->offsetExists($name)) {
  67. return NULL;
  68. }
  69. return $this->offsetGet($name);
  70. }
  71. /**
  72. * Write properties accessor
  73. *
  74. * @param string $name name of the property to set
  75. * @param mixed $value value to set
  76. * @return void
  77. */
  78. public function __set($name, $value)
  79. {
  80. $this->offsetSet($name, $value);
  81. }
  82. /**
  83. * Isset accessor
  84. *
  85. * @param string $key
  86. * @return boolean
  87. */
  88. public function __isset($key)
  89. {
  90. return $this->offsetExists($key);
  91. }
  92. /**
  93. * Unset accessor
  94. *
  95. * @param string $key
  96. * @return void
  97. */
  98. public function __unset($key)
  99. {
  100. if ($this->offsetExists($key)) {
  101. $this->offsetUnset($key);
  102. }
  103. }
  104. /**
  105. * Timestamp of the update date
  106. *
  107. * @param int $lastUpdate
  108. * @return Zend_Feed_Builder_Header
  109. */
  110. public function setLastUpdate($lastUpdate)
  111. {
  112. $this->offsetSet('lastUpdate', $lastUpdate);
  113. return $this;
  114. }
  115. /**
  116. * Timestamp of the publication date
  117. *
  118. * @param int $published
  119. * @return Zend_Feed_Builder_Header
  120. */
  121. public function setPublishedDate($published)
  122. {
  123. $this->offsetSet('published', $published);
  124. return $this;
  125. }
  126. /**
  127. * Short description of the feed
  128. *
  129. * @param string $description
  130. * @return Zend_Feed_Builder_Header
  131. */
  132. public function setDescription($description)
  133. {
  134. $this->offsetSet('description', $description);
  135. return $this;
  136. }
  137. /**
  138. * Sets the author of the feed
  139. *
  140. * @param string $author
  141. * @return Zend_Feed_Builder_Header
  142. */
  143. public function setAuthor($author)
  144. {
  145. $this->offsetSet('author', $author);
  146. return $this;
  147. }
  148. /**
  149. * Sets the author's email
  150. *
  151. * @param string $email
  152. * @return Zend_Feed_Builder_Header
  153. * @throws Zend_Feed_Builder_Exception
  154. */
  155. public function setEmail($email)
  156. {
  157. /**
  158. * @see Zend_Validate_EmailAddress
  159. */
  160. require_once 'Zend/Validate/EmailAddress.php';
  161. $validate = new Zend_Validate_EmailAddress();
  162. if (!$validate->isValid($email)) {
  163. /**
  164. * @see Zend_Feed_Builder_Exception
  165. */
  166. require_once 'Zend/Feed/Builder/Exception.php';
  167. throw new Zend_Feed_Builder_Exception("you have to set a valid email address into the email property");
  168. }
  169. $this->offsetSet('email', $email);
  170. return $this;
  171. }
  172. /**
  173. * Sets the copyright notice
  174. *
  175. * @param string $copyright
  176. * @return Zend_Feed_Builder_Header
  177. */
  178. public function setCopyright($copyright)
  179. {
  180. $this->offsetSet('copyright', $copyright);
  181. return $this;
  182. }
  183. /**
  184. * Sets the image of the feed
  185. *
  186. * @param string $image
  187. * @return Zend_Feed_Builder_Header
  188. */
  189. public function setImage($image)
  190. {
  191. $this->offsetSet('image', $image);
  192. return $this;
  193. }
  194. /**
  195. * Sets the generator of the feed
  196. *
  197. * @param string $generator
  198. * @return Zend_Feed_Builder_Header
  199. */
  200. public function setGenerator($generator)
  201. {
  202. $this->offsetSet('generator', $generator);
  203. return $this;
  204. }
  205. /**
  206. * Sets the language of the feed
  207. *
  208. * @param string $language
  209. * @return Zend_Feed_Builder_Header
  210. */
  211. public function setLanguage($language)
  212. {
  213. $this->offsetSet('language', $language);
  214. return $this;
  215. }
  216. /**
  217. * Email address for person responsible for technical issues
  218. * Ignored if atom is used
  219. *
  220. * @param string $webmaster
  221. * @return Zend_Feed_Builder_Header
  222. * @throws Zend_Feed_Builder_Exception
  223. */
  224. public function setWebmaster($webmaster)
  225. {
  226. /**
  227. * @see Zend_Validate_EmailAddress
  228. */
  229. require_once 'Zend/Validate/EmailAddress.php';
  230. $validate = new Zend_Validate_EmailAddress();
  231. if (!$validate->isValid($webmaster)) {
  232. /**
  233. * @see Zend_Feed_Builder_Exception
  234. */
  235. require_once 'Zend/Feed/Builder/Exception.php';
  236. throw new Zend_Feed_Builder_Exception("you have to set a valid email address into the webmaster property");
  237. }
  238. $this->offsetSet('webmaster', $webmaster);
  239. return $this;
  240. }
  241. /**
  242. * How long in minutes a feed can be cached before refreshing
  243. * Ignored if atom is used
  244. *
  245. * @param int $ttl
  246. * @return Zend_Feed_Builder_Header
  247. * @throws Zend_Feed_Builder_Exception
  248. */
  249. public function setTtl($ttl)
  250. {
  251. /**
  252. * @see Zend_Validate_Int
  253. */
  254. require_once 'Zend/Validate/Int.php';
  255. $validate = new Zend_Validate_Int();
  256. if (!$validate->isValid($ttl)) {
  257. /**
  258. * @see Zend_Feed_Builder_Exception
  259. */
  260. require_once 'Zend/Feed/Builder/Exception.php';
  261. throw new Zend_Feed_Builder_Exception("you have to set an integer value to the ttl property");
  262. }
  263. $this->offsetSet('ttl', $ttl);
  264. return $this;
  265. }
  266. /**
  267. * PICS rating for the feed
  268. * Ignored if atom is used
  269. *
  270. * @param string $rating
  271. * @return Zend_Feed_Builder_Header
  272. */
  273. public function setRating($rating)
  274. {
  275. $this->offsetSet('rating', $rating);
  276. return $this;
  277. }
  278. /**
  279. * Cloud to be notified of updates of the feed
  280. * Ignored if atom is used
  281. *
  282. * @param string|Zend_Uri_Http $uri
  283. * @param string $procedure procedure to call, e.g. myCloud.rssPleaseNotify
  284. * @param string $protocol protocol to use, e.g. soap or xml-rpc
  285. * @return Zend_Feed_Builder_Header
  286. * @throws Zend_Feed_Builder_Exception
  287. */
  288. public function setCloud($uri, $procedure, $protocol)
  289. {
  290. if (is_string($uri) && Zend_Uri_Http::check($uri)) {
  291. $uri = Zend_Uri::factory($uri);
  292. }
  293. if (!$uri instanceof Zend_Uri_Http) {
  294. /**
  295. * @see Zend_Feed_Builder_Exception
  296. */
  297. require_once 'Zend/Feed/Builder/Exception.php';
  298. throw new Zend_Feed_Builder_Exception('Passed parameter is not a valid HTTP URI');
  299. }
  300. if (!$uri->getPort()) {
  301. $uri->setPort(80);
  302. }
  303. $this->offsetSet('cloud', array('uri' => $uri,
  304. 'procedure' => $procedure,
  305. 'protocol' => $protocol));
  306. return $this;
  307. }
  308. /**
  309. * A text input box that can be displayed with the feed
  310. * Ignored if atom is used
  311. *
  312. * @param string $title the label of the Submit button in the text input area
  313. * @param string $description explains the text input area
  314. * @param string $name the name of the text object in the text input area
  315. * @param string $link the URL of the CGI script that processes text input requests
  316. * @return Zend_Feed_Builder_Header
  317. */
  318. public function setTextInput($title, $description, $name, $link)
  319. {
  320. $this->offsetSet('textInput', array('title' => $title,
  321. 'description' => $description,
  322. 'name' => $name,
  323. 'link' => $link));
  324. return $this;
  325. }
  326. /**
  327. * Hint telling aggregators which hours they can skip
  328. * Ignored if atom is used
  329. *
  330. * @param array $hours list of hours in 24 format
  331. * @return Zend_Feed_Builder_Header
  332. * @throws Zend_Feed_Builder_Exception
  333. */
  334. public function setSkipHours(array $hours)
  335. {
  336. if (count($hours) > 24) {
  337. /**
  338. * @see Zend_Feed_Builder_Exception
  339. */
  340. require_once 'Zend/Feed/Builder/Exception.php';
  341. throw new Zend_Feed_Builder_Exception("you can not have more than 24 rows in the skipHours property");
  342. }
  343. foreach ($hours as $hour) {
  344. if ($hour < 0 || $hour > 23) {
  345. /**
  346. * @see Zend_Feed_Builder_Exception
  347. */
  348. require_once 'Zend/Feed/Builder/Exception.php';
  349. throw new Zend_Feed_Builder_Exception("$hour has te be between 0 and 23");
  350. }
  351. }
  352. $this->offsetSet('skipHours', $hours);
  353. return $this;
  354. }
  355. /**
  356. * Hint telling aggregators which days they can skip
  357. * Ignored if atom is used
  358. *
  359. * @param array $days list of days to skip, e.g. Monday
  360. * @return Zend_Feed_Builder_Header
  361. * @throws Zend_Feed_Builder_Exception
  362. */
  363. public function setSkipDays(array $days)
  364. {
  365. if (count($days) > 7) {
  366. /**
  367. * @see Zend_Feed_Builder_Exception
  368. */
  369. require_once 'Zend/Feed/Builder/Exception.php';
  370. throw new Zend_Feed_Builder_Exception("you can not have more than 7 days in the skipDays property");
  371. }
  372. $valid = array('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday');
  373. foreach ($days as $day) {
  374. if (!in_array(strtolower($day), $valid)) {
  375. /**
  376. * @see Zend_Feed_Builder_Exception
  377. */
  378. require_once 'Zend/Feed/Builder/Exception.php';
  379. throw new Zend_Feed_Builder_Exception("$day is not a valid day");
  380. }
  381. }
  382. $this->offsetSet('skipDays', $days);
  383. return $this;
  384. }
  385. /**
  386. * Sets the iTunes rss extension
  387. *
  388. * @param Zend_Feed_Builder_Header_Itunes $itunes
  389. * @return Zend_Feed_Builder_Header
  390. */
  391. public function setITunes(Zend_Feed_Builder_Header_Itunes $itunes)
  392. {
  393. $this->offsetSet('itunes', $itunes);
  394. return $this;
  395. }
  396. }