You are here

function filefield_paths_token_values in File (Field) Paths 5

Same name and namespace in other branches
  1. 6.2 modules/token.inc \filefield_paths_token_values()
  2. 6 filefield_paths.module \filefield_paths_token_values()

Implementation of hook_token_values().

1 call to filefield_paths_token_values()
_filefield_paths_get_values in ./filefield_paths.module

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;
  }
}