You are here

function geoip_tokens in GeoIP API 7.2

Implements hook_tokens().

File

./geoip.tokens.inc, line 46
Token callbacks for the geoip module.

Code

function geoip_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();
  if ($type == 'user') {
    foreach ($tokens as $token => $placeholder) {
      switch ($token) {

        // Replace continent code tokens.
        case 'geoip-continent-code':
          $replacements[$placeholder] = geoip_continent_code();
          break;

        // Replace continent name tokens.
        case 'geoip-continent-name':
          $continent_name = geoip_continent_name();
          $replacements[$placeholder] = !empty($continent_name) ? $continent_name : t('Unknown');
          break;

        // Replace region code tokens.
        case 'geoip-region-code':
          $replacements[$placeholder] = geoip_region_code();
          break;

        // Replace region name tokens.
        case 'geoip-region-name':
          $region_name = geoip_region_name();
          $replacements[$placeholder] = !empty($region_name) ? $region_name : t('Unknown');
          break;

        // Replace country code tokens.
        case 'geoip-country-code':
          $replacements[$placeholder] = geoip_country_code();
          break;

        // Replace country name tokens.
        case 'geoip-country-name':
          $country_name = geoip_country_name();
          $replacements[$placeholder] = !empty($country_name) ? $country_name : t('Unknown');
          break;
      }
    }
  }
  return $replacements;
}