From 747e28e07cd879c231fa57fbfd696eb40e09a267 Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Thu, 12 Oct 2023 16:15:50 +0700 Subject: [PATCH] adding themes system --- .gitignore | 5 ++++- system/autoload/Lang.php | 5 +++++ system/boot.php | 15 ++++++++++++--- system/controllers/settings.php | 22 +++++++++++++++++++++- ui/themes/README.md | 3 +++ ui/ui/app-settings.tpl | 11 +++++++++++ 6 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 ui/themes/README.md diff --git a/.gitignore b/.gitignore index 8d917f5a..d4ac02b4 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,7 @@ system/uploads/** system/uploads/sms/** !system/uploads/sms/index.html system/uploads/system/** -!system/uploads/system/index.html \ No newline at end of file +!system/uploads/system/index.html +ui/themes/** +!ui/themes/index.html +!ui/themes/README.md \ No newline at end of file diff --git a/system/autoload/Lang.php b/system/autoload/Lang.php index 9879950e..dfe8cebc 100644 --- a/system/autoload/Lang.php +++ b/system/autoload/Lang.php @@ -81,4 +81,9 @@ class Lang return $_notifmsg_default[$key]; } } + + public static function ucWords($text) + { + return ucwords(str_replace('_', ' ', $text)); + } } diff --git a/system/boot.php b/system/boot.php index 141765c2..4181ca12 100644 --- a/system/boot.php +++ b/system/boot.php @@ -128,9 +128,18 @@ function _notify($msg, $type = 'e') } $lan_file = File::pathFixer('system/lan/' . $config['language'] . '/common.lan.php'); -require($lan_file); +require $lan_file; + $ui = new Smarty(); -$ui->setTemplateDir(['custom' => File::pathFixer('ui/ui_custom/'), 'default' => File::pathFixer('ui/ui/')]); + +if (!empty($config['theme']) && $config['theme'] != 'default') { + $_theme = APP_URL . '/ui/theme/' . $config['theme']; + $ui->setTemplateDir(['custom' => File::pathFixer('ui/ui_custom/'), 'theme' => $_theme, 'default' => File::pathFixer('ui/ui/')]); +} else { + $_theme = APP_URL . '/ui/ui'; + $ui->setTemplateDir(['custom' => File::pathFixer('ui/ui_custom/'), 'default' => File::pathFixer('ui/ui/')]); +} +$ui->assign('_theme', $_theme); $ui->addTemplateDir(File::pathFixer('system/paymentgateway/ui/'), 'pg'); $ui->addTemplateDir(File::pathFixer('system/plugin/ui/'), 'plugin'); $ui->setCompileDir(File::pathFixer('ui/compiled/')); @@ -338,7 +347,7 @@ try { } } catch (Exception $e) { $ui->assign("error_title", "PHPNuxBill Crash"); - $ui->assign("error_message", $e->getMessage().'
'.$e->getTraceAsString().'
'); + $ui->assign("error_message", $e->getMessage() . '
' . $e->getTraceAsString() . '
'); $ui->display('router-error.tpl'); die(); } diff --git a/system/controllers/settings.php b/system/controllers/settings.php index 93aab7ed..19e2adf7 100644 --- a/system/controllers/settings.php +++ b/system/controllers/settings.php @@ -30,6 +30,14 @@ switch ($action) { //ignore } } + $themes = []; + $files = scandir('ui/themes/'); + foreach ($files as $file) { + if (is_dir('ui/themes/' . $file) && !in_array($file, ['.', '..'])) { + $themes[] = $file; + } + } + $ui->assign('themes', $themes); run_hook('view_app_settings'); #HOOK $ui->display('app-settings.tpl'); break; @@ -46,7 +54,6 @@ switch ($action) { } } $ui->assign('lan', $folders); - $timezonelist = Timezone::timezoneList(); $ui->assign('tlist', $timezonelist); $ui->assign('xjq', ' $("#tzone").select2(); '); @@ -242,6 +249,7 @@ switch ($action) { $http_proxyauth = _post('http_proxyauth'); $radius_enable = _post('radius_enable'); $radius_client = _post('radius_client'); + $theme = _post('theme'); run_hook('save_settings'); #HOOK @@ -289,6 +297,18 @@ switch ($action) { $d->save(); } + + $d = ORM::for_table('tbl_appconfig')->where('setting', 'theme')->find_one(); + if ($d) { + $d->value = $theme; + $d->save(); + } else { + $d = ORM::for_table('tbl_appconfig')->create(); + $d->setting = 'theme'; + $d->value = $theme; + $d->save(); + } + $d = ORM::for_table('tbl_appconfig')->where('setting', 'CompanyFooter')->find_one(); if ($d) { $d->value = $footer; diff --git a/ui/themes/README.md b/ui/themes/README.md new file mode 100644 index 00000000..a155c4c1 --- /dev/null +++ b/ui/themes/README.md @@ -0,0 +1,3 @@ +# Themes Folder + +Folder name must only alphanumeric characters and underscores _**my_theme**_ will show as _**My Theme**_ diff --git a/ui/ui/app-settings.tpl b/ui/ui/app-settings.tpl index 0c9bd223..4a2540e7 100644 --- a/ui/ui/app-settings.tpl +++ b/ui/ui/app-settings.tpl @@ -53,6 +53,17 @@ +
+ +
+ +
+