function sheetnode_tokens in Sheetnode 7
Same name and namespace in other branches
- 7.2 sheetnode.module \sheetnode_tokens()
Implements hook_tokens().
File
- ./
sheetnode.module, line 380 - Module file for the sheetnode module.
Code
function sheetnode_tokens($type, $tokens, array $data = array(), array $options = array()) {
$replacements = array();
$sanitize = !empty($options['sanitize']);
if ($type == 'sheet' && !empty($data['sheet'])) {
module_load_include('inc', 'sheetnode', 'socialcalc');
$socialcalc = socialcalc_parse($data['sheet']);
$sc = $socialcalc['sheet'];
foreach ($tokens as $name => $original) {
switch ($name) {
default:
list($token, $coord) = explode(':', $name, 2);
if ($token == 'cell' && isset($sc['cells'][$coord])) {
$c = $sc['cells'][$coord];
$replacements[$original] = isset($c['datavalue']) ? $c['datavalue'] : '';
}
break;
}
}
}
if ($type == 'node' && !empty($data['node']) && $data['node']->type == 'sheetnode') {
$node = $data['node'];
foreach ($tokens as $name => $original) {
switch ($name) {
case 'sheetnode':
$replacements[$original] = $node->sheetnode['value'];
break;
}
}
if ($sheet_tokens = token_find_with_prefix($tokens, 'sheetnode')) {
$replacements += token_generate('sheet', $sheet_tokens, array(
'sheet' => $node->sheetnode['value'],
), $options);
}
}
return $replacements;
}