commit 28d03bce94e0d7ceb2d9cfb42c4084bcabf051c3
parent d23a41ca8b70cdc409bdae5e7f4ab2f565a39886
Author: Jan Dankert <develop@jandankert.de>
Date: Wed, 10 Feb 2021 22:04:26 +0100
Provide the theme configuration through a class.
Diffstat:
8 files changed, 179 insertions(+), 61 deletions(-)
diff --git a/modules/cms/action/profile/ProfileUserinfoAction.class.php b/modules/cms/action/profile/ProfileUserinfoAction.class.php
@@ -3,6 +3,7 @@ namespace cms\action\profile;
use cms\action\Method;
use cms\action\ProfileAction;
use cms\base\Configuration;
+use cms\ui\themes\ThemeStyle;
use util\Session;
use util\UIUtils;
@@ -17,16 +18,10 @@ class ProfileUserinfoAction extends ProfileAction implements Method {
$this->setTemplateVar('style',$currentStyle);
- $defaultStyleConfig = Configuration::Conf()->get('style-default',[]); // default style config
- $userStyleConfig = Configuration::subset('style')->get($currentStyle,[]); // user style config
-
- if ( $userStyleConfig )
- $defaultStyleConfig = array_merge($defaultStyleConfig, $userStyleConfig ); // Merging user style into default style
- else
- ; // Unknown style name, we are ignoring this.
+ $themeStyle = new ThemeStyle( Configuration::subset('style')->get($currentStyle,[]) ); // user style config
// Theme base color for smartphones colorizing their status bar.
- $this->setTemplateVar('theme-color', UIUtils::getColorHexCode($defaultStyleConfig['title_background_color']));
+ $this->setTemplateVar('theme-color', UIUtils::getColorHexCode($themeStyle->getThemeColor()));
}
diff --git a/modules/cms/base/DefaultConfig.class.php b/modules/cms/base/DefaultConfig.class.php
@@ -646,15 +646,6 @@ class DefaultConfig {
],
'content-security-policy' => true,
],
- 'style-default' =>
- [
- 'name' => 'Unnamed',
- 'title_background_color' => 'grey',
- 'title_text_color' => 'white',
- 'text_color' => 'black',
- 'background_color' => '#d9d9d9',
- 'inactive_background_color' => 'silver',
- ],
'style' =>
[
'earlgrey' =>
diff --git a/modules/cms/ui/action/index/IndexManifestAction.class.php b/modules/cms/ui/action/index/IndexManifestAction.class.php
@@ -1,12 +1,13 @@
<?php
namespace cms\ui\action\index;
use cms\action\Method;
+use cms\base\Configuration;
use cms\ui\action\IndexAction;
+use cms\ui\themes\ThemeStyle;
use util\Session;
use cms\action\RequestParams;
use cms\auth\Auth;
use cms\auth\AuthRunner;
-use cms\base\Configuration;
use cms\base\Configuration as C;
use cms\base\Startup;
use cms\model\BaseObject;
@@ -39,19 +40,13 @@ class IndexManifestAction extends IndexAction implements Method {
else
$this->lastModified( time() );
- $style = $this->getUserStyle( $user );
+ $currentStyle = $this->getUserStyle( $user );
- $styleConfig = C::Conf()->subset('style-default' ); // default style config
- $userStyleConfig = C::subset('style')->subset( $style ); // user style config
-
- if ( $userStyleConfig->hasContent() )
- $styleConfig->merge( $userStyleConfig ); // Merging user style into default style
- else
- ; // Unknown style name, we are ignoring this.
+ $themeStyle = new ThemeStyle( Configuration::subset('style')->get($currentStyle,[]) ); // user style config
- // Theme base color for smartphones colorizing their status bar.
- $themeColor = UIUtils::getColorHexCode($styleConfig->get('title_background_color','white'));
+ // Theme base color for smartphones colorizing their status bar.
+ $themeColor = UIUtils::getColorHexCode($themeStyle->getThemeColor());
$appName = C::subset(['application'])->get('name',Startup::TITLE);
diff --git a/modules/cms/ui/action/index/IndexShowAction.class.php b/modules/cms/ui/action/index/IndexShowAction.class.php
@@ -3,6 +3,7 @@ namespace cms\ui\action\index;
use cms\action\Method;
use cms\model\User;
use cms\ui\action\IndexAction;
+use cms\ui\themes\ThemeStyle;
use language\Messages;
use util\Html;
use util\Session;
@@ -67,16 +68,10 @@ class IndexShowAction extends IndexAction implements Method {
$this->setTemplateVar('themeStyleLink', Html::url('index','themestyle') );
$this->setTemplateVar('manifestLink' , Html::url('index','manifest' ) );
- $styleConfig = C::Conf()->get('style-default',[]); // default style config
- $userStyleConfig = C::subset('style')->get( $style,[]); // user style config
-
- if ( $userStyleConfig )
- $styleConfig = array_merge($styleConfig,$userStyleConfig); // Merging user style into default style
- else
- ; // Unknown style name, we are ignoring this.
+ $themeStyle = new ThemeStyle( Configuration::subset('style')->get($style,[]) ); // user style config
// Theme base color for smartphones colorizing their status bar.
- $this->setTemplateVar('themeColor', UIUtils::getColorHexCode($styleConfig['title_background_color']));
+ $this->setTemplateVar('themeColor', UIUtils::getColorHexCode($themeStyle->getThemeColor()));
$messageOfTheDay = C::subset('login')->get('motd','');
diff --git a/modules/cms/ui/action/index/IndexThemestyleAction.class.php b/modules/cms/ui/action/index/IndexThemestyleAction.class.php
@@ -13,12 +13,14 @@ use cms\model\Project;
use cms\model\User;
use cms\model\Value;
use cms\ui\themes\Theme;
+use cms\ui\themes\ThemeStyle;
use Exception;
use language\Messages;
use util\Html;
use util\json\JSON;
use logger\Logger;
use util\Less;
+use util\text\Converter;
use util\UIUtils;
use \util\exception\ObjectNotFoundException;
use util\Session;
@@ -31,6 +33,8 @@ class IndexThemestyleAction extends IndexAction implements Method {
$this->setTemplateVar('style',$this->getThemeCSS() );
}
+
+
public function post() {
}
@@ -38,7 +42,7 @@ class IndexThemestyleAction extends IndexAction implements Method {
/**
* Gets the theme CSS.
*
- * @return string
+ * @return string The ready to use CSS
*/
protected function getThemeCSS()
{
@@ -51,7 +55,7 @@ class IndexThemestyleAction extends IndexAction implements Method {
{
try
{
- $styleConfig = C::Conf()->subset('style-default')->merge( $styleConfig );
+ $themeStyle = new ThemeStyle( $styleConfig->getConfig() );
if ( DEVELOPMENT )
$css .= "\n".'/* Theme: '.$styleId.' */'."\n";
@@ -61,8 +65,11 @@ class IndexThemestyleAction extends IndexAction implements Method {
'cms-image-path' => '"'.Startup::THEMES_DIR.'default/images/'.'"',
);
- foreach ($styleConfig->getConfig() as $styleSetting => $value)
- $lessVars['cms-' . strtolower(strtr($styleSetting, '_', '-'))] = $value;
+ foreach ( $themeStyle->getProperties() as $styleSetting => $value)
+ $lessVars['cms-' . Converter::camelToUnderscore($styleSetting, '-')] = $value;
+
+ if ( DEVELOPMENT )
+ $css .= "\n".'/* Theme-Properties: '.print_r( $lessVars,true).' */'."\n";
// we must create a new instance here, because the less parser is buggy when changing vars.
$parser = new Less(array(
diff --git a/modules/cms/ui/themes/ThemeStyle.class.php b/modules/cms/ui/themes/ThemeStyle.class.php
@@ -0,0 +1,108 @@
+<?php
+
+
+namespace cms\ui\themes;
+
+
+use cms\base\Configuration as C;
+use util\text\Converter;
+
+class ThemeStyle
+{
+ private $name;
+ private $titleBackgroundColor;
+ private $titleTextColor;
+ private $textColor = 'black';
+ private $backgroundColor = '#d9d9d9';
+ private $inactiveBackgroundColor;
+ private $themeColor;
+ private $searchBackgroundcolor;
+ private $searchTextColor;
+ private $navBackgroundcolor;
+ private $navTextColor;
+ private $arrowColor;
+ private $imageColor;
+
+ private $noticeOkColor = '#00d95a';
+ private $noticeInfoColor = '#86caff';
+ private $noticeWarningColor = '#FBDE2D';
+ private $noticeErrorColor = '#f54b07';
+
+ /**
+ * ThemeStyle constructor.
+ */
+ public function __construct( $config )
+ {
+ if ( is_string( $config ) )
+ $config = C::subset('style')->get( $config,[]); // user style config
+
+ $this->setValues( $config );
+ $this->fillMissingValues();
+ }
+
+
+
+ protected function setValues( $styleConfig ) {
+
+ foreach( $styleConfig as $property=>$value ) {
+ $property = Converter::toCamelCase($property);
+ if ( property_exists($this,$property ) ) {
+ $this->$property = $value;
+ }
+ }
+ }
+
+
+ /**
+ * Fill empty values with a default value.
+ */
+ protected function fillMissingValues() {
+
+ if ( ! $this->titleBackgroundColor )
+ $this->titleBackgroundColor = $this->backgroundColor;
+
+ if ( ! $this->titleTextColor )
+ $this->titleTextColor = $this->textColor;
+
+ if ( ! $this->themeColor )
+ $this->themeColor = $this->titleBackgroundColor;
+
+ if ( ! $this->inactiveBackgroundColor )
+ $this->inactiveBackgroundColor = $this->backgroundColor;
+
+ if ( ! $this->searchTextColor )
+ $this->searchTextColor = $this->titleTextColor;
+
+ if ( ! $this->searchBackgroundcolor )
+ $this->searchBackgroundcolor = $this->titleBackgroundColor;
+
+ if ( ! $this->navTextColor )
+ $this->navTextColor = $this->textColor;
+
+ if ( ! $this->navBackgroundcolor )
+ $this->navBackgroundcolor = $this->backgroundColor;
+
+ if ( ! $this->arrowColor )
+ $this->arrowColor = $this->themeColor;
+
+ if ( ! $this->imageColor )
+ $this->imageColor = $this->themeColor;
+ }
+
+
+
+ public function getProperties() {
+
+ return get_object_vars($this);
+ }
+
+ /**
+ * Theme color.
+ *
+ * @return string
+ */
+ public function getThemeColor()
+ {
+ return $this->themeColor;
+ }
+}+
\ No newline at end of file
diff --git a/modules/cms/ui/themes/default/style/theme/openrat-theme.less b/modules/cms/ui/themes/default/style/theme/openrat-theme.less
@@ -13,10 +13,10 @@
@cms-inactive-background-color: gray;
@cms-background-image: "@{cms-image-path}background/fog.jpeg";
-@notice-ok-color: #00d95a;
-@notice-info-color: #86caff;
-@notice-warning-color: #FBDE2D;
-@notice-error-color: #f54b07;
+@cms-notice-ok-color: green;
+@cms-notice-info-color: blue;
+@cms-notice-warning-color: yellow;
+@cms-notice-error-color: red;
html.or-theme-@{cms-theme-id} {
@@ -62,47 +62,47 @@ html.or-theme-@{cms-theme-id} {
line-height: 1.5em;
&--ok {
- background-color: @notice-ok-color;
- border-color: darken(@notice-ok-color, 10%);
+ background-color: @cms-notice-ok-color;
+ border-color: darken(@cms-notice-ok-color, 10%);
&:after {
- border-left-color: darken(@notice-ok-color, 10%);
+ border-left-color: darken(@cms-notice-ok-color, 10%);
}
- .box-shadow(3px, 3px, 10px, mix(@cms-background-color, @notice-ok-color, 20%));
+ .box-shadow(3px, 3px, 10px, mix(@cms-background-color, @cms-notice-ok-color, 20%));
}
&--warning {
- background-color: @notice-warning-color;
- border-color: darken(@notice-warning-color, 10%);
+ background-color: @cms-notice-warning-color;
+ border-color: darken(@cms-notice-warning-color, 10%);
&:after {
- border-left-color: darken(@notice-warning-color, 10%);
+ border-left-color: darken(@cms-notice-warning-color, 10%);
}
- .box-shadow(3px, 3px, 10px, mix(@cms-background-color, @notice-warning-color, 20%));
+ .box-shadow(3px, 3px, 10px, mix(@cms-background-color, @cms-notice-warning-color, 20%));
}
&--info {
- background-color: @notice-info-color;
- border-color: darken(@notice-info-color, 10%);
+ background-color: @cms-notice-info-color;
+ border-color: darken(@cms-notice-info-color, 10%);
&:after {
- border-left-color: darken(@notice-info-color, 10%);
+ border-left-color: darken(@cms-notice-info-color, 10%);
}
- .box-shadow(3px, 3px, 10px, mix(@cms-background-color, @notice-info-color, 20%));
+ .box-shadow(3px, 3px, 10px, mix(@cms-background-color, @cms-notice-info-color, 20%));
}
&--error {
- background-color: @notice-error-color;
- border-color: darken(@notice-error-color, 10%);
+ background-color: @cms-notice-error-color;
+ border-color: darken(@cms-notice-error-color, 10%);
&:after {
- border-left-color: darken(@notice-error-color, 10%);
+ border-left-color: darken(@cms-notice-error-color, 10%);
}
- .box-shadow(3px, 3px, 10px, mix(@cms-background-color, @notice-error-color, 20%));
+ .box-shadow(3px, 3px, 10px, mix(@cms-background-color, @cms-notice-error-color, 20%));
}
}
@@ -200,7 +200,7 @@ html.or-theme-@{cms-theme-id} {
&--error {
border-bottom: 1px dotted @cms-text-color ! important;
- border: 1px solid @notice-error-color ! important;
+ border: 1px solid @cms-notice-error-color ! important;
}
diff --git a/modules/util/text/Converter.class.php b/modules/util/text/Converter.class.php
@@ -0,0 +1,25 @@
+<?php
+
+
+namespace util\text;
+
+
+class Converter
+{
+ public static function toCamelCase($string) {
+ $string = str_replace('-', ' ', $string);
+ $string = str_replace('_', ' ', $string);
+ $string = ucwords(strtolower($string));
+ $string = str_replace(' ', '', $string);
+ $string = lcfirst($string);
+
+ return $string;
+ }
+
+
+ public static function camelToUnderscore($string, $us = "-") {
+
+ return strtolower(preg_replace(
+ '/(?<=\d)(?=[A-Za-z])|(?<=[A-Za-z])(?=\d)|(?<=[a-z])(?=[A-Z])/', $us, $string));
+ }
+}+
\ No newline at end of file