mirror of
https://github.com/AzuraCast/AzuraCast.git
synced 2024-06-14 13:16:37 +00:00
Move time zone and locale customization to a user profile level.
This commit is contained in:
parent
4177085b49
commit
1ed54855e8
|
@ -277,9 +277,12 @@ $cache = $di->get('cache');
|
|||
|
||||
if (!APP_IS_COMMAND_LINE)
|
||||
{
|
||||
/** @var \Entity\User|null $user */
|
||||
$user = $di->get('user');
|
||||
|
||||
// Set time zone.
|
||||
$timezone = $di['em']->getRepository('Entity\Settings')->getSetting('timezone', date_default_timezone_get());
|
||||
date_default_timezone_set($timezone);
|
||||
if ($user !== null && !empty($user->timezone))
|
||||
date_default_timezone_set($user->timezone);
|
||||
|
||||
/*
|
||||
* Commands:
|
||||
|
@ -289,21 +292,34 @@ if (!APP_IS_COMMAND_LINE)
|
|||
* find /var/azuracast/www/app/locale -name \*.po -execdir msgfmt default.po -o default.mo \;
|
||||
*/
|
||||
|
||||
// Set up localization.
|
||||
$browser_locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||
|
||||
$locale = null;
|
||||
$supported_locales = $config->application->locale->supported->toArray();
|
||||
foreach($supported_locales as $lang_code => $lang_name)
|
||||
|
||||
// Prefer user-based profile locale.
|
||||
if ($user !== null && !empty($user->locale) && $user->locale !== 'default')
|
||||
{
|
||||
if (strcmp(substr($browser_locale, 0, 2), substr($lang_code, 0, 2)) == 0)
|
||||
if (isset($supported_locales[$user->locale]))
|
||||
$locale = $user->locale;
|
||||
}
|
||||
|
||||
// Attempt to load from browser headers.
|
||||
if (!$locale)
|
||||
{
|
||||
$browser_locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||
|
||||
foreach($supported_locales as $lang_code => $lang_name)
|
||||
{
|
||||
$locale = $lang_code;
|
||||
break;
|
||||
if (strcmp(substr($browser_locale, 0, 2), substr($lang_code, 0, 2)) == 0)
|
||||
{
|
||||
$locale = $lang_code;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($locale))
|
||||
$locale = $di['em']->getRepository('Entity\Settings')->getSetting('locale', $config->application->locale->default);
|
||||
// Default to system option.
|
||||
if (!$locale)
|
||||
$locale = $config->application->locale->default;
|
||||
|
||||
putenv("LANG=".$locale);
|
||||
setlocale(LC_ALL, $locale);
|
||||
|
|
|
@ -29,6 +29,16 @@ class Entity implements \ArrayAccess
|
|||
return $this->_setVar($key, $value);
|
||||
}
|
||||
|
||||
public function __isset($key)
|
||||
{
|
||||
$method_name = $this->_getMethodName($key, 'get');
|
||||
|
||||
if (method_exists($this, $method_name))
|
||||
return $this->$method_name();
|
||||
else
|
||||
return property_exists($this, $key);
|
||||
}
|
||||
|
||||
public function __call($method, $arguments)
|
||||
{
|
||||
if (substr($method, 0, 3) == "get") {
|
||||
|
|
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2016-10-04 21:05+0000\n"
|
||||
"POT-Creation-Date: 2016-10-06 05:59+0000\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
@ -26,7 +26,7 @@ msgid "System Maintenance"
|
|||
msgstr ""
|
||||
|
||||
#: /var/azuracast/www/app/modules/admin/config/dashboard.conf.php:8
|
||||
#: /var/azuracast/www/app/modules/admin/config/forms/settings.conf.php:22
|
||||
#: /var/azuracast/www/app/modules/admin/config/forms/settings.conf.php:19
|
||||
msgid "System Settings"
|
||||
msgstr ""
|
||||
|
||||
|
@ -80,10 +80,11 @@ msgstr ""
|
|||
#: /var/azuracast/www/app/modules/admin/config/forms/action.conf.php:27
|
||||
#: /var/azuracast/www/app/modules/admin/config/forms/api_key.conf.php:15
|
||||
#: /var/azuracast/www/app/modules/admin/config/forms/role.conf.php:60
|
||||
#: /var/azuracast/www/app/modules/admin/config/forms/settings.conf.php:52
|
||||
#: /var/azuracast/www/app/modules/admin/config/forms/settings.conf.php:36
|
||||
#: /var/azuracast/www/app/modules/admin/config/forms/song.conf.php:36
|
||||
#: /var/azuracast/www/app/modules/admin/config/forms/station.conf.php:101
|
||||
#: /var/azuracast/www/app/modules/admin/config/forms/user.conf.php:37
|
||||
#: /var/azuracast/www/app/modules/frontend/config/forms/profile.conf.php:65
|
||||
#: /var/azuracast/www/app/modules/stations/config/forms/automation.conf.php:32
|
||||
#: /var/azuracast/www/app/modules/stations/config/forms/media.conf.php:20
|
||||
#: /var/azuracast/www/app/modules/stations/config/forms/playlist.conf.php:171
|
||||
|
@ -116,36 +117,17 @@ msgstr ""
|
|||
msgid "Actions"
|
||||
msgstr ""
|
||||
|
||||
#: /var/azuracast/www/app/modules/admin/config/forms/settings.conf.php:26
|
||||
#: /var/azuracast/www/app/modules/admin/config/forms/settings.conf.php:23
|
||||
msgid "Site Base URL"
|
||||
msgstr ""
|
||||
|
||||
#: /var/azuracast/www/app/modules/admin/config/forms/settings.conf.php:27
|
||||
#: /var/azuracast/www/app/modules/admin/config/forms/settings.conf.php:24
|
||||
msgid ""
|
||||
"The base URL where this service is located. For local testing, use "
|
||||
"\"localhost\". Otherwise, use either the external IP address or fully-"
|
||||
"qualified domain name pointing to the server."
|
||||
msgstr ""
|
||||
|
||||
#: /var/azuracast/www/app/modules/admin/config/forms/settings.conf.php:32
|
||||
msgid "Default Language"
|
||||
msgstr ""
|
||||
|
||||
#: /var/azuracast/www/app/modules/admin/config/forms/settings.conf.php:38
|
||||
msgid "Server Time Zone"
|
||||
msgstr ""
|
||||
|
||||
#: /var/azuracast/www/app/modules/admin/config/forms/settings.conf.php:39
|
||||
msgid "All times displayed on the site will be based on this time zone."
|
||||
msgstr ""
|
||||
|
||||
#: /var/azuracast/www/app/modules/admin/config/forms/settings.conf.php:39
|
||||
#: /var/azuracast/www/app/modules/stations/config/forms/playlist.conf.php:94
|
||||
#: /var/azuracast/www/app/modules/stations/config/forms/playlist.conf.php:159
|
||||
#, php-format
|
||||
msgid "Current server time is <b>%s</b>."
|
||||
msgstr ""
|
||||
|
||||
#: /var/azuracast/www/app/modules/admin/config/forms/song.conf.php:8
|
||||
msgid "Metadata"
|
||||
msgstr ""
|
||||
|
@ -233,7 +215,7 @@ msgstr ""
|
|||
#: /var/azuracast/www/app/modules/admin/config/forms/user.conf.php:18
|
||||
#: /var/azuracast/www/app/modules/admin/views/scripts/users/index.phtml:30
|
||||
#: /var/azuracast/www/app/modules/frontend/config/forms/login.conf.php:11
|
||||
#: /var/azuracast/www/app/modules/frontend/config/forms/profile.conf.php:23
|
||||
#: /var/azuracast/www/app/modules/frontend/config/forms/profile.conf.php:26
|
||||
#: /var/azuracast/www/app/modules/frontend/config/forms/register.conf.php:11
|
||||
#: /var/azuracast/www/app/modules/frontend/views/scripts/account/login.phtml:12
|
||||
#: /var/azuracast/www/app/modules/frontend/views/scripts/setup/register.phtml:12
|
||||
|
@ -241,7 +223,7 @@ msgid "E-mail Address"
|
|||
msgstr ""
|
||||
|
||||
#: /var/azuracast/www/app/modules/admin/config/forms/user.conf.php:24
|
||||
#: /var/azuracast/www/app/modules/frontend/config/forms/profile.conf.php:30
|
||||
#: /var/azuracast/www/app/modules/frontend/config/forms/profile.conf.php:33
|
||||
msgid "Reset Password"
|
||||
msgstr ""
|
||||
|
||||
|
@ -391,17 +373,45 @@ msgstr ""
|
|||
msgid "Log in"
|
||||
msgstr ""
|
||||
|
||||
#: /var/azuracast/www/app/modules/frontend/config/forms/profile.conf.php:11
|
||||
#: /var/azuracast/www/app/modules/frontend/config/forms/profile.conf.php:10
|
||||
msgid "Use Browser Default"
|
||||
msgstr ""
|
||||
|
||||
#: /var/azuracast/www/app/modules/frontend/config/forms/profile.conf.php:17
|
||||
#: /var/azuracast/www/app/modules/frontend/config/forms/register.conf.php:7
|
||||
msgid "Account Information"
|
||||
msgstr ""
|
||||
|
||||
#: /var/azuracast/www/app/modules/frontend/config/forms/profile.conf.php:31
|
||||
#: /var/azuracast/www/app/modules/frontend/config/forms/profile.conf.php:21
|
||||
#: /var/azuracast/www/app/modules/stations/views/scripts/files/index.phtml:66
|
||||
msgid "Name"
|
||||
msgstr ""
|
||||
|
||||
#: /var/azuracast/www/app/modules/frontend/config/forms/profile.conf.php:34
|
||||
msgid "To change your password, enter the new password in the field below."
|
||||
msgstr ""
|
||||
|
||||
#: /var/azuracast/www/app/modules/frontend/config/forms/profile.conf.php:42
|
||||
msgid "Save Profile"
|
||||
msgid "Customization"
|
||||
msgstr ""
|
||||
|
||||
#: /var/azuracast/www/app/modules/frontend/config/forms/profile.conf.php:46
|
||||
msgid "Server Time Zone"
|
||||
msgstr ""
|
||||
|
||||
#: /var/azuracast/www/app/modules/frontend/config/forms/profile.conf.php:47
|
||||
msgid "All times displayed on the site will be based on this time zone."
|
||||
msgstr ""
|
||||
|
||||
#: /var/azuracast/www/app/modules/frontend/config/forms/profile.conf.php:47
|
||||
#: /var/azuracast/www/app/modules/stations/config/forms/playlist.conf.php:94
|
||||
#: /var/azuracast/www/app/modules/stations/config/forms/playlist.conf.php:159
|
||||
#, php-format
|
||||
msgid "Current server time is <b>%s</b>."
|
||||
msgstr ""
|
||||
|
||||
#: /var/azuracast/www/app/modules/frontend/config/forms/profile.conf.php:53
|
||||
msgid "Default Language"
|
||||
msgstr ""
|
||||
|
||||
#: /var/azuracast/www/app/modules/frontend/config/forms/register.conf.php:29
|
||||
|
@ -858,10 +868,6 @@ msgstr ""
|
|||
msgid "Create Folder"
|
||||
msgstr ""
|
||||
|
||||
#: /var/azuracast/www/app/modules/stations/views/scripts/files/index.phtml:66
|
||||
msgid "Name"
|
||||
msgstr ""
|
||||
|
||||
#: /var/azuracast/www/app/modules/stations/views/scripts/files/index.phtml:67
|
||||
msgid "Title"
|
||||
msgstr ""
|
||||
|
|
|
@ -7,16 +7,24 @@ use \Doctrine\Common\Collections\ArrayCollection;
|
|||
/**
|
||||
* @Table(name="users")
|
||||
* @Entity(repositoryClass="UserRepository")
|
||||
* @HasLifecycleCallbacks
|
||||
*/
|
||||
class User extends \App\Doctrine\Entity
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->roles = new ArrayCollection;
|
||||
$this->stations = new ArrayCollection;
|
||||
|
||||
$this->time_created = time();
|
||||
$this->time_updated = time();
|
||||
$this->created_at = time();
|
||||
$this->updated_at = time();
|
||||
}
|
||||
|
||||
/**
|
||||
* @PrePersist
|
||||
*/
|
||||
public function preSave()
|
||||
{
|
||||
$this->updated_at = time();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,29 +65,23 @@ class User extends \App\Doctrine\Entity
|
|||
|
||||
public function generateRandomPassword()
|
||||
{
|
||||
$this->setAuthPassword(md5('APP_EXTERNAL_'.mt_rand(0, 10000)));
|
||||
}
|
||||
|
||||
/** @Column(name="auth_last_login_time", type="integer", nullable=true) */
|
||||
protected $auth_last_login_time;
|
||||
|
||||
/** @Column(name="auth_recovery_code", type="string", length=50, nullable=true) */
|
||||
protected $auth_recovery_code;
|
||||
|
||||
public function generateAuthRecoveryCode()
|
||||
{
|
||||
$this->auth_recovery_code = sha1(mt_rand());
|
||||
return $this->auth_recovery_code;
|
||||
$this->setAuthPassword(md5('APP_EXTERNAL_'.mt_rand()));
|
||||
}
|
||||
|
||||
/** @Column(name="name", type="string", length=100, nullable=true) */
|
||||
protected $name;
|
||||
|
||||
/** @Column(name="gender", type="string", length=1, nullable=true) */
|
||||
protected $gender;
|
||||
|
||||
/** @Column(name="customization", type="json", nullable=true) */
|
||||
protected $customization;
|
||||
/** @Column(name="timezone", type="string", length=100, nullable=true) */
|
||||
protected $timezone;
|
||||
|
||||
/** @Column(name="locale", type="string", length=25, nullable=true) */
|
||||
protected $locale;
|
||||
|
||||
/** @Column(name="created_at", type="integer") */
|
||||
protected $created_at;
|
||||
|
||||
/** @Column(name="updated_at", type="integer") */
|
||||
protected $updated_at;
|
||||
|
||||
/**
|
||||
* @ManyToMany(targetEntity="Role", inversedBy="users")
|
||||
|
@ -89,15 +91,6 @@ class User extends \App\Doctrine\Entity
|
|||
* )
|
||||
*/
|
||||
protected $roles;
|
||||
|
||||
/**
|
||||
* @ManyToMany(targetEntity="Station", inversedBy="users")
|
||||
* @JoinTable(name="user_manages_station",
|
||||
* joinColumns={@JoinColumn(name="user_id", referencedColumnName="uid", onDelete="CASCADE")},
|
||||
* inverseJoinColumns={@JoinColumn(name="station_id", referencedColumnName="id", onDelete="CASCADE")}
|
||||
* )
|
||||
*/
|
||||
protected $stations;
|
||||
}
|
||||
|
||||
use App\Doctrine\Repository;
|
||||
|
|
49
app/models/Migration/Version20161006030903.php
Normal file
49
app/models/Migration/Version20161006030903.php
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace Migration;
|
||||
|
||||
use Doctrine\DBAL\Migrations\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
class Version20161006030903 extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function up(Schema $schema)
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||
|
||||
$this->addSql('DROP TABLE IF EXISTS user_manages_station');
|
||||
|
||||
$this->addSql('DELETE FROM role_has_actions WHERE role_id NOT IN (SELECT id FROM role)');
|
||||
$this->addSql('DELETE FROM role_has_actions WHERE action_id NOT IN (SELECT id FROM action)');
|
||||
|
||||
$this->addSql('ALTER TABLE role_has_actions ADD CONSTRAINT FK_50EEC1BDD60322AC FOREIGN KEY (role_id) REFERENCES role (id) ON DELETE CASCADE');
|
||||
$this->addSql('ALTER TABLE role_has_actions ADD CONSTRAINT FK_50EEC1BD9D32F035 FOREIGN KEY (action_id) REFERENCES action (id) ON DELETE CASCADE');
|
||||
$this->addSql('CREATE INDEX IDX_50EEC1BD9D32F035 ON role_has_actions (action_id)');
|
||||
|
||||
$this->addSql('ALTER TABLE users ADD timezone VARCHAR(100) DEFAULT NULL, ADD locale VARCHAR(25) DEFAULT NULL, ADD created_at INT NOT NULL, ADD updated_at INT NOT NULL, DROP auth_last_login_time, DROP auth_recovery_code, DROP gender, DROP customization');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function down(Schema $schema)
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||
|
||||
$this->addSql('CREATE TABLE user_manages_station (user_id INT NOT NULL, station_id INT NOT NULL, INDEX IDX_2453B56BA76ED395 (user_id), INDEX IDX_2453B56B21BDB235 (station_id), PRIMARY KEY(user_id, station_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
|
||||
$this->addSql('ALTER TABLE user_manages_station ADD CONSTRAINT FK_2453B56B21BDB235 FOREIGN KEY (station_id) REFERENCES station (id) ON DELETE CASCADE');
|
||||
$this->addSql('ALTER TABLE user_manages_station ADD CONSTRAINT FK_2453B56BA76ED395 FOREIGN KEY (user_id) REFERENCES users (uid) ON DELETE CASCADE');
|
||||
$this->addSql('ALTER TABLE role_has_actions DROP FOREIGN KEY FK_50EEC1BDD60322AC');
|
||||
$this->addSql('ALTER TABLE role_has_actions DROP FOREIGN KEY FK_50EEC1BD9D32F035');
|
||||
$this->addSql('DROP INDEX IDX_50EEC1BD9D32F035 ON role_has_actions');
|
||||
$this->addSql('ALTER TABLE users ADD auth_last_login_time INT DEFAULT NULL, ADD auth_recovery_code VARCHAR(50) DEFAULT NULL COLLATE utf8_unicode_ci, ADD gender VARCHAR(1) DEFAULT NULL COLLATE utf8_unicode_ci, ADD customization LONGTEXT DEFAULT NULL COLLATE utf8_unicode_ci COMMENT \'(DC2Type:json)\', DROP timezone, DROP locale, DROP created_at, DROP updated_at');
|
||||
}
|
||||
}
|
|
@ -6,9 +6,6 @@
|
|||
$base_url_parts = parse_url($_SERVER['HTTP_HOST']);
|
||||
$base_url_default = $base_url_parts['host'];
|
||||
|
||||
/** @var \App\Config $config */
|
||||
$config = $di['config'];
|
||||
|
||||
return [
|
||||
/**
|
||||
* Form Configuration
|
||||
|
@ -28,19 +25,6 @@ return [
|
|||
'default' => $base_url_default,
|
||||
]],
|
||||
|
||||
'locale' => ['radio', [
|
||||
'label' => _('Default Language'),
|
||||
'options' => $config->application->locale->supported->toArray(),
|
||||
'default' => $config->application->locale->default,
|
||||
]],
|
||||
|
||||
'timezone' => ['select', [
|
||||
'label' => _('Server Time Zone'),
|
||||
'description' => _('All times displayed on the site will be based on this time zone.').'<br>'.sprintf(_('Current server time is <b>%s</b>.'), date('g:ia')),
|
||||
'options' => \App\Timezone::fetchSelect(),
|
||||
'default' => date_default_timezone_get(),
|
||||
]],
|
||||
|
||||
],
|
||||
],
|
||||
|
||||
|
|
|
@ -3,6 +3,12 @@
|
|||
* Profile Form
|
||||
*/
|
||||
|
||||
/** @var \App\Config $config */
|
||||
$config = $di['config'];
|
||||
|
||||
$locale_select = $config->application->locale->supported->toArray();
|
||||
$locale_select = ['default' => _('Use Browser Default')] + $locale_select;
|
||||
|
||||
return [
|
||||
'method' => 'post',
|
||||
'groups' => [
|
||||
|
@ -11,13 +17,10 @@ return [
|
|||
'legend' => _('Account Information'),
|
||||
'elements' => [
|
||||
|
||||
/*
|
||||
'name' => array('text', array(
|
||||
'label' => 'Your Name',
|
||||
'label' => _('Name'),
|
||||
'class' => 'half-width',
|
||||
'required' => true,
|
||||
)),
|
||||
*/
|
||||
|
||||
'email' => ['text', [
|
||||
'label' => _('E-mail Address'),
|
||||
|
@ -35,11 +38,31 @@ return [
|
|||
],
|
||||
],
|
||||
|
||||
'customization' => [
|
||||
'legend' => _('Customization'),
|
||||
'elements' => [
|
||||
|
||||
'timezone' => ['select', [
|
||||
'label' => _('Server Time Zone'),
|
||||
'description' => _('All times displayed on the site will be based on this time zone.').'<br>'.sprintf(_('Current server time is <b>%s</b>.'), date('g:ia')),
|
||||
'options' => \App\Timezone::fetchSelect(),
|
||||
'default' => date_default_timezone_get(),
|
||||
]],
|
||||
|
||||
'locale' => ['radio', [
|
||||
'label' => _('Default Language'),
|
||||
'options' => $locale_select,
|
||||
'default' => 'default',
|
||||
]],
|
||||
|
||||
],
|
||||
],
|
||||
|
||||
'submit' => [
|
||||
'elements' => [
|
||||
'submit' => ['submit', [
|
||||
'type' => 'submit',
|
||||
'label' => _('Save Profile'),
|
||||
'label' => _('Save Changes'),
|
||||
'helper' => 'formButton',
|
||||
'class' => 'btn btn-lg btn-primary',
|
||||
]],
|
||||
|
|
Loading…
Reference in New Issue
Block a user