PageRenderTime 61ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/library/Zend/Feed/Writer/Feed/FeedAbstract.php

https://bitbucket.org/rtsukui/jelly2
PHP | 872 lines | 505 code | 59 blank | 308 comment | 125 complexity | bd3d1ca03a5c73290bf5298b39a43284 MD5 | raw file
Possible License(s): BSD-3-Clause
  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_Writer
  17. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id: FeedAbstract.php 23775 2011-03-01 17:25:24Z ralph $
  20. */
  21. /**
  22. * @see Zend_Date
  23. */
  24. require_once 'Zend/Date.php';
  25. /**
  26. * @see Zend_Date
  27. */
  28. require_once 'Zend/Uri.php';
  29. /**
  30. * @see Zend_Feed_Writer
  31. */
  32. require_once 'Zend/Feed/Writer.php';
  33. /**
  34. * @see Zend_Feed_Writer_Entry
  35. */
  36. require_once 'Zend/Feed/Writer/Entry.php';
  37. /**
  38. * @see Zend_Feed_Writer_Renderer_Feed_Atom
  39. */
  40. require_once 'Zend/Feed/Writer/Renderer/Feed/Atom.php';
  41. /**
  42. * @see Zend_Feed_Writer_Renderer_Feed_Rss
  43. */
  44. require_once 'Zend/Feed/Writer/Renderer/Feed/Rss.php';
  45. require_once 'Zend/Validate/EmailAddress.php';
  46. /**
  47. * @category Zend
  48. * @package Zend_Feed_Writer
  49. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  50. * @license http://framework.zend.com/license/new-bsd New BSD License
  51. */
  52. class Zend_Feed_Writer_Feed_FeedAbstract
  53. {
  54. /**
  55. * Contains all Feed level date to append in feed output
  56. *
  57. * @var array
  58. */
  59. protected $_data = array();
  60. /**
  61. * Holds the value "atom" or "rss" depending on the feed type set when
  62. * when last exported.
  63. *
  64. * @var string
  65. */
  66. protected $_type = null;
  67. /**
  68. * Constructor: Primarily triggers the registration of core extensions and
  69. * loads those appropriate to this data container.
  70. *
  71. * @return void
  72. */
  73. public function __construct()
  74. {
  75. Zend_Feed_Writer::registerCoreExtensions();
  76. $this->_loadExtensions();
  77. }
  78. /**
  79. * Set a single author
  80. *
  81. * @param int $index
  82. * @return string|null
  83. */
  84. public function addAuthor($name, $email = null, $uri = null)
  85. {
  86. $author = array();
  87. if (is_array($name)) {
  88. if (!array_key_exists('name', $name) || empty($name['name']) || !is_string($name['name'])) {
  89. require_once 'Zend/Feed/Exception.php';
  90. throw new Zend_Feed_Exception('Invalid parameter: author array must include a "name" key with a non-empty string value');
  91. }
  92. $author['name'] = $name['name'];
  93. if (isset($name['email'])) {
  94. if (empty($name['email']) || !is_string($name['email'])) {
  95. require_once 'Zend/Feed/Exception.php';
  96. throw new Zend_Feed_Exception('Invalid parameter: "email" array value must be a non-empty string');
  97. }
  98. $author['email'] = $name['email'];
  99. }
  100. if (isset($name['uri'])) {
  101. if (empty($name['uri']) || !is_string($name['uri']) || !Zend_Uri::check($name['uri'])) {
  102. require_once 'Zend/Feed/Exception.php';
  103. throw new Zend_Feed_Exception('Invalid parameter: "uri" array value must be a non-empty string and valid URI/IRI');
  104. }
  105. $author['uri'] = $name['uri'];
  106. }
  107. } else {
  108. if (empty($name['name']) || !is_string($name['name'])) {
  109. require_once 'Zend/Feed/Exception.php';
  110. throw new Zend_Feed_Exception('Invalid parameter: "name" must be a non-empty string value');
  111. }
  112. $author['name'] = $name;
  113. if (isset($email)) {
  114. if (empty($email) || !is_string($email)) {
  115. require_once 'Zend/Feed/Exception.php';
  116. throw new Zend_Feed_Exception('Invalid parameter: "email" value must be a non-empty string');
  117. }
  118. $author['email'] = $email;
  119. }
  120. if (isset($uri)) {
  121. if (empty($uri) || !is_string($uri) || !Zend_Uri::check($uri)) {
  122. require_once 'Zend/Feed/Exception.php';
  123. throw new Zend_Feed_Exception('Invalid parameter: "uri" value must be a non-empty string and valid URI/IRI');
  124. }
  125. $author['uri'] = $uri;
  126. }
  127. }
  128. $this->_data['authors'][] = $author;
  129. }
  130. /**
  131. * Set an array with feed authors
  132. *
  133. * @return array
  134. */
  135. public function addAuthors(array $authors)
  136. {
  137. foreach($authors as $author) {
  138. $this->addAuthor($author);
  139. }
  140. }
  141. /**
  142. * Set the copyright entry
  143. *
  144. * @return string|null
  145. */
  146. public function setCopyright($copyright)
  147. {
  148. if (empty($copyright) || !is_string($copyright)) {
  149. require_once 'Zend/Feed/Exception.php';
  150. throw new Zend_Feed_Exception('Invalid parameter: parameter must be a non-empty string');
  151. }
  152. $this->_data['copyright'] = $copyright;
  153. }
  154. /**
  155. * Set the feed creation date
  156. *
  157. * @param null|integer|Zend_Date
  158. */
  159. public function setDateCreated($date = null)
  160. {
  161. $zdate = null;
  162. if ($date === null) {
  163. $zdate = new Zend_Date;
  164. } elseif (ctype_digit($date) && strlen($date) == 10) {
  165. $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP);
  166. } elseif ($date instanceof Zend_Date) {
  167. $zdate = $date;
  168. } else {
  169. require_once 'Zend/Feed/Exception.php';
  170. throw new Zend_Feed_Exception('Invalid Zend_Date object or UNIX Timestamp passed as parameter');
  171. }
  172. $this->_data['dateCreated'] = $zdate;
  173. }
  174. /**
  175. * Set the feed modification date
  176. *
  177. * @param null|integer|Zend_Date
  178. */
  179. public function setDateModified($date = null)
  180. {
  181. $zdate = null;
  182. if ($date === null) {
  183. $zdate = new Zend_Date;
  184. } elseif (ctype_digit($date) && strlen($date) == 10) {
  185. $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP);
  186. } elseif ($date instanceof Zend_Date) {
  187. $zdate = $date;
  188. } else {
  189. require_once 'Zend/Feed/Exception.php';
  190. throw new Zend_Feed_Exception('Invalid Zend_Date object or UNIX Timestamp passed as parameter');
  191. }
  192. $this->_data['dateModified'] = $zdate;
  193. }
  194. /**
  195. * Set the feed last-build date. Ignored for Atom 1.0.
  196. *
  197. * @param null|integer|Zend_Date
  198. */
  199. public function setLastBuildDate($date = null)
  200. {
  201. $zdate = null;
  202. if ($date === null) {
  203. $zdate = new Zend_Date;
  204. } elseif (ctype_digit($date) && strlen($date) == 10) {
  205. $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP);
  206. } elseif ($date instanceof Zend_Date) {
  207. $zdate = $date;
  208. } else {
  209. require_once 'Zend/Feed/Exception.php';
  210. throw new Zend_Feed_Exception('Invalid Zend_Date object or UNIX Timestamp passed as parameter');
  211. }
  212. $this->_data['lastBuildDate'] = $zdate;
  213. }
  214. /**
  215. * Set the feed description
  216. *
  217. * @return string|null
  218. */
  219. public function setDescription($description)
  220. {
  221. if (empty($description) || !is_string($description)) {
  222. require_once 'Zend/Feed/Exception.php';
  223. throw new Zend_Feed_Exception('Invalid parameter: parameter must be a non-empty string');
  224. }
  225. $this->_data['description'] = $description;
  226. }
  227. /**
  228. * Set the feed generator entry
  229. *
  230. * @return string|null
  231. */
  232. public function setGenerator($name, $version = null, $uri = null)
  233. {
  234. if (is_array($name)) {
  235. $data = $name;
  236. if (empty($data['name']) || !is_string($data['name'])) {
  237. require_once 'Zend/Feed/Exception.php';
  238. throw new Zend_Feed_Exception('Invalid parameter: "name" must be a non-empty string');
  239. }
  240. $generator = array('name' => $data['name']);
  241. if (isset($data['version'])) {
  242. if (empty($data['version']) || !is_string($data['version'])) {
  243. require_once 'Zend/Feed/Exception.php';
  244. throw new Zend_Feed_Exception('Invalid parameter: "version" must be a non-empty string');
  245. }
  246. $generator['version'] = $data['version'];
  247. }
  248. if (isset($data['uri'])) {
  249. if (empty($data['uri']) || !is_string($data['uri']) || !Zend_Uri::check($data['uri'])) {
  250. require_once 'Zend/Feed/Exception.php';
  251. throw new Zend_Feed_Exception('Invalid parameter: "uri" must be a non-empty string and a valid URI/IRI');
  252. }
  253. $generator['uri'] = $data['uri'];
  254. }
  255. } else {
  256. if (empty($name) || !is_string($name)) {
  257. require_once 'Zend/Feed/Exception.php';
  258. throw new Zend_Feed_Exception('Invalid parameter: "name" must be a non-empty string');
  259. }
  260. $generator = array('name' => $name);
  261. if (isset($version)) {
  262. if (empty($version) || !is_string($version)) {
  263. require_once 'Zend/Feed/Exception.php';
  264. throw new Zend_Feed_Exception('Invalid parameter: "version" must be a non-empty string');
  265. }
  266. $generator['version'] = $version;
  267. }
  268. if (isset($uri)) {
  269. if (empty($uri) || !is_string($uri) || !Zend_Uri::check($uri)) {
  270. require_once 'Zend/Feed/Exception.php';
  271. throw new Zend_Feed_Exception('Invalid parameter: "uri" must be a non-empty string and a valid URI/IRI');
  272. }
  273. $generator['uri'] = $uri;
  274. }
  275. }
  276. $this->_data['generator'] = $generator;
  277. }
  278. /**
  279. * Set the feed ID - URI or URN (via PCRE pattern) supported
  280. *
  281. * @param string $id
  282. */
  283. public function setId($id)
  284. {
  285. if ((empty($id) || !is_string($id) || !Zend_Uri::check($id)) &&
  286. !preg_match("#^urn:[a-zA-Z0-9][a-zA-Z0-9\-]{1,31}:([a-zA-Z0-9\(\)\+\,\.\:\=\@\;\$\_\!\*\-]|%[0-9a-fA-F]{2})*#", $id)
  287. && !$this->_validateTagUri($id)) {
  288. require_once 'Zend/Feed/Exception.php';
  289. throw new Zend_Feed_Exception('Invalid parameter: parameter must be a non-empty string and valid URI/IRI');
  290. }
  291. $this->_data['id'] = $id;
  292. }
  293. /**
  294. * Validate a URI using the tag scheme (RFC 4151)
  295. *
  296. * @param string $id
  297. * @return bool
  298. */
  299. protected function _validateTagUri($id)
  300. {
  301. if (preg_match('/^tag:(?<name>.*),(?<date>\d{4}-?\d{0,2}-?\d{0,2}):(?<specific>.*)(.*:)*$/', $id, $matches)) {
  302. $dvalid = false;
  303. $nvalid = false;
  304. $date = $matches['date'];
  305. $d6 = strtotime($date);
  306. if ((strlen($date) == 4) && $date <= date('Y')) {
  307. $dvalid = true;
  308. } elseif ((strlen($date) == 7) && ($d6 < strtotime("now"))) {
  309. $dvalid = true;
  310. } elseif ((strlen($date) == 10) && ($d6 < strtotime("now"))) {
  311. $dvalid = true;
  312. }
  313. $validator = new Zend_Validate_EmailAddress;
  314. if ($validator->isValid($matches['name'])) {
  315. $nvalid = true;
  316. } else {
  317. $nvalid = $validator->isValid('info@' . $matches['name']);
  318. }
  319. return $dvalid && $nvalid;
  320. }
  321. return false;
  322. }
  323. /**
  324. * Set a feed image (URI at minimum). Parameter is a single array with the
  325. * required key 'uri'. When rendering as RSS, the required keys are 'uri',
  326. * 'title' and 'link'. RSS also specifies three optional parameters 'width',
  327. * 'height' and 'description'. Only 'uri' is required and used for Atom rendering.
  328. *
  329. * @param array $data
  330. */
  331. public function setImage(array $data)
  332. {
  333. if (empty($data['uri']) || !is_string($data['uri'])
  334. || !Zend_Uri::check($data['uri'])) {
  335. require_once 'Zend/Feed/Exception.php';
  336. throw new Zend_Feed_Exception('Invalid parameter: parameter \'uri\''
  337. . ' must be a non-empty string and valid URI/IRI');
  338. }
  339. $this->_data['image'] = $data;
  340. }
  341. /**
  342. * Set a feed icon (URI at minimum). Parameter is a single array with the
  343. * required key 'uri'. Only 'uri' is required and used for Atom rendering.
  344. * RSS does not support an Icon tag except via Atom 1.0 as an extension.
  345. *
  346. * @param array $data
  347. */
  348. public function setIcon(array $data)
  349. {
  350. if (empty($data['uri']) || !is_string($data['uri'])
  351. || !Zend_Uri::check($data['uri'])) {
  352. require_once 'Zend/Feed/Exception.php';
  353. throw new Zend_Feed_Exception('Invalid parameter: parameter \'uri\''
  354. . ' must be a non-empty string and valid URI/IRI');
  355. }
  356. $this->_data['icon'] = $data;
  357. }
  358. /**
  359. * Set the feed language
  360. *
  361. * @return string|null
  362. */
  363. public function setLanguage($language)
  364. {
  365. if (empty($language) || !is_string($language)) {
  366. require_once 'Zend/Feed/Exception.php';
  367. throw new Zend_Feed_Exception('Invalid parameter: parameter must be a non-empty string');
  368. }
  369. $this->_data['language'] = $language;
  370. }
  371. /**
  372. * Set a link to the HTML source
  373. *
  374. * @param string $link
  375. */
  376. public function setLink($link)
  377. {
  378. if (empty($link) || !is_string($link) || !Zend_Uri::check($link)) {
  379. require_once 'Zend/Feed/Exception.php';
  380. throw new Zend_Feed_Exception('Invalid parameter: parameter must be a non-empty string and valid URI/IRI');
  381. }
  382. $this->_data['link'] = $link;
  383. }
  384. /**
  385. * Set a link to an XML feed for any feed type/version
  386. *
  387. * @return string|null
  388. */
  389. public function setFeedLink($link, $type)
  390. {
  391. if (empty($link) || !is_string($link) || !Zend_Uri::check($link)) {
  392. require_once 'Zend/Feed/Exception.php';
  393. throw new Zend_Feed_Exception('Invalid parameter: "link"" must be a non-empty string and valid URI/IRI');
  394. }
  395. if (!in_array(strtolower($type), array('rss', 'rdf', 'atom'))) {
  396. require_once 'Zend/Feed/Exception.php';
  397. throw new Zend_Feed_Exception('Invalid parameter: "type"; You must declare the type of feed the link points to, i.e. RSS, RDF or Atom');
  398. }
  399. $this->_data['feedLinks'][strtolower($type)] = $link;
  400. }
  401. /**
  402. * Set the feed title
  403. *
  404. * @return string|null
  405. */
  406. public function setTitle($title)
  407. {
  408. if (empty($title) || !is_string($title)) {
  409. require_once 'Zend/Feed/Exception.php';
  410. throw new Zend_Feed_Exception('Invalid parameter: parameter must be a non-empty string');
  411. }
  412. $this->_data['title'] = $title;
  413. }
  414. /**
  415. * Set the feed character encoding
  416. *
  417. * @param string $encoding
  418. */
  419. public function setEncoding($encoding)
  420. {
  421. if (empty($encoding) || !is_string($encoding)) {
  422. require_once 'Zend/Feed/Exception.php';
  423. throw new Zend_Feed_Exception('Invalid parameter: parameter must be a non-empty string');
  424. }
  425. $this->_data['encoding'] = $encoding;
  426. }
  427. /**
  428. * Set the feed's base URL
  429. *
  430. * @param string $url
  431. */
  432. public function setBaseUrl($url)
  433. {
  434. if (empty($url) || !is_string($url) || !Zend_Uri::check($url)) {
  435. require_once 'Zend/Feed/Exception.php';
  436. throw new Zend_Feed_Exception('Invalid parameter: "url" array value'
  437. . ' must be a non-empty string and valid URI/IRI');
  438. }
  439. $this->_data['baseUrl'] = $url;
  440. }
  441. /**
  442. * Add a Pubsubhubbub hub endpoint URL
  443. *
  444. * @param string $url
  445. */
  446. public function addHub($url)
  447. {
  448. if (empty($url) || !is_string($url) || !Zend_Uri::check($url)) {
  449. require_once 'Zend/Feed/Exception.php';
  450. throw new Zend_Feed_Exception('Invalid parameter: "url" array value'
  451. . ' must be a non-empty string and valid URI/IRI');
  452. }
  453. if (!isset($this->_data['hubs'])) {
  454. $this->_data['hubs'] = array();
  455. }
  456. $this->_data['hubs'][] = $url;
  457. }
  458. /**
  459. * Add Pubsubhubbub hub endpoint URLs
  460. *
  461. * @param array $urls
  462. */
  463. public function addHubs(array $urls)
  464. {
  465. foreach ($urls as $url) {
  466. $this->addHub($url);
  467. }
  468. }
  469. /**
  470. * Add a feed category
  471. *
  472. * @param string $category
  473. */
  474. public function addCategory(array $category)
  475. {
  476. if (!isset($category['term'])) {
  477. require_once 'Zend/Feed/Exception.php';
  478. throw new Zend_Feed_Exception('Each category must be an array and '
  479. . 'contain at least a "term" element containing the machine '
  480. . ' readable category name');
  481. }
  482. if (isset($category['scheme'])) {
  483. if (empty($category['scheme'])
  484. || !is_string($category['scheme'])
  485. || !Zend_Uri::check($category['scheme'])
  486. ) {
  487. require_once 'Zend/Feed/Exception.php';
  488. throw new Zend_Feed_Exception('The Atom scheme or RSS domain of'
  489. . ' a category must be a valid URI');
  490. }
  491. }
  492. if (!isset($this->_data['categories'])) {
  493. $this->_data['categories'] = array();
  494. }
  495. $this->_data['categories'][] = $category;
  496. }
  497. /**
  498. * Set an array of feed categories
  499. *
  500. * @param array $categories
  501. */
  502. public function addCategories(array $categories)
  503. {
  504. foreach ($categories as $category) {
  505. $this->addCategory($category);
  506. }
  507. }
  508. /**
  509. * Get a single author
  510. *
  511. * @param int $index
  512. * @return string|null
  513. */
  514. public function getAuthor($index = 0)
  515. {
  516. if (isset($this->_data['authors'][$index])) {
  517. return $this->_data['authors'][$index];
  518. } else {
  519. return null;
  520. }
  521. }
  522. /**
  523. * Get an array with feed authors
  524. *
  525. * @return array
  526. */
  527. public function getAuthors()
  528. {
  529. if (!array_key_exists('authors', $this->_data)) {
  530. return null;
  531. }
  532. return $this->_data['authors'];
  533. }
  534. /**
  535. * Get the copyright entry
  536. *
  537. * @return string|null
  538. */
  539. public function getCopyright()
  540. {
  541. if (!array_key_exists('copyright', $this->_data)) {
  542. return null;
  543. }
  544. return $this->_data['copyright'];
  545. }
  546. /**
  547. * Get the feed creation date
  548. *
  549. * @return string|null
  550. */
  551. public function getDateCreated()
  552. {
  553. if (!array_key_exists('dateCreated', $this->_data)) {
  554. return null;
  555. }
  556. return $this->_data['dateCreated'];
  557. }
  558. /**
  559. * Get the feed modification date
  560. *
  561. * @return string|null
  562. */
  563. public function getDateModified()
  564. {
  565. if (!array_key_exists('dateModified', $this->_data)) {
  566. return null;
  567. }
  568. return $this->_data['dateModified'];
  569. }
  570. /**
  571. * Get the feed last-build date
  572. *
  573. * @return string|null
  574. */
  575. public function getLastBuildDate()
  576. {
  577. if (!array_key_exists('lastBuildDate', $this->_data)) {
  578. return null;
  579. }
  580. return $this->_data['lastBuildDate'];
  581. }
  582. /**
  583. * Get the feed description
  584. *
  585. * @return string|null
  586. */
  587. public function getDescription()
  588. {
  589. if (!array_key_exists('description', $this->_data)) {
  590. return null;
  591. }
  592. return $this->_data['description'];
  593. }
  594. /**
  595. * Get the feed generator entry
  596. *
  597. * @return string|null
  598. */
  599. public function getGenerator()
  600. {
  601. if (!array_key_exists('generator', $this->_data)) {
  602. return null;
  603. }
  604. return $this->_data['generator'];
  605. }
  606. /**
  607. * Get the feed ID
  608. *
  609. * @return string|null
  610. */
  611. public function getId()
  612. {
  613. if (!array_key_exists('id', $this->_data)) {
  614. return null;
  615. }
  616. return $this->_data['id'];
  617. }
  618. /**
  619. * Get the feed image URI
  620. *
  621. * @return array
  622. */
  623. public function getImage()
  624. {
  625. if (!array_key_exists('image', $this->_data)) {
  626. return null;
  627. }
  628. return $this->_data['image'];
  629. }
  630. /**
  631. * Get the feed icon URI
  632. *
  633. * @return array
  634. */
  635. public function getIcon()
  636. {
  637. if (!array_key_exists('icon', $this->_data)) {
  638. return null;
  639. }
  640. return $this->_data['icon'];
  641. }
  642. /**
  643. * Get the feed language
  644. *
  645. * @return string|null
  646. */
  647. public function getLanguage()
  648. {
  649. if (!array_key_exists('language', $this->_data)) {
  650. return null;
  651. }
  652. return $this->_data['language'];
  653. }
  654. /**
  655. * Get a link to the HTML source
  656. *
  657. * @return string|null
  658. */
  659. public function getLink()
  660. {
  661. if (!array_key_exists('link', $this->_data)) {
  662. return null;
  663. }
  664. return $this->_data['link'];
  665. }
  666. /**
  667. * Get a link to the XML feed
  668. *
  669. * @return string|null
  670. */
  671. public function getFeedLinks()
  672. {
  673. if (!array_key_exists('feedLinks', $this->_data)) {
  674. return null;
  675. }
  676. return $this->_data['feedLinks'];
  677. }
  678. /**
  679. * Get the feed title
  680. *
  681. * @return string|null
  682. */
  683. public function getTitle()
  684. {
  685. if (!array_key_exists('title', $this->_data)) {
  686. return null;
  687. }
  688. return $this->_data['title'];
  689. }
  690. /**
  691. * Get the feed character encoding
  692. *
  693. * @return string|null
  694. */
  695. public function getEncoding()
  696. {
  697. if (!array_key_exists('encoding', $this->_data)) {
  698. return 'UTF-8';
  699. }
  700. return $this->_data['encoding'];
  701. }
  702. /**
  703. * Get the feed's base url
  704. *
  705. * @return string|null
  706. */
  707. public function getBaseUrl()
  708. {
  709. if (!array_key_exists('baseUrl', $this->_data)) {
  710. return null;
  711. }
  712. return $this->_data['baseUrl'];
  713. }
  714. /**
  715. * Get the URLs used as Pubsubhubbub hubs endpoints
  716. *
  717. * @return string|null
  718. */
  719. public function getHubs()
  720. {
  721. if (!array_key_exists('hubs', $this->_data)) {
  722. return null;
  723. }
  724. return $this->_data['hubs'];
  725. }
  726. /**
  727. * Get the feed categories
  728. *
  729. * @return string|null
  730. */
  731. public function getCategories()
  732. {
  733. if (!array_key_exists('categories', $this->_data)) {
  734. return null;
  735. }
  736. return $this->_data['categories'];
  737. }
  738. /**
  739. * Resets the instance and deletes all data
  740. *
  741. * @return void
  742. */
  743. public function reset()
  744. {
  745. $this->_data = array();
  746. }
  747. /**
  748. * Set the current feed type being exported to "rss" or "atom". This allows
  749. * other objects to gracefully choose whether to execute or not, depending
  750. * on their appropriateness for the current type, e.g. renderers.
  751. *
  752. * @param string $type
  753. */
  754. public function setType($type)
  755. {
  756. $this->_type = $type;
  757. }
  758. /**
  759. * Retrieve the current or last feed type exported.
  760. *
  761. * @return string Value will be "rss" or "atom"
  762. */
  763. public function getType()
  764. {
  765. return $this->_type;
  766. }
  767. /**
  768. * Unset a specific data point
  769. *
  770. * @param string $name
  771. */
  772. public function remove($name)
  773. {
  774. if (isset($this->_data[$name])) {
  775. unset($this->_data[$name]);
  776. }
  777. }
  778. /**
  779. * Method overloading: call given method on first extension implementing it
  780. *
  781. * @param string $method
  782. * @param array $args
  783. * @return mixed
  784. * @throws Zend_Feed_Exception if no extensions implements the method
  785. */
  786. public function __call($method, $args)
  787. {
  788. foreach ($this->_extensions as $extension) {
  789. try {
  790. return call_user_func_array(array($extension, $method), $args);
  791. } catch (Zend_Feed_Writer_Exception_InvalidMethodException $e) {
  792. }
  793. }
  794. require_once 'Zend/Feed/Exception.php';
  795. throw new Zend_Feed_Exception('Method: ' . $method
  796. . ' does not exist and could not be located on a registered Extension');
  797. }
  798. /**
  799. * Load extensions from Zend_Feed_Writer
  800. *
  801. * @return void
  802. */
  803. protected function _loadExtensions()
  804. {
  805. $all = Zend_Feed_Writer::getExtensions();
  806. $exts = $all['feed'];
  807. foreach ($exts as $ext) {
  808. $className = Zend_Feed_Writer::getPluginLoader()->getClassName($ext);
  809. $this->_extensions[$ext] = new $className();
  810. $this->_extensions[$ext]->setEncoding($this->getEncoding());
  811. }
  812. }
  813. }