You are here

function pathfilter_filefield_paths_process_file in File (Field) Paths 6.2

Same name and namespace in other branches
  1. 6 modules/pathfilter.inc \pathfilter_filefield_paths_process_file()

Implements hook_filefield_paths_process_file().

File

modules/pathfilter.inc, line 10
Provides FileField Paths integration with the Path Filter module.

Code

function pathfilter_filefield_paths_process_file($new, &$file, $settings, &$node, &$update) {
  if ($new && dirname($file['filepath']['new']) != dirname($file['filepath']['old']) || $file['filename']['new'] != $file['filename']['old']) {
    $file_directory_path = variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC ? file_directory_path() : 'system/files';

    // Regular expression to replace old file reference.
    $pattern = array(
      'regex' => 'files:([^"]*?)' . str_replace('/', '\\/', str_replace(file_directory_path() . '/', '', $file['filepath']['old'])),
      'regex_enc' => 'files:([^"]*?)' . str_replace('/', '\\/', str_replace(drupal_urlencode(file_directory_path()) . '/', '', drupal_urlencode($file['filepath']['old']))),
      'replace' => 'files:$1' . str_replace(file_directory_path() . '/', '', $file['filepath']['new']),
    );

    // Process regular expression.
    _filefield_paths_replace_pattern($pattern, $node, $update);
  }
}