]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #4079 detecting docx, xlsx, and pptx files in file plugin
authorCash Costello <cash.costello@gmail.com>
Sun, 17 Jun 2012 02:05:07 +0000 (22:05 -0400)
committerCash Costello <cash.costello@gmail.com>
Sun, 17 Jun 2012 02:05:07 +0000 (22:05 -0400)
mod/file/actions/file/upload.php
mod/file/start.php

index 5242cbda2c748752ef741837648616950b35183c..d72d04eb73f35b7ac1277048ad7d1df76b46be3a 100644 (file)
@@ -94,8 +94,31 @@ if (isset($_FILES['upload']['name']) && !empty($_FILES['upload']['name'])) {
                $filestorename = elgg_strtolower(time().$_FILES['upload']['name']);
        }
 
-       $mime_type = $file->detectMimeType($_FILES['upload']['tmp_name'], $_FILES['upload']['type']);
        $file->setFilename($prefix . $filestorename);
+       $mime_type = ElggFile::detectMimeType($_FILES['upload']['tmp_name'], $_FILES['upload']['type']);
+
+       // hack for Microsoft zipped formats
+       $info = pathinfo($_FILES['upload']['name']);
+       $office_formats = array('docx', 'xlsx', 'pptx');
+       if ($mime_type == "application/zip" && in_array($info['extension'], $office_formats)) {
+               switch ($info['extension']) {
+                       case 'docx':
+                               $mime_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
+                               break;
+                       case 'xlsx':
+                               $mime_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
+                               break;
+                       case 'pptx':
+                               $mime_type = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
+                               break;
+               }
+       }
+
+       // check for bad ppt detection
+       if ($mime_type == "application/vnd.ms-office" && $info['extension'] == "ppt") {
+               $mime_type = "application/vnd.ms-powerpoint";
+       }
+
        $file->setMimeType($mime_type);
        $file->originalfilename = $_FILES['upload']['name'];
        $file->simpletype = file_get_simple_type($mime_type);
index 1201292762ed0eb7364b9812cd1605c04abe67c4..172042332eed549849632fca410bae2f93573a3c 100644 (file)
@@ -240,11 +240,15 @@ function file_get_simple_type($mimetype) {
 
        switch ($mimetype) {
                case "application/msword":
+               case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
                        return "document";
                        break;
                case "application/pdf":
                        return "document";
                        break;
+               case "application/ogg":
+                       return "audio";
+                       break;
        }
 
        if (substr_count($mimetype, 'text/')) {
@@ -357,11 +361,15 @@ function file_icon_url_override($hook, $type, $returnvalue, $params) {
                $mapping = array(
                        'application/excel' => 'excel',
                        'application/msword' => 'word',
+                       'application/ogg' => 'music',
                        'application/pdf' => 'pdf',
                        'application/powerpoint' => 'ppt',
                        'application/vnd.ms-excel' => 'excel',
                        'application/vnd.ms-powerpoint' => 'ppt',
                        'application/vnd.oasis.opendocument.text' => 'openoffice',
+                       'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'word',
+                       'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'excel',
+                       'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'ppt',
                        'application/x-gzip' => 'archive',
                        'application/x-rar-compressed' => 'archive',
                        'application/x-stuffit' => 'archive',