mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-19 06:51:33 +02:00
[ticket/14285] Move downloads to controller
PHPBB3-14285
This commit is contained in:
74
phpBB/phpbb/storage/controller/avatar.php
Normal file
74
phpBB/phpbb/storage/controller/avatar.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\storage\controller;
|
||||
|
||||
use phpbb\config\config;
|
||||
use phpbb\storage\storage;
|
||||
|
||||
class avatar extends controller
|
||||
{
|
||||
/** @var config */
|
||||
protected $config;
|
||||
|
||||
protected $allowed_extensions = ['png', 'gif', 'jpg', 'jpeg'];
|
||||
|
||||
public function __construct(config $config, storage $storage)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->storage = $storage;
|
||||
}
|
||||
|
||||
public function handle($file)
|
||||
{
|
||||
$file = $this->decode_avatar_filename($file);
|
||||
|
||||
parent::handle($file);
|
||||
}
|
||||
|
||||
protected function is_allowed($file)
|
||||
{
|
||||
$ext = substr(strrchr($file, '.'), 1);
|
||||
|
||||
// If filename have point and have an allowed extension
|
||||
return strpos($file, '.') && in_array($ext, $this->allowed_extensions);
|
||||
}
|
||||
|
||||
protected function decode_avatar_filename($file)
|
||||
{
|
||||
$avatar_group = false;
|
||||
|
||||
if (isset($file[0]) && $file[0] === 'g')
|
||||
{
|
||||
$avatar_group = true;
|
||||
$file = substr($file, 1);
|
||||
}
|
||||
|
||||
$ext = substr(strrchr($file, '.'), 1);
|
||||
$file = (int) $file;
|
||||
|
||||
return $this->config['avatar_salt'] . '_' . ($avatar_group ? 'g' : '') . $file . '.' . $ext;
|
||||
}
|
||||
|
||||
protected function send($file)
|
||||
{
|
||||
if (!headers_sent())
|
||||
{
|
||||
header('Content-Disposition: inline; ' . header_filename($file));
|
||||
|
||||
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 3600*24*365) . ' GMT');
|
||||
}
|
||||
|
||||
parent::send($file);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user