[CORE] Make avatars be served with the same mechanism as attachments
This commit is contained in:
parent
1ea12e0cdf
commit
b7ed15c865
69
actions/avatar.php
Normal file
69
actions/avatar.php
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
<?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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 <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
|
||||||
|
{
|
||||||
|
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 {
|
||||||
|
$attachment = new AttachmentAction(); // kludge...
|
||||||
|
$attachment->filepath = common_config('avatar', 'dir') . $this->filename;
|
||||||
|
$attachment->sendFile();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -187,7 +187,7 @@ class Avatar extends Managed_DataObject
|
||||||
|
|
||||||
public static function url($filename)
|
public static function url($filename)
|
||||||
{
|
{
|
||||||
$path = common_config('avatar', 'path');
|
$path = common_config('avatar', 'url_base');
|
||||||
|
|
||||||
if ($path[strlen($path)-1] != '/') {
|
if ($path[strlen($path)-1] != '/') {
|
||||||
$path .= '/';
|
$path .= '/';
|
||||||
|
|
|
@ -147,8 +147,8 @@ $default =
|
||||||
array('jpegquality' => 85),
|
array('jpegquality' => 85),
|
||||||
'avatar' =>
|
'avatar' =>
|
||||||
array('server' => null,
|
array('server' => null,
|
||||||
'dir' => PUBLICDIR . '/avatar/',
|
'dir' => INSTALLDIR . '/file/avatar/',
|
||||||
'path' => $_path . '/avatar/',
|
'url_base' => $_path . '/avatar/',
|
||||||
'ssl' => null,
|
'ssl' => null,
|
||||||
'maxsize' => 300),
|
'maxsize' => 300),
|
||||||
'foaf' =>
|
'foaf' =>
|
||||||
|
|
|
@ -1040,6 +1040,10 @@ class Router
|
||||||
['nickname' => Nickname::DISPLAY_FMT]);
|
['nickname' => Nickname::DISPLAY_FMT]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$m->connect('avatar/:file',
|
||||||
|
['action' => 'avatar'],
|
||||||
|
['file' => '.*']);
|
||||||
|
|
||||||
$m->connect(':nickname/avatar',
|
$m->connect(':nickname/avatar',
|
||||||
['action' => 'avatarbynickname'],
|
['action' => 'avatarbynickname'],
|
||||||
['nickname' => Nickname::DISPLAY_FMT]);
|
['nickname' => Nickname::DISPLAY_FMT]);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user