Browse Source

updated mimetype selection

pull/547/head
Alan Stanley 10 years ago
parent
commit
b7d20be402
  1. 14
      includes/datastream.version.inc
  2. 29
      includes/mimetype.utils.inc

14
includes/datastream.version.inc

@ -282,16 +282,12 @@ function islandora_datastream_version_replace_form($form, &$form_state, Abstract
$form_state['dsid'] = $datastream->id; $form_state['dsid'] = $datastream->id;
$form_state['object'] = $object; $form_state['object'] = $object;
$datastream_mime_map = islandora_get_object_extensions($object); $datastream_mime_map = islandora_get_object_extensions($object);
$mime_detect = new MimeDetect(); $mimes = $datastream_mime_map[$datastream->id]['mime'];
$ext = array(); $drupal_extensions = array();
if (isset($datastream_mime_map[$datastream->id])) { foreach ($mimes as $mime) {
foreach ($datastream_mime_map[$datastream->id]['mime'] as $key => $value) { $drupal_extensions = array_merge($drupal_extensions, islandora_get_extensions_for_mimetype($mime));
$extensions = $mime_detect->getValidExtensions($value);
$ext = array_merge($ext, $extensions);
} }
} $valid_extensions = implode(' ', $drupal_extensions);
$valid_extensions = implode(' ', $ext);
$valid_extensions .= ' ' . islandora_get_extension_for_mimetype($datastream->mimetype);
$upload_size = min((int) ini_get('post_max_size'), (int) ini_get('upload_max_filesize')); $upload_size = min((int) ini_get('post_max_size'), (int) ini_get('upload_max_filesize'));
return array( return array(
'dsid_fieldset' => array( 'dsid_fieldset' => array(

29
includes/mimetype.utils.inc

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @file * @file
* Mimetype specific utility functions. * Mimetype specific utility functions.
@ -20,8 +21,10 @@ function islandora_get_extension_for_mimetype($mimetype) {
$mimetype_mapping = file_mimetype_mapping(); $mimetype_mapping = file_mimetype_mapping();
$extension_index = array_search($mimetype, $mimetype_mapping['mimetypes']); $extension_index = array_search($mimetype, $mimetype_mapping['mimetypes']);
if ($extension_index !== FALSE) {
$mime_array_flipped = array_reverse($mimetype_mapping['extensions']); $mime_array_flipped = array_reverse($mimetype_mapping['extensions']);
$extension = array_search($extension_index, $mime_array_flipped); $extension = array_search($extension_index, $mime_array_flipped);
}
// We can only have one mapping in drupal for 'xml'. // We can only have one mapping in drupal for 'xml'.
if ($mimetype == "text/xml") { if ($mimetype == "text/xml") {
@ -29,3 +32,29 @@ function islandora_get_extension_for_mimetype($mimetype) {
} }
return $extension; return $extension;
} }
/**
* Retrieve all file extensions for a give mimetype.
*
* @param string $mimetype
* The mimetype whose extensions are required.
*
* @return array
* All known legal extensions.
*/
function islandora_get_extensions_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();
$index = array_search($mimetype, $mimetype_mapping['mimetypes']);
$extensions = array();
if ($index !== FALSE) {
$extensions = array_keys($mimetype_mapping['extensions'], $index);
}
// We can only have one mapping in drupal for 'xml'.
if ($mimetype == "text/xml") {
$extensions[] = 'xml';
}
return $extensions;
}
Loading…
Cancel
Save