Passed
Push — develop ( 51f80f...cde9d6 )
by Jens
03:13
created
cloudcontrol/library/components/CmsComponent.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 
19 19
 		/**
20 20
 		 * @var null
21
-         */
21
+		 */
22 22
 		protected $subTemplate = null;
23 23
 
24 24
 		/**
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 		/**
140 140
 		 * @param $remoteAddress
141 141
 		 * @throws \Exception
142
-         */
142
+		 */
143 143
 		private function checkWhiteList($remoteAddress)
144 144
 		{
145 145
 			if (isset($this->parameters['whitelistIps'])) {
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 		/**
155 155
 		 * @param $remoteAddress
156 156
 		 * @throws \Exception
157
-         */
157
+		 */
158 158
 		private function checkBlackList($remoteAddress)
159 159
 		{
160 160
 			if (isset($this->parameters['blacklistIps'])) {
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 		/**
170 170
 		 * @param $request
171 171
 		 * @return mixed|string
172
-         */
172
+		 */
173 173
 		private function getRelativeCmsUri($request)
174 174
 		{
175 175
 			// TODO Use regex match parameter instead of calculating relative uri
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 		/**
185 185
 		 * @param $request
186 186
 		 * @param $relativeCmsUri
187
-         */
187
+		 */
188 188
 		private function documentsRouting($request, $relativeCmsUri)
189 189
 		{
190 190
 			if ($relativeCmsUri == '/documents') {
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 		/**
200 200
 		 * @param $request
201 201
 		 * @param $relativeCmsUri
202
-         */
202
+		 */
203 203
 		private function sitemapRouting($request, $relativeCmsUri)
204 204
 		{
205 205
 			if ($relativeCmsUri == '/sitemap') {
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 		/**
238 238
 		 * @param $request
239 239
 		 * @param $relativeCmsUri
240
-         */
240
+		 */
241 241
 		private function imagesRouting($request, $relativeCmsUri)
242 242
 		{
243 243
 			if ($relativeCmsUri == '/images') {
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 
270 270
 		/**
271 271
 		 * @param $relativeCmsUri
272
-         */
272
+		 */
273 273
 		private function apiRouting($relativeCmsUri)
274 274
 		{
275 275
 			if ($relativeCmsUri == '/images.json') {
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
 		/**
288 288
 		 * @param $request
289 289
 		 * @param $relativeCmsUri
290
-         */
290
+		 */
291 291
 		private function filesRouting($request, $relativeCmsUri)
292 292
 		{
293 293
 			if ($relativeCmsUri == '/files') {
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
 
314 314
 		/**
315 315
 		 * @param $slug
316
-         */
316
+		 */
317 317
 		private function downloadFile($slug)
318 318
 		{
319 319
 			$file = $this->storage->getFileByName($slug);
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
 		/**
339 339
 		 * @param $request
340 340
 		 * @param $relativeCmsUri
341
-         */
341
+		 */
342 342
 		private function configurationRouting($request, $relativeCmsUri)
343 343
 		{
344 344
 			if ($relativeCmsUri == '/configuration') {
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
 		 * @param $request
358 358
 		 * @param $relativeCmsUri
359 359
 		 * @throws \Exception
360
-         */
360
+		 */
361 361
 		private function documentRouting($request, $relativeCmsUri)
362 362
 		{
363 363
 			if ($relativeCmsUri == '/documents/new-document' && isset($request::$get['path'])) {
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
 		/**
413 413
 		 * @param $request
414 414
 		 * @param $relativeCmsUri
415
-         */
415
+		 */
416 416
 		private function folderRouting($request, $relativeCmsUri)
417 417
 		{
418 418
 			if ($relativeCmsUri == '/documents/new-folder' && isset($request::$get['path'])) {
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
 		/**
454 454
 		 * @param $request
455 455
 		 * @param $relativeCmsUri
456
-         */
456
+		 */
457 457
 		private function usersRouting($request, $relativeCmsUri)
458 458
 		{
459 459
 			if ($relativeCmsUri == '/configuration/users') {
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
 		/**
488 488
 		 * @param $request
489 489
 		 * @param $relativeCmsUri
490
-         */
490
+		 */
491 491
 		private function documentTypesRouting($request, $relativeCmsUri)
492 492
 		{
493 493
 			if ($relativeCmsUri == '/configuration/document-types') {
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
 		/**
527 527
 		 * @param $request
528 528
 		 * @param $relativeCmsUri
529
-         */
529
+		 */
530 530
 		private function bricksRouting($request, $relativeCmsUri)
531 531
 		{
532 532
 			if ($relativeCmsUri == '/configuration/bricks') {
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
 		/**
566 566
 		 * @param $request
567 567
 		 * @param $relativeCmsUri
568
-         */
568
+		 */
569 569
 		private function imageSetRouting($request, $relativeCmsUri)
570 570
 		{
571 571
 			if ($relativeCmsUri == '/configuration/image-set') {
@@ -600,7 +600,7 @@  discard block
 block discarded – undo
600 600
 		/**
601 601
 		 * @param $request
602 602
 		 * @param $relativeCmsUri
603
-         */
603
+		 */
604 604
 		private function applicationComponentRouting($request, $relativeCmsUri)
605 605
 		{
606 606
 			if ($relativeCmsUri == '/configuration/application-components') {
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 				$whitelistIps = explode(',', $this->parameters['whitelistIps']);
149 149
 				$whitelistIps = array_map("trim", $whitelistIps);
150 150
 				if (!in_array($remoteAddress, $whitelistIps)) {
151
-					throw new \Exception('Ip address ' . $remoteAddress . ' is not on whitelist');
151
+					throw new \Exception('Ip address '.$remoteAddress.' is not on whitelist');
152 152
 				}
153 153
 			}
154 154
 		}
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 				$blacklistIps = explode(',', $this->parameters['blacklistIps']);
164 164
 				$blacklistIps = array_map("trim", $blacklistIps);
165 165
 				if (in_array($remoteAddress, $blacklistIps)) {
166
-					throw new \Exception('Ip address ' . $remoteAddress . ' is on blacklist');
166
+					throw new \Exception('Ip address '.$remoteAddress.' is on blacklist');
167 167
 				}
168 168
 			}
169 169
 		}
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 				$this->parameters['mainNavClass'] = 'sitemap';
217 217
 				if (isset($request::$post['title'], $request::$post['template'], $request::$post['component'])) {
218 218
 					$this->storage->addSitemapItem($request::$post);
219
-					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/sitemap');
219
+					header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/sitemap');
220 220
 					exit;
221 221
 				}
222 222
 			} elseif ($relativeCmsUri == '/sitemap/edit' && isset($request::$get['slug'])) {
@@ -225,13 +225,13 @@  discard block
 block discarded – undo
225 225
 				$sitemapItem = $this->storage->getSitemapItemBySlug($request::$get['slug']);
226 226
 				if (isset($request::$post['title'], $request::$post['template'], $request::$post['component'])) {
227 227
 					$this->storage->saveSitemapItem($request::$get['slug'], $request::$post);
228
-					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/sitemap');
228
+					header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/sitemap');
229 229
 					exit;
230 230
 				}
231 231
 				$this->parameters['sitemapItem'] = $sitemapItem;
232 232
 			} elseif ($relativeCmsUri == '/sitemap/delete' && isset($request::$get['slug'])) {
233 233
 				$this->storage->deleteSitemapItemBySlug($request::$get['slug']);
234
-				header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/sitemap');
234
+				header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/sitemap');
235 235
 				exit;
236 236
 			}
237 237
 		}
@@ -255,12 +255,12 @@  discard block
 block discarded – undo
255 255
 				$this->parameters['mainNavClass'] = 'images';
256 256
 				if (isset($_FILES['file'])) {
257 257
 					$this->storage->addImage($_FILES['file']);
258
-					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/images');
258
+					header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/images');
259 259
 					exit;
260 260
 				}
261 261
 			} elseif ($relativeCmsUri == '/images/delete' && isset($request::$get['file'])) {
262 262
 				$this->storage->deleteImageByName($request::$get['file']);
263
-				header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/images');
263
+				header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/images');
264 264
 				exit;
265 265
 			} elseif ($relativeCmsUri == '/images/show' && isset($request::$get['file'])) {
266 266
 				$this->subTemplate = 'cms/images/show';
@@ -301,14 +301,14 @@  discard block
 block discarded – undo
301 301
 				$this->parameters['mainNavClass'] = 'files';
302 302
 				if (isset($_FILES['file'])) {
303 303
 					$this->storage->addFile($_FILES['file']);
304
-					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/files');
304
+					header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/files');
305 305
 					exit;
306 306
 				}
307 307
 			} elseif ($relativeCmsUri == '/files/get' && isset($request::$get['file'])) {
308 308
 				$this->downloadFile($request::$get['file']);
309 309
 			} elseif ($relativeCmsUri == '/files/delete' && isset($request::$get['file'])) {
310 310
 				$this->storage->deleteFileByName($request::$get['file']);
311
-				header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/files');
311
+				header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/files');
312 312
 				exit;
313 313
 			}
314 314
 		}
@@ -319,21 +319,21 @@  discard block
 block discarded – undo
319 319
 		private function downloadFile($slug)
320 320
 		{
321 321
 			$file = $this->storage->getFileByName($slug);
322
-			$path = realpath(__DIR__ . '/../../www/files/');
323
-			$quoted = sprintf('"%s"', addcslashes(basename($path . '/' . $file->file), '"\\'));
324
-			$size   = filesize($path . '/' . $file->file);
322
+			$path = realpath(__DIR__.'/../../www/files/');
323
+			$quoted = sprintf('"%s"', addcslashes(basename($path.'/'.$file->file), '"\\'));
324
+			$size   = filesize($path.'/'.$file->file);
325 325
 
326 326
 			header('Content-Description: File Transfer');
327
-			header('Content-Type: ' . $file->type);
328
-			header('Content-Disposition: attachment; filename=' . $quoted);
327
+			header('Content-Type: '.$file->type);
328
+			header('Content-Disposition: attachment; filename='.$quoted);
329 329
 			header('Content-Transfer-Encoding: binary');
330 330
 			header('Connection: Keep-Alive');
331 331
 			header('Expires: 0');
332 332
 			header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
333 333
 			header('Pragma: public');
334
-			header('Content-Length: ' . $size);
334
+			header('Content-Length: '.$size);
335 335
 
336
-			readfile($path . '/' . $file->file);
336
+			readfile($path.'/'.$file->file);
337 337
 			exit;
338 338
 		}
339 339
 
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
 				if (isset($request::$get['documentType'])) {
370 370
 					if (isset($request::$post['title'], $request::$get['documentType'], $request::$get['path'])) {
371 371
 						$this->storage->addDocument($request::$post);
372
-						header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/documents');
372
+						header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/documents');
373 373
 						exit;
374 374
 					}
375 375
 					$this->parameters['documentType'] = $this->storage->getDocumentTypeBySlug($request::$get['documentType'], true);
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 				$this->parameters['smallestImage'] = $this->storage->getSmallestImageSet()->slug;
384 384
 				if (isset($request::$post['title'], $request::$get['slug'])) {
385 385
 					$this->storage->saveDocument($request::$post);
386
-					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/documents');
386
+					header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/documents');
387 387
 					exit;
388 388
 				}
389 389
 				$this->parameters['document'] = $this->storage->getDocumentBySlug($request::$get['slug']);
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
 				die(json_encode($result));
407 407
 			} else if ($relativeCmsUri == '/documents/delete-document' && isset($request::$get['slug'])) {
408 408
 				$this->storage->deleteDocumentBySlug($request::$get['slug']);
409
-				header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/documents');
409
+				header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/documents');
410 410
 				exit;
411 411
 			}
412 412
 		}
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
 				$this->parameters['mainNavClass'] = 'documents';
423 423
 				if (isset($request::$post['title'], $request::$post['path'])) {
424 424
 					$this->storage->addDocumentFolder($request::$post);
425
-					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/documents');
425
+					header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/documents');
426 426
 					exit;
427 427
 				}
428 428
 			} else if ($relativeCmsUri == '/documents/edit-folder' && isset($request::$get['slug'])) {
@@ -435,11 +435,11 @@  discard block
 block discarded – undo
435 435
 				array_pop($path);
436 436
 				$path = implode('/', $path);
437 437
 
438
-				$request::$get['path'] = '/' . $path;
438
+				$request::$get['path'] = '/'.$path;
439 439
 
440 440
 				if (isset($request::$post['title'], $request::$post['content'])) {
441 441
 					$this->storage->saveDocumentFolder($request::$post);
442
-					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/documents');
442
+					header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/documents');
443 443
 					exit;
444 444
 				}
445 445
 
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
 				$this->parameters['folder'] = $folder;
448 448
 			} else if ($relativeCmsUri == '/documents/delete-folder' && isset($request::$get['slug'])) {
449 449
 				$this->storage->deleteDocumentFolderBySlug($request::$get['slug']);
450
-				header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/documents');
450
+				header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/documents');
451 451
 				exit;
452 452
 			}
453 453
 		}
@@ -467,12 +467,12 @@  discard block
 block discarded – undo
467 467
 				$this->parameters['mainNavClass'] = 'configuration';
468 468
 				if (isset($_POST['username'])) {
469 469
 					$this->storage->addUser($request::$post);
470
-					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/users');
470
+					header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/configuration/users');
471 471
 					exit;
472 472
 				}
473 473
 			} elseif ($relativeCmsUri == '/configuration/users/delete' && isset($request::$get['slug'])) {
474 474
 				$this->storage->deleteUserBySlug($request::$get['slug']);
475
-				header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/users');
475
+				header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/configuration/users');
476 476
 				exit;
477 477
 			} elseif ($relativeCmsUri == '/configuration/users/edit' && isset($request::$get['slug'])) {
478 478
 				$this->subTemplate = 'cms/configuration/users-form';
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 				$this->parameters['user'] = $this->storage->getUserBySlug($request::$get['slug']);
481 481
 				if (isset($_POST['username'])) {
482 482
 					$this->storage->saveUser($request::$get['slug'], $request::$post);
483
-					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/users');
483
+					header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/configuration/users');
484 484
 					exit;
485 485
 				}
486 486
 			}
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
 				$bricks = $this->storage->getBricks();
503 503
 				if (isset($request::$post['title'])) {
504 504
 					$this->storage->addDocumentType($request::$post);
505
-					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/document-types');
505
+					header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/configuration/document-types');
506 506
 					exit;
507 507
 				}
508 508
 				$this->parameters['bricks'] = $bricks;
@@ -513,14 +513,14 @@  discard block
 block discarded – undo
513 513
 				$bricks = $this->storage->getBricks();
514 514
 				if (isset($request::$post['title'])) {
515 515
 					$this->storage->saveDocumentType($request::$get['slug'], $request::$post);
516
-					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/document-types');
516
+					header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/configuration/document-types');
517 517
 					exit;
518 518
 				}
519 519
 				$this->parameters['documentType'] = $documentType;
520 520
 				$this->parameters['bricks'] = $bricks;
521 521
 			} elseif ($relativeCmsUri == '/configuration/document-types/delete' && isset($request::$get['slug'])) {
522 522
 				$this->storage->deleteDocumentTypeBySlug($request::$get['slug']);
523
-				header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/document-types');
523
+				header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/configuration/document-types');
524 524
 				exit;
525 525
 			}
526 526
 		}
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
 				$this->parameters['mainNavClass'] = 'configuration';
541 541
 				if (isset($request::$post['title'])) {
542 542
 					$this->storage->addBrick($request::$post);
543
-					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/bricks');
543
+					header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/configuration/bricks');
544 544
 					exit;
545 545
 				}
546 546
 			} elseif ($relativeCmsUri == '/configuration/bricks/edit' && isset($request::$get['slug'])) {
@@ -549,13 +549,13 @@  discard block
 block discarded – undo
549 549
 				$brick = $this->storage->getBrickBySlug($request::$get['slug']);
550 550
 				if (isset($request::$post['title'])) {
551 551
 					$this->storage->saveBrick($request::$get['slug'], $request::$post);
552
-					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/bricks');
552
+					header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/configuration/bricks');
553 553
 					exit;
554 554
 				}
555 555
 				$this->parameters['brick'] = $brick;
556 556
 			} elseif ($relativeCmsUri == '/configuration/bricks/delete' && isset($request::$get['slug'])) {
557 557
 				$this->storage->deleteBrickBySlug($request::$get['slug']);
558
-				header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/bricks');
558
+				header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/configuration/bricks');
559 559
 				exit;
560 560
 			} elseif ($relativeCmsUri == '/configuration/image-set') {
561 561
 				$this->subTemplate = 'cms/configuration/image-set';
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
 				$imageSet = $this->storage->getImageSetBySlug($request::$get['slug']);
581 581
 				if (isset($request::$post['title'])) {
582 582
 					$this->storage->saveImageSet($request::$get['slug'], $request::$post);
583
-					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/image-set');
583
+					header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/configuration/image-set');
584 584
 					exit;
585 585
 				}
586 586
 				$this->parameters['imageSet'] = $imageSet;
@@ -589,12 +589,12 @@  discard block
 block discarded – undo
589 589
 				$this->parameters['mainNavClass'] = 'configuration';
590 590
 				if (isset($request::$post['title'])) {
591 591
 					$this->storage->addImageSet($request::$post);
592
-					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/image-set');
592
+					header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/configuration/image-set');
593 593
 					exit;
594 594
 				}
595 595
 			} elseif ($relativeCmsUri == '/configuration/image-set/delete' && isset($request::$get['slug'])) {
596 596
 				$this->storage->deleteImageSetBySlug($request::$get['slug']);
597
-				header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/image-set');
597
+				header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/configuration/image-set');
598 598
 				exit;
599 599
 			}
600 600
 		}
@@ -614,7 +614,7 @@  discard block
 block discarded – undo
614 614
 				$this->parameters['mainNavClass'] = 'configuration';
615 615
 				if (isset($request::$post['title'])) {
616 616
 					$this->storage->addApplicationComponent($request::$post);
617
-					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/application-components');
617
+					header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/configuration/application-components');
618 618
 					exit;
619 619
 				}
620 620
 			} elseif ($relativeCmsUri == '/configuration/application-components/edit' && isset($request::$get['slug'])) {
@@ -623,13 +623,13 @@  discard block
 block discarded – undo
623 623
 				$applicationComponent = $this->storage->getApplicationComponentBySlug($request::$get['slug']);
624 624
 				if (isset($request::$post['title'])) {
625 625
 					$this->storage->saveApplicationComponent($request::$get['slug'], $request::$post);
626
-					header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/application-components');
626
+					header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/configuration/application-components');
627 627
 					exit;
628 628
 				}
629 629
 				$this->parameters['applicationComponent'] = $applicationComponent;
630 630
 			} elseif ($relativeCmsUri == '/configuration/application-components/delete' && isset($request::$get['slug'])) {
631 631
 				$this->storage->deleteApplicationComponentBySlug($request::$get['slug']);
632
-				header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix'] . '/configuration/application-components');
632
+				header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix'].'/configuration/application-components');
633 633
 				exit;
634 634
 			}
635 635
 		}
@@ -639,7 +639,7 @@  discard block
 block discarded – undo
639 639
 			if ($relativeCmsUri == '/log-off') {
640 640
 				$_SESSION['cloudcontrol'] = null;
641 641
 				unset($_SESSION['cloudcontrol']);
642
-				header('Location: ' . $request::$subfolders . $this->parameters['cmsPrefix']);
642
+				header('Location: '.$request::$subfolders.$this->parameters['cmsPrefix']);
643 643
 				exit;
644 644
 			}
645 645
 		}
Please login to merge, or discard this patch.
cloudcontrol/templates/cms/documents/document-form.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.1/js/bootstrap.min.js"></script>
4 4
 <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet">
5 5
 <script>var smallestImage = '<?=$smallestImage?>';</script>
6
-<?$copyable=''?>
6
+<?$copyable = ''?>
7 7
 <section class="documents">
8 8
 	<h2><i class="fa fa-file-text-o"></i> Documents</h2>
9 9
 	<nav class="actions">
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 			</div>
24 24
 		</li>
25 25
 	</ul>
26
-	<?include('document-form-form.php');?>
26
+	<?include('document-form-form.php'); ?>
27 27
 </section>
28 28
 
29 29
 <script>
Please login to merge, or discard this patch.
cloudcontrol/library/images/ImageResizer.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 				}
44 44
 				return $returnFileNames;
45 45
 			} else {
46
-				throw new \Exception('Image doesnt exist: ' . $imagePath);
46
+				throw new \Exception('Image doesnt exist: '.$imagePath);
47 47
 			}
48 48
 		}
49 49
 
@@ -54,10 +54,10 @@  discard block
 block discarded – undo
54 54
 		 * @return string
55 55
 		 * @throws \Exception
56 56
 		 */
57
-		public function resize($imagePath='', $width='',$height='')
57
+		public function resize($imagePath = '', $width = '', $height = '')
58 58
 		{
59
-			$modifier = '-r' . $width . 'x' . $height;
60
-			return $this->applyMethod('Resize', $imagePath, $width,$height, $modifier);
59
+			$modifier = '-r'.$width.'x'.$height;
60
+			return $this->applyMethod('Resize', $imagePath, $width, $height, $modifier);
61 61
 		}
62 62
 
63 63
 		/**
@@ -67,10 +67,10 @@  discard block
 block discarded – undo
67 67
 		 * @return string
68 68
 		 * @throws \Exception
69 69
 		 */
70
-		public function smartcrop($imagePath='', $width='',$height='')
70
+		public function smartcrop($imagePath = '', $width = '', $height = '')
71 71
 		{
72
-			$modifier = '-s' . $width . 'x' . $height;
73
-			return $this->applyMethod('SmartCrop', $imagePath, $width,$height, $modifier);
72
+			$modifier = '-s'.$width.'x'.$height;
73
+			return $this->applyMethod('SmartCrop', $imagePath, $width, $height, $modifier);
74 74
 		}
75 75
 
76 76
 		/**
@@ -80,10 +80,10 @@  discard block
 block discarded – undo
80 80
 		 * @return string
81 81
 		 * @throws \Exception
82 82
 		 */
83
-		public function boxcrop($imagePath='', $width='',$height='')
83
+		public function boxcrop($imagePath = '', $width = '', $height = '')
84 84
 		{
85
-			$modifier = '-b' . $width . 'x' . $height;
86
-			return $this->applyMethod('BoxCrop', $imagePath, $width,$height, $modifier);
85
+			$modifier = '-b'.$width.'x'.$height;
86
+			return $this->applyMethod('BoxCrop', $imagePath, $width, $height, $modifier);
87 87
 		}
88 88
 
89 89
 		/**
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 		 *
93 93
 		 * @return string
94 94
 		 */
95
-		private function modifyName($imagePath, $modifier='')
95
+		private function modifyName($imagePath, $modifier = '')
96 96
 		{
97 97
 			$filename = basename($imagePath);
98 98
 			$path = dirname($imagePath);
@@ -102,30 +102,30 @@  discard block
 block discarded – undo
102 102
 				array_pop($fileParts);
103 103
 				$fileNameWithoutExtension = implode('-', $fileParts);
104 104
 				$fileNameWithoutExtension = slugify($fileNameWithoutExtension);
105
-				$filename = $fileNameWithoutExtension . $modifier  . '.' . $extension;
105
+				$filename = $fileNameWithoutExtension.$modifier.'.'.$extension;
106 106
 			} else {
107 107
 				$filename = slugify($filename);
108 108
 			}
109 109
 
110
-			if (file_exists($path . '/' . $filename)) {
110
+			if (file_exists($path.'/'.$filename)) {
111 111
 				$fileParts = explode('.', $filename);
112 112
 				if (count($fileParts) > 1) {
113 113
 					$extension = end($fileParts);
114 114
 					array_pop($fileParts);
115 115
 					$fileNameWithoutExtension = implode('-', $fileParts);
116 116
 					$fileNameWithoutExtension .= '-copy';
117
-					$filename = $fileNameWithoutExtension . '.' . $extension;
117
+					$filename = $fileNameWithoutExtension.'.'.$extension;
118 118
 				} else {
119 119
 					$filename .= '-copy';
120 120
 				}
121
-				return $this->modifyName($path . '/' . $filename);
121
+				return $this->modifyName($path.'/'.$filename);
122 122
 			}
123
-			return $path . '/' . $filename;
123
+			return $path.'/'.$filename;
124 124
 		}
125 125
 
126 126
 		private function applyMethod($method, $imagePath, $width, $height, $modifier)
127 127
 		{
128
-			$method = 'library\\images\\methods\\' . $method;
128
+			$method = 'library\\images\\methods\\'.$method;
129 129
 			$destination = $this->modifyName($imagePath, $modifier);
130 130
 			if (file_exists($imagePath)) {
131 131
 				$image = new Image();
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 				$resizedImage->SaveImage($destination, $resizedImage->GetImageMimeType($imagePath), 80);
140 140
 				return basename($destination);
141 141
 			} else {
142
-				throw new \Exception('Image doesnt exist: ' . $imagePath);
142
+				throw new \Exception('Image doesnt exist: '.$imagePath);
143 143
 			}
144 144
 		}
145 145
 	}
Please login to merge, or discard this patch.
cloudcontrol/library/components/FormComponent.php 3 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
             unset($request::$get['path']);
81 81
         }
82 82
         if ($this->isFormSubmitted($this->request)) {
83
-            $this->parameters[$this->formParameterName] = '<a name="' . $this->formId . '"></a>' . $this->thankYouMessage;
83
+            $this->parameters[$this->formParameterName] = '<a name="'.$this->formId.'"></a>'.$this->thankYouMessage;
84 84
         } else {
85 85
             $this->parameters[$this->formParameterName] = $form;
86 86
         }
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
         $postValues = $request::$post;
198 198
         $postValues['documentType'] = $this->documentType;
199 199
         $postValues['path'] = $this->responseFolder;
200
-        $postValues['title'] = date('r') . ' - From: ' . $request::$requestUri;
200
+        $postValues['title'] = date('r').' - From: '.$request::$requestUri;
201 201
     }
202 202
 
203 203
     /**
Please login to merge, or discard this patch.
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 
133 133
     /**
134 134
      * Sets variables needed for rendering the form template
135
-     * @param $storage
135
+     * @param Storage $storage
136 136
      */
137 137
     private function initialize($storage)
138 138
     {
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
      * submitting the form
169 169
      *
170 170
      * @param $postValues
171
-     * @param $storage
171
+     * @param Storage $storage
172 172
      */
173 173
     protected function postSubmit($postValues, $storage)
174 174
     {}
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
     /**
192 192
      * Checks if this form has been submitted
193 193
      *
194
-     * @param $request
194
+     * @param \library\cc\Request $request
195 195
      * @return bool
196 196
      */
197 197
     private function isFormSubmitted($request)
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
     /**
203 203
      *
204 204
      *
205
-     * @param $request
205
+     * @param \library\cc\Request $request
206 206
      */
207 207
     private function getPostValues($request)
208 208
     {
Please login to merge, or discard this patch.
Indentation   +244 added lines, -244 removed lines patch added patch discarded remove patch
@@ -7,248 +7,248 @@
 block discarded – undo
7 7
 
8 8
 class FormComponent Extends BaseComponent
9 9
 {
10
-    /**
11
-     * @var null|string
12
-     */
13
-    protected $documentType = null;
14
-    /**
15
-     * @var null|string
16
-     */
17
-    protected $responseFolder = null;
18
-    /**
19
-     * @var string
20
-     */
21
-    protected $subTemplate = 'cms/documents/document-form-form';
22
-    /**
23
-     * @var string
24
-     */
25
-    protected $formParameterName = 'form';
26
-    /**
27
-     * @var string
28
-     */
29
-    protected $thankYouMessage = 'Thank you for sending us your response.';
30
-
31
-    /**
32
-     * @var bool
33
-     */
34
-    protected $submitOncePerSession = false;
35
-
36
-    /**
37
-     * @var string
38
-     */
39
-    private $formId;
40
-    /**
41
-     * @var null|string
42
-     */
43
-    private $getPathBackup = null;
44
-
45
-    /**
46
-     * @var null|\stdClass
47
-     */
48
-    private $userSessionBackup = null;
49
-
50
-    /**
51
-     * @param Storage $storage
52
-     * @return void
53
-     * @throws \Exception
54
-     */
55
-    public function run(Storage $storage)
56
-    {
57
-        parent::run($storage);
58
-
59
-        $this->checkParameters();
60
-
61
-        if ($this->documentType === null || $this->responseFolder === null) {
62
-            throw new \Exception('Parameters `documentType` and `responseFolder` are required for usage with this form');
63
-        }
64
-
65
-        $this->setFormId();
66
-        $this->initialize($storage);
67
-        $this->checkSubmit($storage);
68
-    }
69
-
70
-    /**
71
-     * @param null|Application $application
72
-     * @throws \Exception
73
-     */
74
-    public function render($application = null)
75
-    {
76
-        $request = $this->request;
77
-        if (isset($request::$get['path'])) {
78
-            $this->getPathBackup = $request::$get['path'];
79
-        }
80
-        $request::$get['path'] = $this->responseFolder;
81
-        $form = $this->renderTemplate($this->subTemplate);
82
-        if ($this->getPathBackup !== null) {
83
-            $request::$get['path'] = $this->getPathBackup;
84
-        } else {
85
-            unset($request::$get['path']);
86
-        }
87
-        if ($this->isFormSubmitted($this->request) || $this->isSubmitAllowed() === false) {
88
-            $this->parameters[$this->formParameterName] = '<a name="' . $this->formId . '"></a>' . $this->thankYouMessage;
89
-        } else {
90
-            $this->parameters[$this->formParameterName] = $form;
91
-        }
92
-
93
-        parent::render($application);
94
-    }
95
-
96
-    /**
97
-     * Checks if parameters were given in the CMS configuration and
98
-     * sets them to their respective fields
99
-     */
100
-    private function checkParameters()
101
-    {
102
-        if (isset($this->parameters['documentType'])) {
103
-            $this->documentType = $this->parameters['documentType'];
104
-            unset($this->parameters['documentType']);
105
-        }
106
-
107
-        if (isset($this->parameters['responseFolder'])) {
108
-            $this->responseFolder = $this->parameters['responseFolder'];
109
-            unset($this->parameters['responseFolder']);
110
-        }
111
-
112
-        if (isset($this->parameters['subTemplate'])) {
113
-            $this->subTemplate = $this->parameters['subTemplate'];
114
-            unset($this->parameters['subTemplate']);
115
-        }
116
-
117
-        if (isset($this->parameters['formParameterName'])) {
118
-            $this->formParameterName = $this->parameters['formParameterName'];
119
-            unset($this->parameters['formParameterName']);
120
-        }
121
-
122
-        if (isset($this->parameters['thankYouMessage'])) {
123
-            $this->thankYouMessage = $this->parameters['thankYouMessage'];
124
-            unset($this->parameters['thankYouMessage']);
125
-        }
126
-
127
-        if (isset($this->parameters['submitOncePerSession'])) {
128
-            $this->submitOncePerSession = $this->parameters['submitOncePerSession'] === 'true' ? true : false;
129
-            unset($this->parameters['submitOncePerSession']);
130
-        }
131
-    }
132
-
133
-    /**
134
-     * Sets variables needed for rendering the form template
135
-     * @param $storage
136
-     */
137
-    private function initialize($storage)
138
-    {
139
-        $this->parameters['smallestImage'] = $storage->getSmallestImageSet()->slug;
140
-        $this->parameters['cmsPrefix'] = '';
141
-
142
-        $this->parameters['documentType'] = $this->storage->getDocumentTypeBySlug($this->documentType, true);
143
-        $this->parameters['documentTypes'] = $this->storage->getDocumentTypes();
144
-        $this->parameters['hideTitleAndState'] = true;
145
-        $this->parameters['formId'] = $this->formId;
146
-    }
147
-
148
-    /**
149
-     * If the form has been submitted, save the document
150
-     * Calls $this->postSubmit() afterwards
151
-     *
152
-     * @param Storage $storage
153
-     */
154
-    private function checkSubmit($storage)
155
-    {
156
-        if ($this->isFormSubmitted($this->request) && $this->isSubmitAllowed()) {
157
-            $postValues = $this->getPostValues($this->request);
158
-            $this->setUserSessionBackup();
159
-            $storage->addDocument($postValues);
160
-            $this->restoreUserSessionBackup();
161
-            $this->setSubmitToSession();
162
-            $this->postSubmit($postValues, $storage);
163
-        }
164
-    }
165
-
166
-    /**
167
-     * Hook for derived classes to take actions after
168
-     * submitting the form
169
-     *
170
-     * @param $postValues
171
-     * @param $storage
172
-     */
173
-    protected function postSubmit($postValues, $storage)
174
-    {}
175
-
176
-    /**
177
-     * Sets a unique id for this particular form, so it can recognize
178
-     * it when a submit occurs
179
-     */
180
-    private function setFormId()
181
-    {
182
-        if (isset($_SESSION['FormComponent'][$this->formParameterName]['formId'])) {
183
-            $this->formId = $_SESSION['FormComponent'][$this->formParameterName]['formId'];
184
-        } else {
185
-            $_SESSION['FormComponent'][$this->formParameterName]['formId'] = (string) microtime(true);
186
-            $_SESSION['FormComponent'][$this->formParameterName]['submitted'] = false;
187
-            $this->formId = $_SESSION['FormComponent'][$this->formParameterName]['formId'];
188
-        }
189
-    }
190
-
191
-    /**
192
-     * Checks if this form has been submitted
193
-     *
194
-     * @param $request
195
-     * @return bool
196
-     */
197
-    private function isFormSubmitted($request)
198
-    {
199
-        return !empty($request::$post) && isset($request::$post['formId']) && $request::$post['formId'] === $this->formId && isset($_SESSION['FormComponent'][$this->formParameterName]['formId']) && $_SESSION['FormComponent'][$this->formParameterName]['formId'] === $this->formId;
200
-    }
201
-
202
-    /**
203
-     *
204
-     *
205
-     * @param $request
206
-     */
207
-    private function getPostValues($request)
208
-    {
209
-        $postValues = $request::$post;
210
-        $postValues['documentType'] = $this->documentType;
211
-        $postValues['path'] = $this->responseFolder;
212
-        $postValues['title'] = date('r') . ' - From: ' . $request::$requestUri;
213
-        return $postValues;
214
-    }
215
-
216
-    /**
217
-     * Temporarily stores the current user session in a backup variable
218
-     * and sets a fake user instead
219
-     */
220
-    private function setUserSessionBackup()
221
-    {
222
-        $this->userSessionBackup = isset($_SESSION['cloudcontrol']) ? $_SESSION['cloudcontrol'] : null;
223
-        $fakeUser = new \stdClass();
224
-        $fakeUser->username = 'FormComponent';
225
-        $_SESSION['cloudcontrol'] = $fakeUser;
226
-    }
227
-
228
-    /**
229
-     * Removes the fake user and restores the existing user
230
-     * session if it was there
231
-     */
232
-    private function restoreUserSessionBackup()
233
-    {
234
-        if ($this->userSessionBackup === null) {
235
-            unset($_SESSION['cloudcontrol']);
236
-        } else {
237
-            $_SESSION['cloudcontrol'] = $this->userSessionBackup;
238
-        }
239
-    }
240
-
241
-    private function setSubmitToSession()
242
-    {
243
-        $_SESSION['FormComponent'][$this->formParameterName]['submitted'] = true;
244
-    }
245
-
246
-    private function isSubmitAllowed()
247
-    {
248
-        if ($this->submitOncePerSession === true && $_SESSION['FormComponent'][$this->formParameterName]['submitted'] === true) {
249
-            return false;
250
-        } else {
251
-            return true;
252
-        }
253
-    }
10
+	/**
11
+	 * @var null|string
12
+	 */
13
+	protected $documentType = null;
14
+	/**
15
+	 * @var null|string
16
+	 */
17
+	protected $responseFolder = null;
18
+	/**
19
+	 * @var string
20
+	 */
21
+	protected $subTemplate = 'cms/documents/document-form-form';
22
+	/**
23
+	 * @var string
24
+	 */
25
+	protected $formParameterName = 'form';
26
+	/**
27
+	 * @var string
28
+	 */
29
+	protected $thankYouMessage = 'Thank you for sending us your response.';
30
+
31
+	/**
32
+	 * @var bool
33
+	 */
34
+	protected $submitOncePerSession = false;
35
+
36
+	/**
37
+	 * @var string
38
+	 */
39
+	private $formId;
40
+	/**
41
+	 * @var null|string
42
+	 */
43
+	private $getPathBackup = null;
44
+
45
+	/**
46
+	 * @var null|\stdClass
47
+	 */
48
+	private $userSessionBackup = null;
49
+
50
+	/**
51
+	 * @param Storage $storage
52
+	 * @return void
53
+	 * @throws \Exception
54
+	 */
55
+	public function run(Storage $storage)
56
+	{
57
+		parent::run($storage);
58
+
59
+		$this->checkParameters();
60
+
61
+		if ($this->documentType === null || $this->responseFolder === null) {
62
+			throw new \Exception('Parameters `documentType` and `responseFolder` are required for usage with this form');
63
+		}
64
+
65
+		$this->setFormId();
66
+		$this->initialize($storage);
67
+		$this->checkSubmit($storage);
68
+	}
69
+
70
+	/**
71
+	 * @param null|Application $application
72
+	 * @throws \Exception
73
+	 */
74
+	public function render($application = null)
75
+	{
76
+		$request = $this->request;
77
+		if (isset($request::$get['path'])) {
78
+			$this->getPathBackup = $request::$get['path'];
79
+		}
80
+		$request::$get['path'] = $this->responseFolder;
81
+		$form = $this->renderTemplate($this->subTemplate);
82
+		if ($this->getPathBackup !== null) {
83
+			$request::$get['path'] = $this->getPathBackup;
84
+		} else {
85
+			unset($request::$get['path']);
86
+		}
87
+		if ($this->isFormSubmitted($this->request) || $this->isSubmitAllowed() === false) {
88
+			$this->parameters[$this->formParameterName] = '<a name="' . $this->formId . '"></a>' . $this->thankYouMessage;
89
+		} else {
90
+			$this->parameters[$this->formParameterName] = $form;
91
+		}
92
+
93
+		parent::render($application);
94
+	}
95
+
96
+	/**
97
+	 * Checks if parameters were given in the CMS configuration and
98
+	 * sets them to their respective fields
99
+	 */
100
+	private function checkParameters()
101
+	{
102
+		if (isset($this->parameters['documentType'])) {
103
+			$this->documentType = $this->parameters['documentType'];
104
+			unset($this->parameters['documentType']);
105
+		}
106
+
107
+		if (isset($this->parameters['responseFolder'])) {
108
+			$this->responseFolder = $this->parameters['responseFolder'];
109
+			unset($this->parameters['responseFolder']);
110
+		}
111
+
112
+		if (isset($this->parameters['subTemplate'])) {
113
+			$this->subTemplate = $this->parameters['subTemplate'];
114
+			unset($this->parameters['subTemplate']);
115
+		}
116
+
117
+		if (isset($this->parameters['formParameterName'])) {
118
+			$this->formParameterName = $this->parameters['formParameterName'];
119
+			unset($this->parameters['formParameterName']);
120
+		}
121
+
122
+		if (isset($this->parameters['thankYouMessage'])) {
123
+			$this->thankYouMessage = $this->parameters['thankYouMessage'];
124
+			unset($this->parameters['thankYouMessage']);
125
+		}
126
+
127
+		if (isset($this->parameters['submitOncePerSession'])) {
128
+			$this->submitOncePerSession = $this->parameters['submitOncePerSession'] === 'true' ? true : false;
129
+			unset($this->parameters['submitOncePerSession']);
130
+		}
131
+	}
132
+
133
+	/**
134
+	 * Sets variables needed for rendering the form template
135
+	 * @param $storage
136
+	 */
137
+	private function initialize($storage)
138
+	{
139
+		$this->parameters['smallestImage'] = $storage->getSmallestImageSet()->slug;
140
+		$this->parameters['cmsPrefix'] = '';
141
+
142
+		$this->parameters['documentType'] = $this->storage->getDocumentTypeBySlug($this->documentType, true);
143
+		$this->parameters['documentTypes'] = $this->storage->getDocumentTypes();
144
+		$this->parameters['hideTitleAndState'] = true;
145
+		$this->parameters['formId'] = $this->formId;
146
+	}
147
+
148
+	/**
149
+	 * If the form has been submitted, save the document
150
+	 * Calls $this->postSubmit() afterwards
151
+	 *
152
+	 * @param Storage $storage
153
+	 */
154
+	private function checkSubmit($storage)
155
+	{
156
+		if ($this->isFormSubmitted($this->request) && $this->isSubmitAllowed()) {
157
+			$postValues = $this->getPostValues($this->request);
158
+			$this->setUserSessionBackup();
159
+			$storage->addDocument($postValues);
160
+			$this->restoreUserSessionBackup();
161
+			$this->setSubmitToSession();
162
+			$this->postSubmit($postValues, $storage);
163
+		}
164
+	}
165
+
166
+	/**
167
+	 * Hook for derived classes to take actions after
168
+	 * submitting the form
169
+	 *
170
+	 * @param $postValues
171
+	 * @param $storage
172
+	 */
173
+	protected function postSubmit($postValues, $storage)
174
+	{}
175
+
176
+	/**
177
+	 * Sets a unique id for this particular form, so it can recognize
178
+	 * it when a submit occurs
179
+	 */
180
+	private function setFormId()
181
+	{
182
+		if (isset($_SESSION['FormComponent'][$this->formParameterName]['formId'])) {
183
+			$this->formId = $_SESSION['FormComponent'][$this->formParameterName]['formId'];
184
+		} else {
185
+			$_SESSION['FormComponent'][$this->formParameterName]['formId'] = (string) microtime(true);
186
+			$_SESSION['FormComponent'][$this->formParameterName]['submitted'] = false;
187
+			$this->formId = $_SESSION['FormComponent'][$this->formParameterName]['formId'];
188
+		}
189
+	}
190
+
191
+	/**
192
+	 * Checks if this form has been submitted
193
+	 *
194
+	 * @param $request
195
+	 * @return bool
196
+	 */
197
+	private function isFormSubmitted($request)
198
+	{
199
+		return !empty($request::$post) && isset($request::$post['formId']) && $request::$post['formId'] === $this->formId && isset($_SESSION['FormComponent'][$this->formParameterName]['formId']) && $_SESSION['FormComponent'][$this->formParameterName]['formId'] === $this->formId;
200
+	}
201
+
202
+	/**
203
+	 *
204
+	 *
205
+	 * @param $request
206
+	 */
207
+	private function getPostValues($request)
208
+	{
209
+		$postValues = $request::$post;
210
+		$postValues['documentType'] = $this->documentType;
211
+		$postValues['path'] = $this->responseFolder;
212
+		$postValues['title'] = date('r') . ' - From: ' . $request::$requestUri;
213
+		return $postValues;
214
+	}
215
+
216
+	/**
217
+	 * Temporarily stores the current user session in a backup variable
218
+	 * and sets a fake user instead
219
+	 */
220
+	private function setUserSessionBackup()
221
+	{
222
+		$this->userSessionBackup = isset($_SESSION['cloudcontrol']) ? $_SESSION['cloudcontrol'] : null;
223
+		$fakeUser = new \stdClass();
224
+		$fakeUser->username = 'FormComponent';
225
+		$_SESSION['cloudcontrol'] = $fakeUser;
226
+	}
227
+
228
+	/**
229
+	 * Removes the fake user and restores the existing user
230
+	 * session if it was there
231
+	 */
232
+	private function restoreUserSessionBackup()
233
+	{
234
+		if ($this->userSessionBackup === null) {
235
+			unset($_SESSION['cloudcontrol']);
236
+		} else {
237
+			$_SESSION['cloudcontrol'] = $this->userSessionBackup;
238
+		}
239
+	}
240
+
241
+	private function setSubmitToSession()
242
+	{
243
+		$_SESSION['FormComponent'][$this->formParameterName]['submitted'] = true;
244
+	}
245
+
246
+	private function isSubmitAllowed()
247
+	{
248
+		if ($this->submitOncePerSession === true && $_SESSION['FormComponent'][$this->formParameterName]['submitted'] === true) {
249
+			return false;
250
+		} else {
251
+			return true;
252
+		}
253
+	}
254 254
 }
255 255
\ No newline at end of file
Please login to merge, or discard this patch.
cloudcontrol/library/cc/errorhandler.php 3 patches
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -31,11 +31,11 @@  discard block
 block discarded – undo
31 31
  */
32 32
 function shutdownHandler () {
33 33
 	$error = error_get_last(); 
34
-    if (isset($error['type'], $error['message'], $error['file'], $error['line'])) { 
35
-        errorHandler($error['type'],$error['message'],$error['file'],$error['line']);
36
-    }elseif ($error['type'] == 1) {
37
-        dump($error);
38
-    }
34
+	if (isset($error['type'], $error['message'], $error['file'], $error['line'])) { 
35
+		errorHandler($error['type'],$error['message'],$error['file'],$error['line']);
36
+	}elseif ($error['type'] == 1) {
37
+		dump($error);
38
+	}
39 39
 }
40 40
 
41 41
 /**
@@ -49,28 +49,28 @@  discard block
 block discarded – undo
49 49
 	$jsonErrorNr = json_last_error();
50 50
 	$errstr = '';
51 51
 	switch ($jsonErrorNr) {
52
-        case JSON_ERROR_NONE:
53
-            $errstr .= ' - No errors' . PHP_EOL;
54
-        break;
55
-        case JSON_ERROR_DEPTH:
56
-            $errstr .= ' - Maximum stack depth exceeded' . PHP_EOL;
57
-        break;
58
-        case JSON_ERROR_STATE_MISMATCH:
59
-            $errstr .= ' - Underflow or the modes mismatch' . PHP_EOL;
60
-        break;
61
-        case JSON_ERROR_CTRL_CHAR:
62
-            $errstr .= ' - Unexpected control character found' . PHP_EOL;
63
-        break;
64
-        case JSON_ERROR_SYNTAX:
65
-            $errstr .= ' - Syntax error, malformed JSON' . PHP_EOL;
66
-        break;
67
-        case JSON_ERROR_UTF8:
68
-            $errstr .= ' - Malformed UTF-8 characters, possibly incorrectly encoded' . PHP_EOL;
69
-        break;
70
-        default:
71
-            $errstr = ' - Unknown error' . PHP_EOL;
72
-        break;
73
-    }
52
+		case JSON_ERROR_NONE:
53
+			$errstr .= ' - No errors' . PHP_EOL;
54
+		break;
55
+		case JSON_ERROR_DEPTH:
56
+			$errstr .= ' - Maximum stack depth exceeded' . PHP_EOL;
57
+		break;
58
+		case JSON_ERROR_STATE_MISMATCH:
59
+			$errstr .= ' - Underflow or the modes mismatch' . PHP_EOL;
60
+		break;
61
+		case JSON_ERROR_CTRL_CHAR:
62
+			$errstr .= ' - Unexpected control character found' . PHP_EOL;
63
+		break;
64
+		case JSON_ERROR_SYNTAX:
65
+			$errstr .= ' - Syntax error, malformed JSON' . PHP_EOL;
66
+		break;
67
+		case JSON_ERROR_UTF8:
68
+			$errstr .= ' - Malformed UTF-8 characters, possibly incorrectly encoded' . PHP_EOL;
69
+		break;
70
+		default:
71
+			$errstr = ' - Unknown error' . PHP_EOL;
72
+		break;
73
+	}
74 74
 	errorHandler ($jsonErrorNr, $errstr, $file, $line);
75 75
 }
76 76
 
@@ -85,57 +85,57 @@  discard block
 block discarded – undo
85 85
  * @param string $httpHeader
86 86
  */
87 87
 function renderError ($message='', $file='', $line='', $code=0, $trace=array(), $httpHeader = 'HTTP/1.0 500 Internal Server Error') {
88
-    if (ob_get_contents()) ob_end_clean();
89
-    header($_SERVER['SERVER_PROTOCOL'] . $httpHeader, true);
90
-    header('X-Error-Message: ' . $message);
91
-    header('X-Error-File: ' . $file);
92
-    header('X-Error-Line: ' . $line);
93
-    if (canShowError()) {
94
-        $file_lines = file_exists($file) ? file($file) : array();
95
-        $range = ($line - 15) < 0 ? range(1, 30) : range($line - 15, $line + 15);
96
-        $lines = array();
88
+	if (ob_get_contents()) ob_end_clean();
89
+	header($_SERVER['SERVER_PROTOCOL'] . $httpHeader, true);
90
+	header('X-Error-Message: ' . $message);
91
+	header('X-Error-File: ' . $file);
92
+	header('X-Error-Line: ' . $line);
93
+	if (canShowError()) {
94
+		$file_lines = file_exists($file) ? file($file) : array();
95
+		$range = ($line - 15) < 0 ? range(1, 30) : range($line - 15, $line + 15);
96
+		$lines = array();
97 97
 
98
-        foreach ($range as $line_number) {
99
-            if(isset($file_lines[$line_number-1])) {
100
-                $lines[$line_number] = $file_lines[$line_number-1];
101
-            }
102
-        }
98
+		foreach ($range as $line_number) {
99
+			if(isset($file_lines[$line_number-1])) {
100
+				$lines[$line_number] = $file_lines[$line_number-1];
101
+			}
102
+		}
103 103
 
104
-        $error = array(
105
-            'message' 		=> $message,
106
-            'file' 			=> $file,
107
-            'line' 			=> $line,
108
-            'code' 			=> $code,
109
-            'lines' 		=> $lines,
110
-            'trace' 		=> $trace,
111
-            'httpHeader' 	=> $httpHeader,
112
-        );
113
-        if (file_exists(realpath(__DIR__) . '/errorviewdetailed.php')) {
114
-            include(realpath(__DIR__) . '/errorviewdetailed.php');
115
-        } else {
116
-            header('Content-type: application/json');
117
-            die(json_encode($error));
118
-        }
119
-        exit;
120
-    } else {
121
-        if (file_exists(realpath(__DIR__) . '/errorviewcompact.php')) {
122
-            include(realpath(__DIR__) . '/errorviewcompact.php');
123
-        } else {
124
-            header('Content-type: application/json');
125
-            die(json_encode('An error occured.'));
126
-        }
127
-    }
104
+		$error = array(
105
+			'message' 		=> $message,
106
+			'file' 			=> $file,
107
+			'line' 			=> $line,
108
+			'code' 			=> $code,
109
+			'lines' 		=> $lines,
110
+			'trace' 		=> $trace,
111
+			'httpHeader' 	=> $httpHeader,
112
+		);
113
+		if (file_exists(realpath(__DIR__) . '/errorviewdetailed.php')) {
114
+			include(realpath(__DIR__) . '/errorviewdetailed.php');
115
+		} else {
116
+			header('Content-type: application/json');
117
+			die(json_encode($error));
118
+		}
119
+		exit;
120
+	} else {
121
+		if (file_exists(realpath(__DIR__) . '/errorviewcompact.php')) {
122
+			include(realpath(__DIR__) . '/errorviewcompact.php');
123
+		} else {
124
+			header('Content-type: application/json');
125
+			die(json_encode('An error occured.'));
126
+		}
127
+	}
128 128
 }
129 129
 
130 130
 function canShowError()
131 131
 {
132
-    if (file_exists('../config.json') && !isset($_SESSION['cloudcontrol'])) {
133
-        $config = file_get_contents('../config.json');
134
-        $config = json_decode($config);
135
-        if (isset($config->showErrorsToAll)) {
136
-            return $config->showErrorsToAll;
137
-        }
138
-    } else {
139
-        return true;
140
-    }
132
+	if (file_exists('../config.json') && !isset($_SESSION['cloudcontrol'])) {
133
+		$config = file_get_contents('../config.json');
134
+		$config = json_decode($config);
135
+		if (isset($config->showErrorsToAll)) {
136
+			return $config->showErrorsToAll;
137
+		}
138
+	} else {
139
+		return true;
140
+	}
141 141
 }
142 142
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -9,8 +9,8 @@  discard block
 block discarded – undo
9 9
  *
10 10
  * @param $e
11 11
  */
12
-function exceptionHandler ($e) {
13
-	renderError($e->getMessage(),$e->getFile(),$e->getLine(),$e->getCode(),$e->getTrace());
12
+function exceptionHandler($e) {
13
+	renderError($e->getMessage(), $e->getFile(), $e->getLine(), $e->getCode(), $e->getTrace());
14 14
 }
15 15
 
16 16
 /**
@@ -21,18 +21,18 @@  discard block
 block discarded – undo
21 21
  * @param $errfile
22 22
  * @param $errline
23 23
  */
24
-function errorHandler ($errno, $errstr, $errfile, $errline) {
25
-	renderError($errstr,$errfile,$errline,$errno,debug_backtrace());
24
+function errorHandler($errno, $errstr, $errfile, $errline) {
25
+	renderError($errstr, $errfile, $errline, $errno, debug_backtrace());
26 26
 }
27 27
 
28 28
 /**
29 29
  * When an error occurs that kills the process, still try
30 30
  * to show it using a shutdownHandler.
31 31
  */
32
-function shutdownHandler () {
32
+function shutdownHandler() {
33 33
 	$error = error_get_last(); 
34 34
     if (isset($error['type'], $error['message'], $error['file'], $error['line'])) { 
35
-        errorHandler($error['type'],$error['message'],$error['file'],$error['line']);
35
+        errorHandler($error['type'], $error['message'], $error['file'], $error['line']);
36 36
     }elseif ($error['type'] == 1) {
37 37
         dump($error);
38 38
     }
@@ -50,28 +50,28 @@  discard block
 block discarded – undo
50 50
 	$errstr = '';
51 51
 	switch ($jsonErrorNr) {
52 52
         case JSON_ERROR_NONE:
53
-            $errstr .= ' - No errors' . PHP_EOL;
53
+            $errstr .= ' - No errors'.PHP_EOL;
54 54
         break;
55 55
         case JSON_ERROR_DEPTH:
56
-            $errstr .= ' - Maximum stack depth exceeded' . PHP_EOL;
56
+            $errstr .= ' - Maximum stack depth exceeded'.PHP_EOL;
57 57
         break;
58 58
         case JSON_ERROR_STATE_MISMATCH:
59
-            $errstr .= ' - Underflow or the modes mismatch' . PHP_EOL;
59
+            $errstr .= ' - Underflow or the modes mismatch'.PHP_EOL;
60 60
         break;
61 61
         case JSON_ERROR_CTRL_CHAR:
62
-            $errstr .= ' - Unexpected control character found' . PHP_EOL;
62
+            $errstr .= ' - Unexpected control character found'.PHP_EOL;
63 63
         break;
64 64
         case JSON_ERROR_SYNTAX:
65
-            $errstr .= ' - Syntax error, malformed JSON' . PHP_EOL;
65
+            $errstr .= ' - Syntax error, malformed JSON'.PHP_EOL;
66 66
         break;
67 67
         case JSON_ERROR_UTF8:
68
-            $errstr .= ' - Malformed UTF-8 characters, possibly incorrectly encoded' . PHP_EOL;
68
+            $errstr .= ' - Malformed UTF-8 characters, possibly incorrectly encoded'.PHP_EOL;
69 69
         break;
70 70
         default:
71
-            $errstr = ' - Unknown error' . PHP_EOL;
71
+            $errstr = ' - Unknown error'.PHP_EOL;
72 72
         break;
73 73
     }
74
-	errorHandler ($jsonErrorNr, $errstr, $file, $line);
74
+	errorHandler($jsonErrorNr, $errstr, $file, $line);
75 75
 }
76 76
 
77 77
 /**
@@ -84,20 +84,20 @@  discard block
 block discarded – undo
84 84
  * @param array  $trace
85 85
  * @param string $httpHeader
86 86
  */
87
-function renderError ($message='', $file='', $line='', $code=0, $trace=array(), $httpHeader = 'HTTP/1.0 500 Internal Server Error') {
87
+function renderError($message = '', $file = '', $line = '', $code = 0, $trace = array(), $httpHeader = 'HTTP/1.0 500 Internal Server Error') {
88 88
     if (ob_get_contents()) ob_end_clean();
89
-    header($_SERVER['SERVER_PROTOCOL'] . $httpHeader, true);
90
-    header('X-Error-Message: ' . $message);
91
-    header('X-Error-File: ' . $file);
92
-    header('X-Error-Line: ' . $line);
89
+    header($_SERVER['SERVER_PROTOCOL'].$httpHeader, true);
90
+    header('X-Error-Message: '.$message);
91
+    header('X-Error-File: '.$file);
92
+    header('X-Error-Line: '.$line);
93 93
     if (canShowError()) {
94 94
         $file_lines = file_exists($file) ? file($file) : array();
95 95
         $range = ($line - 15) < 0 ? range(1, 30) : range($line - 15, $line + 15);
96 96
         $lines = array();
97 97
 
98 98
         foreach ($range as $line_number) {
99
-            if(isset($file_lines[$line_number-1])) {
100
-                $lines[$line_number] = $file_lines[$line_number-1];
99
+            if (isset($file_lines[$line_number - 1])) {
100
+                $lines[$line_number] = $file_lines[$line_number - 1];
101 101
             }
102 102
         }
103 103
 
@@ -110,16 +110,16 @@  discard block
 block discarded – undo
110 110
             'trace' 		=> $trace,
111 111
             'httpHeader' 	=> $httpHeader,
112 112
         );
113
-        if (file_exists(realpath(__DIR__) . '/errorviewdetailed.php')) {
114
-            include(realpath(__DIR__) . '/errorviewdetailed.php');
113
+        if (file_exists(realpath(__DIR__).'/errorviewdetailed.php')) {
114
+            include(realpath(__DIR__).'/errorviewdetailed.php');
115 115
         } else {
116 116
             header('Content-type: application/json');
117 117
             die(json_encode($error));
118 118
         }
119 119
         exit;
120 120
     } else {
121
-        if (file_exists(realpath(__DIR__) . '/errorviewcompact.php')) {
122
-            include(realpath(__DIR__) . '/errorviewcompact.php');
121
+        if (file_exists(realpath(__DIR__).'/errorviewcompact.php')) {
122
+            include(realpath(__DIR__).'/errorviewcompact.php');
123 123
         } else {
124 124
             header('Content-type: application/json');
125 125
             die(json_encode('An error occured.'));
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 	$error = error_get_last(); 
34 34
     if (isset($error['type'], $error['message'], $error['file'], $error['line'])) { 
35 35
         errorHandler($error['type'],$error['message'],$error['file'],$error['line']);
36
-    }elseif ($error['type'] == 1) {
36
+    } elseif ($error['type'] == 1) {
37 37
         dump($error);
38 38
     }
39 39
 }
@@ -85,7 +85,9 @@  discard block
 block discarded – undo
85 85
  * @param string $httpHeader
86 86
  */
87 87
 function renderError ($message='', $file='', $line='', $code=0, $trace=array(), $httpHeader = 'HTTP/1.0 500 Internal Server Error') {
88
-    if (ob_get_contents()) ob_end_clean();
88
+    if (ob_get_contents()) {
89
+    	ob_end_clean();
90
+    }
89 91
     header($_SERVER['SERVER_PROTOCOL'] . $httpHeader, true);
90 92
     header('X-Error-Message: ' . $message);
91 93
     header('X-Error-File: ' . $file);
Please login to merge, or discard this patch.
cloudcontrol/library/cc/Application.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 		 */
66 66
 		private function config()
67 67
 		{
68
-			$configPath = __DIR__ . '/../../config.json';
68
+			$configPath = __DIR__.'/../../config.json';
69 69
 			if (realpath($configPath) !== false) {
70 70
 				$json = file_get_contents($configPath);
71 71
 				$this->config = json_decode($json);
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 		private function sitemapMatching($request)
95 95
 		{
96 96
 			$sitemap = $this->storage->getSitemap();
97
-			$relativeUri = '/' . $request::$relativeUri;
97
+			$relativeUri = '/'.$request::$relativeUri;
98 98
 
99 99
 			foreach ($sitemap as $sitemapItem) {
100 100
 				if ($sitemapItem->regex) {
@@ -157,17 +157,17 @@  discard block
 block discarded – undo
157 157
 		 * @return mixed
158 158
 		 * @throws \Exception
159 159
 		 */
160
-		private function getComponentObject($class='', $template='', $parameters=array(), $matchedSitemapItem)
160
+		private function getComponentObject($class = '', $template = '', $parameters = array(), $matchedSitemapItem)
161 161
 		{
162
-			$libraryComponentName = '\\library\\components\\' . $class;
163
-			$userComponentName = '\\components\\' . $class;
162
+			$libraryComponentName = '\\library\\components\\'.$class;
163
+			$userComponentName = '\\components\\'.$class;
164 164
 			
165 165
 			if (\autoLoad($libraryComponentName, false)) {
166 166
 				$component = new $libraryComponentName($template, $this->request, $parameters, $matchedSitemapItem);
167 167
 			} elseif (\autoLoad($userComponentName, false)) {
168 168
 				$component = new $userComponentName($template, $this->request, $parameters, $matchedSitemapItem);
169 169
 			} else {
170
-				throw new \Exception('Could not load component ' . $class);
170
+				throw new \Exception('Could not load component '.$class);
171 171
 			}
172 172
 			
173 173
 			if (!$component instanceof Component) {
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 		public function setCachingHeaders()
227 227
 		{
228 228
 			header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60 * 24 * 2))); // 2 days
229
-			header("Cache-Control: max-age=" . (60 * 60 * 24 * 2));
229
+			header("Cache-Control: max-age=".(60 * 60 * 24 * 2));
230 230
 		}
231 231
 
232 232
 		/**
Please login to merge, or discard this patch.