ip_geoloc.tokens.inc in IP Geolocation Views & Maps 8
Same filename and directory in other branches
Pending doc.
File
ip_geoloc.tokens.incView source
<?php
/**
* @file
* Pending doc.
*/
/**
* Implements hook_token_info().
*/
function ip_geoloc_token_info() {
$types['visitor-location'] = [
'name' => t('Visitor location'),
'description' => t("Tokens related to the visitor's location"),
];
$token_keys = [
'country',
'country_code',
'region',
'region_code',
'city',
'locality',
'route',
'street_number',
'postal_code',
'administrative_area_level_1',
'formatted_address',
'latitude',
'longitude',
'ip_address',
'provider',
];
$token_info = [];
foreach ($token_keys as $key) {
$name = str_replace('_', ' ', $key);
$token_info[$key] = [
'name' => $name,
'description' => t("Visitor's @name", [
'@name' => $name,
]),
];
}
$token_info['provider']['description'] = t('Provider of location, for example <em>user</em> or <em>google</em>');
return [
'types' => $types,
'tokens' => [
'visitor-location' => $token_info,
],
];
}
/**
* Implements hook_tokens().
*/
function ip_geoloc_tokens($type, $tokens, array $data = [], array $options = []) {
$replacements = [];
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];
}
}
}
return $replacements;
}
Functions
Name![]() |
Description |
---|---|
ip_geoloc_tokens | Implements hook_tokens(). |
ip_geoloc_token_info | Implements hook_token_info(). |