Calling all Drupal developers!
Help us get this on the first page of Digg. DIGG NOW!
Help us get this on the first page of Digg. DIGG NOW!
token_get_values($type = 'global', $object = NULL, $flush = FALSE, $options = array())
contributions/token/token.module, line 217
Return a list of valid substitution tokens and their values for the specified type.
type A flag indicating the class of substitution tokens to use. If an object is passed in the second param, 'type' should contain the object's type. For example, 'node', 'comment', or 'user'. If no type is specified, only 'global' site-wide substitution tokens are built.
object Optionally, the object to use for building substitution values. A node, comment, user, etc.
A keyed array containing the substitution tokens and the substition values for the passed-in type and object.
<?php
function token_get_values($type = 'global', $object = NULL, $flush = FALSE, $options = array()) {
static $tokens;
static $running;
// Flush the static token cache. Useful for processes that need to slog through
// huge numbers of tokens in a single execution cycle. Flushing it will keep
// them from burning through memory.
if ($flush || !isset($tokens)) {
$tokens = array();
}
// Since objects in PHP5 are always passed by reference, we ensure we're
// working on a copy of the object.
if (is_object($object)) {
$object = drupal_clone($object);
}
// Simple recursion check. This is to avoid content_view()'s potential
// for endless looping when a filter uses tokens, which load the content
// view, which calls the filter, which uses tokens, which...
if ($running) {
// We'll allow things to get two levels deep, but bail out after that
// without performing any substitutions.
$result = new stdClass();
$result->tokens = array();
$result->values = array();
return $result;
}
$running = TRUE;
token_include();
$id = _token_get_id($type, $object);
if (isset($tokens[$type][$id])) {
$tmp_tokens = $tokens[$type][$id];
}
else {
$tmp_tokens = module_invoke_all('token_values', $type, $object, $options);
$tokens[$type][$id] = $tmp_tokens;
}
// Special-case global tokens, as we always want to be able to process
// those substitutions.
if (!isset($tokens['global']['default'])) {
$tokens['global']['default'] = module_invoke_all('token_values', 'global');
}
$all = array_merge($tokens['global']['default'], $tokens[$type][$id]);
$result = new stdClass();
$result->tokens = array_keys($all);
$result->values = array_values($all);
$running = FALSE;
return $result;
}
?>