You are here

function ip_geoloc_tokens in IP Geolocation Views & Maps 7

Same name and namespace in other branches
  1. 8 ip_geoloc.tokens.inc \ip_geoloc_tokens()

Implements hook_tokens().

File

./ip_geoloc.tokens.inc, line 37

Code

function ip_geoloc_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();
  if ($type == 'visitor-location') {
    $is_sanitize = !empty($options['sanitize']);
    $location = ip_geoloc_get_visitor_location();
    foreach ($tokens as $key => $original) {
      if (isset($location[$key])) {
        $replacements[$original] = $is_sanitize ? filter_xss_admin($location[$key]) : $location[$key];
      }
    }
    if (!empty($replacements['[visitor-location:formatted_address]'])) {
      $need_street = variable_get('ip_geoloc_return_address_street');
      $need_locality = variable_get('ip_geoloc_return_address_locality');
      $need_country = variable_get('ip_geoloc_return_address_country');
      $address = _ip_geoloc_custom_formatted_address($location, $need_street, $need_locality, $need_country);
      $replacements['[visitor-location:formatted_address]'] = $is_sanitize ? filter_xss_admin($address) : $address;
    }
  }
  return $replacements;
}