Browse Source

Merge pull request #543 from MorganDawe/7.x-EMIC-210

7.x emic 210
pull/546/head
ajstanley 10 years ago
parent
commit
9920669f4f
  1. 4
      includes/datastream.inc
  2. 1
      includes/mime_detect.inc
  3. 31
      includes/mimetype.utils.inc
  4. 1
      islandora.module

4
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/mimetype.utils');
// 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);
// Prevent adding on a duplicate extension.
$label = $datastream->label;
$extension_length = strlen($extension);

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',

31
includes/mimetype.utils.inc

@ -0,0 +1,31 @@
<?php
/**
* @file
* Mimetype specific utility functions.
*/
/**
* 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) {
// file.mimetypes.inc is a part of Drupal core, however is not
// automatically loaded. Manually require it.
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;
}

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