Completed
Pull Request — master (#9723)
by Julius
33:33 queued 06:24
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.
lib/private/legacy/template.php 2 patches
Indentation   +346 added lines, -346 removed lines patch added patch discarded remove patch
@@ -46,350 +46,350 @@
 block discarded – undo
46 46
  */
47 47
 class OC_Template extends \OC\Template\Base {
48 48
 
49
-	/** @var string */
50
-	private $renderAs; // Create a full page?
51
-
52
-	/** @var string */
53
-	private $path; // The path to the template
54
-
55
-	/** @var array */
56
-	private $headers = array(); //custom headers
57
-
58
-	/** @var string */
59
-	protected $app; // app id
60
-
61
-	protected static $initTemplateEngineFirstRun = true;
62
-
63
-	/**
64
-	 * Constructor
65
-	 *
66
-	 * @param string $app app providing the template
67
-	 * @param string $name of the template file (without suffix)
68
-	 * @param string $renderAs If $renderAs is set, OC_Template will try to
69
-	 *                         produce a full page in the according layout. For
70
-	 *                         now, $renderAs can be set to "guest", "user" or
71
-	 *                         "admin".
72
-	 * @param bool $registerCall = true
73
-	 */
74
-	public function __construct( $app, $name, $renderAs = "", $registerCall = true ) {
75
-		// Read the selected theme from the config file
76
-		self::initTemplateEngine($renderAs);
77
-
78
-		$theme = OC_Util::getTheme();
79
-
80
-		$requestToken = (OC::$server->getSession() && $registerCall) ? \OCP\Util::callRegister() : '';
81
-
82
-		$parts = explode('/', $app); // fix translation when app is something like core/lostpassword
83
-		$l10n = \OC::$server->getL10N($parts[0]);
84
-		/** @var \OCP\Defaults $themeDefaults */
85
-		$themeDefaults = \OC::$server->query(\OCP\Defaults::class);
86
-
87
-		list($path, $template) = $this->findTemplate($theme, $app, $name);
88
-
89
-		// Set the private data
90
-		$this->renderAs = $renderAs;
91
-		$this->path = $path;
92
-		$this->app = $app;
93
-
94
-		parent::__construct($template, $requestToken, $l10n, $themeDefaults);
95
-	}
96
-
97
-	/**
98
-	 * @param string $renderAs
99
-	 */
100
-	public static function initTemplateEngine($renderAs) {
101
-		if (self::$initTemplateEngineFirstRun){
102
-
103
-			//apps that started before the template initialization can load their own scripts/styles
104
-			//so to make sure this scripts/styles here are loaded first we use OC_Util::addScript() with $prepend=true
105
-			//meaning the last script/style in this list will be loaded first
106
-			if (\OC::$server->getSystemConfig()->getValue ('installed', false) && $renderAs !== 'error' && !\OCP\Util::needUpgrade()) {
107
-				if (\OC::$server->getConfig ()->getAppValue ( 'core', 'backgroundjobs_mode', 'ajax' ) == 'ajax') {
108
-					OC_Util::addScript ( 'backgroundjobs', null, true );
109
-				}
110
-			}
111
-
112
-			OC_Util::addStyle('css-variables', null, true);
113
-			OC_Util::addStyle('server', null, true);
114
-			OC_Util::addStyle('jquery-ui-fixes',null,true);
115
-			OC_Util::addVendorStyle('jquery-ui/themes/base/jquery-ui',null,true);
116
-			OC_Util::addVendorStyle('select2/select2', null, true);
117
-			OC_Util::addStyle('jquery.ocdialog');
118
-			OC_Util::addTranslations("core", null, true);
119
-			OC_Util::addScript('search', 'search', true);
120
-			OC_Util::addScript('merged-template-prepend', null, true);
121
-			OC_Util::addScript('jquery-ui-fixes');
122
-			OC_Util::addScript('files/fileinfo');
123
-			OC_Util::addScript('files/client');
124
-			OC_Util::addScript('contactsmenu');
125
-
126
-			if (\OC::$server->getConfig()->getSystemValue('debug')) {
127
-				// Add the stuff we need always
128
-				// following logic will import all vendor libraries that are
129
-				// specified in core/js/core.json
130
-				$fileContent = file_get_contents(OC::$SERVERROOT . '/core/js/core.json');
131
-				if($fileContent !== false) {
132
-					$coreDependencies = json_decode($fileContent, true);
133
-					foreach(array_reverse($coreDependencies['vendor']) as $vendorLibrary) {
134
-						//remove trailing ".js" as addVendorScript will append it
135
-						OC_Util::addVendorScript(
136
-							substr($vendorLibrary, 0, -3),null,true);
137
-						}
138
- 				} else {
139
-					throw new \Exception('Cannot read core/js/core.json');
140
-				}
141
-			} else {
142
-				// Import all (combined) default vendor libraries
143
-				OC_Util::addVendorScript('core', null, true);
144
-			}
145
-
146
-			if (\OC::$server->getRequest()->isUserAgent([\OC\AppFramework\Http\Request::USER_AGENT_IE])) {
147
-				// polyfill for btoa/atob for IE friends
148
-				OC_Util::addVendorScript('base64/base64');
149
-				// shim for the davclient.js library
150
-				\OCP\Util::addScript('files/iedavclient');
151
-			}
152
-
153
-			self::$initTemplateEngineFirstRun = false;
154
-		}
155
-
156
-	}
157
-
158
-
159
-	/**
160
-	 * find the template with the given name
161
-	 * @param string $name of the template file (without suffix)
162
-	 *
163
-	 * Will select the template file for the selected theme.
164
-	 * Checking all the possible locations.
165
-	 * @param string $theme
166
-	 * @param string $app
167
-	 * @return string[]
168
-	 */
169
-	protected function findTemplate($theme, $app, $name) {
170
-		// Check if it is a app template or not.
171
-		if( $app !== '' ) {
172
-			$dirs = $this->getAppTemplateDirs($theme, $app, OC::$SERVERROOT, OC_App::getAppPath($app));
173
-		} else {
174
-			$dirs = $this->getCoreTemplateDirs($theme, OC::$SERVERROOT);
175
-		}
176
-		$locator = new \OC\Template\TemplateFileLocator( $dirs );
177
-		$template = $locator->find($name);
178
-		$path = $locator->getPath();
179
-		return array($path, $template);
180
-	}
181
-
182
-	/**
183
-	 * Add a custom element to the header
184
-	 * @param string $tag tag name of the element
185
-	 * @param array $attributes array of attributes for the element
186
-	 * @param string $text the text content for the element. If $text is null then the
187
-	 * element will be written as empty element. So use "" to get a closing tag.
188
-	 */
189
-	public function addHeader($tag, $attributes, $text=null) {
190
-		$this->headers[]= array(
191
-			'tag' => $tag,
192
-			'attributes' => $attributes,
193
-			'text' => $text
194
-		);
195
-	}
196
-
197
-	/**
198
-	 * Process the template
199
-	 * @return boolean|string
200
-	 *
201
-	 * This function process the template. If $this->renderAs is set, it
202
-	 * will produce a full page.
203
-	 */
204
-	public function fetchPage($additionalParams = null) {
205
-		$data = parent::fetchPage($additionalParams);
206
-
207
-		if( $this->renderAs ) {
208
-			$page = new TemplateLayout($this->renderAs, $this->app);
209
-
210
-			if(is_array($additionalParams)) {
211
-				foreach ($additionalParams as $key => $value) {
212
-					$page->assign($key, $value);
213
-				}
214
-			}
215
-
216
-			// Add custom headers
217
-			$headers = '';
218
-			foreach(OC_Util::$headers as $header) {
219
-				$headers .= '<'.\OCP\Util::sanitizeHTML($header['tag']);
220
-				if ( strcasecmp($header['tag'], 'script') === 0 && in_array('src', array_map('strtolower', array_keys($header['attributes']))) ) {
221
-					$headers .= ' defer';
222
-				}
223
-				foreach($header['attributes'] as $name=>$value) {
224
-					$headers .= ' '.\OCP\Util::sanitizeHTML($name).'="'.\OCP\Util::sanitizeHTML($value).'"';
225
-				}
226
-				if ($header['text'] !== null) {
227
-					$headers .= '>'.\OCP\Util::sanitizeHTML($header['text']).'</'.\OCP\Util::sanitizeHTML($header['tag']).'>';
228
-				} else {
229
-					$headers .= '/>';
230
-				}
231
-			}
232
-
233
-			$page->assign('headers', $headers);
234
-
235
-			$page->assign('content', $data);
236
-			return $page->fetchPage($additionalParams);
237
-		}
238
-
239
-		return $data;
240
-	}
241
-
242
-	/**
243
-	 * Include template
244
-	 *
245
-	 * @param string $file
246
-	 * @param array|null $additionalParams
247
-	 * @return string returns content of included template
248
-	 *
249
-	 * Includes another template. use <?php echo $this->inc('template'); ?> to
250
-	 * do this.
251
-	 */
252
-	public function inc( $file, $additionalParams = null ) {
253
-		return $this->load($this->path.$file.'.php', $additionalParams);
254
-	}
255
-
256
-	/**
257
-	 * Shortcut to print a simple page for users
258
-	 * @param string $application The application we render the template for
259
-	 * @param string $name Name of the template
260
-	 * @param array $parameters Parameters for the template
261
-	 * @return boolean|null
262
-	 */
263
-	public static function printUserPage( $application, $name, $parameters = array() ) {
264
-		$content = new OC_Template( $application, $name, "user" );
265
-		foreach( $parameters as $key => $value ) {
266
-			$content->assign( $key, $value );
267
-		}
268
-		print $content->printPage();
269
-	}
270
-
271
-	/**
272
-	 * Shortcut to print a simple page for admins
273
-	 * @param string $application The application we render the template for
274
-	 * @param string $name Name of the template
275
-	 * @param array $parameters Parameters for the template
276
-	 * @return bool
277
-	 */
278
-	public static function printAdminPage( $application, $name, $parameters = array() ) {
279
-		$content = new OC_Template( $application, $name, "admin" );
280
-		foreach( $parameters as $key => $value ) {
281
-			$content->assign( $key, $value );
282
-		}
283
-		return $content->printPage();
284
-	}
285
-
286
-	/**
287
-	 * Shortcut to print a simple page for guests
288
-	 * @param string $application The application we render the template for
289
-	 * @param string $name Name of the template
290
-	 * @param array|string $parameters Parameters for the template
291
-	 * @return bool
292
-	 */
293
-	public static function printGuestPage( $application, $name, $parameters = array() ) {
294
-		$content = new OC_Template( $application, $name, "guest" );
295
-		foreach( $parameters as $key => $value ) {
296
-			$content->assign( $key, $value );
297
-		}
298
-		return $content->printPage();
299
-	}
300
-
301
-	/**
302
-	 * Print a fatal error page and terminates the script
303
-	 * @param string $error_msg The error message to show
304
-	 * @param string $hint An optional hint message - needs to be properly escape
305
-	 * @suppress PhanAccessMethodInternal
306
-	 */
307
-	public static function printErrorPage( $error_msg, $hint = '' ) {
308
-		if (\OC::$server->getAppManager()->isEnabledForUser('theming') && !\OC_App::isAppLoaded('theming')) {
309
-			\OC_App::loadApp('theming');
310
-		}
311
-
312
-
313
-		if ($error_msg === $hint) {
314
-			// If the hint is the same as the message there is no need to display it twice.
315
-			$hint = '';
316
-		}
317
-
318
-		try {
319
-			$content = new \OC_Template( '', 'error', 'error', false );
320
-			$errors = array(array('error' => $error_msg, 'hint' => $hint));
321
-			$content->assign( 'errors', $errors );
322
-			$content->printPage();
323
-		} catch (\Exception $e) {
324
-			$logger = \OC::$server->getLogger();
325
-			$logger->error("$error_msg $hint", ['app' => 'core']);
326
-			$logger->logException($e, ['app' => 'core']);
327
-
328
-			header(self::getHttpProtocol() . ' 500 Internal Server Error');
329
-			header('Content-Type: text/plain; charset=utf-8');
330
-			print("$error_msg $hint");
331
-		}
332
-		die();
333
-	}
334
-
335
-	/**
336
-	 * print error page using Exception details
337
-	 * @param Exception|Throwable $exception
338
-	 * @param bool $fetchPage
339
-	 * @return bool|string
340
-	 * @suppress PhanAccessMethodInternal
341
-	 */
342
-	public static function printExceptionErrorPage($exception, $fetchPage = false) {
343
-		try {
344
-			$request = \OC::$server->getRequest();
345
-			$content = new \OC_Template('', 'exception', 'error', false);
346
-			$content->assign('errorClass', get_class($exception));
347
-			$content->assign('errorMsg', $exception->getMessage());
348
-			$content->assign('errorCode', $exception->getCode());
349
-			$content->assign('file', $exception->getFile());
350
-			$content->assign('line', $exception->getLine());
351
-			$content->assign('trace', $exception->getTraceAsString());
352
-			$content->assign('debugMode', \OC::$server->getSystemConfig()->getValue('debug', false));
353
-			$content->assign('remoteAddr', $request->getRemoteAddress());
354
-			$content->assign('requestID', $request->getId());
355
-			if ($fetchPage) {
356
-				return $content->fetchPage();
357
-			}
358
-			$content->printPage();
359
-		} catch (\Exception $e) {
360
-			$logger = \OC::$server->getLogger();
361
-			$logger->logException($exception, ['app' => 'core']);
362
-			$logger->logException($e, ['app' => 'core']);
363
-
364
-			header(self::getHttpProtocol() . ' 500 Internal Server Error');
365
-			header('Content-Type: text/plain; charset=utf-8');
366
-			print("Internal Server Error\n\n");
367
-			print("The server encountered an internal error and was unable to complete your request.\n");
368
-			print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n");
369
-			print("More details can be found in the server log.\n");
370
-		}
371
-		die();
372
-	}
373
-
374
-	/**
375
-	 * This is only here to reduce the dependencies in case of an exception to
376
-	 * still be able to print a plain error message.
377
-	 *
378
-	 * Returns the used HTTP protocol.
379
-	 *
380
-	 * @return string HTTP protocol. HTTP/2, HTTP/1.1 or HTTP/1.0.
381
-	 * @internal Don't use this - use AppFramework\Http\Request->getHttpProtocol instead
382
-	 */
383
-	protected static function getHttpProtocol() {
384
-		$claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']);
385
-		$validProtocols = [
386
-			'HTTP/1.0',
387
-			'HTTP/1.1',
388
-			'HTTP/2',
389
-		];
390
-		if(in_array($claimedProtocol, $validProtocols, true)) {
391
-			return $claimedProtocol;
392
-		}
393
-		return 'HTTP/1.1';
394
-	}
49
+    /** @var string */
50
+    private $renderAs; // Create a full page?
51
+
52
+    /** @var string */
53
+    private $path; // The path to the template
54
+
55
+    /** @var array */
56
+    private $headers = array(); //custom headers
57
+
58
+    /** @var string */
59
+    protected $app; // app id
60
+
61
+    protected static $initTemplateEngineFirstRun = true;
62
+
63
+    /**
64
+     * Constructor
65
+     *
66
+     * @param string $app app providing the template
67
+     * @param string $name of the template file (without suffix)
68
+     * @param string $renderAs If $renderAs is set, OC_Template will try to
69
+     *                         produce a full page in the according layout. For
70
+     *                         now, $renderAs can be set to "guest", "user" or
71
+     *                         "admin".
72
+     * @param bool $registerCall = true
73
+     */
74
+    public function __construct( $app, $name, $renderAs = "", $registerCall = true ) {
75
+        // Read the selected theme from the config file
76
+        self::initTemplateEngine($renderAs);
77
+
78
+        $theme = OC_Util::getTheme();
79
+
80
+        $requestToken = (OC::$server->getSession() && $registerCall) ? \OCP\Util::callRegister() : '';
81
+
82
+        $parts = explode('/', $app); // fix translation when app is something like core/lostpassword
83
+        $l10n = \OC::$server->getL10N($parts[0]);
84
+        /** @var \OCP\Defaults $themeDefaults */
85
+        $themeDefaults = \OC::$server->query(\OCP\Defaults::class);
86
+
87
+        list($path, $template) = $this->findTemplate($theme, $app, $name);
88
+
89
+        // Set the private data
90
+        $this->renderAs = $renderAs;
91
+        $this->path = $path;
92
+        $this->app = $app;
93
+
94
+        parent::__construct($template, $requestToken, $l10n, $themeDefaults);
95
+    }
96
+
97
+    /**
98
+     * @param string $renderAs
99
+     */
100
+    public static function initTemplateEngine($renderAs) {
101
+        if (self::$initTemplateEngineFirstRun){
102
+
103
+            //apps that started before the template initialization can load their own scripts/styles
104
+            //so to make sure this scripts/styles here are loaded first we use OC_Util::addScript() with $prepend=true
105
+            //meaning the last script/style in this list will be loaded first
106
+            if (\OC::$server->getSystemConfig()->getValue ('installed', false) && $renderAs !== 'error' && !\OCP\Util::needUpgrade()) {
107
+                if (\OC::$server->getConfig ()->getAppValue ( 'core', 'backgroundjobs_mode', 'ajax' ) == 'ajax') {
108
+                    OC_Util::addScript ( 'backgroundjobs', null, true );
109
+                }
110
+            }
111
+
112
+            OC_Util::addStyle('css-variables', null, true);
113
+            OC_Util::addStyle('server', null, true);
114
+            OC_Util::addStyle('jquery-ui-fixes',null,true);
115
+            OC_Util::addVendorStyle('jquery-ui/themes/base/jquery-ui',null,true);
116
+            OC_Util::addVendorStyle('select2/select2', null, true);
117
+            OC_Util::addStyle('jquery.ocdialog');
118
+            OC_Util::addTranslations("core", null, true);
119
+            OC_Util::addScript('search', 'search', true);
120
+            OC_Util::addScript('merged-template-prepend', null, true);
121
+            OC_Util::addScript('jquery-ui-fixes');
122
+            OC_Util::addScript('files/fileinfo');
123
+            OC_Util::addScript('files/client');
124
+            OC_Util::addScript('contactsmenu');
125
+
126
+            if (\OC::$server->getConfig()->getSystemValue('debug')) {
127
+                // Add the stuff we need always
128
+                // following logic will import all vendor libraries that are
129
+                // specified in core/js/core.json
130
+                $fileContent = file_get_contents(OC::$SERVERROOT . '/core/js/core.json');
131
+                if($fileContent !== false) {
132
+                    $coreDependencies = json_decode($fileContent, true);
133
+                    foreach(array_reverse($coreDependencies['vendor']) as $vendorLibrary) {
134
+                        //remove trailing ".js" as addVendorScript will append it
135
+                        OC_Util::addVendorScript(
136
+                            substr($vendorLibrary, 0, -3),null,true);
137
+                        }
138
+                    } else {
139
+                    throw new \Exception('Cannot read core/js/core.json');
140
+                }
141
+            } else {
142
+                // Import all (combined) default vendor libraries
143
+                OC_Util::addVendorScript('core', null, true);
144
+            }
145
+
146
+            if (\OC::$server->getRequest()->isUserAgent([\OC\AppFramework\Http\Request::USER_AGENT_IE])) {
147
+                // polyfill for btoa/atob for IE friends
148
+                OC_Util::addVendorScript('base64/base64');
149
+                // shim for the davclient.js library
150
+                \OCP\Util::addScript('files/iedavclient');
151
+            }
152
+
153
+            self::$initTemplateEngineFirstRun = false;
154
+        }
155
+
156
+    }
157
+
158
+
159
+    /**
160
+     * find the template with the given name
161
+     * @param string $name of the template file (without suffix)
162
+     *
163
+     * Will select the template file for the selected theme.
164
+     * Checking all the possible locations.
165
+     * @param string $theme
166
+     * @param string $app
167
+     * @return string[]
168
+     */
169
+    protected function findTemplate($theme, $app, $name) {
170
+        // Check if it is a app template or not.
171
+        if( $app !== '' ) {
172
+            $dirs = $this->getAppTemplateDirs($theme, $app, OC::$SERVERROOT, OC_App::getAppPath($app));
173
+        } else {
174
+            $dirs = $this->getCoreTemplateDirs($theme, OC::$SERVERROOT);
175
+        }
176
+        $locator = new \OC\Template\TemplateFileLocator( $dirs );
177
+        $template = $locator->find($name);
178
+        $path = $locator->getPath();
179
+        return array($path, $template);
180
+    }
181
+
182
+    /**
183
+     * Add a custom element to the header
184
+     * @param string $tag tag name of the element
185
+     * @param array $attributes array of attributes for the element
186
+     * @param string $text the text content for the element. If $text is null then the
187
+     * element will be written as empty element. So use "" to get a closing tag.
188
+     */
189
+    public function addHeader($tag, $attributes, $text=null) {
190
+        $this->headers[]= array(
191
+            'tag' => $tag,
192
+            'attributes' => $attributes,
193
+            'text' => $text
194
+        );
195
+    }
196
+
197
+    /**
198
+     * Process the template
199
+     * @return boolean|string
200
+     *
201
+     * This function process the template. If $this->renderAs is set, it
202
+     * will produce a full page.
203
+     */
204
+    public function fetchPage($additionalParams = null) {
205
+        $data = parent::fetchPage($additionalParams);
206
+
207
+        if( $this->renderAs ) {
208
+            $page = new TemplateLayout($this->renderAs, $this->app);
209
+
210
+            if(is_array($additionalParams)) {
211
+                foreach ($additionalParams as $key => $value) {
212
+                    $page->assign($key, $value);
213
+                }
214
+            }
215
+
216
+            // Add custom headers
217
+            $headers = '';
218
+            foreach(OC_Util::$headers as $header) {
219
+                $headers .= '<'.\OCP\Util::sanitizeHTML($header['tag']);
220
+                if ( strcasecmp($header['tag'], 'script') === 0 && in_array('src', array_map('strtolower', array_keys($header['attributes']))) ) {
221
+                    $headers .= ' defer';
222
+                }
223
+                foreach($header['attributes'] as $name=>$value) {
224
+                    $headers .= ' '.\OCP\Util::sanitizeHTML($name).'="'.\OCP\Util::sanitizeHTML($value).'"';
225
+                }
226
+                if ($header['text'] !== null) {
227
+                    $headers .= '>'.\OCP\Util::sanitizeHTML($header['text']).'</'.\OCP\Util::sanitizeHTML($header['tag']).'>';
228
+                } else {
229
+                    $headers .= '/>';
230
+                }
231
+            }
232
+
233
+            $page->assign('headers', $headers);
234
+
235
+            $page->assign('content', $data);
236
+            return $page->fetchPage($additionalParams);
237
+        }
238
+
239
+        return $data;
240
+    }
241
+
242
+    /**
243
+     * Include template
244
+     *
245
+     * @param string $file
246
+     * @param array|null $additionalParams
247
+     * @return string returns content of included template
248
+     *
249
+     * Includes another template. use <?php echo $this->inc('template'); ?> to
250
+     * do this.
251
+     */
252
+    public function inc( $file, $additionalParams = null ) {
253
+        return $this->load($this->path.$file.'.php', $additionalParams);
254
+    }
255
+
256
+    /**
257
+     * Shortcut to print a simple page for users
258
+     * @param string $application The application we render the template for
259
+     * @param string $name Name of the template
260
+     * @param array $parameters Parameters for the template
261
+     * @return boolean|null
262
+     */
263
+    public static function printUserPage( $application, $name, $parameters = array() ) {
264
+        $content = new OC_Template( $application, $name, "user" );
265
+        foreach( $parameters as $key => $value ) {
266
+            $content->assign( $key, $value );
267
+        }
268
+        print $content->printPage();
269
+    }
270
+
271
+    /**
272
+     * Shortcut to print a simple page for admins
273
+     * @param string $application The application we render the template for
274
+     * @param string $name Name of the template
275
+     * @param array $parameters Parameters for the template
276
+     * @return bool
277
+     */
278
+    public static function printAdminPage( $application, $name, $parameters = array() ) {
279
+        $content = new OC_Template( $application, $name, "admin" );
280
+        foreach( $parameters as $key => $value ) {
281
+            $content->assign( $key, $value );
282
+        }
283
+        return $content->printPage();
284
+    }
285
+
286
+    /**
287
+     * Shortcut to print a simple page for guests
288
+     * @param string $application The application we render the template for
289
+     * @param string $name Name of the template
290
+     * @param array|string $parameters Parameters for the template
291
+     * @return bool
292
+     */
293
+    public static function printGuestPage( $application, $name, $parameters = array() ) {
294
+        $content = new OC_Template( $application, $name, "guest" );
295
+        foreach( $parameters as $key => $value ) {
296
+            $content->assign( $key, $value );
297
+        }
298
+        return $content->printPage();
299
+    }
300
+
301
+    /**
302
+     * Print a fatal error page and terminates the script
303
+     * @param string $error_msg The error message to show
304
+     * @param string $hint An optional hint message - needs to be properly escape
305
+     * @suppress PhanAccessMethodInternal
306
+     */
307
+    public static function printErrorPage( $error_msg, $hint = '' ) {
308
+        if (\OC::$server->getAppManager()->isEnabledForUser('theming') && !\OC_App::isAppLoaded('theming')) {
309
+            \OC_App::loadApp('theming');
310
+        }
311
+
312
+
313
+        if ($error_msg === $hint) {
314
+            // If the hint is the same as the message there is no need to display it twice.
315
+            $hint = '';
316
+        }
317
+
318
+        try {
319
+            $content = new \OC_Template( '', 'error', 'error', false );
320
+            $errors = array(array('error' => $error_msg, 'hint' => $hint));
321
+            $content->assign( 'errors', $errors );
322
+            $content->printPage();
323
+        } catch (\Exception $e) {
324
+            $logger = \OC::$server->getLogger();
325
+            $logger->error("$error_msg $hint", ['app' => 'core']);
326
+            $logger->logException($e, ['app' => 'core']);
327
+
328
+            header(self::getHttpProtocol() . ' 500 Internal Server Error');
329
+            header('Content-Type: text/plain; charset=utf-8');
330
+            print("$error_msg $hint");
331
+        }
332
+        die();
333
+    }
334
+
335
+    /**
336
+     * print error page using Exception details
337
+     * @param Exception|Throwable $exception
338
+     * @param bool $fetchPage
339
+     * @return bool|string
340
+     * @suppress PhanAccessMethodInternal
341
+     */
342
+    public static function printExceptionErrorPage($exception, $fetchPage = false) {
343
+        try {
344
+            $request = \OC::$server->getRequest();
345
+            $content = new \OC_Template('', 'exception', 'error', false);
346
+            $content->assign('errorClass', get_class($exception));
347
+            $content->assign('errorMsg', $exception->getMessage());
348
+            $content->assign('errorCode', $exception->getCode());
349
+            $content->assign('file', $exception->getFile());
350
+            $content->assign('line', $exception->getLine());
351
+            $content->assign('trace', $exception->getTraceAsString());
352
+            $content->assign('debugMode', \OC::$server->getSystemConfig()->getValue('debug', false));
353
+            $content->assign('remoteAddr', $request->getRemoteAddress());
354
+            $content->assign('requestID', $request->getId());
355
+            if ($fetchPage) {
356
+                return $content->fetchPage();
357
+            }
358
+            $content->printPage();
359
+        } catch (\Exception $e) {
360
+            $logger = \OC::$server->getLogger();
361
+            $logger->logException($exception, ['app' => 'core']);
362
+            $logger->logException($e, ['app' => 'core']);
363
+
364
+            header(self::getHttpProtocol() . ' 500 Internal Server Error');
365
+            header('Content-Type: text/plain; charset=utf-8');
366
+            print("Internal Server Error\n\n");
367
+            print("The server encountered an internal error and was unable to complete your request.\n");
368
+            print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n");
369
+            print("More details can be found in the server log.\n");
370
+        }
371
+        die();
372
+    }
373
+
374
+    /**
375
+     * This is only here to reduce the dependencies in case of an exception to
376
+     * still be able to print a plain error message.
377
+     *
378
+     * Returns the used HTTP protocol.
379
+     *
380
+     * @return string HTTP protocol. HTTP/2, HTTP/1.1 or HTTP/1.0.
381
+     * @internal Don't use this - use AppFramework\Http\Request->getHttpProtocol instead
382
+     */
383
+    protected static function getHttpProtocol() {
384
+        $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']);
385
+        $validProtocols = [
386
+            'HTTP/1.0',
387
+            'HTTP/1.1',
388
+            'HTTP/2',
389
+        ];
390
+        if(in_array($claimedProtocol, $validProtocols, true)) {
391
+            return $claimedProtocol;
392
+        }
393
+        return 'HTTP/1.1';
394
+    }
395 395
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	 *                         "admin".
72 72
 	 * @param bool $registerCall = true
73 73
 	 */
74
-	public function __construct( $app, $name, $renderAs = "", $registerCall = true ) {
74
+	public function __construct($app, $name, $renderAs = "", $registerCall = true) {
75 75
 		// Read the selected theme from the config file
76 76
 		self::initTemplateEngine($renderAs);
77 77
 
@@ -98,21 +98,21 @@  discard block
 block discarded – undo
98 98
 	 * @param string $renderAs
99 99
 	 */
100 100
 	public static function initTemplateEngine($renderAs) {
101
-		if (self::$initTemplateEngineFirstRun){
101
+		if (self::$initTemplateEngineFirstRun) {
102 102
 
103 103
 			//apps that started before the template initialization can load their own scripts/styles
104 104
 			//so to make sure this scripts/styles here are loaded first we use OC_Util::addScript() with $prepend=true
105 105
 			//meaning the last script/style in this list will be loaded first
106
-			if (\OC::$server->getSystemConfig()->getValue ('installed', false) && $renderAs !== 'error' && !\OCP\Util::needUpgrade()) {
107
-				if (\OC::$server->getConfig ()->getAppValue ( 'core', 'backgroundjobs_mode', 'ajax' ) == 'ajax') {
108
-					OC_Util::addScript ( 'backgroundjobs', null, true );
106
+			if (\OC::$server->getSystemConfig()->getValue('installed', false) && $renderAs !== 'error' && !\OCP\Util::needUpgrade()) {
107
+				if (\OC::$server->getConfig()->getAppValue('core', 'backgroundjobs_mode', 'ajax') == 'ajax') {
108
+					OC_Util::addScript('backgroundjobs', null, true);
109 109
 				}
110 110
 			}
111 111
 
112 112
 			OC_Util::addStyle('css-variables', null, true);
113 113
 			OC_Util::addStyle('server', null, true);
114
-			OC_Util::addStyle('jquery-ui-fixes',null,true);
115
-			OC_Util::addVendorStyle('jquery-ui/themes/base/jquery-ui',null,true);
114
+			OC_Util::addStyle('jquery-ui-fixes', null, true);
115
+			OC_Util::addVendorStyle('jquery-ui/themes/base/jquery-ui', null, true);
116 116
 			OC_Util::addVendorStyle('select2/select2', null, true);
117 117
 			OC_Util::addStyle('jquery.ocdialog');
118 118
 			OC_Util::addTranslations("core", null, true);
@@ -127,13 +127,13 @@  discard block
 block discarded – undo
127 127
 				// Add the stuff we need always
128 128
 				// following logic will import all vendor libraries that are
129 129
 				// specified in core/js/core.json
130
-				$fileContent = file_get_contents(OC::$SERVERROOT . '/core/js/core.json');
131
-				if($fileContent !== false) {
130
+				$fileContent = file_get_contents(OC::$SERVERROOT.'/core/js/core.json');
131
+				if ($fileContent !== false) {
132 132
 					$coreDependencies = json_decode($fileContent, true);
133
-					foreach(array_reverse($coreDependencies['vendor']) as $vendorLibrary) {
133
+					foreach (array_reverse($coreDependencies['vendor']) as $vendorLibrary) {
134 134
 						//remove trailing ".js" as addVendorScript will append it
135 135
 						OC_Util::addVendorScript(
136
-							substr($vendorLibrary, 0, -3),null,true);
136
+							substr($vendorLibrary, 0, -3), null, true);
137 137
 						}
138 138
  				} else {
139 139
 					throw new \Exception('Cannot read core/js/core.json');
@@ -168,12 +168,12 @@  discard block
 block discarded – undo
168 168
 	 */
169 169
 	protected function findTemplate($theme, $app, $name) {
170 170
 		// Check if it is a app template or not.
171
-		if( $app !== '' ) {
171
+		if ($app !== '') {
172 172
 			$dirs = $this->getAppTemplateDirs($theme, $app, OC::$SERVERROOT, OC_App::getAppPath($app));
173 173
 		} else {
174 174
 			$dirs = $this->getCoreTemplateDirs($theme, OC::$SERVERROOT);
175 175
 		}
176
-		$locator = new \OC\Template\TemplateFileLocator( $dirs );
176
+		$locator = new \OC\Template\TemplateFileLocator($dirs);
177 177
 		$template = $locator->find($name);
178 178
 		$path = $locator->getPath();
179 179
 		return array($path, $template);
@@ -186,8 +186,8 @@  discard block
 block discarded – undo
186 186
 	 * @param string $text the text content for the element. If $text is null then the
187 187
 	 * element will be written as empty element. So use "" to get a closing tag.
188 188
 	 */
189
-	public function addHeader($tag, $attributes, $text=null) {
190
-		$this->headers[]= array(
189
+	public function addHeader($tag, $attributes, $text = null) {
190
+		$this->headers[] = array(
191 191
 			'tag' => $tag,
192 192
 			'attributes' => $attributes,
193 193
 			'text' => $text
@@ -204,10 +204,10 @@  discard block
 block discarded – undo
204 204
 	public function fetchPage($additionalParams = null) {
205 205
 		$data = parent::fetchPage($additionalParams);
206 206
 
207
-		if( $this->renderAs ) {
207
+		if ($this->renderAs) {
208 208
 			$page = new TemplateLayout($this->renderAs, $this->app);
209 209
 
210
-			if(is_array($additionalParams)) {
210
+			if (is_array($additionalParams)) {
211 211
 				foreach ($additionalParams as $key => $value) {
212 212
 					$page->assign($key, $value);
213 213
 				}
@@ -215,12 +215,12 @@  discard block
 block discarded – undo
215 215
 
216 216
 			// Add custom headers
217 217
 			$headers = '';
218
-			foreach(OC_Util::$headers as $header) {
218
+			foreach (OC_Util::$headers as $header) {
219 219
 				$headers .= '<'.\OCP\Util::sanitizeHTML($header['tag']);
220
-				if ( strcasecmp($header['tag'], 'script') === 0 && in_array('src', array_map('strtolower', array_keys($header['attributes']))) ) {
220
+				if (strcasecmp($header['tag'], 'script') === 0 && in_array('src', array_map('strtolower', array_keys($header['attributes'])))) {
221 221
 					$headers .= ' defer';
222 222
 				}
223
-				foreach($header['attributes'] as $name=>$value) {
223
+				foreach ($header['attributes'] as $name=>$value) {
224 224
 					$headers .= ' '.\OCP\Util::sanitizeHTML($name).'="'.\OCP\Util::sanitizeHTML($value).'"';
225 225
 				}
226 226
 				if ($header['text'] !== null) {
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 	 * Includes another template. use <?php echo $this->inc('template'); ?> to
250 250
 	 * do this.
251 251
 	 */
252
-	public function inc( $file, $additionalParams = null ) {
252
+	public function inc($file, $additionalParams = null) {
253 253
 		return $this->load($this->path.$file.'.php', $additionalParams);
254 254
 	}
255 255
 
@@ -260,10 +260,10 @@  discard block
 block discarded – undo
260 260
 	 * @param array $parameters Parameters for the template
261 261
 	 * @return boolean|null
262 262
 	 */
263
-	public static function printUserPage( $application, $name, $parameters = array() ) {
264
-		$content = new OC_Template( $application, $name, "user" );
265
-		foreach( $parameters as $key => $value ) {
266
-			$content->assign( $key, $value );
263
+	public static function printUserPage($application, $name, $parameters = array()) {
264
+		$content = new OC_Template($application, $name, "user");
265
+		foreach ($parameters as $key => $value) {
266
+			$content->assign($key, $value);
267 267
 		}
268 268
 		print $content->printPage();
269 269
 	}
@@ -275,10 +275,10 @@  discard block
 block discarded – undo
275 275
 	 * @param array $parameters Parameters for the template
276 276
 	 * @return bool
277 277
 	 */
278
-	public static function printAdminPage( $application, $name, $parameters = array() ) {
279
-		$content = new OC_Template( $application, $name, "admin" );
280
-		foreach( $parameters as $key => $value ) {
281
-			$content->assign( $key, $value );
278
+	public static function printAdminPage($application, $name, $parameters = array()) {
279
+		$content = new OC_Template($application, $name, "admin");
280
+		foreach ($parameters as $key => $value) {
281
+			$content->assign($key, $value);
282 282
 		}
283 283
 		return $content->printPage();
284 284
 	}
@@ -290,10 +290,10 @@  discard block
 block discarded – undo
290 290
 	 * @param array|string $parameters Parameters for the template
291 291
 	 * @return bool
292 292
 	 */
293
-	public static function printGuestPage( $application, $name, $parameters = array() ) {
294
-		$content = new OC_Template( $application, $name, "guest" );
295
-		foreach( $parameters as $key => $value ) {
296
-			$content->assign( $key, $value );
293
+	public static function printGuestPage($application, $name, $parameters = array()) {
294
+		$content = new OC_Template($application, $name, "guest");
295
+		foreach ($parameters as $key => $value) {
296
+			$content->assign($key, $value);
297 297
 		}
298 298
 		return $content->printPage();
299 299
 	}
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 	 * @param string $hint An optional hint message - needs to be properly escape
305 305
 	 * @suppress PhanAccessMethodInternal
306 306
 	 */
307
-	public static function printErrorPage( $error_msg, $hint = '' ) {
307
+	public static function printErrorPage($error_msg, $hint = '') {
308 308
 		if (\OC::$server->getAppManager()->isEnabledForUser('theming') && !\OC_App::isAppLoaded('theming')) {
309 309
 			\OC_App::loadApp('theming');
310 310
 		}
@@ -316,16 +316,16 @@  discard block
 block discarded – undo
316 316
 		}
317 317
 
318 318
 		try {
319
-			$content = new \OC_Template( '', 'error', 'error', false );
319
+			$content = new \OC_Template('', 'error', 'error', false);
320 320
 			$errors = array(array('error' => $error_msg, 'hint' => $hint));
321
-			$content->assign( 'errors', $errors );
321
+			$content->assign('errors', $errors);
322 322
 			$content->printPage();
323 323
 		} catch (\Exception $e) {
324 324
 			$logger = \OC::$server->getLogger();
325 325
 			$logger->error("$error_msg $hint", ['app' => 'core']);
326 326
 			$logger->logException($e, ['app' => 'core']);
327 327
 
328
-			header(self::getHttpProtocol() . ' 500 Internal Server Error');
328
+			header(self::getHttpProtocol().' 500 Internal Server Error');
329 329
 			header('Content-Type: text/plain; charset=utf-8');
330 330
 			print("$error_msg $hint");
331 331
 		}
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
 			$logger->logException($exception, ['app' => 'core']);
362 362
 			$logger->logException($e, ['app' => 'core']);
363 363
 
364
-			header(self::getHttpProtocol() . ' 500 Internal Server Error');
364
+			header(self::getHttpProtocol().' 500 Internal Server Error');
365 365
 			header('Content-Type: text/plain; charset=utf-8');
366 366
 			print("Internal Server Error\n\n");
367 367
 			print("The server encountered an internal error and was unable to complete your request.\n");
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
 			'HTTP/1.1',
388 388
 			'HTTP/2',
389 389
 		];
390
-		if(in_array($claimedProtocol, $validProtocols, true)) {
390
+		if (in_array($claimedProtocol, $validProtocols, true)) {
391 391
 			return $claimedProtocol;
392 392
 		}
393 393
 		return 'HTTP/1.1';
Please login to merge, or discard this patch.
apps/theming/lib/Controller/ThemingController.php 1 patch
Indentation   +353 added lines, -353 removed lines patch added patch discarded remove patch
@@ -62,352 +62,352 @@  discard block
 block discarded – undo
62 62
  * @package OCA\Theming\Controller
63 63
  */
64 64
 class ThemingController extends Controller {
65
-	/** @var ThemingDefaults */
66
-	private $themingDefaults;
67
-	/** @var Util */
68
-	private $util;
69
-	/** @var IL10N */
70
-	private $l10n;
71
-	/** @var IConfig */
72
-	private $config;
73
-	/** @var ITempManager */
74
-	private $tempManager;
75
-	/** @var IAppData */
76
-	private $appData;
77
-	/** @var SCSSCacher */
78
-	private $scssCacher;
79
-	/** @var IURLGenerator */
80
-	private $urlGenerator;
81
-	/** @var IAppManager */
82
-	private $appManager;
83
-	/** @var ImageManager */
84
-	private $imageManager;
65
+    /** @var ThemingDefaults */
66
+    private $themingDefaults;
67
+    /** @var Util */
68
+    private $util;
69
+    /** @var IL10N */
70
+    private $l10n;
71
+    /** @var IConfig */
72
+    private $config;
73
+    /** @var ITempManager */
74
+    private $tempManager;
75
+    /** @var IAppData */
76
+    private $appData;
77
+    /** @var SCSSCacher */
78
+    private $scssCacher;
79
+    /** @var IURLGenerator */
80
+    private $urlGenerator;
81
+    /** @var IAppManager */
82
+    private $appManager;
83
+    /** @var ImageManager */
84
+    private $imageManager;
85 85
 
86
-	/**
87
-	 * ThemingController constructor.
88
-	 *
89
-	 * @param string $appName
90
-	 * @param IRequest $request
91
-	 * @param IConfig $config
92
-	 * @param ThemingDefaults $themingDefaults
93
-	 * @param Util $util
94
-	 * @param IL10N $l
95
-	 * @param ITempManager $tempManager
96
-	 * @param IAppData $appData
97
-	 * @param SCSSCacher $scssCacher
98
-	 * @param IURLGenerator $urlGenerator
99
-	 * @param IAppManager $appManager
100
-	 * @param ImageManager $imageManager
101
-	 */
102
-	public function __construct(
103
-		$appName,
104
-		IRequest $request,
105
-		IConfig $config,
106
-		ThemingDefaults $themingDefaults,
107
-		Util $util,
108
-		IL10N $l,
109
-		ITempManager $tempManager,
110
-		IAppData $appData,
111
-		SCSSCacher $scssCacher,
112
-		IURLGenerator $urlGenerator,
113
-		IAppManager $appManager,
114
-		ImageManager $imageManager
115
-	) {
116
-		parent::__construct($appName, $request);
86
+    /**
87
+     * ThemingController constructor.
88
+     *
89
+     * @param string $appName
90
+     * @param IRequest $request
91
+     * @param IConfig $config
92
+     * @param ThemingDefaults $themingDefaults
93
+     * @param Util $util
94
+     * @param IL10N $l
95
+     * @param ITempManager $tempManager
96
+     * @param IAppData $appData
97
+     * @param SCSSCacher $scssCacher
98
+     * @param IURLGenerator $urlGenerator
99
+     * @param IAppManager $appManager
100
+     * @param ImageManager $imageManager
101
+     */
102
+    public function __construct(
103
+        $appName,
104
+        IRequest $request,
105
+        IConfig $config,
106
+        ThemingDefaults $themingDefaults,
107
+        Util $util,
108
+        IL10N $l,
109
+        ITempManager $tempManager,
110
+        IAppData $appData,
111
+        SCSSCacher $scssCacher,
112
+        IURLGenerator $urlGenerator,
113
+        IAppManager $appManager,
114
+        ImageManager $imageManager
115
+    ) {
116
+        parent::__construct($appName, $request);
117 117
 
118
-		$this->themingDefaults = $themingDefaults;
119
-		$this->util = $util;
120
-		$this->l10n = $l;
121
-		$this->config = $config;
122
-		$this->tempManager = $tempManager;
123
-		$this->appData = $appData;
124
-		$this->scssCacher = $scssCacher;
125
-		$this->urlGenerator = $urlGenerator;
126
-		$this->appManager = $appManager;
127
-		$this->imageManager = $imageManager;
128
-	}
118
+        $this->themingDefaults = $themingDefaults;
119
+        $this->util = $util;
120
+        $this->l10n = $l;
121
+        $this->config = $config;
122
+        $this->tempManager = $tempManager;
123
+        $this->appData = $appData;
124
+        $this->scssCacher = $scssCacher;
125
+        $this->urlGenerator = $urlGenerator;
126
+        $this->appManager = $appManager;
127
+        $this->imageManager = $imageManager;
128
+    }
129 129
 
130
-	/**
131
-	 * @param string $setting
132
-	 * @param string $value
133
-	 * @return DataResponse
134
-	 * @throws NotPermittedException
135
-	 */
136
-	public function updateStylesheet($setting, $value) {
137
-		$value = trim($value);
138
-		switch ($setting) {
139
-			case 'name':
140
-				if (strlen($value) > 250) {
141
-					return new DataResponse([
142
-						'data' => [
143
-							'message' => $this->l10n->t('The given name is too long'),
144
-						],
145
-						'status' => 'error'
146
-					]);
147
-				}
148
-				break;
149
-			case 'url':
150
-				if (strlen($value) > 500) {
151
-					return new DataResponse([
152
-						'data' => [
153
-							'message' => $this->l10n->t('The given web address is too long'),
154
-						],
155
-						'status' => 'error'
156
-					]);
157
-				}
158
-				break;
159
-			case 'imprintUrl':
160
-				if (strlen($value) > 500) {
161
-					return new DataResponse([
162
-						'data' => [
163
-							'message' => $this->l10n->t('The given legal notice address is too long'),
164
-						],
165
-						'status' => 'error'
166
-					]);
167
-				}
168
-				break;
169
-			case 'privacyUrl':
170
-				if (strlen($value) > 500) {
171
-					return new DataResponse([
172
-						'data' => [
173
-							'message' => $this->l10n->t('The given privacy policy address is too long'),
174
-						],
175
-						'status' => 'error'
176
-					]);
177
-				}
178
-				break;
179
-			case 'slogan':
180
-				if (strlen($value) > 500) {
181
-					return new DataResponse([
182
-						'data' => [
183
-							'message' => $this->l10n->t('The given slogan is too long'),
184
-						],
185
-						'status' => 'error'
186
-					]);
187
-				}
188
-				break;
189
-			case 'color':
190
-				if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) {
191
-					return new DataResponse([
192
-						'data' => [
193
-							'message' => $this->l10n->t('The given color is invalid'),
194
-						],
195
-						'status' => 'error'
196
-					]);
197
-				}
198
-				break;
199
-		}
130
+    /**
131
+     * @param string $setting
132
+     * @param string $value
133
+     * @return DataResponse
134
+     * @throws NotPermittedException
135
+     */
136
+    public function updateStylesheet($setting, $value) {
137
+        $value = trim($value);
138
+        switch ($setting) {
139
+            case 'name':
140
+                if (strlen($value) > 250) {
141
+                    return new DataResponse([
142
+                        'data' => [
143
+                            'message' => $this->l10n->t('The given name is too long'),
144
+                        ],
145
+                        'status' => 'error'
146
+                    ]);
147
+                }
148
+                break;
149
+            case 'url':
150
+                if (strlen($value) > 500) {
151
+                    return new DataResponse([
152
+                        'data' => [
153
+                            'message' => $this->l10n->t('The given web address is too long'),
154
+                        ],
155
+                        'status' => 'error'
156
+                    ]);
157
+                }
158
+                break;
159
+            case 'imprintUrl':
160
+                if (strlen($value) > 500) {
161
+                    return new DataResponse([
162
+                        'data' => [
163
+                            'message' => $this->l10n->t('The given legal notice address is too long'),
164
+                        ],
165
+                        'status' => 'error'
166
+                    ]);
167
+                }
168
+                break;
169
+            case 'privacyUrl':
170
+                if (strlen($value) > 500) {
171
+                    return new DataResponse([
172
+                        'data' => [
173
+                            'message' => $this->l10n->t('The given privacy policy address is too long'),
174
+                        ],
175
+                        'status' => 'error'
176
+                    ]);
177
+                }
178
+                break;
179
+            case 'slogan':
180
+                if (strlen($value) > 500) {
181
+                    return new DataResponse([
182
+                        'data' => [
183
+                            'message' => $this->l10n->t('The given slogan is too long'),
184
+                        ],
185
+                        'status' => 'error'
186
+                    ]);
187
+                }
188
+                break;
189
+            case 'color':
190
+                if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) {
191
+                    return new DataResponse([
192
+                        'data' => [
193
+                            'message' => $this->l10n->t('The given color is invalid'),
194
+                        ],
195
+                        'status' => 'error'
196
+                    ]);
197
+                }
198
+                break;
199
+        }
200 200
 
201
-		$this->themingDefaults->set($setting, $value);
201
+        $this->themingDefaults->set($setting, $value);
202 202
 
203
-		// reprocess server scss for preview
204
-		$cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/css-variables.scss', 'core');
203
+        // reprocess server scss for preview
204
+        $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/css-variables.scss', 'core');
205 205
 
206
-		return new DataResponse(
207
-			[
208
-				'data' =>
209
-					[
210
-						'message' => $this->l10n->t('Saved'),
211
-						'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/css-variables.scss'))
212
-					],
213
-				'status' => 'success'
214
-			]
215
-		);
216
-	}
206
+        return new DataResponse(
207
+            [
208
+                'data' =>
209
+                    [
210
+                        'message' => $this->l10n->t('Saved'),
211
+                        'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/css-variables.scss'))
212
+                    ],
213
+                'status' => 'success'
214
+            ]
215
+        );
216
+    }
217 217
 
218
-	/**
219
-	 * @return DataResponse
220
-	 * @throws NotPermittedException
221
-	 */
222
-	public function uploadImage(): DataResponse {
223
-		// logo / background
224
-		// new: favicon logo-header
225
-		//
226
-		$key = $this->request->getParam('key');
227
-		$image = $this->request->getUploadedFile('image');
228
-		$error = null;
229
-		$phpFileUploadErrors = [
230
-			UPLOAD_ERR_OK => $this->l10n->t('The file was uploaded'),
231
-			UPLOAD_ERR_INI_SIZE => $this->l10n->t('The uploaded file exceeds the upload_max_filesize directive in php.ini'),
232
-			UPLOAD_ERR_FORM_SIZE => $this->l10n->t('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'),
233
-			UPLOAD_ERR_PARTIAL => $this->l10n->t('The file was only partially uploaded'),
234
-			UPLOAD_ERR_NO_FILE => $this->l10n->t('No file was uploaded'),
235
-			UPLOAD_ERR_NO_TMP_DIR => $this->l10n->t('Missing a temporary folder'),
236
-			UPLOAD_ERR_CANT_WRITE => $this->l10n->t('Could not write file to disk'),
237
-			UPLOAD_ERR_EXTENSION => $this->l10n->t('A PHP extension stopped the file upload'),
238
-		];
239
-		if (empty($image)) {
240
-			$error = $this->l10n->t('No file uploaded');
241
-		}
242
-		if (!empty($image) && array_key_exists('error', $image) && $image['error'] !== UPLOAD_ERR_OK) {
243
-			$error = $phpFileUploadErrors[$image['error']];
244
-		}
218
+    /**
219
+     * @return DataResponse
220
+     * @throws NotPermittedException
221
+     */
222
+    public function uploadImage(): DataResponse {
223
+        // logo / background
224
+        // new: favicon logo-header
225
+        //
226
+        $key = $this->request->getParam('key');
227
+        $image = $this->request->getUploadedFile('image');
228
+        $error = null;
229
+        $phpFileUploadErrors = [
230
+            UPLOAD_ERR_OK => $this->l10n->t('The file was uploaded'),
231
+            UPLOAD_ERR_INI_SIZE => $this->l10n->t('The uploaded file exceeds the upload_max_filesize directive in php.ini'),
232
+            UPLOAD_ERR_FORM_SIZE => $this->l10n->t('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'),
233
+            UPLOAD_ERR_PARTIAL => $this->l10n->t('The file was only partially uploaded'),
234
+            UPLOAD_ERR_NO_FILE => $this->l10n->t('No file was uploaded'),
235
+            UPLOAD_ERR_NO_TMP_DIR => $this->l10n->t('Missing a temporary folder'),
236
+            UPLOAD_ERR_CANT_WRITE => $this->l10n->t('Could not write file to disk'),
237
+            UPLOAD_ERR_EXTENSION => $this->l10n->t('A PHP extension stopped the file upload'),
238
+        ];
239
+        if (empty($image)) {
240
+            $error = $this->l10n->t('No file uploaded');
241
+        }
242
+        if (!empty($image) && array_key_exists('error', $image) && $image['error'] !== UPLOAD_ERR_OK) {
243
+            $error = $phpFileUploadErrors[$image['error']];
244
+        }
245 245
 
246
-		if ($error !== null) {
247
-			return new DataResponse(
248
-				[
249
-					'data' => [
250
-						'message' => $error
251
-					],
252
-					'status' => 'failure',
253
-				],
254
-				Http::STATUS_UNPROCESSABLE_ENTITY
255
-			);
256
-		}
246
+        if ($error !== null) {
247
+            return new DataResponse(
248
+                [
249
+                    'data' => [
250
+                        'message' => $error
251
+                    ],
252
+                    'status' => 'failure',
253
+                ],
254
+                Http::STATUS_UNPROCESSABLE_ENTITY
255
+            );
256
+        }
257 257
 
258
-		$name = '';
259
-		try {
260
-			$folder = $this->appData->getFolder('images');
261
-		} catch (NotFoundException $e) {
262
-			$folder = $this->appData->newFolder('images');
263
-		}
258
+        $name = '';
259
+        try {
260
+            $folder = $this->appData->getFolder('images');
261
+        } catch (NotFoundException $e) {
262
+            $folder = $this->appData->newFolder('images');
263
+        }
264 264
 
265
-		$target = $folder->newFile($key);
266
-		$supportedFormats = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml', 'image/svg'];
267
-		$detectedMimeType = mime_content_type($image['tmp_name']);
268
-		if (!in_array($image['type'], $supportedFormats) || !in_array($detectedMimeType, $supportedFormats)) {
269
-			return new DataResponse(
270
-				[
271
-					'data' => [
272
-						'message' => $this->l10n->t('Unsupported image type'),
273
-					],
274
-					'status' => 'failure',
275
-				],
276
-				Http::STATUS_UNPROCESSABLE_ENTITY
277
-			);
278
-		}
265
+        $target = $folder->newFile($key);
266
+        $supportedFormats = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml', 'image/svg'];
267
+        $detectedMimeType = mime_content_type($image['tmp_name']);
268
+        if (!in_array($image['type'], $supportedFormats) || !in_array($detectedMimeType, $supportedFormats)) {
269
+            return new DataResponse(
270
+                [
271
+                    'data' => [
272
+                        'message' => $this->l10n->t('Unsupported image type'),
273
+                    ],
274
+                    'status' => 'failure',
275
+                ],
276
+                Http::STATUS_UNPROCESSABLE_ENTITY
277
+            );
278
+        }
279 279
 
280
-		$resizeKeys = ['background'];
281
-		if (in_array($key, $resizeKeys, true)) {
282
-			// Optimize the image since some people may upload images that will be
283
-			// either to big or are not progressive rendering.
284
-			$newImage = @imagecreatefromstring(file_get_contents($image['tmp_name'], 'r'));
280
+        $resizeKeys = ['background'];
281
+        if (in_array($key, $resizeKeys, true)) {
282
+            // Optimize the image since some people may upload images that will be
283
+            // either to big or are not progressive rendering.
284
+            $newImage = @imagecreatefromstring(file_get_contents($image['tmp_name'], 'r'));
285 285
 
286
-			$tmpFile = $this->tempManager->getTemporaryFile();
287
-			$newWidth = imagesx($newImage) < 4096 ? imagesx($newImage) : 4096;
288
-			$newHeight = imagesy($newImage) / (imagesx($newImage) / $newWidth);
289
-			$outputImage = imagescale($newImage, $newWidth, $newHeight);
286
+            $tmpFile = $this->tempManager->getTemporaryFile();
287
+            $newWidth = imagesx($newImage) < 4096 ? imagesx($newImage) : 4096;
288
+            $newHeight = imagesy($newImage) / (imagesx($newImage) / $newWidth);
289
+            $outputImage = imagescale($newImage, $newWidth, $newHeight);
290 290
 
291
-			imageinterlace($outputImage, 1);
292
-			imagejpeg($outputImage, $tmpFile, 75);
293
-			imagedestroy($outputImage);
291
+            imageinterlace($outputImage, 1);
292
+            imagejpeg($outputImage, $tmpFile, 75);
293
+            imagedestroy($outputImage);
294 294
 
295
-			$target->putContent(file_get_contents($tmpFile, 'r'));
296
-		} else {
297
-			$target->putContent(file_get_contents($image['tmp_name'], 'r'));
298
-		}
299
-		$name = $image['name'];
295
+            $target->putContent(file_get_contents($tmpFile, 'r'));
296
+        } else {
297
+            $target->putContent(file_get_contents($image['tmp_name'], 'r'));
298
+        }
299
+        $name = $image['name'];
300 300
 
301
-		$this->themingDefaults->set($key.'Mime', $image['type']);
301
+        $this->themingDefaults->set($key.'Mime', $image['type']);
302 302
 
303
-		$cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/css-variables.scss', 'core');
303
+        $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/css-variables.scss', 'core');
304 304
 
305
-		return new DataResponse(
306
-			[
307
-				'data' =>
308
-					[
309
-						'name' => $name,
310
-						'url' => $this->imageManager->getImageUrl($key),
311
-						'message' => $this->l10n->t('Saved'),
312
-						'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/css-variables.scss'))
313
-					],
314
-				'status' => 'success'
315
-			]
316
-		);
317
-	}
305
+        return new DataResponse(
306
+            [
307
+                'data' =>
308
+                    [
309
+                        'name' => $name,
310
+                        'url' => $this->imageManager->getImageUrl($key),
311
+                        'message' => $this->l10n->t('Saved'),
312
+                        'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/css-variables.scss'))
313
+                    ],
314
+                'status' => 'success'
315
+            ]
316
+        );
317
+    }
318 318
 
319
-	/**
320
-	 * Revert setting to default value
321
-	 *
322
-	 * @param string $setting setting which should be reverted
323
-	 * @return DataResponse
324
-	 * @throws NotPermittedException
325
-	 */
326
-	public function undo(string $setting): DataResponse {
327
-		$value = $this->themingDefaults->undo($setting);
328
-		// reprocess server scss for preview
329
-		$cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/css-variables.scss', 'core');
319
+    /**
320
+     * Revert setting to default value
321
+     *
322
+     * @param string $setting setting which should be reverted
323
+     * @return DataResponse
324
+     * @throws NotPermittedException
325
+     */
326
+    public function undo(string $setting): DataResponse {
327
+        $value = $this->themingDefaults->undo($setting);
328
+        // reprocess server scss for preview
329
+        $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/css-variables.scss', 'core');
330 330
 
331
-		if (strpos($setting, 'Mime') !== -1) {
332
-			$imageKey = str_replace('Mime', '', $setting);
333
-			$this->imageManager->delete($imageKey);
334
-		}
331
+        if (strpos($setting, 'Mime') !== -1) {
332
+            $imageKey = str_replace('Mime', '', $setting);
333
+            $this->imageManager->delete($imageKey);
334
+        }
335 335
 
336
-		return new DataResponse(
337
-			[
338
-				'data' =>
339
-					[
340
-						'value' => $value,
341
-						'message' => $this->l10n->t('Saved'),
342
-						'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/css-variables.scss'))
343
-					],
344
-				'status' => 'success'
345
-			]
346
-		);
347
-	}
336
+        return new DataResponse(
337
+            [
338
+                'data' =>
339
+                    [
340
+                        'value' => $value,
341
+                        'message' => $this->l10n->t('Saved'),
342
+                        'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/css-variables.scss'))
343
+                    ],
344
+                'status' => 'success'
345
+            ]
346
+        );
347
+    }
348 348
 
349
-	/**
350
-	 * @PublicPage
351
-	 * @NoCSRFRequired
352
-	 *
353
-	 * @param string $key
354
-	 * @return FileDisplayResponse|NotFoundResponse
355
-	 * @throws \Exception
356
-	 */
357
-	public function getImage(string $key) {
358
-		try {
359
-			$file = $this->imageManager->getImage($key);
360
-		} catch (NotFoundException $e) {
361
-			return new NotFoundResponse();
362
-		}
349
+    /**
350
+     * @PublicPage
351
+     * @NoCSRFRequired
352
+     *
353
+     * @param string $key
354
+     * @return FileDisplayResponse|NotFoundResponse
355
+     * @throws \Exception
356
+     */
357
+    public function getImage(string $key) {
358
+        try {
359
+            $file = $this->imageManager->getImage($key);
360
+        } catch (NotFoundException $e) {
361
+            return new NotFoundResponse();
362
+        }
363 363
 
364
-		$response = new FileDisplayResponse($file);
365
-		$response->cacheFor(3600);
366
-		$response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key . 'Mime', ''));
367
-		$response->addHeader('Content-Disposition', 'attachment; filename="' . $key . '"');
368
-		return $response;
369
-	}
364
+        $response = new FileDisplayResponse($file);
365
+        $response->cacheFor(3600);
366
+        $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key . 'Mime', ''));
367
+        $response->addHeader('Content-Disposition', 'attachment; filename="' . $key . '"');
368
+        return $response;
369
+    }
370 370
 
371
-	/**
372
-	 * @NoCSRFRequired
373
-	 * @PublicPage
374
-	 *
375
-	 * @return FileDisplayResponse|NotFoundResponse
376
-	 * @throws NotPermittedException
377
-	 * @throws \Exception
378
-	 * @throws \OCP\App\AppPathNotFoundException
379
-	 */
380
-	public function getStylesheet() {
381
-		$appPath = $this->appManager->getAppPath('theming');
371
+    /**
372
+     * @NoCSRFRequired
373
+     * @PublicPage
374
+     *
375
+     * @return FileDisplayResponse|NotFoundResponse
376
+     * @throws NotPermittedException
377
+     * @throws \Exception
378
+     * @throws \OCP\App\AppPathNotFoundException
379
+     */
380
+    public function getStylesheet() {
381
+        $appPath = $this->appManager->getAppPath('theming');
382 382
 
383
-		/* SCSSCacher is required here
383
+        /* SCSSCacher is required here
384 384
 		 * We cannot rely on automatic caching done by \OC_Util::addStyle,
385 385
 		 * since we need to add the cacheBuster value to the url
386 386
 		 */
387
-		$cssCached = $this->scssCacher->process($appPath, 'css/theming.scss', 'theming');
388
-		if(!$cssCached) {
389
-			return new NotFoundResponse();
390
-		}
387
+        $cssCached = $this->scssCacher->process($appPath, 'css/theming.scss', 'theming');
388
+        if(!$cssCached) {
389
+            return new NotFoundResponse();
390
+        }
391 391
 
392
-		try {
393
-			$cssFile = $this->scssCacher->getCachedCSS('theming', 'theming.css');
394
-			$response = new FileDisplayResponse($cssFile, Http::STATUS_OK, ['Content-Type' => 'text/css']);
395
-			$response->cacheFor(86400);
396
-			return $response;
397
-		} catch (NotFoundException $e) {
398
-			return new NotFoundResponse();
399
-		}
400
-	}
392
+        try {
393
+            $cssFile = $this->scssCacher->getCachedCSS('theming', 'theming.css');
394
+            $response = new FileDisplayResponse($cssFile, Http::STATUS_OK, ['Content-Type' => 'text/css']);
395
+            $response->cacheFor(86400);
396
+            return $response;
397
+        } catch (NotFoundException $e) {
398
+            return new NotFoundResponse();
399
+        }
400
+    }
401 401
 
402
-	/**
403
-	 * @NoCSRFRequired
404
-	 * @PublicPage
405
-	 *
406
-	 * @return DataDownloadResponse
407
-	 */
408
-	public function getJavascript() {
409
-		$cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
410
-		$responseJS = '(function() {
402
+    /**
403
+     * @NoCSRFRequired
404
+     * @PublicPage
405
+     *
406
+     * @return DataDownloadResponse
407
+     */
408
+    public function getJavascript() {
409
+        $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
410
+        $responseJS = '(function() {
411 411
 	OCA.Theming = {
412 412
 		name: ' . json_encode($this->themingDefaults->getName()) . ',
413 413
 		url: ' . json_encode($this->themingDefaults->getBaseUrl()) . ',
@@ -419,41 +419,41 @@  discard block
 block discarded – undo
419 419
 		cacheBuster: ' . json_encode($cacheBusterValue) . '
420 420
 	};
421 421
 })();';
422
-		$response = new DataDownloadResponse($responseJS, 'javascript', 'text/javascript');
423
-		$response->cacheFor(3600);
424
-		return $response;
425
-	}
422
+        $response = new DataDownloadResponse($responseJS, 'javascript', 'text/javascript');
423
+        $response->cacheFor(3600);
424
+        return $response;
425
+    }
426 426
 
427
-	/**
428
-	 * @NoCSRFRequired
429
-	 * @PublicPage
430
-	 *
431
-	 * @return Http\JSONResponse
432
-	 */
433
-	public function getManifest($app) {
434
-		$cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
435
-		$responseJS = [
436
-			'name' => $this->themingDefaults->getName(),
437
-			'start_url' => $this->urlGenerator->getBaseUrl(),
438
-			'icons' =>
439
-				[
440
-					[
441
-						'src' => $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon',
442
-								['app' => $app]) . '?v=' . $cacheBusterValue,
443
-						'type'=> 'image/png',
444
-						'sizes'=> '128x128'
445
-					],
446
-					[
447
-						'src' => $this->urlGenerator->linkToRoute('theming.Icon.getFavicon',
448
-								['app' => $app]) . '?v=' . $cacheBusterValue,
449
-						'type' => 'image/svg+xml',
450
-						'sizes' => '16x16'
451
-					]
452
-				],
453
-			'display' => 'standalone'
454
-		];
455
-		$response = new Http\JSONResponse($responseJS);
456
-		$response->cacheFor(3600);
457
-		return $response;
458
-	}
427
+    /**
428
+     * @NoCSRFRequired
429
+     * @PublicPage
430
+     *
431
+     * @return Http\JSONResponse
432
+     */
433
+    public function getManifest($app) {
434
+        $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
435
+        $responseJS = [
436
+            'name' => $this->themingDefaults->getName(),
437
+            'start_url' => $this->urlGenerator->getBaseUrl(),
438
+            'icons' =>
439
+                [
440
+                    [
441
+                        'src' => $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon',
442
+                                ['app' => $app]) . '?v=' . $cacheBusterValue,
443
+                        'type'=> 'image/png',
444
+                        'sizes'=> '128x128'
445
+                    ],
446
+                    [
447
+                        'src' => $this->urlGenerator->linkToRoute('theming.Icon.getFavicon',
448
+                                ['app' => $app]) . '?v=' . $cacheBusterValue,
449
+                        'type' => 'image/svg+xml',
450
+                        'sizes' => '16x16'
451
+                    ]
452
+                ],
453
+            'display' => 'standalone'
454
+        ];
455
+        $response = new Http\JSONResponse($responseJS);
456
+        $response->cacheFor(3600);
457
+        return $response;
458
+    }
459 459
 }
Please login to merge, or discard this patch.