File class no longer depends on MIME
+ minor tweaks to MediaFile
This commit is contained in:
parent
6faed0e451
commit
639f1a01e0
|
@ -265,20 +265,13 @@ class File extends Managed_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();
|
||||
$ext = $mte->getExtension($mimetype);
|
||||
if (PEAR::isError($ext)) {
|
||||
$ext = strtolower(preg_replace('/\W/', '', $mimetype));
|
||||
try {
|
||||
$ext = common_supported_mime_to_ext($mimetype);
|
||||
} catch (Exception $e) {
|
||||
// We don't support this mimetype, but let's guess the extension
|
||||
$ext = substr(strrchr($mimetype, '/'), 1);
|
||||
}
|
||||
|
||||
// Restore error handling.
|
||||
PEAR::staticPopErrorHandling();
|
||||
|
||||
$nickname = $profile->nickname;
|
||||
$datestamp = strftime('%Y%m%dT%H%M%S', time());
|
||||
$random = strtolower(common_confirmation_code(32));
|
||||
|
|
|
@ -298,9 +298,11 @@ class MediaFile
|
|||
|
||||
// If we didn't match, or it is an unclear match
|
||||
if ($originalFilename && (!$mimetype || in_array($mimetype, $unclearTypes))) {
|
||||
try {
|
||||
$type = common_supported_ext_to_mime($originalFilename);
|
||||
if (!empty($type)) {
|
||||
return $type;
|
||||
} catch (Exception $e) {
|
||||
// Extension not found, so $mimetype is our best guess
|
||||
}
|
||||
}
|
||||
|
||||
|
|
15
lib/util.php
15
lib/util.php
|
@ -1812,7 +1812,20 @@ function common_supported_ext_to_mime($fileext)
|
|||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
throw new ServerException('Unsupported file extension');
|
||||
}
|
||||
|
||||
// Match by our supported mime types
|
||||
function common_supported_mime_to_ext($mimetype)
|
||||
{
|
||||
$supported = common_config('attachments', 'supported');
|
||||
foreach($supported as $type => $ext) {
|
||||
if ($mimetype === $type) {
|
||||
return $ext;
|
||||
}
|
||||
}
|
||||
|
||||
throw new ServerException('Unsupported MIME type');
|
||||
}
|
||||
|
||||
// The MIME "media" is the part before the slash (video in video/webm)
|
||||
|
|
Loading…
Reference in New Issue
Block a user