1
0
mirror of https://github.com/flarum/core.git synced 2025-10-15 00:44:40 +02:00

Add ability to upload a logo + favicon, and add custom header HTML

Closes #268. Not going to bother with a preview SVG or anything fancy for now – we can think about that as part of #746. Right now it's just good to finally get this functionality in!

Also need to think about apple-touch-icon, msTile stuff, and social sharing image. Not sure if this is all too much for core, but it's definitely too much for the current Appearance page layout. Again, something to think about as part of #746.

Code is a bit rough around the edges, but figured there's not much point in using the command bus properly since #870.
This commit is contained in:
Toby Zerner
2016-06-04 18:05:46 +09:30
parent 01a6dccb83
commit feffe53a86
17 changed files with 811 additions and 92 deletions

View File

@@ -11,6 +11,7 @@
namespace Flarum\Api\Serializer;
use Flarum\Core\Access\Gate;
use Flarum\Forum\UrlGenerator;
use Flarum\Foundation\Application;
use Flarum\Settings\SettingsRepositoryInterface;
@@ -21,11 +22,6 @@ class ForumSerializer extends AbstractSerializer
*/
protected $type = 'forums';
/**
* @var Gate
*/
protected $gate;
/**
* @var Application
*/
@@ -37,15 +33,20 @@ class ForumSerializer extends AbstractSerializer
protected $settings;
/**
* @param Gate $gate
* @var UrlGenerator
*/
protected $url;
/**
* @param Application $app
* @param SettingsRepositoryInterface $settings
* @param UrlGenerator $url
*/
public function __construct(Gate $gate, Application $app, SettingsRepositoryInterface $settings)
public function __construct(Application $app, SettingsRepositoryInterface $settings, UrlGenerator $url)
{
$this->gate = $gate;
$this->app = $app;
$this->settings = $settings;
$this->url = $url;
}
/**
@@ -61,25 +62,27 @@ class ForumSerializer extends AbstractSerializer
*/
protected function getDefaultAttributes($model)
{
$gate = $this->gate->forUser($this->actor);
$attributes = [
'title' => $this->settings->get('forum_title'),
'description' => $this->settings->get('forum_description'),
'baseUrl' => $url = $this->app->url(),
'basePath' => parse_url($url, PHP_URL_PATH) ?: '',
'debug' => $this->app->inDebugMode(),
'apiUrl' => $this->app->url('api'),
'welcomeTitle' => $this->settings->get('welcome_title'),
'welcomeMessage' => $this->settings->get('welcome_message'),
'themePrimaryColor' => $this->settings->get('theme_primary_color'),
'allowSignUp' => (bool) $this->settings->get('allow_sign_up'),
'defaultRoute' => $this->settings->get('default_route'),
'canViewDiscussions' => $gate->allows('viewDiscussions'),
'canStartDiscussion' => $gate->allows('startDiscussion')
'title' => $this->settings->get('forum_title'),
'description' => $this->settings->get('forum_description'),
'baseUrl' => $url = $this->app->url(),
'basePath' => parse_url($url, PHP_URL_PATH) ?: '',
'debug' => $this->app->inDebugMode(),
'apiUrl' => $this->app->url('api'),
'welcomeTitle' => $this->settings->get('welcome_title'),
'welcomeMessage' => $this->settings->get('welcome_message'),
'themePrimaryColor' => $this->settings->get('theme_primary_color'),
'themeSecondaryColor' => $this->settings->get('theme_secondary_color'),
'logoUrl' => $this->getLogoUrl(),
'faviconUrl' => $this->getFaviconUrl(),
'headerHtml' => $this->settings->get('custom_header'),
'allowSignUp' => (bool) $this->settings->get('allow_sign_up'),
'defaultRoute' => $this->settings->get('default_route'),
'canViewDiscussions' => $this->actor->can('viewDiscussions'),
'canStartDiscussion' => $this->actor->can('startDiscussion')
];
if ($gate->allows('administrate')) {
if ($this->actor->can('administrate')) {
$attributes['adminUrl'] = $this->app->url('admin');
$attributes['version'] = $this->app->version();
}
@@ -94,4 +97,24 @@ class ForumSerializer extends AbstractSerializer
{
return $this->hasMany($model, 'Flarum\Api\Serializer\GroupSerializer');
}
/**
* @return null|string
*/
protected function getLogoUrl()
{
$logoPath = $this->settings->get('logo_path');
return $logoPath ? $this->url->toPath('assets/'.$logoPath) : null;
}
/**
* @return null|string
*/
protected function getFaviconUrl()
{
$faviconPath = $this->settings->get('favicon_path');
return $faviconPath ? $this->url->toPath('assets/'.$faviconPath) : null;
}
}