2020-03-06 17:34:49 +00:00
|
|
|
<?php
|
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// GNU social is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
/**
|
2020-06-27 22:39:09 +01:00
|
|
|
* Retrieve user avatar by filename action class.
|
2020-03-06 17:34:49 +00:00
|
|
|
*
|
|
|
|
* @category Action
|
|
|
|
* @package GNUsocial
|
|
|
|
*
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
|
|
|
|
*/
|
2020-06-27 22:39:09 +01:00
|
|
|
defined('GNUSOCIAL') || die;
|
2020-03-06 17:34:49 +00:00
|
|
|
|
|
|
|
/**
|
2020-06-27 22:39:09 +01:00
|
|
|
* Retrieve user avatar by filename action class.
|
2020-03-06 17:34:49 +00:00
|
|
|
*
|
|
|
|
* @category Action
|
|
|
|
* @package GNUsocial
|
|
|
|
*
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @author Robin Millette <millette@status.net>
|
|
|
|
* @author Mikael Nordfeldth <mmn@hethane.se>
|
|
|
|
* @author Hugo Sales <hugo@fc.up.pt>
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
|
|
|
|
*
|
|
|
|
* @see http://www.gnu.org/software/social/
|
|
|
|
*/
|
|
|
|
class AvatarAction extends Action
|
|
|
|
{
|
2020-06-27 22:39:09 +01:00
|
|
|
public $filename = null;
|
|
|
|
public $filepath = null;
|
|
|
|
public $mimetype = null;
|
|
|
|
|
2020-03-06 17:34:49 +00:00
|
|
|
protected function prepare(array $args = [])
|
|
|
|
{
|
|
|
|
parent::prepare($args);
|
2020-06-27 22:39:09 +01:00
|
|
|
$this->filename = File::tryFilename($this->trimmed('file'));
|
|
|
|
$this->filepath = File::path($this->filename, common_config('avatar', 'dir'), false);
|
|
|
|
if (!file_exists($this->filepath)) {
|
2020-03-06 17:34:49 +00:00
|
|
|
// TRANS: Client error displayed trying to get a non-existing avatar.
|
|
|
|
$this->clientError(_m('No such avatar.'), 404);
|
|
|
|
}
|
2020-06-27 22:39:09 +01:00
|
|
|
$this->mimetype = (new ImageFile(-1, $this->filepath))->mimetype;
|
|
|
|
|
2020-03-06 17:34:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function handle()
|
|
|
|
{
|
|
|
|
parent::handle();
|
|
|
|
|
2020-06-27 22:39:09 +01:00
|
|
|
common_send_file($this->filepath, $this->mimetype, $this->filename, 'inline');
|
2020-03-06 17:34:49 +00:00
|
|
|
}
|
|
|
|
}
|