FeedsSyndicationParser.inc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * @file
  4. * Contains FeedsSyndicationParser and related classes.
  5. */
  6. /**
  7. * Class definition for Common Syndication Parser.
  8. *
  9. * Parses RSS and Atom feeds.
  10. */
  11. class FeedsSyndicationParser extends FeedsParser {
  12. /**
  13. * Implements FeedsParser::parse().
  14. */
  15. public function parse(FeedsSource $source, FeedsFetcherResult $fetcher_result) {
  16. feeds_include_library('common_syndication_parser.inc', 'common_syndication_parser');
  17. $feed = common_syndication_parser_parse($fetcher_result->getRaw());
  18. $result = new FeedsParserResult();
  19. $result->title = $feed['title'];
  20. $result->description = $feed['description'];
  21. $result->link = $feed['link'];
  22. if (is_array($feed['items'])) {
  23. foreach ($feed['items'] as $item) {
  24. if (isset($item['geolocations'])) {
  25. foreach ($item['geolocations'] as $k => $v) {
  26. $item['geolocations'][$k] = new FeedsGeoTermElement($v);
  27. }
  28. }
  29. $result->items[] = $item;
  30. }
  31. }
  32. return $result;
  33. }
  34. /**
  35. * Return mapping sources.
  36. *
  37. * At a future point, we could expose data type information here,
  38. * storage systems like Data module could use this information to store
  39. * parsed data automatically in fields with a correct field type.
  40. */
  41. public function getMappingSources() {
  42. return array(
  43. 'title' => array(
  44. 'name' => t('Title'),
  45. 'description' => t('Title of the feed item.'),
  46. ),
  47. 'description' => array(
  48. 'name' => t('Description'),
  49. 'description' => t('Description of the feed item.'),
  50. ),
  51. 'author_name' => array(
  52. 'name' => t('Author name'),
  53. 'description' => t('Name of the feed item\'s author.'),
  54. ),
  55. 'timestamp' => array(
  56. 'name' => t('Published date'),
  57. 'description' => t('Published date as UNIX time GMT of the feed item.'),
  58. ),
  59. 'url' => array(
  60. 'name' => t('Item URL (link)'),
  61. 'description' => t('URL of the feed item.'),
  62. ),
  63. 'guid' => array(
  64. 'name' => t('Item GUID'),
  65. 'description' => t('Global Unique Identifier of the feed item.'),
  66. ),
  67. 'tags' => array(
  68. 'name' => t('Categories'),
  69. 'description' => t('An array of categories that have been assigned to the feed item.'),
  70. ),
  71. 'geolocations' => array(
  72. 'name' => t('Geo Locations'),
  73. 'description' => t('An array of geographic locations with a name and a position.'),
  74. ),
  75. ) + parent::getMappingSources();
  76. }
  77. }