Browse Source

[BS5] add theme selector

FreddleSpl0it 3 years ago
parent
commit
37b4ff811d

+ 3 - 0
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 = 'admin.twig';
 $template_data = [
 $template_data = [
@@ -90,6 +92,7 @@ $template_data = [
   'tfa_id' => @$_SESSION['tfa_id'],
   'tfa_id' => @$_SESSION['tfa_id'],
   'fido2_cid' => @$_SESSION['fido2_cid'],
   'fido2_cid' => @$_SESSION['fido2_cid'],
   'fido2_data' => $fido2_data,
   'fido2_data' => $fido2_data,
+  'themes' => $themes,
   'gal' => @$_SESSION['gal'],
   'gal' => @$_SESSION['gal'],
   'license_guid' => license('guid'),
   'license_guid' => license('guid'),
   'api' => [
   'api' => [

+ 29 - 0
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_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_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);
           $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 {
           try {
             $redis->set('TITLE_NAME', htmlspecialchars($title_name));
             $redis->set('TITLE_NAME', htmlspecialchars($title_name));
             $redis->set('MAIN_NAME', htmlspecialchars($main_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_TEXT', $ui_announcement_text);
             $redis->set('UI_ANNOUNCEMENT_TYPE', $ui_announcement_type);
             $redis->set('UI_ANNOUNCEMENT_TYPE', $ui_announcement_type);
             $redis->set('UI_ANNOUNCEMENT_ACTIVE', $ui_announcement_active);
             $redis->set('UI_ANNOUNCEMENT_ACTIVE', $ui_announcement_active);
+            $redis->set('UI_THEME', $theme);
           }
           }
           catch (RedisException $e) {
           catch (RedisException $e) {
             $_SESSION['return'][] = array(
             $_SESSION['return'][] = array(
@@ -228,6 +244,19 @@ function customize($_action, $_item, $_data = null) {
             return false;
             return false;
           }
           }
         break;
         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':
         case 'main_logo_specs':
           try {
           try {
             $image = new Imagick();
             $image = new Imagick();

+ 1 - 1
data/web/inc/prerequisites.inc.php

@@ -252,7 +252,7 @@ $css_minifier = new CSSminifierExtended();
 $css_dir = array_diff(scandir('/web/css/build'), array('..', '.'));
 $css_dir = array_diff(scandir('/web/css/build'), array('..', '.'));
 // get customized ui data
 // get customized ui data
 $UI_TEXTS = customize('get', 'ui_texts');
 $UI_TEXTS = customize('get', 'ui_texts');
-$UI_THEME = "lumen"; // TODO: customize('get', 'ui_theme');
+$UI_THEME = customize('get', 'ui_theme');
 // minify bootstrap theme
 // minify bootstrap theme
 if (file_exists('/web/css/themes/'.$UI_THEME.'-bootstrap.css'))
 if (file_exists('/web/css/themes/'.$UI_THEME.'-bootstrap.css'))
   $css_minifier->add('/web/css/themes/'.$UI_THEME.'-bootstrap.css');
   $css_minifier->add('/web/css/themes/'.$UI_THEME.'-bootstrap.css');

+ 1 - 0
data/web/lang/lang.en.json

@@ -337,6 +337,7 @@
         "ui_header_announcement_type_info": "Info",
         "ui_header_announcement_type_info": "Info",
         "ui_header_announcement_type_warning": "Important",
         "ui_header_announcement_type_warning": "Important",
         "ui_texts": "UI labels and texts",
         "ui_texts": "UI labels and texts",
+        "ui_theme": "Design",
         "unban_pending": "unban pending",
         "unban_pending": "unban pending",
         "unchanged_if_empty": "If unchanged leave blank",
         "unchanged_if_empty": "If unchanged leave blank",
         "upload": "Upload",
         "upload": "Upload",

+ 8 - 0
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 />
       <legend data-bs-target="#ui_texts" style="padding-top:20px" unselectable="on">{{ lang.admin.ui_texts }}</legend><hr />
       <div id="ui_texts">
       <div id="ui_texts">
         <form class="form" data-id="uitexts" role="form" method="post">
         <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">
           <div class="mb-2">
             <label for="uitests_title_name">{{ lang.admin.title_name }}:</label>
             <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 }}">
             <input type="text" class="form-control" id="uitests_title_name" name="title_name" placeholder="mailcow UI" value="{{ ui_texts.title_name|raw }}">