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