You are here

function hook_aggregator_parse in Drupal 7

Create an alternative parser for aggregator module.

A parser converts feed item data to a common format. The parser is called at the second of the three aggregation stages: first, data is downloaded by the active fetcher; second, it is converted to a common format by the active parser; and finally, it is passed to all active processors which manipulate or store the data.

Modules that define this hook can be set as the active parser within the configuration page. Only one parser can be active at a time.

Parameters

$feed: An object describing the resource to be parsed. $feed->source_string contains the raw feed data. The hook implementation should parse this data and add the following properties to the $feed object:

  • description: The human-readable description of the feed.
  • link: A full URL that directly relates to the feed.
  • image: An image URL used to display an image of the feed.
  • etag: An entity tag from the HTTP header used for cache validation to determine if the content has been changed.
  • modified: The UNIX timestamp when the feed was last modified.
  • items: An array of feed items. The common format for a single feed item is an associative array containing:

    • title: The human-readable title of the feed item.
    • description: The full body text of the item or a summary.
    • timestamp: The UNIX timestamp when the feed item was last published.
    • author: The author of the feed item.
    • guid: The global unique identifier (GUID) string that uniquely identifies the item. If not available, the link is used to identify the item.
    • link: A full URL to the individual feed item.

Return value

TRUE if parsing was successful, FALSE otherwise.

See also

hook_aggregator_parse_info()

hook_aggregator_fetch()

hook_aggregator_process()

Related topics

1 function implements hook_aggregator_parse()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

aggregator_aggregator_parse in modules/aggregator/aggregator.parser.inc
Implements hook_aggregator_parse().
2 invocations of hook_aggregator_parse()
aggregator_admin_form in modules/aggregator/aggregator.admin.inc
Form constructor for the aggregator system settings.
aggregator_refresh in modules/aggregator/aggregator.module
Checks a news feed for new items.

File

modules/aggregator/aggregator.api.php, line 110
Documentation for aggregator API.

Code

function hook_aggregator_parse($feed) {
  if ($items = mymodule_parse($feed->source_string)) {
    $feed->items = $items;
    return TRUE;
  }
  return FALSE;
}