You are here

function ip_geoloc_use_smart_ip_if_enabled in IP Geolocation Views & Maps 8

Same name and namespace in other branches
  1. 7 ip_geoloc.module \ip_geoloc_use_smart_ip_if_enabled()

Use Smart IP (if enabled) to retrieve lat/long and address info.

Note that smart_ip_get_location() will invoke hook_smart_ip_get_location_alter($location), which we use to format the address.

Parameters

array $location: If $location['ip_address'] isn't filled out the current user's IP address will be used.

Return value

bool TRUE upon success, FALSE otherwise.

3 calls to ip_geoloc_use_smart_ip_if_enabled()
IpGeoLocAPI::getLocationByIp in src/Services/IpGeoLocAPI.php
Returns the location details associated with the supplied IP address.
ip_geoloc_get_location_by_ip in ./ip_geoloc_api.inc
Returns the location details associated with the supplied IP address.
_ip_geoloc_reinit_location in ./ip_geoloc.module
Reinitialises the supplied location array.

File

./ip_geoloc.module, line 344
IPGV&M is a mapping engine for Views that contain locations of entities and/or visitors. Google Maps, Leaflet and OpenLayers2 maps are all supported and available through this module. Using a number of optional sources IPGV&M also retrieves…

Code

function ip_geoloc_use_smart_ip_if_enabled(array &$location) {
  if (\Drupal::state()
    ->get('ip_geoloc_smart_ip_as_backup', FALSE)) {
    if (function_exists('smart_ip_get_location')) {
      if (empty($location['ip_address'])) {
        $location['ip_address'] = ip_address();
      }
      $fixed_address = isset($location['fixed_address']) ? $location['fixed_address'] : 0;
      $region = isset($location['region']) ? $location['region'] : 0;

      // See also: ip_geoloc_smart_ip_get_location_alter().
      $location = [
        'provider' => 'smart_ip',
        'fixed_address' => $fixed_address,
        'region' => $region,
      ] + smart_ip_get_location($location['ip_address']);
      return TRUE;
    }
    ip_geoloc_debug(t('IPGV&M: Smart IP configured as a backup, but is not enabled.'));
  }

  // $location['formatted_address'] = '';.
  return FALSE;
}