From e2efb62a6a41d002d918f9963c7138220b2274ea Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Tue, 19 Apr 2022 13:17:21 +0300 Subject: [PATCH] install theme selection --- install/core/Installer.php | 26 ++++++++++- install/core/actions/checkPermission.php | 33 ++++++++++---- install/core/actions/main.php | 20 +++++++-- install/core/actions/saveSettings.php | 19 ++++++-- install/core/tpl/index.tpl | 2 +- install/core/tpl/main.tpl | 57 +++++++++++++++++------- install/core/tpl/step1.tpl | 2 +- install/entry.php | 10 ++++- public/install/css/install.css | 29 +++++------- public/install/js/install.js | 12 +++-- 10 files changed, 152 insertions(+), 58 deletions(-) diff --git a/install/core/Installer.php b/install/core/Installer.php index 8f636f8462..803315155b 100644 --- a/install/core/Installer.php +++ b/install/core/Installer.php @@ -83,6 +83,7 @@ class Installer 'outboundEmailFromName', 'outboundEmailFromAddress', 'outboundEmailIsShared', + 'theme', ]; public function __construct() @@ -237,7 +238,15 @@ class Installer return $this->app->isInstalled(); } - private function getLanguage(): Language + public function createLanguage(string $language): Language + { + return $this->app + ->getContainer() + ->get('injectableFactory') + ->createWith(Language::class, ['language' => $language]); + } + + public function getLanguage(): Language { if (!isset($this->language)) { try { @@ -255,6 +264,14 @@ class Installer return $this->language; } + public function getThemeList(): array + { + return [ + 'HazyblueVertical', + 'DarkVertical', + ]; + } + public function getLanguageList($isTranslated = true): array { $languageList = $this->getMetadata()->get(['app', 'language', 'list']); @@ -349,6 +366,7 @@ class Installer 'passwordSalt' => $this->getPasswordHash()->generateSalt(), 'cryptKey' => $this->getContainer()->get('crypt')->generateKey(), 'hashSecretKey' => Util::generateSecretKey(), + 'theme' => $saveData['theme'] ?? 'HazyblueVertical', ]; if (empty($saveData['defaultPermissions']['user'])) { @@ -528,6 +546,7 @@ class Installer 'thousandSeparator', 'decimalMark', 'language', + 'theme', ]; $data = array_intersect_key($preferences, array_flip($permittedSettingList)); @@ -605,6 +624,11 @@ class Installer case 'language': $settingDefs['language']['options'] = $this->getLanguageList(false); + break; + + case 'theme': + $settingDefs['theme']['options'] = $this->getThemeList(); + break; } diff --git a/install/core/actions/checkPermission.php b/install/core/actions/checkPermission.php index ec7d6e4db9..c35a0f0562 100644 --- a/install/core/actions/checkPermission.php +++ b/install/core/actions/checkPermission.php @@ -28,31 +28,48 @@ ************************************************************************/ ob_start(); -$result = array('success' => true, 'errorMsg' => ''); + +$result = ['success' => true, 'errorMsg' => '']; if (!$installer->checkPermission()) { $result['success'] = false; $error = $installer->getLastPermissionError(); + $urls = array_keys($error); - $group = array(); - foreach($error as $folder => $permission) { + + $group = []; + + foreach ($error as $folder => $permission) { $group[implode('-', $permission)][] = $folder; } + ksort($group); + $instruction = ''; $instructionSU = ''; $changeOwner = true; + foreach($group as $permission => $folders) { - if ($permission == '0644-0755') $folders = ''; - $instruction .= $systemHelper->getPermissionCommands(array($folders, ''), explode('-', $permission), false, null, $changeOwner) . "
"; - $instructionSU .= $systemHelper->getPermissionCommands(array($folders, ''), explode('-', $permission), true, null, $changeOwner) . "
"; + if ($permission == '0644-0755') { + $folders = ''; + } + + $instruction .= $systemHelper + ->getPermissionCommands([$folders, ''], explode('-', $permission), false, null, $changeOwner) . "
"; + + $instructionSU .= $systemHelper + ->getPermissionCommands([$folders, ''], explode('-', $permission), true, null, $changeOwner) . "
"; + if ($changeOwner) { $changeOwner = false; } } + $result['errorMsg'] = $langs['messages']['Permission denied to'] . ':
'.implode('
', $urls).'
'; - $result['errorFixInstruction'] = str_replace( '"{C}"' , $instruction, $langs['messages']['permissionInstruction']) . "
" . - str_replace( '{CSU}' , $instructionSU, $langs['messages']['operationNotPermitted']); + + $result['errorFixInstruction'] = + str_replace( '"{C}"' , $instruction, $langs['messages']['permissionInstruction']) . + "
" . str_replace( '{CSU}' , $instructionSU, $langs['messages']['operationNotPermitted']); } ob_clean(); diff --git a/install/core/actions/main.php b/install/core/actions/main.php index 2879f3a31a..32e3ac81ba 100644 --- a/install/core/actions/main.php +++ b/install/core/actions/main.php @@ -29,11 +29,14 @@ $config = $installer->getConfig(); -$fields = array( - 'user-lang' => array( +$fields = [ + 'user-lang' => [ 'default' => $config->get('language', 'en_US'), - ), -); + ], + 'theme' => [ + 'default' => $config->get('theme'), + ], +]; foreach ($fields as $fieldName => $field) { if (isset($_SESSION['install'][$fieldName])) { @@ -43,4 +46,13 @@ foreach ($fields as $fieldName => $field) { } } +$language = $installer->createLanguage($_SESSION['install']['user-lang'] ?? 'en_US'); + +$themes = []; +foreach ($installer->getThemeList() as $item) { + $themes[$item] = $language->translate($item, 'themes', 'Global'); +} + +$smarty->assign('themeLabel', $language->translate('theme', 'fields', 'Settings')); $smarty->assign('fields', $fields); +$smarty->assign("themes", $themes); \ No newline at end of file diff --git a/install/core/actions/saveSettings.php b/install/core/actions/saveSettings.php index 211eb08df5..0648970e5b 100644 --- a/install/core/actions/saveSettings.php +++ b/install/core/actions/saveSettings.php @@ -28,19 +28,26 @@ ************************************************************************/ ob_start(); -$result = array('success' => true, 'errorMsg' => ''); + +$result = [ + 'success' => true, + 'errorMsg' => '', +]; // save settings -$database = array( +$database = [ 'driver' => 'pdo_mysql', 'dbname' => $_SESSION['install']['db-name'], 'user' => $_SESSION['install']['db-user-name'], 'password' => $_SESSION['install']['db-user-password'], -); +]; + $host = $_SESSION['install']['host-name']; + if (strpos($host,':') === false) { - $host .= ":"; + $host .= ":"; } + list($database['host'], $database['port']) = explode(':', $host); $saveData = [ @@ -49,6 +56,10 @@ $saveData = [ 'siteUrl' => !empty($_SESSION['install']['site-url']) ? $_SESSION['install']['site-url'] : null, ]; +if (!empty($_SESSION['install']['theme'])) { + $saveData['theme'] = $_SESSION['install']['theme']; +} + if (!empty($_SESSION['install']['default-permissions-user']) && !empty($_SESSION['install']['default-permissions-group'])) { $saveData['defaultPermissions'] = [ 'user' => $_SESSION['install']['default-permissions-user'], diff --git a/install/core/tpl/index.tpl b/install/core/tpl/index.tpl index e74f495e9c..7ee6113b2c 100644 --- a/install/core/tpl/index.tpl +++ b/install/core/tpl/index.tpl @@ -15,7 +15,7 @@ {/if} - + diff --git a/install/core/tpl/main.tpl b/install/core/tpl/main.tpl index 24edc85238..422e069be5 100644 --- a/install/core/tpl/main.tpl +++ b/install/core/tpl/main.tpl @@ -1,6 +1,7 @@