public function FeedsSitemapParser::parse in Feeds 7
Same name and namespace in other branches
- 6 plugins/FeedsSitemapParser.inc \FeedsSitemapParser::parse()
- 7.2 plugins/FeedsSitemapParser.inc \FeedsSitemapParser::parse()
Implements 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'] = $url->changefreq;
}
if ($url->priority) {
$item['priority'] = $url->priority;
}
$batch
->addItem($item);
}
date_default_timezone_set($tz);
}