You are here

public function FeedsSitemapParser::parse in Feeds 6

Same name and namespace in other branches
  1. 7.2 plugins/FeedsSitemapParser.inc \FeedsSitemapParser::parse()
  2. 7 plugins/FeedsSitemapParser.inc \FeedsSitemapParser::parse()

Implementation of FeedsParser::parse().

Overrides FeedsParser::parse

File

plugins/FeedsSitemapParser.inc, line 10

Class

FeedsSitemapParser
A parser for the Sitemap specification http://www.sitemaps.org/protocol.php

Code

public function parse(FeedsImportBatch $batch, FeedsSource $source) {

  // Set time zone to GMT for parsing dates with strtotime().
  $tz = date_default_timezone_get();
  date_default_timezone_set('GMT');

  // Yes, using a DOM parser is a bit inefficient, but will do for now
  $xml = new SimpleXMLElement($batch
    ->getRaw());
  foreach ($xml->url as $url) {
    $item = array(
      'url' => (string) $url->loc,
    );
    if ($url->lastmod) {
      $item['lastmod'] = strtotime($url->lastmod);
    }
    if ($url->changefreq) {
      $item['changefreq'] = (string) $url->changefreq;
    }
    if ($url->priority) {
      $item['priority'] = (string) $url->priority;
    }
    $batch->items[] = $item;
  }
  date_default_timezone_set($tz);
}