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