function token_get_info in Token 7
Retrieve, sort, store token info from the cache.
Parameters
$token_type: The optional token type that if specified will return $info['types'][$token_type].
$token: The optional token name if specified will return $info['tokens'][$token_type][$token].
Return value
An array of all token information from hook_token_info(), or the array of a token type or specific token.
See also
8 calls to token_get_info()
- theme_token_tree in ./token.pages.inc 
- Provide a 'tree' display of nested tokens.
- token_get_global_token_types in ./token.module 
- Get a list of token types that can be used without any context (global).
- token_get_invalid_tokens in ./token.module 
- Validate an array of tokens based on their token type.
- token_get_invalid_tokens_by_context in ./token.module 
- Validate an tokens in raw text based on possible contexts.
- token_tokens in ./token.tokens.inc 
- Implements hook_tokens().
1 string reference to 'token_get_info'
- token_clear_cache in ./token.module 
- Clear token caches and static variables.
File
- ./token.module, line 502 
- Enhances the token API in core: adds a browseable UI, missing tokens, etc.
Code
function token_get_info($token_type = NULL, $token = NULL) {
  global $language;
  // Use the advanced drupal_static() pattern, since this is called very often.
  static $drupal_static_fast;
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast['token_info'] =& drupal_static(__FUNCTION__);
  }
  $token_info =& $drupal_static_fast['token_info'];
  if (empty($token_info)) {
    $cid = "info:{$language->language}";
    if ($cache = cache_get($cid, 'cache_token')) {
      $token_info = $cache->data;
    }
    else {
      $token_info = token_info();
      foreach (array_keys($token_info['types']) as $type_key) {
        if (isset($token_info['types'][$type_key]['type'])) {
          $base_type = $token_info['types'][$type_key]['type'];
          // If this token type extends another token type, then merge in
          // the base token type's tokens.
          if (isset($token_info['tokens'][$base_type])) {
            $token_info['tokens'] += array(
              $type_key => array(),
            );
            $token_info['tokens'][$type_key] += $token_info['tokens'][$base_type];
          }
        }
        else {
          // Add a 'type' value to each token type so we can properly use
          // token_type_load().
          $token_info['types'][$type_key]['type'] = $type_key;
        }
      }
      // Pre-sort tokens.
      uasort($token_info['types'], 'token_asort_tokens');
      foreach (array_keys($token_info['tokens']) as $type) {
        uasort($token_info['tokens'][$type], 'token_asort_tokens');
      }
      // Store info in cache for future use.
      cache_set($cid, $token_info, 'cache_token');
    }
  }
  if (isset($token_type) && isset($token)) {
    return isset($token_info['tokens'][$token_type][$token]) ? $token_info['tokens'][$token_type][$token] : NULL;
  }
  elseif (isset($token_type)) {
    return isset($token_info['types'][$token_type]) ? $token_info['types'][$token_type] : NULL;
  }
  else {
    return $token_info;
  }
}