From d4783db6a314894b86d4ca9f3585e1a44d994ecb Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Thu, 28 Nov 2013 20:41:45 +0000 Subject: [PATCH] Fix MimeDetect to allow checking MIMEs for multiple mapped values. --- includes/add_datastream.form.inc | 5 ++++- includes/mime_detect.inc | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/includes/add_datastream.form.inc b/includes/add_datastream.form.inc index 3a1d964d..33decefc 100644 --- a/includes/add_datastream.form.inc +++ b/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]); diff --git a/includes/mime_detect.inc b/includes/mime_detect.inc index 4035afe5..c275f150 100644 --- a/includes/mime_detect.inc +++ b/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)); + } }