You are here

function geofield_feeds_combined_source in Geofield 7

Same name and namespace in other branches
  1. 7.2 geofield.feeds.inc \geofield_feeds_combined_source()

Callback; Provides a source combining geo information from items.

Currently handles geo output from:

  • simplepie 1.3
  • common syndication parser (feeds 7.x-2.x)

Parameters

$source: The FeedsSource object being imported.

$result: The FeedsParserResult object being mapped from.

$key: The key specified in the $sources array in hook_feeds_parser_sources_alter().

Return value

The value to be extracted from the source.

See also

geofield_feeds_parser_sources_alter()

1 string reference to 'geofield_feeds_combined_source'
geofield_feeds_parser_sources_alter in ./geofield.feeds.inc
Implementation of hook_feeds_parser_sources_alter().

File

./geofield.feeds.inc, line 41
Provides integration with Feeds module (http://drupal.org/project/feeds)

Code

function geofield_feeds_combined_source($source, FeedsParserResult $result, $key) {
  $values = array();
  $item = $result
    ->currentItem();

  // Simplepie 1.3 output
  if (isset($item['location_latitude'])) {

    // Lon X; lat Y
    foreach ($item['location_latitude'] as $key => $lat) {
      $point = array(
        'lat' => $lat,
        'lon' => $item['location_longitude'][$key],
      );
      $values[] = geofield_compute_values($point, 'latlon');
    }
  }
  elseif (isset($item['geolocations'][0]) && is_a($item['geolocations'][0], 'FeedsGeoTermElement')) {

    // Presently Common Syndication Parser is just parsing points?
    // and is creating FeedsGeoTermElements, which is possibly not so useful.
    // Maybe better if we could read access the original item, or add in to the item parsing?
    foreach ($item['geolocations'] as $geolocation) {
      $point = array(
        'lat' => $geolocation->lat,
        'lon' => $geolocation->lon,
      );
      $values[] = geofield_compute_values($point, 'latlon');
    }
  }
  return $values;
}