You are here

function filefield_sources_file_access in FileField Sources 7

Same name and namespace in other branches
  1. 6 filefield_sources.module \filefield_sources_file_access()

Check the current user's access to a file through hook_file_download().

Parameters

$uri: A file URI as loaded from the database.

Return value

Boolean TRUE if the user has access, FALSE otherwise.

See also

file_download()

hook_file_download().

2 calls to filefield_sources_file_access()
filefield_source_reference_autocomplete in sources/reference.inc
Menu callback; autocomplete.js callback to return a list of files.
filefield_source_reference_value in sources/reference.inc
A #filefield_value_callback function.

File

./filefield_sources.module, line 427
Extend FileField to allow files from multiple sources.

Code

function filefield_sources_file_access($uri) {

  // Always allow access to public files.
  $scheme = file_uri_scheme($uri);
  if ($scheme === 'public') {
    return TRUE;
  }

  // Or if the current user has the "bypass file access" permission from the
  // File Entity module, then reuse of any file is permitted.
  if (user_access('bypass file access')) {
    return TRUE;
  }
  $headers = array();
  foreach (module_implements('file_download') as $module) {
    $function = $module . '_file_download';
    $result = $function($uri);
    if ($result == -1) {

      // Throw away the headers received so far.
      $headers = array();
      break;
    }
    if (isset($result) && is_array($result)) {
      $headers = array_merge($headers, $result);
    }
  }
  return !empty($headers);
}