function ip_geoloc_init in IP Geolocation Views & Maps 7
Implements hook_init().
Due to the weight set in ip_geoloc.install this hook is called after all other hook_init() implementations have completed. hook_inits are called as the last step in _drupal_bootstrap_full(), file includes/common.inc Note that the {accesslog} is updated in statistics_exit(), i.e. after the page is loaded. This means that a second click may be required before the current position marker appears on the recent visitor map.
File
- ./
ip_geoloc.module, line 248 - 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_init() {
foreach (arg() as $arg) {
// Only works on Views pages that have a (dummy) contextual filter defined.
if ($arg == 'erase-location') {
$location = ip_geoloc_get_visitor_location();
if (empty($location['is_updated'])) {
// Wipe the current visitor location.
_ip_geoloc_set_session_value('location', NULL);
// ... now pretend to everyone it never happened
$_GET['q'] = str_replace('/erase-location', '', $_GET['q']);
return;
}
}
}
ip_geoloc_log_errors();
$location = ip_geoloc_get_visitor_location();
$reverse_geocode_client_timeout = _ip_geoloc_reverse_geocode_timeout();
if ($reverse_geocode_client_timeout || ip_geoloc_is_first_click()) {
// Not convinced this is desirable
_ip_geoloc_reinit_location($location, $reverse_geocode_client_timeout);
ip_geoloc_store_location($location);
_ip_geoloc_set_session_value('location', $location);
}
$scheduled_reverse_geocode = _ip_geoloc_check_location($location);
// 2nd condition is to avoid HTTP 503 error.
if ($scheduled_reverse_geocode && !variable_get('maintenance_mode', 0)) {
// Insert some javascript to first retrieve the user's lat/lon coords,
// HTML5 style (requiring the user to accept a browser prompt) and then
// optionally (default) use Google Maps API to reverse-geocode the lat/lon
// into a street address.
// This is all done via client-side calls, so the Drupal server will not
// rake up any calls against its Google-imposed quotum, i.e. the
// OVER_QUERY_LIMIT.
// When done, the javascript calls us back on the default menu callback,
// '/js/ip_geoloc/current_location', which receives the geolocation data
// from the Google Maps call via the $_POST variable and stores it on the
// session.
// Naturally all of this will only work if the browser is connected to
// the internet and has javascript enabled.
// See also: _ip_geoloc_process_find_me_ajax().
ip_geoloc_get_current_location();
_ip_geoloc_set_session_value('last_position_check', time());
}
}