@@ -62,8 +62,8 @@ |
||
62 | 62 | |
63 | 63 | // Preserve transparency |
64 | 64 | imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127)); |
65 | - imagealphablending($new, false); |
|
66 | - imagesavealpha($new, true); |
|
65 | + imagealphablending($new, false); |
|
66 | + imagesavealpha($new, true); |
|
67 | 67 | |
68 | 68 | imagecopyresampled($new, $imageResource, $this->_destX, $this->_destY, $this->_x, $this->_y, $this->_destWidth, $this->_destHeight, $originalWidth, $originalHeight); |
69 | 69 |
@@ -62,8 +62,8 @@ |
||
62 | 62 | |
63 | 63 | // Preserve transparency |
64 | 64 | imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127)); |
65 | - imagealphablending($new, false); |
|
66 | - imagesavealpha($new, true); |
|
65 | + imagealphablending($new, false); |
|
66 | + imagesavealpha($new, true); |
|
67 | 67 | |
68 | 68 | imagecopyresampled($new, $imageResource, $this->_destX, $this->_destY, $this->_x, $this->_y, $this->_destWidth, $this->_destHeight, $originalWidth, $originalHeight); |
69 | 69 |
@@ -17,7 +17,7 @@ |
||
17 | 17 | /** |
18 | 18 | * @param resource $imageResource |
19 | 19 | * @return resource |
20 | - */ |
|
20 | + */ |
|
21 | 21 | public function Execute($imageResource) |
22 | 22 | { |
23 | 23 | // Define the origial width and height |
@@ -786,7 +786,7 @@ discard block |
||
786 | 786 | /** |
787 | 787 | * @param $filename |
788 | 788 | * @return null |
789 | - */ |
|
789 | + */ |
|
790 | 790 | public function getImageByName($filename) |
791 | 791 | { |
792 | 792 | $images = $this->getImages(); |
@@ -876,7 +876,7 @@ discard block |
||
876 | 876 | /** |
877 | 877 | * @param $filename |
878 | 878 | * @return null |
879 | - */ |
|
879 | + */ |
|
880 | 880 | public function getFileByName($filename) |
881 | 881 | { |
882 | 882 | $files = $this->getFiles(); |
@@ -891,7 +891,7 @@ discard block |
||
891 | 891 | /** |
892 | 892 | * @param $filename |
893 | 893 | * @throws \Exception |
894 | - */ |
|
894 | + */ |
|
895 | 895 | public function deleteFileByName($filename) |
896 | 896 | { |
897 | 897 | $destinationPath = realpath(__DIR__ . '/../../www/files/'); |
@@ -7,248 +7,248 @@ |
||
7 | 7 | |
8 | 8 | class FormComponent Extends BaseComponent |
9 | 9 | { |
10 | - /** |
|
11 | - * @var null|string |
|
12 | - */ |
|
13 | - protected $documentType = null; |
|
14 | - /** |
|
15 | - * @var null|string |
|
16 | - */ |
|
17 | - protected $responseFolder = null; |
|
18 | - /** |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - protected $subTemplate = 'cms/documents/document-form-form'; |
|
22 | - /** |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - protected $formParameterName = 'form'; |
|
26 | - /** |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - protected $thankYouMessage = 'Thank you for sending us your response.'; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var bool |
|
33 | - */ |
|
34 | - protected $submitOncePerSession = false; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - private $formId; |
|
40 | - /** |
|
41 | - * @var null|string |
|
42 | - */ |
|
43 | - private $getPathBackup = null; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var null|\stdClass |
|
47 | - */ |
|
48 | - private $userSessionBackup = null; |
|
49 | - |
|
50 | - /** |
|
51 | - * @param Storage $storage |
|
52 | - * @return void |
|
53 | - * @throws \Exception |
|
54 | - */ |
|
55 | - public function run(Storage $storage) |
|
56 | - { |
|
57 | - parent::run($storage); |
|
58 | - |
|
59 | - $this->checkParameters(); |
|
60 | - |
|
61 | - if ($this->documentType === null || $this->responseFolder === null) { |
|
62 | - throw new \Exception('Parameters `documentType` and `responseFolder` are required for usage with this form'); |
|
63 | - } |
|
64 | - |
|
65 | - $this->setFormId(); |
|
66 | - $this->initialize($storage); |
|
67 | - $this->checkSubmit($storage); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @param null|Application $application |
|
72 | - * @throws \Exception |
|
73 | - */ |
|
74 | - public function render($application = null) |
|
75 | - { |
|
76 | - $request = $this->request; |
|
77 | - if (isset($request::$get['path'])) { |
|
78 | - $this->getPathBackup = $request::$get['path']; |
|
79 | - } |
|
80 | - $request::$get['path'] = $this->responseFolder; |
|
81 | - $form = $this->renderTemplate($this->subTemplate); |
|
82 | - if ($this->getPathBackup !== null) { |
|
83 | - $request::$get['path'] = $this->getPathBackup; |
|
84 | - } else { |
|
85 | - unset($request::$get['path']); |
|
86 | - } |
|
87 | - if ($this->isFormSubmitted($this->request) || $this->isSubmitAllowed() === false) { |
|
88 | - $this->parameters[$this->formParameterName] = '<a name="' . $this->formId . '"></a>' . $this->thankYouMessage; |
|
89 | - } else { |
|
90 | - $this->parameters[$this->formParameterName] = $form; |
|
91 | - } |
|
92 | - |
|
93 | - parent::render($application); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Checks if parameters were given in the CMS configuration and |
|
98 | - * sets them to their respective fields |
|
99 | - */ |
|
100 | - private function checkParameters() |
|
101 | - { |
|
102 | - if (isset($this->parameters['documentType'])) { |
|
103 | - $this->documentType = $this->parameters['documentType']; |
|
104 | - unset($this->parameters['documentType']); |
|
105 | - } |
|
106 | - |
|
107 | - if (isset($this->parameters['responseFolder'])) { |
|
108 | - $this->responseFolder = $this->parameters['responseFolder']; |
|
109 | - unset($this->parameters['responseFolder']); |
|
110 | - } |
|
111 | - |
|
112 | - if (isset($this->parameters['subTemplate'])) { |
|
113 | - $this->subTemplate = $this->parameters['subTemplate']; |
|
114 | - unset($this->parameters['subTemplate']); |
|
115 | - } |
|
116 | - |
|
117 | - if (isset($this->parameters['formParameterName'])) { |
|
118 | - $this->formParameterName = $this->parameters['formParameterName']; |
|
119 | - unset($this->parameters['formParameterName']); |
|
120 | - } |
|
121 | - |
|
122 | - if (isset($this->parameters['thankYouMessage'])) { |
|
123 | - $this->thankYouMessage = $this->parameters['thankYouMessage']; |
|
124 | - unset($this->parameters['thankYouMessage']); |
|
125 | - } |
|
126 | - |
|
127 | - if (isset($this->parameters['submitOncePerSession'])) { |
|
128 | - $this->submitOncePerSession = $this->parameters['submitOncePerSession'] === 'true' ? true : false; |
|
129 | - unset($this->parameters['submitOncePerSession']); |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Sets variables needed for rendering the form template |
|
135 | - * @param $storage |
|
136 | - */ |
|
137 | - private function initialize($storage) |
|
138 | - { |
|
139 | - $this->parameters['smallestImage'] = $storage->getSmallestImageSet()->slug; |
|
140 | - $this->parameters['cmsPrefix'] = ''; |
|
141 | - |
|
142 | - $this->parameters['documentType'] = $this->storage->getDocumentTypeBySlug($this->documentType, true); |
|
143 | - $this->parameters['documentTypes'] = $this->storage->getDocumentTypes(); |
|
144 | - $this->parameters['hideTitleAndState'] = true; |
|
145 | - $this->parameters['formId'] = $this->formId; |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * If the form has been submitted, save the document |
|
150 | - * Calls $this->postSubmit() afterwards |
|
151 | - * |
|
152 | - * @param Storage $storage |
|
153 | - */ |
|
154 | - private function checkSubmit($storage) |
|
155 | - { |
|
156 | - if ($this->isFormSubmitted($this->request) && $this->isSubmitAllowed()) { |
|
157 | - $postValues = $this->getPostValues($this->request); |
|
158 | - $this->setUserSessionBackup(); |
|
159 | - $storage->addDocument($postValues); |
|
160 | - $this->restoreUserSessionBackup(); |
|
161 | - $this->setSubmitToSession(); |
|
162 | - $this->postSubmit($postValues, $storage); |
|
163 | - } |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Hook for derived classes to take actions after |
|
168 | - * submitting the form |
|
169 | - * |
|
170 | - * @param $postValues |
|
171 | - * @param $storage |
|
172 | - */ |
|
173 | - protected function postSubmit($postValues, $storage) |
|
174 | - {} |
|
175 | - |
|
176 | - /** |
|
177 | - * Sets a unique id for this particular form, so it can recognize |
|
178 | - * it when a submit occurs |
|
179 | - */ |
|
180 | - private function setFormId() |
|
181 | - { |
|
182 | - if (isset($_SESSION['FormComponent'][$this->formParameterName]['formId'])) { |
|
183 | - $this->formId = $_SESSION['FormComponent'][$this->formParameterName]['formId']; |
|
184 | - } else { |
|
185 | - $_SESSION['FormComponent'][$this->formParameterName]['formId'] = (string) microtime(true); |
|
186 | - $_SESSION['FormComponent'][$this->formParameterName]['submitted'] = false; |
|
187 | - $this->formId = $_SESSION['FormComponent'][$this->formParameterName]['formId']; |
|
188 | - } |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Checks if this form has been submitted |
|
193 | - * |
|
194 | - * @param $request |
|
195 | - * @return bool |
|
196 | - */ |
|
197 | - private function isFormSubmitted($request) |
|
198 | - { |
|
199 | - return !empty($request::$post) && isset($request::$post['formId']) && $request::$post['formId'] === $this->formId && isset($_SESSION['FormComponent'][$this->formParameterName]['formId']) && $_SESSION['FormComponent'][$this->formParameterName]['formId'] === $this->formId; |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * |
|
204 | - * |
|
205 | - * @param $request |
|
206 | - */ |
|
207 | - private function getPostValues($request) |
|
208 | - { |
|
209 | - $postValues = $request::$post; |
|
210 | - $postValues['documentType'] = $this->documentType; |
|
211 | - $postValues['path'] = $this->responseFolder; |
|
212 | - $postValues['title'] = date('r') . ' - From: ' . $request::$requestUri; |
|
213 | - return $postValues; |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Temporarily stores the current user session in a backup variable |
|
218 | - * and sets a fake user instead |
|
219 | - */ |
|
220 | - private function setUserSessionBackup() |
|
221 | - { |
|
222 | - $this->userSessionBackup = isset($_SESSION['cloudcontrol']) ? $_SESSION['cloudcontrol'] : null; |
|
223 | - $fakeUser = new \stdClass(); |
|
224 | - $fakeUser->username = 'FormComponent'; |
|
225 | - $_SESSION['cloudcontrol'] = $fakeUser; |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * Removes the fake user and restores the existing user |
|
230 | - * session if it was there |
|
231 | - */ |
|
232 | - private function restoreUserSessionBackup() |
|
233 | - { |
|
234 | - if ($this->userSessionBackup === null) { |
|
235 | - unset($_SESSION['cloudcontrol']); |
|
236 | - } else { |
|
237 | - $_SESSION['cloudcontrol'] = $this->userSessionBackup; |
|
238 | - } |
|
239 | - } |
|
240 | - |
|
241 | - private function setSubmitToSession() |
|
242 | - { |
|
243 | - $_SESSION['FormComponent'][$this->formParameterName]['submitted'] = true; |
|
244 | - } |
|
245 | - |
|
246 | - private function isSubmitAllowed() |
|
247 | - { |
|
248 | - if ($this->submitOncePerSession === true && $_SESSION['FormComponent'][$this->formParameterName]['submitted'] === true) { |
|
249 | - return false; |
|
250 | - } else { |
|
251 | - return true; |
|
252 | - } |
|
253 | - } |
|
10 | + /** |
|
11 | + * @var null|string |
|
12 | + */ |
|
13 | + protected $documentType = null; |
|
14 | + /** |
|
15 | + * @var null|string |
|
16 | + */ |
|
17 | + protected $responseFolder = null; |
|
18 | + /** |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + protected $subTemplate = 'cms/documents/document-form-form'; |
|
22 | + /** |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + protected $formParameterName = 'form'; |
|
26 | + /** |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + protected $thankYouMessage = 'Thank you for sending us your response.'; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var bool |
|
33 | + */ |
|
34 | + protected $submitOncePerSession = false; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + private $formId; |
|
40 | + /** |
|
41 | + * @var null|string |
|
42 | + */ |
|
43 | + private $getPathBackup = null; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var null|\stdClass |
|
47 | + */ |
|
48 | + private $userSessionBackup = null; |
|
49 | + |
|
50 | + /** |
|
51 | + * @param Storage $storage |
|
52 | + * @return void |
|
53 | + * @throws \Exception |
|
54 | + */ |
|
55 | + public function run(Storage $storage) |
|
56 | + { |
|
57 | + parent::run($storage); |
|
58 | + |
|
59 | + $this->checkParameters(); |
|
60 | + |
|
61 | + if ($this->documentType === null || $this->responseFolder === null) { |
|
62 | + throw new \Exception('Parameters `documentType` and `responseFolder` are required for usage with this form'); |
|
63 | + } |
|
64 | + |
|
65 | + $this->setFormId(); |
|
66 | + $this->initialize($storage); |
|
67 | + $this->checkSubmit($storage); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @param null|Application $application |
|
72 | + * @throws \Exception |
|
73 | + */ |
|
74 | + public function render($application = null) |
|
75 | + { |
|
76 | + $request = $this->request; |
|
77 | + if (isset($request::$get['path'])) { |
|
78 | + $this->getPathBackup = $request::$get['path']; |
|
79 | + } |
|
80 | + $request::$get['path'] = $this->responseFolder; |
|
81 | + $form = $this->renderTemplate($this->subTemplate); |
|
82 | + if ($this->getPathBackup !== null) { |
|
83 | + $request::$get['path'] = $this->getPathBackup; |
|
84 | + } else { |
|
85 | + unset($request::$get['path']); |
|
86 | + } |
|
87 | + if ($this->isFormSubmitted($this->request) || $this->isSubmitAllowed() === false) { |
|
88 | + $this->parameters[$this->formParameterName] = '<a name="' . $this->formId . '"></a>' . $this->thankYouMessage; |
|
89 | + } else { |
|
90 | + $this->parameters[$this->formParameterName] = $form; |
|
91 | + } |
|
92 | + |
|
93 | + parent::render($application); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Checks if parameters were given in the CMS configuration and |
|
98 | + * sets them to their respective fields |
|
99 | + */ |
|
100 | + private function checkParameters() |
|
101 | + { |
|
102 | + if (isset($this->parameters['documentType'])) { |
|
103 | + $this->documentType = $this->parameters['documentType']; |
|
104 | + unset($this->parameters['documentType']); |
|
105 | + } |
|
106 | + |
|
107 | + if (isset($this->parameters['responseFolder'])) { |
|
108 | + $this->responseFolder = $this->parameters['responseFolder']; |
|
109 | + unset($this->parameters['responseFolder']); |
|
110 | + } |
|
111 | + |
|
112 | + if (isset($this->parameters['subTemplate'])) { |
|
113 | + $this->subTemplate = $this->parameters['subTemplate']; |
|
114 | + unset($this->parameters['subTemplate']); |
|
115 | + } |
|
116 | + |
|
117 | + if (isset($this->parameters['formParameterName'])) { |
|
118 | + $this->formParameterName = $this->parameters['formParameterName']; |
|
119 | + unset($this->parameters['formParameterName']); |
|
120 | + } |
|
121 | + |
|
122 | + if (isset($this->parameters['thankYouMessage'])) { |
|
123 | + $this->thankYouMessage = $this->parameters['thankYouMessage']; |
|
124 | + unset($this->parameters['thankYouMessage']); |
|
125 | + } |
|
126 | + |
|
127 | + if (isset($this->parameters['submitOncePerSession'])) { |
|
128 | + $this->submitOncePerSession = $this->parameters['submitOncePerSession'] === 'true' ? true : false; |
|
129 | + unset($this->parameters['submitOncePerSession']); |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Sets variables needed for rendering the form template |
|
135 | + * @param $storage |
|
136 | + */ |
|
137 | + private function initialize($storage) |
|
138 | + { |
|
139 | + $this->parameters['smallestImage'] = $storage->getSmallestImageSet()->slug; |
|
140 | + $this->parameters['cmsPrefix'] = ''; |
|
141 | + |
|
142 | + $this->parameters['documentType'] = $this->storage->getDocumentTypeBySlug($this->documentType, true); |
|
143 | + $this->parameters['documentTypes'] = $this->storage->getDocumentTypes(); |
|
144 | + $this->parameters['hideTitleAndState'] = true; |
|
145 | + $this->parameters['formId'] = $this->formId; |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * If the form has been submitted, save the document |
|
150 | + * Calls $this->postSubmit() afterwards |
|
151 | + * |
|
152 | + * @param Storage $storage |
|
153 | + */ |
|
154 | + private function checkSubmit($storage) |
|
155 | + { |
|
156 | + if ($this->isFormSubmitted($this->request) && $this->isSubmitAllowed()) { |
|
157 | + $postValues = $this->getPostValues($this->request); |
|
158 | + $this->setUserSessionBackup(); |
|
159 | + $storage->addDocument($postValues); |
|
160 | + $this->restoreUserSessionBackup(); |
|
161 | + $this->setSubmitToSession(); |
|
162 | + $this->postSubmit($postValues, $storage); |
|
163 | + } |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Hook for derived classes to take actions after |
|
168 | + * submitting the form |
|
169 | + * |
|
170 | + * @param $postValues |
|
171 | + * @param $storage |
|
172 | + */ |
|
173 | + protected function postSubmit($postValues, $storage) |
|
174 | + {} |
|
175 | + |
|
176 | + /** |
|
177 | + * Sets a unique id for this particular form, so it can recognize |
|
178 | + * it when a submit occurs |
|
179 | + */ |
|
180 | + private function setFormId() |
|
181 | + { |
|
182 | + if (isset($_SESSION['FormComponent'][$this->formParameterName]['formId'])) { |
|
183 | + $this->formId = $_SESSION['FormComponent'][$this->formParameterName]['formId']; |
|
184 | + } else { |
|
185 | + $_SESSION['FormComponent'][$this->formParameterName]['formId'] = (string) microtime(true); |
|
186 | + $_SESSION['FormComponent'][$this->formParameterName]['submitted'] = false; |
|
187 | + $this->formId = $_SESSION['FormComponent'][$this->formParameterName]['formId']; |
|
188 | + } |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Checks if this form has been submitted |
|
193 | + * |
|
194 | + * @param $request |
|
195 | + * @return bool |
|
196 | + */ |
|
197 | + private function isFormSubmitted($request) |
|
198 | + { |
|
199 | + return !empty($request::$post) && isset($request::$post['formId']) && $request::$post['formId'] === $this->formId && isset($_SESSION['FormComponent'][$this->formParameterName]['formId']) && $_SESSION['FormComponent'][$this->formParameterName]['formId'] === $this->formId; |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * |
|
204 | + * |
|
205 | + * @param $request |
|
206 | + */ |
|
207 | + private function getPostValues($request) |
|
208 | + { |
|
209 | + $postValues = $request::$post; |
|
210 | + $postValues['documentType'] = $this->documentType; |
|
211 | + $postValues['path'] = $this->responseFolder; |
|
212 | + $postValues['title'] = date('r') . ' - From: ' . $request::$requestUri; |
|
213 | + return $postValues; |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Temporarily stores the current user session in a backup variable |
|
218 | + * and sets a fake user instead |
|
219 | + */ |
|
220 | + private function setUserSessionBackup() |
|
221 | + { |
|
222 | + $this->userSessionBackup = isset($_SESSION['cloudcontrol']) ? $_SESSION['cloudcontrol'] : null; |
|
223 | + $fakeUser = new \stdClass(); |
|
224 | + $fakeUser->username = 'FormComponent'; |
|
225 | + $_SESSION['cloudcontrol'] = $fakeUser; |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * Removes the fake user and restores the existing user |
|
230 | + * session if it was there |
|
231 | + */ |
|
232 | + private function restoreUserSessionBackup() |
|
233 | + { |
|
234 | + if ($this->userSessionBackup === null) { |
|
235 | + unset($_SESSION['cloudcontrol']); |
|
236 | + } else { |
|
237 | + $_SESSION['cloudcontrol'] = $this->userSessionBackup; |
|
238 | + } |
|
239 | + } |
|
240 | + |
|
241 | + private function setSubmitToSession() |
|
242 | + { |
|
243 | + $_SESSION['FormComponent'][$this->formParameterName]['submitted'] = true; |
|
244 | + } |
|
245 | + |
|
246 | + private function isSubmitAllowed() |
|
247 | + { |
|
248 | + if ($this->submitOncePerSession === true && $_SESSION['FormComponent'][$this->formParameterName]['submitted'] === true) { |
|
249 | + return false; |
|
250 | + } else { |
|
251 | + return true; |
|
252 | + } |
|
253 | + } |
|
254 | 254 | } |
255 | 255 | \ No newline at end of file |
@@ -31,11 +31,11 @@ discard block |
||
31 | 31 | */ |
32 | 32 | function shutdownHandler () { |
33 | 33 | $error = error_get_last(); |
34 | - if (isset($error['type'], $error['message'], $error['file'], $error['line'])) { |
|
35 | - errorHandler($error['type'],$error['message'],$error['file'],$error['line']); |
|
36 | - }elseif ($error['type'] == 1) { |
|
37 | - dump($error); |
|
38 | - } |
|
34 | + if (isset($error['type'], $error['message'], $error['file'], $error['line'])) { |
|
35 | + errorHandler($error['type'],$error['message'],$error['file'],$error['line']); |
|
36 | + }elseif ($error['type'] == 1) { |
|
37 | + dump($error); |
|
38 | + } |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -49,28 +49,28 @@ discard block |
||
49 | 49 | $jsonErrorNr = json_last_error(); |
50 | 50 | $errstr = ''; |
51 | 51 | switch ($jsonErrorNr) { |
52 | - case JSON_ERROR_NONE: |
|
53 | - $errstr .= ' - No errors' . PHP_EOL; |
|
54 | - break; |
|
55 | - case JSON_ERROR_DEPTH: |
|
56 | - $errstr .= ' - Maximum stack depth exceeded' . PHP_EOL; |
|
57 | - break; |
|
58 | - case JSON_ERROR_STATE_MISMATCH: |
|
59 | - $errstr .= ' - Underflow or the modes mismatch' . PHP_EOL; |
|
60 | - break; |
|
61 | - case JSON_ERROR_CTRL_CHAR: |
|
62 | - $errstr .= ' - Unexpected control character found' . PHP_EOL; |
|
63 | - break; |
|
64 | - case JSON_ERROR_SYNTAX: |
|
65 | - $errstr .= ' - Syntax error, malformed JSON' . PHP_EOL; |
|
66 | - break; |
|
67 | - case JSON_ERROR_UTF8: |
|
68 | - $errstr .= ' - Malformed UTF-8 characters, possibly incorrectly encoded' . PHP_EOL; |
|
69 | - break; |
|
70 | - default: |
|
71 | - $errstr = ' - Unknown error' . PHP_EOL; |
|
72 | - break; |
|
73 | - } |
|
52 | + case JSON_ERROR_NONE: |
|
53 | + $errstr .= ' - No errors' . PHP_EOL; |
|
54 | + break; |
|
55 | + case JSON_ERROR_DEPTH: |
|
56 | + $errstr .= ' - Maximum stack depth exceeded' . PHP_EOL; |
|
57 | + break; |
|
58 | + case JSON_ERROR_STATE_MISMATCH: |
|
59 | + $errstr .= ' - Underflow or the modes mismatch' . PHP_EOL; |
|
60 | + break; |
|
61 | + case JSON_ERROR_CTRL_CHAR: |
|
62 | + $errstr .= ' - Unexpected control character found' . PHP_EOL; |
|
63 | + break; |
|
64 | + case JSON_ERROR_SYNTAX: |
|
65 | + $errstr .= ' - Syntax error, malformed JSON' . PHP_EOL; |
|
66 | + break; |
|
67 | + case JSON_ERROR_UTF8: |
|
68 | + $errstr .= ' - Malformed UTF-8 characters, possibly incorrectly encoded' . PHP_EOL; |
|
69 | + break; |
|
70 | + default: |
|
71 | + $errstr = ' - Unknown error' . PHP_EOL; |
|
72 | + break; |
|
73 | + } |
|
74 | 74 | errorHandler ($jsonErrorNr, $errstr, $file, $line); |
75 | 75 | } |
76 | 76 | |
@@ -85,102 +85,102 @@ discard block |
||
85 | 85 | * @param string $httpHeader |
86 | 86 | */ |
87 | 87 | function renderError ($message='', $file='', $line='', $code=0, $trace=array(), $httpHeader = 'HTTP/1.0 500 Internal Server Error') { |
88 | - if (ob_get_contents()) ob_end_clean(); |
|
88 | + if (ob_get_contents()) ob_end_clean(); |
|
89 | 89 | |
90 | - if (canShowError()) { |
|
91 | - $file_lines = file_exists($file) ? file($file) : array(); |
|
92 | - $range = ($line - 15) < 0 ? range(1, 30) : range($line - 15, $line + 15); |
|
93 | - $lines = array(); |
|
90 | + if (canShowError()) { |
|
91 | + $file_lines = file_exists($file) ? file($file) : array(); |
|
92 | + $range = ($line - 15) < 0 ? range(1, 30) : range($line - 15, $line + 15); |
|
93 | + $lines = array(); |
|
94 | 94 | |
95 | - foreach ($range as $line_number) { |
|
96 | - if(isset($file_lines[$line_number-1])) { |
|
97 | - $lines[$line_number] = $file_lines[$line_number-1]; |
|
98 | - } |
|
99 | - } |
|
95 | + foreach ($range as $line_number) { |
|
96 | + if(isset($file_lines[$line_number-1])) { |
|
97 | + $lines[$line_number] = $file_lines[$line_number-1]; |
|
98 | + } |
|
99 | + } |
|
100 | 100 | |
101 | - $error = array( |
|
102 | - 'message' => $message, |
|
103 | - 'file' => $file, |
|
104 | - 'line' => $line, |
|
105 | - 'code' => $code, |
|
106 | - 'lines' => $lines, |
|
107 | - 'trace' => $trace, |
|
108 | - 'httpHeader' => $httpHeader, |
|
109 | - ); |
|
101 | + $error = array( |
|
102 | + 'message' => $message, |
|
103 | + 'file' => $file, |
|
104 | + 'line' => $line, |
|
105 | + 'code' => $code, |
|
106 | + 'lines' => $lines, |
|
107 | + 'trace' => $trace, |
|
108 | + 'httpHeader' => $httpHeader, |
|
109 | + ); |
|
110 | 110 | |
111 | - if (PHP_SAPI === 'cli') { |
|
112 | - renderCliException($message, $file, $line, $code, $trace, $lines); |
|
113 | - } |
|
111 | + if (PHP_SAPI === 'cli') { |
|
112 | + renderCliException($message, $file, $line, $code, $trace, $lines); |
|
113 | + } |
|
114 | 114 | |
115 | - if (file_exists(realpath(__DIR__) . '/errorviewdetailed.php')) { |
|
116 | - include(realpath(__DIR__) . '/errorviewdetailed.php'); |
|
117 | - } else { |
|
118 | - header('Content-type: application/json'); |
|
119 | - die(json_encode($error)); |
|
120 | - } |
|
121 | - exit; |
|
122 | - } else { |
|
123 | - header($_SERVER['SERVER_PROTOCOL'] . $httpHeader, true); |
|
124 | - header('X-Error-Message: ' . $message); |
|
125 | - header('X-Error-File: ' . $file); |
|
126 | - header('X-Error-Line: ' . $line); |
|
127 | - if (file_exists(realpath(__DIR__) . '/errorviewcompact.php')) { |
|
128 | - include(realpath(__DIR__) . '/errorviewcompact.php'); |
|
129 | - } else { |
|
130 | - header('Content-type: application/json'); |
|
131 | - die(json_encode('An error occured.')); |
|
132 | - } |
|
133 | - } |
|
115 | + if (file_exists(realpath(__DIR__) . '/errorviewdetailed.php')) { |
|
116 | + include(realpath(__DIR__) . '/errorviewdetailed.php'); |
|
117 | + } else { |
|
118 | + header('Content-type: application/json'); |
|
119 | + die(json_encode($error)); |
|
120 | + } |
|
121 | + exit; |
|
122 | + } else { |
|
123 | + header($_SERVER['SERVER_PROTOCOL'] . $httpHeader, true); |
|
124 | + header('X-Error-Message: ' . $message); |
|
125 | + header('X-Error-File: ' . $file); |
|
126 | + header('X-Error-Line: ' . $line); |
|
127 | + if (file_exists(realpath(__DIR__) . '/errorviewcompact.php')) { |
|
128 | + include(realpath(__DIR__) . '/errorviewcompact.php'); |
|
129 | + } else { |
|
130 | + header('Content-type: application/json'); |
|
131 | + die(json_encode('An error occured.')); |
|
132 | + } |
|
133 | + } |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | function canShowError() |
137 | 137 | { |
138 | - if (PHP_SAPI === 'cli') { |
|
139 | - return true; |
|
140 | - } |
|
141 | - if (file_exists('../config.json') && !isset($_SESSION['cloudcontrol'])) { |
|
142 | - $config = file_get_contents('../config.json'); |
|
143 | - $config = json_decode($config); |
|
144 | - if (isset($config->showErrorsToAll)) { |
|
145 | - return $config->showErrorsToAll; |
|
146 | - } |
|
147 | - } else { |
|
148 | - return true; |
|
149 | - } |
|
138 | + if (PHP_SAPI === 'cli') { |
|
139 | + return true; |
|
140 | + } |
|
141 | + if (file_exists('../config.json') && !isset($_SESSION['cloudcontrol'])) { |
|
142 | + $config = file_get_contents('../config.json'); |
|
143 | + $config = json_decode($config); |
|
144 | + if (isset($config->showErrorsToAll)) { |
|
145 | + return $config->showErrorsToAll; |
|
146 | + } |
|
147 | + } else { |
|
148 | + return true; |
|
149 | + } |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | function renderCliException($message, $file, $line, $code, $trace, $lines) |
153 | 153 | { |
154 | - echo PHP_EOL; |
|
155 | - echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
156 | - echo '| THE FOLLOWING ERROR OCCURED |' . PHP_EOL; |
|
157 | - echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
158 | - echo PHP_EOL; |
|
159 | - echo ' ' . $message . PHP_EOL; |
|
160 | - echo PHP_EOL; |
|
161 | - echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
162 | - echo '| IN FILE |' . PHP_EOL; |
|
163 | - echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
164 | - echo PHP_EOL; |
|
165 | - echo ' ' . $file . ':' . $line . PHP_EOL; |
|
166 | - echo PHP_EOL; |
|
167 | - echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
168 | - echo '| CONTENTS OF THE FILE |' . PHP_EOL; |
|
169 | - echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
170 | - echo PHP_EOL; |
|
171 | - foreach($lines as $nr => $currentLine) { |
|
172 | - echo ($nr == $line ? '* ' : ' ' ) . str_pad($nr, 3, "0", STR_PAD_LEFT) . ' ' . $currentLine; |
|
173 | - } |
|
174 | - echo PHP_EOL; |
|
175 | - echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
176 | - echo '| STACK TRACE |' . PHP_EOL; |
|
177 | - echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
178 | - foreach($trace as $row) { |
|
179 | - echo (isset($row['file']) ? basename($row['file']) : '') . ':' |
|
180 | - . (isset($row['line']) ? $row['line'] : '') . "\t\t\t" |
|
181 | - . (isset($row['class']) ? $row['class'] : ' ') . "\t\t\t" |
|
182 | - . (isset($row['type']) ? $row['type'] : ' ') . "\t\t\t" |
|
183 | - . (isset($row['function']) ? $row['function'] : ' ') . PHP_EOL; |
|
184 | - } |
|
185 | - exit; |
|
154 | + echo PHP_EOL; |
|
155 | + echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
156 | + echo '| THE FOLLOWING ERROR OCCURED |' . PHP_EOL; |
|
157 | + echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
158 | + echo PHP_EOL; |
|
159 | + echo ' ' . $message . PHP_EOL; |
|
160 | + echo PHP_EOL; |
|
161 | + echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
162 | + echo '| IN FILE |' . PHP_EOL; |
|
163 | + echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
164 | + echo PHP_EOL; |
|
165 | + echo ' ' . $file . ':' . $line . PHP_EOL; |
|
166 | + echo PHP_EOL; |
|
167 | + echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
168 | + echo '| CONTENTS OF THE FILE |' . PHP_EOL; |
|
169 | + echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
170 | + echo PHP_EOL; |
|
171 | + foreach($lines as $nr => $currentLine) { |
|
172 | + echo ($nr == $line ? '* ' : ' ' ) . str_pad($nr, 3, "0", STR_PAD_LEFT) . ' ' . $currentLine; |
|
173 | + } |
|
174 | + echo PHP_EOL; |
|
175 | + echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
176 | + echo '| STACK TRACE |' . PHP_EOL; |
|
177 | + echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
178 | + foreach($trace as $row) { |
|
179 | + echo (isset($row['file']) ? basename($row['file']) : '') . ':' |
|
180 | + . (isset($row['line']) ? $row['line'] : '') . "\t\t\t" |
|
181 | + . (isset($row['class']) ? $row['class'] : ' ') . "\t\t\t" |
|
182 | + . (isset($row['type']) ? $row['type'] : ' ') . "\t\t\t" |
|
183 | + . (isset($row['function']) ? $row['function'] : ' ') . PHP_EOL; |
|
184 | + } |
|
185 | + exit; |
|
186 | 186 | } |
187 | 187 | \ No newline at end of file |
@@ -7,124 +7,124 @@ |
||
7 | 7 | |
8 | 8 | class LanguageComponent implements Component |
9 | 9 | { |
10 | - protected $request; |
|
11 | - protected $parameters; |
|
12 | - |
|
13 | - protected $defaultLanguage = 'en'; |
|
14 | - protected $acceptedLanguages = null; |
|
15 | - protected $languageParameterName = 'language'; |
|
16 | - protected $forceRedirect = false; |
|
17 | - protected $sessionValues; |
|
18 | - |
|
19 | - /** |
|
20 | - * Component constructor. |
|
21 | - * |
|
22 | - * @param $template |
|
23 | - * @param Request $request |
|
24 | - * @param $parameters |
|
25 | - * @param $matchedSitemapItem |
|
26 | - */ |
|
27 | - public function __construct($template, Request $request, $parameters, $matchedSitemapItem) |
|
28 | - { |
|
29 | - $this->parameters = (array) $parameters; |
|
30 | - $this->checkParameters(); |
|
31 | - |
|
32 | - $lang = substr(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : $this->defaultLanguage, 0, 2); |
|
33 | - $_SESSION['LanguageComponent']['detectedLanguage'] = $lang; |
|
34 | - |
|
35 | - $this->checkLanguageSwitch($request); |
|
36 | - |
|
37 | - if (!isset($_SESSION['LanguageComponent'][$this->languageParameterName])) { |
|
38 | - $this->detectLanguage($lang, $request); |
|
39 | - } else { |
|
40 | - if ($this->forceRedirect === true) { |
|
41 | - $this->detectLanguage($_SESSION['LanguageComponent'][$this->languageParameterName], $request); |
|
42 | - } |
|
43 | - } |
|
44 | - |
|
45 | - $this->parameters[$this->languageParameterName] = $_SESSION['LanguageComponent'][$this->languageParameterName]; |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Checks to see if any parameters are given from the configuration in the CMS |
|
50 | - */ |
|
51 | - private function checkParameters() |
|
52 | - { |
|
53 | - if (isset($this->parameters['defaultLanguage'])) { |
|
54 | - $this->defaultLanguage = $this->parameters['defaultLanguage']; |
|
55 | - unset($this->parameters['defaultLanguage']); |
|
56 | - } |
|
57 | - if (isset($this->parameters['acceptedLanguages'])) { |
|
58 | - $this->acceptedLanguages = explode(',', $this->parameters['acceptedLanguages']); |
|
59 | - unset($this->parameters['acceptedLanguages']); |
|
60 | - } |
|
61 | - if (isset($this->parameters['languageParameterName'])) { |
|
62 | - $this->languageParameterName = $this->parameters['languageParameterName']; |
|
63 | - unset($this->parameters['languageParameterName']); |
|
64 | - } |
|
65 | - if (isset($this->parameters['forceRedirect'])) { |
|
66 | - $this->forceRedirect = (bool) $this->parameters['forceRedirect']; |
|
67 | - unset($this->parameters['forceRedirect']); |
|
68 | - } |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @return array |
|
73 | - */ |
|
74 | - public function getParameters() |
|
75 | - { |
|
76 | - return $this->parameters; |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * Check if the found language is allowed and |
|
82 | - * if an action is to be taken. |
|
83 | - * |
|
84 | - * @param $lang |
|
85 | - * @param $request |
|
86 | - */ |
|
87 | - private function detectLanguage($lang, $request) |
|
88 | - { |
|
89 | - $_SESSION['LanguageComponent'][$this->languageParameterName] = $this->defaultLanguage; |
|
90 | - |
|
91 | - if ($this->acceptedLanguages === null) { |
|
92 | - $_SESSION['LanguageComponent'][$this->languageParameterName] = $lang; |
|
93 | - } else if (in_array($lang, $this->acceptedLanguages)) { |
|
94 | - $_SESSION['LanguageComponent'][$this->languageParameterName] = $lang; |
|
95 | - } else { |
|
96 | - $lang = $this->defaultLanguage; |
|
97 | - } |
|
98 | - |
|
99 | - $this->sessionValues = $_SESSION['LanguageComponent']; |
|
100 | - |
|
101 | - if ($this->forceRedirect === true) { |
|
102 | - if (substr($request::$relativeUri, 0, 2) !== $lang ) { |
|
103 | - if ($lang !== $this->defaultLanguage) { |
|
104 | - header('Location: ' . $request::$subfolders . $lang . '/' . $request::$relativeUri); |
|
105 | - exit; |
|
106 | - } |
|
107 | - } |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Detect if the language is switched manually |
|
113 | - * |
|
114 | - * @param $request |
|
115 | - */ |
|
116 | - private function checkLanguageSwitch($request) |
|
117 | - { |
|
118 | - if (isset($request::$get['langSwitch'])) { |
|
119 | - $this->forceRedirect = true; |
|
120 | - $this->detectLanguage($request::$get['langSwitch'], $request); |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - /* |
|
10 | + protected $request; |
|
11 | + protected $parameters; |
|
12 | + |
|
13 | + protected $defaultLanguage = 'en'; |
|
14 | + protected $acceptedLanguages = null; |
|
15 | + protected $languageParameterName = 'language'; |
|
16 | + protected $forceRedirect = false; |
|
17 | + protected $sessionValues; |
|
18 | + |
|
19 | + /** |
|
20 | + * Component constructor. |
|
21 | + * |
|
22 | + * @param $template |
|
23 | + * @param Request $request |
|
24 | + * @param $parameters |
|
25 | + * @param $matchedSitemapItem |
|
26 | + */ |
|
27 | + public function __construct($template, Request $request, $parameters, $matchedSitemapItem) |
|
28 | + { |
|
29 | + $this->parameters = (array) $parameters; |
|
30 | + $this->checkParameters(); |
|
31 | + |
|
32 | + $lang = substr(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : $this->defaultLanguage, 0, 2); |
|
33 | + $_SESSION['LanguageComponent']['detectedLanguage'] = $lang; |
|
34 | + |
|
35 | + $this->checkLanguageSwitch($request); |
|
36 | + |
|
37 | + if (!isset($_SESSION['LanguageComponent'][$this->languageParameterName])) { |
|
38 | + $this->detectLanguage($lang, $request); |
|
39 | + } else { |
|
40 | + if ($this->forceRedirect === true) { |
|
41 | + $this->detectLanguage($_SESSION['LanguageComponent'][$this->languageParameterName], $request); |
|
42 | + } |
|
43 | + } |
|
44 | + |
|
45 | + $this->parameters[$this->languageParameterName] = $_SESSION['LanguageComponent'][$this->languageParameterName]; |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Checks to see if any parameters are given from the configuration in the CMS |
|
50 | + */ |
|
51 | + private function checkParameters() |
|
52 | + { |
|
53 | + if (isset($this->parameters['defaultLanguage'])) { |
|
54 | + $this->defaultLanguage = $this->parameters['defaultLanguage']; |
|
55 | + unset($this->parameters['defaultLanguage']); |
|
56 | + } |
|
57 | + if (isset($this->parameters['acceptedLanguages'])) { |
|
58 | + $this->acceptedLanguages = explode(',', $this->parameters['acceptedLanguages']); |
|
59 | + unset($this->parameters['acceptedLanguages']); |
|
60 | + } |
|
61 | + if (isset($this->parameters['languageParameterName'])) { |
|
62 | + $this->languageParameterName = $this->parameters['languageParameterName']; |
|
63 | + unset($this->parameters['languageParameterName']); |
|
64 | + } |
|
65 | + if (isset($this->parameters['forceRedirect'])) { |
|
66 | + $this->forceRedirect = (bool) $this->parameters['forceRedirect']; |
|
67 | + unset($this->parameters['forceRedirect']); |
|
68 | + } |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @return array |
|
73 | + */ |
|
74 | + public function getParameters() |
|
75 | + { |
|
76 | + return $this->parameters; |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * Check if the found language is allowed and |
|
82 | + * if an action is to be taken. |
|
83 | + * |
|
84 | + * @param $lang |
|
85 | + * @param $request |
|
86 | + */ |
|
87 | + private function detectLanguage($lang, $request) |
|
88 | + { |
|
89 | + $_SESSION['LanguageComponent'][$this->languageParameterName] = $this->defaultLanguage; |
|
90 | + |
|
91 | + if ($this->acceptedLanguages === null) { |
|
92 | + $_SESSION['LanguageComponent'][$this->languageParameterName] = $lang; |
|
93 | + } else if (in_array($lang, $this->acceptedLanguages)) { |
|
94 | + $_SESSION['LanguageComponent'][$this->languageParameterName] = $lang; |
|
95 | + } else { |
|
96 | + $lang = $this->defaultLanguage; |
|
97 | + } |
|
98 | + |
|
99 | + $this->sessionValues = $_SESSION['LanguageComponent']; |
|
100 | + |
|
101 | + if ($this->forceRedirect === true) { |
|
102 | + if (substr($request::$relativeUri, 0, 2) !== $lang ) { |
|
103 | + if ($lang !== $this->defaultLanguage) { |
|
104 | + header('Location: ' . $request::$subfolders . $lang . '/' . $request::$relativeUri); |
|
105 | + exit; |
|
106 | + } |
|
107 | + } |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Detect if the language is switched manually |
|
113 | + * |
|
114 | + * @param $request |
|
115 | + */ |
|
116 | + private function checkLanguageSwitch($request) |
|
117 | + { |
|
118 | + if (isset($request::$get['langSwitch'])) { |
|
119 | + $this->forceRedirect = true; |
|
120 | + $this->detectLanguage($request::$get['langSwitch'], $request); |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + /* |
|
125 | 125 | * These functions are required by the interface, but not for the functionality |
126 | 126 | */ |
127 | - public function run(Storage $storage) {} |
|
128 | - public function render() {} |
|
129 | - public function get() {} |
|
127 | + public function run(Storage $storage) {} |
|
128 | + public function render() {} |
|
129 | + public function get() {} |
|
130 | 130 | } |
131 | 131 | \ No newline at end of file |
@@ -12,124 +12,124 @@ |
||
12 | 12 | |
13 | 13 | class DocumentRouting |
14 | 14 | { |
15 | - /** |
|
16 | - * DocumentRouting constructor. |
|
17 | - * @param $request |
|
18 | - * @param $relativeCmsUri |
|
19 | - * @param CmsComponent $cmsComponent |
|
20 | - */ |
|
21 | - public function __construct($request, $relativeCmsUri, $cmsComponent) |
|
22 | - { |
|
23 | - if ($relativeCmsUri == '/documents') { |
|
24 | - $cmsComponent->subTemplate = 'cms/documents'; |
|
25 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENTS, $cmsComponent->storage->getDocuments()); |
|
26 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_DOCUMENTS); |
|
27 | - } |
|
28 | - $this->documentRouting($request, $relativeCmsUri, $cmsComponent); |
|
29 | - $this->folderRouting($request, $relativeCmsUri, $cmsComponent); |
|
30 | - } |
|
15 | + /** |
|
16 | + * DocumentRouting constructor. |
|
17 | + * @param $request |
|
18 | + * @param $relativeCmsUri |
|
19 | + * @param CmsComponent $cmsComponent |
|
20 | + */ |
|
21 | + public function __construct($request, $relativeCmsUri, $cmsComponent) |
|
22 | + { |
|
23 | + if ($relativeCmsUri == '/documents') { |
|
24 | + $cmsComponent->subTemplate = 'cms/documents'; |
|
25 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENTS, $cmsComponent->storage->getDocuments()); |
|
26 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_DOCUMENTS); |
|
27 | + } |
|
28 | + $this->documentRouting($request, $relativeCmsUri, $cmsComponent); |
|
29 | + $this->folderRouting($request, $relativeCmsUri, $cmsComponent); |
|
30 | + } |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * @param $request |
|
35 | - * @param $relativeCmsUri |
|
36 | - * @param CmsComponent $cmsComponent |
|
37 | - * @throws \Exception |
|
38 | - */ |
|
39 | - private function documentRouting($request, $relativeCmsUri, $cmsComponent) |
|
40 | - { |
|
41 | - if ($relativeCmsUri == '/documents/new-document' && isset($request::$get[CmsComponent::GET_PARAMETER_PATH])) { |
|
42 | - $cmsComponent->subTemplate = 'cms/documents/document-form'; |
|
43 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_DOCUMENTS); |
|
44 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_SMALLEST_IMAGE, $cmsComponent->storage->getSmallestImageSet()->slug); |
|
45 | - if (isset($request::$get[CmsComponent::PARAMETER_DOCUMENT_TYPE])) { |
|
46 | - if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE], $request::$get[CmsComponent::PARAMETER_DOCUMENT_TYPE], $request::$get[CmsComponent::GET_PARAMETER_PATH])) { |
|
47 | - $cmsComponent->storage->addDocument($request::$post); |
|
48 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/documents'); |
|
49 | - exit; |
|
50 | - } |
|
51 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENT_TYPE, $cmsComponent->storage->getDocumentTypeBySlug($request::$get[CmsComponent::PARAMETER_DOCUMENT_TYPE], true)); |
|
52 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_BRICKS, $cmsComponent->storage->getBricks()); |
|
53 | - } else { |
|
54 | - $documentTypes = $cmsComponent->storage->getDocumentTypes(); |
|
55 | - if (count($documentTypes) < 1) { |
|
56 | - throw new \Exception('No Document Types defined yet. <a href="' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/document-types/new">Please do so first.</a>'); |
|
57 | - } |
|
58 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENT_TYPES, $documentTypes); |
|
59 | - } |
|
60 | - } elseif ($relativeCmsUri == '/documents/edit-document' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
61 | - $cmsComponent->subTemplate = 'cms/documents/document-form'; |
|
62 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_DOCUMENTS); |
|
63 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_SMALLEST_IMAGE, $cmsComponent->storage->getSmallestImageSet()->slug); |
|
64 | - if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE], $request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
65 | - $cmsComponent->storage->saveDocument($request::$post); |
|
66 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/documents'); |
|
67 | - exit; |
|
68 | - } |
|
69 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENT, $cmsComponent->storage->getDocumentBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG])); |
|
70 | - $request::$get[CmsComponent::GET_PARAMETER_PATH] = $request::$get[CmsComponent::GET_PARAMETER_SLUG]; |
|
71 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENT_TYPE, $cmsComponent->storage->getDocumentTypeBySlug($cmsComponent->getParameter(CmsComponent::PARAMETER_DOCUMENT)->documentTypeSlug, true)); |
|
72 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_BRICKS, $cmsComponent->storage->getBricks()); |
|
73 | - } elseif ($relativeCmsUri == '/documents/get-brick' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
74 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_SMALLEST_IMAGE, $cmsComponent->storage->getSmallestImageSet()->slug); |
|
75 | - $cmsComponent->subTemplate = 'cms/documents/brick'; |
|
76 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_BRICK, $cmsComponent->storage->getBrickBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG])); |
|
77 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_STATIC, $request::$get[CmsComponent::PARAMETER_STATIC] === 'true'); |
|
78 | - if (isset($request::$get[CmsComponent::PARAMETER_MY_BRICK_SLUG])) { |
|
79 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_MY_BRICK_SLUG, $request::$get[CmsComponent::PARAMETER_MY_BRICK_SLUG]); |
|
80 | - } |
|
81 | - $result = new \stdClass(); |
|
82 | - $result->body = $cmsComponent->renderTemplate('cms/documents/brick'); |
|
83 | - $result->rteList = isset($GLOBALS['rteList']) ? $GLOBALS['rteList'] : array(); |
|
84 | - ob_clean(); |
|
85 | - header(CmsComponent::CONTENT_TYPE_APPLICATION_JSON); |
|
86 | - die(json_encode($result)); |
|
87 | - } else if ($relativeCmsUri == '/documents/delete-document' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
88 | - $cmsComponent->storage->deleteDocumentBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
|
89 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/documents'); |
|
90 | - exit; |
|
91 | - } |
|
92 | - } |
|
33 | + /** |
|
34 | + * @param $request |
|
35 | + * @param $relativeCmsUri |
|
36 | + * @param CmsComponent $cmsComponent |
|
37 | + * @throws \Exception |
|
38 | + */ |
|
39 | + private function documentRouting($request, $relativeCmsUri, $cmsComponent) |
|
40 | + { |
|
41 | + if ($relativeCmsUri == '/documents/new-document' && isset($request::$get[CmsComponent::GET_PARAMETER_PATH])) { |
|
42 | + $cmsComponent->subTemplate = 'cms/documents/document-form'; |
|
43 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_DOCUMENTS); |
|
44 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_SMALLEST_IMAGE, $cmsComponent->storage->getSmallestImageSet()->slug); |
|
45 | + if (isset($request::$get[CmsComponent::PARAMETER_DOCUMENT_TYPE])) { |
|
46 | + if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE], $request::$get[CmsComponent::PARAMETER_DOCUMENT_TYPE], $request::$get[CmsComponent::GET_PARAMETER_PATH])) { |
|
47 | + $cmsComponent->storage->addDocument($request::$post); |
|
48 | + header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/documents'); |
|
49 | + exit; |
|
50 | + } |
|
51 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENT_TYPE, $cmsComponent->storage->getDocumentTypeBySlug($request::$get[CmsComponent::PARAMETER_DOCUMENT_TYPE], true)); |
|
52 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_BRICKS, $cmsComponent->storage->getBricks()); |
|
53 | + } else { |
|
54 | + $documentTypes = $cmsComponent->storage->getDocumentTypes(); |
|
55 | + if (count($documentTypes) < 1) { |
|
56 | + throw new \Exception('No Document Types defined yet. <a href="' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/document-types/new">Please do so first.</a>'); |
|
57 | + } |
|
58 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENT_TYPES, $documentTypes); |
|
59 | + } |
|
60 | + } elseif ($relativeCmsUri == '/documents/edit-document' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
61 | + $cmsComponent->subTemplate = 'cms/documents/document-form'; |
|
62 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_DOCUMENTS); |
|
63 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_SMALLEST_IMAGE, $cmsComponent->storage->getSmallestImageSet()->slug); |
|
64 | + if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE], $request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
65 | + $cmsComponent->storage->saveDocument($request::$post); |
|
66 | + header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/documents'); |
|
67 | + exit; |
|
68 | + } |
|
69 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENT, $cmsComponent->storage->getDocumentBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG])); |
|
70 | + $request::$get[CmsComponent::GET_PARAMETER_PATH] = $request::$get[CmsComponent::GET_PARAMETER_SLUG]; |
|
71 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENT_TYPE, $cmsComponent->storage->getDocumentTypeBySlug($cmsComponent->getParameter(CmsComponent::PARAMETER_DOCUMENT)->documentTypeSlug, true)); |
|
72 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_BRICKS, $cmsComponent->storage->getBricks()); |
|
73 | + } elseif ($relativeCmsUri == '/documents/get-brick' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
74 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_SMALLEST_IMAGE, $cmsComponent->storage->getSmallestImageSet()->slug); |
|
75 | + $cmsComponent->subTemplate = 'cms/documents/brick'; |
|
76 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_BRICK, $cmsComponent->storage->getBrickBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG])); |
|
77 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_STATIC, $request::$get[CmsComponent::PARAMETER_STATIC] === 'true'); |
|
78 | + if (isset($request::$get[CmsComponent::PARAMETER_MY_BRICK_SLUG])) { |
|
79 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_MY_BRICK_SLUG, $request::$get[CmsComponent::PARAMETER_MY_BRICK_SLUG]); |
|
80 | + } |
|
81 | + $result = new \stdClass(); |
|
82 | + $result->body = $cmsComponent->renderTemplate('cms/documents/brick'); |
|
83 | + $result->rteList = isset($GLOBALS['rteList']) ? $GLOBALS['rteList'] : array(); |
|
84 | + ob_clean(); |
|
85 | + header(CmsComponent::CONTENT_TYPE_APPLICATION_JSON); |
|
86 | + die(json_encode($result)); |
|
87 | + } else if ($relativeCmsUri == '/documents/delete-document' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
88 | + $cmsComponent->storage->deleteDocumentBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
|
89 | + header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/documents'); |
|
90 | + exit; |
|
91 | + } |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @param $request |
|
96 | - * @param $relativeCmsUri |
|
97 | - * @param CmsComponent $cmsComponent |
|
98 | - */ |
|
99 | - private function folderRouting($request, $relativeCmsUri, $cmsComponent) |
|
100 | - { |
|
101 | - if ($relativeCmsUri == '/documents/new-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_PATH])) { |
|
102 | - $cmsComponent->subTemplate = 'cms/documents/folder-form'; |
|
103 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_DOCUMENTS); |
|
104 | - if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE], $request::$post[CmsComponent::GET_PARAMETER_PATH])) { |
|
105 | - $cmsComponent->storage->addDocumentFolder($request::$post); |
|
106 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/documents'); |
|
107 | - exit; |
|
108 | - } |
|
109 | - } else if ($relativeCmsUri == '/documents/edit-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
94 | + /** |
|
95 | + * @param $request |
|
96 | + * @param $relativeCmsUri |
|
97 | + * @param CmsComponent $cmsComponent |
|
98 | + */ |
|
99 | + private function folderRouting($request, $relativeCmsUri, $cmsComponent) |
|
100 | + { |
|
101 | + if ($relativeCmsUri == '/documents/new-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_PATH])) { |
|
102 | + $cmsComponent->subTemplate = 'cms/documents/folder-form'; |
|
103 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_DOCUMENTS); |
|
104 | + if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE], $request::$post[CmsComponent::GET_PARAMETER_PATH])) { |
|
105 | + $cmsComponent->storage->addDocumentFolder($request::$post); |
|
106 | + header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/documents'); |
|
107 | + exit; |
|
108 | + } |
|
109 | + } else if ($relativeCmsUri == '/documents/edit-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
110 | 110 | |
111 | - $cmsComponent->subTemplate = 'cms/documents/folder-form'; |
|
112 | - $folder = $cmsComponent->storage->getDocumentFolderBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
|
111 | + $cmsComponent->subTemplate = 'cms/documents/folder-form'; |
|
112 | + $folder = $cmsComponent->storage->getDocumentFolderBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
|
113 | 113 | |
114 | - $path = $request::$get[CmsComponent::GET_PARAMETER_SLUG]; |
|
115 | - $path = explode('/', $path); |
|
116 | - array_pop($path); |
|
117 | - $path = implode('/', $path); |
|
114 | + $path = $request::$get[CmsComponent::GET_PARAMETER_SLUG]; |
|
115 | + $path = explode('/', $path); |
|
116 | + array_pop($path); |
|
117 | + $path = implode('/', $path); |
|
118 | 118 | |
119 | - $request::$get[CmsComponent::GET_PARAMETER_PATH] = '/' . $path; |
|
119 | + $request::$get[CmsComponent::GET_PARAMETER_PATH] = '/' . $path; |
|
120 | 120 | |
121 | - if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE], $request::$post['content'])) { |
|
122 | - $cmsComponent->storage->saveDocumentFolder($request::$post); |
|
123 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/documents'); |
|
124 | - exit; |
|
125 | - } |
|
121 | + if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE], $request::$post['content'])) { |
|
122 | + $cmsComponent->storage->saveDocumentFolder($request::$post); |
|
123 | + header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/documents'); |
|
124 | + exit; |
|
125 | + } |
|
126 | 126 | |
127 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_DOCUMENTS); |
|
128 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_FOLDER, $folder); |
|
129 | - } else if ($relativeCmsUri == '/documents/delete-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
130 | - $cmsComponent->storage->deleteDocumentFolderBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
|
131 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/documents'); |
|
132 | - exit; |
|
133 | - } |
|
134 | - } |
|
127 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_DOCUMENTS); |
|
128 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_FOLDER, $folder); |
|
129 | + } else if ($relativeCmsUri == '/documents/delete-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
130 | + $cmsComponent->storage->deleteDocumentFolderBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
|
131 | + header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/documents'); |
|
132 | + exit; |
|
133 | + } |
|
134 | + } |
|
135 | 135 | } |
136 | 136 | \ No newline at end of file |
@@ -1,589 +1,589 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace library\components { |
3 | 3 | |
4 | - use library\components\cms\DocumentRouting; |
|
5 | - use library\crypt\Crypt; |
|
6 | - use library\storage\Storage; |
|
4 | + use library\components\cms\DocumentRouting; |
|
5 | + use library\crypt\Crypt; |
|
6 | + use library\storage\Storage; |
|
7 | 7 | |
8 | - class CmsComponent extends BaseComponent |
|
9 | - { |
|
10 | - /* |
|
8 | + class CmsComponent extends BaseComponent |
|
9 | + { |
|
10 | + /* |
|
11 | 11 | * var \library\storage\Storage |
12 | 12 | */ |
13 | - public $storage; |
|
14 | - |
|
15 | - const INVALID_CREDENTIALS_MESSAGE = 'Invalid username / password combination'; |
|
16 | - |
|
17 | - const MAIN_NAV_CLASS = 'default'; |
|
18 | - |
|
19 | - const PARAMETER_BLACKLIST_IPS = 'blacklistIps'; |
|
20 | - const PARAMETER_BODY = 'body'; |
|
21 | - const PARAMETER_BRICK = 'brick'; |
|
22 | - const PARAMETER_BRICKS = 'bricks'; |
|
23 | - const PARAMETER_CMS_PREFIX = 'cmsPrefix'; |
|
24 | - const PARAMETER_DOCUMENT = 'document'; |
|
25 | - const PARAMETER_DOCUMENTS = 'documents'; |
|
26 | - const PARAMETER_DOCUMENT_TYPE = 'documentType'; |
|
27 | - const PARAMETER_DOCUMENT_TYPES = 'documentTypes'; |
|
28 | - const PARAMETER_ERROR_MESSAGE = 'errorMsg'; |
|
29 | - const PARAMETER_FILES = 'files'; |
|
30 | - const PARAMETER_FOLDER = 'folder'; |
|
31 | - const PARAMETER_IMAGE = 'image'; |
|
32 | - const PARAMETER_IMAGES = 'images'; |
|
33 | - const PARAMETER_IMAGE_SET = 'imageSet'; |
|
34 | - const PARAMETER_MAIN_NAV_CLASS = 'mainNavClass'; |
|
35 | - const PARAMETER_MY_BRICK_SLUG = 'myBrickSlug'; |
|
36 | - const PARAMETER_SITEMAP = 'sitemap'; |
|
37 | - const PARAMETER_SITEMAP_ITEM = 'sitemapItem'; |
|
38 | - const PARAMETER_SMALLEST_IMAGE = 'smallestImage'; |
|
39 | - const PARAMETER_STATIC = 'static'; |
|
40 | - const PARAMETER_USER = 'user'; |
|
41 | - const PARAMETER_USERS = 'users'; |
|
42 | - const PARAMETER_USER_RIGHTS = 'userRights'; |
|
43 | - const PARAMETER_WHITELIST_IPS = 'whitelistIps'; |
|
44 | - |
|
45 | - const POST_PARAMETER_COMPONENT = 'component'; |
|
46 | - const POST_PARAMETER_PASSWORD = 'password'; |
|
47 | - const POST_PARAMETER_SAVE = 'save'; |
|
48 | - const POST_PARAMETER_TEMPLATE = 'template'; |
|
49 | - const POST_PARAMETER_TITLE = 'title'; |
|
50 | - const POST_PARAMETER_USERNAME = 'username'; |
|
51 | - |
|
52 | - const GET_PARAMETER_PATH = 'path'; |
|
53 | - const GET_PARAMETER_SLUG = 'slug'; |
|
54 | - |
|
55 | - const FILES_PARAMETER_FILE = 'file'; |
|
56 | - |
|
57 | - const SESSION_PARAMETER_CLOUD_CONTROL = 'cloudcontrol'; |
|
58 | - |
|
59 | - const LOGIN_TEMPLATE_PATH = 'cms/login'; |
|
60 | - |
|
61 | - const CONTENT_TYPE_APPLICATION_JSON = 'Content-type:application/json'; |
|
62 | - |
|
63 | - public $subTemplate = null; |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * @param \library\storage\Storage $storage |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - public function run(Storage $storage) |
|
72 | - { |
|
73 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::MAIN_NAV_CLASS; |
|
74 | - $this->storage = $storage; |
|
75 | - |
|
76 | - $remoteAddress = $_SERVER['REMOTE_ADDR']; |
|
77 | - $this->checkWhiteList($remoteAddress); |
|
78 | - $this->checkBlackList($remoteAddress); |
|
79 | - |
|
80 | - $this->checkLogin(); |
|
81 | - |
|
82 | - $this->parameters[self::PARAMETER_USER_RIGHTS] = $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]->rights; |
|
83 | - |
|
84 | - $this->routing(); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * See if a user is logged or wants to log in and |
|
89 | - * takes appropriate actions. |
|
90 | - * |
|
91 | - * @throws \Exception |
|
92 | - */ |
|
93 | - protected function checkLogin() |
|
94 | - { |
|
95 | - $request = $this->request; |
|
96 | - |
|
97 | - if (!isset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL])) { |
|
98 | - if (isset($request::$post[self::POST_PARAMETER_USERNAME], $request::$post[self::POST_PARAMETER_PASSWORD])) { |
|
99 | - $user = $this->storage->getUserByUsername($request::$post[self::POST_PARAMETER_USERNAME]); |
|
100 | - $crypt = new Crypt(); |
|
101 | - if (empty($user)) { |
|
102 | - $crypt->encrypt($request::$post[self::POST_PARAMETER_PASSWORD], 16); // Buy time, to avoid brute forcing |
|
103 | - $this->parameters[self::PARAMETER_ERROR_MESSAGE] = self::INVALID_CREDENTIALS_MESSAGE; |
|
104 | - $this->showLogin(); |
|
105 | - } else { |
|
106 | - $salt = $user->salt; |
|
107 | - $password = $user->password; |
|
108 | - |
|
109 | - $passwordCorrect = $crypt->compare($request::$post[self::POST_PARAMETER_PASSWORD], $password, $salt); |
|
110 | - |
|
111 | - if ($passwordCorrect) { |
|
112 | - $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = $user; |
|
113 | - } else { |
|
114 | - $this->parameters[self::PARAMETER_ERROR_MESSAGE] = self::INVALID_CREDENTIALS_MESSAGE; |
|
115 | - $this->showLogin(); |
|
116 | - } |
|
117 | - } |
|
118 | - } else { |
|
119 | - $this->showLogin(); |
|
120 | - } |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Overrides normal behaviour and only renders the |
|
126 | - * login screen |
|
127 | - * |
|
128 | - * @throws \Exception |
|
129 | - */ |
|
130 | - protected function showLogin() |
|
131 | - { |
|
132 | - $loginTemplatePath = self::LOGIN_TEMPLATE_PATH; |
|
133 | - $this->renderTemplate($loginTemplatePath); |
|
134 | - ob_end_flush(); |
|
135 | - exit; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * As an exception, to keep the initial file structure simple |
|
140 | - * the cms implements it's own routing, apart from the regular sitemap functionality |
|
141 | - * |
|
142 | - * @throws \Exception |
|
143 | - */ |
|
144 | - protected function routing() |
|
145 | - { |
|
146 | - $relativeCmsUri = $this->getRelativeCmsUri($this->request); |
|
147 | - |
|
148 | - $userRights = $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]->rights; |
|
149 | - |
|
150 | - if ($relativeCmsUri == '' || $relativeCmsUri == '/') { |
|
151 | - $this->subTemplate = 'cms/dashboard'; |
|
152 | - } |
|
153 | - |
|
154 | - $this->logOffRouting($this->request, $relativeCmsUri); |
|
155 | - |
|
156 | - $this->apiRouting($relativeCmsUri); |
|
157 | - |
|
158 | - if (in_array(self::PARAMETER_DOCUMENTS, $userRights)) { |
|
159 | - new DocumentRouting($this->request, $relativeCmsUri, $this); |
|
160 | - } |
|
161 | - |
|
162 | - if (in_array(self::PARAMETER_SITEMAP, $userRights)) { |
|
163 | - $this->sitemapRouting($this->request, $relativeCmsUri); |
|
164 | - } |
|
165 | - |
|
166 | - if (in_array(self::PARAMETER_IMAGES, $userRights)) { |
|
167 | - $this->imagesRouting($this->request, $relativeCmsUri); |
|
168 | - } |
|
169 | - |
|
170 | - if (in_array(self::PARAMETER_FILES, $userRights)) { |
|
171 | - $this->filesRouting($this->request, $relativeCmsUri); |
|
172 | - } |
|
173 | - |
|
174 | - if (in_array('configuration', $userRights)) { |
|
175 | - $this->configurationRouting($this->request, $relativeCmsUri); |
|
176 | - } |
|
177 | - |
|
178 | - if ($this->subTemplate !== null) { |
|
179 | - $this->parameters[self::PARAMETER_BODY] = $this->renderTemplate($this->subTemplate); |
|
180 | - } |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * @param $remoteAddress |
|
185 | - * @throws \Exception |
|
186 | - */ |
|
187 | - private function checkWhiteList($remoteAddress) |
|
188 | - { |
|
189 | - if (isset($this->parameters[self::PARAMETER_WHITELIST_IPS])) { |
|
190 | - $whitelistIps = explode(',', $this->parameters[self::PARAMETER_WHITELIST_IPS]); |
|
191 | - $whitelistIps = array_map("trim", $whitelistIps); |
|
192 | - if (!in_array($remoteAddress, $whitelistIps)) { |
|
193 | - throw new \Exception('Ip address ' . $remoteAddress . ' is not on whitelist'); |
|
194 | - } |
|
195 | - } |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * @param $remoteAddress |
|
200 | - * @throws \Exception |
|
201 | - */ |
|
202 | - private function checkBlackList($remoteAddress) |
|
203 | - { |
|
204 | - if (isset($this->parameters[self::PARAMETER_BLACKLIST_IPS])) { |
|
205 | - $blacklistIps = explode(',', $this->parameters[self::PARAMETER_BLACKLIST_IPS]); |
|
206 | - $blacklistIps = array_map("trim", $blacklistIps); |
|
207 | - if (in_array($remoteAddress, $blacklistIps)) { |
|
208 | - throw new \Exception('Ip address ' . $remoteAddress . ' is on blacklist'); |
|
209 | - } |
|
210 | - } |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * @param $request |
|
215 | - * @return mixed|string |
|
216 | - */ |
|
217 | - private function getRelativeCmsUri($request) |
|
218 | - { |
|
219 | - // TODO Use regex match parameter instead of calculating relative uri |
|
220 | - $pos = strpos($request::$relativeUri, $this->parameters[self::PARAMETER_CMS_PREFIX]); |
|
221 | - $relativeCmsUri = '/'; |
|
222 | - if ($pos !== false) { |
|
223 | - $relativeCmsUri = substr_replace($request::$relativeUri, '', $pos, strlen($this->parameters[self::PARAMETER_CMS_PREFIX])); |
|
224 | - } |
|
225 | - return $relativeCmsUri; |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * @param \library\cc\Request $request |
|
230 | - * @param $relativeCmsUri |
|
231 | - */ |
|
232 | - private function sitemapRouting($request, $relativeCmsUri) |
|
233 | - { |
|
234 | - if ($relativeCmsUri == '/sitemap') { |
|
235 | - $this->subTemplate = 'cms/sitemap'; |
|
236 | - if (isset($request::$post[self::POST_PARAMETER_SAVE])) { |
|
237 | - $this->storage->saveSitemap($request::$post); |
|
238 | - } |
|
239 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_SITEMAP; |
|
240 | - $this->parameters[self::PARAMETER_SITEMAP] = $this->storage->getSitemap(); |
|
241 | - } elseif ($relativeCmsUri == '/sitemap/new') { |
|
242 | - $this->subTemplate = 'cms/sitemap/form'; |
|
243 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_SITEMAP; |
|
244 | - if (isset($request::$post[self::POST_PARAMETER_TITLE], $request::$post[self::POST_PARAMETER_TEMPLATE], $request::$post[self::POST_PARAMETER_COMPONENT])) { |
|
245 | - $this->storage->addSitemapItem($request::$post); |
|
246 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/sitemap'); |
|
247 | - exit; |
|
248 | - } |
|
249 | - } elseif ($relativeCmsUri == '/sitemap/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
250 | - $this->subTemplate = 'cms/sitemap/form'; |
|
251 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_SITEMAP; |
|
252 | - $sitemapItem = $this->storage->getSitemapItemBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
253 | - if (isset($request::$post[self::POST_PARAMETER_TITLE], $request::$post[self::POST_PARAMETER_TEMPLATE], $request::$post[self::POST_PARAMETER_COMPONENT])) { |
|
254 | - $this->storage->saveSitemapItem($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
|
255 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/sitemap'); |
|
256 | - exit; |
|
257 | - } |
|
258 | - $this->parameters[self::PARAMETER_SITEMAP_ITEM] = $sitemapItem; |
|
259 | - } elseif ($relativeCmsUri == '/sitemap/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
260 | - $this->storage->deleteSitemapItemBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
261 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/sitemap'); |
|
262 | - exit; |
|
263 | - } |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * @param $request |
|
268 | - * @param $relativeCmsUri |
|
269 | - */ |
|
270 | - private function imagesRouting($request, $relativeCmsUri) |
|
271 | - { |
|
272 | - if ($relativeCmsUri == '/images') { |
|
273 | - $this->subTemplate = 'cms/images'; |
|
274 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_IMAGES; |
|
275 | - $this->parameters[self::PARAMETER_IMAGES] = $this->storage->getImages(); |
|
276 | - $this->parameters[self::PARAMETER_SMALLEST_IMAGE] = $this->storage->getSmallestImageSet()->slug; |
|
277 | - } elseif ($relativeCmsUri == '/images.json') { |
|
278 | - header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
279 | - die(json_encode($this->storage->getImages())); |
|
280 | - } elseif ($relativeCmsUri == '/images/new') { |
|
281 | - $this->subTemplate = 'cms/images/form'; |
|
282 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_IMAGES; |
|
283 | - if (isset($_FILES[self::FILES_PARAMETER_FILE])) { |
|
284 | - $this->storage->addImage($_FILES[self::FILES_PARAMETER_FILE]); |
|
285 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/images'); |
|
286 | - exit; |
|
287 | - } |
|
288 | - } elseif ($relativeCmsUri == '/images/delete' && isset($request::$get[self::FILES_PARAMETER_FILE])) { |
|
289 | - $this->storage->deleteImageByName($request::$get[self::FILES_PARAMETER_FILE]); |
|
290 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/images'); |
|
291 | - exit; |
|
292 | - } elseif ($relativeCmsUri == '/images/show' && isset($request::$get[self::FILES_PARAMETER_FILE])) { |
|
293 | - $this->subTemplate = 'cms/images/show'; |
|
294 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_IMAGES; |
|
295 | - $this->parameters[self::PARAMETER_IMAGE] = $this->storage->getImageByName($request::$get[self::FILES_PARAMETER_FILE]); |
|
296 | - } |
|
297 | - } |
|
298 | - |
|
299 | - /** |
|
300 | - * @param $relativeCmsUri |
|
301 | - */ |
|
302 | - private function apiRouting($relativeCmsUri) |
|
303 | - { |
|
304 | - if ($relativeCmsUri == '/images.json') { |
|
305 | - header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
306 | - die(json_encode($this->storage->getImages())); |
|
307 | - } elseif ($relativeCmsUri == '/files.json') { |
|
308 | - header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
309 | - die(json_encode($this->storage->getFiles())); |
|
310 | - } elseif ($relativeCmsUri == '/documents.json') { |
|
311 | - header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
312 | - die(json_encode($this->storage->getDocuments())); |
|
313 | - } |
|
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * @param $request |
|
318 | - * @param $relativeCmsUri |
|
319 | - */ |
|
320 | - private function filesRouting($request, $relativeCmsUri) |
|
321 | - { |
|
322 | - if ($relativeCmsUri == '/files') { |
|
323 | - $this->subTemplate = 'cms/files'; |
|
324 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_FILES; |
|
325 | - $this->parameters[self::PARAMETER_FILES] = $this->storage->getFiles(); |
|
326 | - } elseif ($relativeCmsUri == '/files/new') { |
|
327 | - $this->subTemplate = 'cms/files/form'; |
|
328 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_FILES; |
|
329 | - if (isset($_FILES[self::FILES_PARAMETER_FILE])) { |
|
330 | - $this->storage->addFile($_FILES[self::FILES_PARAMETER_FILE]); |
|
331 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/files'); |
|
332 | - exit; |
|
333 | - } |
|
334 | - } elseif ($relativeCmsUri == '/files/get' && isset($request::$get[self::FILES_PARAMETER_FILE])) { |
|
335 | - $this->downloadFile($request::$get[self::FILES_PARAMETER_FILE]); |
|
336 | - } elseif ($relativeCmsUri == '/files/delete' && isset($request::$get[self::FILES_PARAMETER_FILE])) { |
|
337 | - $this->storage->deleteFileByName($request::$get[self::FILES_PARAMETER_FILE]); |
|
338 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/files'); |
|
339 | - exit; |
|
340 | - } |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * @param $slug |
|
345 | - */ |
|
346 | - private function downloadFile($slug) |
|
347 | - { |
|
348 | - $file = $this->storage->getFileByName($slug); |
|
349 | - $path = realpath(__DIR__ . '/../../www/files/'); |
|
350 | - $quoted = sprintf('"%s"', addcslashes(basename($path . '/' . $file->file), '"\\')); |
|
351 | - $size = filesize($path . '/' . $file->file); |
|
352 | - |
|
353 | - header('Content-Description: File Transfer'); |
|
354 | - header('Content-Type: ' . $file->type); |
|
355 | - header('Content-Disposition: attachment; filename=' . $quoted); |
|
356 | - header('Content-Transfer-Encoding: binary'); |
|
357 | - header('Connection: Keep-Alive'); |
|
358 | - header('Expires: 0'); |
|
359 | - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
360 | - header('Pragma: public'); |
|
361 | - header('Content-Length: ' . $size); |
|
362 | - |
|
363 | - readfile($path . '/' . $file->file); |
|
364 | - exit; |
|
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * @param $request |
|
369 | - * @param $relativeCmsUri |
|
370 | - */ |
|
371 | - private function configurationRouting($request, $relativeCmsUri) |
|
372 | - { |
|
373 | - if ($relativeCmsUri == '/configuration') { |
|
374 | - $this->subTemplate = 'cms/configuration'; |
|
375 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
376 | - } |
|
377 | - |
|
378 | - $this->usersRouting($request, $relativeCmsUri); |
|
379 | - $this->documentTypesRouting($request, $relativeCmsUri); |
|
380 | - $this->bricksRouting($request, $relativeCmsUri); |
|
381 | - $this->imageSetRouting($request, $relativeCmsUri); |
|
382 | - $this->applicationComponentRouting($request, $relativeCmsUri); |
|
383 | - } |
|
384 | - |
|
385 | - |
|
386 | - |
|
387 | - /** |
|
388 | - * @param $request |
|
389 | - * @param $relativeCmsUri |
|
390 | - */ |
|
391 | - private function usersRouting($request, $relativeCmsUri) |
|
392 | - { |
|
393 | - if ($relativeCmsUri == '/configuration/users') { |
|
394 | - $this->subTemplate = 'cms/configuration/users'; |
|
395 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
396 | - $this->parameters[self::PARAMETER_USERS] = $this->storage->getUsers(); |
|
397 | - } elseif ($relativeCmsUri == '/configuration/users/new') { |
|
398 | - $this->subTemplate = 'cms/configuration/users-form'; |
|
399 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
400 | - if (isset($_POST[self::POST_PARAMETER_USERNAME])) { |
|
401 | - $this->storage->addUser($request::$post); |
|
402 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/users'); |
|
403 | - exit; |
|
404 | - } |
|
405 | - } elseif ($relativeCmsUri == '/configuration/users/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
406 | - $this->storage->deleteUserBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
407 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/users'); |
|
408 | - exit; |
|
409 | - } elseif ($relativeCmsUri == '/configuration/users/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
410 | - $this->subTemplate = 'cms/configuration/users-form'; |
|
411 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
412 | - $this->parameters[self::PARAMETER_USER] = $this->storage->getUserBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
413 | - if (isset($_POST[self::POST_PARAMETER_USERNAME])) { |
|
414 | - $this->storage->saveUser($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
|
415 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/users'); |
|
416 | - exit; |
|
417 | - } |
|
418 | - } |
|
419 | - } |
|
420 | - |
|
421 | - /** |
|
422 | - * @param $request |
|
423 | - * @param $relativeCmsUri |
|
424 | - */ |
|
425 | - private function documentTypesRouting($request, $relativeCmsUri) |
|
426 | - { |
|
427 | - if ($relativeCmsUri == '/configuration/document-types') { |
|
428 | - $this->subTemplate = 'cms/configuration/document-types'; |
|
429 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
430 | - $this->parameters[self::PARAMETER_DOCUMENT_TYPES] = $this->storage->getDocumentTypes(); |
|
431 | - } elseif ($relativeCmsUri == '/configuration/document-types/new') { |
|
432 | - $this->subTemplate = 'cms/configuration/document-types-form'; |
|
433 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
434 | - $bricks = $this->storage->getBricks(); |
|
435 | - if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
436 | - $this->storage->addDocumentType($request::$post); |
|
437 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/document-types'); |
|
438 | - exit; |
|
439 | - } |
|
440 | - $this->parameters[self::PARAMETER_BRICKS] = $bricks; |
|
441 | - } elseif ($relativeCmsUri == '/configuration/document-types/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
442 | - $this->subTemplate = 'cms/configuration/document-types-form'; |
|
443 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
444 | - $documentType = $this->storage->getDocumentTypeBySlug($request::$get[self::GET_PARAMETER_SLUG], false); |
|
445 | - $bricks = $this->storage->getBricks(); |
|
446 | - if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
447 | - $this->storage->saveDocumentType($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
|
448 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/document-types'); |
|
449 | - exit; |
|
450 | - } |
|
451 | - $this->parameters[self::PARAMETER_DOCUMENT_TYPE] = $documentType; |
|
452 | - $this->parameters[self::PARAMETER_BRICKS] = $bricks; |
|
453 | - } elseif ($relativeCmsUri == '/configuration/document-types/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
454 | - $this->storage->deleteDocumentTypeBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
455 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/document-types'); |
|
456 | - exit; |
|
457 | - } |
|
458 | - } |
|
459 | - |
|
460 | - /** |
|
461 | - * @param $request |
|
462 | - * @param $relativeCmsUri |
|
463 | - */ |
|
464 | - private function bricksRouting($request, $relativeCmsUri) |
|
465 | - { |
|
466 | - if ($relativeCmsUri == '/configuration/bricks') { |
|
467 | - $this->subTemplate = 'cms/configuration/bricks'; |
|
468 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
469 | - $this->parameters[self::PARAMETER_BRICKS] = $this->storage->getBricks(); |
|
470 | - } elseif ($relativeCmsUri == '/configuration/bricks/new') { |
|
471 | - $this->subTemplate = 'cms/configuration/bricks-form'; |
|
472 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
473 | - if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
474 | - $this->storage->addBrick($request::$post); |
|
475 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/bricks'); |
|
476 | - exit; |
|
477 | - } |
|
478 | - } elseif ($relativeCmsUri == '/configuration/bricks/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
479 | - $this->subTemplate = 'cms/configuration/bricks-form'; |
|
480 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
481 | - $brick = $this->storage->getBrickBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
482 | - if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
483 | - $this->storage->saveBrick($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
|
484 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/bricks'); |
|
485 | - exit; |
|
486 | - } |
|
487 | - $this->parameters[self::PARAMETER_BRICK] = $brick; |
|
488 | - } elseif ($relativeCmsUri == '/configuration/bricks/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
489 | - $this->storage->deleteBrickBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
490 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/bricks'); |
|
491 | - exit; |
|
492 | - } elseif ($relativeCmsUri == '/configuration/image-set') { |
|
493 | - $this->subTemplate = 'cms/configuration/image-set'; |
|
494 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
495 | - $this->parameters[self::PARAMETER_IMAGE_SET] = $this->storage->getImageSet(); |
|
496 | - } |
|
497 | - } |
|
498 | - |
|
499 | - /** |
|
500 | - * @param $request |
|
501 | - * @param $relativeCmsUri |
|
502 | - */ |
|
503 | - private function imageSetRouting($request, $relativeCmsUri) |
|
504 | - { |
|
505 | - if ($relativeCmsUri == '/configuration/image-set') { |
|
506 | - $this->subTemplate = 'cms/configuration/image-set'; |
|
507 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
508 | - $this->parameters[self::PARAMETER_IMAGE_SET] = $this->storage->getImageSet(); |
|
509 | - } elseif ($relativeCmsUri == '/configuration/image-set/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
510 | - $this->subTemplate = 'cms/configuration/image-set-form'; |
|
511 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
512 | - $imageSet = $this->storage->getImageSetBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
513 | - if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
514 | - $this->storage->saveImageSet($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
|
515 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/image-set'); |
|
516 | - exit; |
|
517 | - } |
|
518 | - $this->parameters[self::PARAMETER_IMAGE_SET] = $imageSet; |
|
519 | - } elseif ($relativeCmsUri == '/configuration/image-set/new') { |
|
520 | - $this->subTemplate = 'cms/configuration/image-set-form'; |
|
521 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
522 | - if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
523 | - $this->storage->addImageSet($request::$post); |
|
524 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/image-set'); |
|
525 | - exit; |
|
526 | - } |
|
527 | - } elseif ($relativeCmsUri == '/configuration/image-set/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
528 | - $this->storage->deleteImageSetBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
529 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/image-set'); |
|
530 | - exit; |
|
531 | - } |
|
532 | - } |
|
533 | - |
|
534 | - /** |
|
535 | - * @param $request |
|
536 | - * @param $relativeCmsUri |
|
537 | - */ |
|
538 | - private function applicationComponentRouting($request, $relativeCmsUri) |
|
539 | - { |
|
540 | - if ($relativeCmsUri == '/configuration/application-components') { |
|
541 | - $this->subTemplate = 'cms/configuration/application-components'; |
|
542 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
543 | - $this->parameters['applicationComponents'] = $this->storage->getApplicationComponents(); |
|
544 | - } elseif ($relativeCmsUri == '/configuration/application-components/new') { |
|
545 | - $this->subTemplate = 'cms/configuration/application-components-form'; |
|
546 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
547 | - if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
548 | - $this->storage->addApplicationComponent($request::$post); |
|
549 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/application-components'); |
|
550 | - exit; |
|
551 | - } |
|
552 | - } elseif ($relativeCmsUri == '/configuration/application-components/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
553 | - $this->subTemplate = 'cms/configuration/application-components-form'; |
|
554 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
555 | - $applicationComponent = $this->storage->getApplicationComponentBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
556 | - if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
557 | - $this->storage->saveApplicationComponent($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
|
558 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/application-components'); |
|
559 | - exit; |
|
560 | - } |
|
561 | - $this->parameters['applicationComponent'] = $applicationComponent; |
|
562 | - } elseif ($relativeCmsUri == '/configuration/application-components/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
563 | - $this->storage->deleteApplicationComponentBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
564 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/application-components'); |
|
565 | - exit; |
|
566 | - } |
|
567 | - } |
|
568 | - |
|
569 | - private function logOffRouting($request, $relativeCmsUri) |
|
570 | - { |
|
571 | - if ($relativeCmsUri == '/log-off') { |
|
572 | - $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = null; |
|
573 | - unset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]); |
|
574 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX]); |
|
575 | - exit; |
|
576 | - } |
|
577 | - } |
|
578 | - |
|
579 | - public function setParameter($parameterName, $parameterValue) |
|
580 | - { |
|
581 | - $this->parameters[$parameterName] = $parameterValue; |
|
582 | - } |
|
583 | - |
|
584 | - public function getParameter($parameterName) |
|
585 | - { |
|
586 | - return $this->parameters[$parameterName]; |
|
587 | - } |
|
588 | - } |
|
13 | + public $storage; |
|
14 | + |
|
15 | + const INVALID_CREDENTIALS_MESSAGE = 'Invalid username / password combination'; |
|
16 | + |
|
17 | + const MAIN_NAV_CLASS = 'default'; |
|
18 | + |
|
19 | + const PARAMETER_BLACKLIST_IPS = 'blacklistIps'; |
|
20 | + const PARAMETER_BODY = 'body'; |
|
21 | + const PARAMETER_BRICK = 'brick'; |
|
22 | + const PARAMETER_BRICKS = 'bricks'; |
|
23 | + const PARAMETER_CMS_PREFIX = 'cmsPrefix'; |
|
24 | + const PARAMETER_DOCUMENT = 'document'; |
|
25 | + const PARAMETER_DOCUMENTS = 'documents'; |
|
26 | + const PARAMETER_DOCUMENT_TYPE = 'documentType'; |
|
27 | + const PARAMETER_DOCUMENT_TYPES = 'documentTypes'; |
|
28 | + const PARAMETER_ERROR_MESSAGE = 'errorMsg'; |
|
29 | + const PARAMETER_FILES = 'files'; |
|
30 | + const PARAMETER_FOLDER = 'folder'; |
|
31 | + const PARAMETER_IMAGE = 'image'; |
|
32 | + const PARAMETER_IMAGES = 'images'; |
|
33 | + const PARAMETER_IMAGE_SET = 'imageSet'; |
|
34 | + const PARAMETER_MAIN_NAV_CLASS = 'mainNavClass'; |
|
35 | + const PARAMETER_MY_BRICK_SLUG = 'myBrickSlug'; |
|
36 | + const PARAMETER_SITEMAP = 'sitemap'; |
|
37 | + const PARAMETER_SITEMAP_ITEM = 'sitemapItem'; |
|
38 | + const PARAMETER_SMALLEST_IMAGE = 'smallestImage'; |
|
39 | + const PARAMETER_STATIC = 'static'; |
|
40 | + const PARAMETER_USER = 'user'; |
|
41 | + const PARAMETER_USERS = 'users'; |
|
42 | + const PARAMETER_USER_RIGHTS = 'userRights'; |
|
43 | + const PARAMETER_WHITELIST_IPS = 'whitelistIps'; |
|
44 | + |
|
45 | + const POST_PARAMETER_COMPONENT = 'component'; |
|
46 | + const POST_PARAMETER_PASSWORD = 'password'; |
|
47 | + const POST_PARAMETER_SAVE = 'save'; |
|
48 | + const POST_PARAMETER_TEMPLATE = 'template'; |
|
49 | + const POST_PARAMETER_TITLE = 'title'; |
|
50 | + const POST_PARAMETER_USERNAME = 'username'; |
|
51 | + |
|
52 | + const GET_PARAMETER_PATH = 'path'; |
|
53 | + const GET_PARAMETER_SLUG = 'slug'; |
|
54 | + |
|
55 | + const FILES_PARAMETER_FILE = 'file'; |
|
56 | + |
|
57 | + const SESSION_PARAMETER_CLOUD_CONTROL = 'cloudcontrol'; |
|
58 | + |
|
59 | + const LOGIN_TEMPLATE_PATH = 'cms/login'; |
|
60 | + |
|
61 | + const CONTENT_TYPE_APPLICATION_JSON = 'Content-type:application/json'; |
|
62 | + |
|
63 | + public $subTemplate = null; |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * @param \library\storage\Storage $storage |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + public function run(Storage $storage) |
|
72 | + { |
|
73 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::MAIN_NAV_CLASS; |
|
74 | + $this->storage = $storage; |
|
75 | + |
|
76 | + $remoteAddress = $_SERVER['REMOTE_ADDR']; |
|
77 | + $this->checkWhiteList($remoteAddress); |
|
78 | + $this->checkBlackList($remoteAddress); |
|
79 | + |
|
80 | + $this->checkLogin(); |
|
81 | + |
|
82 | + $this->parameters[self::PARAMETER_USER_RIGHTS] = $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]->rights; |
|
83 | + |
|
84 | + $this->routing(); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * See if a user is logged or wants to log in and |
|
89 | + * takes appropriate actions. |
|
90 | + * |
|
91 | + * @throws \Exception |
|
92 | + */ |
|
93 | + protected function checkLogin() |
|
94 | + { |
|
95 | + $request = $this->request; |
|
96 | + |
|
97 | + if (!isset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL])) { |
|
98 | + if (isset($request::$post[self::POST_PARAMETER_USERNAME], $request::$post[self::POST_PARAMETER_PASSWORD])) { |
|
99 | + $user = $this->storage->getUserByUsername($request::$post[self::POST_PARAMETER_USERNAME]); |
|
100 | + $crypt = new Crypt(); |
|
101 | + if (empty($user)) { |
|
102 | + $crypt->encrypt($request::$post[self::POST_PARAMETER_PASSWORD], 16); // Buy time, to avoid brute forcing |
|
103 | + $this->parameters[self::PARAMETER_ERROR_MESSAGE] = self::INVALID_CREDENTIALS_MESSAGE; |
|
104 | + $this->showLogin(); |
|
105 | + } else { |
|
106 | + $salt = $user->salt; |
|
107 | + $password = $user->password; |
|
108 | + |
|
109 | + $passwordCorrect = $crypt->compare($request::$post[self::POST_PARAMETER_PASSWORD], $password, $salt); |
|
110 | + |
|
111 | + if ($passwordCorrect) { |
|
112 | + $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = $user; |
|
113 | + } else { |
|
114 | + $this->parameters[self::PARAMETER_ERROR_MESSAGE] = self::INVALID_CREDENTIALS_MESSAGE; |
|
115 | + $this->showLogin(); |
|
116 | + } |
|
117 | + } |
|
118 | + } else { |
|
119 | + $this->showLogin(); |
|
120 | + } |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Overrides normal behaviour and only renders the |
|
126 | + * login screen |
|
127 | + * |
|
128 | + * @throws \Exception |
|
129 | + */ |
|
130 | + protected function showLogin() |
|
131 | + { |
|
132 | + $loginTemplatePath = self::LOGIN_TEMPLATE_PATH; |
|
133 | + $this->renderTemplate($loginTemplatePath); |
|
134 | + ob_end_flush(); |
|
135 | + exit; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * As an exception, to keep the initial file structure simple |
|
140 | + * the cms implements it's own routing, apart from the regular sitemap functionality |
|
141 | + * |
|
142 | + * @throws \Exception |
|
143 | + */ |
|
144 | + protected function routing() |
|
145 | + { |
|
146 | + $relativeCmsUri = $this->getRelativeCmsUri($this->request); |
|
147 | + |
|
148 | + $userRights = $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]->rights; |
|
149 | + |
|
150 | + if ($relativeCmsUri == '' || $relativeCmsUri == '/') { |
|
151 | + $this->subTemplate = 'cms/dashboard'; |
|
152 | + } |
|
153 | + |
|
154 | + $this->logOffRouting($this->request, $relativeCmsUri); |
|
155 | + |
|
156 | + $this->apiRouting($relativeCmsUri); |
|
157 | + |
|
158 | + if (in_array(self::PARAMETER_DOCUMENTS, $userRights)) { |
|
159 | + new DocumentRouting($this->request, $relativeCmsUri, $this); |
|
160 | + } |
|
161 | + |
|
162 | + if (in_array(self::PARAMETER_SITEMAP, $userRights)) { |
|
163 | + $this->sitemapRouting($this->request, $relativeCmsUri); |
|
164 | + } |
|
165 | + |
|
166 | + if (in_array(self::PARAMETER_IMAGES, $userRights)) { |
|
167 | + $this->imagesRouting($this->request, $relativeCmsUri); |
|
168 | + } |
|
169 | + |
|
170 | + if (in_array(self::PARAMETER_FILES, $userRights)) { |
|
171 | + $this->filesRouting($this->request, $relativeCmsUri); |
|
172 | + } |
|
173 | + |
|
174 | + if (in_array('configuration', $userRights)) { |
|
175 | + $this->configurationRouting($this->request, $relativeCmsUri); |
|
176 | + } |
|
177 | + |
|
178 | + if ($this->subTemplate !== null) { |
|
179 | + $this->parameters[self::PARAMETER_BODY] = $this->renderTemplate($this->subTemplate); |
|
180 | + } |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * @param $remoteAddress |
|
185 | + * @throws \Exception |
|
186 | + */ |
|
187 | + private function checkWhiteList($remoteAddress) |
|
188 | + { |
|
189 | + if (isset($this->parameters[self::PARAMETER_WHITELIST_IPS])) { |
|
190 | + $whitelistIps = explode(',', $this->parameters[self::PARAMETER_WHITELIST_IPS]); |
|
191 | + $whitelistIps = array_map("trim", $whitelistIps); |
|
192 | + if (!in_array($remoteAddress, $whitelistIps)) { |
|
193 | + throw new \Exception('Ip address ' . $remoteAddress . ' is not on whitelist'); |
|
194 | + } |
|
195 | + } |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * @param $remoteAddress |
|
200 | + * @throws \Exception |
|
201 | + */ |
|
202 | + private function checkBlackList($remoteAddress) |
|
203 | + { |
|
204 | + if (isset($this->parameters[self::PARAMETER_BLACKLIST_IPS])) { |
|
205 | + $blacklistIps = explode(',', $this->parameters[self::PARAMETER_BLACKLIST_IPS]); |
|
206 | + $blacklistIps = array_map("trim", $blacklistIps); |
|
207 | + if (in_array($remoteAddress, $blacklistIps)) { |
|
208 | + throw new \Exception('Ip address ' . $remoteAddress . ' is on blacklist'); |
|
209 | + } |
|
210 | + } |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * @param $request |
|
215 | + * @return mixed|string |
|
216 | + */ |
|
217 | + private function getRelativeCmsUri($request) |
|
218 | + { |
|
219 | + // TODO Use regex match parameter instead of calculating relative uri |
|
220 | + $pos = strpos($request::$relativeUri, $this->parameters[self::PARAMETER_CMS_PREFIX]); |
|
221 | + $relativeCmsUri = '/'; |
|
222 | + if ($pos !== false) { |
|
223 | + $relativeCmsUri = substr_replace($request::$relativeUri, '', $pos, strlen($this->parameters[self::PARAMETER_CMS_PREFIX])); |
|
224 | + } |
|
225 | + return $relativeCmsUri; |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * @param \library\cc\Request $request |
|
230 | + * @param $relativeCmsUri |
|
231 | + */ |
|
232 | + private function sitemapRouting($request, $relativeCmsUri) |
|
233 | + { |
|
234 | + if ($relativeCmsUri == '/sitemap') { |
|
235 | + $this->subTemplate = 'cms/sitemap'; |
|
236 | + if (isset($request::$post[self::POST_PARAMETER_SAVE])) { |
|
237 | + $this->storage->saveSitemap($request::$post); |
|
238 | + } |
|
239 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_SITEMAP; |
|
240 | + $this->parameters[self::PARAMETER_SITEMAP] = $this->storage->getSitemap(); |
|
241 | + } elseif ($relativeCmsUri == '/sitemap/new') { |
|
242 | + $this->subTemplate = 'cms/sitemap/form'; |
|
243 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_SITEMAP; |
|
244 | + if (isset($request::$post[self::POST_PARAMETER_TITLE], $request::$post[self::POST_PARAMETER_TEMPLATE], $request::$post[self::POST_PARAMETER_COMPONENT])) { |
|
245 | + $this->storage->addSitemapItem($request::$post); |
|
246 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/sitemap'); |
|
247 | + exit; |
|
248 | + } |
|
249 | + } elseif ($relativeCmsUri == '/sitemap/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
250 | + $this->subTemplate = 'cms/sitemap/form'; |
|
251 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_SITEMAP; |
|
252 | + $sitemapItem = $this->storage->getSitemapItemBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
253 | + if (isset($request::$post[self::POST_PARAMETER_TITLE], $request::$post[self::POST_PARAMETER_TEMPLATE], $request::$post[self::POST_PARAMETER_COMPONENT])) { |
|
254 | + $this->storage->saveSitemapItem($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
|
255 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/sitemap'); |
|
256 | + exit; |
|
257 | + } |
|
258 | + $this->parameters[self::PARAMETER_SITEMAP_ITEM] = $sitemapItem; |
|
259 | + } elseif ($relativeCmsUri == '/sitemap/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
260 | + $this->storage->deleteSitemapItemBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
261 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/sitemap'); |
|
262 | + exit; |
|
263 | + } |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * @param $request |
|
268 | + * @param $relativeCmsUri |
|
269 | + */ |
|
270 | + private function imagesRouting($request, $relativeCmsUri) |
|
271 | + { |
|
272 | + if ($relativeCmsUri == '/images') { |
|
273 | + $this->subTemplate = 'cms/images'; |
|
274 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_IMAGES; |
|
275 | + $this->parameters[self::PARAMETER_IMAGES] = $this->storage->getImages(); |
|
276 | + $this->parameters[self::PARAMETER_SMALLEST_IMAGE] = $this->storage->getSmallestImageSet()->slug; |
|
277 | + } elseif ($relativeCmsUri == '/images.json') { |
|
278 | + header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
279 | + die(json_encode($this->storage->getImages())); |
|
280 | + } elseif ($relativeCmsUri == '/images/new') { |
|
281 | + $this->subTemplate = 'cms/images/form'; |
|
282 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_IMAGES; |
|
283 | + if (isset($_FILES[self::FILES_PARAMETER_FILE])) { |
|
284 | + $this->storage->addImage($_FILES[self::FILES_PARAMETER_FILE]); |
|
285 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/images'); |
|
286 | + exit; |
|
287 | + } |
|
288 | + } elseif ($relativeCmsUri == '/images/delete' && isset($request::$get[self::FILES_PARAMETER_FILE])) { |
|
289 | + $this->storage->deleteImageByName($request::$get[self::FILES_PARAMETER_FILE]); |
|
290 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/images'); |
|
291 | + exit; |
|
292 | + } elseif ($relativeCmsUri == '/images/show' && isset($request::$get[self::FILES_PARAMETER_FILE])) { |
|
293 | + $this->subTemplate = 'cms/images/show'; |
|
294 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_IMAGES; |
|
295 | + $this->parameters[self::PARAMETER_IMAGE] = $this->storage->getImageByName($request::$get[self::FILES_PARAMETER_FILE]); |
|
296 | + } |
|
297 | + } |
|
298 | + |
|
299 | + /** |
|
300 | + * @param $relativeCmsUri |
|
301 | + */ |
|
302 | + private function apiRouting($relativeCmsUri) |
|
303 | + { |
|
304 | + if ($relativeCmsUri == '/images.json') { |
|
305 | + header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
306 | + die(json_encode($this->storage->getImages())); |
|
307 | + } elseif ($relativeCmsUri == '/files.json') { |
|
308 | + header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
309 | + die(json_encode($this->storage->getFiles())); |
|
310 | + } elseif ($relativeCmsUri == '/documents.json') { |
|
311 | + header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
312 | + die(json_encode($this->storage->getDocuments())); |
|
313 | + } |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * @param $request |
|
318 | + * @param $relativeCmsUri |
|
319 | + */ |
|
320 | + private function filesRouting($request, $relativeCmsUri) |
|
321 | + { |
|
322 | + if ($relativeCmsUri == '/files') { |
|
323 | + $this->subTemplate = 'cms/files'; |
|
324 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_FILES; |
|
325 | + $this->parameters[self::PARAMETER_FILES] = $this->storage->getFiles(); |
|
326 | + } elseif ($relativeCmsUri == '/files/new') { |
|
327 | + $this->subTemplate = 'cms/files/form'; |
|
328 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_FILES; |
|
329 | + if (isset($_FILES[self::FILES_PARAMETER_FILE])) { |
|
330 | + $this->storage->addFile($_FILES[self::FILES_PARAMETER_FILE]); |
|
331 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/files'); |
|
332 | + exit; |
|
333 | + } |
|
334 | + } elseif ($relativeCmsUri == '/files/get' && isset($request::$get[self::FILES_PARAMETER_FILE])) { |
|
335 | + $this->downloadFile($request::$get[self::FILES_PARAMETER_FILE]); |
|
336 | + } elseif ($relativeCmsUri == '/files/delete' && isset($request::$get[self::FILES_PARAMETER_FILE])) { |
|
337 | + $this->storage->deleteFileByName($request::$get[self::FILES_PARAMETER_FILE]); |
|
338 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/files'); |
|
339 | + exit; |
|
340 | + } |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * @param $slug |
|
345 | + */ |
|
346 | + private function downloadFile($slug) |
|
347 | + { |
|
348 | + $file = $this->storage->getFileByName($slug); |
|
349 | + $path = realpath(__DIR__ . '/../../www/files/'); |
|
350 | + $quoted = sprintf('"%s"', addcslashes(basename($path . '/' . $file->file), '"\\')); |
|
351 | + $size = filesize($path . '/' . $file->file); |
|
352 | + |
|
353 | + header('Content-Description: File Transfer'); |
|
354 | + header('Content-Type: ' . $file->type); |
|
355 | + header('Content-Disposition: attachment; filename=' . $quoted); |
|
356 | + header('Content-Transfer-Encoding: binary'); |
|
357 | + header('Connection: Keep-Alive'); |
|
358 | + header('Expires: 0'); |
|
359 | + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
360 | + header('Pragma: public'); |
|
361 | + header('Content-Length: ' . $size); |
|
362 | + |
|
363 | + readfile($path . '/' . $file->file); |
|
364 | + exit; |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * @param $request |
|
369 | + * @param $relativeCmsUri |
|
370 | + */ |
|
371 | + private function configurationRouting($request, $relativeCmsUri) |
|
372 | + { |
|
373 | + if ($relativeCmsUri == '/configuration') { |
|
374 | + $this->subTemplate = 'cms/configuration'; |
|
375 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
376 | + } |
|
377 | + |
|
378 | + $this->usersRouting($request, $relativeCmsUri); |
|
379 | + $this->documentTypesRouting($request, $relativeCmsUri); |
|
380 | + $this->bricksRouting($request, $relativeCmsUri); |
|
381 | + $this->imageSetRouting($request, $relativeCmsUri); |
|
382 | + $this->applicationComponentRouting($request, $relativeCmsUri); |
|
383 | + } |
|
384 | + |
|
385 | + |
|
386 | + |
|
387 | + /** |
|
388 | + * @param $request |
|
389 | + * @param $relativeCmsUri |
|
390 | + */ |
|
391 | + private function usersRouting($request, $relativeCmsUri) |
|
392 | + { |
|
393 | + if ($relativeCmsUri == '/configuration/users') { |
|
394 | + $this->subTemplate = 'cms/configuration/users'; |
|
395 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
396 | + $this->parameters[self::PARAMETER_USERS] = $this->storage->getUsers(); |
|
397 | + } elseif ($relativeCmsUri == '/configuration/users/new') { |
|
398 | + $this->subTemplate = 'cms/configuration/users-form'; |
|
399 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
400 | + if (isset($_POST[self::POST_PARAMETER_USERNAME])) { |
|
401 | + $this->storage->addUser($request::$post); |
|
402 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/users'); |
|
403 | + exit; |
|
404 | + } |
|
405 | + } elseif ($relativeCmsUri == '/configuration/users/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
406 | + $this->storage->deleteUserBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
407 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/users'); |
|
408 | + exit; |
|
409 | + } elseif ($relativeCmsUri == '/configuration/users/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
410 | + $this->subTemplate = 'cms/configuration/users-form'; |
|
411 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
412 | + $this->parameters[self::PARAMETER_USER] = $this->storage->getUserBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
413 | + if (isset($_POST[self::POST_PARAMETER_USERNAME])) { |
|
414 | + $this->storage->saveUser($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
|
415 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/users'); |
|
416 | + exit; |
|
417 | + } |
|
418 | + } |
|
419 | + } |
|
420 | + |
|
421 | + /** |
|
422 | + * @param $request |
|
423 | + * @param $relativeCmsUri |
|
424 | + */ |
|
425 | + private function documentTypesRouting($request, $relativeCmsUri) |
|
426 | + { |
|
427 | + if ($relativeCmsUri == '/configuration/document-types') { |
|
428 | + $this->subTemplate = 'cms/configuration/document-types'; |
|
429 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
430 | + $this->parameters[self::PARAMETER_DOCUMENT_TYPES] = $this->storage->getDocumentTypes(); |
|
431 | + } elseif ($relativeCmsUri == '/configuration/document-types/new') { |
|
432 | + $this->subTemplate = 'cms/configuration/document-types-form'; |
|
433 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
434 | + $bricks = $this->storage->getBricks(); |
|
435 | + if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
436 | + $this->storage->addDocumentType($request::$post); |
|
437 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/document-types'); |
|
438 | + exit; |
|
439 | + } |
|
440 | + $this->parameters[self::PARAMETER_BRICKS] = $bricks; |
|
441 | + } elseif ($relativeCmsUri == '/configuration/document-types/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
442 | + $this->subTemplate = 'cms/configuration/document-types-form'; |
|
443 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
444 | + $documentType = $this->storage->getDocumentTypeBySlug($request::$get[self::GET_PARAMETER_SLUG], false); |
|
445 | + $bricks = $this->storage->getBricks(); |
|
446 | + if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
447 | + $this->storage->saveDocumentType($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
|
448 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/document-types'); |
|
449 | + exit; |
|
450 | + } |
|
451 | + $this->parameters[self::PARAMETER_DOCUMENT_TYPE] = $documentType; |
|
452 | + $this->parameters[self::PARAMETER_BRICKS] = $bricks; |
|
453 | + } elseif ($relativeCmsUri == '/configuration/document-types/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
454 | + $this->storage->deleteDocumentTypeBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
455 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/document-types'); |
|
456 | + exit; |
|
457 | + } |
|
458 | + } |
|
459 | + |
|
460 | + /** |
|
461 | + * @param $request |
|
462 | + * @param $relativeCmsUri |
|
463 | + */ |
|
464 | + private function bricksRouting($request, $relativeCmsUri) |
|
465 | + { |
|
466 | + if ($relativeCmsUri == '/configuration/bricks') { |
|
467 | + $this->subTemplate = 'cms/configuration/bricks'; |
|
468 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
469 | + $this->parameters[self::PARAMETER_BRICKS] = $this->storage->getBricks(); |
|
470 | + } elseif ($relativeCmsUri == '/configuration/bricks/new') { |
|
471 | + $this->subTemplate = 'cms/configuration/bricks-form'; |
|
472 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
473 | + if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
474 | + $this->storage->addBrick($request::$post); |
|
475 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/bricks'); |
|
476 | + exit; |
|
477 | + } |
|
478 | + } elseif ($relativeCmsUri == '/configuration/bricks/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
479 | + $this->subTemplate = 'cms/configuration/bricks-form'; |
|
480 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
481 | + $brick = $this->storage->getBrickBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
482 | + if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
483 | + $this->storage->saveBrick($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
|
484 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/bricks'); |
|
485 | + exit; |
|
486 | + } |
|
487 | + $this->parameters[self::PARAMETER_BRICK] = $brick; |
|
488 | + } elseif ($relativeCmsUri == '/configuration/bricks/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
489 | + $this->storage->deleteBrickBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
490 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/bricks'); |
|
491 | + exit; |
|
492 | + } elseif ($relativeCmsUri == '/configuration/image-set') { |
|
493 | + $this->subTemplate = 'cms/configuration/image-set'; |
|
494 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
495 | + $this->parameters[self::PARAMETER_IMAGE_SET] = $this->storage->getImageSet(); |
|
496 | + } |
|
497 | + } |
|
498 | + |
|
499 | + /** |
|
500 | + * @param $request |
|
501 | + * @param $relativeCmsUri |
|
502 | + */ |
|
503 | + private function imageSetRouting($request, $relativeCmsUri) |
|
504 | + { |
|
505 | + if ($relativeCmsUri == '/configuration/image-set') { |
|
506 | + $this->subTemplate = 'cms/configuration/image-set'; |
|
507 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
508 | + $this->parameters[self::PARAMETER_IMAGE_SET] = $this->storage->getImageSet(); |
|
509 | + } elseif ($relativeCmsUri == '/configuration/image-set/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
510 | + $this->subTemplate = 'cms/configuration/image-set-form'; |
|
511 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
512 | + $imageSet = $this->storage->getImageSetBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
513 | + if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
514 | + $this->storage->saveImageSet($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
|
515 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/image-set'); |
|
516 | + exit; |
|
517 | + } |
|
518 | + $this->parameters[self::PARAMETER_IMAGE_SET] = $imageSet; |
|
519 | + } elseif ($relativeCmsUri == '/configuration/image-set/new') { |
|
520 | + $this->subTemplate = 'cms/configuration/image-set-form'; |
|
521 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
522 | + if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
523 | + $this->storage->addImageSet($request::$post); |
|
524 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/image-set'); |
|
525 | + exit; |
|
526 | + } |
|
527 | + } elseif ($relativeCmsUri == '/configuration/image-set/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
528 | + $this->storage->deleteImageSetBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
529 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/image-set'); |
|
530 | + exit; |
|
531 | + } |
|
532 | + } |
|
533 | + |
|
534 | + /** |
|
535 | + * @param $request |
|
536 | + * @param $relativeCmsUri |
|
537 | + */ |
|
538 | + private function applicationComponentRouting($request, $relativeCmsUri) |
|
539 | + { |
|
540 | + if ($relativeCmsUri == '/configuration/application-components') { |
|
541 | + $this->subTemplate = 'cms/configuration/application-components'; |
|
542 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
543 | + $this->parameters['applicationComponents'] = $this->storage->getApplicationComponents(); |
|
544 | + } elseif ($relativeCmsUri == '/configuration/application-components/new') { |
|
545 | + $this->subTemplate = 'cms/configuration/application-components-form'; |
|
546 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
547 | + if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
548 | + $this->storage->addApplicationComponent($request::$post); |
|
549 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/application-components'); |
|
550 | + exit; |
|
551 | + } |
|
552 | + } elseif ($relativeCmsUri == '/configuration/application-components/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
553 | + $this->subTemplate = 'cms/configuration/application-components-form'; |
|
554 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
555 | + $applicationComponent = $this->storage->getApplicationComponentBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
556 | + if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
557 | + $this->storage->saveApplicationComponent($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
|
558 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/application-components'); |
|
559 | + exit; |
|
560 | + } |
|
561 | + $this->parameters['applicationComponent'] = $applicationComponent; |
|
562 | + } elseif ($relativeCmsUri == '/configuration/application-components/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
563 | + $this->storage->deleteApplicationComponentBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
564 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/application-components'); |
|
565 | + exit; |
|
566 | + } |
|
567 | + } |
|
568 | + |
|
569 | + private function logOffRouting($request, $relativeCmsUri) |
|
570 | + { |
|
571 | + if ($relativeCmsUri == '/log-off') { |
|
572 | + $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = null; |
|
573 | + unset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]); |
|
574 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX]); |
|
575 | + exit; |
|
576 | + } |
|
577 | + } |
|
578 | + |
|
579 | + public function setParameter($parameterName, $parameterValue) |
|
580 | + { |
|
581 | + $this->parameters[$parameterName] = $parameterValue; |
|
582 | + } |
|
583 | + |
|
584 | + public function getParameter($parameterName) |
|
585 | + { |
|
586 | + return $this->parameters[$parameterName]; |
|
587 | + } |
|
588 | + } |
|
589 | 589 | } |
590 | 590 | \ No newline at end of file |