Browse Source

Updated file extension logic on ds download.

pull/543/head
MorganDawe 10 years ago
parent
commit
8efd0c23fc
  1. 1
      includes/mime_detect.inc
  2. 29
      includes/utilities.inc
  3. 1
      islandora.module

1
includes/mime_detect.inc

@ -134,7 +134,6 @@ class MimeDetect {
'xhtml' => 'application/xhtml+xml', 'xhtml' => 'application/xhtml+xml',
'xsl' => 'text/xsl', 'xsl' => 'text/xsl',
'xslt' => 'text/xsl', 'xslt' => 'text/xsl',
'xml' => 'application/xml',
'csv' => 'text/csv', 'csv' => 'text/csv',
'tsv' => 'text/tab-separated-values', 'tsv' => 'text/tab-separated-values',
'txt' => 'text/plain', 'txt' => 'text/plain',

29
includes/utilities.inc

@ -46,15 +46,30 @@ function islandora_convert_bytes_to_human_readable($bytes, $precision = 2) {
} }
} }
/**
* Retrieve the correct file extension for a give mimetype.
*
* @param string $mimetype
* The mimetype whose extension is required.
*
* @return string
* The extension mapped to the given mimetype.
*/
function islandora_get_extension_for_mimetype($mimetype) { function islandora_get_extension_for_mimetype($mimetype) {
module_load_include('inc', 'file', 'file.mimetypes.inc'); require_once(DRUPAL_ROOT . '/includes/file.mimetypes.inc');
dsm($mimetype, "mimetype");
$mimetype_mapping = file_default_mimetype_mapping(); $mimetype_mapping = file_mimetype_mapping();
$extenstion_index = array_search($mimetype, $mimetype_mapping['mimetypes']); $extension_index = array_search($mimetype, $mimetype_mapping['mimetypes']);
$extenstion = array_search($extenstion_index, $mimetype_mapping['extensions']); $mime_array_flipped = array_reverse($mimetype_mapping['extensions']);
dsm($extenstion, "extenstion"); $extension = array_search($extension_index, $mime_array_flipped);
return $extenstion;
// We can only have one mapping in drupal for 'xml'.
if ($mimetype == "text/xml") {
return "xml";
} }
return $extension;
}
/** /**
* Add a file as managed if is not already. * Add a file as managed if is not already.
* *

1
islandora.module

@ -1590,6 +1590,7 @@ function islandora_download_clip(AbstractObject $object) {
function islandora_file_mimetype_mapping_alter(&$mapping) { function islandora_file_mimetype_mapping_alter(&$mapping) {
$mime_detect = new MimeDetect(); $mime_detect = new MimeDetect();
$types = $mime_detect->getMimeTypes(); $types = $mime_detect->getMimeTypes();
$diff = array_diff_key($types, $mapping['extensions']); $diff = array_diff_key($types, $mapping['extensions']);
foreach ($diff as $ext => $mime) { foreach ($diff as $ext => $mime) {
$mapping['mimetypes'][] = $mime; $mapping['mimetypes'][] = $mime;

Loading…
Cancel
Save