function filefield_paths_token_values in File (Field) Paths 5
Same name and namespace in other branches
- 6.2 modules/token.inc \filefield_paths_token_values()
- 6 filefield_paths.module \filefield_paths_token_values()
Implementation of hook_token_values().
1 call to filefield_paths_token_values()
File
- ./
filefield_paths.module, line 501 - Adds extra functionality to FileFields Path settings.
Code
function filefield_paths_token_values($type, $object = NULL) {
if ($type == 'field') {
$item = pathinfo($object[0]['filename']);
$tokens = array();
$tokens['filefield-onlyname'] = $item['filename'];
$tokens['filefield-extension'] = $item['extension'];
// Original filename.
$orig = $item;
$filename = $object[0]['filename'];
if (!empty($object[0]['origname'])) {
$orig = pathinfo($object[0]['origname']);
$filename = $object[0]['origname'];
}
// PHP < 5.2: pathinfo() doesn't return 'filename' variable.
$tokens['filefield-onlyname-original'] = isset($orig['filename']) ? $orig['filename'] : basename($filename, '.' . $orig['extension']);
$tokens['filefield-extension-original'] = $orig['extension'];
// Tokens for Image module integration.
if (module_exists('image')) {
$tokens['image-derivative'] = isset($object[0]['type']) && $object[0]['type'] !== '_original' ? '.' . $object[0]['type'] : '';
}
return $tokens;
}
}