function webform_protected_downloads_tokens in Webform Protected Downloads 7
Same name and namespace in other branches
- 8 webform_protected_downloads.module \webform_protected_downloads_tokens()
Implements of hook_tokens().
File
- ./
webform_protected_downloads.module, line 1139 - This file contains hook declarations and functions for the Webform Protected Downloads module.
Code
function webform_protected_downloads_tokens($type, $tokens, array $data = array(), array $options = array()) {
$replacements = array();
if ($type == 'protected-downloads') {
$node = $data['node'];
// fill basic tokens
$hash = webform_protected_downloads_get_hash_details($data['hash']);
$expires = $hash->expires > 0 ? format_date($hash->expires) : t('never');
if (isset($tokens['download-url'])) {
$replacements[$tokens['download-url']] = url('node/' . $node->nid . '/download/' . $hash->hash, array(
'absolute' => TRUE,
));
}
if (isset($tokens['download-expires'])) {
$replacements[$tokens['download-expires']] = $expires;
}
// fill file list tokens
$theme_function = 'webform_protected_downloads_mail_token_file_list';
if (isset($tokens['file-list'])) {
$replacements[$tokens['file-list']] = theme($theme_function, array(
'files' => $node->wpd['private_files'],
));
}
if (isset($tokens['file-list-checksum'])) {
$replacements[$tokens['file-list-checksum']] = theme($theme_function, array(
'files' => $node->wpd['private_files'],
'checksum' => TRUE,
));
}
}
return $replacements;
}