| 5 |
*/ |
*/ |
| 6 |
function _aggregation_RSS20_parse($feed_XML, $feed) |
function _aggregation_RSS20_parse($feed_XML, $feed) |
| 7 |
{ |
{ |
| 8 |
|
// set category splitter |
| 9 |
|
$category_splitter = '.'; |
| 10 |
|
|
| 11 |
foreach ($feed_XML->xpath('//item') AS $news) |
foreach ($feed_XML->xpath('//item') AS $news) |
| 12 |
{ |
{ |
| 13 |
|
// for PHP > 5.1.2 get 'content' namespace |
| 14 |
|
$content = $news->children('http://purl.org/rss/1.0/modules/content/'); |
| 15 |
|
$dc = $news->children('http://purl.org/dc/elements/1.1/'); |
| 16 |
|
|
| 17 |
if ($news->guid) |
if ($news->guid) |
| 18 |
$guid = (string)$news->guid; |
$guid = "{$news->guid}"; |
| 19 |
else |
else |
| 20 |
$guid = NULL; |
$guid = NULL; |
| 21 |
|
|
| 22 |
$title = (string)$news->title; |
if ($news->title) |
| 23 |
$body = (string)$news->description; |
$title = "{$news->title}"; |
| 24 |
|
else |
| 25 |
|
$title = ''; |
| 26 |
|
|
| 27 |
|
$body = ''; |
| 28 |
|
if ($news->description) |
| 29 |
|
{ |
| 30 |
|
foreach($news->description->children() as $child) |
| 31 |
|
$body .= $child->asXML(); |
| 32 |
|
$body .= "{$news->description}"; |
| 33 |
|
} |
| 34 |
|
// some sources use content:encoded as description i.e. PostNuke PageSetter module |
| 35 |
|
elseif ($news->encoded) //content:encoded for PHP < 5.1.2 |
| 36 |
|
{ |
| 37 |
|
foreach($news->encoded->children() as $child) |
| 38 |
|
$body .= $child->asXML(); |
| 39 |
|
$body .= "{$news->encoded}"; |
| 40 |
|
} |
| 41 |
|
elseif ($content->encoded) //content:encoded for PHP >= 5.1.2 |
| 42 |
|
{ |
| 43 |
|
foreach($content->encoded->children() as $child) |
| 44 |
|
$body .= $child->asXML(); |
| 45 |
|
$body .= "{$content->encoded}"; |
| 46 |
|
} |
| 47 |
|
else |
| 48 |
|
$body = $title; |
| 49 |
|
|
| 50 |
$teaser = node_teaser($body); |
$teaser = node_teaser($body); |
| 51 |
$original_author = $feed->original_author; |
|
| 52 |
|
if ($news->author) |
| 53 |
|
$original_author = "{$news->author}"; |
| 54 |
|
elseif ($dc->creator) |
| 55 |
|
$original_author = "{$dc->creator}"; |
| 56 |
|
elseif ($feed_XML->channel->title) |
| 57 |
|
$original_author = "{$feed_XML->channel->title}"; |
| 58 |
|
else |
| 59 |
|
$original_author = $feed->original_author; |
| 60 |
|
|
| 61 |
if ($news->link) |
if ($news->link) |
| 62 |
$original_url = (string)$news->link; |
$original_url = "{$news->link}"; |
| 63 |
else |
else |
| 64 |
$original_url = NULL; |
$original_url = NULL; |
| 65 |
|
|
| 66 |
$timestamp = strtotime((string)$news->pubDate); |
$timestamp = strtotime("{$news->pubDate}"); |
| 67 |
if ($timestamp === FALSE) |
if ($timestamp === FALSE) |
| 68 |
$timestamp = time(); |
$timestamp = time(); |
| 69 |
|
|
| 70 |
|
$additional_taxonomies = array(); |
| 71 |
|
|
| 72 |
|
if ($news->category) |
| 73 |
|
{ |
| 74 |
|
$additional_taxonomies = array(); |
| 75 |
|
|
| 76 |
|
foreach ($news->category as $cat) |
| 77 |
|
{ |
| 78 |
|
if (is_object($cat)) |
| 79 |
|
$additional_taxonomies['Feed Categories'][] = trim(strip_tags("$cat")); |
| 80 |
|
else |
| 81 |
|
foreach (explode($category_splitter, $cat) as $tag) |
| 82 |
|
{ |
| 83 |
|
$additional_taxonomies['Feed Categories'][] = $tag; |
| 84 |
|
} |
| 85 |
|
} |
| 86 |
|
$additional_taxonomies['Feed Categories'] = array_unique($additional_taxonomies['Feed Categories']); |
| 87 |
|
} |
| 88 |
|
|
| 89 |
|
$other = array(); |
| 90 |
|
if ($news->comments) |
| 91 |
|
$other['original_comments'] = "{$news->comments}"; |
| 92 |
|
|
| 93 |
|
$image = array(); |
| 94 |
|
if ($news->enclosure) { |
| 95 |
|
if (preg_match('/^image/', $news->enclosure['type'])) { |
| 96 |
|
$image[] = array('url' => "{$news->enclosure['url']}"); |
| 97 |
|
} |
| 98 |
|
} |
| 99 |
|
|
| 100 |
_aggregation_add_item($title, $body, $teaser, $original_author, $feed, array(), $timestamp, $original_url, $guid, array()); |
_aggregation_add_item($title, $body, $teaser, $original_author, $feed, $additional_taxonomies, $timestamp, $original_url, $guid, $image, $other); |
| 101 |
} |
} |
| 102 |
} |
} |