From 6424a97495323e120811c29c61dc432becafd7bd Mon Sep 17 00:00:00 2001 From: Nelson Hart Date: Fri, 31 May 2013 15:11:56 -0300 Subject: [PATCH 1/3] include islandora mimetypes in drupal mimetype mappings --- includes/mime_detect.inc | 11 +++++++++++ islandora.module | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/includes/mime_detect.inc b/includes/mime_detect.inc index 0914f62b..c92b5a15 100644 --- a/includes/mime_detect.inc +++ b/includes/mime_detect.inc @@ -366,4 +366,15 @@ class MimeDetect { return $out; } + /** + * Gets MIME type array. + * + * @return array + * returns associative array with exts and mimetypes + */ + public function getMimeTypes() { + return $this->protectedMimeTypes; + } + } + diff --git a/islandora.module b/islandora.module index ad9e569e..db5147b3 100644 --- a/islandora.module +++ b/islandora.module @@ -1097,3 +1097,26 @@ function islandora_download_clip(AbstractObject $object) { } exit(); } + +/** + * Implements hook_file_mimetype_mapping_alter(). + * + * Grab custom islandora mime type list and add any missing ext/mimes to the drupal mapping + * + * @param array $mapping + * The Drupal mimetype mapping. + */ +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) { + if (!isset($mapping['extensions'][$ext])) { + $mapping['mimetypes'][] = $mime; + $last = end($mapping['mimetypes']); + reset($mapping['mimetypes']); + $key = array_search($mime, $mapping['mimetypes']); + $mapping['extensions'][$ext] = $key; + } + } +} \ No newline at end of file From 27f97e74cb28bb3b69adc373c9d7f2b0591ce0a1 Mon Sep 17 00:00:00 2001 From: Nelson Hart Date: Fri, 31 May 2013 15:16:29 -0300 Subject: [PATCH 2/3] coder review --- includes/mime_detect.inc | 1 - islandora.module | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/mime_detect.inc b/includes/mime_detect.inc index c92b5a15..d1fb058b 100644 --- a/includes/mime_detect.inc +++ b/includes/mime_detect.inc @@ -377,4 +377,3 @@ class MimeDetect { } } - diff --git a/islandora.module b/islandora.module index db5147b3..e7527a70 100644 --- a/islandora.module +++ b/islandora.module @@ -1119,4 +1119,4 @@ function islandora_file_mimetype_mapping_alter(&$mapping) { $mapping['extensions'][$ext] = $key; } } -} \ No newline at end of file +} From 1c39358457e49f682844987f5b203254f2a0bf52 Mon Sep 17 00:00:00 2001 From: Nelson Hart Date: Tue, 4 Jun 2013 09:33:46 -0300 Subject: [PATCH 3/3] code review changes --- includes/mime_detect.inc | 2 +- islandora.module | 16 +++++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/includes/mime_detect.inc b/includes/mime_detect.inc index 3c3741dd..13b66cc8 100644 --- a/includes/mime_detect.inc +++ b/includes/mime_detect.inc @@ -376,7 +376,7 @@ class MimeDetect { * Gets MIME type array. * * @return array - * returns associative array with exts and mimetypes + * Returns associative array with exts and mimetypes. */ public function getMimeTypes() { return $this->protectedMimeTypes; diff --git a/islandora.module b/islandora.module index 3899ddb9..d6c89e99 100644 --- a/islandora.module +++ b/islandora.module @@ -1113,22 +1113,16 @@ function islandora_download_clip(AbstractObject $object) { /** * Implements hook_file_mimetype_mapping_alter(). * - * Grab custom islandora mime type list and add any missing ext/mimes to the drupal mapping - * - * @param array $mapping - * The Drupal mimetype mapping. + * Grab custom islandora mime type list + * and add any missing ext/mimes to the drupal mapping */ 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) { - if (!isset($mapping['extensions'][$ext])) { - $mapping['mimetypes'][] = $mime; - $last = end($mapping['mimetypes']); - reset($mapping['mimetypes']); - $key = array_search($mime, $mapping['mimetypes']); - $mapping['extensions'][$ext] = $key; - } + $mapping['mimetypes'][] = $mime; + end($mapping['mimetypes']); + $mapping['extensions'][$ext] = key($mapping['mimetypes']); } }