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