Add channels

This commit is contained in:
Jay Trees 2022-04-07 11:14:32 +02:00
parent 9c830273da
commit 2bddcb3871
6 changed files with 74 additions and 10 deletions

View file

@ -23,7 +23,8 @@ $(function() {
} }
}); });
$('.ui.dropdown').dropdown({ $('.ui.dropdown').dropdown();
$('.ui.dropdown.locale').dropdown({
sortSelect : 'natural', sortSelect : 'natural',
}); });
}); });

View file

@ -16,7 +16,15 @@ define('ENV_IS_DEV', false);
define( define(
'CHANNELS', 'CHANNELS',
array( array(
'stable' => 'wishthis.online', array(
'release-candidate' => 'rc.wishthis.online', 'branch' => 'stable',
'host' => 'wishthis.online',
'label' => __('Stable'),
),
array(
'branch' => 'release-candidate',
'host' => 'rc.wishthis.online',
'label' => __('Release candidate'),
),
) )
); );

View file

@ -8,6 +8,34 @@
function redirect(string $target) function redirect(string $target)
{ {
global $user;
if (
defined('CHANNELS')
&& is_array(CHANNELS)
&& isset($user->channel)
&& '127.0.0.1' !== $_SERVER['REMOTE_ADDR']
) {
$host = null;
foreach (CHANNELS as $channel) {
if (
$channel['branch'] === $user->channel
&& $channel['host'] !== $_SERVER['HTTP_HOST']
) {
$host = $channel['host'];
break;
}
}
if (null !== $host) {
$target = 'https://' . $host . $target;
header('Location: ' . $target);
die();
}
}
if ($target !== $_SERVER['REQUEST_URI']) { if ($target !== $_SERVER['REQUEST_URI']) {
header('Location: ' . $target); header('Location: ' . $target);
die(); die();

View file

@ -136,7 +136,8 @@ switch ($step) {
`locale` VARCHAR(5) NOT NULL DEFAULT "' . DEFAULT_LOCALE . '", `locale` VARCHAR(5) NOT NULL DEFAULT "' . DEFAULT_LOCALE . '",
`name_first` VARCHAR(32) NULL DEFAULT NULL, `name_first` VARCHAR(32) NULL DEFAULT NULL,
`name_last` VARCHAR(32) NULL DEFAULT NULL, `name_last` VARCHAR(32) NULL DEFAULT NULL,
`name_nick` VARCHAR(32) NULL DEFAULT NULL `name_nick` VARCHAR(32) NULL DEFAULT NULL,
`channel` VARCHAR(24) NULL DEFAULT NULL
);'); );');
$database->query('CREATE INDEX `idx_password` ON `users` (`password`);'); $database->query('CREATE INDEX `idx_password` ON `users` (`password`);');

View file

@ -38,6 +38,11 @@ if (isset($_POST['user-id'], $_POST['section'])) {
'key' => 'user-locale', 'key' => 'user-locale',
'label' => __('Language'), 'label' => __('Language'),
), ),
array(
'column' => 'channel',
'key' => 'user-channel',
'label' => __('Channel'),
),
); );
$loginRequired = false; $loginRequired = false;
@ -83,10 +88,12 @@ if (isset($_POST['user-id'], $_POST['section'])) {
$loginRequired = true; $loginRequired = true;
} }
if ($set) {
$database $database
->query('UPDATE `users` ->query('UPDATE `users`
SET ' . implode(',', $set) . ' SET ' . implode(',', $set) . '
WHERE `id` = ' . $_POST['user-id']); WHERE `id` = ' . $_POST['user-id']);
}
if ($loginRequired) { if ($loginRequired) {
session_destroy(); session_destroy();
@ -234,7 +241,7 @@ $page->navigation();
<div class="field"> <div class="field">
<label><?= __('Language') ?></label> <label><?= __('Language') ?></label>
<select class="ui search dropdown" name="user-locale"> <select class="ui search dropdown locale" name="user-locale">
<?php if (!in_array('en', $locales)) { ?> <?php if (!in_array('en', $locales)) { ?>
<option value="<?= 'en' ?>"><?= \Locale::getDisplayName('en', $user->locale) ?></option> <option value="<?= 'en' ?>"><?= \Locale::getDisplayName('en', $user->locale) ?></option>
<?php } ?> <?php } ?>
@ -248,6 +255,24 @@ $page->navigation();
<?php } ?> <?php } ?>
</select> </select>
</div> </div>
<?php if (defined('CHANNELS') && is_array(CHANNELS)) { ?>
<div class="field">
<label><?= __('Channel') ?></label>
<select class="ui search clearable dropdown" name="user-channel">
<option value=""><?= __('Select channel') ?></option>
<?php foreach (CHANNELS as $channel) { ?>
<?php if ($channel['branch'] === $user->channel) { ?>
<option value="<?= $channel['branch'] ?>" selected><?= $channel['label'] ?></option>
<?php } else { ?>
<option value="<?= $channel['branch'] ?>"><?= $channel['label'] ?></option>
<?php } ?>
<?php } ?>
</select>
</div>
<?php } ?>
</div> </div>
<div class="ui error message"></div> <div class="ui error message"></div>

View file

@ -1,5 +1,6 @@
ALTER TABLE `users` ALTER TABLE `users`
ADD COLUMN `name_first` VARCHAR(32) NULL DEFAULT NULL, ADD COLUMN `name_first` VARCHAR(32) NULL DEFAULT NULL,
ADD COLUMN `name_last` VARCHAR(32) NULL DEFAULT NULL, ADD COLUMN `name_last` VARCHAR(32) NULL DEFAULT NULL,
ADD COLUMN `name_nick` VARCHAR(32) NULL DEFAULT NULL ADD COLUMN `name_nick` VARCHAR(32) NULL DEFAULT NULL,
ADD COLUMN `channel` VARCHAR(24) NULL DEFAULT NULL
; ;