function parser_common_syndication_feedapi_feed in FeedAPI 6
Same name and namespace in other branches
- 5 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;
}
require_once './' . drupal_get_path('module', 'parser_common_syndication') . '/parser_common_syndication.inc';
$url = $args[1]->url;
$settings = isset($args[2]) ? $args[2] : array();
$downloaded_string = _parser_common_syndication_download($url, $settings);
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, 'SimpleXMLElement', LIBXML_NOERROR | LIBXML_NOWARNING | LIBXML_NOCDATA));
}
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) && empty($parsed_feed->from_cache)) {
_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':
require_once './' . drupal_get_path('module', 'parser_common_syndication') . '/parser_common_syndication.inc';
$feed = is_object($args[1]) ? $args[1] : FALSE;
$parsed_feed = _parser_common_syndication_feedapi_parse($feed);
if (is_object($parsed_feed) && empty($parsed_feed->from_cache)) {
_parser_common_syndication_cache_set($feed->url, $parsed_feed);
}
return $parsed_feed;
}
}