You are here

function smart_ip_init in Smart IP 7.2

Same name and namespace in other branches
  1. 6.2 smart_ip.module \smart_ip_init()
  2. 6 smart_ip.module \smart_ip_init()
  3. 7 smart_ip.module \smart_ip_init()

Implements hook_init()

Allows geo location of anonymous users

File

./smart_ip.module, line 112
Determines country, geo location (longitude/latitude), region, city and postal code of the user, based on IP address

Code

function smart_ip_init() {

  // Check to see if the page is one of those allowed for geolocation
  if (!smart_ip_check_allowed_page()) {

    // This page is not on the list to acquire/update user's geolocation
    return;
  }

  // Save a database hit
  $smart_ip_session = smart_ip_session_get('smart_ip');
  if (isset($smart_ip_session['location'])) {

    // Make user geolocation available to javascript
    drupal_add_js(array(
      'smart_ip' => $smart_ip_session,
      'smart_ip_src' => array(
        'smart_ip' => SMART_IP_SOURCE_SMART_IP,
        'geocoded_smart_ip' => SMART_IP_SOURCE_GEOCODED_SMART_IP,
        'w3c' => SMART_IP_SOURCE_W3C,
      ),
    ), 'setting');
  }
}