From b4a345d182ee7f06e9a027115aadbd3fc70cd454 Mon Sep 17 00:00:00 2001 From: "Florian Aders (EleRas)" Date: Sun, 29 Dec 2013 17:35:03 +0100 Subject: [PATCH] Allow themes to have various variants Signed-off-by: Florian Aders (EleRas) --- admin_index.php | 4 +- customer_index.php | 4 +- lib/functions/froxlor/function.getThemes.php | 16 +++++++- lib/init.php | 40 ++++++++++++++++++-- templates/Sparkle/config.json | 1 + templates/Sparkle/header.tpl | 4 +- 6 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 templates/Sparkle/config.json diff --git a/admin_index.php b/admin_index.php index 8be08418..375ae538 100644 --- a/admin_index.php +++ b/admin_index.php @@ -320,8 +320,8 @@ if ($page == 'overview') { } $themes_avail = getThemes(); - foreach ($themes_avail as $t) { - $theme_options.= makeoption($t, $t, $default_theme, true); + foreach ($themes_avail as $t => $d) { + $theme_options.= makeoption($d, $t, $default_theme, true); } eval("echo \"" . getTemplate("index/change_theme") . "\";"); diff --git a/customer_index.php b/customer_index.php index e43e4ec4..cea66902 100644 --- a/customer_index.php +++ b/customer_index.php @@ -231,8 +231,8 @@ if ($page == 'overview') { $theme_options = ''; $themes_avail = getThemes(); - foreach ($themes_avail as $t) { - $theme_options .= makeoption($t, $t, $default_theme, true); + foreach ($themes_avail as $t => $d) { + $theme_options.= makeoption($d, $t, $default_theme, true); } eval("echo \"" . getTemplate('index/change_theme') . "\";"); diff --git a/lib/functions/froxlor/function.getThemes.php b/lib/functions/froxlor/function.getThemes.php index ceb2c6c6..c4a39c82 100644 --- a/lib/functions/froxlor/function.getThemes.php +++ b/lib/functions/froxlor/function.getThemes.php @@ -34,7 +34,21 @@ function getThemes() { && $it->getFilename() != '..' && $it->getFilename() != 'misc' ) { - $themes_available[$it->getFilename()] = $it->getFilename(); + $theme = $themespath . $it->getFilename(); + if (file_exists($theme . '/config.json')) { + $themeconfig = json_decode(file_get_contents($theme . '/config.json'), true); + if (array_key_exists('variants', $themeconfig) && is_array($themeconfig['variants'])) { + foreach ($themeconfig['variants'] as $variant => $data) { + if ($variant == "default") { + $themes_available[$it->getFilename()] = $it->getFilename(); + } else { + $themes_available[$it->getFilename() . '_' . $variant] = $it->getFilename() . ' (' . $data['description'] . ')'; + } + } + } else { + $themes_available[$it->getFilename()] = $it->getFilename(); + } + } } } } diff --git a/lib/init.php b/lib/init.php index 26f95d41..3136b27c 100644 --- a/lib/init.php +++ b/lib/init.php @@ -324,7 +324,7 @@ $linker = new linker('index.php', $s); /** * global Theme-variable */ -$theme = (Settings::Get('panel.default_theme') !== null) ? Settings::Get('panel.default_theme') : 'Sparkle'; +$theme = (Settings::Get('panel.default_theme') !== null) ? Settings::Get('panel.default_theme') : $_deftheme; /** * overwrite with customer/admin theme if defined @@ -333,10 +333,25 @@ if (isset($userinfo['theme']) && $userinfo['theme'] != $theme) { $theme = $userinfo['theme']; } +// Check if a different variant of the theme is used +$themevariant = "default"; +if (preg_match("/([a-z0-9\.\-]+)_([a-z0-9\.\-]+)/i", $theme, $matches)) { + $theme = $matches[1]; + $themevariant = $matches[2]; +} + // check for existence of the theme -if (!file_exists('templates/'.$theme.'/index.tpl')) { +if (!file_exists('templates/'.$theme.'/config.json')) { // Fallback - $theme = 'Sparkle'; + $theme = $_deftheme; +} + +$_themeoptions = json_decode(file_get_contents('templates/'.$theme.'/config.json'), true); + +// check for existence of variant in theme +if (!array_key_exists('variants', $_themeoptions) || !array_key_exists($themevariant, $_themeoptions['variants'])) +{ + $themevariant = "default"; } // check for custom header-graphic @@ -456,7 +471,26 @@ if (Settings::Get('ticket.enabled') == '1') { } $webfont = str_replace('+', ' ', Settings::Get('panel.webfont')); +$js = ""; +if (array_key_exists('js', $_themeoptions['variants'][$themevariant]) && is_array($_themeoptions['variants'][$themevariant]['js'])) { + foreach ($_themeoptions['variants'][$themevariant]['js'] as $jsfile) { + if (file_exists('templates/'.$theme.'/assets/js/'.$jsfile)) { + $js .= '' . "\n"; + } + } +} + +$css = ""; +if (array_key_exists('css', $_themeoptions['variants'][$themevariant]) && is_array($_themeoptions['variants'][$themevariant]['css'])) { + foreach ($_themeoptions['variants'][$themevariant]['css'] as $cssfile) { + if (file_exists('templates/'.$theme.'/assets/css/'.$cssfile)) { + $css .= '' . "\n"; + } + } +} eval("\$header = \"" . getTemplate('header', '1') . "\";"); +unset($js); +unset($css); $current_year = date('Y', time()); eval("\$footer = \"" . getTemplate('footer', '1') . "\";"); diff --git a/templates/Sparkle/config.json b/templates/Sparkle/config.json new file mode 100644 index 00000000..9d7c5e0d --- /dev/null +++ b/templates/Sparkle/config.json @@ -0,0 +1 @@ +{"variants":{"default":{"css":["main.css"],"js":["main.js"],"description":"Default"}},"author":"Roman Schmerold"} diff --git a/templates/Sparkle/header.tpl b/templates/Sparkle/header.tpl index 9a0fa86d..1c2f01a7 100644 --- a/templates/Sparkle/header.tpl +++ b/templates/Sparkle/header.tpl @@ -22,10 +22,10 @@ - + {$css} - + {$js} <if isset($userinfo['loginname']) && $userinfo['loginname'] != ''>{$userinfo['loginname']} - </if>Froxlor Server Management Panel