Atom.php 8.4 KB

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