Passed
Push — master ( 8c639f...f61691 )
by Jens
05:01
created
src/templates/documents/function.renderDocument.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -31,26 +31,26 @@
 block discarded – undo
31 31
   <div class="documentActions grid-box-2">
32 32
       <? if ($document->state == 'unpublished' || $document->unpublishedChanges) : ?>
33 33
           <? renderAction('Publish',
34
-              'publish',
35
-              $request::$subfolders . $cmsPrefix . '/documents/publish-document?slug=' . $slugPrefix . $document->slug,
36
-              'check'); ?>
34
+                'publish',
35
+                $request::$subfolders . $cmsPrefix . '/documents/publish-document?slug=' . $slugPrefix . $document->slug,
36
+                'check'); ?>
37 37
       <? endif ?>
38 38
       <? if ($document->state == 'published') : ?>
39 39
           <? renderAction('Unpublish',
40
-              'unpublish',
41
-              $request::$subfolders . $cmsPrefix . '/documents/unpublish-document?slug=' . $slugPrefix . $document->slug,
42
-              'times'); ?>
40
+                'unpublish',
41
+                $request::$subfolders . $cmsPrefix . '/documents/unpublish-document?slug=' . $slugPrefix . $document->slug,
42
+                'times'); ?>
43 43
       <? endif ?>
44 44
       <? renderAction('Edit',
45
-          '',
46
-          $request::$subfolders . $cmsPrefix . '/documents/edit-document?slug=' . $slugPrefix . $document->slug,
47
-          'pencil'); ?>
45
+            '',
46
+            $request::$subfolders . $cmsPrefix . '/documents/edit-document?slug=' . $slugPrefix . $document->slug,
47
+            'pencil'); ?>
48 48
       <? if ($document->state == 'unpublished') : ?>
49 49
           <? renderAction('Delete',
50
-              'error',
51
-              $request::$subfolders . $cmsPrefix . '/documents/delete-document?slug=' . $slugPrefix . $document->slug,
52
-              'trash',
53
-              'return confirm(\'Are you sure you want to delete this document?\');'); ?>
50
+                'error',
51
+                $request::$subfolders . $cmsPrefix . '/documents/delete-document?slug=' . $slugPrefix . $document->slug,
52
+                'trash',
53
+                'return confirm(\'Are you sure you want to delete this document?\');'); ?>
54 54
       <? endif ?>
55 55
   </div>
56 56
 <? } ?>
Please login to merge, or discard this patch.
src/templates/documents/function.renderFolder.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -17,14 +17,14 @@
 block discarded – undo
17 17
   </div>
18 18
   <div class="documentActions grid-box-4">
19 19
       <? renderAction('Edit',
20
-          '',
21
-          $request::$subfolders . $cmsPrefix . '/documents/edit-folder?slug=' . $slugPrefix . $document->slug,
22
-          'pencil'); ?>
20
+            '',
21
+            $request::$subfolders . $cmsPrefix . '/documents/edit-folder?slug=' . $slugPrefix . $document->slug,
22
+            'pencil'); ?>
23 23
       <? renderAction('Delete',
24
-          'error',
25
-          $request::$subfolders . $cmsPrefix . '/documents/delete-folder?slug=' . $slugPrefix . $document->slug,
26
-          'trash',
27
-          'return confirm(\'Are you sure you want to delete this document?\');'); ?>
24
+            'error',
25
+            $request::$subfolders . $cmsPrefix . '/documents/delete-folder?slug=' . $slugPrefix . $document->slug,
26
+            'trash',
27
+            'return confirm(\'Are you sure you want to delete this document?\');'); ?>
28 28
   </div>
29 29
   <ul class="documents grid-wrapper nested<?= $root ? ' root' : '' ?>">
30 30
       <? foreach ($document->getContent() as $subDocument) : ?>
Please login to merge, or discard this patch.
src/templates/documents/document-form-form.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -22,11 +22,11 @@  discard block
 block discarded – undo
22 22
 				<div class="form-element">
23 23
 					<label for="<?=$field->slug?>"><?=$field->title?></label>
24 24
 					<? if (isset($document)) :
25
-						$fieldSlug = $field->slug;
26
-						$value = isset($document->fields->$fieldSlug) ? current($document->fields->$fieldSlug) : '';
27
-					else :
28
-						$value = '';
29
-					endif ?>
25
+                        $fieldSlug = $field->slug;
26
+                        $value = isset($document->fields->$fieldSlug) ? current($document->fields->$fieldSlug) : '';
27
+                    else :
28
+                        $value = '';
29
+                    endif ?>
30 30
 					<? if ($field->multiple == true && $field->type != 'Rich Text') : ?>
31 31
 					<ul class="grid-wrapper sortable">
32 32
 						<li class="grid-container">
@@ -54,10 +54,10 @@  discard block
 block discarded – undo
54 54
 							</div>
55 55
 						</li>
56 56
 						<? if (isset($document)) :
57
-							$fieldSlug = $field->slug;
58
-							$iterable = isset($document->fields->$fieldSlug) ? $document->fields->$fieldSlug : array();
59
-							array_shift($iterable);
60
-							?>
57
+                            $fieldSlug = $field->slug;
58
+                            $iterable = isset($document->fields->$fieldSlug) ? $document->fields->$fieldSlug : array();
59
+                            array_shift($iterable);
60
+                            ?>
61 61
 							<? foreach ($iterable as $value) : ?>
62 62
 
63 63
 							<li class="grid-container">
@@ -80,10 +80,10 @@  discard block
 block discarded – undo
80 80
 					<a class="btn js-addmultiple">+</a>
81 81
 					<? elseif ($field->multiple == true) : ?>
82 82
 						<? if (isset($document)) :
83
-							$fieldSlug = $field->slug;
84
-							$iterable = isset($document->fields->$fieldSlug) ? $document->fields->$fieldSlug : array();
85
-							array_shift($iterable);
86
-							?>
83
+                            $fieldSlug = $field->slug;
84
+                            $iterable = isset($document->fields->$fieldSlug) ? $document->fields->$fieldSlug : array();
85
+                            array_shift($iterable);
86
+                            ?>
87 87
 							<? foreach ($iterable as $value) : ?>
88 88
 
89 89
 							<li>
@@ -118,10 +118,10 @@  discard block
 block discarded – undo
118 118
 							<? foreach ($document->bricks as $currentBrickSlug => $brickArray) : ?>
119 119
 								<? foreach ($brickArray as $dynamicBrick) : ?>
120 120
 									<? foreach ($bricks as $brick) :
121
-										if (is_object($dynamicBrick) && isset($dynamicBrick->type) && $brick->slug === $dynamicBrick->type && $currentBrickSlug === $myBrickSlug) {
122
-											break;
123
-										}
124
-									endforeach ?>
121
+                                        if (is_object($dynamicBrick) && isset($dynamicBrick->type) && $brick->slug === $dynamicBrick->type && $currentBrickSlug === $myBrickSlug) {
122
+                                            break;
123
+                                        }
124
+                                    endforeach ?>
125 125
 									<? if (is_object($dynamicBrick) && isset($dynamicBrick->type) && $brick->slug === $dynamicBrick->type && $currentBrickSlug === $myBrickSlug) : ?>
126 126
 									<li class="brick form-element">
127 127
 
@@ -142,12 +142,12 @@  discard block
 block discarded – undo
142 142
 						<div class="form-element">
143 143
 						<label for="<?=$field->slug?>"><?=$field->title?></label>
144 144
 						<? if (isset($document)) :
145
-							$brickSlug = $brick->slug;
146
-							$fieldSlug = $field->slug;
147
-							$value = isset($document->bricks->$brickSlug->fields->$fieldSlug) ? current($document->bricks->$brickSlug->fields->$fieldSlug) : '';
148
-						else :
149
-							$value = '';
150
-						endif ?>
145
+                            $brickSlug = $brick->slug;
146
+                            $fieldSlug = $field->slug;
147
+                            $value = isset($document->bricks->$brickSlug->fields->$fieldSlug) ? current($document->bricks->$brickSlug->fields->$fieldSlug) : '';
148
+                        else :
149
+                            $value = '';
150
+                        endif ?>
151 151
 						<? if ($field->multiple == true && $field->type != 'Rich Text') : ?>
152 152
 						<ul class="grid-wrapper sortable">
153 153
 							<li class="grid-container">
@@ -175,11 +175,11 @@  discard block
 block discarded – undo
175 175
 								</div>
176 176
 							</li>
177 177
 							<? if (isset($document)) :
178
-								$brickSlug = $brick->slug;
179
-								$fieldSlug = $field->slug;
180
-								$iterable = isset($document->bricks->$brickSlug->fields->$fieldSlug) ? $document->bricks->$brickSlug->fields->$fieldSlug : array();
181
-								array_shift($iterable);
182
-								?>
178
+                                $brickSlug = $brick->slug;
179
+                                $fieldSlug = $field->slug;
180
+                                $iterable = isset($document->bricks->$brickSlug->fields->$fieldSlug) ? $document->bricks->$brickSlug->fields->$fieldSlug : array();
181
+                                array_shift($iterable);
182
+                                ?>
183 183
 								<? foreach ($iterable as $value) : ?>
184 184
 
185 185
 								<li class="grid-container">
@@ -202,11 +202,11 @@  discard block
 block discarded – undo
202 202
 						<a class="btn js-addmultiple">+</a>
203 203
 						<? elseif ($field->multiple == true) : ?>
204 204
 							<? if (isset($document)) :
205
-								$brickSlug = $brick->slug;
206
-								$fieldSlug = $field->slug;
207
-								$iterable = isset($document->bricks->$brickSlug->fields->$fieldSlug) ? $document->bricks->$brickSlug->fields->$fieldSlug : array();
208
-								array_shift($iterable);
209
-								?>
205
+                                $brickSlug = $brick->slug;
206
+                                $fieldSlug = $field->slug;
207
+                                $iterable = isset($document->bricks->$brickSlug->fields->$fieldSlug) ? $document->bricks->$brickSlug->fields->$fieldSlug : array();
208
+                                array_shift($iterable);
209
+                                ?>
210 210
 								<? foreach ($iterable as $value) : ?>
211 211
 
212 212
 								<li>
@@ -246,10 +246,10 @@  discard block
 block discarded – undo
246 246
 				<? if (isset($document)) : ?>
247 247
 					<? foreach ($document->dynamicBricks as $dynamicBrick) : ?>
248 248
 						<? foreach ($bricks as $brick) :
249
-						if ($brick->slug == $dynamicBrick->type) {
250
-							break;
251
-						}
252
-						endforeach ?>
249
+                        if ($brick->slug == $dynamicBrick->type) {
250
+                            break;
251
+                        }
252
+                        endforeach ?>
253 253
 						<li class="brick form-element">
254 254
 							<label><?=$brick->title?></label>
255 255
 							<?$static = false; ?>
Please login to merge, or discard this patch.
src/cc/StringUtil.php 1 patch
Indentation   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -8,123 +8,123 @@
 block discarded – undo
8 8
 
9 9
 class StringUtil
10 10
 {
11
-	/**
12
-	 * Convert a string to url friendly slug
13
-	 *
14
-	 * @param string $str
15
-	 * @param array  $replace
16
-	 * @param string $delimiter
17
-	 *
18
-	 * @return mixed|string
19
-	 */
20
-	public static function slugify($str, $replace = array(), $delimiter = '-')
21
-	{
22
-		if (!empty($replace)) {
23
-			$str = str_replace((array)$replace, ' ', $str);
24
-		}
25
-
26
-		$clean = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $str);
27
-		$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
28
-		$clean = strtolower(trim($clean, '-'));
29
-		$clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
30
-
31
-		return $clean;
32
-	}
33
-
34
-	/**
35
-	 * Selects the right font-awesome icon for each filetype
36
-	 *
37
-	 * @param $fileType
38
-	 *
39
-	 * @return string
40
-	 */
41
-	public static function iconByFileType($fileType)
42
-	{
43
-		$fileTypeIcons = array(
44
-			'image'                                                                   => 'file-image-o',
45
-			'pdf'                                                                     => 'file-pdf-o',
46
-			'audio'                                                                   => 'file-audio-o',
47
-			'x-msdownload'                                                            => 'windows',
48
-			'application/vnd.ms-excel'                                                => 'file-excel-o',
49
-			'application/msexcel'                                                     => 'file-excel-o',
50
-			'application/xls'                                                         => 'file-excel-o',
51
-			'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'       => 'file-excel-o',
52
-			'application/vnd.google-apps.spreadsheet'                                 => 'file-excel-o',
53
-			'application/msword'                                                      => 'file-word-o',
54
-			'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'file-word-o',
55
-			'application/x-rar-compressed'                                            => 'file-archive-o',
56
-			'application/x-zip-compressed'                                            => 'file-archive-o',
57
-			'application/zip'                                                         => 'file-archive-o',
58
-			'text'                                                                    => 'file-text-o',
59
-		);
60
-
61
-		foreach ($fileTypeIcons as $needle => $icon) {
62
-			if (strpos($fileType, $needle) !== false) {
63
-				return $icon;
64
-			}
65
-		}
66
-
67
-		return 'file-o';
68
-	}
69
-
70
-	/**
71
-	 * Converts an amount of bytes to a human readable
72
-	 * format
73
-	 *
74
-	 * @param        $size
75
-	 * @param string $unit
76
-	 *
77
-	 * @return string
78
-	 */
79
-	public static function humanFileSize($size, $unit = "")
80
-	{
81
-		if ((!$unit && $size >= 1 << 30) || $unit == "GB")
82
-			return number_format($size / (1 << 30), 2) . "GB";
83
-		if ((!$unit && $size >= 1 << 20) || $unit == "MB")
84
-			return number_format($size / (1 << 20), 2) . "MB";
85
-		if ((!$unit && $size >= 1 << 10) || $unit == "KB")
86
-			return number_format($size / (1 << 10), 2) . "KB";
87
-
88
-		return number_format($size) . " bytes";
89
-	}
90
-
91
-	/**
92
-	 * @param $ptime
93
-	 *
94
-	 * @return string
95
-	 */
96
-	public static function timeElapsedString($ptime)
97
-	{
98
-		$etime = time() - $ptime;
99
-
100
-		if ($etime < 1) {
101
-			return '0 seconds';
102
-		}
103
-
104
-		$a = array(365 * 24 * 60 * 60 => 'year',
105
-				   30 * 24 * 60 * 60  => 'month',
106
-				   24 * 60 * 60       => 'day',
107
-				   60 * 60            => 'hour',
108
-				   60                 => 'minute',
109
-				   1                  => 'second'
110
-		);
111
-		$a_plural = array('year'   => 'years',
112
-						  'month'  => 'months',
113
-						  'day'    => 'days',
114
-						  'hour'   => 'hours',
115
-						  'minute' => 'minutes',
116
-						  'second' => 'seconds'
117
-		);
118
-
119
-		foreach ($a as $secs => $str) {
120
-			$d = $etime / $secs;
121
-			if ($d >= 1) {
122
-				$r = round($d);
123
-
124
-				return $r . ' ' . ($r > 1 ? $a_plural[$str] : $str) . ' ago';
125
-			}
126
-		}
127
-
128
-		return 0;
129
-	}
11
+    /**
12
+     * Convert a string to url friendly slug
13
+     *
14
+     * @param string $str
15
+     * @param array  $replace
16
+     * @param string $delimiter
17
+     *
18
+     * @return mixed|string
19
+     */
20
+    public static function slugify($str, $replace = array(), $delimiter = '-')
21
+    {
22
+        if (!empty($replace)) {
23
+            $str = str_replace((array)$replace, ' ', $str);
24
+        }
25
+
26
+        $clean = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $str);
27
+        $clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
28
+        $clean = strtolower(trim($clean, '-'));
29
+        $clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
30
+
31
+        return $clean;
32
+    }
33
+
34
+    /**
35
+     * Selects the right font-awesome icon for each filetype
36
+     *
37
+     * @param $fileType
38
+     *
39
+     * @return string
40
+     */
41
+    public static function iconByFileType($fileType)
42
+    {
43
+        $fileTypeIcons = array(
44
+            'image'                                                                   => 'file-image-o',
45
+            'pdf'                                                                     => 'file-pdf-o',
46
+            'audio'                                                                   => 'file-audio-o',
47
+            'x-msdownload'                                                            => 'windows',
48
+            'application/vnd.ms-excel'                                                => 'file-excel-o',
49
+            'application/msexcel'                                                     => 'file-excel-o',
50
+            'application/xls'                                                         => 'file-excel-o',
51
+            'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'       => 'file-excel-o',
52
+            'application/vnd.google-apps.spreadsheet'                                 => 'file-excel-o',
53
+            'application/msword'                                                      => 'file-word-o',
54
+            'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'file-word-o',
55
+            'application/x-rar-compressed'                                            => 'file-archive-o',
56
+            'application/x-zip-compressed'                                            => 'file-archive-o',
57
+            'application/zip'                                                         => 'file-archive-o',
58
+            'text'                                                                    => 'file-text-o',
59
+        );
60
+
61
+        foreach ($fileTypeIcons as $needle => $icon) {
62
+            if (strpos($fileType, $needle) !== false) {
63
+                return $icon;
64
+            }
65
+        }
66
+
67
+        return 'file-o';
68
+    }
69
+
70
+    /**
71
+     * Converts an amount of bytes to a human readable
72
+     * format
73
+     *
74
+     * @param        $size
75
+     * @param string $unit
76
+     *
77
+     * @return string
78
+     */
79
+    public static function humanFileSize($size, $unit = "")
80
+    {
81
+        if ((!$unit && $size >= 1 << 30) || $unit == "GB")
82
+            return number_format($size / (1 << 30), 2) . "GB";
83
+        if ((!$unit && $size >= 1 << 20) || $unit == "MB")
84
+            return number_format($size / (1 << 20), 2) . "MB";
85
+        if ((!$unit && $size >= 1 << 10) || $unit == "KB")
86
+            return number_format($size / (1 << 10), 2) . "KB";
87
+
88
+        return number_format($size) . " bytes";
89
+    }
90
+
91
+    /**
92
+     * @param $ptime
93
+     *
94
+     * @return string
95
+     */
96
+    public static function timeElapsedString($ptime)
97
+    {
98
+        $etime = time() - $ptime;
99
+
100
+        if ($etime < 1) {
101
+            return '0 seconds';
102
+        }
103
+
104
+        $a = array(365 * 24 * 60 * 60 => 'year',
105
+                    30 * 24 * 60 * 60  => 'month',
106
+                    24 * 60 * 60       => 'day',
107
+                    60 * 60            => 'hour',
108
+                    60                 => 'minute',
109
+                    1                  => 'second'
110
+        );
111
+        $a_plural = array('year'   => 'years',
112
+                            'month'  => 'months',
113
+                            'day'    => 'days',
114
+                            'hour'   => 'hours',
115
+                            'minute' => 'minutes',
116
+                            'second' => 'seconds'
117
+        );
118
+
119
+        foreach ($a as $secs => $str) {
120
+            $d = $etime / $secs;
121
+            if ($d >= 1) {
122
+                $r = round($d);
123
+
124
+                return $r . ' ' . ($r > 1 ? $a_plural[$str] : $str) . ' ago';
125
+            }
126
+        }
127
+
128
+        return 0;
129
+    }
130 130
 }
131 131
\ No newline at end of file
Please login to merge, or discard this patch.
src/cc/Request.php 1 patch
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -5,79 +5,79 @@
 block discarded – undo
5 5
      * Class Request
6 6
      * @package CloudControl\Cms\cc
7 7
      */
8
-	class Request {
8
+    class Request {
9 9
 
10
-		/**
11
-		 * @var string
12
-		 */
13
-		public static $subfolders;
14
-		/**
15
-		 * @var string
16
-		 */
17
-		public static $requestUri;
18
-		/**
19
-		 * @var string
20
-		 */
21
-		public static $relativeUri;
22
-		/**
23
-		 * @var string
24
-		 */
25
-		public static $queryString;
26
-		/**
27
-		 * @var array
28
-		 */
29
-		public static $requestParameters;
30
-		/**
31
-		 * @var array
32
-		 */
33
-		public static $post = array();
34
-		/**
35
-		 * @var array
36
-		 */
37
-		public static $get = array();
38
-		/**
39
-		 * @var array
40
-		 */
41
-		private $statics = array();
10
+        /**
11
+         * @var string
12
+         */
13
+        public static $subfolders;
14
+        /**
15
+         * @var string
16
+         */
17
+        public static $requestUri;
18
+        /**
19
+         * @var string
20
+         */
21
+        public static $relativeUri;
22
+        /**
23
+         * @var string
24
+         */
25
+        public static $queryString;
26
+        /**
27
+         * @var array
28
+         */
29
+        public static $requestParameters;
30
+        /**
31
+         * @var array
32
+         */
33
+        public static $post = array();
34
+        /**
35
+         * @var array
36
+         */
37
+        public static $get = array();
38
+        /**
39
+         * @var array
40
+         */
41
+        private $statics = array();
42 42
 
43
-		/**
44
-		 * Request constructor.
45
-		 */
46
-		public function __construct() 
47
-		{
43
+        /**
44
+         * Request constructor.
45
+         */
46
+        public function __construct() 
47
+        {
48 48
             $rootPath = str_replace('\\', '/', realpath(str_replace('\\', '/', dirname(__FILE__)) . '/../../') . '/');
49 49
 			
50
-			self::$subfolders = '/' . str_replace('//', '/', str_replace(str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']), "", $rootPath));
51
-			self::$subfolders = str_replace('//', '/', self::$subfolders);
52
-			if (PHP_SAPI === 'cli') {
53
-				global $argv;
54
-				array_shift($argv);
55
-				self::$queryString = '';
56
-				self::$requestUri = self::$subfolders . implode('/', $argv);
57
-			} else {
58
-				self::$requestUri = $_SERVER['REQUEST_URI'];
59
-				self::$queryString = $_SERVER['QUERY_STRING'];
60
-			}
61
-			if (self::$subfolders === '/') {
62
-				self::$relativeUri = str_replace('?' . self::$queryString, '', substr(self::$requestUri,1));
63
-			} else {
64
-				self::$relativeUri = str_replace('?' . self::$queryString, '', str_replace(self::$subfolders, '', self::$requestUri));
65
-			}
50
+            self::$subfolders = '/' . str_replace('//', '/', str_replace(str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']), "", $rootPath));
51
+            self::$subfolders = str_replace('//', '/', self::$subfolders);
52
+            if (PHP_SAPI === 'cli') {
53
+                global $argv;
54
+                array_shift($argv);
55
+                self::$queryString = '';
56
+                self::$requestUri = self::$subfolders . implode('/', $argv);
57
+            } else {
58
+                self::$requestUri = $_SERVER['REQUEST_URI'];
59
+                self::$queryString = $_SERVER['QUERY_STRING'];
60
+            }
61
+            if (self::$subfolders === '/') {
62
+                self::$relativeUri = str_replace('?' . self::$queryString, '', substr(self::$requestUri,1));
63
+            } else {
64
+                self::$relativeUri = str_replace('?' . self::$queryString, '', str_replace(self::$subfolders, '', self::$requestUri));
65
+            }
66 66
 
67
-			self::$requestParameters = explode('/', self::$relativeUri);
67
+            self::$requestParameters = explode('/', self::$relativeUri);
68 68
 			
69
-			self::$get = $_GET;
70
-			self::$post = $_POST;
69
+            self::$get = $_GET;
70
+            self::$post = $_POST;
71 71
 			
72
-			$this->statics = array(
73
-				'subfolders' => self::$subfolders,
74
-				'requestUri' => self::$requestUri,
75
-				'relativeUri' => self::$relativeUri,
76
-				'queryString' => self::$queryString,
77
-				'requestParameters' => self::$requestParameters,
78
-				'post' => self::$post,
79
-				'get' => self::$get
80
-			);
81
-		}
82
-	}
72
+            $this->statics = array(
73
+                'subfolders' => self::$subfolders,
74
+                'requestUri' => self::$requestUri,
75
+                'relativeUri' => self::$relativeUri,
76
+                'queryString' => self::$queryString,
77
+                'requestParameters' => self::$requestParameters,
78
+                'post' => self::$post,
79
+                'get' => self::$get
80
+            );
81
+        }
82
+    }
83 83
 }
84 84
\ No newline at end of file
Please login to merge, or discard this patch.
src/cc/errortemplates/errorviewcli.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 
17 17
 <?php
18 18
 foreach($lines as $nr => $currentLine) {
19
-	echo ($nr == $line ? '* ' : '  ' ) . str_pad($nr, 3, "0", STR_PAD_LEFT) . ' ' . $currentLine;
19
+    echo ($nr == $line ? '* ' : '  ' ) . str_pad($nr, 3, "0", STR_PAD_LEFT) . ' ' . $currentLine;
20 20
 }
21 21
 ?>
22 22
 
@@ -26,10 +26,10 @@  discard block
 block discarded – undo
26 26
 
27 27
 <?php
28 28
 foreach($trace as $row) {
29
-	echo (isset($row['file']) ? basename($row['file']) : '') . ':'
30
-		. (isset($row['line']) ? $row['line'] : '') . "\t\t\t"
31
-		. (isset($row['class']) ? $row['class'] : ' ') . "\t\t\t"
32
-		. (isset($row['type']) ? $row['type'] : ' ') . "\t\t\t"
33
-		. (isset($row['function']) ? $row['function'] : ' ') . PHP_EOL;
29
+    echo (isset($row['file']) ? basename($row['file']) : '') . ':'
30
+        . (isset($row['line']) ? $row['line'] : '') . "\t\t\t"
31
+        . (isset($row['class']) ? $row['class'] : ' ') . "\t\t\t"
32
+        . (isset($row['type']) ? $row['type'] : ' ') . "\t\t\t"
33
+        . (isset($row['function']) ? $row['function'] : ' ') . PHP_EOL;
34 34
 }
35 35
 ?>
36 36
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/SearchComponent.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -14,41 +14,41 @@
 block discarded – undo
14 14
 
15 15
 class SearchComponent extends BaseComponent
16 16
 {
17
-	protected $searchParameterName = 'q';
18
-	protected $searchResultsParameterName = 'searchResults';
19
-
20
-	/**
21
-	 * @param \CloudControl\Cms\storage\Storage $storage
22
-	 */
23
-	public function run(Storage $storage)
24
-	{
25
-		parent::run($storage);
26
-
27
-		$this->checkParameters();
28
-
29
-		$request = $this->request;
30
-		if (isset($request::$get[$this->searchParameterName])) {
31
-			$query = $request::$get[$this->searchParameterName];
32
-			$filteredQuery = new CharacterFilter($query);
33
-			$tokenizer = new Tokenizer($filteredQuery);
34
-			$search = new Search($storage);
35
-			$results = $search->getDocumentsForTokenizer($tokenizer);
36
-			$this->parameters[$this->searchResultsParameterName] = $results;
37
-		}
38
-	}
39
-
40
-	/**
41
-	 * Checks to see if any parameters were defined in the cms and acts according
42
-	 */
43
-	private function checkParameters()
44
-	{
45
-		if (isset($this->parameters['searchParameterName'])) {
46
-			$this->searchParameterName = $this->parameters['searchParameterName'];
47
-		}
48
-
49
-		if (isset($this->parameters['searchResultsParameterName'])) {
50
-			$this->searchParameterName = $this->parameters['searchResultsParameterName'];
51
-		}
52
-	}
17
+    protected $searchParameterName = 'q';
18
+    protected $searchResultsParameterName = 'searchResults';
19
+
20
+    /**
21
+     * @param \CloudControl\Cms\storage\Storage $storage
22
+     */
23
+    public function run(Storage $storage)
24
+    {
25
+        parent::run($storage);
26
+
27
+        $this->checkParameters();
28
+
29
+        $request = $this->request;
30
+        if (isset($request::$get[$this->searchParameterName])) {
31
+            $query = $request::$get[$this->searchParameterName];
32
+            $filteredQuery = new CharacterFilter($query);
33
+            $tokenizer = new Tokenizer($filteredQuery);
34
+            $search = new Search($storage);
35
+            $results = $search->getDocumentsForTokenizer($tokenizer);
36
+            $this->parameters[$this->searchResultsParameterName] = $results;
37
+        }
38
+    }
39
+
40
+    /**
41
+     * Checks to see if any parameters were defined in the cms and acts according
42
+     */
43
+    private function checkParameters()
44
+    {
45
+        if (isset($this->parameters['searchParameterName'])) {
46
+            $this->searchParameterName = $this->parameters['searchParameterName'];
47
+        }
48
+
49
+        if (isset($this->parameters['searchResultsParameterName'])) {
50
+            $this->searchParameterName = $this->parameters['searchResultsParameterName'];
51
+        }
52
+    }
53 53
 
54 54
 }
55 55
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/FormComponent.php 1 patch
Indentation   +320 added lines, -320 removed lines patch added patch discarded remove patch
@@ -7,324 +7,324 @@
 block discarded – undo
7 7
 
8 8
 class FormComponent Extends BaseComponent
9 9
 {
10
-	const GET_PARAMETER_PATH = 'path';
11
-
12
-	const PARAMETER_CMS_PREFIX = 'cmsPrefix';
13
-	const PARAMETER_DOCUMENT_TYPE = 'documentType';
14
-	const PARAMETER_DOCUMENT_TYPES = 'documentTypes';
15
-	const PARAMETER_FORM_ID = 'formId';
16
-	const PARAMETER_FORM_PARAMETER_NAME = 'formParameterName';
17
-	const PARAMETER_HIDE_TITLE_AND_STATE = 'hideTitleAndState';
18
-	const PARAMETER_RESPONSE_FOLDER = 'responseFolder';
19
-	const PARAMETER_SMALLEST_IMAGE = 'smallestImage';
20
-	const PARAMETER_SUBMIT_ONCE_PER_SESSION = 'submitOncePerSession';
21
-	const PARAMETER_SUB_TEMPLATE = 'subTemplate';
22
-	const PARAMETER_THANK_YOU_MESSAGE = 'thankYouMessage';
23
-
24
-	const SESSION_PARAMETER_CLOUDCONTROL = 'cloudcontrol';
25
-	const SESSION_PARAMETER_FORM_COMPONENT = 'FormComponent';
26
-	/**
27
-	 * @var null|string
28
-	 */
29
-	protected $documentType = null;
30
-	/**
31
-	 * @var null|string
32
-	 */
33
-	protected $responseFolder = null;
34
-	/**
35
-	 * @var string
36
-	 */
37
-	protected $subTemplate = 'cms/documents/document-form-form';
38
-	/**
39
-	 * @var string
40
-	 */
41
-	protected $formParameterName = 'form';
42
-	/**
43
-	 * @var string
44
-	 */
45
-	protected $thankYouMessage = 'Thank you for sending us your response.';
46
-
47
-	/**
48
-	 * @var bool
49
-	 */
50
-	protected $submitOncePerSession = false;
51
-
52
-	/**
53
-	 * @var string
54
-	 */
55
-	private $formId;
56
-	/**
57
-	 * @var null|string
58
-	 */
59
-	private $getPathBackup = null;
60
-
61
-	/**
62
-	 * @var null|\stdClass
63
-	 */
64
-	private $userSessionBackup = null;
65
-
66
-	/**
67
-	 * @param Storage $storage
68
-	 *
69
-	 * @return void
70
-	 * @throws \Exception
71
-	 */
72
-	public function run(Storage $storage)
73
-	{
74
-		parent::run($storage);
75
-		$this->checkParameters();
76
-		$this->checkRequiredParameters();
77
-		$this->setFormId();
78
-		$this->initialize($storage);
79
-		$this->checkSubmit($storage);
80
-	}
81
-
82
-	/**
83
-	 * @param null|Application $application
84
-	 *
85
-	 * @throws \Exception
86
-	 */
87
-	public function render($application = null)
88
-	{
89
-		$request = $this->setPathBackup();
90
-		$form = $this->renderTemplate($this->subTemplate);
91
-		$this->resetPathBackup($request);
92
-		$this->setFormParameter($form);
93
-
94
-		parent::render($application);
95
-	}
96
-
97
-	/**
98
-	 * Checks if parameters were given in the CMS configuration and
99
-	 * sets them to their respective fields
100
-	 */
101
-	private function checkParameters()
102
-	{
103
-		$this->checkDocumentTypeParameter();
104
-		$this->checkResponseFolderParameter();
105
-		$this->checkSubTemplateParameter();
106
-		$this->checkFormParameterNameParameter();
107
-		$this->checkThankYouMessageParameter();
108
-		$this->checkSubmitOncePerSessionParameter();
109
-	}
110
-
111
-	/**
112
-	 * Sets variables needed for rendering the form template
113
-	 *
114
-	 * @param Storage $storage
115
-	 */
116
-	private function initialize($storage)
117
-	{
118
-		$this->parameters[self::PARAMETER_SMALLEST_IMAGE] = $storage->getImageSet()->getSmallestImageSet();
119
-		$this->parameters[self::PARAMETER_CMS_PREFIX] = '';
120
-
121
-		$this->parameters[self::PARAMETER_DOCUMENT_TYPE] = $this->storage->getDocumentTypes()->getDocumentTypeBySlug($this->documentType, true);
122
-		$this->parameters[self::PARAMETER_DOCUMENT_TYPES] = $this->storage->getDocumentTypes()->getDocumentTypes();
123
-		$this->parameters[self::PARAMETER_HIDE_TITLE_AND_STATE] = true;
124
-		$this->parameters[self::PARAMETER_FORM_ID] = $this->formId;
125
-	}
126
-
127
-	/**
128
-	 * If the form has been submitted, save the document
129
-	 * Calls $this->postSubmit() afterwards
130
-	 *
131
-	 * @param Storage $storage
132
-	 */
133
-	private function checkSubmit($storage)
134
-	{
135
-		if ($this->isFormSubmitted($this->request) && $this->isSubmitAllowed()) {
136
-			$postValues = $this->getPostValues($this->request);
137
-			$this->setUserSessionBackup();
138
-			$storage->getDocuments()->addDocument($postValues);
139
-			$this->restoreUserSessionBackup();
140
-			$this->setSubmitToSession();
141
-			$this->postSubmit($postValues, $storage);
142
-		}
143
-	}
144
-
145
-	/**
146
-	 * Hook for derived classes to take actions after
147
-	 * submitting the form
148
-	 *
149
-	 * @param $postValues
150
-	 * @param $storage
151
-	 */
152
-	protected function postSubmit($postValues, $storage)
153
-	{}
154
-
155
-	/**
156
-	 * Sets a unique id for this particular form, so it can recognize
157
-	 * it when a submit occurs
158
-	 */
159
-	private function setFormId()
160
-	{
161
-		if (isset($_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID])) {
162
-			$this->formId = $_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID];
163
-		} else {
164
-			$_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID] = (string)microtime(true);
165
-			$_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName]['submitted'] = false;
166
-			$this->formId = $_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID];
167
-		}
168
-	}
169
-
170
-	/**
171
-	 * Checks if this form has been submitted
172
-	 *
173
-	 * @param \CloudControl\Cms\cc\Request $request
174
-	 *
175
-	 * @return bool
176
-	 */
177
-	private function isFormSubmitted($request)
178
-	{
179
-		return !empty($request::$post) && isset($request::$post[self::PARAMETER_FORM_ID]) && $request::$post[self::PARAMETER_FORM_ID] === $this->formId && isset($_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID]) && $_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID] === $this->formId;
180
-	}
181
-
182
-	/**
183
-	 * @param \cc\Request $request
184
-	 * @return array
185
-	 */
186
-	private function getPostValues($request)
187
-	{
188
-		$postValues = $request::$post;
189
-		$postValues[self::PARAMETER_DOCUMENT_TYPE] = $this->documentType;
190
-		$postValues[self::GET_PARAMETER_PATH] = $this->responseFolder;
191
-		$postValues['title'] = date('r') . ' - From: ' . $request::$requestUri;
192
-
193
-		return $postValues;
194
-	}
195
-
196
-	/**
197
-	 * Temporarily stores the current user session in a backup variable
198
-	 * and sets a fake user instead
199
-	 */
200
-	private function setUserSessionBackup()
201
-	{
202
-		$this->userSessionBackup = isset($_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL]) ? $_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL] : null;
203
-		$fakeUser = new \stdClass();
204
-		$fakeUser->username = self::SESSION_PARAMETER_FORM_COMPONENT;
205
-		$_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL] = $fakeUser;
206
-	}
207
-
208
-	/**
209
-	 * Removes the fake user and restores the existing user
210
-	 * session if it was there
211
-	 */
212
-	private function restoreUserSessionBackup()
213
-	{
214
-		if ($this->userSessionBackup === null) {
215
-			unset($_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL]);
216
-		} else {
217
-			$_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL] = $this->userSessionBackup;
218
-		}
219
-	}
220
-
221
-	private function setSubmitToSession()
222
-	{
223
-		$_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName]['submitted'] = true;
224
-	}
225
-
226
-	private function isSubmitAllowed()
227
-	{
228
-		if ($this->submitOncePerSession === true && $_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName]['submitted'] === true) {
229
-			return false;
230
-		} else {
231
-			return true;
232
-		}
233
-	}
234
-
235
-	private function checkDocumentTypeParameter()
236
-	{
237
-		if (isset($this->parameters[self::PARAMETER_DOCUMENT_TYPE])) {
238
-			$this->documentType = $this->parameters[self::PARAMETER_DOCUMENT_TYPE];
239
-			unset($this->parameters[self::PARAMETER_DOCUMENT_TYPE]);
240
-		}
241
-	}
242
-
243
-	private function checkResponseFolderParameter()
244
-	{
245
-		if (isset($this->parameters[self::PARAMETER_RESPONSE_FOLDER])) {
246
-			$this->responseFolder = $this->parameters[self::PARAMETER_RESPONSE_FOLDER];
247
-			unset($this->parameters[self::PARAMETER_RESPONSE_FOLDER]);
248
-		}
249
-	}
250
-
251
-	private function checkSubTemplateParameter()
252
-	{
253
-		if (isset($this->parameters[self::PARAMETER_SUB_TEMPLATE])) {
254
-			$this->subTemplate = $this->parameters[self::PARAMETER_SUB_TEMPLATE];
255
-			unset($this->parameters[self::PARAMETER_SUB_TEMPLATE]);
256
-		}
257
-	}
258
-
259
-	private function checkFormParameterNameParameter()
260
-	{
261
-		if (isset($this->parameters[self::PARAMETER_FORM_PARAMETER_NAME])) {
262
-			$this->formParameterName = $this->parameters[self::PARAMETER_FORM_PARAMETER_NAME];
263
-			unset($this->parameters[self::PARAMETER_FORM_PARAMETER_NAME]);
264
-		}
265
-	}
266
-
267
-	private function checkThankYouMessageParameter()
268
-	{
269
-		if (isset($this->parameters[self::PARAMETER_THANK_YOU_MESSAGE])) {
270
-			$this->thankYouMessage = $this->parameters[self::PARAMETER_THANK_YOU_MESSAGE];
271
-			unset($this->parameters[self::PARAMETER_THANK_YOU_MESSAGE]);
272
-		}
273
-	}
274
-
275
-	private function checkSubmitOncePerSessionParameter()
276
-	{
277
-		if (isset($this->parameters[self::PARAMETER_SUBMIT_ONCE_PER_SESSION])) {
278
-			$this->submitOncePerSession = $this->parameters[self::PARAMETER_SUBMIT_ONCE_PER_SESSION] === 'true';
279
-			unset($this->parameters[self::PARAMETER_SUBMIT_ONCE_PER_SESSION]);
280
-		}
281
-	}
282
-
283
-	/**
284
-	 * @throws \Exception
285
-	 */
286
-	private function checkRequiredParameters()
287
-	{
288
-		if ($this->documentType === null || $this->responseFolder === null) {
289
-			throw new \Exception('Parameters `documentType` and `responseFolder` are required for usage with this form');
290
-		}
291
-	}
292
-
293
-	/**
294
-	 * @return \cc\Request
295
-	 */
296
-	private function setPathBackup()
297
-	{
298
-		$request = $this->request;
299
-		if (isset($request::$get[self::GET_PARAMETER_PATH])) {
300
-			$this->getPathBackup = $request::$get[self::GET_PARAMETER_PATH];
301
-		}
302
-		$request::$get[self::GET_PARAMETER_PATH] = $this->responseFolder;
303
-
304
-		return $request;
305
-	}
306
-
307
-	/**
308
-	 * @param \cc\Request $request
309
-	 */
310
-	private function resetPathBackup($request)
311
-	{
312
-		if ($this->getPathBackup !== null) {
313
-			$request::$get[self::GET_PARAMETER_PATH] = $this->getPathBackup;
314
-		} else {
315
-			unset($request::$get[self::GET_PARAMETER_PATH]);
316
-		}
317
-	}
318
-
319
-	/**
320
-	 * @param $form
321
-	 */
322
-	private function setFormParameter($form)
323
-	{
324
-		if ($this->isFormSubmitted($this->request) || $this->isSubmitAllowed() === false) {
325
-			$this->parameters[$this->formParameterName] = '<a name="' . $this->formId . '"></a>' . $this->thankYouMessage;
326
-		} else {
327
-			$this->parameters[$this->formParameterName] = $form;
328
-		}
329
-	}
10
+    const GET_PARAMETER_PATH = 'path';
11
+
12
+    const PARAMETER_CMS_PREFIX = 'cmsPrefix';
13
+    const PARAMETER_DOCUMENT_TYPE = 'documentType';
14
+    const PARAMETER_DOCUMENT_TYPES = 'documentTypes';
15
+    const PARAMETER_FORM_ID = 'formId';
16
+    const PARAMETER_FORM_PARAMETER_NAME = 'formParameterName';
17
+    const PARAMETER_HIDE_TITLE_AND_STATE = 'hideTitleAndState';
18
+    const PARAMETER_RESPONSE_FOLDER = 'responseFolder';
19
+    const PARAMETER_SMALLEST_IMAGE = 'smallestImage';
20
+    const PARAMETER_SUBMIT_ONCE_PER_SESSION = 'submitOncePerSession';
21
+    const PARAMETER_SUB_TEMPLATE = 'subTemplate';
22
+    const PARAMETER_THANK_YOU_MESSAGE = 'thankYouMessage';
23
+
24
+    const SESSION_PARAMETER_CLOUDCONTROL = 'cloudcontrol';
25
+    const SESSION_PARAMETER_FORM_COMPONENT = 'FormComponent';
26
+    /**
27
+     * @var null|string
28
+     */
29
+    protected $documentType = null;
30
+    /**
31
+     * @var null|string
32
+     */
33
+    protected $responseFolder = null;
34
+    /**
35
+     * @var string
36
+     */
37
+    protected $subTemplate = 'cms/documents/document-form-form';
38
+    /**
39
+     * @var string
40
+     */
41
+    protected $formParameterName = 'form';
42
+    /**
43
+     * @var string
44
+     */
45
+    protected $thankYouMessage = 'Thank you for sending us your response.';
46
+
47
+    /**
48
+     * @var bool
49
+     */
50
+    protected $submitOncePerSession = false;
51
+
52
+    /**
53
+     * @var string
54
+     */
55
+    private $formId;
56
+    /**
57
+     * @var null|string
58
+     */
59
+    private $getPathBackup = null;
60
+
61
+    /**
62
+     * @var null|\stdClass
63
+     */
64
+    private $userSessionBackup = null;
65
+
66
+    /**
67
+     * @param Storage $storage
68
+     *
69
+     * @return void
70
+     * @throws \Exception
71
+     */
72
+    public function run(Storage $storage)
73
+    {
74
+        parent::run($storage);
75
+        $this->checkParameters();
76
+        $this->checkRequiredParameters();
77
+        $this->setFormId();
78
+        $this->initialize($storage);
79
+        $this->checkSubmit($storage);
80
+    }
81
+
82
+    /**
83
+     * @param null|Application $application
84
+     *
85
+     * @throws \Exception
86
+     */
87
+    public function render($application = null)
88
+    {
89
+        $request = $this->setPathBackup();
90
+        $form = $this->renderTemplate($this->subTemplate);
91
+        $this->resetPathBackup($request);
92
+        $this->setFormParameter($form);
93
+
94
+        parent::render($application);
95
+    }
96
+
97
+    /**
98
+     * Checks if parameters were given in the CMS configuration and
99
+     * sets them to their respective fields
100
+     */
101
+    private function checkParameters()
102
+    {
103
+        $this->checkDocumentTypeParameter();
104
+        $this->checkResponseFolderParameter();
105
+        $this->checkSubTemplateParameter();
106
+        $this->checkFormParameterNameParameter();
107
+        $this->checkThankYouMessageParameter();
108
+        $this->checkSubmitOncePerSessionParameter();
109
+    }
110
+
111
+    /**
112
+     * Sets variables needed for rendering the form template
113
+     *
114
+     * @param Storage $storage
115
+     */
116
+    private function initialize($storage)
117
+    {
118
+        $this->parameters[self::PARAMETER_SMALLEST_IMAGE] = $storage->getImageSet()->getSmallestImageSet();
119
+        $this->parameters[self::PARAMETER_CMS_PREFIX] = '';
120
+
121
+        $this->parameters[self::PARAMETER_DOCUMENT_TYPE] = $this->storage->getDocumentTypes()->getDocumentTypeBySlug($this->documentType, true);
122
+        $this->parameters[self::PARAMETER_DOCUMENT_TYPES] = $this->storage->getDocumentTypes()->getDocumentTypes();
123
+        $this->parameters[self::PARAMETER_HIDE_TITLE_AND_STATE] = true;
124
+        $this->parameters[self::PARAMETER_FORM_ID] = $this->formId;
125
+    }
126
+
127
+    /**
128
+     * If the form has been submitted, save the document
129
+     * Calls $this->postSubmit() afterwards
130
+     *
131
+     * @param Storage $storage
132
+     */
133
+    private function checkSubmit($storage)
134
+    {
135
+        if ($this->isFormSubmitted($this->request) && $this->isSubmitAllowed()) {
136
+            $postValues = $this->getPostValues($this->request);
137
+            $this->setUserSessionBackup();
138
+            $storage->getDocuments()->addDocument($postValues);
139
+            $this->restoreUserSessionBackup();
140
+            $this->setSubmitToSession();
141
+            $this->postSubmit($postValues, $storage);
142
+        }
143
+    }
144
+
145
+    /**
146
+     * Hook for derived classes to take actions after
147
+     * submitting the form
148
+     *
149
+     * @param $postValues
150
+     * @param $storage
151
+     */
152
+    protected function postSubmit($postValues, $storage)
153
+    {}
154
+
155
+    /**
156
+     * Sets a unique id for this particular form, so it can recognize
157
+     * it when a submit occurs
158
+     */
159
+    private function setFormId()
160
+    {
161
+        if (isset($_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID])) {
162
+            $this->formId = $_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID];
163
+        } else {
164
+            $_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID] = (string)microtime(true);
165
+            $_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName]['submitted'] = false;
166
+            $this->formId = $_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID];
167
+        }
168
+    }
169
+
170
+    /**
171
+     * Checks if this form has been submitted
172
+     *
173
+     * @param \CloudControl\Cms\cc\Request $request
174
+     *
175
+     * @return bool
176
+     */
177
+    private function isFormSubmitted($request)
178
+    {
179
+        return !empty($request::$post) && isset($request::$post[self::PARAMETER_FORM_ID]) && $request::$post[self::PARAMETER_FORM_ID] === $this->formId && isset($_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID]) && $_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID] === $this->formId;
180
+    }
181
+
182
+    /**
183
+     * @param \cc\Request $request
184
+     * @return array
185
+     */
186
+    private function getPostValues($request)
187
+    {
188
+        $postValues = $request::$post;
189
+        $postValues[self::PARAMETER_DOCUMENT_TYPE] = $this->documentType;
190
+        $postValues[self::GET_PARAMETER_PATH] = $this->responseFolder;
191
+        $postValues['title'] = date('r') . ' - From: ' . $request::$requestUri;
192
+
193
+        return $postValues;
194
+    }
195
+
196
+    /**
197
+     * Temporarily stores the current user session in a backup variable
198
+     * and sets a fake user instead
199
+     */
200
+    private function setUserSessionBackup()
201
+    {
202
+        $this->userSessionBackup = isset($_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL]) ? $_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL] : null;
203
+        $fakeUser = new \stdClass();
204
+        $fakeUser->username = self::SESSION_PARAMETER_FORM_COMPONENT;
205
+        $_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL] = $fakeUser;
206
+    }
207
+
208
+    /**
209
+     * Removes the fake user and restores the existing user
210
+     * session if it was there
211
+     */
212
+    private function restoreUserSessionBackup()
213
+    {
214
+        if ($this->userSessionBackup === null) {
215
+            unset($_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL]);
216
+        } else {
217
+            $_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL] = $this->userSessionBackup;
218
+        }
219
+    }
220
+
221
+    private function setSubmitToSession()
222
+    {
223
+        $_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName]['submitted'] = true;
224
+    }
225
+
226
+    private function isSubmitAllowed()
227
+    {
228
+        if ($this->submitOncePerSession === true && $_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName]['submitted'] === true) {
229
+            return false;
230
+        } else {
231
+            return true;
232
+        }
233
+    }
234
+
235
+    private function checkDocumentTypeParameter()
236
+    {
237
+        if (isset($this->parameters[self::PARAMETER_DOCUMENT_TYPE])) {
238
+            $this->documentType = $this->parameters[self::PARAMETER_DOCUMENT_TYPE];
239
+            unset($this->parameters[self::PARAMETER_DOCUMENT_TYPE]);
240
+        }
241
+    }
242
+
243
+    private function checkResponseFolderParameter()
244
+    {
245
+        if (isset($this->parameters[self::PARAMETER_RESPONSE_FOLDER])) {
246
+            $this->responseFolder = $this->parameters[self::PARAMETER_RESPONSE_FOLDER];
247
+            unset($this->parameters[self::PARAMETER_RESPONSE_FOLDER]);
248
+        }
249
+    }
250
+
251
+    private function checkSubTemplateParameter()
252
+    {
253
+        if (isset($this->parameters[self::PARAMETER_SUB_TEMPLATE])) {
254
+            $this->subTemplate = $this->parameters[self::PARAMETER_SUB_TEMPLATE];
255
+            unset($this->parameters[self::PARAMETER_SUB_TEMPLATE]);
256
+        }
257
+    }
258
+
259
+    private function checkFormParameterNameParameter()
260
+    {
261
+        if (isset($this->parameters[self::PARAMETER_FORM_PARAMETER_NAME])) {
262
+            $this->formParameterName = $this->parameters[self::PARAMETER_FORM_PARAMETER_NAME];
263
+            unset($this->parameters[self::PARAMETER_FORM_PARAMETER_NAME]);
264
+        }
265
+    }
266
+
267
+    private function checkThankYouMessageParameter()
268
+    {
269
+        if (isset($this->parameters[self::PARAMETER_THANK_YOU_MESSAGE])) {
270
+            $this->thankYouMessage = $this->parameters[self::PARAMETER_THANK_YOU_MESSAGE];
271
+            unset($this->parameters[self::PARAMETER_THANK_YOU_MESSAGE]);
272
+        }
273
+    }
274
+
275
+    private function checkSubmitOncePerSessionParameter()
276
+    {
277
+        if (isset($this->parameters[self::PARAMETER_SUBMIT_ONCE_PER_SESSION])) {
278
+            $this->submitOncePerSession = $this->parameters[self::PARAMETER_SUBMIT_ONCE_PER_SESSION] === 'true';
279
+            unset($this->parameters[self::PARAMETER_SUBMIT_ONCE_PER_SESSION]);
280
+        }
281
+    }
282
+
283
+    /**
284
+     * @throws \Exception
285
+     */
286
+    private function checkRequiredParameters()
287
+    {
288
+        if ($this->documentType === null || $this->responseFolder === null) {
289
+            throw new \Exception('Parameters `documentType` and `responseFolder` are required for usage with this form');
290
+        }
291
+    }
292
+
293
+    /**
294
+     * @return \cc\Request
295
+     */
296
+    private function setPathBackup()
297
+    {
298
+        $request = $this->request;
299
+        if (isset($request::$get[self::GET_PARAMETER_PATH])) {
300
+            $this->getPathBackup = $request::$get[self::GET_PARAMETER_PATH];
301
+        }
302
+        $request::$get[self::GET_PARAMETER_PATH] = $this->responseFolder;
303
+
304
+        return $request;
305
+    }
306
+
307
+    /**
308
+     * @param \cc\Request $request
309
+     */
310
+    private function resetPathBackup($request)
311
+    {
312
+        if ($this->getPathBackup !== null) {
313
+            $request::$get[self::GET_PARAMETER_PATH] = $this->getPathBackup;
314
+        } else {
315
+            unset($request::$get[self::GET_PARAMETER_PATH]);
316
+        }
317
+    }
318
+
319
+    /**
320
+     * @param $form
321
+     */
322
+    private function setFormParameter($form)
323
+    {
324
+        if ($this->isFormSubmitted($this->request) || $this->isSubmitAllowed() === false) {
325
+            $this->parameters[$this->formParameterName] = '<a name="' . $this->formId . '"></a>' . $this->thankYouMessage;
326
+        } else {
327
+            $this->parameters[$this->formParameterName] = $form;
328
+        }
329
+    }
330 330
 }
331 331
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/DocumentFolderComponent.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -10,39 +10,39 @@
 block discarded – undo
10 10
 
11 11
 class DocumentFolderComponent extends BaseComponent
12 12
 {
13
-	const PARAMETER_DOCUMENT_FOLDER_PATH = 'documentFolderPath';
14
-	const PARAMETER_DOCUMENT_FOLDER_PARAMETER_NAME = 'documentFolderParameter';
15
-
16
-	protected $documentFolderParameterName = 'folder';
17
-	protected $documentFolderPath;
18
-
19
-	/**
20
-	 * @param Storage $storage
21
-	 *
22
-	 * @return mixed|void
23
-	 * @throws \Exception
24
-	 */
25
-	public function run(Storage $storage)
26
-	{
27
-		parent::run($storage);
28
-
29
-		$this->checkParameters();
30
-
31
-		$this->parameters[$this->documentFolderParameterName] = $this->storage->getDocumentFolderBySlug($this->documentFolderPath);
32
-	}
33
-
34
-
35
-	/**
36
-	 * Checks to see if any parameters were defined in the cms and acts according
37
-	 */
38
-	private function checkParameters()
39
-	{
40
-		if (isset($this->parameters[self::PARAMETER_DOCUMENT_FOLDER_PATH])) {
41
-			$this->documentFolderPath = $this->parameters[self::PARAMETER_DOCUMENT_FOLDER_PATH];
42
-		}
43
-
44
-		if (isset($this->parameters[self::PARAMETER_DOCUMENT_FOLDER_PARAMETER_NAME])) {
45
-			$this->documentFolderParameterName = $this->parameters[self::PARAMETER_DOCUMENT_FOLDER_PARAMETER_NAME];
46
-		}
47
-	}
13
+    const PARAMETER_DOCUMENT_FOLDER_PATH = 'documentFolderPath';
14
+    const PARAMETER_DOCUMENT_FOLDER_PARAMETER_NAME = 'documentFolderParameter';
15
+
16
+    protected $documentFolderParameterName = 'folder';
17
+    protected $documentFolderPath;
18
+
19
+    /**
20
+     * @param Storage $storage
21
+     *
22
+     * @return mixed|void
23
+     * @throws \Exception
24
+     */
25
+    public function run(Storage $storage)
26
+    {
27
+        parent::run($storage);
28
+
29
+        $this->checkParameters();
30
+
31
+        $this->parameters[$this->documentFolderParameterName] = $this->storage->getDocumentFolderBySlug($this->documentFolderPath);
32
+    }
33
+
34
+
35
+    /**
36
+     * Checks to see if any parameters were defined in the cms and acts according
37
+     */
38
+    private function checkParameters()
39
+    {
40
+        if (isset($this->parameters[self::PARAMETER_DOCUMENT_FOLDER_PATH])) {
41
+            $this->documentFolderPath = $this->parameters[self::PARAMETER_DOCUMENT_FOLDER_PATH];
42
+        }
43
+
44
+        if (isset($this->parameters[self::PARAMETER_DOCUMENT_FOLDER_PARAMETER_NAME])) {
45
+            $this->documentFolderParameterName = $this->parameters[self::PARAMETER_DOCUMENT_FOLDER_PARAMETER_NAME];
46
+        }
47
+    }
48 48
 }
49 49
\ No newline at end of file
Please login to merge, or discard this patch.