function datex_tokens in Datex 7.2
Implements hook_tokens().
File
- ./
datex.tokens.inc, line 56 - Token module integration.
Code
function datex_tokens($type, $tokens, array $data = array(), array $options = array()) {
$replacements = array();
if ($type == 'datex') {
$date = empty($data['date']) ? REQUEST_TIME : $data['date'];
foreach ($tokens as $name => $original) {
switch ($name) {
case 'short':
$format = variable_get('date_format_short');
$replacements[$original] = datex_format_date('fa', $date, $format);
break;
case 'medium':
$format = variable_get('date_format_short');
$replacements[$original] = datex_format_date('fa', $date, $format);
break;
case 'long':
$format = variable_get('date_format_short');
$replacements[$original] = datex_format_date('fa', $date, $format);
break;
}
}
if ($created_tokens = token_find_with_prefix($tokens, 'custom')) {
foreach ($created_tokens as $name => $original) {
list($calendar, $format) = @explode(':', $name);
if (isset($format) && _datex_calendar_is_valid($calendar)) {
$replacements[$original] = datex_format_date($calendar, $date, $format);
}
else {
watchdog(WATCHDOG_WARNING, 'Invalid token arguments for datex. Format is not given or requested calerndar is not available. Token replacement ignored.');
}
}
}
}
return $replacements;
}