Projet

Général

Profil

Paste
Télécharger (1,84 ko) Statistiques
| Branche: | Révision:

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

1
<?php
2

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

    
8
/**
9
 * A parser for the Sitemap specification http://www.sitemaps.org/protocol.php.
10
 */
11
class FeedsSitemapParser extends FeedsParser {
12

    
13
  /**
14
   * Implements FeedsParser::parse().
15
   */
16
  public function parse(FeedsSource $source, FeedsFetcherResult $fetcher_result) {
17
    // Set time zone to GMT for parsing dates with strtotime().
18
    $tz = date_default_timezone_get();
19
    date_default_timezone_set('GMT');
20
    // Yes, using a DOM parser is a bit inefficient, but will do for now.
21
    $xml = new SimpleXMLElement($fetcher_result->getRaw());
22
    $result = new FeedsParserResult();
23
    foreach ($xml->url as $url) {
24
      $item = array('url' => (string) $url->loc);
25
      if ($url->lastmod) {
26
        $item['lastmod'] = strtotime($url->lastmod);
27
      }
28
      if ($url->changefreq) {
29
        $item['changefreq'] = (string) $url->changefreq;
30
      }
31
      if ($url->priority) {
32
        $item['priority'] = (string) $url->priority;
33
      }
34
      $result->items[] = $item;
35
    }
36
    date_default_timezone_set($tz);
37
    return $result;
38
  }
39

    
40
  /**
41
   * Implements FeedsParser::getMappingSources().
42
   */
43
  public function getMappingSources() {
44
    return array(
45
      'url' => array(
46
        'name' => t('Item URL (link)'),
47
        'description' => t('URL of the feed item.'),
48
      ),
49
      'lastmod' => array(
50
        'name' => t('Last modification date'),
51
        'description' => t('Last modified date as UNIX time GMT of the feed item.'),
52
      ),
53
      'changefreq' => array(
54
        'name' => t('Change frequency'),
55
        'description' => t('How frequently the page is likely to change.'),
56
      ),
57
      'priority' => array(
58
        'name' => t('Priority'),
59
        'description' => t('The priority of this URL relative to other URLs on the site.'),
60
      ),
61
    ) + parent::getMappingSources();
62
  }
63

    
64
}