You are here

function filefield_paths_process_string in File (Field) Paths 6

Same name and namespace in other branches
  1. 8 filefield_paths.module \filefield_paths_process_string()
  2. 5 filefield_paths.module \filefield_paths_process_string()
  3. 7 filefield_paths.module \filefield_paths_process_string()

Process and cleanup strings.

1 call to filefield_paths_process_string()
filefield_paths_filefield_paths_process_file in ./filefield_paths.module
Implements hook_filefield_paths_process_file().

File

./filefield_paths.module, line 646
Contains core functions for the FileField Paths module.

Code

function filefield_paths_process_string($value, $type, $object, $settings = array()) {

  // Process string tokens.
  $placeholders = _filefield_paths_get_values($type, $object, module_exists('pathauto') && isset($settings['pathauto']) && $settings['pathauto']);
  $value = str_replace($placeholders['tokens'], $placeholders['values'], $value);

  // Transliterate string.
  if (module_exists('transliteration') && isset($settings['transliterate']) && $settings['transliterate']) {
    $value = transliteration_get($value);
    if ($type == 'field') {
      $paths = explode('/', $value);
      foreach ($paths as &$path) {
        $path = transliteration_clean_filename($path);
      }
      $value = implode('/', $paths);
    }
  }

  // Convert string to lower case.
  if (isset($settings['tolower']) && $settings['tolower'] || isset($settings['pathauto']) && $settings['pathauto'] && variable_get('pathauto_case', 0)) {

    // Convert string to lower case
    $value = drupal_strtolower($value);
  }

  // Ensure that there are no double-slash sequences due to empty token values.
  $value = preg_replace('/\\/+/', '/', $value);
  return $value;
}