Skip to content

Commit

Permalink
[BS5] add theme selector
Browse files Browse the repository at this point in the history
  • Loading branch information
FreddleSpl0it committed Jun 14, 2022
1 parent 7384aab commit 37b4ff8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
3 changes: 3 additions & 0 deletions data/web/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,16 @@
];
}

$themes = array_diff(scandir('/web/css/themes'), array('..', '.'));
$themes = array_filter((str_replace("-bootstrap.css", "", $themes)));

$template = 'admin.twig';
$template_data = [
'tfa_data' => $tfa_data,
'tfa_id' => @$_SESSION['tfa_id'],
'fido2_cid' => @$_SESSION['fido2_cid'],
'fido2_data' => $fido2_data,
'themes' => $themes,
'gal' => @$_SESSION['gal'],
'license_guid' => license('guid'),
'api' => [
Expand Down
29 changes: 29 additions & 0 deletions data/web/inc/functions.customize.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ function customize($_action, $_item, $_data = null) {
$ui_announcement_text = $_data['ui_announcement_text'];
$ui_announcement_type = (in_array($_data['ui_announcement_type'], array('info', 'warning', 'danger'))) ? $_data['ui_announcement_type'] : false;
$ui_announcement_active = (!empty($_data['ui_announcement_active']) ? 1 : 0);

// check theme
$theme = strtolower($_data['ui_theme']);
$themes = array_diff(scandir('/web/css/themes'), array('..', '.'));
$themes = array_filter((str_replace("-bootstrap.css", "", $themes)));
if (!in_array($theme, $themes)){
// err, theme not found
$_SESSION['return'][] = array(
'type' => 'danger',
'log' => array(__FUNCTION__, $_action, $_item, $_data),
'msg' => "Theme not found"
);
return false;
}

try {
$redis->set('TITLE_NAME', htmlspecialchars($title_name));
$redis->set('MAIN_NAME', htmlspecialchars($main_name));
Expand All @@ -125,6 +140,7 @@ function customize($_action, $_item, $_data = null) {
$redis->set('UI_ANNOUNCEMENT_TEXT', $ui_announcement_text);
$redis->set('UI_ANNOUNCEMENT_TYPE', $ui_announcement_type);
$redis->set('UI_ANNOUNCEMENT_ACTIVE', $ui_announcement_active);
$redis->set('UI_THEME', $theme);
}
catch (RedisException $e) {
$_SESSION['return'][] = array(
Expand Down Expand Up @@ -228,6 +244,19 @@ function customize($_action, $_item, $_data = null) {
return false;
}
break;
case 'ui_theme':
try {
return $redis->get('UI_THEME');
}
catch (RedisException $e) {
$_SESSION['return'][] = array(
'type' => 'danger',
'log' => array(__FUNCTION__, $_action, $_item, $_data),
'msg' => array('redis_error', $e)
);
return false;
}
break;
case 'main_logo_specs':
try {
$image = new Imagick();
Expand Down
2 changes: 1 addition & 1 deletion data/web/inc/prerequisites.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ function get_remote_ip() {
$css_dir = array_diff(scandir('/web/css/build'), array('..', '.'));
// get customized ui data
$UI_TEXTS = customize('get', 'ui_texts');
$UI_THEME = "lumen"; // TODO: customize('get', 'ui_theme');
$UI_THEME = customize('get', 'ui_theme');
// minify bootstrap theme
if (file_exists('/web/css/themes/'.$UI_THEME.'-bootstrap.css'))
$css_minifier->add('/web/css/themes/'.$UI_THEME.'-bootstrap.css');
Expand Down
1 change: 1 addition & 0 deletions data/web/lang/lang.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@
"ui_header_announcement_type_info": "Info",
"ui_header_announcement_type_warning": "Important",
"ui_texts": "UI labels and texts",
"ui_theme": "Design",
"unban_pending": "unban pending",
"unchanged_if_empty": "If unchanged leave blank",
"upload": "Upload",
Expand Down
8 changes: 8 additions & 0 deletions data/web/templates/admin/tab-config-customize.twig
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@
<legend data-bs-target="#ui_texts" style="padding-top:20px" unselectable="on">{{ lang.admin.ui_texts }}</legend><hr />
<div id="ui_texts">
<form class="form" data-id="uitexts" role="form" method="post">
<div class="mb-4 d-flex flex-column">
<label for="uitests_theme">{{ lang.admin.ui_theme }}:</label>
<select class="full-width-select" data-live-search="true" id="uitests_theme" name="ui_theme" required>
{% for theme in themes %}
<option>{{ theme }}</option>
{% endfor %}
</select>
</div>
<div class="mb-2">
<label for="uitests_title_name">{{ lang.admin.title_name }}:</label>
<input type="text" class="form-control" id="uitests_title_name" name="title_name" placeholder="mailcow UI" value="{{ ui_texts.title_name|raw }}">
Expand Down

0 comments on commit 37b4ff8

Please sign in to comment.