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',
'xsl' => 'text/xsl',
'xslt' => 'text/xsl',
'xml' => 'application/xml',
'csv' => 'text/csv',
'tsv' => 'text/tab-separated-values',
'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) {
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;
require_once(DRUPAL_ROOT . '/includes/file.mimetypes.inc');
$mimetype_mapping = file_mimetype_mapping();
$extension_index = array_search($mimetype, $mimetype_mapping['mimetypes']);
$mime_array_flipped = array_reverse($mimetype_mapping['extensions']);
$extension = array_search($extension_index, $mime_array_flipped);
// 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.
*

1
islandora.module

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

Loading…
Cancel
Save