PageRenderTime 25ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/magento/zendframework1/library/Zend/Feed/Reader/Entry/Atom.php

https://gitlab.com/yousafsyed/easternglamor
PHP | 400 lines | 177 code | 76 blank | 147 comment | 20 complexity | c4f9ba356c97d5ad4ad6a5a210fa5d31 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-2015 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-2015 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. $threadClass = Zend_Feed_Reader::getPluginLoader()->getClassName('DublinCore_Entry');
  69. $this->_extensions['DublinCore_Entry'] = new $threadClass($entry, $entryKey, $type);
  70. }
  71. /**
  72. * Get the specified author
  73. *
  74. * @param int $index
  75. * @return string|null
  76. */
  77. public function getAuthor($index = 0)
  78. {
  79. $authors = $this->getAuthors();
  80. if (isset($authors[$index])) {
  81. return $authors[$index];
  82. }
  83. return null;
  84. }
  85. /**
  86. * Get an array with feed authors
  87. *
  88. * @return array
  89. */
  90. public function getAuthors()
  91. {
  92. if (array_key_exists('authors', $this->_data)) {
  93. return $this->_data['authors'];
  94. }
  95. $people = $this->getExtension('Atom')->getAuthors();
  96. $this->_data['authors'] = $people;
  97. return $this->_data['authors'];
  98. }
  99. /**
  100. * Get the entry content
  101. *
  102. * @return string
  103. */
  104. public function getContent()
  105. {
  106. if (array_key_exists('content', $this->_data)) {
  107. return $this->_data['content'];
  108. }
  109. $content = $this->getExtension('Atom')->getContent();
  110. $this->_data['content'] = $content;
  111. return $this->_data['content'];
  112. }
  113. /**
  114. * Get the entry creation date
  115. *
  116. * @return string
  117. */
  118. public function getDateCreated()
  119. {
  120. if (array_key_exists('datecreated', $this->_data)) {
  121. return $this->_data['datecreated'];
  122. }
  123. $dateCreated = $this->getExtension('Atom')->getDateCreated();
  124. $this->_data['datecreated'] = $dateCreated;
  125. return $this->_data['datecreated'];
  126. }
  127. /**
  128. * Get the entry modification date
  129. *
  130. * @return string
  131. */
  132. public function getDateModified()
  133. {
  134. if (array_key_exists('datemodified', $this->_data)) {
  135. return $this->_data['datemodified'];
  136. }
  137. $dateModified = $this->getExtension('Atom')->getDateModified();
  138. $this->_data['datemodified'] = $dateModified;
  139. return $this->_data['datemodified'];
  140. }
  141. /**
  142. * Get the entry description
  143. *
  144. * @return string
  145. */
  146. public function getDescription()
  147. {
  148. if (array_key_exists('description', $this->_data)) {
  149. return $this->_data['description'];
  150. }
  151. $description = $this->getExtension('Atom')->getDescription();
  152. $this->_data['description'] = $description;
  153. return $this->_data['description'];
  154. }
  155. /**
  156. * Get the entry enclosure
  157. *
  158. * @return string
  159. */
  160. public function getEnclosure()
  161. {
  162. if (array_key_exists('enclosure', $this->_data)) {
  163. return $this->_data['enclosure'];
  164. }
  165. $enclosure = $this->getExtension('Atom')->getEnclosure();
  166. $this->_data['enclosure'] = $enclosure;
  167. return $this->_data['enclosure'];
  168. }
  169. /**
  170. * Get the entry ID
  171. *
  172. * @return string
  173. */
  174. public function getId()
  175. {
  176. if (array_key_exists('id', $this->_data)) {
  177. return $this->_data['id'];
  178. }
  179. $id = $this->getExtension('Atom')->getId();
  180. $this->_data['id'] = $id;
  181. return $this->_data['id'];
  182. }
  183. /**
  184. * Get a specific link
  185. *
  186. * @param int $index
  187. * @return string
  188. */
  189. public function getLink($index = 0)
  190. {
  191. if (!array_key_exists('links', $this->_data)) {
  192. $this->getLinks();
  193. }
  194. if (isset($this->_data['links'][$index])) {
  195. return $this->_data['links'][$index];
  196. }
  197. return null;
  198. }
  199. /**
  200. * Get all links
  201. *
  202. * @return array
  203. */
  204. public function getLinks()
  205. {
  206. if (array_key_exists('links', $this->_data)) {
  207. return $this->_data['links'];
  208. }
  209. $links = $this->getExtension('Atom')->getLinks();
  210. $this->_data['links'] = $links;
  211. return $this->_data['links'];
  212. }
  213. /**
  214. * Get a permalink to the entry
  215. *
  216. * @return string
  217. */
  218. public function getPermalink()
  219. {
  220. return $this->getLink(0);
  221. }
  222. /**
  223. * Get the entry title
  224. *
  225. * @return string
  226. */
  227. public function getTitle()
  228. {
  229. if (array_key_exists('title', $this->_data)) {
  230. return $this->_data['title'];
  231. }
  232. $title = $this->getExtension('Atom')->getTitle();
  233. $this->_data['title'] = $title;
  234. return $this->_data['title'];
  235. }
  236. /**
  237. * Get the number of comments/replies for current entry
  238. *
  239. * @return integer
  240. */
  241. public function getCommentCount()
  242. {
  243. if (array_key_exists('commentcount', $this->_data)) {
  244. return $this->_data['commentcount'];
  245. }
  246. $commentcount = $this->getExtension('Thread')->getCommentCount();
  247. if (!$commentcount) {
  248. $commentcount = $this->getExtension('Atom')->getCommentCount();
  249. }
  250. $this->_data['commentcount'] = $commentcount;
  251. return $this->_data['commentcount'];
  252. }
  253. /**
  254. * Returns a URI pointing to the HTML page where comments can be made on this entry
  255. *
  256. * @return string
  257. */
  258. public function getCommentLink()
  259. {
  260. if (array_key_exists('commentlink', $this->_data)) {
  261. return $this->_data['commentlink'];
  262. }
  263. $commentlink = $this->getExtension('Atom')->getCommentLink();
  264. $this->_data['commentlink'] = $commentlink;
  265. return $this->_data['commentlink'];
  266. }
  267. /**
  268. * Returns a URI pointing to a feed of all comments for this entry
  269. *
  270. * @return string
  271. */
  272. public function getCommentFeedLink()
  273. {
  274. if (array_key_exists('commentfeedlink', $this->_data)) {
  275. return $this->_data['commentfeedlink'];
  276. }
  277. $commentfeedlink = $this->getExtension('Atom')->getCommentFeedLink();
  278. $this->_data['commentfeedlink'] = $commentfeedlink;
  279. return $this->_data['commentfeedlink'];
  280. }
  281. /**
  282. * Get category data as a Zend_Feed_Reader_Collection_Category object
  283. *
  284. * @return Zend_Feed_Reader_Collection_Category
  285. */
  286. public function getCategories()
  287. {
  288. if (array_key_exists('categories', $this->_data)) {
  289. return $this->_data['categories'];
  290. }
  291. $categoryCollection = $this->getExtension('Atom')->getCategories();
  292. if (count($categoryCollection) == 0) {
  293. $categoryCollection = $this->getExtension('DublinCore')->getCategories();
  294. }
  295. $this->_data['categories'] = $categoryCollection;
  296. return $this->_data['categories'];
  297. }
  298. /**
  299. * Get source feed metadata from the entry
  300. *
  301. * @return Zend_Feed_Reader_Feed_Atom_Source|null
  302. */
  303. public function getSource()
  304. {
  305. if (array_key_exists('source', $this->_data)) {
  306. return $this->_data['source'];
  307. }
  308. $source = $this->getExtension('Atom')->getSource();
  309. $this->_data['source'] = $source;
  310. return $this->_data['source'];
  311. }
  312. /**
  313. * Set the XPath query (incl. on all Extensions)
  314. *
  315. * @param DOMXPath $xpath
  316. */
  317. public function setXpath(DOMXPath $xpath)
  318. {
  319. parent::setXpath($xpath);
  320. foreach ($this->_extensions as $extension) {
  321. $extension->setXpath($this->_xpath);
  322. }
  323. }
  324. }