Allow themes to have various variants
Signed-off-by: Florian Aders (EleRas) <eleras@froxlor.org>
This commit is contained in:
@@ -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") . "\";");
|
||||
|
||||
@@ -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') . "\";");
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
40
lib/init.php
40
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 .= '<script type="text/javascript" src="templates/' . $theme . '/assets/js/' . $jsfile . '"></script>' . "\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 .= '<link href="templates/' . $theme . '/assets/css/' . $cssfile . '" rel="stylesheet" type="text/css" />' . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
eval("\$header = \"" . getTemplate('header', '1') . "\";");
|
||||
unset($js);
|
||||
unset($css);
|
||||
|
||||
$current_year = date('Y', time());
|
||||
eval("\$footer = \"" . getTemplate('footer', '1') . "\";");
|
||||
|
||||
1
templates/Sparkle/config.json
vendored
Normal file
1
templates/Sparkle/config.json
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"variants":{"default":{"css":["main.css"],"js":["main.js"],"description":"Default"}},"author":"Roman Schmerold"}
|
||||
4
templates/Sparkle/header.tpl
vendored
4
templates/Sparkle/header.tpl
vendored
@@ -22,10 +22,10 @@
|
||||
<if Settings::Get('panel.use_webfonts') == '1'>
|
||||
<link href="//fonts.googleapis.com/css?family={Settings::Get('panel.webfont')}" rel="stylesheet">
|
||||
</if>
|
||||
<link href="templates/{$theme}/assets/css/main.css" rel="stylesheet" type="text/css" />
|
||||
{$css}
|
||||
<!--[if IE]><link rel="stylesheet" href="templates/{$theme}/css/main_ie.css" type="text/css" /><![endif]-->
|
||||
<link href="css/jquery-ui.min.css" rel="stylesheet" type="text/css"/>
|
||||
<script type="text/javascript" src="templates/{$theme}/assets/js/main.js"></script>
|
||||
{$js}
|
||||
<link href="templates/{$theme}/assets/img/favicon.ico" rel="icon" type="image/x-icon" />
|
||||
<title><if isset($userinfo['loginname']) && $userinfo['loginname'] != ''>{$userinfo['loginname']} - </if>Froxlor Server Management Panel</title>
|
||||
<style type="text/css">
|
||||
|
||||
Reference in New Issue
Block a user