From 28c0c6197a7004256673b8894abe050d404691c2 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Fri, 10 Mar 2006 19:02:06 +0000 Subject: - Patch #52092 by wtanaka, dopry and moshe: fixed regression with hook_file_download. --- includes/file.inc | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'includes') diff --git a/includes/file.inc b/includes/file.inc index 15d5b376f..60d176892 100644 --- a/includes/file.inc +++ b/includes/file.inc @@ -565,27 +565,28 @@ function file_transfer($source, $headers) { /** * Call modules that implement hook_file_download() to find out if a file is - * accessible for a given user. If a module returns an array of headers, the - * download will start. If a module denies it, drupal_access_denied() will be - * called. If no module responds then drupal_not_found() will be called. + * accessible and what headers it should be transferred with. If a module + * returns -1 drupal_access_denied() will be returned. If one or more modules + * returned headers the download will start with the returned headers. If no + * modules respond drupal_not_found() will be returned. */ + function file_download() { - $file = $_GET['file']; - if (file_exists(file_create_path($file))) { - $list = module_list(); - foreach ($list as $module) { - $headers = module_invoke($module, 'file_download', $file); - if (is_array($headers)) { - file_transfer($file, $headers); - } - elseif ($headers == -1) { - drupal_access_denied(); - } + $filepath = $_GET['file']; + + if (file_exists(file_create_path($filepath))) { + $headers = module_invoke_all('file_download', $filepath); + if (in_array(-1, $headers)) { + return drupal_access_denied(); + } + if (count($headers)) { + file_transfer($filepath, $headers); } } - drupal_not_found(); + return drupal_not_found(); } + /** * Finds all files that match a given mask in a given * directory. -- cgit v1.2.3