Projet

Général

Profil

Paste
Télécharger (3,07 ko) Statistiques
| Branche: | Révision:

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

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

    
23
    // Return an empty result object when feed is false.
24
    if (!$feed) {
25
      return $result;
26
    }
27

    
28
    $result->title = $feed['title'];
29
    $result->description = $feed['description'];
30
    $result->link = $feed['link'];
31
    if (is_array($feed['items'])) {
32
      foreach ($feed['items'] as $item) {
33
        if (isset($item['geolocations'])) {
34
          foreach ($item['geolocations'] as $k => $v) {
35
            $item['geolocations'][$k] = new FeedsGeoTermElement($v);
36
          }
37
        }
38
        $result->items[] = $item;
39
      }
40
    }
41
    return $result;
42
  }
43

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

    
96
  /**
97
   * Overrides FeedsParser::providesSourceTitle().
98
   *
99
   * This parser supports retrieving a title from the source.
100
   */
101
  public function providesSourceTitle() {
102
    return TRUE;
103
  }
104

    
105
}