. /** * Retrieve user avatar by filename action class. * * @category Action * @package GNUsocial * * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 */ defined('GNUSOCIAL') || die; /** * Retrieve user avatar by filename action class. * * @category Action * @package GNUsocial * * @author Evan Prodromou * @author Robin Millette * @author Mikael Nordfeldth * @author Hugo Sales * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 * * @see http://www.gnu.org/software/social/ */ class AvatarAction extends Action { public $filename = null; public $filepath = null; public $mimetype = null; protected function prepare(array $args = []) { parent::prepare($args); $this->filename = File::tryFilename($this->trimmed('file')); $this->filepath = File::path($this->filename, common_config('avatar', 'dir'), false); if (!file_exists($this->filepath)) { // TRANS: Client error displayed trying to get a non-existing avatar. $this->clientError(_m('No such avatar.'), 404); } $this->mimetype = (new ImageFile(-1, $this->filepath))->mimetype; return true; } protected function handle() { parent::handle(); common_send_file($this->filepath, $this->mimetype, $this->filename, 'inline'); } }