public
nobgit
read
NobMail
Based on mailcow: dockerized
Languages
Repository composition by tracked source files.
PHP
49%
JavaScript
35%
HTML
9%
CSS
4%
Shell
2%
Python
1%
Lua
0%
Perl
0%
Ruby
0%
SCSS
0%
Create file
Wiki Documentation
Clone
https://nobgit.com/orgs/nobgit/nobmail.git
ssh://[email protected]:2222/orgs/nobgit/nobmail.git
Commit
[BS5] add theme selector
37b4ff81
data/web/admin.php | 3 +++
data/web/inc/functions.customize.inc.php | 29 ++++++++++++++++++++++
data/web/inc/prerequisites.inc.php | 2 +-
data/web/lang/lang.en.json | 1 +
data/web/templates/admin/tab-config-customize.twig | 8 ++++++
5 files changed, 42 insertions(+), 1 deletion(-)
Diff
diff --git a/data/web/admin.php b/data/web/admin.php
index 78b45729..2a79e69e 100644
--- a/data/web/admin.php
+++ b/data/web/admin.php
@@ -83,6 +83,8 @@ foreach ($RSPAMD_MAPS['regex'] as $rspamd_regex_desc => $rspamd_regex_map) {
];
}
+$themes = array_diff(scandir('/web/css/themes'), array('..', '.'));
+$themes = array_filter((str_replace("-bootstrap.css", "", $themes)));
$template = 'admin.twig';
$template_data = [
@@ -90,6 +92,7 @@ $template_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' => [
diff --git a/data/web/inc/functions.customize.inc.php b/data/web/inc/functions.customize.inc.php
index de1b22c3..5b2f3076 100644
--- a/data/web/inc/functions.customize.inc.php
+++ b/data/web/inc/functions.customize.inc.php
@@ -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));
@@ -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(
@@ -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();
diff --git a/data/web/inc/prerequisites.inc.php b/data/web/inc/prerequisites.inc.php
index 20cb742c..18ebbca5 100644
--- a/data/web/inc/prerequisites.inc.php
+++ b/data/web/inc/prerequisites.inc.php
@@ -252,7 +252,7 @@ $css_minifier = new CSSminifierExtended();
$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');
diff --git a/data/web/lang/lang.en.json b/data/web/lang/lang.en.json
index 9eb4f82b..cc07b2fc 100644
--- a/data/web/lang/lang.en.json
+++ b/data/web/lang/lang.en.json
@@ -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",
diff --git a/data/web/templates/admin/tab-config-customize.twig b/data/web/templates/admin/tab-config-customize.twig
index 1452a370..2486747b 100644
--- a/data/web/templates/admin/tab-config-customize.twig
+++ b/data/web/templates/admin/tab-config-customize.twig
@@ -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 }}">