Completed
Pull Request — master (#4617)
by Julius
14:00
created
apps/theming/lib/Controller/ThemingController.php 2 patches
Indentation   +325 added lines, -325 removed lines patch added patch discarded remove patch
@@ -57,350 +57,350 @@  discard block
 block discarded – undo
57 57
  * @package OCA\Theming\Controller
58 58
  */
59 59
 class ThemingController extends Controller {
60
-	/** @var ThemingDefaults */
61
-	private $themingDefaults;
62
-	/** @var Util */
63
-	private $util;
64
-	/** @var ITimeFactory */
65
-	private $timeFactory;
66
-	/** @var IL10N */
67
-	private $l10n;
68
-	/** @var IConfig */
69
-	private $config;
70
-	/** @var ITempManager */
71
-	private $tempManager;
72
-	/** @var IAppData */
73
-	private $appData;
74
-	/** @var SCSSCacher */
75
-	private $scssCacher;
60
+    /** @var ThemingDefaults */
61
+    private $themingDefaults;
62
+    /** @var Util */
63
+    private $util;
64
+    /** @var ITimeFactory */
65
+    private $timeFactory;
66
+    /** @var IL10N */
67
+    private $l10n;
68
+    /** @var IConfig */
69
+    private $config;
70
+    /** @var ITempManager */
71
+    private $tempManager;
72
+    /** @var IAppData */
73
+    private $appData;
74
+    /** @var SCSSCacher */
75
+    private $scssCacher;
76 76
 
77
-	/**
78
-	 * ThemingController constructor.
79
-	 *
80
-	 * @param string $appName
81
-	 * @param IRequest $request
82
-	 * @param IConfig $config
83
-	 * @param ThemingDefaults $themingDefaults
84
-	 * @param Util $util
85
-	 * @param ITimeFactory $timeFactory
86
-	 * @param IL10N $l
87
-	 * @param ITempManager $tempManager
88
-	 * @param IAppData $appData
89
-	 * @param SCSSCacher $scssCacher
90
-	 */
91
-	public function __construct(
92
-		$appName,
93
-		IRequest $request,
94
-		IConfig $config,
95
-		ThemingDefaults $themingDefaults,
96
-		Util $util,
97
-		ITimeFactory $timeFactory,
98
-		IL10N $l,
99
-		ITempManager $tempManager,
100
-		IAppData $appData,
101
-		SCSSCacher $scssCacher
102
-	) {
103
-		parent::__construct($appName, $request);
77
+    /**
78
+     * ThemingController constructor.
79
+     *
80
+     * @param string $appName
81
+     * @param IRequest $request
82
+     * @param IConfig $config
83
+     * @param ThemingDefaults $themingDefaults
84
+     * @param Util $util
85
+     * @param ITimeFactory $timeFactory
86
+     * @param IL10N $l
87
+     * @param ITempManager $tempManager
88
+     * @param IAppData $appData
89
+     * @param SCSSCacher $scssCacher
90
+     */
91
+    public function __construct(
92
+        $appName,
93
+        IRequest $request,
94
+        IConfig $config,
95
+        ThemingDefaults $themingDefaults,
96
+        Util $util,
97
+        ITimeFactory $timeFactory,
98
+        IL10N $l,
99
+        ITempManager $tempManager,
100
+        IAppData $appData,
101
+        SCSSCacher $scssCacher
102
+    ) {
103
+        parent::__construct($appName, $request);
104 104
 
105
-		$this->themingDefaults = $themingDefaults;
106
-		$this->util = $util;
107
-		$this->timeFactory = $timeFactory;
108
-		$this->l10n = $l;
109
-		$this->config = $config;
110
-		$this->tempManager = $tempManager;
111
-		$this->appData = $appData;
112
-		$this->scssCacher = $scssCacher;
113
-	}
105
+        $this->themingDefaults = $themingDefaults;
106
+        $this->util = $util;
107
+        $this->timeFactory = $timeFactory;
108
+        $this->l10n = $l;
109
+        $this->config = $config;
110
+        $this->tempManager = $tempManager;
111
+        $this->appData = $appData;
112
+        $this->scssCacher = $scssCacher;
113
+    }
114 114
 
115
-	/**
116
-	 * @param string $setting
117
-	 * @param string $value
118
-	 * @return DataResponse
119
-	 * @internal param string $color
120
-	 */
121
-	public function updateStylesheet($setting, $value) {
122
-		$value = trim($value);
123
-		switch ($setting) {
124
-			case 'name':
125
-				if (strlen($value) > 250) {
126
-					return new DataResponse([
127
-						'data' => [
128
-							'message' => $this->l10n->t('The given name is too long'),
129
-						],
130
-						'status' => 'error'
131
-					]);
132
-				}
133
-				break;
134
-			case 'url':
135
-				if (strlen($value) > 500) {
136
-					return new DataResponse([
137
-						'data' => [
138
-							'message' => $this->l10n->t('The given web address is too long'),
139
-						],
140
-						'status' => 'error'
141
-					]);
142
-				}
143
-				break;
144
-			case 'slogan':
145
-				if (strlen($value) > 500) {
146
-					return new DataResponse([
147
-						'data' => [
148
-							'message' => $this->l10n->t('The given slogan is too long'),
149
-						],
150
-						'status' => 'error'
151
-					]);
152
-				}
153
-				break;
154
-			case 'color':
155
-				if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) {
156
-					return new DataResponse([
157
-						'data' => [
158
-							'message' => $this->l10n->t('The given color is invalid'),
159
-						],
160
-						'status' => 'error'
161
-					]);
162
-				}
163
-				break;
164
-		}
115
+    /**
116
+     * @param string $setting
117
+     * @param string $value
118
+     * @return DataResponse
119
+     * @internal param string $color
120
+     */
121
+    public function updateStylesheet($setting, $value) {
122
+        $value = trim($value);
123
+        switch ($setting) {
124
+            case 'name':
125
+                if (strlen($value) > 250) {
126
+                    return new DataResponse([
127
+                        'data' => [
128
+                            'message' => $this->l10n->t('The given name is too long'),
129
+                        ],
130
+                        'status' => 'error'
131
+                    ]);
132
+                }
133
+                break;
134
+            case 'url':
135
+                if (strlen($value) > 500) {
136
+                    return new DataResponse([
137
+                        'data' => [
138
+                            'message' => $this->l10n->t('The given web address is too long'),
139
+                        ],
140
+                        'status' => 'error'
141
+                    ]);
142
+                }
143
+                break;
144
+            case 'slogan':
145
+                if (strlen($value) > 500) {
146
+                    return new DataResponse([
147
+                        'data' => [
148
+                            'message' => $this->l10n->t('The given slogan is too long'),
149
+                        ],
150
+                        'status' => 'error'
151
+                    ]);
152
+                }
153
+                break;
154
+            case 'color':
155
+                if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) {
156
+                    return new DataResponse([
157
+                        'data' => [
158
+                            'message' => $this->l10n->t('The given color is invalid'),
159
+                        ],
160
+                        'status' => 'error'
161
+                    ]);
162
+                }
163
+                break;
164
+        }
165 165
 
166
-		$this->themingDefaults->set($setting, $value);
166
+        $this->themingDefaults->set($setting, $value);
167 167
 
168
-		// reprocess server scss for preview
169
-		$cssCached = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/server.scss', 'core');
168
+        // reprocess server scss for preview
169
+        $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/server.scss', 'core');
170 170
 
171
-		return new DataResponse(
172
-			[
173
-				'data' =>
174
-					[
175
-						'message' => $this->l10n->t('Saved')
176
-					],
177
-				'status' => 'success'
178
-			]
179
-		);
180
-	}
171
+        return new DataResponse(
172
+            [
173
+                'data' =>
174
+                    [
175
+                        'message' => $this->l10n->t('Saved')
176
+                    ],
177
+                'status' => 'success'
178
+            ]
179
+        );
180
+    }
181 181
 
182
-	/**
183
-	 * Update the logos and background image
184
-	 *
185
-	 * @return DataResponse
186
-	 */
187
-	public function updateLogo() {
188
-		$backgroundColor = $this->request->getParam('backgroundColor', false);
189
-		if($backgroundColor) {
190
-			$this->themingDefaults->set('backgroundMime', 'backgroundColor');
191
-			return new DataResponse(
192
-				[
193
-					'data' =>
194
-						[
195
-							'name' => 'backgroundColor',
196
-							'message' => $this->l10n->t('Saved')
197
-						],
198
-					'status' => 'success'
199
-				]
200
-			);
201
-		}
202
-		$newLogo = $this->request->getUploadedFile('uploadlogo');
203
-		$newBackgroundLogo = $this->request->getUploadedFile('upload-login-background');
204
-		if (empty($newLogo) && empty($newBackgroundLogo)) {
205
-			return new DataResponse(
206
-				[
207
-					'data' => [
208
-						'message' => $this->l10n->t('No file uploaded')
209
-					]
210
-				],
211
-				Http::STATUS_UNPROCESSABLE_ENTITY
212
-			);
213
-		}
182
+    /**
183
+     * Update the logos and background image
184
+     *
185
+     * @return DataResponse
186
+     */
187
+    public function updateLogo() {
188
+        $backgroundColor = $this->request->getParam('backgroundColor', false);
189
+        if($backgroundColor) {
190
+            $this->themingDefaults->set('backgroundMime', 'backgroundColor');
191
+            return new DataResponse(
192
+                [
193
+                    'data' =>
194
+                        [
195
+                            'name' => 'backgroundColor',
196
+                            'message' => $this->l10n->t('Saved')
197
+                        ],
198
+                    'status' => 'success'
199
+                ]
200
+            );
201
+        }
202
+        $newLogo = $this->request->getUploadedFile('uploadlogo');
203
+        $newBackgroundLogo = $this->request->getUploadedFile('upload-login-background');
204
+        if (empty($newLogo) && empty($newBackgroundLogo)) {
205
+            return new DataResponse(
206
+                [
207
+                    'data' => [
208
+                        'message' => $this->l10n->t('No file uploaded')
209
+                    ]
210
+                ],
211
+                Http::STATUS_UNPROCESSABLE_ENTITY
212
+            );
213
+        }
214 214
 
215
-		$name = '';
216
-		try {
217
-			$folder = $this->appData->getFolder('images');
218
-		} catch (NotFoundException $e) {
219
-			$folder = $this->appData->newFolder('images');
220
-		}
215
+        $name = '';
216
+        try {
217
+            $folder = $this->appData->getFolder('images');
218
+        } catch (NotFoundException $e) {
219
+            $folder = $this->appData->newFolder('images');
220
+        }
221 221
 
222
-		if (!empty($newLogo)) {
223
-			$target = $folder->newFile('logo');
224
-			$target->putContent(file_get_contents($newLogo['tmp_name'], 'r'));
225
-			$this->themingDefaults->set('logoMime', $newLogo['type']);
226
-			$name = $newLogo['name'];
227
-		}
228
-		if (!empty($newBackgroundLogo)) {
229
-			$target = $folder->newFile('background');
230
-			$image = @imagecreatefromstring(file_get_contents($newBackgroundLogo['tmp_name'], 'r'));
231
-			if ($image === false) {
232
-				return new DataResponse(
233
-					[
234
-						'data' => [
235
-							'message' => $this->l10n->t('Unsupported image type'),
236
-						],
237
-						'status' => 'failure',
238
-					],
239
-					Http::STATUS_UNPROCESSABLE_ENTITY
240
-				);
241
-			}
222
+        if (!empty($newLogo)) {
223
+            $target = $folder->newFile('logo');
224
+            $target->putContent(file_get_contents($newLogo['tmp_name'], 'r'));
225
+            $this->themingDefaults->set('logoMime', $newLogo['type']);
226
+            $name = $newLogo['name'];
227
+        }
228
+        if (!empty($newBackgroundLogo)) {
229
+            $target = $folder->newFile('background');
230
+            $image = @imagecreatefromstring(file_get_contents($newBackgroundLogo['tmp_name'], 'r'));
231
+            if ($image === false) {
232
+                return new DataResponse(
233
+                    [
234
+                        'data' => [
235
+                            'message' => $this->l10n->t('Unsupported image type'),
236
+                        ],
237
+                        'status' => 'failure',
238
+                    ],
239
+                    Http::STATUS_UNPROCESSABLE_ENTITY
240
+                );
241
+            }
242 242
 
243
-			// Optimize the image since some people may upload images that will be
244
-			// either to big or are not progressive rendering.
245
-			$tmpFile = $this->tempManager->getTemporaryFile();
246
-			if (function_exists('imagescale')) {
247
-				// FIXME: Once PHP 5.5.0 is a requirement the above check can be removed
248
-				// Workaround for https://bugs.php.net/bug.php?id=65171
249
-				$newHeight = imagesy($image) / (imagesx($image) / 1920);
250
-				$image = imagescale($image, 1920, $newHeight);
251
-			}
252
-			imageinterlace($image, 1);
253
-			imagejpeg($image, $tmpFile, 75);
254
-			imagedestroy($image);
243
+            // Optimize the image since some people may upload images that will be
244
+            // either to big or are not progressive rendering.
245
+            $tmpFile = $this->tempManager->getTemporaryFile();
246
+            if (function_exists('imagescale')) {
247
+                // FIXME: Once PHP 5.5.0 is a requirement the above check can be removed
248
+                // Workaround for https://bugs.php.net/bug.php?id=65171
249
+                $newHeight = imagesy($image) / (imagesx($image) / 1920);
250
+                $image = imagescale($image, 1920, $newHeight);
251
+            }
252
+            imageinterlace($image, 1);
253
+            imagejpeg($image, $tmpFile, 75);
254
+            imagedestroy($image);
255 255
 
256
-			$target->putContent(file_get_contents($tmpFile, 'r'));
257
-			$this->themingDefaults->set('backgroundMime', $newBackgroundLogo['type']);
258
-			$name = $newBackgroundLogo['name'];
259
-		}
256
+            $target->putContent(file_get_contents($tmpFile, 'r'));
257
+            $this->themingDefaults->set('backgroundMime', $newBackgroundLogo['type']);
258
+            $name = $newBackgroundLogo['name'];
259
+        }
260 260
 
261
-		return new DataResponse(
262
-			[
263
-				'data' =>
264
-					[
265
-						'name' => $name,
266
-						'message' => $this->l10n->t('Saved')
267
-					],
268
-				'status' => 'success'
269
-			]
270
-		);
271
-	}
261
+        return new DataResponse(
262
+            [
263
+                'data' =>
264
+                    [
265
+                        'name' => $name,
266
+                        'message' => $this->l10n->t('Saved')
267
+                    ],
268
+                'status' => 'success'
269
+            ]
270
+        );
271
+    }
272 272
 
273
-	/**
274
-	 * Revert setting to default value
275
-	 *
276
-	 * @param string $setting setting which should be reverted
277
-	 * @return DataResponse
278
-	 */
279
-	public function undo($setting) {
280
-		$value = $this->themingDefaults->undo($setting);
281
-		// reprocess server scss for preview
282
-		$cssCached = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/server.scss', 'core');
273
+    /**
274
+     * Revert setting to default value
275
+     *
276
+     * @param string $setting setting which should be reverted
277
+     * @return DataResponse
278
+     */
279
+    public function undo($setting) {
280
+        $value = $this->themingDefaults->undo($setting);
281
+        // reprocess server scss for preview
282
+        $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/server.scss', 'core');
283 283
 
284
-		if($setting === 'logoMime') {
285
-			try {
286
-				$file = $this->appData->getFolder('images')->getFile('logo');
287
-				$file->delete();
288
-			} catch (NotFoundException $e) {
289
-			} catch (NotPermittedException $e) {
290
-			}
291
-		}
292
-		if($setting === 'backgroundMime') {
293
-			try {
294
-				$file = $this->appData->getFolder('images')->getFile('background');
295
-				$file->delete();
296
-			} catch (NotFoundException $e) {
297
-			} catch (NotPermittedException $e) {
298
-			}
299
-		}
284
+        if($setting === 'logoMime') {
285
+            try {
286
+                $file = $this->appData->getFolder('images')->getFile('logo');
287
+                $file->delete();
288
+            } catch (NotFoundException $e) {
289
+            } catch (NotPermittedException $e) {
290
+            }
291
+        }
292
+        if($setting === 'backgroundMime') {
293
+            try {
294
+                $file = $this->appData->getFolder('images')->getFile('background');
295
+                $file->delete();
296
+            } catch (NotFoundException $e) {
297
+            } catch (NotPermittedException $e) {
298
+            }
299
+        }
300 300
 
301
-		return new DataResponse(
302
-			[
303
-				'data' =>
304
-					[
305
-						'value' => $value,
306
-						'message' => $this->l10n->t('Saved')
307
-					],
308
-				'status' => 'success'
309
-			]
310
-		);
311
-	}
301
+        return new DataResponse(
302
+            [
303
+                'data' =>
304
+                    [
305
+                        'value' => $value,
306
+                        'message' => $this->l10n->t('Saved')
307
+                    ],
308
+                'status' => 'success'
309
+            ]
310
+        );
311
+    }
312 312
 
313
-	/**
314
-	 * @PublicPage
315
-	 * @NoCSRFRequired
316
-	 *
317
-	 * @return FileDisplayResponse|NotFoundResponse
318
-	 */
319
-	public function getLogo() {
320
-		try {
321
-			/** @var File $file */
322
-			$file = $this->appData->getFolder('images')->getFile('logo');
323
-		} catch (NotFoundException $e) {
324
-			return new NotFoundResponse();
325
-		}
313
+    /**
314
+     * @PublicPage
315
+     * @NoCSRFRequired
316
+     *
317
+     * @return FileDisplayResponse|NotFoundResponse
318
+     */
319
+    public function getLogo() {
320
+        try {
321
+            /** @var File $file */
322
+            $file = $this->appData->getFolder('images')->getFile('logo');
323
+        } catch (NotFoundException $e) {
324
+            return new NotFoundResponse();
325
+        }
326 326
 
327
-		$response = new FileDisplayResponse($file);
328
-		$response->cacheFor(3600);
329
-		$expires = new \DateTime();
330
-		$expires->setTimestamp($this->timeFactory->getTime());
331
-		$expires->add(new \DateInterval('PT24H'));
332
-		$response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
333
-		$response->addHeader('Pragma', 'cache');
334
-		$response->addHeader('Content-Type', $this->config->getAppValue($this->appName, 'logoMime', ''));
335
-		return $response;
336
-	}
327
+        $response = new FileDisplayResponse($file);
328
+        $response->cacheFor(3600);
329
+        $expires = new \DateTime();
330
+        $expires->setTimestamp($this->timeFactory->getTime());
331
+        $expires->add(new \DateInterval('PT24H'));
332
+        $response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
333
+        $response->addHeader('Pragma', 'cache');
334
+        $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, 'logoMime', ''));
335
+        return $response;
336
+    }
337 337
 
338
-	/**
339
-	 * @PublicPage
340
-	 * @NoCSRFRequired
341
-	 *
342
-	 * @return FileDisplayResponse|NotFoundResponse
343
-	 */
344
-	public function getLoginBackground() {
345
-		try {
346
-			/** @var File $file */
347
-			$file = $this->appData->getFolder('images')->getFile('background');
348
-		} catch (NotFoundException $e) {
349
-			return new NotFoundResponse();
350
-		}
338
+    /**
339
+     * @PublicPage
340
+     * @NoCSRFRequired
341
+     *
342
+     * @return FileDisplayResponse|NotFoundResponse
343
+     */
344
+    public function getLoginBackground() {
345
+        try {
346
+            /** @var File $file */
347
+            $file = $this->appData->getFolder('images')->getFile('background');
348
+        } catch (NotFoundException $e) {
349
+            return new NotFoundResponse();
350
+        }
351 351
 
352
-		$response = new FileDisplayResponse($file);
353
-		$response->cacheFor(3600);
354
-		$expires = new \DateTime();
355
-		$expires->setTimestamp($this->timeFactory->getTime());
356
-		$expires->add(new \DateInterval('PT24H'));
357
-		$response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
358
-		$response->addHeader('Pragma', 'cache');
359
-		$response->addHeader('Content-Type', $this->config->getAppValue($this->appName, 'backgroundMime', ''));
360
-		return $response;
361
-	}
352
+        $response = new FileDisplayResponse($file);
353
+        $response->cacheFor(3600);
354
+        $expires = new \DateTime();
355
+        $expires->setTimestamp($this->timeFactory->getTime());
356
+        $expires->add(new \DateInterval('PT24H'));
357
+        $response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
358
+        $response->addHeader('Pragma', 'cache');
359
+        $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, 'backgroundMime', ''));
360
+        return $response;
361
+    }
362 362
 
363
-	/**
364
-	 * @NoCSRFRequired
365
-	 * @PublicPage
366
-	 *
367
-	 * @return FileDisplayResponse|NotFoundResponse
368
-	 */
369
-	public function getStylesheet() {
370
-		$appPath = substr(\OC::$server->getAppManager()->getAppPath('theming'), strlen(\OC::$SERVERROOT) + 1);
371
-		/* SCSSCacher is required here
363
+    /**
364
+     * @NoCSRFRequired
365
+     * @PublicPage
366
+     *
367
+     * @return FileDisplayResponse|NotFoundResponse
368
+     */
369
+    public function getStylesheet() {
370
+        $appPath = substr(\OC::$server->getAppManager()->getAppPath('theming'), strlen(\OC::$SERVERROOT) + 1);
371
+        /* SCSSCacher is required here
372 372
 		 * We cannot rely on automatic caching done by \OC_Util::addStyle,
373 373
 		 * since we need to add the cacheBuster value to the url
374 374
 		 */
375
-		$cssCached = $this->scssCacher->process(\OC::$SERVERROOT, $appPath . '/css/theming.scss', 'theming');
376
-		if(!$cssCached) {
377
-			return new NotFoundResponse();
378
-		}
375
+        $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, $appPath . '/css/theming.scss', 'theming');
376
+        if(!$cssCached) {
377
+            return new NotFoundResponse();
378
+        }
379 379
 
380
-		try {
381
-			$cssFile = $this->scssCacher->getCachedCSS('theming', 'theming.css');
382
-			$response = new FileDisplayResponse($cssFile, Http::STATUS_OK, ['Content-Type' => 'text/css']);
383
-			$response->cacheFor(86400);
384
-			$expires = new \DateTime();
385
-			$expires->setTimestamp($this->timeFactory->getTime());
386
-			$expires->add(new \DateInterval('PT24H'));
387
-			$response->addHeader('Expires', $expires->format(\DateTime::RFC1123));
388
-			$response->addHeader('Pragma', 'cache');
389
-			return $response;
390
-		} catch (NotFoundException $e) {
391
-			return new NotFoundResponse();
392
-		}
393
-	}
380
+        try {
381
+            $cssFile = $this->scssCacher->getCachedCSS('theming', 'theming.css');
382
+            $response = new FileDisplayResponse($cssFile, Http::STATUS_OK, ['Content-Type' => 'text/css']);
383
+            $response->cacheFor(86400);
384
+            $expires = new \DateTime();
385
+            $expires->setTimestamp($this->timeFactory->getTime());
386
+            $expires->add(new \DateInterval('PT24H'));
387
+            $response->addHeader('Expires', $expires->format(\DateTime::RFC1123));
388
+            $response->addHeader('Pragma', 'cache');
389
+            return $response;
390
+        } catch (NotFoundException $e) {
391
+            return new NotFoundResponse();
392
+        }
393
+    }
394 394
 
395
-	/**
396
-	 * @NoCSRFRequired
397
-	 * @PublicPage
398
-	 *
399
-	 * @return DataDownloadResponse
400
-	 */
401
-	public function getJavascript() {
402
-		$cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
403
-		$responseJS = '(function() {
395
+    /**
396
+     * @NoCSRFRequired
397
+     * @PublicPage
398
+     *
399
+     * @return DataDownloadResponse
400
+     */
401
+    public function getJavascript() {
402
+        $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
403
+        $responseJS = '(function() {
404 404
 	OCA.Theming = {
405 405
 		name: ' . json_encode($this->themingDefaults->getName()) . ',
406 406
 		url: ' . json_encode($this->themingDefaults->getBaseUrl()) . ',
@@ -410,10 +410,10 @@  discard block
 block discarded – undo
410 410
 		cacheBuster: ' . json_encode($cacheBusterValue) . '
411 411
 	};
412 412
 })();';
413
-		$response = new DataDownloadResponse($responseJS, 'javascript', 'text/javascript');
414
-		$response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
415
-		$response->addHeader('Pragma', 'cache');
416
-		$response->cacheFor(3600);
417
-		return $response;
418
-	}
413
+        $response = new DataDownloadResponse($responseJS, 'javascript', 'text/javascript');
414
+        $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
415
+        $response->addHeader('Pragma', 'cache');
416
+        $response->cacheFor(3600);
417
+        return $response;
418
+    }
419 419
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 	 */
187 187
 	public function updateLogo() {
188 188
 		$backgroundColor = $this->request->getParam('backgroundColor', false);
189
-		if($backgroundColor) {
189
+		if ($backgroundColor) {
190 190
 			$this->themingDefaults->set('backgroundMime', 'backgroundColor');
191 191
 			return new DataResponse(
192 192
 				[
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 		// reprocess server scss for preview
282 282
 		$cssCached = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/server.scss', 'core');
283 283
 
284
-		if($setting === 'logoMime') {
284
+		if ($setting === 'logoMime') {
285 285
 			try {
286 286
 				$file = $this->appData->getFolder('images')->getFile('logo');
287 287
 				$file->delete();
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 			} catch (NotPermittedException $e) {
290 290
 			}
291 291
 		}
292
-		if($setting === 'backgroundMime') {
292
+		if ($setting === 'backgroundMime') {
293 293
 			try {
294 294
 				$file = $this->appData->getFolder('images')->getFile('background');
295 295
 				$file->delete();
@@ -372,8 +372,8 @@  discard block
 block discarded – undo
372 372
 		 * We cannot rely on automatic caching done by \OC_Util::addStyle,
373 373
 		 * since we need to add the cacheBuster value to the url
374 374
 		 */
375
-		$cssCached = $this->scssCacher->process(\OC::$SERVERROOT, $appPath . '/css/theming.scss', 'theming');
376
-		if(!$cssCached) {
375
+		$cssCached = $this->scssCacher->process(\OC::$SERVERROOT, $appPath.'/css/theming.scss', 'theming');
376
+		if (!$cssCached) {
377 377
 			return new NotFoundResponse();
378 378
 		}
379 379
 
@@ -402,12 +402,12 @@  discard block
 block discarded – undo
402 402
 		$cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
403 403
 		$responseJS = '(function() {
404 404
 	OCA.Theming = {
405
-		name: ' . json_encode($this->themingDefaults->getName()) . ',
406
-		url: ' . json_encode($this->themingDefaults->getBaseUrl()) . ',
407
-		slogan: ' . json_encode($this->themingDefaults->getSlogan()) . ',
408
-		color: ' . json_encode($this->themingDefaults->getColorPrimary()) . ',
409
-		inverted: ' . json_encode($this->util->invertTextColor($this->themingDefaults->getColorPrimary())) . ',
410
-		cacheBuster: ' . json_encode($cacheBusterValue) . '
405
+		name: ' . json_encode($this->themingDefaults->getName()).',
406
+		url: ' . json_encode($this->themingDefaults->getBaseUrl()).',
407
+		slogan: ' . json_encode($this->themingDefaults->getSlogan()).',
408
+		color: ' . json_encode($this->themingDefaults->getColorPrimary()).',
409
+		inverted: ' . json_encode($this->util->invertTextColor($this->themingDefaults->getColorPrimary())).',
410
+		cacheBuster: ' . json_encode($cacheBusterValue).'
411 411
 	};
412 412
 })();';
413 413
 		$response = new DataDownloadResponse($responseJS, 'javascript', 'text/javascript');
Please login to merge, or discard this patch.
apps/theming/lib/ThemingDefaults.php 1 patch
Indentation   +251 added lines, -251 removed lines patch added patch discarded remove patch
@@ -31,256 +31,256 @@
 block discarded – undo
31 31
 
32 32
 class ThemingDefaults extends \OC_Defaults {
33 33
 
34
-	/** @var IConfig */
35
-	private $config;
36
-	/** @var IL10N */
37
-	private $l;
38
-	/** @var IURLGenerator */
39
-	private $urlGenerator;
40
-	/** @var IAppData */
41
-	private $appData;
42
-	/** @var ICacheFactory */
43
-	private $cacheFactory;
44
-	/** @var string */
45
-	private $name;
46
-	/** @var string */
47
-	private $url;
48
-	/** @var string */
49
-	private $slogan;
50
-	/** @var string */
51
-	private $color;
52
-	/** @var Util */
53
-	private $util;
54
-
55
-	/**
56
-	 * ThemingDefaults constructor.
57
-	 *
58
-	 * @param IConfig $config
59
-	 * @param IL10N $l
60
-	 * @param IURLGenerator $urlGenerator
61
-	 * @param \OC_Defaults $defaults
62
-	 * @param IAppData $appData
63
-	 * @param ICacheFactory $cacheFactory
64
-	 * @param Util $util
65
-	 */
66
-	public function __construct(IConfig $config,
67
-								IL10N $l,
68
-								IURLGenerator $urlGenerator,
69
-								IAppData $appData,
70
-								ICacheFactory $cacheFactory,
71
-								Util $util
72
-	) {
73
-		parent::__construct();
74
-		$this->config = $config;
75
-		$this->l = $l;
76
-		$this->urlGenerator = $urlGenerator;
77
-		$this->appData = $appData;
78
-		$this->cacheFactory = $cacheFactory;
79
-		$this->util = $util;
80
-
81
-		$this->name = parent::getName();
82
-		$this->url = parent::getBaseUrl();
83
-		$this->slogan = parent::getSlogan();
84
-		$this->color = parent::getColorPrimary();
85
-	}
86
-
87
-	public function getName() {
88
-		return strip_tags($this->config->getAppValue('theming', 'name', $this->name));
89
-	}
90
-
91
-	public function getHTMLName() {
92
-		return $this->config->getAppValue('theming', 'name', $this->name);
93
-	}
94
-
95
-	public function getTitle() {
96
-		return $this->getName();
97
-	}
98
-
99
-	public function getEntity() {
100
-		return $this->getName();
101
-	}
102
-
103
-	public function getBaseUrl() {
104
-		return $this->config->getAppValue('theming', 'url', $this->url);
105
-	}
106
-
107
-	public function getSlogan() {
108
-		return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan));
109
-	}
110
-
111
-	public function getShortFooter() {
112
-		$slogan = $this->getSlogan();
113
-		$footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
114
-			' rel="noreferrer">' .$this->getEntity() . '</a>'.
115
-			($slogan !== '' ? ' – ' . $slogan : '');
116
-
117
-		return $footer;
118
-	}
119
-
120
-	/**
121
-	 * Color that is used for the header as well as for mail headers
122
-	 *
123
-	 * @return string
124
-	 */
125
-	public function getColorPrimary() {
126
-		return $this->config->getAppValue('theming', 'color', $this->color);
127
-	}
128
-
129
-	/**
130
-	 * Themed logo url
131
-	 *
132
-	 * @return string
133
-	 */
134
-	public function getLogo() {
135
-		$logo = $this->config->getAppValue('theming', 'logoMime', false);
136
-
137
-		$logoExists = true;
138
-		try {
139
-			$this->appData->getFolder('images')->getFile('logo');
140
-		} catch (\Exception $e) {
141
-			$logoExists = false;
142
-		}
143
-
144
-		$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
145
-
146
-		if(!$logo || !$logoExists) {
147
-			return $this->urlGenerator->imagePath('core','logo.svg') . '?v=' . $cacheBusterCounter;
148
-		}
149
-
150
-		return $this->urlGenerator->linkToRoute('theming.Theming.getLogo') . '?v=' . $cacheBusterCounter;
151
-	}
152
-
153
-	/**
154
-	 * Themed background image url
155
-	 *
156
-	 * @return string
157
-	 */
158
-	public function getBackground() {
159
-		$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime',false);
160
-
161
-		$backgroundExists = true;
162
-		try {
163
-			$this->appData->getFolder('images')->getFile('background');
164
-		} catch (\Exception $e) {
165
-			$backgroundExists = false;
166
-		}
167
-
168
-		$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
169
-
170
-		if(!$backgroundLogo || !$backgroundExists) {
171
-			return $this->urlGenerator->imagePath('core','background.jpg') . '?v=' . $cacheBusterCounter;
172
-		}
173
-
174
-		return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground') . '?v=' . $cacheBusterCounter;
175
-	}
176
-
177
-
178
-	/**
179
-	 * @return array scss variables to overwrite
180
-	 */
181
-	public function getScssVariables() {
182
-		$cache = $this->cacheFactory->create('theming');
183
-		if ($value = $cache->get('getScssVariables')) {
184
-			return $value;
185
-		}
186
-
187
-		$variables = [
188
-			'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'",
189
-		];
190
-
191
-		$variables['image-logo'] = "'".$this->urlGenerator->getAbsoluteURL($this->getLogo())."'";
192
-		$variables['image-login-background'] = "'".$this->urlGenerator->getAbsoluteURL($this->getBackground())."'";
193
-		$variables['image-login-plain'] = 'false';
194
-
195
-		if ($this->config->getAppValue('theming', 'color', null) !== null) {
196
-			if ($this->util->invertTextColor($this->getColorPrimary())) {
197
-				$colorPrimaryText = '#000000';
198
-			} else {
199
-				$colorPrimaryText = '#ffffff';
200
-			}
201
-			$variables['color-primary'] = $this->getColorPrimary();
202
-			$variables['color-primary-text'] = $colorPrimaryText;
203
-		}
204
-
205
-		if ($this->config->getAppValue('theming', 'backgroundMime', null) === 'backgroundColor') {
206
-			$variables['image-login-plain'] = 'true';
207
-		}
208
-		$cache->set('getScssVariables', $variables);
209
-		return $variables;
210
-	}
211
-
212
-	/**
213
-	 * Check if Imagemagick is enabled and if SVG is supported
214
-	 * otherwise we can't render custom icons
215
-	 *
216
-	 * @return bool
217
-	 */
218
-	public function shouldReplaceIcons() {
219
-		$cache = $this->cacheFactory->create('theming');
220
-		if($value = $cache->get('shouldReplaceIcons')) {
221
-			return (bool)$value;
222
-		}
223
-		$value = false;
224
-		if(extension_loaded('imagick')) {
225
-			$checkImagick = new \Imagick();
226
-			if (count($checkImagick->queryFormats('SVG')) >= 1) {
227
-				$value = true;
228
-			}
229
-			$checkImagick->clear();
230
-		}
231
-		$cache->set('shouldReplaceIcons', $value);
232
-		return $value;
233
-	}
234
-
235
-	/**
236
-	 * Increases the cache buster key
237
-	 */
238
-	private function increaseCacheBuster() {
239
-		$cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
240
-		$this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
241
-		$this->cacheFactory->create('theming')->clear('getScssVariables');
242
-	}
243
-
244
-	/**
245
-	 * Update setting in the database
246
-	 *
247
-	 * @param string $setting
248
-	 * @param string $value
249
-	 */
250
-	public function set($setting, $value) {
251
-		$this->config->setAppValue('theming', $setting, $value);
252
-		$this->increaseCacheBuster();
253
-	}
254
-
255
-	/**
256
-	 * Revert settings to the default value
257
-	 *
258
-	 * @param string $setting setting which should be reverted
259
-	 * @return string default value
260
-	 */
261
-	public function undo($setting) {
262
-		$this->config->deleteAppValue('theming', $setting);
263
-		$this->increaseCacheBuster();
264
-
265
-		switch ($setting) {
266
-			case 'name':
267
-				$returnValue = $this->getEntity();
268
-				break;
269
-			case 'url':
270
-				$returnValue = $this->getBaseUrl();
271
-				break;
272
-			case 'slogan':
273
-				$returnValue = $this->getSlogan();
274
-				break;
275
-			case 'color':
276
-				$returnValue = $this->getColorPrimary();
277
-				break;
278
-			default:
279
-				$returnValue = '';
280
-				break;
281
-		}
282
-
283
-		return $returnValue;
284
-	}
34
+    /** @var IConfig */
35
+    private $config;
36
+    /** @var IL10N */
37
+    private $l;
38
+    /** @var IURLGenerator */
39
+    private $urlGenerator;
40
+    /** @var IAppData */
41
+    private $appData;
42
+    /** @var ICacheFactory */
43
+    private $cacheFactory;
44
+    /** @var string */
45
+    private $name;
46
+    /** @var string */
47
+    private $url;
48
+    /** @var string */
49
+    private $slogan;
50
+    /** @var string */
51
+    private $color;
52
+    /** @var Util */
53
+    private $util;
54
+
55
+    /**
56
+     * ThemingDefaults constructor.
57
+     *
58
+     * @param IConfig $config
59
+     * @param IL10N $l
60
+     * @param IURLGenerator $urlGenerator
61
+     * @param \OC_Defaults $defaults
62
+     * @param IAppData $appData
63
+     * @param ICacheFactory $cacheFactory
64
+     * @param Util $util
65
+     */
66
+    public function __construct(IConfig $config,
67
+                                IL10N $l,
68
+                                IURLGenerator $urlGenerator,
69
+                                IAppData $appData,
70
+                                ICacheFactory $cacheFactory,
71
+                                Util $util
72
+    ) {
73
+        parent::__construct();
74
+        $this->config = $config;
75
+        $this->l = $l;
76
+        $this->urlGenerator = $urlGenerator;
77
+        $this->appData = $appData;
78
+        $this->cacheFactory = $cacheFactory;
79
+        $this->util = $util;
80
+
81
+        $this->name = parent::getName();
82
+        $this->url = parent::getBaseUrl();
83
+        $this->slogan = parent::getSlogan();
84
+        $this->color = parent::getColorPrimary();
85
+    }
86
+
87
+    public function getName() {
88
+        return strip_tags($this->config->getAppValue('theming', 'name', $this->name));
89
+    }
90
+
91
+    public function getHTMLName() {
92
+        return $this->config->getAppValue('theming', 'name', $this->name);
93
+    }
94
+
95
+    public function getTitle() {
96
+        return $this->getName();
97
+    }
98
+
99
+    public function getEntity() {
100
+        return $this->getName();
101
+    }
102
+
103
+    public function getBaseUrl() {
104
+        return $this->config->getAppValue('theming', 'url', $this->url);
105
+    }
106
+
107
+    public function getSlogan() {
108
+        return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan));
109
+    }
110
+
111
+    public function getShortFooter() {
112
+        $slogan = $this->getSlogan();
113
+        $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
114
+            ' rel="noreferrer">' .$this->getEntity() . '</a>'.
115
+            ($slogan !== '' ? ' – ' . $slogan : '');
116
+
117
+        return $footer;
118
+    }
119
+
120
+    /**
121
+     * Color that is used for the header as well as for mail headers
122
+     *
123
+     * @return string
124
+     */
125
+    public function getColorPrimary() {
126
+        return $this->config->getAppValue('theming', 'color', $this->color);
127
+    }
128
+
129
+    /**
130
+     * Themed logo url
131
+     *
132
+     * @return string
133
+     */
134
+    public function getLogo() {
135
+        $logo = $this->config->getAppValue('theming', 'logoMime', false);
136
+
137
+        $logoExists = true;
138
+        try {
139
+            $this->appData->getFolder('images')->getFile('logo');
140
+        } catch (\Exception $e) {
141
+            $logoExists = false;
142
+        }
143
+
144
+        $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
145
+
146
+        if(!$logo || !$logoExists) {
147
+            return $this->urlGenerator->imagePath('core','logo.svg') . '?v=' . $cacheBusterCounter;
148
+        }
149
+
150
+        return $this->urlGenerator->linkToRoute('theming.Theming.getLogo') . '?v=' . $cacheBusterCounter;
151
+    }
152
+
153
+    /**
154
+     * Themed background image url
155
+     *
156
+     * @return string
157
+     */
158
+    public function getBackground() {
159
+        $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime',false);
160
+
161
+        $backgroundExists = true;
162
+        try {
163
+            $this->appData->getFolder('images')->getFile('background');
164
+        } catch (\Exception $e) {
165
+            $backgroundExists = false;
166
+        }
167
+
168
+        $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
169
+
170
+        if(!$backgroundLogo || !$backgroundExists) {
171
+            return $this->urlGenerator->imagePath('core','background.jpg') . '?v=' . $cacheBusterCounter;
172
+        }
173
+
174
+        return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground') . '?v=' . $cacheBusterCounter;
175
+    }
176
+
177
+
178
+    /**
179
+     * @return array scss variables to overwrite
180
+     */
181
+    public function getScssVariables() {
182
+        $cache = $this->cacheFactory->create('theming');
183
+        if ($value = $cache->get('getScssVariables')) {
184
+            return $value;
185
+        }
186
+
187
+        $variables = [
188
+            'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'",
189
+        ];
190
+
191
+        $variables['image-logo'] = "'".$this->urlGenerator->getAbsoluteURL($this->getLogo())."'";
192
+        $variables['image-login-background'] = "'".$this->urlGenerator->getAbsoluteURL($this->getBackground())."'";
193
+        $variables['image-login-plain'] = 'false';
194
+
195
+        if ($this->config->getAppValue('theming', 'color', null) !== null) {
196
+            if ($this->util->invertTextColor($this->getColorPrimary())) {
197
+                $colorPrimaryText = '#000000';
198
+            } else {
199
+                $colorPrimaryText = '#ffffff';
200
+            }
201
+            $variables['color-primary'] = $this->getColorPrimary();
202
+            $variables['color-primary-text'] = $colorPrimaryText;
203
+        }
204
+
205
+        if ($this->config->getAppValue('theming', 'backgroundMime', null) === 'backgroundColor') {
206
+            $variables['image-login-plain'] = 'true';
207
+        }
208
+        $cache->set('getScssVariables', $variables);
209
+        return $variables;
210
+    }
211
+
212
+    /**
213
+     * Check if Imagemagick is enabled and if SVG is supported
214
+     * otherwise we can't render custom icons
215
+     *
216
+     * @return bool
217
+     */
218
+    public function shouldReplaceIcons() {
219
+        $cache = $this->cacheFactory->create('theming');
220
+        if($value = $cache->get('shouldReplaceIcons')) {
221
+            return (bool)$value;
222
+        }
223
+        $value = false;
224
+        if(extension_loaded('imagick')) {
225
+            $checkImagick = new \Imagick();
226
+            if (count($checkImagick->queryFormats('SVG')) >= 1) {
227
+                $value = true;
228
+            }
229
+            $checkImagick->clear();
230
+        }
231
+        $cache->set('shouldReplaceIcons', $value);
232
+        return $value;
233
+    }
234
+
235
+    /**
236
+     * Increases the cache buster key
237
+     */
238
+    private function increaseCacheBuster() {
239
+        $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
240
+        $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
241
+        $this->cacheFactory->create('theming')->clear('getScssVariables');
242
+    }
243
+
244
+    /**
245
+     * Update setting in the database
246
+     *
247
+     * @param string $setting
248
+     * @param string $value
249
+     */
250
+    public function set($setting, $value) {
251
+        $this->config->setAppValue('theming', $setting, $value);
252
+        $this->increaseCacheBuster();
253
+    }
254
+
255
+    /**
256
+     * Revert settings to the default value
257
+     *
258
+     * @param string $setting setting which should be reverted
259
+     * @return string default value
260
+     */
261
+    public function undo($setting) {
262
+        $this->config->deleteAppValue('theming', $setting);
263
+        $this->increaseCacheBuster();
264
+
265
+        switch ($setting) {
266
+            case 'name':
267
+                $returnValue = $this->getEntity();
268
+                break;
269
+            case 'url':
270
+                $returnValue = $this->getBaseUrl();
271
+                break;
272
+            case 'slogan':
273
+                $returnValue = $this->getSlogan();
274
+                break;
275
+            case 'color':
276
+                $returnValue = $this->getColorPrimary();
277
+                break;
278
+            default:
279
+                $returnValue = '';
280
+                break;
281
+        }
282
+
283
+        return $returnValue;
284
+    }
285 285
 
286 286
 }
Please login to merge, or discard this patch.