You are here

function filefield_paths_tokens in File (Field) Paths 7

Same name and namespace in other branches
  1. 8 filefield_paths.tokens.inc \filefield_paths_tokens()

Implements hook_tokens().

Parameters

$type:

$tokens:

array $data:

Return value

array

File

./filefield_paths.tokens.inc, line 39
Tokens for the File (Field) Paths module.

Code

function filefield_paths_tokens($type, $tokens, array $data = array()) {
  $url_options = array(
    'absolute' => TRUE,
  );
  if (isset($language)) {
    $url_options['language'] = $language;
  }
  $replacements = array();
  if ($type == 'file' && !empty($data['file'])) {
    $file = $data['file'];
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'ffp-name-only':
          $basename = drupal_basename($file->filename);
          $extension = preg_match('/\\.[^.]+$/', $basename, $matches) ? $matches[0] : NULL;
          $replacements[$original] = !is_null($extension) ? drupal_substr($basename, 0, drupal_strlen($basename) - drupal_strlen($extension)) : $basename;
          break;
        case 'ffp-name-only-original':
          $basename = drupal_basename($file->origname);
          $extension = preg_match('/\\.[^.]+$/', $basename, $matches) ? $matches[0] : NULL;
          $replacements[$original] = !is_null($extension) ? drupal_substr($basename, 0, drupal_strlen($basename) - drupal_strlen($extension)) : $basename;
          break;
        case 'ffp-extension-original':
          $replacements[$original] = preg_match('/[^.]+$/', drupal_basename($file->origname), $matches) ? $matches[0] : NULL;
          break;
      }
    }
  }
  return $replacements;
}