123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace Component\Media;
- use App\Core\Cache;
- use App\Core\Event;
- use App\Core\Module;
- use App\Util\Common;
- use App\Util\Nickname;
- class Media extends Module
- {
- public static function __callStatic(string $name, array $args)
- {
- return Utils::{$name}(...$args);
- }
- public function onAddRoute($r)
- {
- $r->connect('avatar', '/{nickname<' . Nickname::DISPLAY_FMT . '>}/avatar/{size<full|big|medium|small>?full}', [Controller\Media::class, 'avatar']);
- $r->connect('attachment_inline', '/attachment/{id<\d+>}', [Controller\Media::class, 'attachment_inline']);
- return Event::next;
- }
- public function onEndTwigPopulateVars(array &$vars)
- {
- if (Common::user() != null) {
- $vars['user_avatar'] = self::getAvatarUrl();
- }
- return Event::next;
- }
- public function onGetAvatarUrl(string $nickname, ?string &$url)
- {
- $url = self::getAvatarUrl($nickname);
- return Event::next;
- }
- public function onDeleteCachedAvatar(string $nickname)
- {
- Cache::delete('avatar-' . $nickname);
- Cache::delete('avatar-url-' . $nickname);
- Cache::delete('avatar-file-info-' . $nickname);
- }
- }
|