diff options
author | Julius Haertl <jus@bitgrid.net> | 2017-02-17 18:42:07 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2017-04-25 12:39:45 +0300 |
commit | 68a63ad3f33c683d726219a508bb31de7b9ab1d0 (patch) | |
tree | 910932971b761689c8ca843860119a1df6e29573 /apps/theming/lib/ThemingDefaults.php | |
parent | 133f3fdc9aec28383dba323d58569eddd160b0df (diff) |
Implement scss variable injection by OC_Defaults
Signed-off-by: Julius Haertl <jus@bitgrid.net>
Add Scss variables to example theme and theming app
Signed-off-by: Julius Haertl <jus@bitgrid.net>
Use SCSSCacher to build theming css
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Update theming.scss
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Code cleanup
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Fix tests
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Inject SCSSCacher for easier testing
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Fix typehint
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Generate absolute URLs
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Fix tests to always use absolute urls for theming images
Signed-off-by: Julius Härtl <jus@bitgrid.net>
MailheaderColor -> ColorPrimary
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/theming/lib/ThemingDefaults.php')
-rw-r--r-- | apps/theming/lib/ThemingDefaults.php | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php index 073410da2c3..e73887d6162 100644 --- a/apps/theming/lib/ThemingDefaults.php +++ b/apps/theming/lib/ThemingDefaults.php @@ -28,7 +28,6 @@ use OCP\ICacheFactory; use OCP\IConfig; use OCP\IL10N; use OCP\IURLGenerator; -use OCP\Util; class ThemingDefaults extends \OC_Defaults { @@ -50,6 +49,8 @@ class ThemingDefaults extends \OC_Defaults { private $slogan; /** @var string */ private $color; + /** @var Util */ + private $util; /** * ThemingDefaults constructor. @@ -60,20 +61,22 @@ class ThemingDefaults extends \OC_Defaults { * @param \OC_Defaults $defaults * @param IAppData $appData * @param ICacheFactory $cacheFactory + * @param Util $util */ public function __construct(IConfig $config, IL10N $l, IURLGenerator $urlGenerator, \OC_Defaults $defaults, IAppData $appData, - ICacheFactory $cacheFactory + ICacheFactory $cacheFactory, + Util $util ) { - parent::__construct(); $this->config = $config; $this->l = $l; $this->urlGenerator = $urlGenerator; $this->appData = $appData; $this->cacheFactory = $cacheFactory; + $this->util = $util; $this->name = $defaults->getName(); $this->url = $defaults->getBaseUrl(); @@ -102,7 +105,7 @@ class ThemingDefaults extends \OC_Defaults { } public function getSlogan() { - return Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan)); + return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan)); } public function getShortFooter() { @@ -129,7 +132,7 @@ class ThemingDefaults extends \OC_Defaults { * @return string */ public function getLogo() { - $logo = $this->config->getAppValue('theming', 'logoMime'); + $logo = $this->config->getAppValue('theming', 'logoMime', false); $logoExists = true; try { @@ -141,10 +144,10 @@ class ThemingDefaults extends \OC_Defaults { $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); if(!$logo || !$logoExists) { - return $this->urlGenerator->imagePath('core','logo.svg') . '?v=' . $cacheBusterCounter; + return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core','logo.svg') . '?v=' . $cacheBusterCounter); } - return $this->urlGenerator->linkToRoute('theming.Theming.getLogo') . '?v=' . $cacheBusterCounter; + return $this->urlGenerator->linkToRouteAbsolute('theming.Theming.getLogo') . '?v=' . $cacheBusterCounter; } /** @@ -153,7 +156,7 @@ class ThemingDefaults extends \OC_Defaults { * @return string */ public function getBackground() { - $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime'); + $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime',false); $backgroundExists = true; try { @@ -169,6 +172,36 @@ class ThemingDefaults extends \OC_Defaults { return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground'); } + + /** + * @return array scss variables to overwrite + */ + public function getScssVariables() { + $cache = $this->cacheFactory->create('theming'); + if ($value = $cache->get('getScssVariables')) { + return $value; + } + + $variables = [ + 'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'", + ]; + + $variables['image-logo'] = "'".$this->getLogo()."'"; + $variables['image-login-background'] = "'".$this->getBackground()."'"; + + if ($this->config->getAppValue('theming', 'color', null) !== null) { + if ($this->util->invertTextColor($this->getColorPrimary())) { + $colorPrimaryText = '#000000'; + } else { + $colorPrimaryText = '#ffffff'; + } + $variables['color-primary'] = $this->getColorPrimary(); + $variables['color-primary-text'] = $colorPrimaryText; + } + $cache->set('getScssVariables', $variables); + return $variables; + } + /** * Check if Imagemagick is enabled and if SVG is supported * otherwise we can't render custom icons @@ -198,6 +231,7 @@ class ThemingDefaults extends \OC_Defaults { private function increaseCacheBuster() { $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1); + $this->cacheFactory->create('theming')->clear('getScssVariables'); } /** |