]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Fix for ticket #2853: fix for some unknown MIME type error cases by adjusting the...
authorBrion Vibber <brion@pobox.com>
Thu, 4 Nov 2010 00:05:26 +0000 (17:05 -0700)
committerBrion Vibber <brion@pobox.com>
Thu, 4 Nov 2010 00:05:26 +0000 (17:05 -0700)
classes/File.php
lib/mediafile.php

index da029e39b69b0641262faca5895971791ca1e593..c7c7658020eaf52b3a7e7ad8f4e7e490bb308f64 100644 (file)
@@ -217,12 +217,19 @@ class File extends Memcached_DataObject
     static function filename($profile, $basename, $mimetype)
     {
         require_once 'MIME/Type/Extension.php';
+
+        // We have to temporarily disable auto handling of PEAR errors...
+        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
+
         $mte = new MIME_Type_Extension();
-        try {
-            $ext = $mte->getExtension($mimetype);
-        } catch ( Exception $e) {
+        $ext = $mte->getExtension($mimetype);
+        if (PEAR::isError($ext)) {
             $ext = strtolower(preg_replace('/\W/', '', $mimetype));
         }
+
+        // Restore error handling.
+        PEAR::staticPopErrorHandling();
+
         $nickname = $profile->nickname;
         $datestamp = strftime('%Y%m%dT%H%M%S', time());
         $random = strtolower(common_confirmation_code(32));
index 23338cc0e1165ac9ac63c7403fdd06acd47e9e20..aad3575d729a900f0faa2102e9c13e234873864a 100644 (file)
@@ -278,6 +278,9 @@ class MediaFile
     static function getUploadedFileType($f, $originalFilename=false) {
         require_once 'MIME/Type.php';
         require_once 'MIME/Type/Extension.php';
+
+        // We have to disable auto handling of PEAR errors
+        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
         $mte = new MIME_Type_Extension();
 
         $cmd = &PEAR::getStaticProperty('MIME_Type', 'fileCmd');
@@ -330,6 +333,8 @@ class MediaFile
             }
         }
         if ($supported === true || in_array($filetype, $supported)) {
+            // Restore PEAR error handlers for our DB code...
+            PEAR::staticPopErrorHandling();
             return $filetype;
         }
         $media = MIME_Type::getMedia($filetype);
@@ -344,6 +349,8 @@ class MediaFile
             // TRANS: %s is the file type that was denied.
             $hint = sprintf(_('"%s" is not a supported file type on this server.'), $filetype);
         }
+        // Restore PEAR error handlers for our DB code...
+        PEAR::staticPopErrorHandling();
         throw new ClientException($hint);
     }