From d4783db6a314894b86d4ca9f3585e1a44d994ecb Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Thu, 28 Nov 2013 20:41:45 +0000 Subject: [PATCH 1/2] 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)); + } } From 25c6c4fe2a459ec7b358c553f3ca51b82d7a991e Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Fri, 29 Nov 2013 13:36:22 +0000 Subject: [PATCH 2/2] Coding standards. --- includes/mime_detect.inc | 2 +- includes/object_properties.form.inc | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/includes/mime_detect.inc b/includes/mime_detect.inc index c275f150..e76975d6 100644 --- a/includes/mime_detect.inc +++ b/includes/mime_detect.inc @@ -393,7 +393,7 @@ class MimeDetect { * An array of valid extensions for this MIME type. */ public function getValidExtensions($mimetype) { - $filter = function($mime) use ($mimetype) { + $filter = function ($mime) use ($mimetype) { return $mime == $mimetype; }; return array_keys(array_filter($this->protectedMimeTypes, $filter)); diff --git a/includes/object_properties.form.inc b/includes/object_properties.form.inc index 5295f067..676f0d0c 100644 --- a/includes/object_properties.form.inc +++ b/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) {