You are here

function _feedapi_call_parsers in FeedAPI 5

Same name and namespace in other branches
  1. 6 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

2 calls to _feedapi_call_parsers()
_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 950
Handle the submodules (for feed and item processing) Provide a basic management of feeds

Code

function _feedapi_call_parsers($feed, $parsers) {
  $nid = $feed->nid;
  $parser_primary = array_shift($parsers);
  $parsers_secondary = $parsers;
  if (module_exists($parser_primary)) {
    $feed->feed_type = module_invoke($parser_primary, 'feedapi_feed', 'compatible', $feed);
    $parser_output = module_invoke($parser_primary, 'feedapi_feed', 'parse', $feed);
    if ($parser_output === FALSE) {
      return $parser_output;
    }
    $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) {
    $feed_ext = module_invoke($parser, 'feedapi_feed', 'parse', $feed, FALSE);
    $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) {
        $feed->items[$key]->options = (object) ((array) $feed->items[$key]->options + (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);
    foreach (array(
      'title',
      'description',
    ) as $property) {
      if (isset($feed->{$property})) {
        if (is_string($feed->{$property})) {
          $feed->{$property} = filter_xss($feed->{$property}, $allowed);
        }
      }
    }
    for ($i = 0; $i < count($feed->items); $i++) {
      $feed->items[$i]->title = filter_xss($feed->items[$i]->title, $allowed);
      $feed->items[$i]->description = filter_xss($feed->items[$i]->description, $allowed);
      if ($feed->items[$i]->options->timestamp == 0) {
        $feed->items[$i]->options->timestamp = time();
      }
    }
  }
  return $feed;
}