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