mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/11148] Use mimetype guesser for uploaded avatars
PHPBB3-11148
This commit is contained in:
parent
94a81fa01d
commit
c22983cbdb
3 changed files with 45 additions and 3 deletions
|
@ -45,6 +45,7 @@ services:
|
||||||
- %core.root_path%
|
- %core.root_path%
|
||||||
- %core.php_ext%
|
- %core.php_ext%
|
||||||
- @path_helper
|
- @path_helper
|
||||||
|
- @mimetype.guesser
|
||||||
- @cache.driver
|
- @cache.driver
|
||||||
calls:
|
calls:
|
||||||
- [set_name, [avatar.driver.upload]]
|
- [set_name, [avatar.driver.upload]]
|
||||||
|
|
|
@ -18,6 +18,32 @@ namespace phpbb\avatar\driver;
|
||||||
*/
|
*/
|
||||||
class upload extends \phpbb\avatar\driver\driver
|
class upload extends \phpbb\avatar\driver\driver
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var \phpbb\mimetype\guesser
|
||||||
|
*/
|
||||||
|
protected $mimetype_guesser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a driver object
|
||||||
|
*
|
||||||
|
* @param \phpbb\config\config $config phpBB configuration
|
||||||
|
* @param \phpbb\request\request $request Request object
|
||||||
|
* @param string $phpbb_root_path Path to the phpBB root
|
||||||
|
* @param string $php_ext PHP file extension
|
||||||
|
* @param \phpbb_path_helper $path_helper phpBB path helper
|
||||||
|
* @param \phpbb\mimetype\guesser $mimetype_guesser Mimetype guesser
|
||||||
|
* @param \phpbb\cache\driver\driver_interface $cache Cache driver
|
||||||
|
*/
|
||||||
|
public function __construct(\phpbb\config\config $config, $phpbb_root_path, $php_ext, \phpbb\path_helper $path_helper, \phpbb\mimetype\guesser $mimetype_guesser, \phpbb\cache\driver\driver_interface $cache = null)
|
||||||
|
{
|
||||||
|
$this->config = $config;
|
||||||
|
$this->phpbb_root_path = $phpbb_root_path;
|
||||||
|
$this->php_ext = $php_ext;
|
||||||
|
$this->path_helper = $path_helper;
|
||||||
|
$this->mimetype_guesser = $mimetype_guesser;
|
||||||
|
$this->cache = $cache;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
@ -70,7 +96,7 @@ class upload extends \phpbb\avatar\driver\driver
|
||||||
|
|
||||||
if (!empty($upload_file['name']))
|
if (!empty($upload_file['name']))
|
||||||
{
|
{
|
||||||
$file = $upload->form_upload('avatar_upload_file');
|
$file = $upload->form_upload('avatar_upload_file', $this->mimetype_guesser);
|
||||||
}
|
}
|
||||||
else if (!empty($this->config['allow_avatar_remote_upload']) && !empty($url))
|
else if (!empty($this->config['allow_avatar_remote_upload']) && !empty($url))
|
||||||
{
|
{
|
||||||
|
@ -100,7 +126,7 @@ class upload extends \phpbb\avatar\driver\driver
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = $upload->remote_upload($url);
|
$file = $upload->remote_upload($url, $this->mimetype_guesser);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,6 +42,14 @@ class phpbb_avatar_manager_test extends \phpbb_test_case
|
||||||
$phpEx
|
$phpEx
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$guessers = array(
|
||||||
|
new \Symfony\Component\HttpFoundation\File\MimeType\FileinfoMimeTypeGuesser(),
|
||||||
|
new \Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser(),
|
||||||
|
new \phpbb\mimetype\extension_guesser,
|
||||||
|
new \phpbb\mimetype\content_guesser,
|
||||||
|
);
|
||||||
|
$guesser = new \phpbb\mimetype\guesser($guessers);
|
||||||
|
|
||||||
// $this->avatar_foobar will be needed later on
|
// $this->avatar_foobar will be needed later on
|
||||||
$this->avatar_foobar = $this->getMock('\phpbb\avatar\driver\foobar', array('get_name'), array($config, $phpbb_root_path, $phpEx, $path_helper, $cache));
|
$this->avatar_foobar = $this->getMock('\phpbb\avatar\driver\foobar', array('get_name'), array($config, $phpbb_root_path, $phpEx, $path_helper, $cache));
|
||||||
$this->avatar_foobar->expects($this->any())
|
$this->avatar_foobar->expects($this->any())
|
||||||
|
@ -56,7 +64,14 @@ class phpbb_avatar_manager_test extends \phpbb_test_case
|
||||||
|
|
||||||
foreach ($this->avatar_drivers() as $driver)
|
foreach ($this->avatar_drivers() as $driver)
|
||||||
{
|
{
|
||||||
$cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($config, $phpbb_root_path, $phpEx, $path_helper, $cache));
|
if ($driver !== 'upload')
|
||||||
|
{
|
||||||
|
$cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($config, $phpbb_root_path, $phpEx, $path_helper, $cache));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($config, $phpbb_root_path, $phpEx, $path_helper, $guesser, $cache));
|
||||||
|
}
|
||||||
$cur_avatar->expects($this->any())
|
$cur_avatar->expects($this->any())
|
||||||
->method('get_name')
|
->method('get_name')
|
||||||
->will($this->returnValue('avatar.driver.' . $driver));
|
->will($this->returnValue('avatar.driver.' . $driver));
|
||||||
|
|
Loading…
Add table
Reference in a new issue