diff --git a/handlers/location_views_handler_filter_proximity.inc b/handlers/location_views_handler_filter_proximity.inc index 5a38acc..fd79a68 100644 --- a/handlers/location_views_handler_filter_proximity.inc +++ b/handlers/location_views_handler_filter_proximity.inc @@ -86,12 +86,15 @@ class location_views_handler_filter_proximity extends views_handler_filter { 'nid_arg' => t("Node's Latitude / Longitude from views nid argument"), 'uid_arg' => t("User's Latitude / Longitude from views uid argument"), ), - '#description' => t('This will be the way the latitude/longitude of origin is determined. If this filter is exposed, this will determine the default values. NOTE: The PHP code, nid argument and uid argument options will not be available when the filter is exposed and the use of map is only available when the filter is exposed.'), + '#description' => t('This will be the way the latitude/longitude of origin is determined. If this filter is exposed, this will determine the default values. NOTE: The PHP code, nid argument and uid argument options will not be available when the filter is exposed and the use of map is only available when the filter is exposed. To use the visitor\'s IP address, you must have the geoip module with the MaxMind GeoLiteCity installed.'), '#default_value' => $this->options['origin'] ? $this->options['origin'] : 'user', ); if (module_exists('gmap')) { $form['origin']['#options']['latlon_gmap'] = t('Latitude / Longitude input (use map)'); } + if (module_exists('geoip')) { + $form['origin']['#options']['geoip'] = t("IP Address of visitor (fall back to static if unset)"); + } // [11:44] If you load the page from scratch, $input for your identifier will be empty. // [11:44] So what's going on here is that for $_GET forms, there's no form id, no op button or anything, so they always appear to submit. @@ -121,7 +124,7 @@ class location_views_handler_filter_proximity extends views_handler_filter { '#title' => t('Latitude'), '#default_value' => $this->value['latitude'], '#process' => array('ctools_dependent_process'), - '#dependency' => array('edit-options-origin' => array('hybrid', 'static', 'latlon_gmap')), + '#dependency' => array('edit-options-origin' => array('hybrid', 'static', 'latlon_gmap', 'geoip')), '#weight' => 1, ); $form['value']['longitude'] = array( @@ -129,7 +132,7 @@ class location_views_handler_filter_proximity extends views_handler_filter { '#title' => t('Longitude'), '#default_value' => $this->value['longitude'], '#process' => array('ctools_dependent_process'), - '#dependency' => array('edit-options-origin' => array('hybrid', 'static', 'latlon_gmap')), + '#dependency' => array('edit-options-origin' => array('hybrid', 'static', 'latlon_gmap', 'geoip')), '#weight' => 2, ); diff --git a/location.views.inc b/location.views.inc index 58c5ff7..460899a 100644 --- a/location.views.inc +++ b/location.views.inc @@ -558,6 +558,18 @@ function location_views_proximity_get_reference_location($view, $options) { $coordinates['latitude'] = (float) $lat; $coordinates['longitude'] = (float) $lon; break; + case 'geoip': + if (module_exists('geoip')) { + if ($geoip_location = geoip_city()) { // intentional assignment of $geoip + $coordinates['latitude'] = $geoip_location->latitude; + $coordinates['longitude'] = $geoip_location->longitude; + } + } + else if ($options['latitude'] && $options['longitude']) { + $coordinates['latitude'] = (float) $options['latitude']; + $coordinates['longitude'] = (float) $options['longitude']; + } + break; }