Atom.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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-2009 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /**
  22. * @see Zend_Feed_Reader
  23. */
  24. require_once 'Zend/Feed/Reader.php';
  25. /**
  26. * @see Zend_Feed_Reader_EntryInterface
  27. */
  28. require_once 'Zend/Feed/Reader/EntryInterface.php';
  29. /**
  30. * @see Zend_Feed_Reader_EntryAbstract
  31. */
  32. require_once 'Zend/Feed/Reader/EntryAbstract.php';
  33. /**
  34. * @see Zend_Feed_Reader_Extension_Atom_Entry
  35. */
  36. require_once 'Zend/Feed/Reader/Extension/Atom/Entry.php';
  37. /**
  38. * @category Zend
  39. * @package Zend_Feed_Reader
  40. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  41. * @license http://framework.zend.com/license/new-bsd New BSD License
  42. */
  43. class Zend_Feed_Reader_Entry_Atom extends Zend_Feed_Reader_EntryAbstract implements Zend_Feed_Reader_EntryInterface
  44. {
  45. /**
  46. * XPath query
  47. *
  48. * @var string
  49. */
  50. protected $_xpathQuery = '';
  51. /**
  52. * Constructor
  53. *
  54. * @param DOMElement $entry
  55. * @param int $entryKey
  56. * @param string $type
  57. * @return void
  58. */
  59. public function __construct(DOMElement $entry, $entryKey, $type = null)
  60. {
  61. parent::__construct($entry, $entryKey, $type);
  62. // Everyone by now should know XPath indices start from 1 not 0
  63. $this->_xpathQuery = '//atom:entry[' . ($this->_entryKey + 1) . ']';
  64. $atomClass = Zend_Feed_Reader::getPluginLoader()->getClassName('Atom_Entry');
  65. $this->_extensions['Atom_Entry'] = new $atomClass($entry, $entryKey, $type);
  66. $threadClass = Zend_Feed_Reader::getPluginLoader()->getClassName('Thread_Entry');
  67. $this->_extensions['Thread_Entry'] = new $threadClass($entry, $entryKey, $type);
  68. }
  69. /**
  70. * Get the specified author
  71. *
  72. * @param int $index
  73. * @return string|null
  74. */
  75. public function getAuthor($index = 0)
  76. {
  77. $authors = $this->getAuthors();
  78. if (isset($authors[$index])) {
  79. return $authors[$index];
  80. }
  81. return null;
  82. }
  83. /**
  84. * Get an array with feed authors
  85. *
  86. * @return array
  87. */
  88. public function getAuthors()
  89. {
  90. if (array_key_exists('authors', $this->_data)) {
  91. return $this->_data['authors'];
  92. }
  93. $people = $this->getExtension('Atom')->getAuthors();
  94. $this->_data['authors'] = $people;
  95. return $this->_data['authors'];
  96. }
  97. /**
  98. * Get the entry content
  99. *
  100. * @return string
  101. */
  102. public function getContent()
  103. {
  104. if (array_key_exists('content', $this->_data)) {
  105. return $this->_data['content'];
  106. }
  107. $content = $this->getExtension('Atom')->getContent();
  108. $this->_data['content'] = $content;
  109. return $this->_data['content'];
  110. }
  111. /**
  112. * Get the entry creation date
  113. *
  114. * @return string
  115. */
  116. public function getDateCreated()
  117. {
  118. if (array_key_exists('datecreated', $this->_data)) {
  119. return $this->_data['datecreated'];
  120. }
  121. $dateCreated = $this->getExtension('Atom')->getDateCreated();
  122. $this->_data['datecreated'] = $dateCreated;
  123. return $this->_data['datecreated'];
  124. }
  125. /**
  126. * Get the entry modification date
  127. *
  128. * @return string
  129. */
  130. public function getDateModified()
  131. {
  132. if (array_key_exists('datemodified', $this->_data)) {
  133. return $this->_data['datemodified'];
  134. }
  135. $dateModified = $this->getExtension('Atom')->getDateModified();
  136. $this->_data['datemodified'] = $dateModified;
  137. return $this->_data['datemodified'];
  138. }
  139. /**
  140. * Get the entry description
  141. *
  142. * @return string
  143. */
  144. public function getDescription()
  145. {
  146. if (array_key_exists('description', $this->_data)) {
  147. return $this->_data['description'];
  148. }
  149. $description = $this->getExtension('Atom')->getDescription();
  150. $this->_data['description'] = $description;
  151. return $this->_data['description'];
  152. }
  153. /**
  154. * Get the entry enclosure
  155. *
  156. * @return string
  157. */
  158. public function getEnclosure()
  159. {
  160. if (array_key_exists('enclosure', $this->_data)) {
  161. return $this->_data['enclosure'];
  162. }
  163. $enclosure = $this->getExtension('Atom')->getEnclosure();
  164. $this->_data['enclosure'] = $enclosure;
  165. return $this->_data['enclosure'];
  166. }
  167. /**
  168. * Get the entry ID
  169. *
  170. * @return string
  171. */
  172. public function getId()
  173. {
  174. if (array_key_exists('id', $this->_data)) {
  175. return $this->_data['id'];
  176. }
  177. $id = $this->getExtension('Atom')->getId();
  178. $this->_data['id'] = $id;
  179. return $this->_data['id'];
  180. }
  181. /**
  182. * Get a specific link
  183. *
  184. * @param int $index
  185. * @return string
  186. */
  187. public function getLink($index = 0)
  188. {
  189. if (!array_key_exists('links', $this->_data)) {
  190. $this->getLinks();
  191. }
  192. if (isset($this->_data['links'][$index])) {
  193. return $this->_data['links'][$index];
  194. }
  195. return null;
  196. }
  197. /**
  198. * Get all links
  199. *
  200. * @return array
  201. */
  202. public function getLinks()
  203. {
  204. if (array_key_exists('links', $this->_data)) {
  205. return $this->_data['links'];
  206. }
  207. $links = $this->getExtension('Atom')->getLinks();
  208. $this->_data['links'] = $links;
  209. return $this->_data['links'];
  210. }
  211. /**
  212. * Get a permalink to the entry
  213. *
  214. * @return string
  215. */
  216. public function getPermalink()
  217. {
  218. return $this->getLink(0);
  219. }
  220. /**
  221. * Get the entry title
  222. *
  223. * @return string
  224. */
  225. public function getTitle()
  226. {
  227. if (array_key_exists('title', $this->_data)) {
  228. return $this->_data['title'];
  229. }
  230. $title = $this->getExtension('Atom')->getTitle();
  231. $this->_data['title'] = $title;
  232. return $this->_data['title'];
  233. }
  234. /**
  235. * Get the number of comments/replies for current entry
  236. *
  237. * @return integer
  238. */
  239. public function getCommentCount()
  240. {
  241. if (array_key_exists('commentcount', $this->_data)) {
  242. return $this->_data['commentcount'];
  243. }
  244. $commentcount = $this->getExtension('Thread')>getCommentCount();
  245. if (!$commentcount) {
  246. $commentcount = $this->getExtension('Atom')->getCommentCount();
  247. }
  248. $this->_data['commentcount'] = $commentcount;
  249. return $this->_data['commentcount'];
  250. }
  251. /**
  252. * Returns a URI pointing to the HTML page where comments can be made on this entry
  253. *
  254. * @return string
  255. */
  256. public function getCommentLink()
  257. {
  258. if (array_key_exists('commentlink', $this->_data)) {
  259. return $this->_data['commentlink'];
  260. }
  261. $commentlink = $this->getExtension('Atom')->getCommentLink();
  262. $this->_data['commentlink'] = $commentlink;
  263. return $this->_data['commentlink'];
  264. }
  265. /**
  266. * Returns a URI pointing to a feed of all comments for this entry
  267. *
  268. * @return string
  269. */
  270. public function getCommentFeedLink()
  271. {
  272. if (array_key_exists('commentfeedlink', $this->_data)) {
  273. return $this->_data['commentfeedlink'];
  274. }
  275. $commentfeedlink = $this->getExtension('Atom')->getCommentFeedLink();
  276. $this->_data['commentfeedlink'] = $commentfeedlink;
  277. return $this->_data['commentfeedlink'];
  278. }
  279. /**
  280. * Set the XPath query (incl. on all Extensions)
  281. *
  282. * @param DOMXPath $xpath
  283. */
  284. public function setXpath(DOMXPath $xpath)
  285. {
  286. parent::setXpath($xpath);
  287. foreach ($this->_extensions as $extension) {
  288. $extension->setXpath($this->_xpath);
  289. }
  290. }
  291. }