You are here

function file_aliases_nodeapi in File Aliases 5

Same name and namespace in other branches
  1. 6 file_aliases.module \file_aliases_nodeapi()

Implementation of hook_nodeapi().

File

./file_aliases.module, line 65

Code

function file_aliases_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'view':
      if (($ffp = filefield_paths_get_fields($node, $op)) == FALSE) {
        break;
      }
      foreach ($ffp['#files'] as &$file) {

        // Convert Upload.module file to Array
        if ($file['module'] == 'upload') {
          $file['field'] = (array) $file['field'];
        }
        if ($ffp['#settings'][$file['name']]['filealias']['display'] == TRUE) {
          $filefield_paths_alias = 'filefield_paths/alias/' . $file['field']['fid'];
          if (($alias = drupal_get_path_alias($filefield_paths_alias)) != $filefield_paths_alias) {
            $file['name'] = $file['name'] == 'upload' ? 'files' : $file['name'];
            if (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PRIVATE) {
              $file['field']['filepath'] = 'system/' . $file['field']['filepath'];
            }
            $node->content[$file['name']]['#value'] = str_replace($file['field']['filepath'], $alias, $node->content[$file['name']]['#value']);
            $node->content[$file['name']]['#value'] = str_replace($file['field']['description'], array_pop(explode('/', $alias)), $node->content[$file['name']]['#value']);
          }
        }

        // Convert Upload.module file back to Object
        if ($file['module'] == 'upload') {
          $file['field'] = (object) $file['field'];
        }
      }
      break;
  }
}