2016-10-07 04:41:04 +02:00
|
|
|
<?php
|
2020-10-15 00:19:31 +02:00
|
|
|
|
2021-07-19 07:53:45 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-08-05 00:05:14 +02:00
|
|
|
namespace App;
|
2016-10-07 04:41:04 +02:00
|
|
|
|
2023-06-07 08:25:57 +02:00
|
|
|
use App\Assets\AssetTypes;
|
2022-05-31 09:50:49 +02:00
|
|
|
use App\Assets\BrowserIconCustomAsset;
|
2023-06-07 08:25:57 +02:00
|
|
|
use App\Container\EnvironmentAwareTrait;
|
2023-06-07 14:18:05 +02:00
|
|
|
use App\Entity\Repository\SettingsRepository;
|
|
|
|
use App\Entity\Settings;
|
|
|
|
use App\Entity\Station;
|
2022-01-07 09:26:40 +01:00
|
|
|
use App\Enums\SupportedLocales;
|
|
|
|
use App\Enums\SupportedThemes;
|
2023-12-04 07:48:40 +01:00
|
|
|
use App\Http\ServerRequest;
|
2022-11-17 16:13:41 +01:00
|
|
|
use App\Traits\RequestAwareTrait;
|
2016-10-07 04:41:04 +02:00
|
|
|
|
2022-07-01 09:41:04 +02:00
|
|
|
final class Customization
|
2016-10-07 04:41:04 +02:00
|
|
|
{
|
2022-11-17 16:13:41 +01:00
|
|
|
use RequestAwareTrait;
|
2023-06-07 08:25:57 +02:00
|
|
|
use EnvironmentAwareTrait;
|
2022-11-17 16:13:41 +01:00
|
|
|
|
2023-06-07 14:18:05 +02:00
|
|
|
private Settings $settings;
|
2020-12-04 09:41:55 +01:00
|
|
|
|
2022-07-01 09:41:04 +02:00
|
|
|
private SupportedLocales $locale;
|
2020-07-10 10:17:51 +02:00
|
|
|
|
2023-06-26 12:33:20 +02:00
|
|
|
private ?SupportedThemes $publicTheme;
|
2020-07-13 07:57:24 +02:00
|
|
|
|
2023-06-06 12:43:06 +02:00
|
|
|
private string $instanceName;
|
2019-08-22 00:33:47 +02:00
|
|
|
|
2020-07-10 06:15:27 +02:00
|
|
|
public function __construct(
|
2023-06-07 14:18:05 +02:00
|
|
|
SettingsRepository $settingsRepo
|
2020-07-10 06:15:27 +02:00
|
|
|
) {
|
2020-12-10 23:46:03 +01:00
|
|
|
$this->settings = $settingsRepo->readSettings();
|
|
|
|
$this->instanceName = $this->settings->getInstanceName() ?? '';
|
2023-05-16 00:13:25 +02:00
|
|
|
$this->publicTheme = $this->settings->getPublicTheme();
|
2022-11-17 16:13:41 +01:00
|
|
|
$this->locale = SupportedLocales::default();
|
|
|
|
}
|
|
|
|
|
2023-12-04 07:48:40 +01:00
|
|
|
public function setRequest(?ServerRequest $request): void
|
2022-11-17 16:13:41 +01:00
|
|
|
{
|
|
|
|
$this->request = $request;
|
|
|
|
|
|
|
|
if (null !== $request) {
|
|
|
|
// Register current theme
|
2023-06-26 12:33:20 +02:00
|
|
|
$queryParams = $request->getQueryParams();
|
|
|
|
if (!empty($queryParams['theme'])) {
|
|
|
|
$theme = SupportedThemes::tryFrom($queryParams['theme']);
|
|
|
|
if (null !== $theme && $theme !== SupportedThemes::Browser) {
|
|
|
|
$this->publicTheme = $theme;
|
|
|
|
}
|
|
|
|
}
|
2020-07-10 10:17:51 +02:00
|
|
|
|
2022-11-17 16:13:41 +01:00
|
|
|
// Register locale
|
|
|
|
$this->locale = SupportedLocales::createFromRequest($this->environment, $request);
|
|
|
|
}
|
2022-01-07 09:26:40 +01:00
|
|
|
}
|
2020-07-13 07:57:24 +02:00
|
|
|
|
2022-01-07 09:26:40 +01:00
|
|
|
public function getLocale(): SupportedLocales
|
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
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
2023-06-26 12:33:20 +02:00
|
|
|
public function getPublicTheme(): ?SupportedThemes
|
2017-09-20 04:10:06 +02:00
|
|
|
{
|
2023-06-26 12:33:20 +02:00
|
|
|
return (SupportedThemes::Browser !== $this->publicTheme)
|
|
|
|
? $this->publicTheme
|
|
|
|
: null;
|
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
|
|
|
{
|
2021-07-30 08:20:14 +02:00
|
|
|
$publicCss = $this->settings->getPublicCustomCss() ?? '';
|
|
|
|
|
2023-06-07 08:25:57 +02:00
|
|
|
$background = AssetTypes::Background->createObject($this->environment);
|
2021-07-30 08:20:14 +02:00
|
|
|
if ($background->isUploaded()) {
|
|
|
|
$backgroundUrl = $background->getUrl();
|
|
|
|
|
|
|
|
$publicCss .= <<<CSS
|
2023-07-09 15:29:36 +02:00
|
|
|
[data-bs-theme] body.page-minimal {
|
2022-05-08 20:05:02 +02:00
|
|
|
background-image: url('{$backgroundUrl}');
|
2021-07-30 08:20:14 +02:00
|
|
|
}
|
|
|
|
CSS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $publicCss;
|
2017-09-20 04:10:06 +02:00
|
|
|
}
|
|
|
|
|
2023-06-07 14:18:05 +02:00
|
|
|
public function getStationCustomPublicCss(Station $station): string
|
2023-01-03 23:55:49 +01:00
|
|
|
{
|
|
|
|
$publicCss = $station->getBrandingConfig()->getPublicCustomCss() ?? '';
|
|
|
|
|
2023-06-07 08:25:57 +02:00
|
|
|
$background = AssetTypes::Background->createObject($this->environment, $station);
|
|
|
|
|
2023-01-03 23:55:49 +01:00
|
|
|
if ($background->isUploaded()) {
|
|
|
|
$backgroundUrl = $background->getUrl();
|
|
|
|
|
|
|
|
$publicCss .= <<<CSS
|
2023-07-09 15:29:36 +02:00
|
|
|
[data-bs-theme] body.page-minimal {
|
2023-01-03 23:55:49 +01:00
|
|
|
background-image: url('{$backgroundUrl}');
|
|
|
|
}
|
|
|
|
CSS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $publicCss;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-06-07 14:18:05 +02:00
|
|
|
public function getStationCustomPublicJs(Station $station): string
|
2023-01-03 23:55:49 +01:00
|
|
|
{
|
|
|
|
return $station->getBrandingConfig()->getPublicCustomJs() ?? '';
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2021-07-30 08:20:14 +02:00
|
|
|
public function getBrowserIconUrl(int $size = 256): string
|
|
|
|
{
|
2023-06-07 08:25:57 +02:00
|
|
|
/** @var BrowserIconCustomAsset $browserIcon */
|
|
|
|
$browserIcon = AssetTypes::BrowserIcon->createObject($this->environment);
|
|
|
|
|
|
|
|
return $browserIcon->getUrlForSize($size);
|
2021-07-30 08:20:14 +02: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
|
|
|
|
*/
|
2021-07-19 07:53:45 +02:00
|
|
|
public function getPageTitle(?string $title = null): string
|
2018-10-17 05:50:14 +02:00
|
|
|
{
|
|
|
|
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()) {
|
2022-01-17 05:45:07 +01:00
|
|
|
$title = '(' . $this->environment->getAppEnvironmentEnum()->getName() . ') ' . $title;
|
2018-10-17 05:50:14 +02:00
|
|
|
}
|
|
|
|
|
2021-07-19 07:53:45 +02:00
|
|
|
return $title ?? '';
|
2018-10-17 05:50:14 +02:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2023-07-28 13:42:30 +02:00
|
|
|
public function enableAdvancedFeatures(): bool
|
|
|
|
{
|
|
|
|
return $this->settings->getEnableAdvancedFeatures();
|
|
|
|
}
|
|
|
|
|
2022-11-10 23:53:23 +01:00
|
|
|
public function useStaticNowPlaying(): bool
|
2018-12-28 03:17:08 +01:00
|
|
|
{
|
2022-11-10 23:53:23 +01:00
|
|
|
return $this->settings->getEnableStaticNowPlaying();
|
2018-12-28 03:17:08 +01:00
|
|
|
}
|
2018-02-28 16:25:33 +01:00
|
|
|
}
|