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