Browse Source

Merge pull request #433 from jordandukart/7.x-mimedetect

Fix MimeDetect to allow checking MIMEs for multiple mapped values.
pull/437/head
Jonathan Green 11 years ago
parent
commit
3a82b75720
  1. 5
      includes/add_datastream.form.inc
  2. 15
      includes/mime_detect.inc
  3. 10
      includes/object_properties.form.inc

5
includes/add_datastream.form.inc

@ -161,7 +161,10 @@ function islandora_add_datastream_form_validate(array $form, array &$form_state)
if (isset($form_state['datastream_requirements'][$dsid]) && $file) {
$allowed_types = $form_state['datastream_requirements'][$dsid]['mime'];
$mime_detect = new MimeDetect();
$allowed_extensions = array_map(array($mime_detect, 'getExtension'), $allowed_types);
$allowed_extensions = array();
foreach ($allowed_types as $mime) {
$allowed_extensions = array_merge($allowed_extensions, $mime_detect->getValidExtensions($mime));
}
$errors = file_validate_extensions($file, implode(' ', $allowed_extensions));
if (count($errors) > 0) {
form_set_error('file', $errors[0]);

15
includes/mime_detect.inc

@ -383,4 +383,19 @@ class MimeDetect {
return $this->protectedMimeTypes;
}
/**
* Get all valid extensions for this MIME type.
*
* @param string $mimetype
* The MIME type we are searching for.
*
* @return array
* An array of valid extensions for this MIME type.
*/
public function getValidExtensions($mimetype) {
$filter = function ($mime) use ($mimetype) {
return $mime == $mimetype;
};
return array_keys(array_filter($this->protectedMimeTypes, $filter));
}
}

10
includes/object_properties.form.inc

@ -166,15 +166,15 @@ function islandora_object_properties_form_delete(array $form, array &$form_state
/**
* Updates object state.
*
* @param String $pid
* @param string $pid
* PID of object to be updated
* @param Boolean $update_states
* @param bool $update_states
* If TRUE, update object state
* @param String $state
* @param string $state
* Desired object state
* @param Boolean $update_owners
* @param bool $update_owners
* If TRUE, update Owner
* @param String $owner
* @param string $owner
* New Owner
*/
function islandora_update_object_properties($pid, $update_states, $state, $update_owners, $owner) {

Loading…
Cancel
Save