diff --git a/libraries/common_syndication_parser.inc b/libraries/common_syndication_parser.inc index 37bc5bb..c59dd1c 100644 --- a/libraries/common_syndication_parser.inc +++ b/libraries/common_syndication_parser.inc @@ -194,6 +194,14 @@ function _parser_common_syndication_atom10_parse($feed_XML) { if (!empty($feed_XML->author->name) && !$author_found) { $original_author = "{$feed_XML->author->name}"; } + + $enclosure = array(); + foreach ($news->link as $item) { + $enc_attributes = $item->attributes(); + if ($enc_attributes['rel'] == 'enclosure' && !empty($enc_attributes['href'])) { + $enclosure[] = "{$enc_attributes['href']}"; + } + } $original_url = _parser_common_syndication_link($news->link); @@ -225,6 +233,7 @@ function _parser_common_syndication_atom10_parse($feed_XML) { } $item['tags'] = isset($additional_taxonomies['ATOM Categories']) ? $additional_taxonomies['ATOM Categories'] : array(); $item['domains'] = isset($additional_taxonomies['ATOM Domains']) ? $additional_taxonomies['ATOM Domains'] : array(); + $item['enclosure'] = $enclosure; $parsed_source['items'][] = $item; } return $parsed_source; @@ -448,6 +457,21 @@ function _parser_common_syndication_RSS20_parse($feed_XML) { } } } + + // Load media from . + $enclosure = array(); + if (!empty($news['enclosure'])) { + if (!is_array($news['enclosure'])) { + $enc_elem = $news['enclosure']; + $news['enclosure'] = array(); + $news['enclosure'][] = $enc_elem; + } + + foreach ($news['enclosure'] as $item) { + $enc_attributes = $item->attributes(); + $enclosure[] = "{$enc_attributes['url']}"; + } + } $item = array(); $item['title'] = _parser_common_syndication_title($title, $body); @@ -478,6 +502,7 @@ function _parser_common_syndication_RSS20_parse($feed_XML) { $item['domains'] = $additional_taxonomies['RSS Domains']; $item['tags'] = $additional_taxonomies['RSS Categories']; + $item['enclosure'] = $enclosure; $parsed_source['items'][] = $item; } return $parsed_source; @@ -554,12 +579,12 @@ function _parser_common_syndication_link($links) { if (count($links) > 0) { foreach ($links as $link) { $link = $link->attributes(); - $to_link = isset($link["href"]) ? "{$link["href"]}" : ""; if (isset($link["rel"])) { - if ("{$link["rel"]}" == 'alternate') { + if ("{$link["rel"]}" == 'alternate' || "{$link["rel"]}" == 'enclosure') { break; } - } + } + $to_link = isset($link["href"]) ? "{$link["href"]}" : ""; } } return $to_link; diff --git a/plugins/FeedsSyndicationParser.inc b/plugins/FeedsSyndicationParser.inc index 64e55a4..dc2a61b 100644 --- a/plugins/FeedsSyndicationParser.inc +++ b/plugins/FeedsSyndicationParser.inc @@ -71,6 +71,10 @@ class FeedsSyndicationParser extends FeedsParser { 'name' => t('Geo Locations'), 'description' => t('An array of geographic locations with a name and a position.'), ), + 'enclosure' => array( + 'name' => t('Enclosure'), + 'description' => t('Array of links to media content.'), + ), ) + parent::getMappingSources(); } }