forked from GNUsocial/gnu-social
[MEDIA] Move avatar fetching and adding to ouput to media component
This commit is contained in:
@@ -19,12 +19,16 @@
|
||||
|
||||
namespace Component\Media;
|
||||
|
||||
use App\Core\DB\DB;
|
||||
use App\Core\Event;
|
||||
use App\Core\Log;
|
||||
use App\Core\Module;
|
||||
use App\Entity\File;
|
||||
use App\Util\Common;
|
||||
use App\Util\Exception\ClientException;
|
||||
use App\Util\Nickname;
|
||||
use Symfony\Component\Asset\Package;
|
||||
use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\File\Exception\FileException;
|
||||
use Symfony\Component\HttpFoundation\File\File as SymfonyFile;
|
||||
@@ -87,4 +91,15 @@ class Media extends Module
|
||||
{
|
||||
$r->connect('avatar', '/{nickname<' . Nickname::DISPLAY_FMT . '>}/avatar/{size<full|big|medium|small>?full}', [Controller\Avatar::class, 'send']);
|
||||
}
|
||||
|
||||
public function onEndTwigPopulateVars(array &$vars)
|
||||
{
|
||||
if (($user = Common::user()) !== null && ($avatar = DB::find('avatar', ['gsactor_id' => $user->getActor()->getId()])) != null) {
|
||||
$vars['user_avatar'] = $avatar->getUrl();
|
||||
} else {
|
||||
$package = new Package(new EmptyVersionStrategy());
|
||||
$vars['user_avatar'] = $package->getUrl('/assets/default-avatar.svg');
|
||||
}
|
||||
return Event::next;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user