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