From 37b4ff811d55f0e718ec16d6919a02be7d60262e Mon Sep 17 00:00:00 2001 From: FreddleSpl0it Date: Tue, 14 Jun 2022 16:31:21 +0200 Subject: [PATCH] [BS5] add theme selector --- 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 + .../templates/admin/tab-config-customize.twig | 8 +++++ 5 files changed, 42 insertions(+), 1 deletion(-) diff --git a/data/web/admin.php b/data/web/admin.php index 78b45729a..2a79e69e9 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 de1b22c37..5b2f30768 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 20cb742ce..18ebbca5f 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 9eb4f82ba..cc07b2fca 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 1452a3708..2486747b5 100644 --- a/data/web/templates/admin/tab-config-customize.twig +++ b/data/web/templates/admin/tab-config-customize.twig @@ -67,6 +67,14 @@ {{ lang.admin.ui_texts }}
+
+ + +