From 2b2c5c8601aa62b13d8d926e9d58d24c9d051c7b Mon Sep 17 00:00:00 2001 From: MorganDawe Date: Wed, 27 Aug 2014 16:43:53 -0300 Subject: [PATCH] Updating extestion and mime detection on download to use drupals file_g=default_mimetype_mapping() funcitons. --- includes/datastream.inc | 4 ++-- includes/utilities.inc | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/includes/datastream.inc b/includes/datastream.inc index edc8ceb1..e31ed254 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -30,6 +30,7 @@ function islandora_download_datastream(AbstractDatastream $datastream) { * The version of the datastream to display */ function islandora_view_datastream(AbstractDatastream $datastream, $download = FALSE, $version = NULL) { + module_load_include('inc', 'islandora', 'includes/utilities'); // XXX: Certain features of the Devel module rely on the use of "shutdown // handlers", such as query logging... The problem is that they might blindly // add additional output which will break things if what is actually being @@ -45,7 +46,6 @@ function islandora_view_datastream(AbstractDatastream $datastream, $download = F return drupal_not_found(); } } - header('Content-type: ' . $datastream->mimetype); if ($datastream->controlGroup == 'M' || $datastream->controlGroup == 'X') { header('Content-length: ' . $datastream->size); @@ -53,7 +53,7 @@ function islandora_view_datastream(AbstractDatastream $datastream, $download = F if ($download) { // Browsers will not append all extensions. $mime_detect = new MimeDetect(); - $extension = '.' . $mime_detect->getExtension($datastream->mimetype); + $extension = '.' . islandora_get_extension_for_mimetype($datastream->mimetype);//$mime_detect->getExtension($datastream->mimetype); // Prevent adding on a duplicate extension. $label = $datastream->label; $extension_length = strlen($extension); diff --git a/includes/utilities.inc b/includes/utilities.inc index 26633df5..4892a4eb 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -46,6 +46,15 @@ function islandora_convert_bytes_to_human_readable($bytes, $precision = 2) { } } +function islandora_get_extension_for_mimetype($mimetype) { + module_load_include('inc', 'file', 'file.mimetypes.inc'); + dsm($mimetype, "mimetype"); + $mimetype_mapping = file_default_mimetype_mapping(); + $extenstion_index = array_search($mimetype, $mimetype_mapping['mimetypes']); + $extenstion = array_search($extenstion_index, $mimetype_mapping['extensions']); + dsm($extenstion, "extenstion"); + return $extenstion; +} /** * Add a file as managed if is not already. *