| @@ -31,294 +31,294 @@ | ||
| 31 | 31 | |
| 32 | 32 |  class ThemingDefaults extends \OC_Defaults { | 
| 33 | 33 | |
| 34 | - /** @var IConfig */ | |
| 35 | - private $config; | |
| 36 | - /** @var IL10N */ | |
| 37 | - private $l; | |
| 38 | - /** @var IURLGenerator */ | |
| 39 | - private $urlGenerator; | |
| 40 | - /** @var IAppData */ | |
| 41 | - private $appData; | |
| 42 | - /** @var ICacheFactory */ | |
| 43 | - private $cacheFactory; | |
| 44 | - /** @var string */ | |
| 45 | - private $name; | |
| 46 | - /** @var string */ | |
| 47 | - private $url; | |
| 48 | - /** @var string */ | |
| 49 | - private $slogan; | |
| 50 | - /** @var string */ | |
| 51 | - private $color; | |
| 52 | - /** @var Util */ | |
| 53 | - private $util; | |
| 54 | - /** @var string */ | |
| 55 | - private $iTunesAppId; | |
| 56 | - /** @var string */ | |
| 57 | - private $iOSClientUrl; | |
| 58 | - /** @var string */ | |
| 59 | - private $AndroidClientUrl; | |
| 60 | - | |
| 61 | - /** | |
| 62 | - * ThemingDefaults constructor. | |
| 63 | - * | |
| 64 | - * @param IConfig $config | |
| 65 | - * @param IL10N $l | |
| 66 | - * @param IURLGenerator $urlGenerator | |
| 67 | - * @param \OC_Defaults $defaults | |
| 68 | - * @param IAppData $appData | |
| 69 | - * @param ICacheFactory $cacheFactory | |
| 70 | - * @param Util $util | |
| 71 | - */ | |
| 72 | - public function __construct(IConfig $config, | |
| 73 | - IL10N $l, | |
| 74 | - IURLGenerator $urlGenerator, | |
| 75 | - IAppData $appData, | |
| 76 | - ICacheFactory $cacheFactory, | |
| 77 | - Util $util | |
| 78 | -	) { | |
| 79 | - parent::__construct(); | |
| 80 | - $this->config = $config; | |
| 81 | - $this->l = $l; | |
| 82 | - $this->urlGenerator = $urlGenerator; | |
| 83 | - $this->appData = $appData; | |
| 84 | - $this->cacheFactory = $cacheFactory; | |
| 85 | - $this->util = $util; | |
| 86 | - | |
| 87 | - $this->name = parent::getName(); | |
| 88 | - $this->url = parent::getBaseUrl(); | |
| 89 | - $this->slogan = parent::getSlogan(); | |
| 90 | - $this->color = parent::getColorPrimary(); | |
| 91 | - $this->iTunesAppId = parent::getiTunesAppId(); | |
| 92 | - $this->iOSClientUrl = parent::getiOSClientUrl(); | |
| 93 | - $this->AndroidClientUrl = parent::getAndroidClientUrl(); | |
| 94 | - } | |
| 95 | - | |
| 96 | -	public function getName() { | |
| 97 | -		return strip_tags($this->config->getAppValue('theming', 'name', $this->name)); | |
| 98 | - } | |
| 99 | - | |
| 100 | -	public function getHTMLName() { | |
| 101 | -		return $this->config->getAppValue('theming', 'name', $this->name); | |
| 102 | - } | |
| 103 | - | |
| 104 | -	public function getTitle() { | |
| 105 | - return $this->getName(); | |
| 106 | - } | |
| 107 | - | |
| 108 | -	public function getEntity() { | |
| 109 | - return $this->getName(); | |
| 110 | - } | |
| 111 | - | |
| 112 | -	public function getBaseUrl() { | |
| 113 | -		return $this->config->getAppValue('theming', 'url', $this->url); | |
| 114 | - } | |
| 115 | - | |
| 116 | -	public function getSlogan() { | |
| 117 | -		return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan)); | |
| 118 | - } | |
| 119 | - | |
| 120 | -	public function getShortFooter() { | |
| 121 | - $slogan = $this->getSlogan(); | |
| 122 | - $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' . | |
| 123 | - ' rel="noreferrer">' .$this->getEntity() . '</a>'. | |
| 124 | - ($slogan !== '' ? ' – ' . $slogan : ''); | |
| 125 | - | |
| 126 | - return $footer; | |
| 127 | - } | |
| 128 | - | |
| 129 | - /** | |
| 130 | - * Color that is used for the header as well as for mail headers | |
| 131 | - * | |
| 132 | - * @return string | |
| 133 | - */ | |
| 134 | -	public function getColorPrimary() { | |
| 135 | -		return $this->config->getAppValue('theming', 'color', $this->color); | |
| 136 | - } | |
| 137 | - | |
| 138 | - /** | |
| 139 | - * Themed logo url | |
| 140 | - * | |
| 141 | - * @param bool $useSvg Whether to point to the SVG image or a fallback | |
| 142 | - * @return string | |
| 143 | - */ | |
| 144 | -	public function getLogo($useSvg = true) { | |
| 145 | -		$logo = $this->config->getAppValue('theming', 'logoMime', false); | |
| 146 | - | |
| 147 | - $logoExists = true; | |
| 148 | -		try { | |
| 149 | -			$this->appData->getFolder('images')->getFile('logo'); | |
| 150 | -		} catch (\Exception $e) { | |
| 151 | - $logoExists = false; | |
| 152 | - } | |
| 153 | - | |
| 154 | -		$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); | |
| 155 | - | |
| 156 | -		if(!$logo || !$logoExists) { | |
| 157 | -			if($useSvg) { | |
| 158 | -				$logo = $this->urlGenerator->imagePath('core', 'logo.svg'); | |
| 159 | -			} else { | |
| 160 | -				$logo = $this->urlGenerator->imagePath('core', 'logo.png'); | |
| 161 | - } | |
| 162 | - return $logo . '?v=' . $cacheBusterCounter; | |
| 163 | - } | |
| 164 | - | |
| 165 | -		return $this->urlGenerator->linkToRoute('theming.Theming.getLogo') . '?v=' . $cacheBusterCounter; | |
| 166 | - } | |
| 167 | - | |
| 168 | - /** | |
| 169 | - * Themed background image url | |
| 170 | - * | |
| 171 | - * @return string | |
| 172 | - */ | |
| 173 | -	public function getBackground() { | |
| 174 | -		$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime',false); | |
| 175 | - | |
| 176 | - $backgroundExists = true; | |
| 177 | -		try { | |
| 178 | -			$this->appData->getFolder('images')->getFile('background'); | |
| 179 | -		} catch (\Exception $e) { | |
| 180 | - $backgroundExists = false; | |
| 181 | - } | |
| 182 | - | |
| 183 | -		$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); | |
| 184 | - | |
| 185 | -		if(!$backgroundLogo || !$backgroundExists) { | |
| 186 | -			return $this->urlGenerator->imagePath('core','background.jpg') . '?v=' . $cacheBusterCounter; | |
| 187 | - } | |
| 188 | - | |
| 189 | -		return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground') . '?v=' . $cacheBusterCounter; | |
| 190 | - } | |
| 191 | - | |
| 192 | - /** | |
| 193 | - * @return string | |
| 194 | - */ | |
| 195 | -	public function getiTunesAppId() { | |
| 196 | -		return $this->config->getAppValue('theming', 'iTunesAppId', $this->iTunesAppId); | |
| 197 | - } | |
| 198 | - | |
| 199 | - /** | |
| 200 | - * @return string | |
| 201 | - */ | |
| 202 | -	public function getiOSClientUrl() { | |
| 203 | -		return $this->config->getAppValue('theming', 'iOSClientUrl', $this->iOSClientUrl); | |
| 204 | - } | |
| 205 | - | |
| 206 | - /** | |
| 207 | - * @return string | |
| 208 | - */ | |
| 209 | -	public function getAndroidClientUrl() { | |
| 210 | -		return $this->config->getAppValue('theming', 'AndroidClientUrl', $this->AndroidClientUrl); | |
| 211 | - } | |
| 212 | - | |
| 213 | - | |
| 214 | - /** | |
| 215 | - * @return array scss variables to overwrite | |
| 216 | - */ | |
| 217 | -	public function getScssVariables() { | |
| 218 | -		$cache = $this->cacheFactory->create('theming'); | |
| 219 | -		if ($value = $cache->get('getScssVariables')) { | |
| 220 | - return $value; | |
| 221 | - } | |
| 222 | - | |
| 223 | - $variables = [ | |
| 224 | -			'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'", | |
| 225 | -			'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime', '') . "'", | |
| 226 | -			'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime', '') . "'" | |
| 227 | - ]; | |
| 228 | - | |
| 229 | - $variables['image-logo'] = "'".$this->urlGenerator->getAbsoluteURL($this->getLogo())."'"; | |
| 230 | - $variables['image-login-background'] = "'".$this->urlGenerator->getAbsoluteURL($this->getBackground())."'"; | |
| 231 | - $variables['image-login-plain'] = 'false'; | |
| 232 | - | |
| 233 | -		if ($this->config->getAppValue('theming', 'color', null) !== null) { | |
| 234 | -			if ($this->util->invertTextColor($this->getColorPrimary())) { | |
| 235 | - $colorPrimaryText = '#000000'; | |
| 236 | -			} else { | |
| 237 | - $colorPrimaryText = '#ffffff'; | |
| 238 | - } | |
| 239 | - $variables['color-primary'] = $this->getColorPrimary(); | |
| 240 | - $variables['color-primary-text'] = $colorPrimaryText; | |
| 241 | - $variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary()); | |
| 242 | - } | |
| 243 | - | |
| 244 | -		if ($this->config->getAppValue('theming', 'backgroundMime', null) === 'backgroundColor') { | |
| 245 | - $variables['image-login-plain'] = 'true'; | |
| 246 | - } | |
| 247 | -		$cache->set('getScssVariables', $variables); | |
| 248 | - return $variables; | |
| 249 | - } | |
| 250 | - | |
| 251 | - /** | |
| 252 | - * Check if Imagemagick is enabled and if SVG is supported | |
| 253 | - * otherwise we can't render custom icons | |
| 254 | - * | |
| 255 | - * @return bool | |
| 256 | - */ | |
| 257 | -	public function shouldReplaceIcons() { | |
| 258 | -		$cache = $this->cacheFactory->create('theming'); | |
| 259 | -		if($value = $cache->get('shouldReplaceIcons')) { | |
| 260 | - return (bool)$value; | |
| 261 | - } | |
| 262 | - $value = false; | |
| 263 | -		if(extension_loaded('imagick')) { | |
| 264 | - $checkImagick = new \Imagick(); | |
| 265 | -			if (count($checkImagick->queryFormats('SVG')) >= 1) { | |
| 266 | - $value = true; | |
| 267 | - } | |
| 268 | - $checkImagick->clear(); | |
| 269 | - } | |
| 270 | -		$cache->set('shouldReplaceIcons', $value); | |
| 271 | - return $value; | |
| 272 | - } | |
| 273 | - | |
| 274 | - /** | |
| 275 | - * Increases the cache buster key | |
| 276 | - */ | |
| 277 | -	private function increaseCacheBuster() { | |
| 278 | -		$cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); | |
| 279 | -		$this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1); | |
| 280 | -		$this->cacheFactory->create('theming')->clear('getScssVariables'); | |
| 281 | - } | |
| 282 | - | |
| 283 | - /** | |
| 284 | - * Update setting in the database | |
| 285 | - * | |
| 286 | - * @param string $setting | |
| 287 | - * @param string $value | |
| 288 | - */ | |
| 289 | -	public function set($setting, $value) { | |
| 290 | -		$this->config->setAppValue('theming', $setting, $value); | |
| 291 | - $this->increaseCacheBuster(); | |
| 292 | - } | |
| 293 | - | |
| 294 | - /** | |
| 295 | - * Revert settings to the default value | |
| 296 | - * | |
| 297 | - * @param string $setting setting which should be reverted | |
| 298 | - * @return string default value | |
| 299 | - */ | |
| 300 | -	public function undo($setting) { | |
| 301 | -		$this->config->deleteAppValue('theming', $setting); | |
| 302 | - $this->increaseCacheBuster(); | |
| 303 | - | |
| 304 | -		switch ($setting) { | |
| 305 | - case 'name': | |
| 306 | - $returnValue = $this->getEntity(); | |
| 307 | - break; | |
| 308 | - case 'url': | |
| 309 | - $returnValue = $this->getBaseUrl(); | |
| 310 | - break; | |
| 311 | - case 'slogan': | |
| 312 | - $returnValue = $this->getSlogan(); | |
| 313 | - break; | |
| 314 | - case 'color': | |
| 315 | - $returnValue = $this->getColorPrimary(); | |
| 316 | - break; | |
| 317 | - default: | |
| 318 | - $returnValue = ''; | |
| 319 | - break; | |
| 320 | - } | |
| 321 | - | |
| 322 | - return $returnValue; | |
| 323 | - } | |
| 34 | + /** @var IConfig */ | |
| 35 | + private $config; | |
| 36 | + /** @var IL10N */ | |
| 37 | + private $l; | |
| 38 | + /** @var IURLGenerator */ | |
| 39 | + private $urlGenerator; | |
| 40 | + /** @var IAppData */ | |
| 41 | + private $appData; | |
| 42 | + /** @var ICacheFactory */ | |
| 43 | + private $cacheFactory; | |
| 44 | + /** @var string */ | |
| 45 | + private $name; | |
| 46 | + /** @var string */ | |
| 47 | + private $url; | |
| 48 | + /** @var string */ | |
| 49 | + private $slogan; | |
| 50 | + /** @var string */ | |
| 51 | + private $color; | |
| 52 | + /** @var Util */ | |
| 53 | + private $util; | |
| 54 | + /** @var string */ | |
| 55 | + private $iTunesAppId; | |
| 56 | + /** @var string */ | |
| 57 | + private $iOSClientUrl; | |
| 58 | + /** @var string */ | |
| 59 | + private $AndroidClientUrl; | |
| 60 | + | |
| 61 | + /** | |
| 62 | + * ThemingDefaults constructor. | |
| 63 | + * | |
| 64 | + * @param IConfig $config | |
| 65 | + * @param IL10N $l | |
| 66 | + * @param IURLGenerator $urlGenerator | |
| 67 | + * @param \OC_Defaults $defaults | |
| 68 | + * @param IAppData $appData | |
| 69 | + * @param ICacheFactory $cacheFactory | |
| 70 | + * @param Util $util | |
| 71 | + */ | |
| 72 | + public function __construct(IConfig $config, | |
| 73 | + IL10N $l, | |
| 74 | + IURLGenerator $urlGenerator, | |
| 75 | + IAppData $appData, | |
| 76 | + ICacheFactory $cacheFactory, | |
| 77 | + Util $util | |
| 78 | +    ) { | |
| 79 | + parent::__construct(); | |
| 80 | + $this->config = $config; | |
| 81 | + $this->l = $l; | |
| 82 | + $this->urlGenerator = $urlGenerator; | |
| 83 | + $this->appData = $appData; | |
| 84 | + $this->cacheFactory = $cacheFactory; | |
| 85 | + $this->util = $util; | |
| 86 | + | |
| 87 | + $this->name = parent::getName(); | |
| 88 | + $this->url = parent::getBaseUrl(); | |
| 89 | + $this->slogan = parent::getSlogan(); | |
| 90 | + $this->color = parent::getColorPrimary(); | |
| 91 | + $this->iTunesAppId = parent::getiTunesAppId(); | |
| 92 | + $this->iOSClientUrl = parent::getiOSClientUrl(); | |
| 93 | + $this->AndroidClientUrl = parent::getAndroidClientUrl(); | |
| 94 | + } | |
| 95 | + | |
| 96 | +    public function getName() { | |
| 97 | +        return strip_tags($this->config->getAppValue('theming', 'name', $this->name)); | |
| 98 | + } | |
| 99 | + | |
| 100 | +    public function getHTMLName() { | |
| 101 | +        return $this->config->getAppValue('theming', 'name', $this->name); | |
| 102 | + } | |
| 103 | + | |
| 104 | +    public function getTitle() { | |
| 105 | + return $this->getName(); | |
| 106 | + } | |
| 107 | + | |
| 108 | +    public function getEntity() { | |
| 109 | + return $this->getName(); | |
| 110 | + } | |
| 111 | + | |
| 112 | +    public function getBaseUrl() { | |
| 113 | +        return $this->config->getAppValue('theming', 'url', $this->url); | |
| 114 | + } | |
| 115 | + | |
| 116 | +    public function getSlogan() { | |
| 117 | +        return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan)); | |
| 118 | + } | |
| 119 | + | |
| 120 | +    public function getShortFooter() { | |
| 121 | + $slogan = $this->getSlogan(); | |
| 122 | + $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' . | |
| 123 | + ' rel="noreferrer">' .$this->getEntity() . '</a>'. | |
| 124 | + ($slogan !== '' ? ' – ' . $slogan : ''); | |
| 125 | + | |
| 126 | + return $footer; | |
| 127 | + } | |
| 128 | + | |
| 129 | + /** | |
| 130 | + * Color that is used for the header as well as for mail headers | |
| 131 | + * | |
| 132 | + * @return string | |
| 133 | + */ | |
| 134 | +    public function getColorPrimary() { | |
| 135 | +        return $this->config->getAppValue('theming', 'color', $this->color); | |
| 136 | + } | |
| 137 | + | |
| 138 | + /** | |
| 139 | + * Themed logo url | |
| 140 | + * | |
| 141 | + * @param bool $useSvg Whether to point to the SVG image or a fallback | |
| 142 | + * @return string | |
| 143 | + */ | |
| 144 | +    public function getLogo($useSvg = true) { | |
| 145 | +        $logo = $this->config->getAppValue('theming', 'logoMime', false); | |
| 146 | + | |
| 147 | + $logoExists = true; | |
| 148 | +        try { | |
| 149 | +            $this->appData->getFolder('images')->getFile('logo'); | |
| 150 | +        } catch (\Exception $e) { | |
| 151 | + $logoExists = false; | |
| 152 | + } | |
| 153 | + | |
| 154 | +        $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); | |
| 155 | + | |
| 156 | +        if(!$logo || !$logoExists) { | |
| 157 | +            if($useSvg) { | |
| 158 | +                $logo = $this->urlGenerator->imagePath('core', 'logo.svg'); | |
| 159 | +            } else { | |
| 160 | +                $logo = $this->urlGenerator->imagePath('core', 'logo.png'); | |
| 161 | + } | |
| 162 | + return $logo . '?v=' . $cacheBusterCounter; | |
| 163 | + } | |
| 164 | + | |
| 165 | +        return $this->urlGenerator->linkToRoute('theming.Theming.getLogo') . '?v=' . $cacheBusterCounter; | |
| 166 | + } | |
| 167 | + | |
| 168 | + /** | |
| 169 | + * Themed background image url | |
| 170 | + * | |
| 171 | + * @return string | |
| 172 | + */ | |
| 173 | +    public function getBackground() { | |
| 174 | +        $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime',false); | |
| 175 | + | |
| 176 | + $backgroundExists = true; | |
| 177 | +        try { | |
| 178 | +            $this->appData->getFolder('images')->getFile('background'); | |
| 179 | +        } catch (\Exception $e) { | |
| 180 | + $backgroundExists = false; | |
| 181 | + } | |
| 182 | + | |
| 183 | +        $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); | |
| 184 | + | |
| 185 | +        if(!$backgroundLogo || !$backgroundExists) { | |
| 186 | +            return $this->urlGenerator->imagePath('core','background.jpg') . '?v=' . $cacheBusterCounter; | |
| 187 | + } | |
| 188 | + | |
| 189 | +        return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground') . '?v=' . $cacheBusterCounter; | |
| 190 | + } | |
| 191 | + | |
| 192 | + /** | |
| 193 | + * @return string | |
| 194 | + */ | |
| 195 | +    public function getiTunesAppId() { | |
| 196 | +        return $this->config->getAppValue('theming', 'iTunesAppId', $this->iTunesAppId); | |
| 197 | + } | |
| 198 | + | |
| 199 | + /** | |
| 200 | + * @return string | |
| 201 | + */ | |
| 202 | +    public function getiOSClientUrl() { | |
| 203 | +        return $this->config->getAppValue('theming', 'iOSClientUrl', $this->iOSClientUrl); | |
| 204 | + } | |
| 205 | + | |
| 206 | + /** | |
| 207 | + * @return string | |
| 208 | + */ | |
| 209 | +    public function getAndroidClientUrl() { | |
| 210 | +        return $this->config->getAppValue('theming', 'AndroidClientUrl', $this->AndroidClientUrl); | |
| 211 | + } | |
| 212 | + | |
| 213 | + | |
| 214 | + /** | |
| 215 | + * @return array scss variables to overwrite | |
| 216 | + */ | |
| 217 | +    public function getScssVariables() { | |
| 218 | +        $cache = $this->cacheFactory->create('theming'); | |
| 219 | +        if ($value = $cache->get('getScssVariables')) { | |
| 220 | + return $value; | |
| 221 | + } | |
| 222 | + | |
| 223 | + $variables = [ | |
| 224 | +            'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'", | |
| 225 | +            'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime', '') . "'", | |
| 226 | +            'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime', '') . "'" | |
| 227 | + ]; | |
| 228 | + | |
| 229 | + $variables['image-logo'] = "'".$this->urlGenerator->getAbsoluteURL($this->getLogo())."'"; | |
| 230 | + $variables['image-login-background'] = "'".$this->urlGenerator->getAbsoluteURL($this->getBackground())."'"; | |
| 231 | + $variables['image-login-plain'] = 'false'; | |
| 232 | + | |
| 233 | +        if ($this->config->getAppValue('theming', 'color', null) !== null) { | |
| 234 | +            if ($this->util->invertTextColor($this->getColorPrimary())) { | |
| 235 | + $colorPrimaryText = '#000000'; | |
| 236 | +            } else { | |
| 237 | + $colorPrimaryText = '#ffffff'; | |
| 238 | + } | |
| 239 | + $variables['color-primary'] = $this->getColorPrimary(); | |
| 240 | + $variables['color-primary-text'] = $colorPrimaryText; | |
| 241 | + $variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary()); | |
| 242 | + } | |
| 243 | + | |
| 244 | +        if ($this->config->getAppValue('theming', 'backgroundMime', null) === 'backgroundColor') { | |
| 245 | + $variables['image-login-plain'] = 'true'; | |
| 246 | + } | |
| 247 | +        $cache->set('getScssVariables', $variables); | |
| 248 | + return $variables; | |
| 249 | + } | |
| 250 | + | |
| 251 | + /** | |
| 252 | + * Check if Imagemagick is enabled and if SVG is supported | |
| 253 | + * otherwise we can't render custom icons | |
| 254 | + * | |
| 255 | + * @return bool | |
| 256 | + */ | |
| 257 | +    public function shouldReplaceIcons() { | |
| 258 | +        $cache = $this->cacheFactory->create('theming'); | |
| 259 | +        if($value = $cache->get('shouldReplaceIcons')) { | |
| 260 | + return (bool)$value; | |
| 261 | + } | |
| 262 | + $value = false; | |
| 263 | +        if(extension_loaded('imagick')) { | |
| 264 | + $checkImagick = new \Imagick(); | |
| 265 | +            if (count($checkImagick->queryFormats('SVG')) >= 1) { | |
| 266 | + $value = true; | |
| 267 | + } | |
| 268 | + $checkImagick->clear(); | |
| 269 | + } | |
| 270 | +        $cache->set('shouldReplaceIcons', $value); | |
| 271 | + return $value; | |
| 272 | + } | |
| 273 | + | |
| 274 | + /** | |
| 275 | + * Increases the cache buster key | |
| 276 | + */ | |
| 277 | +    private function increaseCacheBuster() { | |
| 278 | +        $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); | |
| 279 | +        $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1); | |
| 280 | +        $this->cacheFactory->create('theming')->clear('getScssVariables'); | |
| 281 | + } | |
| 282 | + | |
| 283 | + /** | |
| 284 | + * Update setting in the database | |
| 285 | + * | |
| 286 | + * @param string $setting | |
| 287 | + * @param string $value | |
| 288 | + */ | |
| 289 | +    public function set($setting, $value) { | |
| 290 | +        $this->config->setAppValue('theming', $setting, $value); | |
| 291 | + $this->increaseCacheBuster(); | |
| 292 | + } | |
| 293 | + | |
| 294 | + /** | |
| 295 | + * Revert settings to the default value | |
| 296 | + * | |
| 297 | + * @param string $setting setting which should be reverted | |
| 298 | + * @return string default value | |
| 299 | + */ | |
| 300 | +    public function undo($setting) { | |
| 301 | +        $this->config->deleteAppValue('theming', $setting); | |
| 302 | + $this->increaseCacheBuster(); | |
| 303 | + | |
| 304 | +        switch ($setting) { | |
| 305 | + case 'name': | |
| 306 | + $returnValue = $this->getEntity(); | |
| 307 | + break; | |
| 308 | + case 'url': | |
| 309 | + $returnValue = $this->getBaseUrl(); | |
| 310 | + break; | |
| 311 | + case 'slogan': | |
| 312 | + $returnValue = $this->getSlogan(); | |
| 313 | + break; | |
| 314 | + case 'color': | |
| 315 | + $returnValue = $this->getColorPrimary(); | |
| 316 | + break; | |
| 317 | + default: | |
| 318 | + $returnValue = ''; | |
| 319 | + break; | |
| 320 | + } | |
| 321 | + | |
| 322 | + return $returnValue; | |
| 323 | + } | |
| 324 | 324 | } |