Projet

Général

Profil

Paste
Télécharger (2,47 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / feeds / plugins / FeedsSyndicationParser.inc @ 3aa14731

1
<?php
2

    
3
/**
4
 * @file
5
 * Contains FeedsSyndicationParser and related classes.
6
 */
7

    
8
/**
9
 * Class definition for Common Syndication Parser.
10
 *
11
 * Parses RSS and Atom feeds.
12
 */
13
class FeedsSyndicationParser extends FeedsParser {
14

    
15
  /**
16
   * Implements FeedsParser::parse().
17
   */
18
  public function parse(FeedsSource $source, FeedsFetcherResult $fetcher_result) {
19
    feeds_include_library('common_syndication_parser.inc', 'common_syndication_parser');
20
    $feed = common_syndication_parser_parse($fetcher_result->getRaw());
21
    $result = new FeedsParserResult();
22
    $result->title = $feed['title'];
23
    $result->description = $feed['description'];
24
    $result->link = $feed['link'];
25
    if (is_array($feed['items'])) {
26
      foreach ($feed['items'] as $item) {
27
        if (isset($item['geolocations'])) {
28
          foreach ($item['geolocations'] as $k => $v) {
29
            $item['geolocations'][$k] = new FeedsGeoTermElement($v);
30
          }
31
        }
32
        $result->items[] = $item;
33
      }
34
    }
35
    return $result;
36
  }
37

    
38
  /**
39
   * Return mapping sources.
40
   *
41
   * At a future point, we could expose data type information here,
42
   * storage systems like Data module could use this information to store
43
   * parsed data automatically in fields with a correct field type.
44
   */
45
  public function getMappingSources() {
46
    return array(
47
      'title' => array(
48
        'name' => t('Title'),
49
        'description' => t('Title of the feed item.'),
50
      ),
51
      'description' => array(
52
        'name' => t('Description'),
53
        'description' => t('Description of the feed item.'),
54
      ),
55
      'author_name' => array(
56
        'name' => t('Author name'),
57
        'description' => t('Name of the feed item\'s author.'),
58
      ),
59
      'timestamp' => array(
60
        'name' => t('Published date'),
61
        'description' => t('Published date as UNIX time GMT of the feed item.'),
62
      ),
63
      'url' => array(
64
        'name' => t('Item URL (link)'),
65
        'description' => t('URL of the feed item.'),
66
      ),
67
      'guid' => array(
68
        'name' => t('Item GUID'),
69
        'description' => t('Global Unique Identifier of the feed item.'),
70
      ),
71
      'tags' => array(
72
        'name' => t('Categories'),
73
        'description' => t('An array of categories that have been assigned to the feed item.'),
74
      ),
75
      'geolocations' => array(
76
        'name' => t('Geo Locations'),
77
        'description' => t('An array of geographic locations with a name and a position.'),
78
      ),
79
    ) + parent::getMappingSources();
80
  }
81
}