You are here

function global_filter_extract_proximity in Views Global Filter 8

Same name and namespace in other branches
  1. 7 widgets/global_filter.proximitywidget.inc \global_filter_extract_proximity()

Convert the input (or lack thereof) to lat,lon coordinates and a distance.

@todo use of visitor location and geocoding services is currently hardcoded. Should perhaps be a hook?

Parameters

array $form_state: the form state

Return value

object containing entered values as well as calculated lat,lon

1 call to global_filter_extract_proximity()
global_filter_set_form_on_session in ./global_filter.widgets.inc
Stashes the selected global filter value(s) in the user's session.

File

widgets/global_filter.proximitywidget.inc, line 73
global_filter.proximitywidget.inc

Code

function global_filter_extract_proximity($form_state) {
  $lat = $lon = 0.0;
  $location = trim($form_state['values']['location']);
  if (empty($location) || $location == 'me' || $location == t('me')) {
    if (module_exists('ip_geoloc')) {
      $visitor_location = ip_geoloc_get_visitor_location();
      if (isset($visitor_location['latitude'])) {
        $lat = $visitor_location['latitude'];
        $lon = $visitor_location['longitude'];
      }
    }
  }
  elseif (module_exists('geocoder')) {
    $geocoder_engines = array_keys(geocoder_handler_info('text'));
    $geocoder_engine = in_array('google', $geocoder_engines) ? 'google' : reset($geocoder_engines);
    if ($geocoded_data = geocoder($geocoder_engine, $location)) {
      $lat = $geocoded_data
        ->getY();
      $lon = $geocoded_data
        ->getX();
    }
  }
  $proximity = new stdClass();
  $proximity->location = $location;
  $proximity->distance = trim($form_state['values']['distance']);
  $proximity->latitude = $lat;
  $proximity->longitude = $lon;
  return $proximity;
}