Projet

Général

Profil

Révision f842d52a

Ajouté par Julien Enselme il y a presque 10 ans

Update to 7.28

Voir les différences:

drupal7/includes/file.inc
1999 1999
  $target = implode('/', $args);
2000 2000
  $uri = $scheme . '://' . $target;
2001 2001
  if (file_stream_wrapper_valid_scheme($scheme) && file_exists($uri)) {
2002
    // Let other modules provide headers and controls access to the file.
2003
    // module_invoke_all() uses array_merge_recursive() which merges header
2004
    // values into a new array. To avoid that and allow modules to override
2005
    // headers instead, use array_merge() to merge the returned arrays.
2006
    $headers = array();
2007
    foreach (module_implements('file_download') as $module) {
2008
      $function = $module . '_file_download';
2009
      $result = $function($uri);
2010
      if ($result == -1) {
2011
        // Throw away the headers received so far.
2012
        $headers = array();
2013
        break;
2014
      }
2015
      if (isset($result) && is_array($result)) {
2016
        $headers = array_merge($headers, $result);
2017
      }
2018
    }
2002
    $headers = file_download_headers($uri);
2019 2003
    if (count($headers)) {
2020 2004
      file_transfer($uri, $headers);
2021 2005
    }
......
2027 2011
  drupal_exit();
2028 2012
}
2029 2013

  
2014
/**
2015
 * Retrieves headers for a private file download.
2016
 *
2017
 * Calls all module implementations of hook_file_download() to retrieve headers
2018
 * for files by the module that originally provided the file. The presence of
2019
 * returned headers indicates the current user has access to the file.
2020
 *
2021
 * @param $uri
2022
 *   The URI for the file whose headers should be retrieved.
2023
 *
2024
 * @return
2025
 *   If access is allowed, headers for the file, suitable for passing to
2026
 *   file_transfer(). If access is not allowed, an empty array will be returned.
2027
 *
2028
 * @see file_transfer()
2029
 * @see file_download_access()
2030
 * @see hook_file_downlaod()
2031
 */
2032
function file_download_headers($uri) {
2033
  // Let other modules provide headers and control access to the file.
2034
  // module_invoke_all() uses array_merge_recursive() which merges header
2035
  // values into a new array. To avoid that and allow modules to override
2036
  // headers instead, use array_merge() to merge the returned arrays.
2037
  $headers = array();
2038
  foreach (module_implements('file_download') as $module) {
2039
    $function = $module . '_file_download';
2040
    $result = $function($uri);
2041
    if ($result == -1) {
2042
      // Throw away the headers received so far.
2043
      $headers = array();
2044
      break;
2045
    }
2046
    if (isset($result) && is_array($result)) {
2047
      $headers = array_merge($headers, $result);
2048
    }
2049
  }
2050
  return $headers;
2051
}
2052

  
2053
/**
2054
 * Checks that the current user has access to a particular file.
2055
 *
2056
 * The return value of this function hinges on the return value from
2057
 * file_download_headers(), which is the function responsible for collecting
2058
 * access information through hook_file_download().
2059
 *
2060
 * If immediately transferring the file to the browser and the headers will
2061
 * need to be retrieved, the return value of file_download_headers() should be
2062
 * used to determine access directly, so that access checks will not be run
2063
 * twice.
2064
 *
2065
 * @param $uri
2066
 *   The URI for the file whose access should be retrieved.
2067
 *
2068
 * @return
2069
 *   Boolean TRUE if access is allowed. FALSE if access is not allowed.
2070
 *
2071
 * @see file_download_headers()
2072
 * @see hook_file_download()
2073
 */
2074
function file_download_access($uri) {
2075
  return count(file_download_headers($uri)) > 0;
2076
}
2030 2077

  
2031 2078
/**
2032 2079
 * Finds all files that match a given mask in a given directory.

Formats disponibles : Unified diff