FeedsSitemapParser.inc in Feeds 6
File
plugins/FeedsSitemapParser.inc
View source
<?php
class FeedsSitemapParser extends FeedsParser {
public function parse(FeedsImportBatch $batch, FeedsSource $source) {
$tz = date_default_timezone_get();
date_default_timezone_set('GMT');
$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);
}
public function getMappingSources() {
return array(
'url' => array(
'name' => t('Item URL (link)'),
'description' => t('URL of the feed item.'),
),
'lastmod' => array(
'name' => t('Last modification date'),
'description' => t('Last modified date as UNIX time GMT of the feed item.'),
),
'changefreq' => array(
'name' => t('Change frequency'),
'description' => t('How frequently the page is likely to change.'),
),
'priority' => array(
'name' => t('Priority'),
'description' => t('The priority of this URL relative to other URLs on the site.'),
),
) + parent::getMappingSources();
}
}