PageRenderTime 52ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://rewardvn.googlecode.com/
PHP | 841 lines | 488 code | 57 blank | 296 comment | 121 complexity | add7593fa5db9738f7ca082386cad2e6 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_Writer
  17. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $
  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-2010 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 (is_null($date)) {
  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 (is_null($date)) {
  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 (is_null($date)) {
  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 the feed language
  343. *
  344. * @return string|null
  345. */
  346. public function setLanguage($language)
  347. {
  348. if (empty($language) || !is_string($language)) {
  349. require_once 'Zend/Feed/Exception.php';
  350. throw new Zend_Feed_Exception('Invalid parameter: parameter must be a non-empty string');
  351. }
  352. $this->_data['language'] = $language;
  353. }
  354. /**
  355. * Set a link to the HTML source
  356. *
  357. * @param string $link
  358. */
  359. public function setLink($link)
  360. {
  361. if (empty($link) || !is_string($link) || !Zend_Uri::check($link)) {
  362. require_once 'Zend/Feed/Exception.php';
  363. throw new Zend_Feed_Exception('Invalid parameter: parameter must be a non-empty string and valid URI/IRI');
  364. }
  365. $this->_data['link'] = $link;
  366. }
  367. /**
  368. * Set a link to an XML feed for any feed type/version
  369. *
  370. * @return string|null
  371. */
  372. public function setFeedLink($link, $type)
  373. {
  374. if (empty($link) || !is_string($link) || !Zend_Uri::check($link)) {
  375. require_once 'Zend/Feed/Exception.php';
  376. throw new Zend_Feed_Exception('Invalid parameter: "link"" must be a non-empty string and valid URI/IRI');
  377. }
  378. if (!in_array(strtolower($type), array('rss', 'rdf', 'atom'))) {
  379. require_once 'Zend/Feed/Exception.php';
  380. 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');
  381. }
  382. $this->_data['feedLinks'][strtolower($type)] = $link;
  383. }
  384. /**
  385. * Set the feed title
  386. *
  387. * @return string|null
  388. */
  389. public function setTitle($title)
  390. {
  391. if (empty($title) || !is_string($title)) {
  392. require_once 'Zend/Feed/Exception.php';
  393. throw new Zend_Feed_Exception('Invalid parameter: parameter must be a non-empty string');
  394. }
  395. $this->_data['title'] = $title;
  396. }
  397. /**
  398. * Set the feed character encoding
  399. *
  400. * @param string $encoding
  401. */
  402. public function setEncoding($encoding)
  403. {
  404. if (empty($encoding) || !is_string($encoding)) {
  405. require_once 'Zend/Feed/Exception.php';
  406. throw new Zend_Feed_Exception('Invalid parameter: parameter must be a non-empty string');
  407. }
  408. $this->_data['encoding'] = $encoding;
  409. }
  410. /**
  411. * Set the feed's base URL
  412. *
  413. * @param string $url
  414. */
  415. public function setBaseUrl($url)
  416. {
  417. if (empty($url) || !is_string($url) || !Zend_Uri::check($url)) {
  418. require_once 'Zend/Feed/Exception.php';
  419. throw new Zend_Feed_Exception('Invalid parameter: "url" array value'
  420. . ' must be a non-empty string and valid URI/IRI');
  421. }
  422. $this->_data['baseUrl'] = $url;
  423. }
  424. /**
  425. * Add a Pubsubhubbub hub endpoint URL
  426. *
  427. * @param string $url
  428. */
  429. public function addHub($url)
  430. {
  431. if (empty($url) || !is_string($url) || !Zend_Uri::check($url)) {
  432. require_once 'Zend/Feed/Exception.php';
  433. throw new Zend_Feed_Exception('Invalid parameter: "url" array value'
  434. . ' must be a non-empty string and valid URI/IRI');
  435. }
  436. if (!isset($this->_data['hubs'])) {
  437. $this->_data['hubs'] = array();
  438. }
  439. $this->_data['hubs'][] = $url;
  440. }
  441. /**
  442. * Add Pubsubhubbub hub endpoint URLs
  443. *
  444. * @param array $urls
  445. */
  446. public function addHubs(array $urls)
  447. {
  448. foreach ($urls as $url) {
  449. $this->addHub($url);
  450. }
  451. }
  452. /**
  453. * Add a feed category
  454. *
  455. * @param string $category
  456. */
  457. public function addCategory(array $category)
  458. {
  459. if (!isset($category['term'])) {
  460. require_once 'Zend/Feed/Exception.php';
  461. throw new Zend_Feed_Exception('Each category must be an array and '
  462. . 'contain at least a "term" element containing the machine '
  463. . ' readable category name');
  464. }
  465. if (isset($category['scheme'])) {
  466. if (empty($category['scheme'])
  467. || !is_string($category['scheme'])
  468. || !Zend_Uri::check($category['scheme'])
  469. ) {
  470. require_once 'Zend/Feed/Exception.php';
  471. throw new Zend_Feed_Exception('The Atom scheme or RSS domain of'
  472. . ' a category must be a valid URI');
  473. }
  474. }
  475. if (!isset($this->_data['categories'])) {
  476. $this->_data['categories'] = array();
  477. }
  478. $this->_data['categories'][] = $category;
  479. }
  480. /**
  481. * Set an array of feed categories
  482. *
  483. * @param array $categories
  484. */
  485. public function addCategories(array $categories)
  486. {
  487. foreach ($categories as $category) {
  488. $this->addCategory($category);
  489. }
  490. }
  491. /**
  492. * Get a single author
  493. *
  494. * @param int $index
  495. * @return string|null
  496. */
  497. public function getAuthor($index = 0)
  498. {
  499. if (isset($this->_data['authors'][$index])) {
  500. return $this->_data['authors'][$index];
  501. } else {
  502. return null;
  503. }
  504. }
  505. /**
  506. * Get an array with feed authors
  507. *
  508. * @return array
  509. */
  510. public function getAuthors()
  511. {
  512. if (!array_key_exists('authors', $this->_data)) {
  513. return null;
  514. }
  515. return $this->_data['authors'];
  516. }
  517. /**
  518. * Get the copyright entry
  519. *
  520. * @return string|null
  521. */
  522. public function getCopyright()
  523. {
  524. if (!array_key_exists('copyright', $this->_data)) {
  525. return null;
  526. }
  527. return $this->_data['copyright'];
  528. }
  529. /**
  530. * Get the feed creation date
  531. *
  532. * @return string|null
  533. */
  534. public function getDateCreated()
  535. {
  536. if (!array_key_exists('dateCreated', $this->_data)) {
  537. return null;
  538. }
  539. return $this->_data['dateCreated'];
  540. }
  541. /**
  542. * Get the feed modification date
  543. *
  544. * @return string|null
  545. */
  546. public function getDateModified()
  547. {
  548. if (!array_key_exists('dateModified', $this->_data)) {
  549. return null;
  550. }
  551. return $this->_data['dateModified'];
  552. }
  553. /**
  554. * Get the feed last-build date
  555. *
  556. * @return string|null
  557. */
  558. public function getLastBuildDate()
  559. {
  560. if (!array_key_exists('lastBuildDate', $this->_data)) {
  561. return null;
  562. }
  563. return $this->_data['lastBuildDate'];
  564. }
  565. /**
  566. * Get the feed description
  567. *
  568. * @return string|null
  569. */
  570. public function getDescription()
  571. {
  572. if (!array_key_exists('description', $this->_data)) {
  573. return null;
  574. }
  575. return $this->_data['description'];
  576. }
  577. /**
  578. * Get the feed generator entry
  579. *
  580. * @return string|null
  581. */
  582. public function getGenerator()
  583. {
  584. if (!array_key_exists('generator', $this->_data)) {
  585. return null;
  586. }
  587. return $this->_data['generator'];
  588. }
  589. /**
  590. * Get the feed ID
  591. *
  592. * @return string|null
  593. */
  594. public function getId()
  595. {
  596. if (!array_key_exists('id', $this->_data)) {
  597. return null;
  598. }
  599. return $this->_data['id'];
  600. }
  601. /**
  602. * Get the feed image URI
  603. *
  604. * @return array
  605. */
  606. public function getImage()
  607. {
  608. if (!array_key_exists('image', $this->_data)) {
  609. return null;
  610. }
  611. return $this->_data['image'];
  612. }
  613. /**
  614. * Get the feed language
  615. *
  616. * @return string|null
  617. */
  618. public function getLanguage()
  619. {
  620. if (!array_key_exists('language', $this->_data)) {
  621. return null;
  622. }
  623. return $this->_data['language'];
  624. }
  625. /**
  626. * Get a link to the HTML source
  627. *
  628. * @return string|null
  629. */
  630. public function getLink()
  631. {
  632. if (!array_key_exists('link', $this->_data)) {
  633. return null;
  634. }
  635. return $this->_data['link'];
  636. }
  637. /**
  638. * Get a link to the XML feed
  639. *
  640. * @return string|null
  641. */
  642. public function getFeedLinks()
  643. {
  644. if (!array_key_exists('feedLinks', $this->_data)) {
  645. return null;
  646. }
  647. return $this->_data['feedLinks'];
  648. }
  649. /**
  650. * Get the feed title
  651. *
  652. * @return string|null
  653. */
  654. public function getTitle()
  655. {
  656. if (!array_key_exists('title', $this->_data)) {
  657. return null;
  658. }
  659. return $this->_data['title'];
  660. }
  661. /**
  662. * Get the feed character encoding
  663. *
  664. * @return string|null
  665. */
  666. public function getEncoding()
  667. {
  668. if (!array_key_exists('encoding', $this->_data)) {
  669. return 'UTF-8';
  670. }
  671. return $this->_data['encoding'];
  672. }
  673. /**
  674. * Get the feed's base url
  675. *
  676. * @return string|null
  677. */
  678. public function getBaseUrl()
  679. {
  680. if (!array_key_exists('baseUrl', $this->_data)) {
  681. return null;
  682. }
  683. return $this->_data['baseUrl'];
  684. }
  685. /**
  686. * Get the URLs used as Pubsubhubbub hubs endpoints
  687. *
  688. * @return string|null
  689. */
  690. public function getHubs()
  691. {
  692. if (!array_key_exists('hubs', $this->_data)) {
  693. return null;
  694. }
  695. return $this->_data['hubs'];
  696. }
  697. /**
  698. * Get the feed categories
  699. *
  700. * @return string|null
  701. */
  702. public function getCategories()
  703. {
  704. if (!array_key_exists('categories', $this->_data)) {
  705. return null;
  706. }
  707. return $this->_data['categories'];
  708. }
  709. /**
  710. * Resets the instance and deletes all data
  711. *
  712. * @return void
  713. */
  714. public function reset()
  715. {
  716. $this->_data = array();
  717. }
  718. /**
  719. * Set the current feed type being exported to "rss" or "atom". This allows
  720. * other objects to gracefully choose whether to execute or not, depending
  721. * on their appropriateness for the current type, e.g. renderers.
  722. *
  723. * @param string $type
  724. */
  725. public function setType($type)
  726. {
  727. $this->_type = $type;
  728. }
  729. /**
  730. * Retrieve the current or last feed type exported.
  731. *
  732. * @return string Value will be "rss" or "atom"
  733. */
  734. public function getType()
  735. {
  736. return $this->_type;
  737. }
  738. /**
  739. * Unset a specific data point
  740. *
  741. * @param string $name
  742. */
  743. public function remove($name)
  744. {
  745. if (isset($this->_data[$name])) {
  746. unset($this->_data[$name]);
  747. }
  748. }
  749. /**
  750. * Method overloading: call given method on first extension implementing it
  751. *
  752. * @param string $method
  753. * @param array $args
  754. * @return mixed
  755. * @throws Zend_Feed_Exception if no extensions implements the method
  756. */
  757. public function __call($method, $args)
  758. {
  759. foreach ($this->_extensions as $extension) {
  760. try {
  761. return call_user_func_array(array($extension, $method), $args);
  762. } catch (Zend_Feed_Writer_Exception_InvalidMethodException $e) {
  763. }
  764. }
  765. require_once 'Zend/Feed/Exception.php';
  766. throw new Zend_Feed_Exception('Method: ' . $method
  767. . ' does not exist and could not be located on a registered Extension');
  768. }
  769. /**
  770. * Load extensions from Zend_Feed_Writer
  771. *
  772. * @return void
  773. */
  774. protected function _loadExtensions()
  775. {
  776. $all = Zend_Feed_Writer::getExtensions();
  777. $exts = $all['feed'];
  778. foreach ($exts as $ext) {
  779. $className = Zend_Feed_Writer::getPluginLoader()->getClassName($ext);
  780. $this->_extensions[$ext] = new $className();
  781. $this->_extensions[$ext]->setEncoding($this->getEncoding());
  782. }
  783. }
  784. }