Passed
Push — develop ( 1d94a2...f31b27 )
by Jens
02:50
created
cloudcontrol/library/components/cms/FilesRouting.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -30,14 +30,14 @@  discard block
 block discarded – undo
30 30
 			$cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_FILES);
31 31
 			if (isset($_FILES[CmsComponent::FILES_PARAMETER_FILE])) {
32 32
 				$cmsComponent->storage->addFile($_FILES[CmsComponent::FILES_PARAMETER_FILE]);
33
-				header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/files');
33
+				header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/files');
34 34
 				exit;
35 35
 			}
36 36
 		} elseif ($relativeCmsUri == '/files/get' && isset($request::$get[CmsComponent::FILES_PARAMETER_FILE])) {
37 37
 			$this->downloadFile($request::$get[CmsComponent::FILES_PARAMETER_FILE], $cmsComponent);
38 38
 		} elseif ($relativeCmsUri == '/files/delete' && isset($request::$get[CmsComponent::FILES_PARAMETER_FILE])) {
39 39
 			$cmsComponent->storage->deleteFileByName($request::$get[CmsComponent::FILES_PARAMETER_FILE]);
40
-			header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/files');
40
+			header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/files');
41 41
 			exit;
42 42
 		}
43 43
 	}
@@ -49,21 +49,21 @@  discard block
 block discarded – undo
49 49
 	private function downloadFile($slug, $cmsComponent)
50 50
 	{
51 51
 		$file = $cmsComponent->storage->getFileByName($slug);
52
-		$path = realpath(__DIR__ . '/../../../www/files/');
53
-		$quoted = sprintf('"%s"', addcslashes(basename($path . '/' . $file->file), '"\\'));
54
-		$size = filesize($path . '/' . $file->file);
52
+		$path = realpath(__DIR__.'/../../../www/files/');
53
+		$quoted = sprintf('"%s"', addcslashes(basename($path.'/'.$file->file), '"\\'));
54
+		$size = filesize($path.'/'.$file->file);
55 55
 
56 56
 		header('Content-Description: File Transfer');
57
-		header('Content-Type: ' . $file->type);
58
-		header('Content-Disposition: attachment; filename=' . $quoted);
57
+		header('Content-Type: '.$file->type);
58
+		header('Content-Disposition: attachment; filename='.$quoted);
59 59
 		header('Content-Transfer-Encoding: binary');
60 60
 		header('Connection: Keep-Alive');
61 61
 		header('Expires: 0');
62 62
 		header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
63 63
 		header('Pragma: public');
64
-		header('Content-Length: ' . $size);
64
+		header('Content-Length: '.$size);
65 65
 
66
-		readfile($path . '/' . $file->file);
66
+		readfile($path.'/'.$file->file);
67 67
 		exit;
68 68
 	}
69 69
 
Please login to merge, or discard this patch.
cloudcontrol/library/components/CmsComponent.php 2 patches
Indentation   +460 added lines, -460 removed lines patch added patch discarded remove patch
@@ -1,469 +1,469 @@
 block discarded – undo
1 1
 <?php
2 2
 namespace library\components {
3 3
 
4
-    use library\components\cms\DocumentRouting;
4
+	use library\components\cms\DocumentRouting;
5 5
 	use library\components\cms\FilesRouting;
6 6
 	use library\components\cms\ImagesRouting;
7
-    use library\components\cms\SitemapRouting;
8
-    use library\crypt\Crypt;
9
-    use library\storage\Storage;
7
+	use library\components\cms\SitemapRouting;
8
+	use library\crypt\Crypt;
9
+	use library\storage\Storage;
10 10
 
11
-    class CmsComponent extends BaseComponent
12
-    {
13
-        /*
11
+	class CmsComponent extends BaseComponent
12
+	{
13
+		/*
14 14
          * var \library\storage\Storage
15 15
          */
16
-        public $storage;
17
-
18
-        const INVALID_CREDENTIALS_MESSAGE = 'Invalid username / password combination';
19
-
20
-        const MAIN_NAV_CLASS = 'default';
21
-
22
-        const PARAMETER_BLACKLIST_IPS = 'blacklistIps';
23
-        const PARAMETER_BODY = 'body';
24
-        const PARAMETER_BRICK = 'brick';
25
-        const PARAMETER_BRICKS = 'bricks';
26
-        const PARAMETER_CMS_PREFIX = 'cmsPrefix';
27
-        const PARAMETER_DOCUMENT = 'document';
28
-        const PARAMETER_DOCUMENTS = 'documents';
29
-        const PARAMETER_DOCUMENT_TYPE = 'documentType';
30
-        const PARAMETER_DOCUMENT_TYPES = 'documentTypes';
31
-        const PARAMETER_ERROR_MESSAGE = 'errorMsg';
32
-        const PARAMETER_FILES = 'files';
33
-        const PARAMETER_FOLDER = 'folder';
34
-        const PARAMETER_IMAGE = 'image';
35
-        const PARAMETER_IMAGES = 'images';
36
-        const PARAMETER_IMAGE_SET = 'imageSet';
37
-        const PARAMETER_MAIN_NAV_CLASS = 'mainNavClass';
38
-        const PARAMETER_MY_BRICK_SLUG = 'myBrickSlug';
39
-        const PARAMETER_SITEMAP = 'sitemap';
40
-        const PARAMETER_SITEMAP_ITEM = 'sitemapItem';
41
-        const PARAMETER_SMALLEST_IMAGE = 'smallestImage';
42
-        const PARAMETER_STATIC = 'static';
43
-        const PARAMETER_USER = 'user';
44
-        const PARAMETER_USERS = 'users';
45
-        const PARAMETER_USER_RIGHTS = 'userRights';
46
-        const PARAMETER_WHITELIST_IPS = 'whitelistIps';
47
-
48
-        const POST_PARAMETER_COMPONENT = 'component';
49
-        const POST_PARAMETER_PASSWORD = 'password';
50
-        const POST_PARAMETER_SAVE = 'save';
51
-        const POST_PARAMETER_TEMPLATE = 'template';
52
-        const POST_PARAMETER_TITLE = 'title';
53
-        const POST_PARAMETER_USERNAME = 'username';
54
-
55
-        const GET_PARAMETER_PATH = 'path';
56
-        const GET_PARAMETER_SLUG = 'slug';
57
-
58
-        const FILES_PARAMETER_FILE = 'file';
59
-
60
-        const SESSION_PARAMETER_CLOUD_CONTROL = 'cloudcontrol';
61
-
62
-        const LOGIN_TEMPLATE_PATH = 'cms/login';
63
-
64
-        const CONTENT_TYPE_APPLICATION_JSON = 'Content-type:application/json';
65
-
66
-        public $subTemplate = null;
67
-
68
-
69
-        /**
70
-         * @param \library\storage\Storage $storage
71
-         *
72
-         * @return void
73
-         */
74
-        public function run(Storage $storage)
75
-        {
76
-            $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::MAIN_NAV_CLASS;
77
-            $this->storage = $storage;
78
-
79
-            $remoteAddress = $_SERVER['REMOTE_ADDR'];
80
-            $this->checkWhiteList($remoteAddress);
81
-            $this->checkBlackList($remoteAddress);
82
-
83
-            $this->checkLogin();
84
-
85
-            $this->parameters[self::PARAMETER_USER_RIGHTS] = $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]->rights;
86
-
87
-            $this->routing();
88
-        }
89
-
90
-        /**
91
-         * See if a user is logged or wants to log in and
92
-         * takes appropriate actions.
93
-         *
94
-         * @throws \Exception
95
-         */
96
-        protected function checkLogin()
97
-        {
98
-            $request = $this->request;
99
-
100
-            if (!isset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL])) {
101
-                if (isset($request::$post[self::POST_PARAMETER_USERNAME], $request::$post[self::POST_PARAMETER_PASSWORD])) {
102
-                    $user = $this->storage->getUserByUsername($request::$post[self::POST_PARAMETER_USERNAME]);
103
-                    $crypt = new Crypt();
104
-                    if (empty($user)) {
105
-                        $crypt->encrypt($request::$post[self::POST_PARAMETER_PASSWORD], 16); // Buy time, to avoid brute forcing
106
-                        $this->parameters[self::PARAMETER_ERROR_MESSAGE] = self::INVALID_CREDENTIALS_MESSAGE;
107
-                        $this->showLogin();
108
-                    } else {
109
-                        $salt = $user->salt;
110
-                        $password = $user->password;
111
-
112
-                        $passwordCorrect = $crypt->compare($request::$post[self::POST_PARAMETER_PASSWORD], $password, $salt);
113
-
114
-                        if ($passwordCorrect) {
115
-                            $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = $user;
116
-                        } else {
117
-                            $this->parameters[self::PARAMETER_ERROR_MESSAGE] = self::INVALID_CREDENTIALS_MESSAGE;
118
-                            $this->showLogin();
119
-                        }
120
-                    }
121
-                } else {
122
-                    $this->showLogin();
123
-                }
124
-            }
125
-        }
126
-
127
-        /**
128
-         * Overrides normal behaviour and only renders the
129
-         * login screen
130
-         *
131
-         * @throws \Exception
132
-         */
133
-        protected function showLogin()
134
-        {
135
-            $loginTemplatePath = self::LOGIN_TEMPLATE_PATH;
136
-            $this->renderTemplate($loginTemplatePath);
137
-            ob_end_flush();
138
-            exit;
139
-        }
140
-
141
-        /**
142
-         * As an exception, to keep the initial file structure simple
143
-         * the cms implements it's own routing, apart from the regular sitemap functionality
144
-         *
145
-         * @throws \Exception
146
-         */
147
-        protected function routing()
148
-        {
149
-            $relativeCmsUri = $this->getRelativeCmsUri($this->request);
150
-
151
-            $userRights = $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]->rights;
152
-
153
-            if ($relativeCmsUri == '' || $relativeCmsUri == '/') {
154
-                $this->subTemplate = 'cms/dashboard';
155
-            }
156
-
157
-            $this->logOffRouting($this->request, $relativeCmsUri);
158
-
159
-            $this->apiRouting($relativeCmsUri);
160
-
161
-            if (in_array(self::PARAMETER_DOCUMENTS, $userRights)) {
162
-                new DocumentRouting($this->request, $relativeCmsUri, $this);
163
-            }
164
-
165
-            if (in_array(self::PARAMETER_SITEMAP, $userRights)) {
166
-                new SitemapRouting($this->request, $relativeCmsUri, $this);
167
-            }
168
-
169
-            if (in_array(self::PARAMETER_IMAGES, $userRights)) {
170
-                new ImagesRouting($this->request, $relativeCmsUri, $this);
171
-            }
172
-
173
-            if (in_array(self::PARAMETER_FILES, $userRights)) {
174
-                new FilesRouting($this->request, $relativeCmsUri, $this);
175
-            }
176
-
177
-            if (in_array('configuration', $userRights)) {
178
-                $this->configurationRouting($this->request, $relativeCmsUri);
179
-            }
180
-
181
-            if ($this->subTemplate !== null) {
182
-                $this->parameters[self::PARAMETER_BODY] = $this->renderTemplate($this->subTemplate);
183
-            }
184
-        }
185
-
186
-        /**
187
-         * @param $remoteAddress
188
-         * @throws \Exception
189
-         */
190
-        private function checkWhiteList($remoteAddress)
191
-        {
192
-            if (isset($this->parameters[self::PARAMETER_WHITELIST_IPS])) {
193
-                $whitelistIps = explode(',', $this->parameters[self::PARAMETER_WHITELIST_IPS]);
194
-                $whitelistIps = array_map("trim", $whitelistIps);
195
-                if (!in_array($remoteAddress, $whitelistIps)) {
196
-                    throw new \Exception('Ip address ' . $remoteAddress . ' is not on whitelist');
197
-                }
198
-            }
199
-        }
200
-
201
-        /**
202
-         * @param $remoteAddress
203
-         * @throws \Exception
204
-         */
205
-        private function checkBlackList($remoteAddress)
206
-        {
207
-            if (isset($this->parameters[self::PARAMETER_BLACKLIST_IPS])) {
208
-                $blacklistIps = explode(',', $this->parameters[self::PARAMETER_BLACKLIST_IPS]);
209
-                $blacklistIps = array_map("trim", $blacklistIps);
210
-                if (in_array($remoteAddress, $blacklistIps)) {
211
-                    throw new \Exception('Ip address ' . $remoteAddress . ' is on blacklist');
212
-                }
213
-            }
214
-        }
215
-
216
-        /**
217
-         * @param $request
218
-         * @return mixed|string
219
-         */
220
-        private function getRelativeCmsUri($request)
221
-        {
222
-            // TODO Use regex match parameter instead of calculating relative uri
223
-            $pos = strpos($request::$relativeUri, $this->parameters[self::PARAMETER_CMS_PREFIX]);
224
-            $relativeCmsUri = '/';
225
-            if ($pos !== false) {
226
-                $relativeCmsUri = substr_replace($request::$relativeUri, '', $pos, strlen($this->parameters[self::PARAMETER_CMS_PREFIX]));
227
-            }
228
-            return $relativeCmsUri;
229
-        }
230
-
231
-        /**
232
-         * @param $relativeCmsUri
233
-         */
234
-        private function apiRouting($relativeCmsUri)
235
-        {
236
-            if ($relativeCmsUri == '/images.json') {
237
-                header(self::CONTENT_TYPE_APPLICATION_JSON);
238
-                die(json_encode($this->storage->getImages()));
239
-            } elseif ($relativeCmsUri == '/files.json') {
240
-                header(self::CONTENT_TYPE_APPLICATION_JSON);
241
-                die(json_encode($this->storage->getFiles()));
242
-            } elseif ($relativeCmsUri == '/documents.json') {
243
-                header(self::CONTENT_TYPE_APPLICATION_JSON);
244
-                die(json_encode($this->storage->getDocuments()));
245
-            }
246
-        }
247
-
248
-        /**
249
-         * @param $request
250
-         * @param $relativeCmsUri
251
-         */
252
-        private function configurationRouting($request, $relativeCmsUri)
253
-        {
254
-            if ($relativeCmsUri == '/configuration') {
255
-                $this->subTemplate = 'cms/configuration';
256
-                $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
257
-            }
258
-
259
-            $this->usersRouting($request, $relativeCmsUri);
260
-            $this->documentTypesRouting($request, $relativeCmsUri);
261
-            $this->bricksRouting($request, $relativeCmsUri);
262
-            $this->imageSetRouting($request, $relativeCmsUri);
263
-            $this->applicationComponentRouting($request, $relativeCmsUri);
264
-        }
265
-
266
-
267
-        /**
268
-         * @param $request
269
-         * @param $relativeCmsUri
270
-         */
271
-        private function usersRouting($request, $relativeCmsUri)
272
-        {
273
-            if ($relativeCmsUri == '/configuration/users') {
274
-                $this->subTemplate = 'cms/configuration/users';
275
-                $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
276
-                $this->parameters[self::PARAMETER_USERS] = $this->storage->getUsers();
277
-            } elseif ($relativeCmsUri == '/configuration/users/new') {
278
-                $this->subTemplate = 'cms/configuration/users-form';
279
-                $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
280
-                if (isset($_POST[self::POST_PARAMETER_USERNAME])) {
281
-                    $this->storage->addUser($request::$post);
282
-                    header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/users');
283
-                    exit;
284
-                }
285
-            } elseif ($relativeCmsUri == '/configuration/users/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
286
-                $this->storage->deleteUserBySlug($request::$get[self::GET_PARAMETER_SLUG]);
287
-                header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/users');
288
-                exit;
289
-            } elseif ($relativeCmsUri == '/configuration/users/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
290
-                $this->subTemplate = 'cms/configuration/users-form';
291
-                $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
292
-                $this->parameters[self::PARAMETER_USER] = $this->storage->getUserBySlug($request::$get[self::GET_PARAMETER_SLUG]);
293
-                if (isset($_POST[self::POST_PARAMETER_USERNAME])) {
294
-                    $this->storage->saveUser($request::$get[self::GET_PARAMETER_SLUG], $request::$post);
295
-                    header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/users');
296
-                    exit;
297
-                }
298
-            }
299
-        }
300
-
301
-        /**
302
-         * @param $request
303
-         * @param $relativeCmsUri
304
-         */
305
-        private function documentTypesRouting($request, $relativeCmsUri)
306
-        {
307
-            if ($relativeCmsUri == '/configuration/document-types') {
308
-                $this->subTemplate = 'cms/configuration/document-types';
309
-                $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
310
-                $this->parameters[self::PARAMETER_DOCUMENT_TYPES] = $this->storage->getDocumentTypes();
311
-            } elseif ($relativeCmsUri == '/configuration/document-types/new') {
312
-                $this->subTemplate = 'cms/configuration/document-types-form';
313
-                $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
314
-                $bricks = $this->storage->getBricks();
315
-                if (isset($request::$post[self::POST_PARAMETER_TITLE])) {
316
-                    $this->storage->addDocumentType($request::$post);
317
-                    header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/document-types');
318
-                    exit;
319
-                }
320
-                $this->parameters[self::PARAMETER_BRICKS] = $bricks;
321
-            } elseif ($relativeCmsUri == '/configuration/document-types/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
322
-                $this->subTemplate = 'cms/configuration/document-types-form';
323
-                $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
324
-                $documentType = $this->storage->getDocumentTypeBySlug($request::$get[self::GET_PARAMETER_SLUG], false);
325
-                $bricks = $this->storage->getBricks();
326
-                if (isset($request::$post[self::POST_PARAMETER_TITLE])) {
327
-                    $this->storage->saveDocumentType($request::$get[self::GET_PARAMETER_SLUG], $request::$post);
328
-                    header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/document-types');
329
-                    exit;
330
-                }
331
-                $this->parameters[self::PARAMETER_DOCUMENT_TYPE] = $documentType;
332
-                $this->parameters[self::PARAMETER_BRICKS] = $bricks;
333
-            } elseif ($relativeCmsUri == '/configuration/document-types/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
334
-                $this->storage->deleteDocumentTypeBySlug($request::$get[self::GET_PARAMETER_SLUG]);
335
-                header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/document-types');
336
-                exit;
337
-            }
338
-        }
339
-
340
-        /**
341
-         * @param $request
342
-         * @param $relativeCmsUri
343
-         */
344
-        private function bricksRouting($request, $relativeCmsUri)
345
-        {
346
-            if ($relativeCmsUri == '/configuration/bricks') {
347
-                $this->subTemplate = 'cms/configuration/bricks';
348
-                $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
349
-                $this->parameters[self::PARAMETER_BRICKS] = $this->storage->getBricks();
350
-            } elseif ($relativeCmsUri == '/configuration/bricks/new') {
351
-                $this->subTemplate = 'cms/configuration/bricks-form';
352
-                $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
353
-                if (isset($request::$post[self::POST_PARAMETER_TITLE])) {
354
-                    $this->storage->addBrick($request::$post);
355
-                    header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/bricks');
356
-                    exit;
357
-                }
358
-            } elseif ($relativeCmsUri == '/configuration/bricks/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
359
-                $this->subTemplate = 'cms/configuration/bricks-form';
360
-                $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
361
-                $brick = $this->storage->getBrickBySlug($request::$get[self::GET_PARAMETER_SLUG]);
362
-                if (isset($request::$post[self::POST_PARAMETER_TITLE])) {
363
-                    $this->storage->saveBrick($request::$get[self::GET_PARAMETER_SLUG], $request::$post);
364
-                    header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/bricks');
365
-                    exit;
366
-                }
367
-                $this->parameters[self::PARAMETER_BRICK] = $brick;
368
-            } elseif ($relativeCmsUri == '/configuration/bricks/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
369
-                $this->storage->deleteBrickBySlug($request::$get[self::GET_PARAMETER_SLUG]);
370
-                header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/bricks');
371
-                exit;
372
-            } elseif ($relativeCmsUri == '/configuration/image-set') {
373
-                $this->subTemplate = 'cms/configuration/image-set';
374
-                $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
375
-                $this->parameters[self::PARAMETER_IMAGE_SET] = $this->storage->getImageSet();
376
-            }
377
-        }
378
-
379
-        /**
380
-         * @param $request
381
-         * @param $relativeCmsUri
382
-         */
383
-        private function imageSetRouting($request, $relativeCmsUri)
384
-        {
385
-            if ($relativeCmsUri == '/configuration/image-set') {
386
-                $this->subTemplate = 'cms/configuration/image-set';
387
-                $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
388
-                $this->parameters[self::PARAMETER_IMAGE_SET] = $this->storage->getImageSet();
389
-            } elseif ($relativeCmsUri == '/configuration/image-set/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
390
-                $this->subTemplate = 'cms/configuration/image-set-form';
391
-                $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
392
-                $imageSet = $this->storage->getImageSetBySlug($request::$get[self::GET_PARAMETER_SLUG]);
393
-                if (isset($request::$post[self::POST_PARAMETER_TITLE])) {
394
-                    $this->storage->saveImageSet($request::$get[self::GET_PARAMETER_SLUG], $request::$post);
395
-                    header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/image-set');
396
-                    exit;
397
-                }
398
-                $this->parameters[self::PARAMETER_IMAGE_SET] = $imageSet;
399
-            } elseif ($relativeCmsUri == '/configuration/image-set/new') {
400
-                $this->subTemplate = 'cms/configuration/image-set-form';
401
-                $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
402
-                if (isset($request::$post[self::POST_PARAMETER_TITLE])) {
403
-                    $this->storage->addImageSet($request::$post);
404
-                    header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/image-set');
405
-                    exit;
406
-                }
407
-            } elseif ($relativeCmsUri == '/configuration/image-set/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
408
-                $this->storage->deleteImageSetBySlug($request::$get[self::GET_PARAMETER_SLUG]);
409
-                header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/image-set');
410
-                exit;
411
-            }
412
-        }
413
-
414
-        /**
415
-         * @param $request
416
-         * @param $relativeCmsUri
417
-         */
418
-        private function applicationComponentRouting($request, $relativeCmsUri)
419
-        {
420
-            if ($relativeCmsUri == '/configuration/application-components') {
421
-                $this->subTemplate = 'cms/configuration/application-components';
422
-                $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
423
-                $this->parameters['applicationComponents'] = $this->storage->getApplicationComponents();
424
-            } elseif ($relativeCmsUri == '/configuration/application-components/new') {
425
-                $this->subTemplate = 'cms/configuration/application-components-form';
426
-                $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
427
-                if (isset($request::$post[self::POST_PARAMETER_TITLE])) {
428
-                    $this->storage->addApplicationComponent($request::$post);
429
-                    header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/application-components');
430
-                    exit;
431
-                }
432
-            } elseif ($relativeCmsUri == '/configuration/application-components/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
433
-                $this->subTemplate = 'cms/configuration/application-components-form';
434
-                $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
435
-                $applicationComponent = $this->storage->getApplicationComponentBySlug($request::$get[self::GET_PARAMETER_SLUG]);
436
-                if (isset($request::$post[self::POST_PARAMETER_TITLE])) {
437
-                    $this->storage->saveApplicationComponent($request::$get[self::GET_PARAMETER_SLUG], $request::$post);
438
-                    header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/application-components');
439
-                    exit;
440
-                }
441
-                $this->parameters['applicationComponent'] = $applicationComponent;
442
-            } elseif ($relativeCmsUri == '/configuration/application-components/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
443
-                $this->storage->deleteApplicationComponentBySlug($request::$get[self::GET_PARAMETER_SLUG]);
444
-                header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/application-components');
445
-                exit;
446
-            }
447
-        }
448
-
449
-        private function logOffRouting($request, $relativeCmsUri)
450
-        {
451
-            if ($relativeCmsUri == '/log-off') {
452
-                $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = null;
453
-                unset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]);
454
-                header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX]);
455
-                exit;
456
-            }
457
-        }
458
-
459
-        public function setParameter($parameterName, $parameterValue)
460
-        {
461
-            $this->parameters[$parameterName] = $parameterValue;
462
-        }
463
-
464
-        public function getParameter($parameterName)
465
-        {
466
-            return $this->parameters[$parameterName];
467
-        }
468
-    }
16
+		public $storage;
17
+
18
+		const INVALID_CREDENTIALS_MESSAGE = 'Invalid username / password combination';
19
+
20
+		const MAIN_NAV_CLASS = 'default';
21
+
22
+		const PARAMETER_BLACKLIST_IPS = 'blacklistIps';
23
+		const PARAMETER_BODY = 'body';
24
+		const PARAMETER_BRICK = 'brick';
25
+		const PARAMETER_BRICKS = 'bricks';
26
+		const PARAMETER_CMS_PREFIX = 'cmsPrefix';
27
+		const PARAMETER_DOCUMENT = 'document';
28
+		const PARAMETER_DOCUMENTS = 'documents';
29
+		const PARAMETER_DOCUMENT_TYPE = 'documentType';
30
+		const PARAMETER_DOCUMENT_TYPES = 'documentTypes';
31
+		const PARAMETER_ERROR_MESSAGE = 'errorMsg';
32
+		const PARAMETER_FILES = 'files';
33
+		const PARAMETER_FOLDER = 'folder';
34
+		const PARAMETER_IMAGE = 'image';
35
+		const PARAMETER_IMAGES = 'images';
36
+		const PARAMETER_IMAGE_SET = 'imageSet';
37
+		const PARAMETER_MAIN_NAV_CLASS = 'mainNavClass';
38
+		const PARAMETER_MY_BRICK_SLUG = 'myBrickSlug';
39
+		const PARAMETER_SITEMAP = 'sitemap';
40
+		const PARAMETER_SITEMAP_ITEM = 'sitemapItem';
41
+		const PARAMETER_SMALLEST_IMAGE = 'smallestImage';
42
+		const PARAMETER_STATIC = 'static';
43
+		const PARAMETER_USER = 'user';
44
+		const PARAMETER_USERS = 'users';
45
+		const PARAMETER_USER_RIGHTS = 'userRights';
46
+		const PARAMETER_WHITELIST_IPS = 'whitelistIps';
47
+
48
+		const POST_PARAMETER_COMPONENT = 'component';
49
+		const POST_PARAMETER_PASSWORD = 'password';
50
+		const POST_PARAMETER_SAVE = 'save';
51
+		const POST_PARAMETER_TEMPLATE = 'template';
52
+		const POST_PARAMETER_TITLE = 'title';
53
+		const POST_PARAMETER_USERNAME = 'username';
54
+
55
+		const GET_PARAMETER_PATH = 'path';
56
+		const GET_PARAMETER_SLUG = 'slug';
57
+
58
+		const FILES_PARAMETER_FILE = 'file';
59
+
60
+		const SESSION_PARAMETER_CLOUD_CONTROL = 'cloudcontrol';
61
+
62
+		const LOGIN_TEMPLATE_PATH = 'cms/login';
63
+
64
+		const CONTENT_TYPE_APPLICATION_JSON = 'Content-type:application/json';
65
+
66
+		public $subTemplate = null;
67
+
68
+
69
+		/**
70
+		 * @param \library\storage\Storage $storage
71
+		 *
72
+		 * @return void
73
+		 */
74
+		public function run(Storage $storage)
75
+		{
76
+			$this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::MAIN_NAV_CLASS;
77
+			$this->storage = $storage;
78
+
79
+			$remoteAddress = $_SERVER['REMOTE_ADDR'];
80
+			$this->checkWhiteList($remoteAddress);
81
+			$this->checkBlackList($remoteAddress);
82
+
83
+			$this->checkLogin();
84
+
85
+			$this->parameters[self::PARAMETER_USER_RIGHTS] = $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]->rights;
86
+
87
+			$this->routing();
88
+		}
89
+
90
+		/**
91
+		 * See if a user is logged or wants to log in and
92
+		 * takes appropriate actions.
93
+		 *
94
+		 * @throws \Exception
95
+		 */
96
+		protected function checkLogin()
97
+		{
98
+			$request = $this->request;
99
+
100
+			if (!isset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL])) {
101
+				if (isset($request::$post[self::POST_PARAMETER_USERNAME], $request::$post[self::POST_PARAMETER_PASSWORD])) {
102
+					$user = $this->storage->getUserByUsername($request::$post[self::POST_PARAMETER_USERNAME]);
103
+					$crypt = new Crypt();
104
+					if (empty($user)) {
105
+						$crypt->encrypt($request::$post[self::POST_PARAMETER_PASSWORD], 16); // Buy time, to avoid brute forcing
106
+						$this->parameters[self::PARAMETER_ERROR_MESSAGE] = self::INVALID_CREDENTIALS_MESSAGE;
107
+						$this->showLogin();
108
+					} else {
109
+						$salt = $user->salt;
110
+						$password = $user->password;
111
+
112
+						$passwordCorrect = $crypt->compare($request::$post[self::POST_PARAMETER_PASSWORD], $password, $salt);
113
+
114
+						if ($passwordCorrect) {
115
+							$_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = $user;
116
+						} else {
117
+							$this->parameters[self::PARAMETER_ERROR_MESSAGE] = self::INVALID_CREDENTIALS_MESSAGE;
118
+							$this->showLogin();
119
+						}
120
+					}
121
+				} else {
122
+					$this->showLogin();
123
+				}
124
+			}
125
+		}
126
+
127
+		/**
128
+		 * Overrides normal behaviour and only renders the
129
+		 * login screen
130
+		 *
131
+		 * @throws \Exception
132
+		 */
133
+		protected function showLogin()
134
+		{
135
+			$loginTemplatePath = self::LOGIN_TEMPLATE_PATH;
136
+			$this->renderTemplate($loginTemplatePath);
137
+			ob_end_flush();
138
+			exit;
139
+		}
140
+
141
+		/**
142
+		 * As an exception, to keep the initial file structure simple
143
+		 * the cms implements it's own routing, apart from the regular sitemap functionality
144
+		 *
145
+		 * @throws \Exception
146
+		 */
147
+		protected function routing()
148
+		{
149
+			$relativeCmsUri = $this->getRelativeCmsUri($this->request);
150
+
151
+			$userRights = $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]->rights;
152
+
153
+			if ($relativeCmsUri == '' || $relativeCmsUri == '/') {
154
+				$this->subTemplate = 'cms/dashboard';
155
+			}
156
+
157
+			$this->logOffRouting($this->request, $relativeCmsUri);
158
+
159
+			$this->apiRouting($relativeCmsUri);
160
+
161
+			if (in_array(self::PARAMETER_DOCUMENTS, $userRights)) {
162
+				new DocumentRouting($this->request, $relativeCmsUri, $this);
163
+			}
164
+
165
+			if (in_array(self::PARAMETER_SITEMAP, $userRights)) {
166
+				new SitemapRouting($this->request, $relativeCmsUri, $this);
167
+			}
168
+
169
+			if (in_array(self::PARAMETER_IMAGES, $userRights)) {
170
+				new ImagesRouting($this->request, $relativeCmsUri, $this);
171
+			}
172
+
173
+			if (in_array(self::PARAMETER_FILES, $userRights)) {
174
+				new FilesRouting($this->request, $relativeCmsUri, $this);
175
+			}
176
+
177
+			if (in_array('configuration', $userRights)) {
178
+				$this->configurationRouting($this->request, $relativeCmsUri);
179
+			}
180
+
181
+			if ($this->subTemplate !== null) {
182
+				$this->parameters[self::PARAMETER_BODY] = $this->renderTemplate($this->subTemplate);
183
+			}
184
+		}
185
+
186
+		/**
187
+		 * @param $remoteAddress
188
+		 * @throws \Exception
189
+		 */
190
+		private function checkWhiteList($remoteAddress)
191
+		{
192
+			if (isset($this->parameters[self::PARAMETER_WHITELIST_IPS])) {
193
+				$whitelistIps = explode(',', $this->parameters[self::PARAMETER_WHITELIST_IPS]);
194
+				$whitelistIps = array_map("trim", $whitelistIps);
195
+				if (!in_array($remoteAddress, $whitelistIps)) {
196
+					throw new \Exception('Ip address ' . $remoteAddress . ' is not on whitelist');
197
+				}
198
+			}
199
+		}
200
+
201
+		/**
202
+		 * @param $remoteAddress
203
+		 * @throws \Exception
204
+		 */
205
+		private function checkBlackList($remoteAddress)
206
+		{
207
+			if (isset($this->parameters[self::PARAMETER_BLACKLIST_IPS])) {
208
+				$blacklistIps = explode(',', $this->parameters[self::PARAMETER_BLACKLIST_IPS]);
209
+				$blacklistIps = array_map("trim", $blacklistIps);
210
+				if (in_array($remoteAddress, $blacklistIps)) {
211
+					throw new \Exception('Ip address ' . $remoteAddress . ' is on blacklist');
212
+				}
213
+			}
214
+		}
215
+
216
+		/**
217
+		 * @param $request
218
+		 * @return mixed|string
219
+		 */
220
+		private function getRelativeCmsUri($request)
221
+		{
222
+			// TODO Use regex match parameter instead of calculating relative uri
223
+			$pos = strpos($request::$relativeUri, $this->parameters[self::PARAMETER_CMS_PREFIX]);
224
+			$relativeCmsUri = '/';
225
+			if ($pos !== false) {
226
+				$relativeCmsUri = substr_replace($request::$relativeUri, '', $pos, strlen($this->parameters[self::PARAMETER_CMS_PREFIX]));
227
+			}
228
+			return $relativeCmsUri;
229
+		}
230
+
231
+		/**
232
+		 * @param $relativeCmsUri
233
+		 */
234
+		private function apiRouting($relativeCmsUri)
235
+		{
236
+			if ($relativeCmsUri == '/images.json') {
237
+				header(self::CONTENT_TYPE_APPLICATION_JSON);
238
+				die(json_encode($this->storage->getImages()));
239
+			} elseif ($relativeCmsUri == '/files.json') {
240
+				header(self::CONTENT_TYPE_APPLICATION_JSON);
241
+				die(json_encode($this->storage->getFiles()));
242
+			} elseif ($relativeCmsUri == '/documents.json') {
243
+				header(self::CONTENT_TYPE_APPLICATION_JSON);
244
+				die(json_encode($this->storage->getDocuments()));
245
+			}
246
+		}
247
+
248
+		/**
249
+		 * @param $request
250
+		 * @param $relativeCmsUri
251
+		 */
252
+		private function configurationRouting($request, $relativeCmsUri)
253
+		{
254
+			if ($relativeCmsUri == '/configuration') {
255
+				$this->subTemplate = 'cms/configuration';
256
+				$this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
257
+			}
258
+
259
+			$this->usersRouting($request, $relativeCmsUri);
260
+			$this->documentTypesRouting($request, $relativeCmsUri);
261
+			$this->bricksRouting($request, $relativeCmsUri);
262
+			$this->imageSetRouting($request, $relativeCmsUri);
263
+			$this->applicationComponentRouting($request, $relativeCmsUri);
264
+		}
265
+
266
+
267
+		/**
268
+		 * @param $request
269
+		 * @param $relativeCmsUri
270
+		 */
271
+		private function usersRouting($request, $relativeCmsUri)
272
+		{
273
+			if ($relativeCmsUri == '/configuration/users') {
274
+				$this->subTemplate = 'cms/configuration/users';
275
+				$this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
276
+				$this->parameters[self::PARAMETER_USERS] = $this->storage->getUsers();
277
+			} elseif ($relativeCmsUri == '/configuration/users/new') {
278
+				$this->subTemplate = 'cms/configuration/users-form';
279
+				$this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
280
+				if (isset($_POST[self::POST_PARAMETER_USERNAME])) {
281
+					$this->storage->addUser($request::$post);
282
+					header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/users');
283
+					exit;
284
+				}
285
+			} elseif ($relativeCmsUri == '/configuration/users/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
286
+				$this->storage->deleteUserBySlug($request::$get[self::GET_PARAMETER_SLUG]);
287
+				header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/users');
288
+				exit;
289
+			} elseif ($relativeCmsUri == '/configuration/users/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
290
+				$this->subTemplate = 'cms/configuration/users-form';
291
+				$this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
292
+				$this->parameters[self::PARAMETER_USER] = $this->storage->getUserBySlug($request::$get[self::GET_PARAMETER_SLUG]);
293
+				if (isset($_POST[self::POST_PARAMETER_USERNAME])) {
294
+					$this->storage->saveUser($request::$get[self::GET_PARAMETER_SLUG], $request::$post);
295
+					header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/users');
296
+					exit;
297
+				}
298
+			}
299
+		}
300
+
301
+		/**
302
+		 * @param $request
303
+		 * @param $relativeCmsUri
304
+		 */
305
+		private function documentTypesRouting($request, $relativeCmsUri)
306
+		{
307
+			if ($relativeCmsUri == '/configuration/document-types') {
308
+				$this->subTemplate = 'cms/configuration/document-types';
309
+				$this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
310
+				$this->parameters[self::PARAMETER_DOCUMENT_TYPES] = $this->storage->getDocumentTypes();
311
+			} elseif ($relativeCmsUri == '/configuration/document-types/new') {
312
+				$this->subTemplate = 'cms/configuration/document-types-form';
313
+				$this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
314
+				$bricks = $this->storage->getBricks();
315
+				if (isset($request::$post[self::POST_PARAMETER_TITLE])) {
316
+					$this->storage->addDocumentType($request::$post);
317
+					header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/document-types');
318
+					exit;
319
+				}
320
+				$this->parameters[self::PARAMETER_BRICKS] = $bricks;
321
+			} elseif ($relativeCmsUri == '/configuration/document-types/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
322
+				$this->subTemplate = 'cms/configuration/document-types-form';
323
+				$this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
324
+				$documentType = $this->storage->getDocumentTypeBySlug($request::$get[self::GET_PARAMETER_SLUG], false);
325
+				$bricks = $this->storage->getBricks();
326
+				if (isset($request::$post[self::POST_PARAMETER_TITLE])) {
327
+					$this->storage->saveDocumentType($request::$get[self::GET_PARAMETER_SLUG], $request::$post);
328
+					header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/document-types');
329
+					exit;
330
+				}
331
+				$this->parameters[self::PARAMETER_DOCUMENT_TYPE] = $documentType;
332
+				$this->parameters[self::PARAMETER_BRICKS] = $bricks;
333
+			} elseif ($relativeCmsUri == '/configuration/document-types/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
334
+				$this->storage->deleteDocumentTypeBySlug($request::$get[self::GET_PARAMETER_SLUG]);
335
+				header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/document-types');
336
+				exit;
337
+			}
338
+		}
339
+
340
+		/**
341
+		 * @param $request
342
+		 * @param $relativeCmsUri
343
+		 */
344
+		private function bricksRouting($request, $relativeCmsUri)
345
+		{
346
+			if ($relativeCmsUri == '/configuration/bricks') {
347
+				$this->subTemplate = 'cms/configuration/bricks';
348
+				$this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
349
+				$this->parameters[self::PARAMETER_BRICKS] = $this->storage->getBricks();
350
+			} elseif ($relativeCmsUri == '/configuration/bricks/new') {
351
+				$this->subTemplate = 'cms/configuration/bricks-form';
352
+				$this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
353
+				if (isset($request::$post[self::POST_PARAMETER_TITLE])) {
354
+					$this->storage->addBrick($request::$post);
355
+					header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/bricks');
356
+					exit;
357
+				}
358
+			} elseif ($relativeCmsUri == '/configuration/bricks/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
359
+				$this->subTemplate = 'cms/configuration/bricks-form';
360
+				$this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
361
+				$brick = $this->storage->getBrickBySlug($request::$get[self::GET_PARAMETER_SLUG]);
362
+				if (isset($request::$post[self::POST_PARAMETER_TITLE])) {
363
+					$this->storage->saveBrick($request::$get[self::GET_PARAMETER_SLUG], $request::$post);
364
+					header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/bricks');
365
+					exit;
366
+				}
367
+				$this->parameters[self::PARAMETER_BRICK] = $brick;
368
+			} elseif ($relativeCmsUri == '/configuration/bricks/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
369
+				$this->storage->deleteBrickBySlug($request::$get[self::GET_PARAMETER_SLUG]);
370
+				header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/bricks');
371
+				exit;
372
+			} elseif ($relativeCmsUri == '/configuration/image-set') {
373
+				$this->subTemplate = 'cms/configuration/image-set';
374
+				$this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
375
+				$this->parameters[self::PARAMETER_IMAGE_SET] = $this->storage->getImageSet();
376
+			}
377
+		}
378
+
379
+		/**
380
+		 * @param $request
381
+		 * @param $relativeCmsUri
382
+		 */
383
+		private function imageSetRouting($request, $relativeCmsUri)
384
+		{
385
+			if ($relativeCmsUri == '/configuration/image-set') {
386
+				$this->subTemplate = 'cms/configuration/image-set';
387
+				$this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
388
+				$this->parameters[self::PARAMETER_IMAGE_SET] = $this->storage->getImageSet();
389
+			} elseif ($relativeCmsUri == '/configuration/image-set/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
390
+				$this->subTemplate = 'cms/configuration/image-set-form';
391
+				$this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
392
+				$imageSet = $this->storage->getImageSetBySlug($request::$get[self::GET_PARAMETER_SLUG]);
393
+				if (isset($request::$post[self::POST_PARAMETER_TITLE])) {
394
+					$this->storage->saveImageSet($request::$get[self::GET_PARAMETER_SLUG], $request::$post);
395
+					header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/image-set');
396
+					exit;
397
+				}
398
+				$this->parameters[self::PARAMETER_IMAGE_SET] = $imageSet;
399
+			} elseif ($relativeCmsUri == '/configuration/image-set/new') {
400
+				$this->subTemplate = 'cms/configuration/image-set-form';
401
+				$this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
402
+				if (isset($request::$post[self::POST_PARAMETER_TITLE])) {
403
+					$this->storage->addImageSet($request::$post);
404
+					header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/image-set');
405
+					exit;
406
+				}
407
+			} elseif ($relativeCmsUri == '/configuration/image-set/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
408
+				$this->storage->deleteImageSetBySlug($request::$get[self::GET_PARAMETER_SLUG]);
409
+				header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/image-set');
410
+				exit;
411
+			}
412
+		}
413
+
414
+		/**
415
+		 * @param $request
416
+		 * @param $relativeCmsUri
417
+		 */
418
+		private function applicationComponentRouting($request, $relativeCmsUri)
419
+		{
420
+			if ($relativeCmsUri == '/configuration/application-components') {
421
+				$this->subTemplate = 'cms/configuration/application-components';
422
+				$this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
423
+				$this->parameters['applicationComponents'] = $this->storage->getApplicationComponents();
424
+			} elseif ($relativeCmsUri == '/configuration/application-components/new') {
425
+				$this->subTemplate = 'cms/configuration/application-components-form';
426
+				$this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
427
+				if (isset($request::$post[self::POST_PARAMETER_TITLE])) {
428
+					$this->storage->addApplicationComponent($request::$post);
429
+					header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/application-components');
430
+					exit;
431
+				}
432
+			} elseif ($relativeCmsUri == '/configuration/application-components/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
433
+				$this->subTemplate = 'cms/configuration/application-components-form';
434
+				$this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
435
+				$applicationComponent = $this->storage->getApplicationComponentBySlug($request::$get[self::GET_PARAMETER_SLUG]);
436
+				if (isset($request::$post[self::POST_PARAMETER_TITLE])) {
437
+					$this->storage->saveApplicationComponent($request::$get[self::GET_PARAMETER_SLUG], $request::$post);
438
+					header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/application-components');
439
+					exit;
440
+				}
441
+				$this->parameters['applicationComponent'] = $applicationComponent;
442
+			} elseif ($relativeCmsUri == '/configuration/application-components/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
443
+				$this->storage->deleteApplicationComponentBySlug($request::$get[self::GET_PARAMETER_SLUG]);
444
+				header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/application-components');
445
+				exit;
446
+			}
447
+		}
448
+
449
+		private function logOffRouting($request, $relativeCmsUri)
450
+		{
451
+			if ($relativeCmsUri == '/log-off') {
452
+				$_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = null;
453
+				unset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]);
454
+				header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX]);
455
+				exit;
456
+			}
457
+		}
458
+
459
+		public function setParameter($parameterName, $parameterValue)
460
+		{
461
+			$this->parameters[$parameterName] = $parameterValue;
462
+		}
463
+
464
+		public function getParameter($parameterName)
465
+		{
466
+			return $this->parameters[$parameterName];
467
+		}
468
+	}
469 469
 }
470 470
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
                 $whitelistIps = explode(',', $this->parameters[self::PARAMETER_WHITELIST_IPS]);
194 194
                 $whitelistIps = array_map("trim", $whitelistIps);
195 195
                 if (!in_array($remoteAddress, $whitelistIps)) {
196
-                    throw new \Exception('Ip address ' . $remoteAddress . ' is not on whitelist');
196
+                    throw new \Exception('Ip address '.$remoteAddress.' is not on whitelist');
197 197
                 }
198 198
             }
199 199
         }
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
                 $blacklistIps = explode(',', $this->parameters[self::PARAMETER_BLACKLIST_IPS]);
209 209
                 $blacklistIps = array_map("trim", $blacklistIps);
210 210
                 if (in_array($remoteAddress, $blacklistIps)) {
211
-                    throw new \Exception('Ip address ' . $remoteAddress . ' is on blacklist');
211
+                    throw new \Exception('Ip address '.$remoteAddress.' is on blacklist');
212 212
                 }
213 213
             }
214 214
         }
@@ -279,12 +279,12 @@  discard block
 block discarded – undo
279 279
                 $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
280 280
                 if (isset($_POST[self::POST_PARAMETER_USERNAME])) {
281 281
                     $this->storage->addUser($request::$post);
282
-                    header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/users');
282
+                    header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/users');
283 283
                     exit;
284 284
                 }
285 285
             } elseif ($relativeCmsUri == '/configuration/users/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
286 286
                 $this->storage->deleteUserBySlug($request::$get[self::GET_PARAMETER_SLUG]);
287
-                header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/users');
287
+                header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/users');
288 288
                 exit;
289 289
             } elseif ($relativeCmsUri == '/configuration/users/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
290 290
                 $this->subTemplate = 'cms/configuration/users-form';
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
                 $this->parameters[self::PARAMETER_USER] = $this->storage->getUserBySlug($request::$get[self::GET_PARAMETER_SLUG]);
293 293
                 if (isset($_POST[self::POST_PARAMETER_USERNAME])) {
294 294
                     $this->storage->saveUser($request::$get[self::GET_PARAMETER_SLUG], $request::$post);
295
-                    header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/users');
295
+                    header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/users');
296 296
                     exit;
297 297
                 }
298 298
             }
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
                 $bricks = $this->storage->getBricks();
315 315
                 if (isset($request::$post[self::POST_PARAMETER_TITLE])) {
316 316
                     $this->storage->addDocumentType($request::$post);
317
-                    header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/document-types');
317
+                    header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/document-types');
318 318
                     exit;
319 319
                 }
320 320
                 $this->parameters[self::PARAMETER_BRICKS] = $bricks;
@@ -325,14 +325,14 @@  discard block
 block discarded – undo
325 325
                 $bricks = $this->storage->getBricks();
326 326
                 if (isset($request::$post[self::POST_PARAMETER_TITLE])) {
327 327
                     $this->storage->saveDocumentType($request::$get[self::GET_PARAMETER_SLUG], $request::$post);
328
-                    header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/document-types');
328
+                    header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/document-types');
329 329
                     exit;
330 330
                 }
331 331
                 $this->parameters[self::PARAMETER_DOCUMENT_TYPE] = $documentType;
332 332
                 $this->parameters[self::PARAMETER_BRICKS] = $bricks;
333 333
             } elseif ($relativeCmsUri == '/configuration/document-types/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
334 334
                 $this->storage->deleteDocumentTypeBySlug($request::$get[self::GET_PARAMETER_SLUG]);
335
-                header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/document-types');
335
+                header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/document-types');
336 336
                 exit;
337 337
             }
338 338
         }
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
                 $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
353 353
                 if (isset($request::$post[self::POST_PARAMETER_TITLE])) {
354 354
                     $this->storage->addBrick($request::$post);
355
-                    header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/bricks');
355
+                    header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/bricks');
356 356
                     exit;
357 357
                 }
358 358
             } elseif ($relativeCmsUri == '/configuration/bricks/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
@@ -361,13 +361,13 @@  discard block
 block discarded – undo
361 361
                 $brick = $this->storage->getBrickBySlug($request::$get[self::GET_PARAMETER_SLUG]);
362 362
                 if (isset($request::$post[self::POST_PARAMETER_TITLE])) {
363 363
                     $this->storage->saveBrick($request::$get[self::GET_PARAMETER_SLUG], $request::$post);
364
-                    header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/bricks');
364
+                    header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/bricks');
365 365
                     exit;
366 366
                 }
367 367
                 $this->parameters[self::PARAMETER_BRICK] = $brick;
368 368
             } elseif ($relativeCmsUri == '/configuration/bricks/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
369 369
                 $this->storage->deleteBrickBySlug($request::$get[self::GET_PARAMETER_SLUG]);
370
-                header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/bricks');
370
+                header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/bricks');
371 371
                 exit;
372 372
             } elseif ($relativeCmsUri == '/configuration/image-set') {
373 373
                 $this->subTemplate = 'cms/configuration/image-set';
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
                 $imageSet = $this->storage->getImageSetBySlug($request::$get[self::GET_PARAMETER_SLUG]);
393 393
                 if (isset($request::$post[self::POST_PARAMETER_TITLE])) {
394 394
                     $this->storage->saveImageSet($request::$get[self::GET_PARAMETER_SLUG], $request::$post);
395
-                    header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/image-set');
395
+                    header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/image-set');
396 396
                     exit;
397 397
                 }
398 398
                 $this->parameters[self::PARAMETER_IMAGE_SET] = $imageSet;
@@ -401,12 +401,12 @@  discard block
 block discarded – undo
401 401
                 $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
402 402
                 if (isset($request::$post[self::POST_PARAMETER_TITLE])) {
403 403
                     $this->storage->addImageSet($request::$post);
404
-                    header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/image-set');
404
+                    header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/image-set');
405 405
                     exit;
406 406
                 }
407 407
             } elseif ($relativeCmsUri == '/configuration/image-set/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
408 408
                 $this->storage->deleteImageSetBySlug($request::$get[self::GET_PARAMETER_SLUG]);
409
-                header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/image-set');
409
+                header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/image-set');
410 410
                 exit;
411 411
             }
412 412
         }
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
                 $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration';
427 427
                 if (isset($request::$post[self::POST_PARAMETER_TITLE])) {
428 428
                     $this->storage->addApplicationComponent($request::$post);
429
-                    header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/application-components');
429
+                    header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/application-components');
430 430
                     exit;
431 431
                 }
432 432
             } elseif ($relativeCmsUri == '/configuration/application-components/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
@@ -435,13 +435,13 @@  discard block
 block discarded – undo
435 435
                 $applicationComponent = $this->storage->getApplicationComponentBySlug($request::$get[self::GET_PARAMETER_SLUG]);
436 436
                 if (isset($request::$post[self::POST_PARAMETER_TITLE])) {
437 437
                     $this->storage->saveApplicationComponent($request::$get[self::GET_PARAMETER_SLUG], $request::$post);
438
-                    header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/application-components');
438
+                    header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/application-components');
439 439
                     exit;
440 440
                 }
441 441
                 $this->parameters['applicationComponent'] = $applicationComponent;
442 442
             } elseif ($relativeCmsUri == '/configuration/application-components/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) {
443 443
                 $this->storage->deleteApplicationComponentBySlug($request::$get[self::GET_PARAMETER_SLUG]);
444
-                header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/application-components');
444
+                header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/application-components');
445 445
                 exit;
446 446
             }
447 447
         }
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
             if ($relativeCmsUri == '/log-off') {
452 452
                 $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = null;
453 453
                 unset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]);
454
-                header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX]);
454
+                header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX]);
455 455
                 exit;
456 456
             }
457 457
         }
Please login to merge, or discard this patch.