/libraries/joomla/feed/parser/atom.php

https://gitlab.com/vitaliylukin91/text · PHP · 204 lines · 61 code · 15 blank · 128 comment · 1 complexity · a72cf265f25063674b4049b04b5e5314 MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Platform
  4. * @subpackage Feed
  5. *
  6. * @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE
  8. */
  9. defined('JPATH_PLATFORM') or die;
  10. /**
  11. * ATOM Feed Parser class.
  12. *
  13. * @link http://www.atomenabled.org/developers/syndication/
  14. * @since 12.3
  15. */
  16. class JFeedParserAtom extends JFeedParser
  17. {
  18. /**
  19. * @var string The feed format version.
  20. * @since 12.3
  21. */
  22. protected $version;
  23. /**
  24. * Method to handle the <author> element for the feed.
  25. *
  26. * @param JFeed $feed The JFeed object being built from the parsed feed.
  27. * @param SimpleXMLElement $el The current XML element object to handle.
  28. *
  29. * @return void
  30. *
  31. * @since 12.3
  32. */
  33. protected function handleAuthor(JFeed $feed, SimpleXMLElement $el)
  34. {
  35. // Set the author information from the XML element.
  36. $feed->setAuthor((string) $el->name, (string) $el->email, (string) $el->uri);
  37. }
  38. /**
  39. * Method to handle the <contributor> element for the feed.
  40. *
  41. * @param JFeed $feed The JFeed object being built from the parsed feed.
  42. * @param SimpleXMLElement $el The current XML element object to handle.
  43. *
  44. * @return void
  45. *
  46. * @since 12.3
  47. */
  48. protected function handleContributor(JFeed $feed, SimpleXMLElement $el)
  49. {
  50. $feed->addContributor((string) $el->name, (string) $el->email, (string) $el->uri);
  51. }
  52. /**
  53. * Method to handle the <generator> element for the feed.
  54. *
  55. * @param JFeed $feed The JFeed object being built from the parsed feed.
  56. * @param SimpleXMLElement $el The current XML element object to handle.
  57. *
  58. * @return void
  59. *
  60. * @since 12.3
  61. */
  62. protected function handleGenerator(JFeed $feed, SimpleXMLElement $el)
  63. {
  64. $feed->generator = (string) $el;
  65. }
  66. /**
  67. * Method to handle the <id> element for the feed.
  68. *
  69. * @param JFeed $feed The JFeed object being built from the parsed feed.
  70. * @param SimpleXMLElement $el The current XML element object to handle.
  71. *
  72. * @return void
  73. *
  74. * @since 12.3
  75. */
  76. protected function handleId(JFeed $feed, SimpleXMLElement $el)
  77. {
  78. $feed->uri = (string) $el;
  79. }
  80. /**
  81. * Method to handle the <link> element for the feed.
  82. *
  83. * @param JFeed $feed The JFeed object being built from the parsed feed.
  84. * @param SimpleXMLElement $el The current XML element object to handle.
  85. *
  86. * @return void
  87. *
  88. * @since 12.3
  89. */
  90. protected function handleLink(JFeed $feed, SimpleXMLElement $el)
  91. {
  92. $link = new JFeedLink;
  93. $link->uri = (string) $el['href'];
  94. $link->language = (string) $el['hreflang'];
  95. $link->length = (int) $el['length'];
  96. $link->relation = (string) $el['rel'];
  97. $link->title = (string) $el['title'];
  98. $link->type = (string) $el['type'];
  99. $feed->link = $link;
  100. }
  101. /**
  102. * Method to handle the <rights> element for the feed.
  103. *
  104. * @param JFeed $feed The JFeed object being built from the parsed feed.
  105. * @param SimpleXMLElement $el The current XML element object to handle.
  106. *
  107. * @return void
  108. *
  109. * @since 12.3
  110. */
  111. protected function handleRights(JFeed $feed, SimpleXMLElement $el)
  112. {
  113. $feed->copyright = (string) $el;
  114. }
  115. /**
  116. * Method to handle the <subtitle> element for the feed.
  117. *
  118. * @param JFeed $feed The JFeed object being built from the parsed feed.
  119. * @param SimpleXMLElement $el The current XML element object to handle.
  120. *
  121. * @return void
  122. *
  123. * @since 12.3
  124. */
  125. protected function handleSubtitle(JFeed $feed, SimpleXMLElement $el)
  126. {
  127. $feed->description = (string) $el;
  128. }
  129. /**
  130. * Method to handle the <title> element for the feed.
  131. *
  132. * @param JFeed $feed The JFeed object being built from the parsed feed.
  133. * @param SimpleXMLElement $el The current XML element object to handle.
  134. *
  135. * @return void
  136. *
  137. * @since 12.3
  138. */
  139. protected function handleTitle(JFeed $feed, SimpleXMLElement $el)
  140. {
  141. $feed->title = (string) $el;
  142. }
  143. /**
  144. * Method to handle the <updated> element for the feed.
  145. *
  146. * @param JFeed $feed The JFeed object being built from the parsed feed.
  147. * @param SimpleXMLElement $el The current XML element object to handle.
  148. *
  149. * @return void
  150. *
  151. * @since 12.3
  152. */
  153. protected function handleUpdated(JFeed $feed, SimpleXMLElement $el)
  154. {
  155. $feed->updatedDate = (string) $el;
  156. }
  157. /**
  158. * Method to initialise the feed for parsing. Here we detect the version and advance the stream
  159. * reader so that it is ready to parse feed elements.
  160. *
  161. * @return void
  162. *
  163. * @since 12.3
  164. */
  165. protected function initialise()
  166. {
  167. // Read the version attribute.
  168. $this->version = ($this->stream->getAttribute('version') == '0.3') ? '0.3' : '1.0';
  169. // We want to move forward to the first element after the root element.
  170. $this->moveToNextElement();
  171. }
  172. /**
  173. * Method to handle the feed entry element for the feed: <entry>.
  174. *
  175. * @param JFeedEntry $entry The JFeedEntry object being built from the parsed feed entry.
  176. * @param SimpleXMLElement $el The current XML element object to handle.
  177. *
  178. * @return void
  179. *
  180. * @since 12.3
  181. */
  182. protected function processFeedEntry(JFeedEntry $entry, SimpleXMLElement $el)
  183. {
  184. $entry->uri = (string) $el->id;
  185. $entry->title = (string) $el->title;
  186. $entry->updatedDate = (string) $el->updated;
  187. $entry->content = (string) $el->summary;
  188. }
  189. }