function smart_ip_init in Smart IP 7
Same name and namespace in other branches
- 6.2 smart_ip.module \smart_ip_init()
- 6 smart_ip.module \smart_ip_init()
- 7.2 smart_ip.module \smart_ip_init()
Implements hook_init()
Allows geo location of anonymous users
File
- ./
smart_ip.module, line 90 - Determines country, geo location (longitude/latitude), region, city and postal code of the user, based on IP address
Code
function smart_ip_init() {
// Save a database hit. If there's already session data,
// don't check if we need to geolocate the anonymous role
$smart_ip_session = smart_ip_session_get('smart_ip');
if (empty($smart_ip_session['location'])) {
$roles_to_geo_locate = variable_get('smart_ip_roles_to_geolocate', array(
DRUPAL_AUTHENTICATED_RID,
));
if (in_array(DRUPAL_ANONYMOUS_RID, $roles_to_geo_locate)) {
global $user;
$location = smart_ip_get_current_visitor_location_data();
smart_ip_set_location_data($user, $location);
}
}
if (isset($smart_ip_session['location'])) {
// Make user geolocation available to javascript
drupal_add_js(array(
'smart_ip' => $smart_ip_session,
), 'setting');
}
}