Passed
Push — develop ( 61a0d8...faf047 )
by Jens
02:49
created

CmsComponent::imagesRouting()   D

Complexity

Conditions 9
Paths 7

Size

Total Lines 28
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 9
eloc 24
c 1
b 0
f 0
nc 7
nop 2
dl 0
loc 28
rs 4.909
1
<?php
2
namespace library\components
3
{
4
5
	use library\crypt\Crypt;
6
	use library\storage\Storage;
7
8
	class CmsComponent extends BaseComponent
9
	{
10
		/**
11
		 * @var \library\storage\Storage
12
		 */
13
		protected $storage;
14
		/**
15
		 * @var string
16
		 */
17
		protected $invalidCredentialsMsg = 'Invalid username / password combination';
18
19
		/**
20
		 * @var null
21
         */
22
		protected $subTemplate = null;
23
24
		/**
25
		 * @param \library\storage\Storage $storage
26
		 *
27
		 * @return void
28
		 */
29
		public function run(Storage $storage)
30
		{
31
			$this->parameters['mainNavClass'] = 'default';
32
			$this->storage = $storage;
33
34
			$remoteAddress = $_SERVER['REMOTE_ADDR'];
35
			$this->checkWhiteList($remoteAddress);
36
			$this->checkBlackList($remoteAddress);
37
38
			$this->checkLogin();
39
40
			$this->parameters['userRights'] = $_SESSION['cloudcontrol']->rights;
41
42
			$this->routing();
43
		}
44
45
		/**
46
		 * See if a user is logged or wants to log in and
47
		 * takes appropriate actions.
48
		 *
49
		 * @throws \Exception
50
		 */
51
		protected function checkLogin()
52
		{
53
			$request = $this->request;
54
			
55
			if (!isset($_SESSION['cloudcontrol'])) {
56
				if (isset($request::$post['username'], $request::$post['password'])) {
57
					$user = $this->storage->getUserByUsername($request::$post['username']);
58
					$crypt = new Crypt();
59
					if (empty($user)) {
60
						$crypt->encrypt($request::$post['password'], 16); // Buy time, to avoid brute forcing
61
						$this->parameters['errorMsg'] = $this->invalidCredentialsMsg;
62
						$this->showLogin();
63
					} else {
64
						$salt = $user->salt;
65
						$password = $user->password;
66
						
67
						$passwordCorrect = $crypt->compare($request::$post['password'], $password, $salt);
68
						
69
						if ($passwordCorrect) {
70
							$_SESSION['cloudcontrol'] = $user;
71
						} else {
72
							$this->parameters['errorMsg'] = $this->invalidCredentialsMsg;
73
							$this->showLogin();
74
						}
75
					}
76
				} else {
77
					$this->showLogin();
78
				}
79
			}
80
		}
81
82
		/**
83
		 * Overrides normal behaviour and only renders the
84
		 * login screen
85
		 *
86
		 * @throws \Exception
87
		 */
88
		protected function showLogin()
89
		{
90
			$loginTemplatePath = 'cms/login';
91
			$this->renderTemplate($loginTemplatePath);
92
			ob_end_flush();
93
			exit;
94
		}
95
96
		/**
97
		 * As an exception, to keep the initial file structure simple
98
		 * the cms implements it's own routing, apart from the regular sitemap functionality
99
		 *
100
		 * @throws \Exception
101
		 */
102
		protected function routing()
103
		{
104
			$relativeCmsUri = $this->getRelativeCmsUri($this->request);
105
106
			$userRights = $_SESSION['cloudcontrol']->rights;
107
108
			if ($relativeCmsUri == '' || $relativeCmsUri == '/') {
109
				$this->subTemplate = 'cms/dashboard';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'cms/dashboard' of type string is incompatible with the declared type null of property $subTemplate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
110
			}
111
112
			$this->apiRouting($relativeCmsUri);
113
114
			if (in_array('documents', $userRights)) {
115
				$this->documentsRouting($this->request, $relativeCmsUri);
116
			}
117
118
			if (in_array('sitemap', $userRights)) {
119
				$this->sitemapRouting($this->request, $relativeCmsUri);
120
			}
121
122
			if (in_array('images', $userRights)) {
123
				$this->imagesRouting($this->request, $relativeCmsUri);
124
			}
125
126
			if (in_array('files', $userRights)) {
127
				$this->filesRouting($this->request, $relativeCmsUri);
128
			}
129
130
			if (in_array('configuration', $userRights)) {
131
				$this->configurationRouting($this->request, $relativeCmsUri);
132
			}
133
134
			if ($this->subTemplate !== null) {
135
				$this->parameters['body'] = $this->renderTemplate($this->subTemplate);
136
			}			
137
		}
138
139
		/**
140
		 * @param $remoteAddress
141
		 * @throws \Exception
142
         */
143
		private function checkWhiteList($remoteAddress)
144
		{
145
			if (isset($this->parameters['whitelistIps'])) {
146
				$whitelistIps = explode(',', $this->parameters['whitelistIps']);
147
				$whitelistIps = array_map("trim", $whitelistIps);
148
				if (!in_array($remoteAddress, $whitelistIps)) {
149
					throw new \Exception('Ip address ' . $remoteAddress . ' is not on whitelist');
150
				}
151
			}
152
		}
153
154
		/**
155
		 * @param $remoteAddress
156
		 * @throws \Exception
157
         */
158
		private function checkBlackList($remoteAddress)
159
		{
160
			if (isset($this->parameters['blacklistIps'])) {
161
				$blacklistIps = explode(',', $this->parameters['blacklistIps']);
162
				$blacklistIps = array_map("trim", $blacklistIps);
163
				if (in_array($remoteAddress, $blacklistIps)) {
164
					throw new \Exception('Ip address ' . $remoteAddress . ' is on blacklist');
165
				}
166
			}
167
		}
168
169
		/**
170
		 * @param $request
171
		 * @return mixed|string
172
         */
173
		private function getRelativeCmsUri($request)
174
		{
175
			// TODO Use regex match parameter instead of calculating relative uri
176
			$pos = strpos($request::$relativeUri, $this->parameters['cmsPrefix']);
177
			$relativeCmsUri = '/';
178
			if ($pos !== false) {
179
				$relativeCmsUri = substr_replace($request::$relativeUri, '', $pos, strlen($this->parameters['cmsPrefix']));
180
			}
181
			return $relativeCmsUri;
182
		}
183
184
		/**
185
		 * @param $request
186
		 * @param $relativeCmsUri
187
         */
188
		private function documentsRouting($request, $relativeCmsUri)
189
		{
190
			if ($relativeCmsUri == '/documents') {
191
				$this->subTemplate = 'cms/documents';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'cms/documents' of type string is incompatible with the declared type null of property $subTemplate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
192
				$this->parameters['documents'] = $this->storage->getDocuments();
193
				$this->parameters['mainNavClass'] = 'documents';
194
			}
195
			$this->documentRouting($request, $relativeCmsUri);
196
			$this->folderRouting($request, $relativeCmsUri);
197
		}
198
199
		/**
200
		 * @param $request
201
		 * @param $relativeCmsUri
202
         */
203
		private function sitemapRouting($request, $relativeCmsUri)
204
		{
205
			if ($relativeCmsUri == '/sitemap') {
206
				$this->subTemplate = 'cms/sitemap';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'cms/sitemap' of type string is incompatible with the declared type null of property $subTemplate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
207
				if (isset($request::$post['save'])) {
208
					$this->storage->saveSitemap($request::$post);
209
				}
210
				$this->parameters['mainNavClass'] = 'sitemap';
211
				$this->parameters['sitemap'] = $this->storage->getSitemap();
212
			} elseif ($relativeCmsUri == '/sitemap/new') {
213
				$this->subTemplate = 'cms/sitemap/form';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'cms/sitemap/form' of type string is incompatible with the declared type null of property $subTemplate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
214
				$this->parameters['mainNavClass'] = 'sitemap';
215
				if (isset($request::$post['title'], $request::$post['template'], $request::$post['component'])) {
216
					$this->storage->addSitemapItem($request::$post);
217
					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/sitemap');
218
					exit;
219
				}
220
			} elseif ($relativeCmsUri == '/sitemap/edit' && isset($request::$get['slug'])) {
221
				$this->subTemplate = 'cms/sitemap/form';
222
				$this->parameters['mainNavClass'] = 'sitemap';
223
				$sitemapItem = $this->storage->getSitemapItemBySlug($request::$get['slug']);
224
				if (isset($request::$post['title'], $request::$post['template'], $request::$post['component'])) {
225
					$this->storage->saveSitemapItem($request::$get['slug'], $request::$post);
226
					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/sitemap');
227
					exit;
228
				}
229
				$this->parameters['sitemapItem'] = $sitemapItem;
230
			} elseif ($relativeCmsUri == '/sitemap/delete' && isset($request::$get['slug'])) {
231
				$this->storage->deleteSitemapItemBySlug($request::$get['slug']);
232
				header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/sitemap');
233
				exit;
234
			}
235
		}
236
237
		/**
238
		 * @param $request
239
		 * @param $relativeCmsUri
240
         */
241
		private function imagesRouting($request, $relativeCmsUri)
242
		{
243
			if ($relativeCmsUri == '/images') {
244
				$this->subTemplate = 'cms/images';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'cms/images' of type string is incompatible with the declared type null of property $subTemplate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
245
				$this->parameters['mainNavClass'] = 'images';
246
				$this->parameters['images'] = $this->storage->getImages();
247
				$this->parameters['smallestImage'] = $this->storage->getSmallestImageSet()->slug;
248
			} elseif ($relativeCmsUri == '/images.json') {
249
				header('Content-type:application/json');
250
				die(json_encode($this->storage->getImages()));
251
			} elseif ($relativeCmsUri == '/images/new') {
252
				$this->subTemplate = 'cms/images/form';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'cms/images/form' of type string is incompatible with the declared type null of property $subTemplate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
253
				$this->parameters['mainNavClass'] = 'images';
254
				if (isset($_FILES['file'])) {
255
					$this->storage->addImage($_FILES['file']);
256
					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/images');
257
					exit;
258
				}
259
			} elseif ($relativeCmsUri == '/images/delete' && isset($request::$get['file'])) {
260
				$this->storage->deleteImageByName($request::$get['file']);
261
				header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/images');
262
				exit;
263
			} elseif ($relativeCmsUri == '/images/show' && isset($request::$get['file'])) {
264
				$this->subTemplate = 'cms/images/show';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'cms/images/show' of type string is incompatible with the declared type null of property $subTemplate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
265
				$this->parameters['mainNavClass'] = 'images';
266
				$this->parameters['image'] = $this->storage->getImageByName($request::$get['file']);
267
			}
268
		}
269
270
		/**
271
		 * @param $relativeCmsUri
272
         */
273
		private function apiRouting($relativeCmsUri)
274
		{
275
			if ($relativeCmsUri == '/images.json') {
276
				header('Content-type:application/json');
277
				die(json_encode($this->storage->getImages()));
278
			} elseif ($relativeCmsUri == '/files.json') {
279
				header('Content-type:application/json');
280
				die(json_encode($this->storage->getFiles()));
281
			} elseif ($relativeCmsUri == '/documents.json') {
282
				header('Content-type:application/json');
283
				die(json_encode($this->storage->getDocuments()));
284
			}
285
		}
286
287
		/**
288
		 * @param $request
289
		 * @param $relativeCmsUri
290
         */
291
		private function filesRouting($request, $relativeCmsUri)
292
		{
293
			if ($relativeCmsUri == '/files') {
294
				$this->subTemplate = 'cms/files';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'cms/files' of type string is incompatible with the declared type null of property $subTemplate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
295
				$this->parameters['mainNavClass'] = 'files';
296
				$this->parameters['files'] = $this->storage->getFiles();
297
			} elseif ($relativeCmsUri == '/files/new') {
298
				$this->subTemplate = 'cms/files/form';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'cms/files/form' of type string is incompatible with the declared type null of property $subTemplate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
299
				$this->parameters['mainNavClass'] = 'files';
300
				if (isset($_FILES['file'])) {
301
					$this->storage->addFile($_FILES['file']);
302
					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/files');
303
					exit;
304
				}
305
			} elseif ($relativeCmsUri == '/files/get' && isset($request::$get['file'])) {
306
				$this->downloadFile($request::$get['file']);
307
			} elseif ($relativeCmsUri == '/files/delete' && isset($request::$get['file'])) {
308
				$this->storage->deleteFileByName($request::$get['file']);
309
				header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/files');
310
				exit;
311
			}
312
		}
313
314
		/**
315
		 * @param $slug
316
         */
317
		private function downloadFile($slug)
318
		{
319
			$file = $this->storage->getFileByName($slug);
320
			$path = realpath(__DIR__ . '/../../www/files/');
321
			$quoted = sprintf('"%s"', addcslashes(basename($path . '/' . $file->file), '"\\'));
322
			$size   = filesize($path . '/' . $file->file);
323
324
			header('Content-Description: File Transfer');
325
			header('Content-Type: ' . $file->type);
326
			header('Content-Disposition: attachment; filename=' . $quoted);
327
			header('Content-Transfer-Encoding: binary');
328
			header('Connection: Keep-Alive');
329
			header('Expires: 0');
330
			header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
331
			header('Pragma: public');
332
			header('Content-Length: ' . $size);
333
334
			readfile($path . '/' . $file->file);
335
			exit;
336
		}
337
338
		/**
339
		 * @param $request
340
		 * @param $relativeCmsUri
341
         */
342
		private function configurationRouting($request, $relativeCmsUri)
343
		{
344
			if ($relativeCmsUri == '/configuration') {
345
				$this->subTemplate = 'cms/configuration';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'cms/configuration' of type string is incompatible with the declared type null of property $subTemplate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
346
				$this->parameters['mainNavClass'] = 'configuration';
347
			}
348
349
			$this->usersRouting($request, $relativeCmsUri);
350
			$this->documentTypesRouting($request, $relativeCmsUri);
351
			$this->bricksRouting($request, $relativeCmsUri);
352
			$this->imageSetRouting($request, $relativeCmsUri);
353
			$this->applicationComponentRouting($request, $relativeCmsUri);
354
		}
355
356
		/**
357
		 * @param $request
358
		 * @param $relativeCmsUri
359
		 * @throws \Exception
360
         */
361
		private function documentRouting($request, $relativeCmsUri)
362
		{
363
			if ($relativeCmsUri == '/documents/new-document' && isset($request::$get['path'])) {
364
				$this->subTemplate = 'cms/documents/document-form';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'cms/documents/document-form' of type string is incompatible with the declared type null of property $subTemplate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
365
				$this->parameters['mainNavClass'] = 'documents';
366
				$this->parameters['smallestImage'] = $this->storage->getSmallestImageSet()->slug;
367
				if (isset($request::$get['documentType'])) {
368
					if (isset($request::$post['title'], $request::$get['documentType'], $request::$get['path'])) {
369
						$this->storage->addDocument($request::$post);
370
						header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/documents');
371
						exit;
372
					}
373
					$this->parameters['documentType'] = $this->storage->getDocumentTypeBySlug($request::$get['documentType'], true);
374
					$this->parameters['bricks'] = $this->storage->getBricks();
375
				} else {
376
					$this->parameters['documentTypes'] = $this->storage->getDocumentTypes();
377
				}
378
			} elseif ($relativeCmsUri == '/documents/edit-document' && isset($request::$get['slug'])) {
379
				$this->subTemplate = 'cms/documents/document-form';
380
				$this->parameters['mainNavClass'] = 'documents';
381
				$this->parameters['smallestImage'] = $this->storage->getSmallestImageSet()->slug;
382
				if (isset($request::$post['title'], $request::$get['slug'])) {
383
					$this->storage->saveDocument($request::$post);
384
					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/documents');
385
					exit;
386
				}
387
				$this->parameters['document'] = $this->storage->getDocumentBySlug($request::$get['slug']);
388
				$request::$get['path'] = $request::$get['slug'];
389
				$this->parameters['documentType'] = $this->storage->getDocumentTypeBySlug($this->parameters['document']->documentTypeSlug, true);
390
				$this->parameters['bricks'] = $this->storage->getBricks();
391
			} elseif ($relativeCmsUri == '/documents/get-brick' && isset($request::$get['slug'])) {
392
				$this->parameters['smallestImage'] = $this->storage->getSmallestImageSet()->slug;
393
				$this->subTemplate = 'cms/documents/brick';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'cms/documents/brick' of type string is incompatible with the declared type null of property $subTemplate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
394
				$this->parameters['brick'] = $this->storage->getBrickBySlug($request::$get['slug']);
395
				$this->parameters['static'] = $request::$get['static'] === 'true';
396
				if (isset($request::$get['myBrickSlug'])) {
397
					$this->parameters['myBrickSlug'] = $request::$get['myBrickSlug'];
398
				}
399
				$result = new \stdClass();
400
				$result->body = $this->renderTemplate('cms/documents/brick');
401
				$result->rteList = isset($GLOBALS['rteList']) ? $GLOBALS['rteList'] : array();
402
				ob_clean();
403
				header('Content-type: application/json');
404
				die(json_encode($result));
405
			} else if ($relativeCmsUri == '/documents/delete-document' && isset($request::$get['slug'])) {
406
				$this->storage->deleteDocumentBySlug($request::$get['slug']);
407
				header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/documents');
408
				exit;
409
			}
410
		}
411
412
		/**
413
		 * @param $request
414
		 * @param $relativeCmsUri
415
         */
416
		private function folderRouting($request, $relativeCmsUri)
417
		{
418
			if ($relativeCmsUri == '/documents/new-folder' && isset($request::$get['path'])) {
419
				$this->subTemplate = 'cms/documents/folder-form';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'cms/documents/folder-form' of type string is incompatible with the declared type null of property $subTemplate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
420
				$this->parameters['mainNavClass'] = 'documents';
421
				if (isset($request::$post['title'], $request::$post['path'])) {
422
					$this->storage->addDocumentFolder($request::$post);
423
					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/documents');
424
					exit;
425
				}
426
			} else if ($relativeCmsUri == '/documents/edit-folder' && isset($request::$get['slug'])) {
427
428
				$this->subTemplate = 'cms/documents/folder-form';
429
				$folder = $this->storage->getDocumentFolderBySlug($request::$get['slug']);
430
431
				$path = $request::$get['slug'];
432
				$path = explode('/', $path);
433
				array_pop($path);
434
				$path = implode('/', $path);
435
436
				$request::$get['path'] = '/' . $path;
437
438
				if (isset($request::$post['title'], $request::$post['content'])) {
439
					$this->storage->saveDocumentFolder($request::$post);
440
					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/documents');
441
					exit;
442
				}
443
444
				$this->parameters['mainNavClass'] = 'documents';
445
				$this->parameters['folder'] = $folder;
446
			} else if ($relativeCmsUri == '/documents/delete-folder' && isset($request::$get['slug'])) {
447
				$this->storage->deleteDocumentFolderBySlug($request::$get['slug']);
448
				header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/documents');
449
				exit;
450
			}
451
		}
452
453
		/**
454
		 * @param $request
455
		 * @param $relativeCmsUri
456
         */
457
		private function usersRouting($request, $relativeCmsUri)
458
		{
459
			if ($relativeCmsUri == '/configuration/users') {
460
				$this->subTemplate = 'cms/configuration/users';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'cms/configuration/users' of type string is incompatible with the declared type null of property $subTemplate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
461
				$this->parameters['mainNavClass'] = 'configuration';
462
				$this->parameters['users'] = $this->storage->getUsers();
463
			} elseif ($relativeCmsUri == '/configuration/users/new') {
464
				$this->subTemplate = 'cms/configuration/users-form';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'cms/configuration/users-form' of type string is incompatible with the declared type null of property $subTemplate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
465
				$this->parameters['mainNavClass'] = 'configuration';
466
				if (isset($_POST['username'])) {
467
					$this->storage->addUser($request::$post);
468
					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/users');
469
					exit;
470
				}
471
			} elseif ($relativeCmsUri == '/configuration/users/delete' && isset($request::$get['slug'])) {
472
				$this->storage->deleteUserBySlug($request::$get['slug']);
473
				header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/users');
474
				exit;
475
			} elseif ($relativeCmsUri == '/configuration/users/edit' && isset($request::$get['slug'])) {
476
				$this->subTemplate = 'cms/configuration/users-form';
477
				$this->parameters['mainNavClass'] = 'configuration';
478
				$this->parameters['user'] = $this->storage->getUserBySlug($request::$get['slug']);
479
				if (isset($_POST['username'])) {
480
					$this->storage->saveUser($request::$get['slug'], $request::$post);
481
					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/users');
482
					exit;
483
				}
484
			}
485
		}
486
487
		/**
488
		 * @param $request
489
		 * @param $relativeCmsUri
490
         */
491
		private function documentTypesRouting($request, $relativeCmsUri)
492
		{
493
			if ($relativeCmsUri == '/configuration/document-types') {
494
				$this->subTemplate = 'cms/configuration/document-types';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'cms/configuration/document-types' of type string is incompatible with the declared type null of property $subTemplate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
495
				$this->parameters['mainNavClass'] = 'configuration';
496
				$this->parameters['documentTypes'] = $this->storage->getDocumentTypes();
497
			} elseif ($relativeCmsUri == '/configuration/document-types/new') {
498
				$this->subTemplate = 'cms/configuration/document-types-form';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'cms/configuration/document-types-form' of type string is incompatible with the declared type null of property $subTemplate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
499
				$this->parameters['mainNavClass'] = 'configuration';
500
				$bricks = $this->storage->getBricks();
501
				if (isset($request::$post['title'])) {
502
					$this->storage->addDocumentType($request::$post);
503
					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/document-types');
504
					exit;
505
				}
506
				$this->parameters['bricks'] = $bricks;
507
			} elseif ($relativeCmsUri == '/configuration/document-types/edit' && isset($request::$get['slug'])) {
508
				$this->subTemplate = 'cms/configuration/document-types-form';
509
				$this->parameters['mainNavClass'] = 'configuration';
510
				$documentType = $this->storage->getDocumentTypeBySlug($request::$get['slug'], false);
511
				$bricks = $this->storage->getBricks();
512
				if (isset($request::$post['title'])) {
513
					$this->storage->saveDocumentType($request::$get['slug'], $request::$post);
514
					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/document-types');
515
					exit;
516
				}
517
				$this->parameters['documentType'] = $documentType;
518
				$this->parameters['bricks'] = $bricks;
519
			} elseif ($relativeCmsUri == '/configuration/document-types/delete' && isset($request::$get['slug'])) {
520
				$this->storage->deleteDocumentTypeBySlug($request::$get['slug']);
521
				header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/document-types');
522
				exit;
523
			}
524
		}
525
526
		/**
527
		 * @param $request
528
		 * @param $relativeCmsUri
529
         */
530
		private function bricksRouting($request, $relativeCmsUri)
531
		{
532
			if ($relativeCmsUri == '/configuration/bricks') {
533
				$this->subTemplate = 'cms/configuration/bricks';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'cms/configuration/bricks' of type string is incompatible with the declared type null of property $subTemplate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
534
				$this->parameters['mainNavClass'] = 'configuration';
535
				$this->parameters['bricks'] = $this->storage->getBricks();
536
			} elseif ($relativeCmsUri == '/configuration/bricks/new') {
537
				$this->subTemplate = 'cms/configuration/bricks-form';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'cms/configuration/bricks-form' of type string is incompatible with the declared type null of property $subTemplate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
538
				$this->parameters['mainNavClass'] = 'configuration';
539
				if (isset($request::$post['title'])) {
540
					$this->storage->addBrick($request::$post);
541
					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/bricks');
542
					exit;
543
				}
544
			} elseif ($relativeCmsUri == '/configuration/bricks/edit' && isset($request::$get['slug'])) {
545
				$this->subTemplate = 'cms/configuration/bricks-form';
546
				$this->parameters['mainNavClass'] = 'configuration';
547
				$brick = $this->storage->getBrickBySlug($request::$get['slug']);
548
				if (isset($request::$post['title'])) {
549
					$this->storage->saveBrick($request::$get['slug'], $request::$post);
550
					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/bricks');
551
					exit;
552
				}
553
				$this->parameters['brick'] = $brick;
554
			} elseif ($relativeCmsUri == '/configuration/bricks/delete' && isset($request::$get['slug'])) {
555
				$this->storage->deleteBrickBySlug($request::$get['slug']);
556
				header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/bricks');
557
				exit;
558
			} elseif ($relativeCmsUri == '/configuration/image-set') {
559
				$this->subTemplate = 'cms/configuration/image-set';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'cms/configuration/image-set' of type string is incompatible with the declared type null of property $subTemplate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
560
				$this->parameters['mainNavClass'] = 'configuration';
561
				$this->parameters['imageSet'] = $this->storage->getImageSet();
562
			}
563
		}
564
565
		/**
566
		 * @param $request
567
		 * @param $relativeCmsUri
568
         */
569
		private function imageSetRouting($request, $relativeCmsUri)
570
		{
571
			if ($relativeCmsUri == '/configuration/image-set') {
572
				$this->subTemplate = 'cms/configuration/image-set';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'cms/configuration/image-set' of type string is incompatible with the declared type null of property $subTemplate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
573
				$this->parameters['mainNavClass'] = 'configuration';
574
				$this->parameters['imageSet'] = $this->storage->getImageSet();
575
			} elseif ($relativeCmsUri == '/configuration/image-set/edit' && isset($request::$get['slug'])) {
576
				$this->subTemplate = 'cms/configuration/image-set-form';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'cms/configuration/image-set-form' of type string is incompatible with the declared type null of property $subTemplate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
577
				$this->parameters['mainNavClass'] = 'configuration';
578
				$imageSet = $this->storage->getImageSetBySlug($request::$get['slug']);
579
				if (isset($request::$post['title'])) {
580
					$this->storage->saveImageSet($request::$get['slug'], $request::$post);
581
					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/image-set');
582
					exit;
583
				}
584
				$this->parameters['imageSet'] = $imageSet;
585
			} elseif ($relativeCmsUri == '/configuration/image-set/new') {
586
				$this->subTemplate = 'cms/configuration/image-set-form';
587
				$this->parameters['mainNavClass'] = 'configuration';
588
				if (isset($request::$post['title'])) {
589
					$this->storage->addImageSet($request::$post);
590
					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/image-set');
591
					exit;
592
				}
593
			} elseif ($relativeCmsUri == '/configuration/image-set/delete' && isset($request::$get['slug'])) {
594
				$this->storage->deleteImageSetBySlug($request::$get['slug']);
595
				header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/image-set');
596
				exit;
597
			}
598
		}
599
600
		/**
601
		 * @param $request
602
		 * @param $relativeCmsUri
603
         */
604
		private function applicationComponentRouting($request, $relativeCmsUri)
605
		{
606
			if ($relativeCmsUri == '/configuration/application-components') {
607
				$this->subTemplate = 'cms/configuration/application-components';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'cms/configuration/application-components' of type string is incompatible with the declared type null of property $subTemplate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
608
				$this->parameters['mainNavClass'] = 'configuration';
609
				$this->parameters['applicationComponents'] = $this->storage->getApplicationComponents();
610
			} elseif ($relativeCmsUri == '/configuration/application-components/new') {
611
				$this->subTemplate = 'cms/configuration/application-components-form';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'cms/configuration/application-components-form' of type string is incompatible with the declared type null of property $subTemplate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
612
				$this->parameters['mainNavClass'] = 'configuration';
613
				if (isset($request::$post['title'])) {
614
					$this->storage->addApplicationComponent($request::$post);
615
					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/application-components');
616
					exit;
617
				}
618
			} elseif ($relativeCmsUri == '/configuration/application-components/edit' && isset($request::$get['slug'])) {
619
				$this->subTemplate = 'cms/configuration/application-components-form';
620
				$this->parameters['mainNavClass'] = 'configuration';
621
				$applicationComponent = $this->storage->getApplicationComponentBySlug($request::$get['slug']);
622
				if (isset($request::$post['title'])) {
623
					$this->storage->saveApplicationComponent($request::$get['slug'], $request::$post);
624
					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/application-components');
625
					exit;
626
				}
627
				$this->parameters['applicationComponent'] = $applicationComponent;
628
			} elseif ($relativeCmsUri == '/configuration/application-components/delete' && isset($request::$get['slug'])) {
629
				$this->storage->deleteApplicationComponentBySlug($request::$get['slug']);
630
				header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/application-components');
631
				exit;
632
			}
633
		}
634
	}
635
}