. /** * Retrieve user avatar by nickname action class. * * @category Action * @package GNUsocial * * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 */ if (!defined('GNUSOCIAL')) { exit(1); } /** * Retrieve user avatar by nickname 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; protected function prepare(array $args = []) { parent::prepare($args); if (empty($this->filename = $this->trimmed('file'))) { // TRANS: Client error displayed trying to get a non-existing avatar. $this->clientError(_m('No such avatar.'), 404); } return true; } protected function handle() { parent::handle(); if (is_string($srv = common_config('avatar', 'server')) && $srv != '') { common_redirect(Avatar::url($this->filename), 302); } else { $filepath = common_config('avatar', 'dir') . $this->filename; $info = @getimagesize($filepath); if ($info !== false) { common_send_file($filepath, $info['mime'], $this->filename, 'inline'); } else { throw new UnsupportedMediaException(_m("Avatar is not an image.")); } } return true; } }