[AVATAR] Fixed avatar upload, added avatar inline download and updated template and base controller

This commit is contained in:
Hugo Sales
2020-08-08 16:10:25 +00:00
committed by Hugo Sales
parent d5e41ec099
commit a5c97762e0
13 changed files with 303 additions and 97 deletions

View File

@@ -32,6 +32,8 @@
namespace App\Core;
use App\Core\DB\DB;
use App\Util\Common;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
@@ -60,7 +62,13 @@ class Controller extends AbstractController implements EventSubscriberInterface
$controller = $event->getController();
$request = $event->getRequest();
$this->vars = ['controler' => $controller, 'request' => $request];
if (($avatar = DB::find('avatar', ['profile_id' => Common::profile()->getId()])) != null) {
$avatar_filename = $avatar->getUrl();
} else {
$avatar_filename = '/public/assets/default_avatar.svg';
}
$this->vars = ['controler' => $controller, 'request' => $request, 'user_avatar' => $avatar_filename];
Event::handle('StartTwigPopulateVars', [&$this->vars]);
return $event;

View File

@@ -23,6 +23,7 @@ namespace App\Core;
use App\Core\DB\DB;
use App\Util\Formatting;
use DateTime;
class Entity
{
@@ -33,7 +34,8 @@ class Entity
$args['created'] = $args['modified'] = new DateTime();
foreach ($args as $prop => $val) {
if (property_exists($class, $prop)) {
$obj->{$prop} = $val;
$set = 'set' . Formatting::snakeCaseToCamelCase($prop);
$obj->{$set}($val);
} else {
Log::error("Property {$class}::{$prop} doesn't exist");
}

View File

@@ -58,6 +58,7 @@ use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Security as SSecurity;
use Symfony\Component\Security\Http\Util\TargetPathTrait;
@@ -72,6 +73,7 @@ class GNUsocial implements EventSubscriberInterface
protected TranslatorInterface $translator;
protected EntityManagerInterface $entity_manager;
protected RouterInterface $router;
protected UrlGeneratorInterface $url_generator;
protected FormFactoryInterface $form_factory;
protected MessageBusInterface $message_bus;
protected EventDispatcherInterface $event_dispatcher;
@@ -87,6 +89,7 @@ class GNUsocial implements EventSubscriberInterface
TranslatorInterface $trans,
EntityManagerInterface $em,
RouterInterface $router,
UrlGeneratorInterface $url_gen,
FormFactoryInterface $ff,
MessageBusInterface $mb,
EventDispatcherInterface $ed,
@@ -99,6 +102,7 @@ class GNUsocial implements EventSubscriberInterface
$this->translator = $trans;
$this->entity_manager = $em;
$this->router = $router;
$this->url_generator = $url_gen;
$this->form_factory = $ff;
$this->message_bus = $mb;
$this->event_dispatcher = $ed;
@@ -126,6 +130,7 @@ class GNUsocial implements EventSubscriberInterface
Queue::setMessageBus($this->message_bus);
Security::setHelper($this->security);
Mailer::setMailer($this->mailer);
Router::setRouter($this->router, $this->url_generator);
DefaultSettings::setDefaults();
@@ -134,8 +139,6 @@ class GNUsocial implements EventSubscriberInterface
// Events are proloaded on compilation, but set at runtime
$this->module_manager->loadModules();
Router::setRouter($this->router);
$this->initialized = true;
}
}

View File

@@ -30,15 +30,46 @@
namespace App\Core\Router;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\Router as SRouter;
abstract class Router
{
public static ?SRouter $router = null;
/**
* Generates an absolute URL, e.g. "http://example.com/dir/file".
*/
const ABSOLUTE_URL = UrlGeneratorInterface::ABSOLUTE_URL;
public static function setRouter($rtr): void
/**
* Generates an absolute path, e.g. "/dir/file".
*/
const ABSOLUTE_PATH = UrlGeneratorInterface::ABSOLUTE_PATH;
/**
* Generates a relative path based on the current request path, e.g. "../parent-file".
*
* @see UrlGenerator::getRelativePath()
*/
const RELATIVE_PATH = UrlGeneratorInterface::RELATIVE_PATH;
/**
* Generates a network path, e.g. "//example.com/dir/file".
* Such reference reuses the current scheme but specifies the host.
*/
const NETWORK_PATH = UrlGeneratorInterface::NETWORK_PATH;
public static ?SRouter $router = null;
public static ?UrlGeneratorInterface $url_gen = null;
public static function setRouter($rtr, $gen): void
{
self::$router = $rtr;
self::$router = $rtr;
self::$url_gen = $gen;
}
public static function url(string $id, array $args, int $type = self::ABSOLUTE_PATH): string
{
return self::$url_gen->generate($id, $args, $type);
}
public static function __callStatic(string $name, array $args)