function _feedapi_call_parsers in FeedAPI 6
Same name and namespace in other branches
- 5 feedapi.module \_feedapi_call_parsers()
Execute the enabled parsers and create an unified output
Parameters
$feed: Feed object
$parsers: Structure: array( "primary" => "parser_primary", "secondary" => array("parser1", "parser2", "parserN") );
Return value
The object of the parser data
3 calls to _feedapi_call_parsers()
- feedapi_drush_parse in ./
feedapi.drush.inc - Invokes the parser and displays the output
- _feedapi_build_feed_object in ./
feedapi.module - Builds feed object ready to be sticked onto node.
- _feedapi_invoke_refresh in ./
feedapi.module - Helper function for feedapi_invoke(). Refresh the feed, call the proper parsers and processors' hooks. Don't call this function directly, use feedapi_refresh() instead.
File
- ./
feedapi.module, line 1012 - Handle the submodules (for feed and item processing) Provide a basic management of feeds
Code
function _feedapi_call_parsers($feed, $parsers, $settings) {
$nid = isset($feed->nid) ? $feed->nid : '';
$parser_primary = array_shift($parsers);
$parsers_secondary = $parsers;
// Normalize relative URLs according to the base URL (mostly for uploaded feeds), but allow other schemes too
if (!valid_url($feed->url, TRUE) && valid_url($feed->url) && !strpos($feed->url, '://')) {
$feed->url = $GLOBALS['base_url'] . $feed->url;
}
if (module_exists($parser_primary)) {
$settings_primary = isset($settings[$parser_primary]) ? $settings[$parser_primary] : array();
$feed->feed_type = module_invoke($parser_primary, 'feedapi_feed', 'compatible', $feed, $settings_primary);
$parser_output = module_invoke($parser_primary, 'feedapi_feed', 'parse', $feed, $settings_primary);
if ($parser_output === FALSE) {
return $feed;
}
$feed = (object) array_merge((array) $feed, (array) $parser_output);
}
// Call the turned on parsers, create a union of returned options
$parsers_secondary = is_array($parsers_secondary) ? $parsers_secondary : array();
foreach ($parsers_secondary as $parser) {
$settings_secondary = isset($settings[$parser]) ? $settings[$parser] : array();
$feed_ext = module_invoke($parser, 'feedapi_feed', 'parse', $feed, $settings_secondary);
$feed->options = (object) ((array) $feed->options + (array) $feed_ext->options);
// Merge items' options
if (is_array($feed_ext->items)) {
foreach ($feed_ext->items as $key => $item) {
$src = isset($feed->items[$key]) ? $feed->items[$key]->options : array();
$feed->items[$key]->options = (object) ((array) $src + (array) $item->options);
}
}
}
$feed->nid = $nid;
foreach (module_implements('feedapi_after_parse') as $module) {
$func = $module . '_feedapi_after_parse';
$func($feed);
}
// Filter bad or not allowed tags, sanitize data (currently timestamp checking)
if (!variable_get('feedapi_allow_html_all', FALSE)) {
$allowed = preg_split('/\\s+|<|>/', variable_get('feedapi_allowed_html_tags', '<a> <b> <br> <dd> <dl> <dt> <em> <i> <li> <ol> <p> <strong> <u> <ul>'), -1, PREG_SPLIT_NO_EMPTY);
}
else {
$allowed = TRUE;
}
foreach (array(
'title',
'description',
) as $property) {
if (isset($feed->{$property})) {
if (is_string($feed->{$property})) {
$feed->{$property} = _feedapi_process_text($feed->{$property}, $allowed);
}
}
}
if (isset($feed->options)) {
$props = array_keys(get_object_vars($feed->options));
foreach ($props as $property) {
if (isset($feed->options->{$property})) {
if (is_string($feed->options->{$property})) {
$feed->options->{$property} = _feedapi_process_text($feed->options->{$property}, $allowed);
}
}
}
}
if (isset($feed->items)) {
foreach (array_keys($feed->items) as $i) {
$feed->items[$i]->title = _feedapi_process_text($feed->items[$i]->title, array());
$feed->items[$i]->description = _feedapi_process_text($feed->items[$i]->description, $allowed);
if ($feed->items[$i]->options->timestamp == 0) {
$feed->items[$i]->options->timestamp = time();
}
}
}
return $feed;
}