function parser_common_syndication_feedapi_feed in FeedAPI 5
Same name and namespace in other branches
- 6 parser_common_syndication/parser_common_syndication.module \parser_common_syndication_feedapi_feed()
Implementation of hook_feedapi_feed().
File
- parser_common_syndication/
parser_common_syndication.module, line 24 - Parse the incoming URL with SimpleXML then provide a data structure of the feed. Requires PHP5 because of SimpleXML.
Code
function parser_common_syndication_feedapi_feed($op) {
$args = func_get_args();
switch ($op) {
case 'type':
return array(
"XML feed",
);
case 'compatible':
if (!function_exists('simplexml_load_string')) {
return FALSE;
}
$url = $args[1]->url;
$downloaded_string = _parser_common_syndication_download($url, $op);
if (is_object($downloaded_string)) {
return array_shift(parser_common_syndication_feedapi_feed('type'));
}
if (!defined('LIBXML_VERSION') || version_compare(phpversion(), '5.1.0', '<')) {
@($xml = simplexml_load_string($downloaded_string, NULL));
}
else {
@($xml = simplexml_load_string($downloaded_string, NULL, LIBXML_NOERROR | LIBXML_NOWARNING));
}
if (_parser_common_syndication_feed_format_detect($xml) != FALSE) {
// The parser is compatible. Then has to parse the feed and cache it. Because in the download
// part, the feed etag data be already saved perhaps (depends on the webserver).
$parsed_feed = _parser_common_syndication_feedapi_parse($xml);
if (is_object($parsed_feed) && $parsed_feed->from_cache !== TRUE) {
_parser_common_syndication_cache_set($url, $parsed_feed);
}
// We don't have to choose between the types, because this module is only able to parse one.
return array_shift(parser_common_syndication_feedapi_feed('type'));
}
return FALSE;
case 'parse':
$feed = is_object($args[1]) ? $args[1] : FALSE;
$parsed_feed = _parser_common_syndication_feedapi_parse($feed);
if (is_object($parsed_feed) && $parsed_feed->from_cache !== TRUE) {
_parser_common_syndication_cache_set($feed->url, $parsed_feed);
}
return $parsed_feed;
}
}