mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-03 08:41:39 +09:00
Add option to exclude multimedia files from direct download #1207
This commit is contained in:
parent
b8665d73cb
commit
7633bc7b3a
2 changed files with 12 additions and 4 deletions
|
|
@ -93,22 +93,25 @@ class FilenameFilter
|
|||
* Check if a file has an extension that would allow direct download.
|
||||
*
|
||||
* @param string $filename
|
||||
* @param bool $include_multimedia (optional)
|
||||
* @return bool
|
||||
*/
|
||||
public static function isDirectDownload($filename)
|
||||
public static function isDirectDownload($filename, $include_multimedia = true)
|
||||
{
|
||||
$images = 'gif|jpe?g|png|webp';
|
||||
$audios = 'mp3|wav|ogg|flac|aac';
|
||||
$videos = 'mp4|webm|ogv';
|
||||
$legacy = 'avi|as[fx]|flv|m4[av]|midi?|mkv|moo?v|mpe?g|qt|r[am]m?|wm[av]';
|
||||
|
||||
if (preg_match(sprintf('/\.(?:%s|%s|%s|%s)$/i', $images, $audios, $videos, $legacy), $filename))
|
||||
if ($include_multimedia)
|
||||
{
|
||||
return true;
|
||||
$pattern = sprintf('/\.(?:%s|%s|%s|%s)$/i', $images, $audios, $videos, $legacy);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
$pattern = sprintf('/\.(?:%s)$/i', $images);
|
||||
}
|
||||
|
||||
return preg_match($pattern, $filename) ? true : false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,5 +91,10 @@ class FilenameFilterTest extends \Codeception\TestCase\Test
|
|||
$this->assertFalse(FilenameFilter::isDirectDownload(''));
|
||||
$this->assertFalse(FilenameFilter::isDirectDownload('http://www.google.com'));
|
||||
$this->assertFalse(FilenameFilter::isDirectDownload('/'));
|
||||
|
||||
$this->assertTrue(FilenameFilter::isDirectDownload('foobar.jpg', false));
|
||||
$this->assertTrue(FilenameFilter::isDirectDownload('foobar.webp', false));
|
||||
$this->assertFalse(FilenameFilter::isDirectDownload('foobar.mp4', false));
|
||||
$this->assertFalse(FilenameFilter::isDirectDownload('foobar.webm', false));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue