/protected/vendors/Zend/Feed/Reader/Feed/Atom.php

https://github.com/ButuzGOL/Yii-blog-new · PHP · 329 lines · 162 code · 60 blank · 107 comment · 22 complexity · ece98a1fd96f8d34dc28f4dc7d6cbd63 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_Reader
  17. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id: Atom.php 16963 2009-07-22 14:39:31Z padraic $
  20. */
  21. /**
  22. * @see Zend_Feed_Reader_FeedAbstract
  23. */
  24. require_once 'Zend/Feed/Reader/FeedAbstract.php';
  25. /**
  26. * @see Zend_Feed_Reader_Extension_Atom_Feed
  27. */
  28. require_once 'Zend/Feed/Reader/Extension/Atom/Feed.php';
  29. /**
  30. * @category Zend
  31. * @package Zend_Feed_Reader
  32. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. */
  35. class Zend_Feed_Reader_Feed_Atom extends Zend_Feed_Reader_FeedAbstract
  36. {
  37. /**
  38. * Constructor
  39. *
  40. * @param Zend_Feed_Abstract $feed
  41. * @param string $type
  42. * @param string $xpath
  43. */
  44. public function __construct(DomDocument $dom, $type = null)
  45. {
  46. parent::__construct($dom, $type);
  47. $atomClass = Zend_Feed_Reader::getPluginLoader()->getClassName('Atom_Feed');
  48. $this->_extensions['Atom_Feed'] = new $atomClass($dom, $this->_data['type'], $this->_xpath);
  49. foreach ($this->_extensions as $extension) {
  50. $extension->setXpathPrefix('/atom:feed');
  51. }
  52. }
  53. /**
  54. * Get a single author
  55. *
  56. * @param int $index
  57. * @return string|null
  58. */
  59. public function getAuthor($index = 0)
  60. {
  61. $authors = $this->getAuthors();
  62. if (isset($authors[$index])) {
  63. return $authors[$index];
  64. }
  65. return null;
  66. }
  67. /**
  68. * Get an array with feed authors
  69. *
  70. * @return array
  71. */
  72. public function getAuthors()
  73. {
  74. if (array_key_exists('authors', $this->_data)) {
  75. return $this->_data['authors'];
  76. }
  77. $people = $this->getExtension('Atom')->getAuthors();
  78. $this->_data['authors'] = $people;
  79. return $this->_data['authors'];
  80. }
  81. /**
  82. * Get the copyright entry
  83. *
  84. * @return string|null
  85. */
  86. public function getCopyright()
  87. {
  88. if (array_key_exists('copyright', $this->_data)) {
  89. return $this->_data['copyright'];
  90. }
  91. $copyright = $this->getExtension('Atom')->getCopyright();
  92. if (!$copyright) {
  93. $copyright = null;
  94. }
  95. $this->_data['copyright'] = $copyright;
  96. return $this->_data['copyright'];
  97. }
  98. /**
  99. * Get the feed creation date
  100. *
  101. * @return string|null
  102. */
  103. public function getDateCreated()
  104. {
  105. if (array_key_exists('datecreated', $this->_data)) {
  106. return $this->_data['datecreated'];
  107. }
  108. $dateCreated = $this->getExtension('Atom')->getDateCreated();
  109. if (!$dateCreated) {
  110. $dateCreated = null;
  111. }
  112. $this->_data['datecreated'] = $dateCreated;
  113. return $this->_data['datecreated'];
  114. }
  115. /**
  116. * Get the feed modification date
  117. *
  118. * @return string|null
  119. */
  120. public function getDateModified()
  121. {
  122. if (array_key_exists('datemodified', $this->_data)) {
  123. return $this->_data['datemodified'];
  124. }
  125. $dateModified = $this->getExtension('Atom')->getDateModified();
  126. if (!$dateModified) {
  127. $dateModified = null;
  128. }
  129. $this->_data['datemodified'] = $dateModified;
  130. return $this->_data['datemodified'];
  131. }
  132. /**
  133. * Get the feed description
  134. *
  135. * @return string|null
  136. */
  137. public function getDescription()
  138. {
  139. if (array_key_exists('description', $this->_data)) {
  140. return $this->_data['description'];
  141. }
  142. $description = $this->getExtension('Atom')->getDescription();
  143. if (!$description) {
  144. $description = null;
  145. }
  146. $this->_data['description'] = $description;
  147. return $this->_data['description'];
  148. }
  149. /**
  150. * Get the feed generator entry
  151. *
  152. * @return string|null
  153. */
  154. public function getGenerator()
  155. {
  156. if (array_key_exists('generator', $this->_data)) {
  157. return $this->_data['generator'];
  158. }
  159. $generator = $this->getExtension('Atom')->getGenerator();
  160. $this->_data['generator'] = $generator;
  161. return $this->_data['generator'];
  162. }
  163. /**
  164. * Get the feed ID
  165. *
  166. * @return string|null
  167. */
  168. public function getId()
  169. {
  170. if (array_key_exists('id', $this->_data)) {
  171. return $this->_data['id'];
  172. }
  173. $id = $this->getExtension('Atom')->getId();
  174. $this->_data['id'] = $id;
  175. return $this->_data['id'];
  176. }
  177. /**
  178. * Get the feed language
  179. *
  180. * @return string|null
  181. */
  182. public function getLanguage()
  183. {
  184. if (array_key_exists('language', $this->_data)) {
  185. return $this->_data['language'];
  186. }
  187. $language = $this->getExtension('Atom')->getLanguage();
  188. if (!$language) {
  189. $language = $this->_xpath->evaluate('string(//@xml:lang[1])');
  190. }
  191. if (!$language) {
  192. $language = null;
  193. }
  194. $this->_data['language'] = $language;
  195. return $this->_data['language'];
  196. }
  197. /**
  198. * Get a link to the source website
  199. *
  200. * @return string|null
  201. */
  202. public function getLink()
  203. {
  204. if (array_key_exists('link', $this->_data)) {
  205. return $this->_data['link'];
  206. }
  207. $link = $this->getExtension('Atom')->getLink();
  208. $this->_data['link'] = $link;
  209. return $this->_data['link'];
  210. }
  211. /**
  212. * Get a link to the feed's XML Url
  213. *
  214. * @return string|null
  215. */
  216. public function getFeedLink()
  217. {
  218. if (array_key_exists('feedlink', $this->_data)) {
  219. return $this->_data['feedlink'];
  220. }
  221. $link = $this->getExtension('Atom')->getFeedLink();
  222. $this->_data['feedlink'] = $link;
  223. return $this->_data['feedlink'];
  224. }
  225. /**
  226. * Get the feed title
  227. *
  228. * @return string|null
  229. */
  230. public function getTitle()
  231. {
  232. if (array_key_exists('title', $this->_data)) {
  233. return $this->_data['title'];
  234. }
  235. $title = $this->getExtension('Atom')->getTitle();
  236. $this->_data['title'] = $title;
  237. return $this->_data['title'];
  238. }
  239. /**
  240. * Read all entries to the internal entries array
  241. *
  242. */
  243. protected function _indexEntries()
  244. {
  245. if ($this->getType() == Zend_Feed_Reader::TYPE_ATOM_10 ||
  246. $this->getType() == Zend_Feed_Reader::TYPE_ATOM_03) {
  247. $entries = array();
  248. $entries = $this->_xpath->evaluate('//atom:entry');
  249. foreach($entries as $index=>$entry) {
  250. $this->_entries[$index] = $entry;
  251. }
  252. }
  253. }
  254. /**
  255. * Register the default namespaces for the current feed format
  256. *
  257. */
  258. protected function _registerNamespaces()
  259. {
  260. switch ($this->_data['type']) {
  261. case Zend_Feed_Reader::TYPE_ATOM_03:
  262. $this->_xpath->registerNamespace('atom', Zend_Feed_Reader::NAMESPACE_ATOM_03);
  263. break;
  264. case Zend_Feed_Reader::TYPE_ATOM_10:
  265. default:
  266. $this->_xpath->registerNamespace('atom', Zend_Feed_Reader::NAMESPACE_ATOM_10);
  267. }
  268. }
  269. }