Fixed extension in saved posts
This commit is contained in:
parent
1352aba438
commit
2bad17ebdb
3 changed files with 14 additions and 7 deletions
|
@ -501,14 +501,11 @@ class PostController
|
|||
if (!is_readable($path))
|
||||
throw new SimpleException('Post file is not readable');
|
||||
|
||||
$ext = substr($post->origName, strrpos($post->origName, '.') + 1);
|
||||
if (strpos($post->origName, '.') === false)
|
||||
$ext = 'dat';
|
||||
$fn = sprintf('%s_%s_%s.%s',
|
||||
$this->config->main->title,
|
||||
$post->id,
|
||||
join(',', array_map(function($tag) { return $tag->name; }, $post->getTags())),
|
||||
$ext);
|
||||
TextHelper::resolveMimeType($post->mimeType) ?: 'dat');
|
||||
$fn = preg_replace('/[[:^print:]]/', '', $fn);
|
||||
|
||||
$ttl = 60 * 60 * 24 * 14;
|
||||
|
|
|
@ -328,4 +328,16 @@ class TextHelper
|
|||
|
||||
return $future ? 'in ' . round($diff / $mul) . ' years' : round($diff / $prevMul) . ' years ago';
|
||||
}
|
||||
|
||||
public static function resolveMimeType($mimeType)
|
||||
{
|
||||
$mimeTypes = [
|
||||
'image/jpeg' => 'jpg',
|
||||
'image/gif' => 'gif',
|
||||
'image/png' => 'png',
|
||||
'application/x-shockwave-flash' => 'swf'];
|
||||
return isset($mimeTypes[$mimeType])
|
||||
? $mimeTypes[$mimeType]
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -163,11 +163,9 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
|
|||
<i class="icon-dl"></i>
|
||||
<span>
|
||||
<?php
|
||||
$mimes = ['image/jpeg' => 'jpg', 'image/gif' => 'gif', 'image/png' => 'png', 'application/x-shockwave-flash' => 'swf'];
|
||||
$mime = $this->context->transport->post->mimeType;
|
||||
printf(
|
||||
'Download %s (%s)',
|
||||
isset($mimes[$mime]) ? strtoupper($mimes[$mime]) : 'Unknown',
|
||||
strtoupper(TextHelper::resolveMimeType($this->context->transport->post->mimeType)) ?: 'Unknown',
|
||||
TextHelper::useBytesUnits($this->context->transport->post->fileSize));
|
||||
?>
|
||||
</span>
|
||||
|
|
Loading…
Reference in a new issue