You are here

function fe_paths_tokens in File Entity Paths 7.2

Implements hook_tokens().

File

./fe_paths.tokens.inc, line 31
Tokens for File Entity Paths module.

Code

function fe_paths_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $url_options = array(
    'absolute' => TRUE,
  );
  if (isset($language)) {
    $url_options['language'] = $language;
  }
  $sanitize = !empty($options['sanitize']);
  $replacements = array();
  if ($type == 'file' && !empty($data['file'])) {
    $file = $data['file'];
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'name-only':
          $info = pathinfo($file->filename);
          $replacements[$original] = $info['filename'];
          break;
        case 'name-only-original':
          $info = pathinfo($file->origname);
          $replacements[$original] = $info['filename'];
          break;
        case 'extension-original':
          $info = pathinfo($file->origname);

          // Devel themer provides files with no extensions. @todo: test how
          // will this work.
          $replacements[$original] = isset($info['extension']) ? $info['extension'] : '';
          break;
      }
    }
  }
  return $replacements;
}