Passed
Push — develop ( 9c6499...a5e1bf )
by Jens
02:46
created
src/install/_index.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -25,5 +25,5 @@
 block discarded – undo
25 25
 \CloudControl\Cms\CloudControl::run();
26 26
 
27 27
 if (php_sapi_name() != "cli") {
28
-    ob_end_flush();
28
+	ob_end_flush();
29 29
 }
30 30
\ No newline at end of file
Please login to merge, or discard this patch.
src/images/methods/Watermark.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -12,10 +12,10 @@
 block discarded – undo
12 12
 namespace CloudControl\Cms\images\methods
13 13
 {
14 14
 
15
-    use CloudControl\Cms\images\Image;
16
-    use CloudControl\Cms\images\IMethod;
15
+	use CloudControl\Cms\images\Image;
16
+	use CloudControl\Cms\images\IMethod;
17 17
 
18
-    class Watermark extends IMethod
18
+	class Watermark extends IMethod
19 19
 	{
20 20
 		protected $_x = 0;
21 21
 		protected $_y = 0;
Please login to merge, or discard this patch.
src/images/methods/Crop.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -11,9 +11,9 @@  discard block
 block discarded – undo
11 11
 namespace CloudControl\Cms\images\methods
12 12
 {
13 13
 
14
-    use CloudControl\Cms\images\IMethod;
14
+	use CloudControl\Cms\images\IMethod;
15 15
 
16
-    class Crop extends IMethod
16
+	class Crop extends IMethod
17 17
 	{
18 18
 		protected $_width;
19 19
 		protected $_height;
@@ -116,8 +116,8 @@  discard block
 block discarded – undo
116 116
 
117 117
 			// Preserve transparency
118 118
 			imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127));
119
-            imagealphablending($new, false);
120
-            imagesavealpha($new, true);
119
+			imagealphablending($new, false);
120
+			imagesavealpha($new, true);
121 121
 			
122 122
 			imagecopyresampled($new, $imageResource, $this->_destX, $this->_destY, $this->_x, $this->_y, $this->_destWidth, $this->_destHeight, $this->_destWidth, $this->_destHeight);
123 123
 			
Please login to merge, or discard this patch.
src/images/methods/Resize.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,9 +11,9 @@
 block discarded – undo
11 11
 namespace CloudControl\Cms\images\methods
12 12
 {
13 13
 
14
-    use CloudControl\Cms\images\IMethod;
14
+	use CloudControl\Cms\images\IMethod;
15 15
 
16
-    class Resize extends IMethod
16
+	class Resize extends IMethod
17 17
 	{
18 18
 		protected $_width;
19 19
 		protected $_height;
Please login to merge, or discard this patch.
src/images/methods/Grayscale.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,9 +9,9 @@
 block discarded – undo
9 9
 namespace CloudControl\Cms\images\methods
10 10
 {
11 11
 
12
-    use CloudControl\Cms\images\IMethod;
12
+	use CloudControl\Cms\images\IMethod;
13 13
 
14
-    class Grayscale extends IMethod
14
+	class Grayscale extends IMethod
15 15
 	{		
16 16
 		public function Execute($imageResource)
17 17
 		{			
Please login to merge, or discard this patch.
src/images/ImageResizer.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -2,9 +2,9 @@
 block discarded – undo
2 2
 namespace CloudControl\Cms\images
3 3
 {
4 4
 
5
-    use CloudControl\Cms\cc\StringUtil;
5
+	use CloudControl\Cms\cc\StringUtil;
6 6
 
7
-    /**
7
+	/**
8 8
 	 * Class ImageResizer
9 9
 	 * @package CloudControl\Cms\images
10 10
 	 */
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 				}
46 46
 				return $returnFileNames;
47 47
 			} else {
48
-				throw new \Exception('Image doesnt exist: ' . $imagePath);
48
+				throw new \Exception('Image doesnt exist: '.$imagePath);
49 49
 			}
50 50
 		}
51 51
 
@@ -56,10 +56,10 @@  discard block
 block discarded – undo
56 56
 		 * @return string
57 57
 		 * @throws \Exception
58 58
 		 */
59
-		public function resize($imagePath='', $width='',$height='')
59
+		public function resize($imagePath = '', $width = '', $height = '')
60 60
 		{
61
-			$modifier = '-r' . $width . 'x' . $height;
62
-			return $this->applyMethod('Resize', $imagePath, $width,$height, $modifier);
61
+			$modifier = '-r'.$width.'x'.$height;
62
+			return $this->applyMethod('Resize', $imagePath, $width, $height, $modifier);
63 63
 		}
64 64
 
65 65
 		/**
@@ -69,10 +69,10 @@  discard block
 block discarded – undo
69 69
 		 * @return string
70 70
 		 * @throws \Exception
71 71
 		 */
72
-		public function smartcrop($imagePath='', $width='',$height='')
72
+		public function smartcrop($imagePath = '', $width = '', $height = '')
73 73
 		{
74
-			$modifier = '-s' . $width . 'x' . $height;
75
-			return $this->applyMethod('SmartCrop', $imagePath, $width,$height, $modifier);
74
+			$modifier = '-s'.$width.'x'.$height;
75
+			return $this->applyMethod('SmartCrop', $imagePath, $width, $height, $modifier);
76 76
 		}
77 77
 
78 78
 		/**
@@ -82,10 +82,10 @@  discard block
 block discarded – undo
82 82
 		 * @return string
83 83
 		 * @throws \Exception
84 84
 		 */
85
-		public function boxcrop($imagePath='', $width='',$height='')
85
+		public function boxcrop($imagePath = '', $width = '', $height = '')
86 86
 		{
87
-			$modifier = '-b' . $width . 'x' . $height;
88
-			return $this->applyMethod('BoxCrop', $imagePath, $width,$height, $modifier);
87
+			$modifier = '-b'.$width.'x'.$height;
88
+			return $this->applyMethod('BoxCrop', $imagePath, $width, $height, $modifier);
89 89
 		}
90 90
 
91 91
 		/**
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 		 *
95 95
 		 * @return string
96 96
 		 */
97
-		private function modifyName($imagePath, $modifier='')
97
+		private function modifyName($imagePath, $modifier = '')
98 98
 		{
99 99
 			$filename = basename($imagePath);
100 100
 			$path = dirname($imagePath);
@@ -104,30 +104,30 @@  discard block
 block discarded – undo
104 104
 				array_pop($fileParts);
105 105
 				$fileNameWithoutExtension = implode('-', $fileParts);
106 106
 				$fileNameWithoutExtension = StringUtil::slugify($fileNameWithoutExtension);
107
-				$filename = $fileNameWithoutExtension . $modifier  . '.' . $extension;
107
+				$filename = $fileNameWithoutExtension.$modifier.'.'.$extension;
108 108
 			} else {
109 109
 				$filename = StringUtil::slugify($filename);
110 110
 			}
111 111
 
112
-			if (file_exists($path . '/' . $filename)) {
112
+			if (file_exists($path.'/'.$filename)) {
113 113
 				$fileParts = explode('.', $filename);
114 114
 				if (count($fileParts) > 1) {
115 115
 					$extension = end($fileParts);
116 116
 					array_pop($fileParts);
117 117
 					$fileNameWithoutExtension = implode('-', $fileParts);
118 118
 					$fileNameWithoutExtension .= '-copy';
119
-					$filename = $fileNameWithoutExtension . '.' . $extension;
119
+					$filename = $fileNameWithoutExtension.'.'.$extension;
120 120
 				} else {
121 121
 					$filename .= '-copy';
122 122
 				}
123
-				return $this->modifyName($path . '/' . $filename);
123
+				return $this->modifyName($path.'/'.$filename);
124 124
 			}
125
-			return $path . '/' . $filename;
125
+			return $path.'/'.$filename;
126 126
 		}
127 127
 
128 128
 		private function applyMethod($method, $imagePath, $width, $height, $modifier)
129 129
 		{
130
-			$method = 'CloudControl\Cms\\images\\methods\\' . $method;
130
+			$method = 'CloudControl\Cms\\images\\methods\\'.$method;
131 131
 			$destination = $this->modifyName($imagePath, $modifier);
132 132
 			if (file_exists($imagePath)) {
133 133
 				$image = new Image();
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 				$resizedImage->saveImage($destination, $resizedImage->getImageMimeType($imagePath), 80);
142 142
 				return basename($destination);
143 143
 			} else {
144
-				throw new \Exception('Image doesnt exist: ' . $imagePath);
144
+				throw new \Exception('Image doesnt exist: '.$imagePath);
145 145
 			}
146 146
 		}
147 147
 	}
Please login to merge, or discard this patch.
src/cc/Application.php 2 patches
Indentation   +276 added lines, -276 removed lines patch added patch discarded remove patch
@@ -2,280 +2,280 @@
 block discarded – undo
2 2
 
3 3
 namespace CloudControl\Cms\cc {
4 4
 
5
-    use CloudControl\Cms\components\Component;
6
-    use CloudControl\Cms\storage\Storage;
7
-    use Whoops\Handler\PrettyPageHandler;
8
-    use Whoops\Run;
9
-
10
-    class Application
11
-    {
12
-        /**
13
-         * @var \stdClass
14
-         */
15
-        private $config;
16
-        /**
17
-         * @var \CloudControl\Cms\storage\Storage
18
-         */
19
-        private $storage;
20
-
21
-        /**
22
-         * @var \CloudControl\Cms\cc\Request
23
-         */
24
-        private $request;
25
-
26
-        /**
27
-         * @var array
28
-         */
29
-        private $matchedSitemapItems = array();
30
-
31
-        /**
32
-         * @var array
33
-         */
34
-        private $applicationComponents = array();
35
-
36
-        /**
37
-         * Application constructor.
38
-         */
39
-        public function __construct()
40
-        {
41
-            $this->config();
42
-            $this->storage();
43
-
44
-            $this->request = new Request();
45
-
46
-            $whoops = new Run;
47
-            $whoops->pushHandler(new PrettyPageHandler);
48
-            $whoops->register();
49
-
50
-            $this->redirectMatching($this->request);
51
-            $this->sitemapMatching($this->request);
52
-
53
-            $this->getApplicationComponents();
54
-
55
-            $this->runApplicationComponents();
56
-            $this->runSitemapComponents();
57
-
58
-            $this->renderApplicationComponents();
59
-            $this->renderSitemapComponents();
60
-        }
61
-
62
-        /**
63
-         * Initialize the config
64
-         *
65
-         * @throws \Exception
66
-         */
67
-        private function config()
68
-        {
69
-            $configPath = __DIR__ . '/../../config.json';
70
-            if (realpath($configPath) !== false) {
71
-                $json = file_get_contents($configPath);
72
-                $this->config = json_decode($json);
73
-            } else {
74
-                throw new \Exception('Framework not initialized yet. Consider running composer install');
75
-            }
76
-        }
77
-
78
-        /**
79
-         * Initialize the storage
80
-         */
81
-        private function storage()
82
-        {
83
-            $this->storage = new Storage($this->getStorageDir(), $this->config->imagesDir, $this->config->filesDir);
84
-        }
85
-
86
-        private function redirectMatching($request)
87
-        {
88
-            $redirects = $this->storage->getRedirects()->getRedirects();
89
-            $relativeUri = '/' . $request::$relativeUri;
90
-
91
-            foreach ($redirects as $redirect) {
92
-                if (preg_match_all($redirect->fromUrl, $relativeUri, $matches)) {
93
-                    $toUrl = preg_replace($redirect->fromUrl, $redirect->toUrl, $relativeUri);
94
-                    if (substr($toUrl, 0, 1) == '/') {
95
-                        $toUrl = substr($toUrl, 1);
96
-                    }
97
-                    if ($redirect->type == '301') {
98
-                        header('HTTP/1.1 301 Moved Permanently');
99
-                        header('Location: ' . $request::$subfolders . $toUrl);
100
-                        exit;
101
-                    } elseif ($redirect->type == '302') {
102
-                        header('Location: ' . $request::$subfolders . $toUrl, true, 302);
103
-                        exit;
104
-                    } else {
105
-                        throw new \Exception('Invalid redirect type.');
106
-                    }
107
-                }
108
-            }
109
-        }
110
-
111
-        /**
112
-         * Loop through sitemap items and see if one matches the requestUri.
113
-         * If it does, add it tot the matchedSitemapItems array
114
-         *
115
-         * @param $request
116
-         */
117
-        private function sitemapMatching($request)
118
-        {
119
-            $sitemap = $this->storage->getSitemap()->getSitemap();
120
-            $relativeUri = '/' . $request::$relativeUri;
121
-
122
-            foreach ($sitemap as $sitemapItem) {
123
-                if ($sitemapItem->regex) {
124
-                    $matches = array();
125
-                    if (preg_match_all($sitemapItem->url, $relativeUri, $matches)) {
126
-                        // Make a clone, so it doesnt add the matches to the original
127
-                        $matchedClone = clone $sitemapItem;
128
-                        $matchedClone->matches = $matches;
129
-                        $this->matchedSitemapItems[] = $matchedClone;
130
-                        return;
131
-                    }
132
-                } else {
133
-                    if ($sitemapItem->url == $relativeUri) {
134
-                        $this->matchedSitemapItems[] = $sitemapItem;
135
-                        return;
136
-                    }
137
-                }
138
-            }
139
-        }
140
-
141
-        /**
142
-         * Loop through all application components and run them
143
-         *
144
-         * @throws \Exception
145
-         */
146
-        private function runApplicationComponents()
147
-        {
148
-            foreach ($this->applicationComponents as $key => $applicationComponent) {
149
-                $class = $applicationComponent->component;
150
-                $parameters = $applicationComponent->parameters;
151
-                $this->applicationComponents[$key]->{'object'} = $this->getComponentObject($class, null, $parameters, null);
152
-                $this->applicationComponents[$key]->{'object'}->run($this->storage);
153
-            }
154
-        }
155
-
156
-        /**
157
-         * Loop through all (matched) sitemap components and run them
158
-         *
159
-         * @throws \Exception
160
-         */
161
-        private function runSitemapComponents()
162
-        {
163
-            foreach ($this->matchedSitemapItems as $key => $sitemapItem) {
164
-                $class = $sitemapItem->component;
165
-                $template = $sitemapItem->template;
166
-                $parameters = $sitemapItem->parameters;
167
-
168
-                $this->matchedSitemapItems[$key]->object = $this->getComponentObject($class, $template, $parameters, $sitemapItem);
169
-
170
-                $this->matchedSitemapItems[$key]->object->run($this->storage);
171
-            }
172
-        }
173
-
174
-        /**
175
-         * @param string $class
176
-         * @param string $template
177
-         * @param array $parameters
178
-         * @param \stdClass|null $matchedSitemapItem
179
-         *
180
-         * @return mixed
181
-         * @throws \Exception
182
-         */
183
-        private function getComponentObject($class = '', $template = '', $parameters = array(), $matchedSitemapItem)
184
-        {
185
-            $libraryComponentName = '\\CloudControl\Cms\\components\\' . $class;
186
-            $userComponentName = '\\components\\' . $class;
187
-
188
-            if (!class_exists($libraryComponentName, false)) {
189
-                $component = new $libraryComponentName($template, $this->request, $parameters, $matchedSitemapItem);
190
-            } elseif (!class_exists($userComponentName, false)) {
191
-                $component = new $userComponentName($template, $this->request, $parameters, $matchedSitemapItem);
192
-            } else {
193
-                throw new \Exception('Could not load component ' . $class);
194
-            }
195
-
196
-            if (!$component instanceof Component) {
197
-                throw new \Exception('Component not of type Component. Must inherit \CloudControl\Cms\components\Component');
198
-            }
199
-
200
-            return $component;
201
-        }
202
-
203
-        /**
204
-         * Loop through all application components and render them
205
-         */
206
-        private function renderApplicationComponents()
207
-        {
208
-            foreach ($this->applicationComponents as $applicationComponent) {
209
-                $applicationComponent->{'object'}->render();
210
-            }
211
-        }
212
-
213
-        /**
214
-         * Loop through all (matched) sitemap components and render them
215
-         */
216
-        private function renderSitemapComponents()
217
-        {
218
-            foreach ($this->matchedSitemapItems as $sitemapItem) {
219
-                $this->setCachingHeaders();
220
-                $sitemapItem->object->render($this);
221
-                ob_clean();
222
-                echo $sitemapItem->object->get();
223
-                ob_end_flush();
224
-                exit;
225
-            }
226
-        }
227
-
228
-        public function getAllApplicationComponentParameters()
229
-        {
230
-            $allParameters = array();
231
-            foreach ($this->applicationComponents as $applicationComponent) {
232
-                $parameters = $applicationComponent->{'object'}->getParameters();
233
-                $allParameters[] = $parameters;
234
-            }
235
-            return $allParameters;
236
-        }
237
-
238
-        public function unlockApplicationComponentParameters()
239
-        {
240
-            foreach ($this->applicationComponents as $applicationComponent) {
241
-                $parameters = $applicationComponent->{'object'}->getParameters();
242
-                extract($parameters);
243
-            }
244
-        }
245
-
246
-        /**
247
-         * Set the default caching of pages to 2 days
248
-         */
249
-        public function setCachingHeaders()
250
-        {
251
-            header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60 * 24 * 2))); // 2 days
252
-            header("Cache-Control: max-age=" . (60 * 60 * 24 * 2));
253
-        }
254
-
255
-        /**
256
-         * @return string
257
-         */
258
-        public function getStoragePath()
259
-        {
260
-            return $this->config->storagePath;
261
-        }
262
-
263
-        /**
264
-         * @return string
265
-         */
266
-        public function getTemplatePath()
267
-        {
268
-            return $this->config->templateDir;
269
-        }
270
-
271
-        public function getStorageDir()
272
-        {
273
-            return $this->config->storageDir;
274
-        }
275
-
276
-        public function getApplicationComponents()
277
-        {
278
-            $this->applicationComponents = $this->storage->getApplicationComponents()->getApplicationComponents();
279
-        }
280
-    }
5
+	use CloudControl\Cms\components\Component;
6
+	use CloudControl\Cms\storage\Storage;
7
+	use Whoops\Handler\PrettyPageHandler;
8
+	use Whoops\Run;
9
+
10
+	class Application
11
+	{
12
+		/**
13
+		 * @var \stdClass
14
+		 */
15
+		private $config;
16
+		/**
17
+		 * @var \CloudControl\Cms\storage\Storage
18
+		 */
19
+		private $storage;
20
+
21
+		/**
22
+		 * @var \CloudControl\Cms\cc\Request
23
+		 */
24
+		private $request;
25
+
26
+		/**
27
+		 * @var array
28
+		 */
29
+		private $matchedSitemapItems = array();
30
+
31
+		/**
32
+		 * @var array
33
+		 */
34
+		private $applicationComponents = array();
35
+
36
+		/**
37
+		 * Application constructor.
38
+		 */
39
+		public function __construct()
40
+		{
41
+			$this->config();
42
+			$this->storage();
43
+
44
+			$this->request = new Request();
45
+
46
+			$whoops = new Run;
47
+			$whoops->pushHandler(new PrettyPageHandler);
48
+			$whoops->register();
49
+
50
+			$this->redirectMatching($this->request);
51
+			$this->sitemapMatching($this->request);
52
+
53
+			$this->getApplicationComponents();
54
+
55
+			$this->runApplicationComponents();
56
+			$this->runSitemapComponents();
57
+
58
+			$this->renderApplicationComponents();
59
+			$this->renderSitemapComponents();
60
+		}
61
+
62
+		/**
63
+		 * Initialize the config
64
+		 *
65
+		 * @throws \Exception
66
+		 */
67
+		private function config()
68
+		{
69
+			$configPath = __DIR__ . '/../../config.json';
70
+			if (realpath($configPath) !== false) {
71
+				$json = file_get_contents($configPath);
72
+				$this->config = json_decode($json);
73
+			} else {
74
+				throw new \Exception('Framework not initialized yet. Consider running composer install');
75
+			}
76
+		}
77
+
78
+		/**
79
+		 * Initialize the storage
80
+		 */
81
+		private function storage()
82
+		{
83
+			$this->storage = new Storage($this->getStorageDir(), $this->config->imagesDir, $this->config->filesDir);
84
+		}
85
+
86
+		private function redirectMatching($request)
87
+		{
88
+			$redirects = $this->storage->getRedirects()->getRedirects();
89
+			$relativeUri = '/' . $request::$relativeUri;
90
+
91
+			foreach ($redirects as $redirect) {
92
+				if (preg_match_all($redirect->fromUrl, $relativeUri, $matches)) {
93
+					$toUrl = preg_replace($redirect->fromUrl, $redirect->toUrl, $relativeUri);
94
+					if (substr($toUrl, 0, 1) == '/') {
95
+						$toUrl = substr($toUrl, 1);
96
+					}
97
+					if ($redirect->type == '301') {
98
+						header('HTTP/1.1 301 Moved Permanently');
99
+						header('Location: ' . $request::$subfolders . $toUrl);
100
+						exit;
101
+					} elseif ($redirect->type == '302') {
102
+						header('Location: ' . $request::$subfolders . $toUrl, true, 302);
103
+						exit;
104
+					} else {
105
+						throw new \Exception('Invalid redirect type.');
106
+					}
107
+				}
108
+			}
109
+		}
110
+
111
+		/**
112
+		 * Loop through sitemap items and see if one matches the requestUri.
113
+		 * If it does, add it tot the matchedSitemapItems array
114
+		 *
115
+		 * @param $request
116
+		 */
117
+		private function sitemapMatching($request)
118
+		{
119
+			$sitemap = $this->storage->getSitemap()->getSitemap();
120
+			$relativeUri = '/' . $request::$relativeUri;
121
+
122
+			foreach ($sitemap as $sitemapItem) {
123
+				if ($sitemapItem->regex) {
124
+					$matches = array();
125
+					if (preg_match_all($sitemapItem->url, $relativeUri, $matches)) {
126
+						// Make a clone, so it doesnt add the matches to the original
127
+						$matchedClone = clone $sitemapItem;
128
+						$matchedClone->matches = $matches;
129
+						$this->matchedSitemapItems[] = $matchedClone;
130
+						return;
131
+					}
132
+				} else {
133
+					if ($sitemapItem->url == $relativeUri) {
134
+						$this->matchedSitemapItems[] = $sitemapItem;
135
+						return;
136
+					}
137
+				}
138
+			}
139
+		}
140
+
141
+		/**
142
+		 * Loop through all application components and run them
143
+		 *
144
+		 * @throws \Exception
145
+		 */
146
+		private function runApplicationComponents()
147
+		{
148
+			foreach ($this->applicationComponents as $key => $applicationComponent) {
149
+				$class = $applicationComponent->component;
150
+				$parameters = $applicationComponent->parameters;
151
+				$this->applicationComponents[$key]->{'object'} = $this->getComponentObject($class, null, $parameters, null);
152
+				$this->applicationComponents[$key]->{'object'}->run($this->storage);
153
+			}
154
+		}
155
+
156
+		/**
157
+		 * Loop through all (matched) sitemap components and run them
158
+		 *
159
+		 * @throws \Exception
160
+		 */
161
+		private function runSitemapComponents()
162
+		{
163
+			foreach ($this->matchedSitemapItems as $key => $sitemapItem) {
164
+				$class = $sitemapItem->component;
165
+				$template = $sitemapItem->template;
166
+				$parameters = $sitemapItem->parameters;
167
+
168
+				$this->matchedSitemapItems[$key]->object = $this->getComponentObject($class, $template, $parameters, $sitemapItem);
169
+
170
+				$this->matchedSitemapItems[$key]->object->run($this->storage);
171
+			}
172
+		}
173
+
174
+		/**
175
+		 * @param string $class
176
+		 * @param string $template
177
+		 * @param array $parameters
178
+		 * @param \stdClass|null $matchedSitemapItem
179
+		 *
180
+		 * @return mixed
181
+		 * @throws \Exception
182
+		 */
183
+		private function getComponentObject($class = '', $template = '', $parameters = array(), $matchedSitemapItem)
184
+		{
185
+			$libraryComponentName = '\\CloudControl\Cms\\components\\' . $class;
186
+			$userComponentName = '\\components\\' . $class;
187
+
188
+			if (!class_exists($libraryComponentName, false)) {
189
+				$component = new $libraryComponentName($template, $this->request, $parameters, $matchedSitemapItem);
190
+			} elseif (!class_exists($userComponentName, false)) {
191
+				$component = new $userComponentName($template, $this->request, $parameters, $matchedSitemapItem);
192
+			} else {
193
+				throw new \Exception('Could not load component ' . $class);
194
+			}
195
+
196
+			if (!$component instanceof Component) {
197
+				throw new \Exception('Component not of type Component. Must inherit \CloudControl\Cms\components\Component');
198
+			}
199
+
200
+			return $component;
201
+		}
202
+
203
+		/**
204
+		 * Loop through all application components and render them
205
+		 */
206
+		private function renderApplicationComponents()
207
+		{
208
+			foreach ($this->applicationComponents as $applicationComponent) {
209
+				$applicationComponent->{'object'}->render();
210
+			}
211
+		}
212
+
213
+		/**
214
+		 * Loop through all (matched) sitemap components and render them
215
+		 */
216
+		private function renderSitemapComponents()
217
+		{
218
+			foreach ($this->matchedSitemapItems as $sitemapItem) {
219
+				$this->setCachingHeaders();
220
+				$sitemapItem->object->render($this);
221
+				ob_clean();
222
+				echo $sitemapItem->object->get();
223
+				ob_end_flush();
224
+				exit;
225
+			}
226
+		}
227
+
228
+		public function getAllApplicationComponentParameters()
229
+		{
230
+			$allParameters = array();
231
+			foreach ($this->applicationComponents as $applicationComponent) {
232
+				$parameters = $applicationComponent->{'object'}->getParameters();
233
+				$allParameters[] = $parameters;
234
+			}
235
+			return $allParameters;
236
+		}
237
+
238
+		public function unlockApplicationComponentParameters()
239
+		{
240
+			foreach ($this->applicationComponents as $applicationComponent) {
241
+				$parameters = $applicationComponent->{'object'}->getParameters();
242
+				extract($parameters);
243
+			}
244
+		}
245
+
246
+		/**
247
+		 * Set the default caching of pages to 2 days
248
+		 */
249
+		public function setCachingHeaders()
250
+		{
251
+			header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60 * 24 * 2))); // 2 days
252
+			header("Cache-Control: max-age=" . (60 * 60 * 24 * 2));
253
+		}
254
+
255
+		/**
256
+		 * @return string
257
+		 */
258
+		public function getStoragePath()
259
+		{
260
+			return $this->config->storagePath;
261
+		}
262
+
263
+		/**
264
+		 * @return string
265
+		 */
266
+		public function getTemplatePath()
267
+		{
268
+			return $this->config->templateDir;
269
+		}
270
+
271
+		public function getStorageDir()
272
+		{
273
+			return $this->config->storageDir;
274
+		}
275
+
276
+		public function getApplicationComponents()
277
+		{
278
+			$this->applicationComponents = $this->storage->getApplicationComponents()->getApplicationComponents();
279
+		}
280
+	}
281 281
 }
282 282
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
          */
67 67
         private function config()
68 68
         {
69
-            $configPath = __DIR__ . '/../../config.json';
69
+            $configPath = __DIR__.'/../../config.json';
70 70
             if (realpath($configPath) !== false) {
71 71
                 $json = file_get_contents($configPath);
72 72
                 $this->config = json_decode($json);
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
         private function redirectMatching($request)
87 87
         {
88 88
             $redirects = $this->storage->getRedirects()->getRedirects();
89
-            $relativeUri = '/' . $request::$relativeUri;
89
+            $relativeUri = '/'.$request::$relativeUri;
90 90
 
91 91
             foreach ($redirects as $redirect) {
92 92
                 if (preg_match_all($redirect->fromUrl, $relativeUri, $matches)) {
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
                     }
97 97
                     if ($redirect->type == '301') {
98 98
                         header('HTTP/1.1 301 Moved Permanently');
99
-                        header('Location: ' . $request::$subfolders . $toUrl);
99
+                        header('Location: '.$request::$subfolders.$toUrl);
100 100
                         exit;
101 101
                     } elseif ($redirect->type == '302') {
102
-                        header('Location: ' . $request::$subfolders . $toUrl, true, 302);
102
+                        header('Location: '.$request::$subfolders.$toUrl, true, 302);
103 103
                         exit;
104 104
                     } else {
105 105
                         throw new \Exception('Invalid redirect type.');
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
         private function sitemapMatching($request)
118 118
         {
119 119
             $sitemap = $this->storage->getSitemap()->getSitemap();
120
-            $relativeUri = '/' . $request::$relativeUri;
120
+            $relativeUri = '/'.$request::$relativeUri;
121 121
 
122 122
             foreach ($sitemap as $sitemapItem) {
123 123
                 if ($sitemapItem->regex) {
@@ -182,15 +182,15 @@  discard block
 block discarded – undo
182 182
          */
183 183
         private function getComponentObject($class = '', $template = '', $parameters = array(), $matchedSitemapItem)
184 184
         {
185
-            $libraryComponentName = '\\CloudControl\Cms\\components\\' . $class;
186
-            $userComponentName = '\\components\\' . $class;
185
+            $libraryComponentName = '\\CloudControl\Cms\\components\\'.$class;
186
+            $userComponentName = '\\components\\'.$class;
187 187
 
188 188
             if (!class_exists($libraryComponentName, false)) {
189 189
                 $component = new $libraryComponentName($template, $this->request, $parameters, $matchedSitemapItem);
190 190
             } elseif (!class_exists($userComponentName, false)) {
191 191
                 $component = new $userComponentName($template, $this->request, $parameters, $matchedSitemapItem);
192 192
             } else {
193
-                throw new \Exception('Could not load component ' . $class);
193
+                throw new \Exception('Could not load component '.$class);
194 194
             }
195 195
 
196 196
             if (!$component instanceof Component) {
@@ -248,8 +248,8 @@  discard block
 block discarded – undo
248 248
          */
249 249
         public function setCachingHeaders()
250 250
         {
251
-            header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60 * 24 * 2))); // 2 days
252
-            header("Cache-Control: max-age=" . (60 * 60 * 24 * 2));
251
+            header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60 * 24 * 2))); // 2 days
252
+            header("Cache-Control: max-age=".(60 * 60 * 24 * 2));
253 253
         }
254 254
 
255 255
         /**
Please login to merge, or discard this patch.
src/cc/Request.php 2 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace CloudControl\Cms\cc
3 3
 {
4
-    /**
5
-     * Class Request
6
-     * @package CloudControl\Cms\cc
7
-     */
4
+	/**
5
+	 * Class Request
6
+	 * @package CloudControl\Cms\cc
7
+	 */
8 8
 	class Request {
9 9
 
10 10
 		/**
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 		 */
46 46
 		public function __construct() 
47 47
 		{
48
-            $rootPath = str_replace('\\', '/', realpath(str_replace('\\', '/', dirname(__FILE__)) . '/../../') . '/');
48
+			$rootPath = str_replace('\\', '/', realpath(str_replace('\\', '/', dirname(__FILE__)) . '/../../') . '/');
49 49
 			
50 50
 			self::$subfolders = '/' . str_replace('//', '/', str_replace(str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']), "", $rootPath));
51 51
 			self::$subfolders = str_replace('//', '/', self::$subfolders);
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -45,23 +45,23 @@
 block discarded – undo
45 45
 		 */
46 46
 		public function __construct() 
47 47
 		{
48
-            $rootPath = str_replace('\\', '/', realpath(str_replace('\\', '/', dirname(__FILE__)) . '/../../') . '/');
48
+            $rootPath = str_replace('\\', '/', realpath(str_replace('\\', '/', dirname(__FILE__)).'/../../').'/');
49 49
 			
50
-			self::$subfolders = '/' . str_replace('//', '/', str_replace(str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']), "", $rootPath));
50
+			self::$subfolders = '/'.str_replace('//', '/', str_replace(str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']), "", $rootPath));
51 51
 			self::$subfolders = str_replace('//', '/', self::$subfolders);
52 52
 			if (PHP_SAPI === 'cli') {
53 53
 				global $argv;
54 54
 				array_shift($argv);
55 55
 				self::$queryString = '';
56
-				self::$requestUri = self::$subfolders . implode('/', $argv);
56
+				self::$requestUri = self::$subfolders.implode('/', $argv);
57 57
 			} else {
58 58
 				self::$requestUri = $_SERVER['REQUEST_URI'];
59 59
 				self::$queryString = $_SERVER['QUERY_STRING'];
60 60
 			}
61 61
 			if (self::$subfolders === '/') {
62
-				self::$relativeUri = str_replace('?' . self::$queryString, '', substr(self::$requestUri,1));
62
+				self::$relativeUri = str_replace('?'.self::$queryString, '', substr(self::$requestUri, 1));
63 63
 			} else {
64
-				self::$relativeUri = str_replace('?' . self::$queryString, '', str_replace(self::$subfolders, '', self::$requestUri));
64
+				self::$relativeUri = str_replace('?'.self::$queryString, '', str_replace(self::$subfolders, '', self::$requestUri));
65 65
 			}
66 66
 
67 67
 			self::$requestParameters = explode('/', self::$relativeUri);
Please login to merge, or discard this patch.
src/templates/documents/function.renderDocument.php 2 patches
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.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 { ?>
10 10
   <div class="grid-box-10">
11 11
     <h3>
12
-      <a class="btn documentTitle" href="<?= $request::$subfolders ?><?= $cmsPrefix ?>/documents/edit-document?slug=<?= $slugPrefix . $document->slug ?>" title="Edit">
12
+      <a class="btn documentTitle" href="<?= $request::$subfolders ?><?= $cmsPrefix ?>/documents/edit-document?slug=<?= $slugPrefix.$document->slug ?>" title="Edit">
13 13
         <i class="fa fa-file-text-o"></i>
14 14
         <small class="state <?= strtolower($document->state) ?>">
15 15
           <i class="fa <?= $document->state == 'published' ? 'fa-check-circle-o' : 'fa-times-circle-o' ?>"></i></small>
@@ -32,23 +32,23 @@  discard block
 block discarded – undo
32 32
       <? if ($document->state == 'unpublished' || $document->unpublishedChanges) : ?>
33 33
           <? renderAction('Publish',
34 34
               'publish',
35
-              $request::$subfolders . $cmsPrefix . '/documents/publish-document?slug=' . $slugPrefix . $document->slug,
35
+              $request::$subfolders.$cmsPrefix.'/documents/publish-document?slug='.$slugPrefix.$document->slug,
36 36
               'check'); ?>
37 37
       <? endif ?>
38 38
       <? if ($document->state == 'published') : ?>
39 39
           <? renderAction('Unpublish',
40 40
               'unpublish',
41
-              $request::$subfolders . $cmsPrefix . '/documents/unpublish-document?slug=' . $slugPrefix . $document->slug,
41
+              $request::$subfolders.$cmsPrefix.'/documents/unpublish-document?slug='.$slugPrefix.$document->slug,
42 42
               'times'); ?>
43 43
       <? endif ?>
44 44
       <? renderAction('Edit',
45 45
           '',
46
-          $request::$subfolders . $cmsPrefix . '/documents/edit-document?slug=' . $slugPrefix . $document->slug,
46
+          $request::$subfolders.$cmsPrefix.'/documents/edit-document?slug='.$slugPrefix.$document->slug,
47 47
           'pencil'); ?>
48 48
       <? if ($document->state == 'unpublished') : ?>
49 49
           <? renderAction('Delete',
50 50
               'error',
51
-              $request::$subfolders . $cmsPrefix . '/documents/delete-document?slug=' . $slugPrefix . $document->slug,
51
+              $request::$subfolders.$cmsPrefix.'/documents/delete-document?slug='.$slugPrefix.$document->slug,
52 52
               'trash',
53 53
               'return confirm(\'Are you sure you want to delete this document?\');'); ?>
54 54
       <? endif ?>
Please login to merge, or discard this patch.