function hansel_replace_tokens in Hansel breadcrumbs 8
Same name and namespace in other branches
- 7 hansel.module \hansel_replace_tokens()
Replace tokens using token module, using the node or user from the path.
Parameters
string $input:
Return value
string
1 call to hansel_replace_tokens()
- hansel_get_breadcrumbs in ./
hansel.module - Generate breadcrumbs.
File
- ./
hansel.module, line 713 - Hansel module
Code
function hansel_replace_tokens($input, $token) {
global $user;
// Statically cache token type and object
static $token_type;
static $token_object;
// Check if token module is enabled and at least one token is used.
if (preg_match('/\\[.+\\]/', $input)) {
// Determine the context for the token replacement and load the node or user object.
if (!isset($token_type)) {
$token_type = 'global';
$token_object = NULL;
if (drupal_strtolower(hansel_arg(0)) == 'node' && is_numeric(hansel_arg(1))) {
$token_type = 'node';
$token_object = node_load(hansel_arg(1));
}
elseif (drupal_strtolower(hansel_arg(0)) == 'user') {
$token_type = 'user';
if (is_numeric(hansel_arg(1))) {
$token_object = user_load(hansel_arg(1));
}
else {
$token_object = $user;
}
}
}
// Replace tokens using token module.
$input = token_replace($input, array(
$token_type => $token_object,
));
}
// Replace [arg-N] tokens
$i = -1;
while ($arg = hansel_arg(++$i)) {
$input = str_replace("[arg-{$i}]", $arg, $input);
}
return $input;
}