2016-10-07 02:41:04 +00:00
|
|
|
<?php
|
2016-12-16 20:49:07 +00:00
|
|
|
namespace AzuraCast;
|
2016-10-07 02:41:04 +00:00
|
|
|
|
|
|
|
use Entity\User;
|
|
|
|
use Interop\Container\ContainerInterface;
|
|
|
|
|
|
|
|
class Customization
|
|
|
|
{
|
|
|
|
/** @var ContainerInterface */
|
|
|
|
protected $di;
|
|
|
|
|
|
|
|
/** @var User|null */
|
|
|
|
protected $user;
|
|
|
|
|
2016-12-16 20:49:07 +00:00
|
|
|
/** @var \App\Config */
|
2016-10-07 02:41:04 +00:00
|
|
|
protected $config;
|
|
|
|
|
|
|
|
public function __construct(ContainerInterface $di)
|
|
|
|
{
|
|
|
|
$this->di = $di;
|
|
|
|
$this->user = $di['user'];
|
|
|
|
$this->config = $di['config'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the user's custom time zone or the system default.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getTimeZone()
|
|
|
|
{
|
2017-01-24 00:35:16 +00:00
|
|
|
if ($this->user !== null && !empty($this->user->timezone)) {
|
2016-10-07 02:41:04 +00:00
|
|
|
return $this->user->timezone;
|
2017-01-24 00:35:16 +00:00
|
|
|
} else {
|
2016-10-07 02:41:04 +00:00
|
|
|
return date_default_timezone_get();
|
2017-01-24 00:35:16 +00:00
|
|
|
}
|
2016-10-07 02:41:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Locale Commands:
|
|
|
|
* find /var/azuracast/www -type f \( -name '*.php' -or -name '*.phtml' \) -print > list
|
|
|
|
* xgettext --files-from=list --language=PHP -o /var/azuracast/www/app/locale/default.pot
|
|
|
|
*
|
|
|
|
* find /var/azuracast/www/app/locale -name \*.po -execdir msgfmt default.po -o default.mo \;
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the user-customized, browser-specified or system default locale.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getLocale()
|
|
|
|
{
|
|
|
|
$locale = null;
|
|
|
|
$supported_locales = $this->config->application->locale->supported->toArray();
|
|
|
|
|
|
|
|
// Prefer user-based profile locale.
|
2017-01-24 00:35:16 +00:00
|
|
|
if ($this->user !== null && !empty($this->user->locale) && $this->user->locale !== 'default') {
|
|
|
|
if (isset($supported_locales[$this->user->locale])) {
|
2016-10-07 02:41:04 +00:00
|
|
|
$locale = $this->user->locale;
|
2017-01-24 00:35:16 +00:00
|
|
|
}
|
2016-10-07 02:41:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Attempt to load from browser headers.
|
2017-01-24 00:35:16 +00:00
|
|
|
if (!$locale) {
|
2016-10-07 02:41:04 +00:00
|
|
|
$browser_locale = \Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
|
|
|
|
2017-01-24 00:35:16 +00:00
|
|
|
foreach ($supported_locales as $lang_code => $lang_name) {
|
|
|
|
if (strcmp(substr($browser_locale, 0, 2), substr($lang_code, 0, 2)) == 0) {
|
2016-10-07 02:41:04 +00:00
|
|
|
$locale = $lang_code;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default to system option.
|
2017-01-24 00:35:16 +00:00
|
|
|
if (!$locale) {
|
2016-10-07 02:41:04 +00:00
|
|
|
$locale = $this->config->application->locale->default;
|
2017-01-24 00:35:16 +00:00
|
|
|
}
|
2016-10-07 02:41:04 +00:00
|
|
|
|
|
|
|
return $locale;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the user-customized or system default theme.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getTheme()
|
|
|
|
{
|
2017-01-24 00:35:16 +00:00
|
|
|
if ($this->user !== null && !empty($this->user->theme)) {
|
2016-10-07 02:41:04 +00:00
|
|
|
$available_themes = $this->config->application->themes->available->toArray();
|
2017-01-24 00:35:16 +00:00
|
|
|
if (isset($available_themes[$this->user->theme])) {
|
2016-10-07 02:41:04 +00:00
|
|
|
return $this->user->theme;
|
2017-01-24 00:35:16 +00:00
|
|
|
}
|
2016-10-07 02:41:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->config->application->themes->default;
|
|
|
|
}
|
|
|
|
}
|