function filefield_paths_token_values in File (Field) Paths 6
Same name and namespace in other branches
- 5 filefield_paths.module \filefield_paths_token_values()
- 6.2 modules/token.inc \filefield_paths_token_values()
Implements hook_token_values().
1 call to filefield_paths_token_values()
File
- ./
filefield_paths.module, line 606 - Contains core functions for the FileField Paths module.
Code
function filefield_paths_token_values($type, $object = NULL) {
if ($type == 'field') {
$item = pathinfo($object[0]['filename']);
$tokens = array();
if (!module_exists('filefield')) {
// PHP < 5.2: pathinfo() doesn't return 'filename' variable.
$tokens['filefield-onlyname'] = isset($item['filename']) ? $item['filename'] : basename($object[0]['filename'], ".{$item['extension']}");
$tokens['filefield-extension'] = $item['extension'];
}
// Original filename.
$orig = $item;
$filename = $object[0]['filename'];
$result = db_fetch_object(db_query("SELECT origname FROM {files} WHERE fid = %d", $object[0]['fid']));
if (!empty($result->origname)) {
$object[0]['origname'] = $result->origname;
}
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;
}
}