function ip_geoloc_use_geoip_api_if_enabled in IP Geolocation Views & Maps 8
Same name and namespace in other branches
- 7 ip_geoloc.module \ip_geoloc_use_geoip_api_if_enabled()
Module GeoIP API does not expose a hook, but it does expose an API.
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_geoip_api_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 378 - 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_geoip_api_if_enabled(array &$location) {
if (!function_exists('geoip_city')) {
return FALSE;
}
$location['provider'] = 'geoip';
if (empty($location['ip_address'])) {
$location['ip_address'] = ip_address();
}
$geoip_location = (array) geoip_city($location['ip_address']);
if (reset($geoip_location)) {
// Where different, convert GeoIP names to our equivalents.
$geoip_location['country'] = isset($geoip_location['country_name']) ? $geoip_location['country_name'] : '';
unset($geoip_location['country_name']);
$location = array_merge($geoip_location, $location);
ip_geoloc_format_address($location);
}
ip_geoloc_debug(t('IPGV&M: GeoIP API retrieved: !location', [
'!location' => ip_geoloc_pretty_print($location),
]));
return TRUE;
}