2016-10-07 04:41:04 +02:00
|
|
|
<?php
|
2020-10-15 00:19:31 +02:00
|
|
|
|
2018-08-05 00:05:14 +02:00
|
|
|
namespace App;
|
2016-10-07 04:41:04 +02:00
|
|
|
|
2019-08-07 06:33:55 +02:00
|
|
|
use App\Entity;
|
2020-07-10 06:15:27 +02:00
|
|
|
use App\Http\ServerRequest;
|
2019-07-31 20:47:12 +02:00
|
|
|
use App\Service\NChan;
|
2020-07-10 06:15:27 +02:00
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
2016-10-07 04:41:04 +02:00
|
|
|
|
|
|
|
class Customization
|
|
|
|
{
|
2021-04-29 14:01:41 +02:00
|
|
|
public const DEFAULT_THEME = 'browser';
|
2018-12-28 03:17:08 +01:00
|
|
|
|
2021-04-29 14:01:41 +02:00
|
|
|
public const THEME_BROWSER = 'browser';
|
2020-12-04 09:41:55 +01:00
|
|
|
public const THEME_LIGHT = 'light';
|
|
|
|
public const THEME_DARK = 'dark';
|
|
|
|
|
2019-12-07 13:19:49 +01:00
|
|
|
protected ?Entity\User $user = null;
|
2016-10-07 04:41:04 +02:00
|
|
|
|
2020-12-04 09:41:55 +01:00
|
|
|
protected Entity\Settings $settings;
|
|
|
|
|
2021-02-28 03:50:45 +01:00
|
|
|
protected Locale $locale;
|
2020-07-10 10:17:51 +02:00
|
|
|
|
|
|
|
protected string $theme = self::DEFAULT_THEME;
|
|
|
|
|
2020-07-13 07:57:24 +02:00
|
|
|
protected string $publicTheme = self::DEFAULT_THEME;
|
|
|
|
|
2020-07-10 10:17:51 +02:00
|
|
|
protected string $instanceName = '';
|
2019-08-22 00:33:47 +02:00
|
|
|
|
2020-07-10 06:15:27 +02:00
|
|
|
public function __construct(
|
2021-04-23 07:24:12 +02:00
|
|
|
protected Environment $environment,
|
2020-12-10 23:46:03 +01:00
|
|
|
Entity\Repository\SettingsRepository $settingsRepo,
|
2020-07-10 06:15:27 +02:00
|
|
|
ServerRequestInterface $request
|
|
|
|
) {
|
2020-12-10 23:46:03 +01:00
|
|
|
$this->settings = $settingsRepo->readSettings();
|
2020-12-04 09:41:55 +01:00
|
|
|
|
2020-12-10 23:46:03 +01:00
|
|
|
$this->instanceName = $this->settings->getInstanceName() ?? '';
|
2019-09-04 20:00:51 +02:00
|
|
|
|
2020-07-10 06:15:27 +02:00
|
|
|
// Register current user
|
|
|
|
$this->user = $request->getAttribute(ServerRequest::ATTR_USER);
|
|
|
|
|
2020-07-10 10:17:51 +02:00
|
|
|
// Register current theme
|
|
|
|
$queryParams = $request->getQueryParams();
|
|
|
|
|
|
|
|
if (!empty($queryParams['theme'])) {
|
2020-07-13 07:57:24 +02:00
|
|
|
$this->publicTheme = $this->theme = $queryParams['theme'];
|
|
|
|
} else {
|
2020-12-10 23:46:03 +01:00
|
|
|
$this->publicTheme = $this->settings->getPublicTheme() ?? $this->publicTheme;
|
2020-07-13 07:57:24 +02:00
|
|
|
|
|
|
|
if (null !== $this->user && !empty($this->user->getTheme())) {
|
|
|
|
$this->theme = (string)$this->user->getTheme();
|
|
|
|
}
|
2020-07-10 10:17:51 +02:00
|
|
|
}
|
|
|
|
|
2021-02-28 03:50:45 +01:00
|
|
|
// Register locale
|
2021-07-08 22:03:54 +02:00
|
|
|
$this->locale = Locale::createFromRequest($this->environment, $request);
|
2021-02-28 03:50:45 +01:00
|
|
|
$this->locale->register();
|
2018-02-01 12:49:40 +01:00
|
|
|
}
|
|
|
|
|
2021-02-28 03:50:45 +01:00
|
|
|
public function getLocale(): Locale
|
2019-08-22 00:33:47 +02:00
|
|
|
{
|
2020-07-10 10:17:51 +02:00
|
|
|
return $this->locale;
|
2016-10-07 04:41:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the user-customized or system default theme.
|
|
|
|
*/
|
2020-07-08 09:03:50 +02:00
|
|
|
public function getTheme(): string
|
2016-10-07 04:41:04 +02:00
|
|
|
{
|
2020-07-10 10:17:51 +02:00
|
|
|
return $this->theme;
|
2016-10-07 04:41:04 +02:00
|
|
|
}
|
2017-05-21 06:27:34 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the instance name for this AzuraCast instance.
|
|
|
|
*/
|
2020-07-10 10:17:51 +02:00
|
|
|
public function getInstanceName(): string
|
2017-05-21 06:27:34 +02:00
|
|
|
{
|
2020-07-10 10:17:51 +02:00
|
|
|
return $this->instanceName;
|
2017-05-21 06:27:34 +02:00
|
|
|
}
|
2017-09-20 04:10:06 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the theme name to be used in public (non-logged-in) pages.
|
|
|
|
*/
|
2019-03-14 02:49:19 +01:00
|
|
|
public function getPublicTheme(): string
|
2017-09-20 04:10:06 +02:00
|
|
|
{
|
2020-07-13 07:57:24 +02:00
|
|
|
return $this->publicTheme;
|
2017-09-20 04:10:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the administrator-supplied custom CSS for public (minimal layout) pages, if specified.
|
|
|
|
*/
|
2020-07-08 09:03:50 +02:00
|
|
|
public function getCustomPublicCss(): string
|
2017-09-20 04:10:06 +02:00
|
|
|
{
|
2020-12-04 09:41:55 +01:00
|
|
|
return $this->settings->getPublicCustomCss() ?? '';
|
2017-09-20 04:10:06 +02:00
|
|
|
}
|
|
|
|
|
2018-02-28 16:25:33 +01:00
|
|
|
/**
|
|
|
|
* Return the administrator-supplied custom JS for public (minimal layout) pages, if specified.
|
|
|
|
*/
|
2020-07-08 09:03:50 +02:00
|
|
|
public function getCustomPublicJs(): string
|
2018-02-28 16:25:33 +01:00
|
|
|
{
|
2020-12-04 09:41:55 +01:00
|
|
|
return $this->settings->getPublicCustomJs() ?? '';
|
2018-02-28 16:25:33 +01:00
|
|
|
}
|
|
|
|
|
2017-09-20 04:10:06 +02:00
|
|
|
/**
|
|
|
|
* Return the administrator-supplied custom CSS for internal (full layout) pages, if specified.
|
|
|
|
*/
|
2020-07-08 09:03:50 +02:00
|
|
|
public function getCustomInternalCss(): string
|
2017-09-20 04:10:06 +02:00
|
|
|
{
|
2020-12-04 09:41:55 +01:00
|
|
|
return $this->settings->getInternalCustomCss() ?? '';
|
2017-09-20 04:10:06 +02:00
|
|
|
}
|
2018-02-04 14:20:23 +01:00
|
|
|
|
2018-03-04 13:06:50 +01:00
|
|
|
/**
|
|
|
|
* Return whether to show or hide album art on public pages.
|
|
|
|
*/
|
|
|
|
public function hideAlbumArt(): bool
|
|
|
|
{
|
2020-12-04 09:41:55 +01:00
|
|
|
return $this->settings->getHideAlbumArt();
|
2018-03-04 13:06:50 +01:00
|
|
|
}
|
2018-03-17 03:40:34 +01:00
|
|
|
|
2018-10-17 05:50:14 +02:00
|
|
|
/**
|
|
|
|
* Return the calculated page title given branding settings and the application environment.
|
|
|
|
*
|
|
|
|
* @param string|null $title
|
|
|
|
*/
|
|
|
|
public function getPageTitle($title = null): string
|
|
|
|
{
|
|
|
|
if (!$this->hideProductName()) {
|
|
|
|
if ($title) {
|
2020-12-06 12:57:39 +01:00
|
|
|
$title .= ' - ' . $this->environment->getAppName();
|
2018-10-17 05:50:14 +02:00
|
|
|
} else {
|
2020-12-06 12:57:39 +01:00
|
|
|
$title = $this->environment->getAppName();
|
2018-10-17 05:50:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-04 09:41:55 +01:00
|
|
|
if (!$this->environment->isProduction()) {
|
2020-12-06 12:57:39 +01:00
|
|
|
$title = '(' . ucfirst($this->environment->getAppEnvironment()) . ') ' . $title;
|
2018-10-17 05:50:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $title;
|
|
|
|
}
|
2018-12-28 03:17:08 +01:00
|
|
|
|
2019-07-31 20:47:12 +02:00
|
|
|
/**
|
2019-09-04 20:00:51 +02:00
|
|
|
* Return whether to show or hide the AzuraCast name from public-facing pages.
|
2019-07-31 20:47:12 +02:00
|
|
|
*/
|
2019-09-04 20:00:51 +02:00
|
|
|
public function hideProductName(): bool
|
2019-07-31 20:47:12 +02:00
|
|
|
{
|
2020-12-04 09:41:55 +01:00
|
|
|
return $this->settings->getHideProductName();
|
2019-07-31 20:47:12 +02:00
|
|
|
}
|
|
|
|
|
2019-09-04 20:00:51 +02:00
|
|
|
public function useWebSocketsForNowPlaying(): bool
|
2018-12-28 03:17:08 +01:00
|
|
|
{
|
2019-09-04 20:00:51 +02:00
|
|
|
if (!NChan::isSupported()) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-12-28 03:17:08 +01:00
|
|
|
|
2020-12-04 09:41:55 +01:00
|
|
|
return $this->settings->getEnableWebsockets();
|
2018-12-28 03:17:08 +01:00
|
|
|
}
|
2018-02-28 16:25:33 +01:00
|
|
|
}
|