@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | } |
| 44 | 44 | return $returnFileNames; |
| 45 | 45 | } else { |
| 46 | - throw new \Exception('Image doesnt exist: ' . $imagePath); |
|
| 46 | + throw new \Exception('Image doesnt exist: '.$imagePath); |
|
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | |
@@ -54,10 +54,10 @@ discard block |
||
| 54 | 54 | * @return string |
| 55 | 55 | * @throws \Exception |
| 56 | 56 | */ |
| 57 | - public function resize($imagePath='', $width='',$height='') |
|
| 57 | + public function resize($imagePath = '', $width = '', $height = '') |
|
| 58 | 58 | { |
| 59 | - $modifier = '-r' . $width . 'x' . $height; |
|
| 60 | - return $this->applyMethod('Resize', $imagePath, $width,$height, $modifier); |
|
| 59 | + $modifier = '-r'.$width.'x'.$height; |
|
| 60 | + return $this->applyMethod('Resize', $imagePath, $width, $height, $modifier); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -67,10 +67,10 @@ discard block |
||
| 67 | 67 | * @return string |
| 68 | 68 | * @throws \Exception |
| 69 | 69 | */ |
| 70 | - public function smartcrop($imagePath='', $width='',$height='') |
|
| 70 | + public function smartcrop($imagePath = '', $width = '', $height = '') |
|
| 71 | 71 | { |
| 72 | - $modifier = '-s' . $width . 'x' . $height; |
|
| 73 | - return $this->applyMethod('SmartCrop', $imagePath, $width,$height, $modifier); |
|
| 72 | + $modifier = '-s'.$width.'x'.$height; |
|
| 73 | + return $this->applyMethod('SmartCrop', $imagePath, $width, $height, $modifier); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -80,10 +80,10 @@ discard block |
||
| 80 | 80 | * @return string |
| 81 | 81 | * @throws \Exception |
| 82 | 82 | */ |
| 83 | - public function boxcrop($imagePath='', $width='',$height='') |
|
| 83 | + public function boxcrop($imagePath = '', $width = '', $height = '') |
|
| 84 | 84 | { |
| 85 | - $modifier = '-b' . $width . 'x' . $height; |
|
| 86 | - return $this->applyMethod('BoxCrop', $imagePath, $width,$height, $modifier); |
|
| 85 | + $modifier = '-b'.$width.'x'.$height; |
|
| 86 | + return $this->applyMethod('BoxCrop', $imagePath, $width, $height, $modifier); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | * |
| 93 | 93 | * @return string |
| 94 | 94 | */ |
| 95 | - private function modifyName($imagePath, $modifier='') |
|
| 95 | + private function modifyName($imagePath, $modifier = '') |
|
| 96 | 96 | { |
| 97 | 97 | $filename = basename($imagePath); |
| 98 | 98 | $path = dirname($imagePath); |
@@ -102,30 +102,30 @@ discard block |
||
| 102 | 102 | array_pop($fileParts); |
| 103 | 103 | $fileNameWithoutExtension = implode('-', $fileParts); |
| 104 | 104 | $fileNameWithoutExtension = slugify($fileNameWithoutExtension); |
| 105 | - $filename = $fileNameWithoutExtension . $modifier . '.' . $extension; |
|
| 105 | + $filename = $fileNameWithoutExtension.$modifier.'.'.$extension; |
|
| 106 | 106 | } else { |
| 107 | 107 | $filename = slugify($filename); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - if (file_exists($path . '/' . $filename)) { |
|
| 110 | + if (file_exists($path.'/'.$filename)) { |
|
| 111 | 111 | $fileParts = explode('.', $filename); |
| 112 | 112 | if (count($fileParts) > 1) { |
| 113 | 113 | $extension = end($fileParts); |
| 114 | 114 | array_pop($fileParts); |
| 115 | 115 | $fileNameWithoutExtension = implode('-', $fileParts); |
| 116 | 116 | $fileNameWithoutExtension .= '-copy'; |
| 117 | - $filename = $fileNameWithoutExtension . '.' . $extension; |
|
| 117 | + $filename = $fileNameWithoutExtension.'.'.$extension; |
|
| 118 | 118 | } else { |
| 119 | 119 | $filename .= '-copy'; |
| 120 | 120 | } |
| 121 | - return $this->modifyName($path . '/' . $filename); |
|
| 121 | + return $this->modifyName($path.'/'.$filename); |
|
| 122 | 122 | } |
| 123 | - return $path . '/' . $filename; |
|
| 123 | + return $path.'/'.$filename; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | private function applyMethod($method, $imagePath, $width, $height, $modifier) |
| 127 | 127 | { |
| 128 | - $method = 'library\\images\\methods\\' . $method; |
|
| 128 | + $method = 'library\\images\\methods\\'.$method; |
|
| 129 | 129 | $destination = $this->modifyName($imagePath, $modifier); |
| 130 | 130 | if (file_exists($imagePath)) { |
| 131 | 131 | $image = new Image(); |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | $resizedImage->SaveImage($destination, $resizedImage->GetImageMimeType($imagePath), 80); |
| 140 | 140 | return basename($destination); |
| 141 | 141 | } else { |
| 142 | - throw new \Exception('Image doesnt exist: ' . $imagePath); |
|
| 142 | + throw new \Exception('Image doesnt exist: '.$imagePath); |
|
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | 145 | } |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | unset($request::$get['path']); |
| 81 | 81 | } |
| 82 | 82 | if ($this->isFormSubmitted($this->request)) { |
| 83 | - $this->parameters[$this->formParameterName] = '<a name="' . $this->formId . '"></a>' . $this->thankYouMessage; |
|
| 83 | + $this->parameters[$this->formParameterName] = '<a name="'.$this->formId.'"></a>'.$this->thankYouMessage; |
|
| 84 | 84 | } else { |
| 85 | 85 | $this->parameters[$this->formParameterName] = $form; |
| 86 | 86 | } |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | $postValues = $request::$post; |
| 198 | 198 | $postValues['documentType'] = $this->documentType; |
| 199 | 199 | $postValues['path'] = $this->responseFolder; |
| 200 | - $postValues['title'] = date('r') . ' - From: ' . $request::$requestUri; |
|
| 200 | + $postValues['title'] = date('r').' - From: '.$request::$requestUri; |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | |
| 133 | 133 | /** |
| 134 | 134 | * Sets variables needed for rendering the form template |
| 135 | - * @param $storage |
|
| 135 | + * @param Storage $storage |
|
| 136 | 136 | */ |
| 137 | 137 | private function initialize($storage) |
| 138 | 138 | { |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | * submitting the form |
| 169 | 169 | * |
| 170 | 170 | * @param $postValues |
| 171 | - * @param $storage |
|
| 171 | + * @param Storage $storage |
|
| 172 | 172 | */ |
| 173 | 173 | protected function postSubmit($postValues, $storage) |
| 174 | 174 | {} |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | /** |
| 192 | 192 | * Checks if this form has been submitted |
| 193 | 193 | * |
| 194 | - * @param $request |
|
| 194 | + * @param \library\cc\Request $request |
|
| 195 | 195 | * @return bool |
| 196 | 196 | */ |
| 197 | 197 | private function isFormSubmitted($request) |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | /** |
| 203 | 203 | * |
| 204 | 204 | * |
| 205 | - * @param $request |
|
| 205 | + * @param \library\cc\Request $request |
|
| 206 | 206 | */ |
| 207 | 207 | private function getPostValues($request) |
| 208 | 208 | { |
@@ -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 |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | $error = error_get_last(); |
| 34 | 34 | if (isset($error['type'], $error['message'], $error['file'], $error['line'])) { |
| 35 | 35 | errorHandler($error['type'],$error['message'],$error['file'],$error['line']); |
| 36 | - }elseif ($error['type'] == 1) { |
|
| 36 | + } elseif ($error['type'] == 1) { |
|
| 37 | 37 | dump($error); |
| 38 | 38 | } |
| 39 | 39 | } |
@@ -85,7 +85,9 @@ discard block |
||
| 85 | 85 | * @param string $httpHeader |
| 86 | 86 | */ |
| 87 | 87 | function renderError ($message='', $file='', $line='', $code=0, $trace=array(), $httpHeader = 'HTTP/1.0 500 Internal Server Error') { |
| 88 | - if (ob_get_contents()) ob_end_clean(); |
|
| 88 | + if (ob_get_contents()) { |
|
| 89 | + ob_end_clean(); |
|
| 90 | + } |
|
| 89 | 91 | header($_SERVER['SERVER_PROTOCOL'] . $httpHeader, true); |
| 90 | 92 | header('X-Error-Message: ' . $message); |
| 91 | 93 | header('X-Error-File: ' . $file); |
@@ -149,6 +149,11 @@ |
||
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | +/** |
|
| 153 | + * @param string $message |
|
| 154 | + * @param string $file |
|
| 155 | + * @param integer $code |
|
| 156 | + */ |
|
| 152 | 157 | function renderCliException($message, $file, $line, $code, $trace, $lines) |
| 153 | 158 | { |
| 154 | 159 | echo PHP_EOL; |
@@ -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 |
@@ -9,8 +9,8 @@ discard block |
||
| 9 | 9 | * |
| 10 | 10 | * @param $e |
| 11 | 11 | */ |
| 12 | -function exceptionHandler ($e) { |
|
| 13 | - renderError($e->getMessage(),$e->getFile(),$e->getLine(),$e->getCode(),$e->getTrace()); |
|
| 12 | +function exceptionHandler($e) { |
|
| 13 | + renderError($e->getMessage(), $e->getFile(), $e->getLine(), $e->getCode(), $e->getTrace()); |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | /** |
@@ -21,18 +21,18 @@ discard block |
||
| 21 | 21 | * @param $errfile |
| 22 | 22 | * @param $errline |
| 23 | 23 | */ |
| 24 | -function errorHandler ($errno, $errstr, $errfile, $errline) { |
|
| 25 | - renderError($errstr,$errfile,$errline,$errno,debug_backtrace()); |
|
| 24 | +function errorHandler($errno, $errstr, $errfile, $errline) { |
|
| 25 | + renderError($errstr, $errfile, $errline, $errno, debug_backtrace()); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * When an error occurs that kills the process, still try |
| 30 | 30 | * to show it using a shutdownHandler. |
| 31 | 31 | */ |
| 32 | -function shutdownHandler () { |
|
| 32 | +function shutdownHandler() { |
|
| 33 | 33 | $error = error_get_last(); |
| 34 | 34 | if (isset($error['type'], $error['message'], $error['file'], $error['line'])) { |
| 35 | - errorHandler($error['type'],$error['message'],$error['file'],$error['line']); |
|
| 35 | + errorHandler($error['type'], $error['message'], $error['file'], $error['line']); |
|
| 36 | 36 | }elseif ($error['type'] == 1) { |
| 37 | 37 | dump($error); |
| 38 | 38 | } |
@@ -50,28 +50,28 @@ discard block |
||
| 50 | 50 | $errstr = ''; |
| 51 | 51 | switch ($jsonErrorNr) { |
| 52 | 52 | case JSON_ERROR_NONE: |
| 53 | - $errstr .= ' - No errors' . PHP_EOL; |
|
| 53 | + $errstr .= ' - No errors'.PHP_EOL; |
|
| 54 | 54 | break; |
| 55 | 55 | case JSON_ERROR_DEPTH: |
| 56 | - $errstr .= ' - Maximum stack depth exceeded' . PHP_EOL; |
|
| 56 | + $errstr .= ' - Maximum stack depth exceeded'.PHP_EOL; |
|
| 57 | 57 | break; |
| 58 | 58 | case JSON_ERROR_STATE_MISMATCH: |
| 59 | - $errstr .= ' - Underflow or the modes mismatch' . PHP_EOL; |
|
| 59 | + $errstr .= ' - Underflow or the modes mismatch'.PHP_EOL; |
|
| 60 | 60 | break; |
| 61 | 61 | case JSON_ERROR_CTRL_CHAR: |
| 62 | - $errstr .= ' - Unexpected control character found' . PHP_EOL; |
|
| 62 | + $errstr .= ' - Unexpected control character found'.PHP_EOL; |
|
| 63 | 63 | break; |
| 64 | 64 | case JSON_ERROR_SYNTAX: |
| 65 | - $errstr .= ' - Syntax error, malformed JSON' . PHP_EOL; |
|
| 65 | + $errstr .= ' - Syntax error, malformed JSON'.PHP_EOL; |
|
| 66 | 66 | break; |
| 67 | 67 | case JSON_ERROR_UTF8: |
| 68 | - $errstr .= ' - Malformed UTF-8 characters, possibly incorrectly encoded' . PHP_EOL; |
|
| 68 | + $errstr .= ' - Malformed UTF-8 characters, possibly incorrectly encoded'.PHP_EOL; |
|
| 69 | 69 | break; |
| 70 | 70 | default: |
| 71 | - $errstr = ' - Unknown error' . PHP_EOL; |
|
| 71 | + $errstr = ' - Unknown error'.PHP_EOL; |
|
| 72 | 72 | break; |
| 73 | 73 | } |
| 74 | - errorHandler ($jsonErrorNr, $errstr, $file, $line); |
|
| 74 | + errorHandler($jsonErrorNr, $errstr, $file, $line); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | * @param array $trace |
| 85 | 85 | * @param string $httpHeader |
| 86 | 86 | */ |
| 87 | -function renderError ($message='', $file='', $line='', $code=0, $trace=array(), $httpHeader = 'HTTP/1.0 500 Internal Server Error') { |
|
| 87 | +function renderError($message = '', $file = '', $line = '', $code = 0, $trace = array(), $httpHeader = 'HTTP/1.0 500 Internal Server Error') { |
|
| 88 | 88 | if (ob_get_contents()) ob_end_clean(); |
| 89 | 89 | |
| 90 | 90 | if (canShowError()) { |
@@ -93,8 +93,8 @@ discard block |
||
| 93 | 93 | $lines = array(); |
| 94 | 94 | |
| 95 | 95 | foreach ($range as $line_number) { |
| 96 | - if(isset($file_lines[$line_number-1])) { |
|
| 97 | - $lines[$line_number] = $file_lines[$line_number-1]; |
|
| 96 | + if (isset($file_lines[$line_number - 1])) { |
|
| 97 | + $lines[$line_number] = $file_lines[$line_number - 1]; |
|
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | |
@@ -112,20 +112,20 @@ discard block |
||
| 112 | 112 | renderCliException($message, $file, $line, $code, $trace, $lines); |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - if (file_exists(realpath(__DIR__) . '/errorviewdetailed.php')) { |
|
| 116 | - include(realpath(__DIR__) . '/errorviewdetailed.php'); |
|
| 115 | + if (file_exists(realpath(__DIR__).'/errorviewdetailed.php')) { |
|
| 116 | + include(realpath(__DIR__).'/errorviewdetailed.php'); |
|
| 117 | 117 | } else { |
| 118 | 118 | header('Content-type: application/json'); |
| 119 | 119 | die(json_encode($error)); |
| 120 | 120 | } |
| 121 | 121 | exit; |
| 122 | 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'); |
|
| 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 | 129 | } else { |
| 130 | 130 | header('Content-type: application/json'); |
| 131 | 131 | die(json_encode('An error occured.')); |
@@ -152,35 +152,35 @@ discard block |
||
| 152 | 152 | function renderCliException($message, $file, $line, $code, $trace, $lines) |
| 153 | 153 | { |
| 154 | 154 | echo PHP_EOL; |
| 155 | - echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
| 156 | - echo '| THE FOLLOWING ERROR OCCURED |' . PHP_EOL; |
|
| 157 | - echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
| 155 | + echo '------------------------------------------------------------------------------------------------------------------------------------------------'.PHP_EOL; |
|
| 156 | + echo '| THE FOLLOWING ERROR OCCURED |'.PHP_EOL; |
|
| 157 | + echo '------------------------------------------------------------------------------------------------------------------------------------------------'.PHP_EOL; |
|
| 158 | 158 | echo PHP_EOL; |
| 159 | - echo ' ' . $message . PHP_EOL; |
|
| 159 | + echo ' '.$message.PHP_EOL; |
|
| 160 | 160 | echo PHP_EOL; |
| 161 | - echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
| 162 | - echo '| IN FILE |' . PHP_EOL; |
|
| 163 | - echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
| 161 | + echo '------------------------------------------------------------------------------------------------------------------------------------------------'.PHP_EOL; |
|
| 162 | + echo '| IN FILE |'.PHP_EOL; |
|
| 163 | + echo '------------------------------------------------------------------------------------------------------------------------------------------------'.PHP_EOL; |
|
| 164 | 164 | echo PHP_EOL; |
| 165 | - echo ' ' . $file . ':' . $line . PHP_EOL; |
|
| 165 | + echo ' '.$file.':'.$line.PHP_EOL; |
|
| 166 | 166 | echo PHP_EOL; |
| 167 | - echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
| 168 | - echo '| CONTENTS OF THE FILE |' . PHP_EOL; |
|
| 169 | - echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
| 167 | + echo '------------------------------------------------------------------------------------------------------------------------------------------------'.PHP_EOL; |
|
| 168 | + echo '| CONTENTS OF THE FILE |'.PHP_EOL; |
|
| 169 | + echo '------------------------------------------------------------------------------------------------------------------------------------------------'.PHP_EOL; |
|
| 170 | 170 | echo PHP_EOL; |
| 171 | - foreach($lines as $nr => $currentLine) { |
|
| 172 | - echo ($nr == $line ? '* ' : ' ' ) . str_pad($nr, 3, "0", STR_PAD_LEFT) . ' ' . $currentLine; |
|
| 171 | + foreach ($lines as $nr => $currentLine) { |
|
| 172 | + echo ($nr == $line ? '* ' : ' ').str_pad($nr, 3, "0", STR_PAD_LEFT).' '.$currentLine; |
|
| 173 | 173 | } |
| 174 | 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; |
|
| 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 | 184 | } |
| 185 | 185 | exit; |
| 186 | 186 | } |
| 187 | 187 | \ No newline at end of file |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | private function config() |
| 67 | 67 | { |
| 68 | - $configPath = __DIR__ . '/../../config.json'; |
|
| 68 | + $configPath = __DIR__.'/../../config.json'; |
|
| 69 | 69 | if (realpath($configPath) !== false) { |
| 70 | 70 | $json = file_get_contents($configPath); |
| 71 | 71 | $this->config = json_decode($json); |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | private function sitemapMatching($request) |
| 95 | 95 | { |
| 96 | 96 | $sitemap = $this->storage->getSitemap(); |
| 97 | - $relativeUri = '/' . $request::$relativeUri; |
|
| 97 | + $relativeUri = '/'.$request::$relativeUri; |
|
| 98 | 98 | |
| 99 | 99 | foreach ($sitemap as $sitemapItem) { |
| 100 | 100 | if ($sitemapItem->regex) { |
@@ -157,17 +157,17 @@ discard block |
||
| 157 | 157 | * @return mixed |
| 158 | 158 | * @throws \Exception |
| 159 | 159 | */ |
| 160 | - private function getComponentObject($class='', $template='', $parameters=array(), $matchedSitemapItem) |
|
| 160 | + private function getComponentObject($class = '', $template = '', $parameters = array(), $matchedSitemapItem) |
|
| 161 | 161 | { |
| 162 | - $libraryComponentName = '\\library\\components\\' . $class; |
|
| 163 | - $userComponentName = '\\components\\' . $class; |
|
| 162 | + $libraryComponentName = '\\library\\components\\'.$class; |
|
| 163 | + $userComponentName = '\\components\\'.$class; |
|
| 164 | 164 | |
| 165 | 165 | if (\autoLoad($libraryComponentName, false)) { |
| 166 | 166 | $component = new $libraryComponentName($template, $this->request, $parameters, $matchedSitemapItem); |
| 167 | 167 | } elseif (\autoLoad($userComponentName, false)) { |
| 168 | 168 | $component = new $userComponentName($template, $this->request, $parameters, $matchedSitemapItem); |
| 169 | 169 | } else { |
| 170 | - throw new \Exception('Could not load component ' . $class); |
|
| 170 | + throw new \Exception('Could not load component '.$class); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | if (!$component instanceof Component) { |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | public function setCachingHeaders() |
| 227 | 227 | { |
| 228 | 228 | header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60 * 24 * 2))); // 2 days |
| 229 | - header("Cache-Control: max-age=" . (60 * 60 * 24 * 2)); |
|
| 229 | + header("Cache-Control: max-age=".(60 * 60 * 24 * 2)); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -47,21 +47,21 @@ |
||
| 47 | 47 | { |
| 48 | 48 | global $rootPath; |
| 49 | 49 | |
| 50 | - self::$subfolders = '/' . str_replace('//', '/', str_replace(str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']), "", $rootPath)); |
|
| 50 | + self::$subfolders = '/'.str_replace('//', '/', str_replace(str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']), "", $rootPath)); |
|
| 51 | 51 | self::$subfolders = str_replace('//', '/', self::$subfolders); |
| 52 | 52 | if (PHP_SAPI === 'cli') { |
| 53 | 53 | global $argv; |
| 54 | 54 | array_shift($argv); |
| 55 | 55 | self::$queryString = ''; |
| 56 | - self::$requestUri = self::$subfolders . implode('/', $argv); |
|
| 56 | + self::$requestUri = self::$subfolders.implode('/', $argv); |
|
| 57 | 57 | } else { |
| 58 | 58 | self::$requestUri = $_SERVER['REQUEST_URI']; |
| 59 | 59 | self::$queryString = $_SERVER['QUERY_STRING']; |
| 60 | 60 | } |
| 61 | 61 | if (self::$subfolders === '/') { |
| 62 | - self::$relativeUri = str_replace('?' . self::$queryString, '', substr(self::$requestUri,1)); |
|
| 62 | + self::$relativeUri = str_replace('?'.self::$queryString, '', substr(self::$requestUri, 1)); |
|
| 63 | 63 | } else { |
| 64 | - self::$relativeUri = str_replace('?' . self::$queryString, '', str_replace(self::$subfolders, '', self::$requestUri)); |
|
| 64 | + self::$relativeUri = str_replace('?'.self::$queryString, '', str_replace(self::$subfolders, '', self::$requestUri)); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | self::$requestParameters = explode('/', self::$relativeUri); |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<form method="<?= isset($documentType) ? 'post' : 'get' ?>" onsubmit="return processRtes();" action="<?=isset($formId) ? '#' . $formId : '' ?>"> |
|
| 1 | +<form method="<?= isset($documentType) ? 'post' : 'get' ?>" onsubmit="return processRtes();" action="<?=isset($formId) ? '#'.$formId : '' ?>"> |
|
| 2 | 2 | <? if (!isset($hideTitleAndState)) : ?> |
| 3 | 3 | <input type="hidden" name="path" value="<?=$request::$get['path']?>" /> |
| 4 | 4 | <? else : ?> |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | <input<?=isset($document) && $document->state == 'published' ? ' checked="checked"' : '' ?> type="checkbox" id="state" name="state" placeholder="State" /> |
| 21 | 21 | </div> |
| 22 | 22 | <? endif ?> |
| 23 | - <?$fieldPrefix='fields';?> |
|
| 23 | + <?$fieldPrefix = 'fields'; ?> |
|
| 24 | 24 | <? foreach ($documentType->fields as $field) : ?> |
| 25 | 25 | <div class="form-element"> |
| 26 | 26 | <label for="<?=$field->slug?>"><?=$field->title?></label> |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | <a class="btn move ui-sortable-handle"><i class="fa fa-arrows-v"></i></a> |
| 45 | 45 | <div class="form-element"> |
| 46 | 46 | <? endif ?> |
| 47 | - <? include(__DIR__ . '/fieldTypes/' . str_replace(' ', '-', $field->type) . '.php') ?> |
|
| 47 | + <? include(__DIR__.'/fieldTypes/'.str_replace(' ', '-', $field->type).'.php') ?> |
|
| 48 | 48 | <? if ($field->multiple == true && $field->type != 'Rich Text') : ?> |
| 49 | 49 | |
| 50 | 50 | </div> |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | <li class="grid-container"> |
| 67 | 67 | <div class="grid-box-10"> |
| 68 | 68 | <div class="grid-inner form-element"> |
| 69 | - <? include(__DIR__ . '/fieldTypes/' . str_replace(' ', '-', $field->type) . '.php') ?> |
|
| 69 | + <? include(__DIR__.'/fieldTypes/'.str_replace(' ', '-', $field->type).'.php') ?> |
|
| 70 | 70 | </div> |
| 71 | 71 | </div> |
| 72 | 72 | <div class="grid-box-2"> |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | </div> |
| 77 | 77 | </div> |
| 78 | 78 | </li> |
| 79 | - <?$value='';?> |
|
| 79 | + <?$value = ''; ?> |
|
| 80 | 80 | <? endforeach ?> |
| 81 | 81 | <? endif ?> |
| 82 | 82 | </ul> |
@@ -93,10 +93,10 @@ discard block |
||
| 93 | 93 | <a class="btn error js-deletemultiple"><i class="fa fa-times"></i></a> |
| 94 | 94 | <a class="btn move ui-sortable-handle"><i class="fa fa-arrows-v"></i></a> |
| 95 | 95 | <div class="form-element"> |
| 96 | - <? include(__DIR__ . '/fieldTypes/' . str_replace(' ', '-', $field->type) . '.php') ?> |
|
| 96 | + <? include(__DIR__.'/fieldTypes/'.str_replace(' ', '-', $field->type).'.php') ?> |
|
| 97 | 97 | </div> |
| 98 | 98 | </li> |
| 99 | - <?$value='';?> |
|
| 99 | + <?$value = ''; ?> |
|
| 100 | 100 | <? endforeach ?> |
| 101 | 101 | <? endif ?> |
| 102 | 102 | </div> |
@@ -105,17 +105,17 @@ discard block |
||
| 105 | 105 | <a class="btn js-addrtemultiple">+</a> |
| 106 | 106 | <? endif ?> |
| 107 | 107 | </div> |
| 108 | - <?$value='';?> |
|
| 108 | + <?$value = ''; ?> |
|
| 109 | 109 | <? endforeach ?> |
| 110 | 110 | <hr /> |
| 111 | - <? $static_brick_nr = 0;?> |
|
| 111 | + <? $static_brick_nr = 0; ?> |
|
| 112 | 112 | <? foreach ($documentType->bricks as $brick) : ?> |
| 113 | 113 | <div class="brick"> |
| 114 | 114 | <label><?=$brick->title?></label> |
| 115 | 115 | <? if ($brick->multiple == 'true') : ?> |
| 116 | 116 | <input type="hidden" value="<?=$brick->brickSlug?>"/> |
| 117 | 117 | <input type="hidden" value="<?=$brick->slug?>"/> |
| 118 | - <?$myBrickSlug=$brick->slug;?> |
|
| 118 | + <?$myBrickSlug = $brick->slug; ?> |
|
| 119 | 119 | <ul id="newBrickDropzone_<?=$static_brick_nr?>" class="dynamicBricks sortable"> |
| 120 | 120 | <? if (isset($document)) : ?> |
| 121 | 121 | <? foreach ($document->bricks as $currentBrickSlug => $brickArray) : ?> |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | <li class="brick form-element"> |
| 130 | 130 | <label><?=$brick->title?></label> |
| 131 | 131 | <?$static = true; ?> |
| 132 | - <?include(__DIR__ . '/brick.php')?> |
|
| 132 | + <?include(__DIR__.'/brick.php')?> |
|
| 133 | 133 | </li> |
| 134 | 134 | <? endif ?> |
| 135 | 135 | <? endforeach ?> |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | <a class="btn" onclick="addDynamicBrick(this, 'true', 'newBrickDropzone_<?=$static_brick_nr?>');">+</a> |
| 140 | 140 | <?$static_brick_nr += 1?> |
| 141 | 141 | <? else : ?> |
| 142 | - <?$fieldPrefix='bricks[' . $brick->slug . '][fields]';?> |
|
| 142 | + <?$fieldPrefix = 'bricks['.$brick->slug.'][fields]'; ?> |
|
| 143 | 143 | <input type="hidden" name="bricks[<?=$brick->slug?>][type]" value="<?=$brick->brickSlug?>" /> |
| 144 | 144 | <? foreach ($brick->structure->fields as $field) : ?> |
| 145 | 145 | <div class="form-element"> |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | <a class="btn move ui-sortable-handle"><i class="fa fa-arrows-v"></i></a> |
| 166 | 166 | <div class="form-element"> |
| 167 | 167 | <? endif ?> |
| 168 | - <? include(__DIR__ . '/fieldTypes/' . str_replace(' ', '-', $field->type) . '.php') ?> |
|
| 168 | + <? include(__DIR__.'/fieldTypes/'.str_replace(' ', '-', $field->type).'.php') ?> |
|
| 169 | 169 | <? if ($field->multiple == true && $field->type != 'Rich Text') : ?> |
| 170 | 170 | |
| 171 | 171 | </div> |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | <li class="grid-container"> |
| 189 | 189 | <div class="grid-box-10"> |
| 190 | 190 | <div class="grid-inner form-element"> |
| 191 | - <? include(__DIR__ . '/fieldTypes/' . str_replace(' ', '-', $field->type) . '.php') ?> |
|
| 191 | + <? include(__DIR__.'/fieldTypes/'.str_replace(' ', '-', $field->type).'.php') ?> |
|
| 192 | 192 | </div> |
| 193 | 193 | </div> |
| 194 | 194 | <div class="grid-box-2"> |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | </div> |
| 199 | 199 | </div> |
| 200 | 200 | </li> |
| 201 | - <?$value='';?> |
|
| 201 | + <?$value = ''; ?> |
|
| 202 | 202 | <? endforeach ?> |
| 203 | 203 | <? endif ?> |
| 204 | 204 | </ul> |
@@ -216,10 +216,10 @@ discard block |
||
| 216 | 216 | <a class="btn error js-deletemultiple"><i class="fa fa-times"></i></a> |
| 217 | 217 | <a class="btn move ui-sortable-handle"><i class="fa fa-arrows-v"></i></a> |
| 218 | 218 | <div class="form-element"> |
| 219 | - <? include(__DIR__ . '/fieldTypes/' . str_replace(' ', '-', $field->type) . '.php') ?> |
|
| 219 | + <? include(__DIR__.'/fieldTypes/'.str_replace(' ', '-', $field->type).'.php') ?> |
|
| 220 | 220 | </div> |
| 221 | 221 | </li> |
| 222 | - <?$value='';?> |
|
| 222 | + <?$value = ''; ?> |
|
| 223 | 223 | <? endforeach ?> |
| 224 | 224 | <? endif ?> |
| 225 | 225 | </div> |
@@ -228,12 +228,12 @@ discard block |
||
| 228 | 228 | <a class="btn js-addrtemultiple">+</a> |
| 229 | 229 | <? endif ?> |
| 230 | 230 | </div> |
| 231 | - <?$value='';?> |
|
| 231 | + <?$value = ''; ?> |
|
| 232 | 232 | <? endforeach ?> |
| 233 | 233 | <? endif ?> |
| 234 | 234 | </div> |
| 235 | 235 | <hr /> |
| 236 | - <? endforeach;?> |
|
| 236 | + <? endforeach; ?> |
|
| 237 | 237 | |
| 238 | 238 | |
| 239 | 239 | |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | <li class="brick form-element"> |
| 257 | 257 | <label><?=$brick->title?></label> |
| 258 | 258 | <?$static = false; ?> |
| 259 | - <?include(__DIR__ . '/brick.php')?> |
|
| 259 | + <?include(__DIR__.'/brick.php')?> |
|
| 260 | 260 | </li> |
| 261 | 261 | <? endforeach ?> |
| 262 | 262 | <? endif ?> |
@@ -1,7 +1,8 @@ discard block |
||
| 1 | 1 | <form method="<?= isset($documentType) ? 'post' : 'get' ?>" onsubmit="return processRtes();" action="<?=isset($formId) ? '#' . $formId : '' ?>"> |
| 2 | 2 | <? if (!isset($hideTitleAndState)) : ?> |
| 3 | 3 | <input type="hidden" name="path" value="<?=$request::$get['path']?>" /> |
| 4 | - <? else : ?> |
|
| 4 | + <? else { |
|
| 5 | + : ?> |
|
| 5 | 6 | <input type="hidden" name="formId" value="<?=$formId?>" /> |
| 6 | 7 | <a name="<?=$formId?>"></a> |
| 7 | 8 | <? endif ?> |
@@ -20,15 +21,19 @@ discard block |
||
| 20 | 21 | <input<?=isset($document) && $document->state == 'published' ? ' checked="checked"' : '' ?> type="checkbox" id="state" name="state" placeholder="State" /> |
| 21 | 22 | </div> |
| 22 | 23 | <? endif ?> |
| 23 | - <?$fieldPrefix='fields';?> |
|
| 24 | + <?$fieldPrefix='fields'; |
|
| 25 | +} |
|
| 26 | +?> |
|
| 24 | 27 | <? foreach ($documentType->fields as $field) : ?> |
| 25 | 28 | <div class="form-element"> |
| 26 | 29 | <label for="<?=$field->slug?>"><?=$field->title?></label> |
| 27 | 30 | <? if (isset($document)) : |
| 28 | 31 | $fieldSlug = $field->slug; |
| 29 | 32 | $value = isset($document->fields->$fieldSlug) ? current($document->fields->$fieldSlug) : ''; |
| 30 | - else : |
|
| 33 | + else { |
|
| 34 | + : |
|
| 31 | 35 | $value = ''; |
| 36 | + } |
|
| 32 | 37 | endif ?> |
| 33 | 38 | <? if ($field->multiple == true && $field->type != 'Rich Text') : ?> |
| 34 | 39 | <ul class="grid-wrapper sortable"> |
@@ -138,8 +143,11 @@ discard block |
||
| 138 | 143 | </ul> |
| 139 | 144 | <a class="btn" onclick="addDynamicBrick(this, 'true', 'newBrickDropzone_<?=$static_brick_nr?>');">+</a> |
| 140 | 145 | <?$static_brick_nr += 1?> |
| 141 | - <? else : ?> |
|
| 142 | - <?$fieldPrefix='bricks[' . $brick->slug . '][fields]';?> |
|
| 146 | + <? else { |
|
| 147 | + : ?> |
|
| 148 | + <?$fieldPrefix='bricks[' . $brick->slug . '][fields]'; |
|
| 149 | +} |
|
| 150 | +?> |
|
| 143 | 151 | <input type="hidden" name="bricks[<?=$brick->slug?>][type]" value="<?=$brick->brickSlug?>" /> |
| 144 | 152 | <? foreach ($brick->structure->fields as $field) : ?> |
| 145 | 153 | <div class="form-element"> |
@@ -148,8 +156,10 @@ discard block |
||
| 148 | 156 | $brickSlug = $brick->slug; |
| 149 | 157 | $fieldSlug = $field->slug; |
| 150 | 158 | $value = isset($document->bricks->$brickSlug->fields->$fieldSlug) ? current($document->bricks->$brickSlug->fields->$fieldSlug) : ''; |
| 151 | - else : |
|
| 159 | + else { |
|
| 160 | + : |
|
| 152 | 161 | $value = ''; |
| 162 | + } |
|
| 153 | 163 | endif ?> |
| 154 | 164 | <? if ($field->multiple == true && $field->type != 'Rich Text') : ?> |
| 155 | 165 | <ul class="grid-wrapper sortable"> |
@@ -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 |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | if (isset($request::$get[CmsComponent::PARAMETER_DOCUMENT_TYPE])) { |
| 46 | 46 | if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE], $request::$get[CmsComponent::PARAMETER_DOCUMENT_TYPE], $request::$get[CmsComponent::GET_PARAMETER_PATH])) { |
| 47 | 47 | $cmsComponent->storage->addDocument($request::$post); |
| 48 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/documents'); |
|
| 48 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/documents'); |
|
| 49 | 49 | exit; |
| 50 | 50 | } |
| 51 | 51 | $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENT_TYPE, $cmsComponent->storage->getDocumentTypeBySlug($request::$get[CmsComponent::PARAMETER_DOCUMENT_TYPE], true)); |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | } else { |
| 54 | 54 | $documentTypes = $cmsComponent->storage->getDocumentTypes(); |
| 55 | 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>'); |
|
| 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 | 57 | } |
| 58 | 58 | $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENT_TYPES, $documentTypes); |
| 59 | 59 | } |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | $cmsComponent->setParameter(CmsComponent::PARAMETER_SMALLEST_IMAGE, $cmsComponent->storage->getSmallestImageSet()->slug); |
| 64 | 64 | if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE], $request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
| 65 | 65 | $cmsComponent->storage->saveDocument($request::$post); |
| 66 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/documents'); |
|
| 66 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/documents'); |
|
| 67 | 67 | exit; |
| 68 | 68 | } |
| 69 | 69 | $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENT, $cmsComponent->storage->getDocumentBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG])); |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | die(json_encode($result)); |
| 87 | 87 | } else if ($relativeCmsUri == '/documents/delete-document' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
| 88 | 88 | $cmsComponent->storage->deleteDocumentBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
| 89 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/documents'); |
|
| 89 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/documents'); |
|
| 90 | 90 | exit; |
| 91 | 91 | } |
| 92 | 92 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_DOCUMENTS); |
| 104 | 104 | if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE], $request::$post[CmsComponent::GET_PARAMETER_PATH])) { |
| 105 | 105 | $cmsComponent->storage->addDocumentFolder($request::$post); |
| 106 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/documents'); |
|
| 106 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/documents'); |
|
| 107 | 107 | exit; |
| 108 | 108 | } |
| 109 | 109 | } else if ($relativeCmsUri == '/documents/edit-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
@@ -116,11 +116,11 @@ discard block |
||
| 116 | 116 | array_pop($path); |
| 117 | 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 | 121 | if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE], $request::$post['content'])) { |
| 122 | 122 | $cmsComponent->storage->saveDocumentFolder($request::$post); |
| 123 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/documents'); |
|
| 123 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/documents'); |
|
| 124 | 124 | exit; |
| 125 | 125 | } |
| 126 | 126 | |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | $cmsComponent->setParameter(CmsComponent::PARAMETER_FOLDER, $folder); |
| 129 | 129 | } else if ($relativeCmsUri == '/documents/delete-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
| 130 | 130 | $cmsComponent->storage->deleteDocumentFolderBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
| 131 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/documents'); |
|
| 131 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/documents'); |
|
| 132 | 132 | exit; |
| 133 | 133 | } |
| 134 | 134 | } |
@@ -13,38 +13,38 @@ |
||
| 13 | 13 | class ImagesRouting |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * ImagesRouting constructor. |
|
| 18 | - * @param \library\cc\Request $request |
|
| 19 | - * @param mixed|string $relativeCmsUri |
|
| 20 | - * @param CmsComponent $cmsComponent |
|
| 21 | - */ |
|
| 22 | - public function __construct($request, $relativeCmsUri, $cmsComponent) |
|
| 23 | - { |
|
| 24 | - if ($relativeCmsUri == '/images') { |
|
| 25 | - $cmsComponent->subTemplate = 'cms/images'; |
|
| 26 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_IMAGES); |
|
| 27 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_IMAGES, $cmsComponent->storage->getImages()); |
|
| 28 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_SMALLEST_IMAGE, $cmsComponent->storage->getSmallestImageSet()->slug); |
|
| 29 | - } elseif ($relativeCmsUri == '/images.json') { |
|
| 30 | - header(CmsComponent::CONTENT_TYPE_APPLICATION_JSON); |
|
| 31 | - die(json_encode($cmsComponent->storage->getImages())); |
|
| 32 | - } elseif ($relativeCmsUri == '/images/new') { |
|
| 33 | - $cmsComponent->subTemplate = 'cms/images/form'; |
|
| 34 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_IMAGES); |
|
| 35 | - if (isset($_FILES[CmsComponent::FILES_PARAMETER_FILE])) { |
|
| 36 | - $cmsComponent->storage->addImage($_FILES[CmsComponent::FILES_PARAMETER_FILE]); |
|
| 37 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/images'); |
|
| 38 | - exit; |
|
| 39 | - } |
|
| 40 | - } elseif ($relativeCmsUri == '/images/delete' && isset($request::$get[CmsComponent::FILES_PARAMETER_FILE])) { |
|
| 41 | - $cmsComponent->storage->deleteImageByName($request::$get[CmsComponent::FILES_PARAMETER_FILE]); |
|
| 42 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/images'); |
|
| 43 | - exit; |
|
| 44 | - } elseif ($relativeCmsUri == '/images/show' && isset($request::$get[CmsComponent::FILES_PARAMETER_FILE])) { |
|
| 45 | - $cmsComponent->subTemplate = 'cms/images/show'; |
|
| 46 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_IMAGES); |
|
| 47 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_IMAGE, $cmsComponent->storage->getImageByName($request::$get[CmsComponent::FILES_PARAMETER_FILE])); |
|
| 48 | - } |
|
| 49 | - } |
|
| 16 | + /** |
|
| 17 | + * ImagesRouting constructor. |
|
| 18 | + * @param \library\cc\Request $request |
|
| 19 | + * @param mixed|string $relativeCmsUri |
|
| 20 | + * @param CmsComponent $cmsComponent |
|
| 21 | + */ |
|
| 22 | + public function __construct($request, $relativeCmsUri, $cmsComponent) |
|
| 23 | + { |
|
| 24 | + if ($relativeCmsUri == '/images') { |
|
| 25 | + $cmsComponent->subTemplate = 'cms/images'; |
|
| 26 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_IMAGES); |
|
| 27 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_IMAGES, $cmsComponent->storage->getImages()); |
|
| 28 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_SMALLEST_IMAGE, $cmsComponent->storage->getSmallestImageSet()->slug); |
|
| 29 | + } elseif ($relativeCmsUri == '/images.json') { |
|
| 30 | + header(CmsComponent::CONTENT_TYPE_APPLICATION_JSON); |
|
| 31 | + die(json_encode($cmsComponent->storage->getImages())); |
|
| 32 | + } elseif ($relativeCmsUri == '/images/new') { |
|
| 33 | + $cmsComponent->subTemplate = 'cms/images/form'; |
|
| 34 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_IMAGES); |
|
| 35 | + if (isset($_FILES[CmsComponent::FILES_PARAMETER_FILE])) { |
|
| 36 | + $cmsComponent->storage->addImage($_FILES[CmsComponent::FILES_PARAMETER_FILE]); |
|
| 37 | + header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/images'); |
|
| 38 | + exit; |
|
| 39 | + } |
|
| 40 | + } elseif ($relativeCmsUri == '/images/delete' && isset($request::$get[CmsComponent::FILES_PARAMETER_FILE])) { |
|
| 41 | + $cmsComponent->storage->deleteImageByName($request::$get[CmsComponent::FILES_PARAMETER_FILE]); |
|
| 42 | + header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/images'); |
|
| 43 | + exit; |
|
| 44 | + } elseif ($relativeCmsUri == '/images/show' && isset($request::$get[CmsComponent::FILES_PARAMETER_FILE])) { |
|
| 45 | + $cmsComponent->subTemplate = 'cms/images/show'; |
|
| 46 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_IMAGES); |
|
| 47 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_IMAGE, $cmsComponent->storage->getImageByName($request::$get[CmsComponent::FILES_PARAMETER_FILE])); |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | 50 | } |
| 51 | 51 | \ No newline at end of file |
@@ -34,12 +34,12 @@ |
||
| 34 | 34 | $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_IMAGES); |
| 35 | 35 | if (isset($_FILES[CmsComponent::FILES_PARAMETER_FILE])) { |
| 36 | 36 | $cmsComponent->storage->addImage($_FILES[CmsComponent::FILES_PARAMETER_FILE]); |
| 37 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/images'); |
|
| 37 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/images'); |
|
| 38 | 38 | exit; |
| 39 | 39 | } |
| 40 | 40 | } elseif ($relativeCmsUri == '/images/delete' && isset($request::$get[CmsComponent::FILES_PARAMETER_FILE])) { |
| 41 | 41 | $cmsComponent->storage->deleteImageByName($request::$get[CmsComponent::FILES_PARAMETER_FILE]); |
| 42 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/images'); |
|
| 42 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/images'); |
|
| 43 | 43 | exit; |
| 44 | 44 | } elseif ($relativeCmsUri == '/images/show' && isset($request::$get[CmsComponent::FILES_PARAMETER_FILE])) { |
| 45 | 45 | $cmsComponent->subTemplate = 'cms/images/show'; |
@@ -1,556 +1,556 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace library\components { |
| 3 | 3 | |
| 4 | - use library\components\cms\DocumentRouting; |
|
| 5 | - use library\components\cms\ImagesRouting; |
|
| 6 | - use library\crypt\Crypt; |
|
| 7 | - use library\storage\Storage; |
|
| 8 | - |
|
| 9 | - class CmsComponent extends BaseComponent |
|
| 10 | - { |
|
| 11 | - /* |
|
| 4 | + use library\components\cms\DocumentRouting; |
|
| 5 | + use library\components\cms\ImagesRouting; |
|
| 6 | + use library\crypt\Crypt; |
|
| 7 | + use library\storage\Storage; |
|
| 8 | + |
|
| 9 | + class CmsComponent extends BaseComponent |
|
| 10 | + { |
|
| 11 | + /* |
|
| 12 | 12 | * var \library\storage\Storage |
| 13 | 13 | */ |
| 14 | - public $storage; |
|
| 15 | - |
|
| 16 | - const INVALID_CREDENTIALS_MESSAGE = 'Invalid username / password combination'; |
|
| 17 | - |
|
| 18 | - const MAIN_NAV_CLASS = 'default'; |
|
| 19 | - |
|
| 20 | - const PARAMETER_BLACKLIST_IPS = 'blacklistIps'; |
|
| 21 | - const PARAMETER_BODY = 'body'; |
|
| 22 | - const PARAMETER_BRICK = 'brick'; |
|
| 23 | - const PARAMETER_BRICKS = 'bricks'; |
|
| 24 | - const PARAMETER_CMS_PREFIX = 'cmsPrefix'; |
|
| 25 | - const PARAMETER_DOCUMENT = 'document'; |
|
| 26 | - const PARAMETER_DOCUMENTS = 'documents'; |
|
| 27 | - const PARAMETER_DOCUMENT_TYPE = 'documentType'; |
|
| 28 | - const PARAMETER_DOCUMENT_TYPES = 'documentTypes'; |
|
| 29 | - const PARAMETER_ERROR_MESSAGE = 'errorMsg'; |
|
| 30 | - const PARAMETER_FILES = 'files'; |
|
| 31 | - const PARAMETER_FOLDER = 'folder'; |
|
| 32 | - const PARAMETER_IMAGE = 'image'; |
|
| 33 | - const PARAMETER_IMAGES = 'images'; |
|
| 34 | - const PARAMETER_IMAGE_SET = 'imageSet'; |
|
| 35 | - const PARAMETER_MAIN_NAV_CLASS = 'mainNavClass'; |
|
| 36 | - const PARAMETER_MY_BRICK_SLUG = 'myBrickSlug'; |
|
| 37 | - const PARAMETER_SITEMAP = 'sitemap'; |
|
| 38 | - const PARAMETER_SITEMAP_ITEM = 'sitemapItem'; |
|
| 39 | - const PARAMETER_SMALLEST_IMAGE = 'smallestImage'; |
|
| 40 | - const PARAMETER_STATIC = 'static'; |
|
| 41 | - const PARAMETER_USER = 'user'; |
|
| 42 | - const PARAMETER_USERS = 'users'; |
|
| 43 | - const PARAMETER_USER_RIGHTS = 'userRights'; |
|
| 44 | - const PARAMETER_WHITELIST_IPS = 'whitelistIps'; |
|
| 45 | - |
|
| 46 | - const POST_PARAMETER_COMPONENT = 'component'; |
|
| 47 | - const POST_PARAMETER_PASSWORD = 'password'; |
|
| 48 | - const POST_PARAMETER_SAVE = 'save'; |
|
| 49 | - const POST_PARAMETER_TEMPLATE = 'template'; |
|
| 50 | - const POST_PARAMETER_TITLE = 'title'; |
|
| 51 | - const POST_PARAMETER_USERNAME = 'username'; |
|
| 52 | - |
|
| 53 | - const GET_PARAMETER_PATH = 'path'; |
|
| 54 | - const GET_PARAMETER_SLUG = 'slug'; |
|
| 55 | - |
|
| 56 | - const FILES_PARAMETER_FILE = 'file'; |
|
| 57 | - |
|
| 58 | - const SESSION_PARAMETER_CLOUD_CONTROL = 'cloudcontrol'; |
|
| 59 | - |
|
| 60 | - const LOGIN_TEMPLATE_PATH = 'cms/login'; |
|
| 61 | - |
|
| 62 | - const CONTENT_TYPE_APPLICATION_JSON = 'Content-type:application/json'; |
|
| 63 | - |
|
| 64 | - public $subTemplate = null; |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @param \library\storage\Storage $storage |
|
| 69 | - * |
|
| 70 | - * @return void |
|
| 71 | - */ |
|
| 72 | - public function run(Storage $storage) |
|
| 73 | - { |
|
| 74 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::MAIN_NAV_CLASS; |
|
| 75 | - $this->storage = $storage; |
|
| 76 | - |
|
| 77 | - $remoteAddress = $_SERVER['REMOTE_ADDR']; |
|
| 78 | - $this->checkWhiteList($remoteAddress); |
|
| 79 | - $this->checkBlackList($remoteAddress); |
|
| 80 | - |
|
| 81 | - $this->checkLogin(); |
|
| 82 | - |
|
| 83 | - $this->parameters[self::PARAMETER_USER_RIGHTS] = $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]->rights; |
|
| 84 | - |
|
| 85 | - $this->routing(); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * See if a user is logged or wants to log in and |
|
| 90 | - * takes appropriate actions. |
|
| 91 | - * |
|
| 92 | - * @throws \Exception |
|
| 93 | - */ |
|
| 94 | - protected function checkLogin() |
|
| 95 | - { |
|
| 96 | - $request = $this->request; |
|
| 97 | - |
|
| 98 | - if (!isset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL])) { |
|
| 99 | - if (isset($request::$post[self::POST_PARAMETER_USERNAME], $request::$post[self::POST_PARAMETER_PASSWORD])) { |
|
| 100 | - $user = $this->storage->getUserByUsername($request::$post[self::POST_PARAMETER_USERNAME]); |
|
| 101 | - $crypt = new Crypt(); |
|
| 102 | - if (empty($user)) { |
|
| 103 | - $crypt->encrypt($request::$post[self::POST_PARAMETER_PASSWORD], 16); // Buy time, to avoid brute forcing |
|
| 104 | - $this->parameters[self::PARAMETER_ERROR_MESSAGE] = self::INVALID_CREDENTIALS_MESSAGE; |
|
| 105 | - $this->showLogin(); |
|
| 106 | - } else { |
|
| 107 | - $salt = $user->salt; |
|
| 108 | - $password = $user->password; |
|
| 109 | - |
|
| 110 | - $passwordCorrect = $crypt->compare($request::$post[self::POST_PARAMETER_PASSWORD], $password, $salt); |
|
| 111 | - |
|
| 112 | - if ($passwordCorrect) { |
|
| 113 | - $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = $user; |
|
| 114 | - } else { |
|
| 115 | - $this->parameters[self::PARAMETER_ERROR_MESSAGE] = self::INVALID_CREDENTIALS_MESSAGE; |
|
| 116 | - $this->showLogin(); |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - } else { |
|
| 120 | - $this->showLogin(); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Overrides normal behaviour and only renders the |
|
| 127 | - * login screen |
|
| 128 | - * |
|
| 129 | - * @throws \Exception |
|
| 130 | - */ |
|
| 131 | - protected function showLogin() |
|
| 132 | - { |
|
| 133 | - $loginTemplatePath = self::LOGIN_TEMPLATE_PATH; |
|
| 134 | - $this->renderTemplate($loginTemplatePath); |
|
| 135 | - ob_end_flush(); |
|
| 136 | - exit; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * As an exception, to keep the initial file structure simple |
|
| 141 | - * the cms implements it's own routing, apart from the regular sitemap functionality |
|
| 142 | - * |
|
| 143 | - * @throws \Exception |
|
| 144 | - */ |
|
| 145 | - protected function routing() |
|
| 146 | - { |
|
| 147 | - $relativeCmsUri = $this->getRelativeCmsUri($this->request); |
|
| 148 | - |
|
| 149 | - $userRights = $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]->rights; |
|
| 150 | - |
|
| 151 | - if ($relativeCmsUri == '' || $relativeCmsUri == '/') { |
|
| 152 | - $this->subTemplate = 'cms/dashboard'; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - $this->logOffRouting($this->request, $relativeCmsUri); |
|
| 156 | - |
|
| 157 | - $this->apiRouting($relativeCmsUri); |
|
| 158 | - |
|
| 159 | - if (in_array(self::PARAMETER_DOCUMENTS, $userRights)) { |
|
| 160 | - new DocumentRouting($this->request, $relativeCmsUri, $this); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - if (in_array(self::PARAMETER_SITEMAP, $userRights)) { |
|
| 164 | - $this->sitemapRouting($this->request, $relativeCmsUri); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - if (in_array(self::PARAMETER_IMAGES, $userRights)) { |
|
| 168 | - new ImagesRouting($this->request, $relativeCmsUri, $this); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - if (in_array(self::PARAMETER_FILES, $userRights)) { |
|
| 172 | - $this->filesRouting($this->request, $relativeCmsUri); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - if (in_array('configuration', $userRights)) { |
|
| 176 | - $this->configurationRouting($this->request, $relativeCmsUri); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - if ($this->subTemplate !== null) { |
|
| 180 | - $this->parameters[self::PARAMETER_BODY] = $this->renderTemplate($this->subTemplate); |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * @param $remoteAddress |
|
| 186 | - * @throws \Exception |
|
| 187 | - */ |
|
| 188 | - private function checkWhiteList($remoteAddress) |
|
| 189 | - { |
|
| 190 | - if (isset($this->parameters[self::PARAMETER_WHITELIST_IPS])) { |
|
| 191 | - $whitelistIps = explode(',', $this->parameters[self::PARAMETER_WHITELIST_IPS]); |
|
| 192 | - $whitelistIps = array_map("trim", $whitelistIps); |
|
| 193 | - if (!in_array($remoteAddress, $whitelistIps)) { |
|
| 194 | - throw new \Exception('Ip address ' . $remoteAddress . ' is not on whitelist'); |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * @param $remoteAddress |
|
| 201 | - * @throws \Exception |
|
| 202 | - */ |
|
| 203 | - private function checkBlackList($remoteAddress) |
|
| 204 | - { |
|
| 205 | - if (isset($this->parameters[self::PARAMETER_BLACKLIST_IPS])) { |
|
| 206 | - $blacklistIps = explode(',', $this->parameters[self::PARAMETER_BLACKLIST_IPS]); |
|
| 207 | - $blacklistIps = array_map("trim", $blacklistIps); |
|
| 208 | - if (in_array($remoteAddress, $blacklistIps)) { |
|
| 209 | - throw new \Exception('Ip address ' . $remoteAddress . ' is on blacklist'); |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * @param $request |
|
| 216 | - * @return mixed|string |
|
| 217 | - */ |
|
| 218 | - private function getRelativeCmsUri($request) |
|
| 219 | - { |
|
| 220 | - // TODO Use regex match parameter instead of calculating relative uri |
|
| 221 | - $pos = strpos($request::$relativeUri, $this->parameters[self::PARAMETER_CMS_PREFIX]); |
|
| 222 | - $relativeCmsUri = '/'; |
|
| 223 | - if ($pos !== false) { |
|
| 224 | - $relativeCmsUri = substr_replace($request::$relativeUri, '', $pos, strlen($this->parameters[self::PARAMETER_CMS_PREFIX])); |
|
| 225 | - } |
|
| 226 | - return $relativeCmsUri; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * @param \library\cc\Request $request |
|
| 231 | - * @param $relativeCmsUri |
|
| 232 | - */ |
|
| 233 | - private function sitemapRouting($request, $relativeCmsUri) |
|
| 234 | - { |
|
| 235 | - if ($relativeCmsUri == '/sitemap') { |
|
| 236 | - $this->subTemplate = 'cms/sitemap'; |
|
| 237 | - if (isset($request::$post[self::POST_PARAMETER_SAVE])) { |
|
| 238 | - $this->storage->saveSitemap($request::$post); |
|
| 239 | - } |
|
| 240 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_SITEMAP; |
|
| 241 | - $this->parameters[self::PARAMETER_SITEMAP] = $this->storage->getSitemap(); |
|
| 242 | - } elseif ($relativeCmsUri == '/sitemap/new') { |
|
| 243 | - $this->subTemplate = 'cms/sitemap/form'; |
|
| 244 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_SITEMAP; |
|
| 245 | - if (isset($request::$post[self::POST_PARAMETER_TITLE], $request::$post[self::POST_PARAMETER_TEMPLATE], $request::$post[self::POST_PARAMETER_COMPONENT])) { |
|
| 246 | - $this->storage->addSitemapItem($request::$post); |
|
| 247 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/sitemap'); |
|
| 248 | - exit; |
|
| 249 | - } |
|
| 250 | - } elseif ($relativeCmsUri == '/sitemap/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
| 251 | - $this->subTemplate = 'cms/sitemap/form'; |
|
| 252 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_SITEMAP; |
|
| 253 | - $sitemapItem = $this->storage->getSitemapItemBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
| 254 | - if (isset($request::$post[self::POST_PARAMETER_TITLE], $request::$post[self::POST_PARAMETER_TEMPLATE], $request::$post[self::POST_PARAMETER_COMPONENT])) { |
|
| 255 | - $this->storage->saveSitemapItem($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
|
| 256 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/sitemap'); |
|
| 257 | - exit; |
|
| 258 | - } |
|
| 259 | - $this->parameters[self::PARAMETER_SITEMAP_ITEM] = $sitemapItem; |
|
| 260 | - } elseif ($relativeCmsUri == '/sitemap/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
| 261 | - $this->storage->deleteSitemapItemBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
| 262 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/sitemap'); |
|
| 263 | - exit; |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * @param $relativeCmsUri |
|
| 269 | - */ |
|
| 270 | - private function apiRouting($relativeCmsUri) |
|
| 271 | - { |
|
| 272 | - if ($relativeCmsUri == '/images.json') { |
|
| 273 | - header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
| 274 | - die(json_encode($this->storage->getImages())); |
|
| 275 | - } elseif ($relativeCmsUri == '/files.json') { |
|
| 276 | - header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
| 277 | - die(json_encode($this->storage->getFiles())); |
|
| 278 | - } elseif ($relativeCmsUri == '/documents.json') { |
|
| 279 | - header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
| 280 | - die(json_encode($this->storage->getDocuments())); |
|
| 281 | - } |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * @param $request |
|
| 286 | - * @param $relativeCmsUri |
|
| 287 | - */ |
|
| 288 | - private function filesRouting($request, $relativeCmsUri) |
|
| 289 | - { |
|
| 290 | - if ($relativeCmsUri == '/files') { |
|
| 291 | - $this->subTemplate = 'cms/files'; |
|
| 292 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_FILES; |
|
| 293 | - $this->parameters[self::PARAMETER_FILES] = $this->storage->getFiles(); |
|
| 294 | - } elseif ($relativeCmsUri == '/files/new') { |
|
| 295 | - $this->subTemplate = 'cms/files/form'; |
|
| 296 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_FILES; |
|
| 297 | - if (isset($_FILES[self::FILES_PARAMETER_FILE])) { |
|
| 298 | - $this->storage->addFile($_FILES[self::FILES_PARAMETER_FILE]); |
|
| 299 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/files'); |
|
| 300 | - exit; |
|
| 301 | - } |
|
| 302 | - } elseif ($relativeCmsUri == '/files/get' && isset($request::$get[self::FILES_PARAMETER_FILE])) { |
|
| 303 | - $this->downloadFile($request::$get[self::FILES_PARAMETER_FILE]); |
|
| 304 | - } elseif ($relativeCmsUri == '/files/delete' && isset($request::$get[self::FILES_PARAMETER_FILE])) { |
|
| 305 | - $this->storage->deleteFileByName($request::$get[self::FILES_PARAMETER_FILE]); |
|
| 306 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/files'); |
|
| 307 | - exit; |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * @param $slug |
|
| 313 | - */ |
|
| 314 | - private function downloadFile($slug) |
|
| 315 | - { |
|
| 316 | - $file = $this->storage->getFileByName($slug); |
|
| 317 | - $path = realpath(__DIR__ . '/../../www/files/'); |
|
| 318 | - $quoted = sprintf('"%s"', addcslashes(basename($path . '/' . $file->file), '"\\')); |
|
| 319 | - $size = filesize($path . '/' . $file->file); |
|
| 320 | - |
|
| 321 | - header('Content-Description: File Transfer'); |
|
| 322 | - header('Content-Type: ' . $file->type); |
|
| 323 | - header('Content-Disposition: attachment; filename=' . $quoted); |
|
| 324 | - header('Content-Transfer-Encoding: binary'); |
|
| 325 | - header('Connection: Keep-Alive'); |
|
| 326 | - header('Expires: 0'); |
|
| 327 | - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
| 328 | - header('Pragma: public'); |
|
| 329 | - header('Content-Length: ' . $size); |
|
| 330 | - |
|
| 331 | - readfile($path . '/' . $file->file); |
|
| 332 | - exit; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * @param $request |
|
| 337 | - * @param $relativeCmsUri |
|
| 338 | - */ |
|
| 339 | - private function configurationRouting($request, $relativeCmsUri) |
|
| 340 | - { |
|
| 341 | - if ($relativeCmsUri == '/configuration') { |
|
| 342 | - $this->subTemplate = 'cms/configuration'; |
|
| 343 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - $this->usersRouting($request, $relativeCmsUri); |
|
| 347 | - $this->documentTypesRouting($request, $relativeCmsUri); |
|
| 348 | - $this->bricksRouting($request, $relativeCmsUri); |
|
| 349 | - $this->imageSetRouting($request, $relativeCmsUri); |
|
| 350 | - $this->applicationComponentRouting($request, $relativeCmsUri); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * @param $request |
|
| 356 | - * @param $relativeCmsUri |
|
| 357 | - */ |
|
| 358 | - private function usersRouting($request, $relativeCmsUri) |
|
| 359 | - { |
|
| 360 | - if ($relativeCmsUri == '/configuration/users') { |
|
| 361 | - $this->subTemplate = 'cms/configuration/users'; |
|
| 362 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 363 | - $this->parameters[self::PARAMETER_USERS] = $this->storage->getUsers(); |
|
| 364 | - } elseif ($relativeCmsUri == '/configuration/users/new') { |
|
| 365 | - $this->subTemplate = 'cms/configuration/users-form'; |
|
| 366 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 367 | - if (isset($_POST[self::POST_PARAMETER_USERNAME])) { |
|
| 368 | - $this->storage->addUser($request::$post); |
|
| 369 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/users'); |
|
| 370 | - exit; |
|
| 371 | - } |
|
| 372 | - } elseif ($relativeCmsUri == '/configuration/users/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
| 373 | - $this->storage->deleteUserBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
| 374 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/users'); |
|
| 375 | - exit; |
|
| 376 | - } elseif ($relativeCmsUri == '/configuration/users/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
| 377 | - $this->subTemplate = 'cms/configuration/users-form'; |
|
| 378 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 379 | - $this->parameters[self::PARAMETER_USER] = $this->storage->getUserBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
| 380 | - if (isset($_POST[self::POST_PARAMETER_USERNAME])) { |
|
| 381 | - $this->storage->saveUser($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
|
| 382 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/users'); |
|
| 383 | - exit; |
|
| 384 | - } |
|
| 385 | - } |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * @param $request |
|
| 390 | - * @param $relativeCmsUri |
|
| 391 | - */ |
|
| 392 | - private function documentTypesRouting($request, $relativeCmsUri) |
|
| 393 | - { |
|
| 394 | - if ($relativeCmsUri == '/configuration/document-types') { |
|
| 395 | - $this->subTemplate = 'cms/configuration/document-types'; |
|
| 396 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 397 | - $this->parameters[self::PARAMETER_DOCUMENT_TYPES] = $this->storage->getDocumentTypes(); |
|
| 398 | - } elseif ($relativeCmsUri == '/configuration/document-types/new') { |
|
| 399 | - $this->subTemplate = 'cms/configuration/document-types-form'; |
|
| 400 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 401 | - $bricks = $this->storage->getBricks(); |
|
| 402 | - if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
| 403 | - $this->storage->addDocumentType($request::$post); |
|
| 404 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/document-types'); |
|
| 405 | - exit; |
|
| 406 | - } |
|
| 407 | - $this->parameters[self::PARAMETER_BRICKS] = $bricks; |
|
| 408 | - } elseif ($relativeCmsUri == '/configuration/document-types/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
| 409 | - $this->subTemplate = 'cms/configuration/document-types-form'; |
|
| 410 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 411 | - $documentType = $this->storage->getDocumentTypeBySlug($request::$get[self::GET_PARAMETER_SLUG], false); |
|
| 412 | - $bricks = $this->storage->getBricks(); |
|
| 413 | - if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
| 414 | - $this->storage->saveDocumentType($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
|
| 415 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/document-types'); |
|
| 416 | - exit; |
|
| 417 | - } |
|
| 418 | - $this->parameters[self::PARAMETER_DOCUMENT_TYPE] = $documentType; |
|
| 419 | - $this->parameters[self::PARAMETER_BRICKS] = $bricks; |
|
| 420 | - } elseif ($relativeCmsUri == '/configuration/document-types/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
| 421 | - $this->storage->deleteDocumentTypeBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
| 422 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/document-types'); |
|
| 423 | - exit; |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - /** |
|
| 428 | - * @param $request |
|
| 429 | - * @param $relativeCmsUri |
|
| 430 | - */ |
|
| 431 | - private function bricksRouting($request, $relativeCmsUri) |
|
| 432 | - { |
|
| 433 | - if ($relativeCmsUri == '/configuration/bricks') { |
|
| 434 | - $this->subTemplate = 'cms/configuration/bricks'; |
|
| 435 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 436 | - $this->parameters[self::PARAMETER_BRICKS] = $this->storage->getBricks(); |
|
| 437 | - } elseif ($relativeCmsUri == '/configuration/bricks/new') { |
|
| 438 | - $this->subTemplate = 'cms/configuration/bricks-form'; |
|
| 439 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 440 | - if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
| 441 | - $this->storage->addBrick($request::$post); |
|
| 442 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/bricks'); |
|
| 443 | - exit; |
|
| 444 | - } |
|
| 445 | - } elseif ($relativeCmsUri == '/configuration/bricks/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
| 446 | - $this->subTemplate = 'cms/configuration/bricks-form'; |
|
| 447 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 448 | - $brick = $this->storage->getBrickBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
| 449 | - if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
| 450 | - $this->storage->saveBrick($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
|
| 451 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/bricks'); |
|
| 452 | - exit; |
|
| 453 | - } |
|
| 454 | - $this->parameters[self::PARAMETER_BRICK] = $brick; |
|
| 455 | - } elseif ($relativeCmsUri == '/configuration/bricks/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
| 456 | - $this->storage->deleteBrickBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
| 457 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/bricks'); |
|
| 458 | - exit; |
|
| 459 | - } elseif ($relativeCmsUri == '/configuration/image-set') { |
|
| 460 | - $this->subTemplate = 'cms/configuration/image-set'; |
|
| 461 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 462 | - $this->parameters[self::PARAMETER_IMAGE_SET] = $this->storage->getImageSet(); |
|
| 463 | - } |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - /** |
|
| 467 | - * @param $request |
|
| 468 | - * @param $relativeCmsUri |
|
| 469 | - */ |
|
| 470 | - private function imageSetRouting($request, $relativeCmsUri) |
|
| 471 | - { |
|
| 472 | - if ($relativeCmsUri == '/configuration/image-set') { |
|
| 473 | - $this->subTemplate = 'cms/configuration/image-set'; |
|
| 474 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 475 | - $this->parameters[self::PARAMETER_IMAGE_SET] = $this->storage->getImageSet(); |
|
| 476 | - } elseif ($relativeCmsUri == '/configuration/image-set/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
| 477 | - $this->subTemplate = 'cms/configuration/image-set-form'; |
|
| 478 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 479 | - $imageSet = $this->storage->getImageSetBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
| 480 | - if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
| 481 | - $this->storage->saveImageSet($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
|
| 482 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/image-set'); |
|
| 483 | - exit; |
|
| 484 | - } |
|
| 485 | - $this->parameters[self::PARAMETER_IMAGE_SET] = $imageSet; |
|
| 486 | - } elseif ($relativeCmsUri == '/configuration/image-set/new') { |
|
| 487 | - $this->subTemplate = 'cms/configuration/image-set-form'; |
|
| 488 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 489 | - if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
| 490 | - $this->storage->addImageSet($request::$post); |
|
| 491 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/image-set'); |
|
| 492 | - exit; |
|
| 493 | - } |
|
| 494 | - } elseif ($relativeCmsUri == '/configuration/image-set/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
| 495 | - $this->storage->deleteImageSetBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
| 496 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/image-set'); |
|
| 497 | - exit; |
|
| 498 | - } |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - /** |
|
| 502 | - * @param $request |
|
| 503 | - * @param $relativeCmsUri |
|
| 504 | - */ |
|
| 505 | - private function applicationComponentRouting($request, $relativeCmsUri) |
|
| 506 | - { |
|
| 507 | - if ($relativeCmsUri == '/configuration/application-components') { |
|
| 508 | - $this->subTemplate = 'cms/configuration/application-components'; |
|
| 509 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 510 | - $this->parameters['applicationComponents'] = $this->storage->getApplicationComponents(); |
|
| 511 | - } elseif ($relativeCmsUri == '/configuration/application-components/new') { |
|
| 512 | - $this->subTemplate = 'cms/configuration/application-components-form'; |
|
| 513 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 514 | - if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
| 515 | - $this->storage->addApplicationComponent($request::$post); |
|
| 516 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/application-components'); |
|
| 517 | - exit; |
|
| 518 | - } |
|
| 519 | - } elseif ($relativeCmsUri == '/configuration/application-components/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
| 520 | - $this->subTemplate = 'cms/configuration/application-components-form'; |
|
| 521 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 522 | - $applicationComponent = $this->storage->getApplicationComponentBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
| 523 | - if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
| 524 | - $this->storage->saveApplicationComponent($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
|
| 525 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/application-components'); |
|
| 526 | - exit; |
|
| 527 | - } |
|
| 528 | - $this->parameters['applicationComponent'] = $applicationComponent; |
|
| 529 | - } elseif ($relativeCmsUri == '/configuration/application-components/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
| 530 | - $this->storage->deleteApplicationComponentBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
| 531 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/application-components'); |
|
| 532 | - exit; |
|
| 533 | - } |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - private function logOffRouting($request, $relativeCmsUri) |
|
| 537 | - { |
|
| 538 | - if ($relativeCmsUri == '/log-off') { |
|
| 539 | - $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = null; |
|
| 540 | - unset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]); |
|
| 541 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX]); |
|
| 542 | - exit; |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - public function setParameter($parameterName, $parameterValue) |
|
| 547 | - { |
|
| 548 | - $this->parameters[$parameterName] = $parameterValue; |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - public function getParameter($parameterName) |
|
| 552 | - { |
|
| 553 | - return $this->parameters[$parameterName]; |
|
| 554 | - } |
|
| 555 | - } |
|
| 14 | + public $storage; |
|
| 15 | + |
|
| 16 | + const INVALID_CREDENTIALS_MESSAGE = 'Invalid username / password combination'; |
|
| 17 | + |
|
| 18 | + const MAIN_NAV_CLASS = 'default'; |
|
| 19 | + |
|
| 20 | + const PARAMETER_BLACKLIST_IPS = 'blacklistIps'; |
|
| 21 | + const PARAMETER_BODY = 'body'; |
|
| 22 | + const PARAMETER_BRICK = 'brick'; |
|
| 23 | + const PARAMETER_BRICKS = 'bricks'; |
|
| 24 | + const PARAMETER_CMS_PREFIX = 'cmsPrefix'; |
|
| 25 | + const PARAMETER_DOCUMENT = 'document'; |
|
| 26 | + const PARAMETER_DOCUMENTS = 'documents'; |
|
| 27 | + const PARAMETER_DOCUMENT_TYPE = 'documentType'; |
|
| 28 | + const PARAMETER_DOCUMENT_TYPES = 'documentTypes'; |
|
| 29 | + const PARAMETER_ERROR_MESSAGE = 'errorMsg'; |
|
| 30 | + const PARAMETER_FILES = 'files'; |
|
| 31 | + const PARAMETER_FOLDER = 'folder'; |
|
| 32 | + const PARAMETER_IMAGE = 'image'; |
|
| 33 | + const PARAMETER_IMAGES = 'images'; |
|
| 34 | + const PARAMETER_IMAGE_SET = 'imageSet'; |
|
| 35 | + const PARAMETER_MAIN_NAV_CLASS = 'mainNavClass'; |
|
| 36 | + const PARAMETER_MY_BRICK_SLUG = 'myBrickSlug'; |
|
| 37 | + const PARAMETER_SITEMAP = 'sitemap'; |
|
| 38 | + const PARAMETER_SITEMAP_ITEM = 'sitemapItem'; |
|
| 39 | + const PARAMETER_SMALLEST_IMAGE = 'smallestImage'; |
|
| 40 | + const PARAMETER_STATIC = 'static'; |
|
| 41 | + const PARAMETER_USER = 'user'; |
|
| 42 | + const PARAMETER_USERS = 'users'; |
|
| 43 | + const PARAMETER_USER_RIGHTS = 'userRights'; |
|
| 44 | + const PARAMETER_WHITELIST_IPS = 'whitelistIps'; |
|
| 45 | + |
|
| 46 | + const POST_PARAMETER_COMPONENT = 'component'; |
|
| 47 | + const POST_PARAMETER_PASSWORD = 'password'; |
|
| 48 | + const POST_PARAMETER_SAVE = 'save'; |
|
| 49 | + const POST_PARAMETER_TEMPLATE = 'template'; |
|
| 50 | + const POST_PARAMETER_TITLE = 'title'; |
|
| 51 | + const POST_PARAMETER_USERNAME = 'username'; |
|
| 52 | + |
|
| 53 | + const GET_PARAMETER_PATH = 'path'; |
|
| 54 | + const GET_PARAMETER_SLUG = 'slug'; |
|
| 55 | + |
|
| 56 | + const FILES_PARAMETER_FILE = 'file'; |
|
| 57 | + |
|
| 58 | + const SESSION_PARAMETER_CLOUD_CONTROL = 'cloudcontrol'; |
|
| 59 | + |
|
| 60 | + const LOGIN_TEMPLATE_PATH = 'cms/login'; |
|
| 61 | + |
|
| 62 | + const CONTENT_TYPE_APPLICATION_JSON = 'Content-type:application/json'; |
|
| 63 | + |
|
| 64 | + public $subTemplate = null; |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @param \library\storage\Storage $storage |
|
| 69 | + * |
|
| 70 | + * @return void |
|
| 71 | + */ |
|
| 72 | + public function run(Storage $storage) |
|
| 73 | + { |
|
| 74 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::MAIN_NAV_CLASS; |
|
| 75 | + $this->storage = $storage; |
|
| 76 | + |
|
| 77 | + $remoteAddress = $_SERVER['REMOTE_ADDR']; |
|
| 78 | + $this->checkWhiteList($remoteAddress); |
|
| 79 | + $this->checkBlackList($remoteAddress); |
|
| 80 | + |
|
| 81 | + $this->checkLogin(); |
|
| 82 | + |
|
| 83 | + $this->parameters[self::PARAMETER_USER_RIGHTS] = $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]->rights; |
|
| 84 | + |
|
| 85 | + $this->routing(); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * See if a user is logged or wants to log in and |
|
| 90 | + * takes appropriate actions. |
|
| 91 | + * |
|
| 92 | + * @throws \Exception |
|
| 93 | + */ |
|
| 94 | + protected function checkLogin() |
|
| 95 | + { |
|
| 96 | + $request = $this->request; |
|
| 97 | + |
|
| 98 | + if (!isset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL])) { |
|
| 99 | + if (isset($request::$post[self::POST_PARAMETER_USERNAME], $request::$post[self::POST_PARAMETER_PASSWORD])) { |
|
| 100 | + $user = $this->storage->getUserByUsername($request::$post[self::POST_PARAMETER_USERNAME]); |
|
| 101 | + $crypt = new Crypt(); |
|
| 102 | + if (empty($user)) { |
|
| 103 | + $crypt->encrypt($request::$post[self::POST_PARAMETER_PASSWORD], 16); // Buy time, to avoid brute forcing |
|
| 104 | + $this->parameters[self::PARAMETER_ERROR_MESSAGE] = self::INVALID_CREDENTIALS_MESSAGE; |
|
| 105 | + $this->showLogin(); |
|
| 106 | + } else { |
|
| 107 | + $salt = $user->salt; |
|
| 108 | + $password = $user->password; |
|
| 109 | + |
|
| 110 | + $passwordCorrect = $crypt->compare($request::$post[self::POST_PARAMETER_PASSWORD], $password, $salt); |
|
| 111 | + |
|
| 112 | + if ($passwordCorrect) { |
|
| 113 | + $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = $user; |
|
| 114 | + } else { |
|
| 115 | + $this->parameters[self::PARAMETER_ERROR_MESSAGE] = self::INVALID_CREDENTIALS_MESSAGE; |
|
| 116 | + $this->showLogin(); |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + } else { |
|
| 120 | + $this->showLogin(); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Overrides normal behaviour and only renders the |
|
| 127 | + * login screen |
|
| 128 | + * |
|
| 129 | + * @throws \Exception |
|
| 130 | + */ |
|
| 131 | + protected function showLogin() |
|
| 132 | + { |
|
| 133 | + $loginTemplatePath = self::LOGIN_TEMPLATE_PATH; |
|
| 134 | + $this->renderTemplate($loginTemplatePath); |
|
| 135 | + ob_end_flush(); |
|
| 136 | + exit; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * As an exception, to keep the initial file structure simple |
|
| 141 | + * the cms implements it's own routing, apart from the regular sitemap functionality |
|
| 142 | + * |
|
| 143 | + * @throws \Exception |
|
| 144 | + */ |
|
| 145 | + protected function routing() |
|
| 146 | + { |
|
| 147 | + $relativeCmsUri = $this->getRelativeCmsUri($this->request); |
|
| 148 | + |
|
| 149 | + $userRights = $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]->rights; |
|
| 150 | + |
|
| 151 | + if ($relativeCmsUri == '' || $relativeCmsUri == '/') { |
|
| 152 | + $this->subTemplate = 'cms/dashboard'; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + $this->logOffRouting($this->request, $relativeCmsUri); |
|
| 156 | + |
|
| 157 | + $this->apiRouting($relativeCmsUri); |
|
| 158 | + |
|
| 159 | + if (in_array(self::PARAMETER_DOCUMENTS, $userRights)) { |
|
| 160 | + new DocumentRouting($this->request, $relativeCmsUri, $this); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + if (in_array(self::PARAMETER_SITEMAP, $userRights)) { |
|
| 164 | + $this->sitemapRouting($this->request, $relativeCmsUri); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + if (in_array(self::PARAMETER_IMAGES, $userRights)) { |
|
| 168 | + new ImagesRouting($this->request, $relativeCmsUri, $this); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + if (in_array(self::PARAMETER_FILES, $userRights)) { |
|
| 172 | + $this->filesRouting($this->request, $relativeCmsUri); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + if (in_array('configuration', $userRights)) { |
|
| 176 | + $this->configurationRouting($this->request, $relativeCmsUri); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + if ($this->subTemplate !== null) { |
|
| 180 | + $this->parameters[self::PARAMETER_BODY] = $this->renderTemplate($this->subTemplate); |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * @param $remoteAddress |
|
| 186 | + * @throws \Exception |
|
| 187 | + */ |
|
| 188 | + private function checkWhiteList($remoteAddress) |
|
| 189 | + { |
|
| 190 | + if (isset($this->parameters[self::PARAMETER_WHITELIST_IPS])) { |
|
| 191 | + $whitelistIps = explode(',', $this->parameters[self::PARAMETER_WHITELIST_IPS]); |
|
| 192 | + $whitelistIps = array_map("trim", $whitelistIps); |
|
| 193 | + if (!in_array($remoteAddress, $whitelistIps)) { |
|
| 194 | + throw new \Exception('Ip address ' . $remoteAddress . ' is not on whitelist'); |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * @param $remoteAddress |
|
| 201 | + * @throws \Exception |
|
| 202 | + */ |
|
| 203 | + private function checkBlackList($remoteAddress) |
|
| 204 | + { |
|
| 205 | + if (isset($this->parameters[self::PARAMETER_BLACKLIST_IPS])) { |
|
| 206 | + $blacklistIps = explode(',', $this->parameters[self::PARAMETER_BLACKLIST_IPS]); |
|
| 207 | + $blacklistIps = array_map("trim", $blacklistIps); |
|
| 208 | + if (in_array($remoteAddress, $blacklistIps)) { |
|
| 209 | + throw new \Exception('Ip address ' . $remoteAddress . ' is on blacklist'); |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * @param $request |
|
| 216 | + * @return mixed|string |
|
| 217 | + */ |
|
| 218 | + private function getRelativeCmsUri($request) |
|
| 219 | + { |
|
| 220 | + // TODO Use regex match parameter instead of calculating relative uri |
|
| 221 | + $pos = strpos($request::$relativeUri, $this->parameters[self::PARAMETER_CMS_PREFIX]); |
|
| 222 | + $relativeCmsUri = '/'; |
|
| 223 | + if ($pos !== false) { |
|
| 224 | + $relativeCmsUri = substr_replace($request::$relativeUri, '', $pos, strlen($this->parameters[self::PARAMETER_CMS_PREFIX])); |
|
| 225 | + } |
|
| 226 | + return $relativeCmsUri; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * @param \library\cc\Request $request |
|
| 231 | + * @param $relativeCmsUri |
|
| 232 | + */ |
|
| 233 | + private function sitemapRouting($request, $relativeCmsUri) |
|
| 234 | + { |
|
| 235 | + if ($relativeCmsUri == '/sitemap') { |
|
| 236 | + $this->subTemplate = 'cms/sitemap'; |
|
| 237 | + if (isset($request::$post[self::POST_PARAMETER_SAVE])) { |
|
| 238 | + $this->storage->saveSitemap($request::$post); |
|
| 239 | + } |
|
| 240 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_SITEMAP; |
|
| 241 | + $this->parameters[self::PARAMETER_SITEMAP] = $this->storage->getSitemap(); |
|
| 242 | + } elseif ($relativeCmsUri == '/sitemap/new') { |
|
| 243 | + $this->subTemplate = 'cms/sitemap/form'; |
|
| 244 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_SITEMAP; |
|
| 245 | + if (isset($request::$post[self::POST_PARAMETER_TITLE], $request::$post[self::POST_PARAMETER_TEMPLATE], $request::$post[self::POST_PARAMETER_COMPONENT])) { |
|
| 246 | + $this->storage->addSitemapItem($request::$post); |
|
| 247 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/sitemap'); |
|
| 248 | + exit; |
|
| 249 | + } |
|
| 250 | + } elseif ($relativeCmsUri == '/sitemap/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
| 251 | + $this->subTemplate = 'cms/sitemap/form'; |
|
| 252 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_SITEMAP; |
|
| 253 | + $sitemapItem = $this->storage->getSitemapItemBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
| 254 | + if (isset($request::$post[self::POST_PARAMETER_TITLE], $request::$post[self::POST_PARAMETER_TEMPLATE], $request::$post[self::POST_PARAMETER_COMPONENT])) { |
|
| 255 | + $this->storage->saveSitemapItem($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
|
| 256 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/sitemap'); |
|
| 257 | + exit; |
|
| 258 | + } |
|
| 259 | + $this->parameters[self::PARAMETER_SITEMAP_ITEM] = $sitemapItem; |
|
| 260 | + } elseif ($relativeCmsUri == '/sitemap/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
| 261 | + $this->storage->deleteSitemapItemBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
| 262 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/sitemap'); |
|
| 263 | + exit; |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * @param $relativeCmsUri |
|
| 269 | + */ |
|
| 270 | + private function apiRouting($relativeCmsUri) |
|
| 271 | + { |
|
| 272 | + if ($relativeCmsUri == '/images.json') { |
|
| 273 | + header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
| 274 | + die(json_encode($this->storage->getImages())); |
|
| 275 | + } elseif ($relativeCmsUri == '/files.json') { |
|
| 276 | + header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
| 277 | + die(json_encode($this->storage->getFiles())); |
|
| 278 | + } elseif ($relativeCmsUri == '/documents.json') { |
|
| 279 | + header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
| 280 | + die(json_encode($this->storage->getDocuments())); |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * @param $request |
|
| 286 | + * @param $relativeCmsUri |
|
| 287 | + */ |
|
| 288 | + private function filesRouting($request, $relativeCmsUri) |
|
| 289 | + { |
|
| 290 | + if ($relativeCmsUri == '/files') { |
|
| 291 | + $this->subTemplate = 'cms/files'; |
|
| 292 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_FILES; |
|
| 293 | + $this->parameters[self::PARAMETER_FILES] = $this->storage->getFiles(); |
|
| 294 | + } elseif ($relativeCmsUri == '/files/new') { |
|
| 295 | + $this->subTemplate = 'cms/files/form'; |
|
| 296 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_FILES; |
|
| 297 | + if (isset($_FILES[self::FILES_PARAMETER_FILE])) { |
|
| 298 | + $this->storage->addFile($_FILES[self::FILES_PARAMETER_FILE]); |
|
| 299 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/files'); |
|
| 300 | + exit; |
|
| 301 | + } |
|
| 302 | + } elseif ($relativeCmsUri == '/files/get' && isset($request::$get[self::FILES_PARAMETER_FILE])) { |
|
| 303 | + $this->downloadFile($request::$get[self::FILES_PARAMETER_FILE]); |
|
| 304 | + } elseif ($relativeCmsUri == '/files/delete' && isset($request::$get[self::FILES_PARAMETER_FILE])) { |
|
| 305 | + $this->storage->deleteFileByName($request::$get[self::FILES_PARAMETER_FILE]); |
|
| 306 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/files'); |
|
| 307 | + exit; |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * @param $slug |
|
| 313 | + */ |
|
| 314 | + private function downloadFile($slug) |
|
| 315 | + { |
|
| 316 | + $file = $this->storage->getFileByName($slug); |
|
| 317 | + $path = realpath(__DIR__ . '/../../www/files/'); |
|
| 318 | + $quoted = sprintf('"%s"', addcslashes(basename($path . '/' . $file->file), '"\\')); |
|
| 319 | + $size = filesize($path . '/' . $file->file); |
|
| 320 | + |
|
| 321 | + header('Content-Description: File Transfer'); |
|
| 322 | + header('Content-Type: ' . $file->type); |
|
| 323 | + header('Content-Disposition: attachment; filename=' . $quoted); |
|
| 324 | + header('Content-Transfer-Encoding: binary'); |
|
| 325 | + header('Connection: Keep-Alive'); |
|
| 326 | + header('Expires: 0'); |
|
| 327 | + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
| 328 | + header('Pragma: public'); |
|
| 329 | + header('Content-Length: ' . $size); |
|
| 330 | + |
|
| 331 | + readfile($path . '/' . $file->file); |
|
| 332 | + exit; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * @param $request |
|
| 337 | + * @param $relativeCmsUri |
|
| 338 | + */ |
|
| 339 | + private function configurationRouting($request, $relativeCmsUri) |
|
| 340 | + { |
|
| 341 | + if ($relativeCmsUri == '/configuration') { |
|
| 342 | + $this->subTemplate = 'cms/configuration'; |
|
| 343 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + $this->usersRouting($request, $relativeCmsUri); |
|
| 347 | + $this->documentTypesRouting($request, $relativeCmsUri); |
|
| 348 | + $this->bricksRouting($request, $relativeCmsUri); |
|
| 349 | + $this->imageSetRouting($request, $relativeCmsUri); |
|
| 350 | + $this->applicationComponentRouting($request, $relativeCmsUri); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * @param $request |
|
| 356 | + * @param $relativeCmsUri |
|
| 357 | + */ |
|
| 358 | + private function usersRouting($request, $relativeCmsUri) |
|
| 359 | + { |
|
| 360 | + if ($relativeCmsUri == '/configuration/users') { |
|
| 361 | + $this->subTemplate = 'cms/configuration/users'; |
|
| 362 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 363 | + $this->parameters[self::PARAMETER_USERS] = $this->storage->getUsers(); |
|
| 364 | + } elseif ($relativeCmsUri == '/configuration/users/new') { |
|
| 365 | + $this->subTemplate = 'cms/configuration/users-form'; |
|
| 366 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 367 | + if (isset($_POST[self::POST_PARAMETER_USERNAME])) { |
|
| 368 | + $this->storage->addUser($request::$post); |
|
| 369 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/users'); |
|
| 370 | + exit; |
|
| 371 | + } |
|
| 372 | + } elseif ($relativeCmsUri == '/configuration/users/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
| 373 | + $this->storage->deleteUserBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
| 374 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/users'); |
|
| 375 | + exit; |
|
| 376 | + } elseif ($relativeCmsUri == '/configuration/users/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
| 377 | + $this->subTemplate = 'cms/configuration/users-form'; |
|
| 378 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 379 | + $this->parameters[self::PARAMETER_USER] = $this->storage->getUserBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
| 380 | + if (isset($_POST[self::POST_PARAMETER_USERNAME])) { |
|
| 381 | + $this->storage->saveUser($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
|
| 382 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/users'); |
|
| 383 | + exit; |
|
| 384 | + } |
|
| 385 | + } |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * @param $request |
|
| 390 | + * @param $relativeCmsUri |
|
| 391 | + */ |
|
| 392 | + private function documentTypesRouting($request, $relativeCmsUri) |
|
| 393 | + { |
|
| 394 | + if ($relativeCmsUri == '/configuration/document-types') { |
|
| 395 | + $this->subTemplate = 'cms/configuration/document-types'; |
|
| 396 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 397 | + $this->parameters[self::PARAMETER_DOCUMENT_TYPES] = $this->storage->getDocumentTypes(); |
|
| 398 | + } elseif ($relativeCmsUri == '/configuration/document-types/new') { |
|
| 399 | + $this->subTemplate = 'cms/configuration/document-types-form'; |
|
| 400 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 401 | + $bricks = $this->storage->getBricks(); |
|
| 402 | + if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
| 403 | + $this->storage->addDocumentType($request::$post); |
|
| 404 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/document-types'); |
|
| 405 | + exit; |
|
| 406 | + } |
|
| 407 | + $this->parameters[self::PARAMETER_BRICKS] = $bricks; |
|
| 408 | + } elseif ($relativeCmsUri == '/configuration/document-types/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
| 409 | + $this->subTemplate = 'cms/configuration/document-types-form'; |
|
| 410 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 411 | + $documentType = $this->storage->getDocumentTypeBySlug($request::$get[self::GET_PARAMETER_SLUG], false); |
|
| 412 | + $bricks = $this->storage->getBricks(); |
|
| 413 | + if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
| 414 | + $this->storage->saveDocumentType($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
|
| 415 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/document-types'); |
|
| 416 | + exit; |
|
| 417 | + } |
|
| 418 | + $this->parameters[self::PARAMETER_DOCUMENT_TYPE] = $documentType; |
|
| 419 | + $this->parameters[self::PARAMETER_BRICKS] = $bricks; |
|
| 420 | + } elseif ($relativeCmsUri == '/configuration/document-types/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
| 421 | + $this->storage->deleteDocumentTypeBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
| 422 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/document-types'); |
|
| 423 | + exit; |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + /** |
|
| 428 | + * @param $request |
|
| 429 | + * @param $relativeCmsUri |
|
| 430 | + */ |
|
| 431 | + private function bricksRouting($request, $relativeCmsUri) |
|
| 432 | + { |
|
| 433 | + if ($relativeCmsUri == '/configuration/bricks') { |
|
| 434 | + $this->subTemplate = 'cms/configuration/bricks'; |
|
| 435 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 436 | + $this->parameters[self::PARAMETER_BRICKS] = $this->storage->getBricks(); |
|
| 437 | + } elseif ($relativeCmsUri == '/configuration/bricks/new') { |
|
| 438 | + $this->subTemplate = 'cms/configuration/bricks-form'; |
|
| 439 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 440 | + if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
| 441 | + $this->storage->addBrick($request::$post); |
|
| 442 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/bricks'); |
|
| 443 | + exit; |
|
| 444 | + } |
|
| 445 | + } elseif ($relativeCmsUri == '/configuration/bricks/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
| 446 | + $this->subTemplate = 'cms/configuration/bricks-form'; |
|
| 447 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 448 | + $brick = $this->storage->getBrickBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
| 449 | + if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
| 450 | + $this->storage->saveBrick($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
|
| 451 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/bricks'); |
|
| 452 | + exit; |
|
| 453 | + } |
|
| 454 | + $this->parameters[self::PARAMETER_BRICK] = $brick; |
|
| 455 | + } elseif ($relativeCmsUri == '/configuration/bricks/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
| 456 | + $this->storage->deleteBrickBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
| 457 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/bricks'); |
|
| 458 | + exit; |
|
| 459 | + } elseif ($relativeCmsUri == '/configuration/image-set') { |
|
| 460 | + $this->subTemplate = 'cms/configuration/image-set'; |
|
| 461 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 462 | + $this->parameters[self::PARAMETER_IMAGE_SET] = $this->storage->getImageSet(); |
|
| 463 | + } |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + /** |
|
| 467 | + * @param $request |
|
| 468 | + * @param $relativeCmsUri |
|
| 469 | + */ |
|
| 470 | + private function imageSetRouting($request, $relativeCmsUri) |
|
| 471 | + { |
|
| 472 | + if ($relativeCmsUri == '/configuration/image-set') { |
|
| 473 | + $this->subTemplate = 'cms/configuration/image-set'; |
|
| 474 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 475 | + $this->parameters[self::PARAMETER_IMAGE_SET] = $this->storage->getImageSet(); |
|
| 476 | + } elseif ($relativeCmsUri == '/configuration/image-set/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
| 477 | + $this->subTemplate = 'cms/configuration/image-set-form'; |
|
| 478 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 479 | + $imageSet = $this->storage->getImageSetBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
| 480 | + if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
| 481 | + $this->storage->saveImageSet($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
|
| 482 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/image-set'); |
|
| 483 | + exit; |
|
| 484 | + } |
|
| 485 | + $this->parameters[self::PARAMETER_IMAGE_SET] = $imageSet; |
|
| 486 | + } elseif ($relativeCmsUri == '/configuration/image-set/new') { |
|
| 487 | + $this->subTemplate = 'cms/configuration/image-set-form'; |
|
| 488 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 489 | + if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
| 490 | + $this->storage->addImageSet($request::$post); |
|
| 491 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/image-set'); |
|
| 492 | + exit; |
|
| 493 | + } |
|
| 494 | + } elseif ($relativeCmsUri == '/configuration/image-set/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
| 495 | + $this->storage->deleteImageSetBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
| 496 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/image-set'); |
|
| 497 | + exit; |
|
| 498 | + } |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + /** |
|
| 502 | + * @param $request |
|
| 503 | + * @param $relativeCmsUri |
|
| 504 | + */ |
|
| 505 | + private function applicationComponentRouting($request, $relativeCmsUri) |
|
| 506 | + { |
|
| 507 | + if ($relativeCmsUri == '/configuration/application-components') { |
|
| 508 | + $this->subTemplate = 'cms/configuration/application-components'; |
|
| 509 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 510 | + $this->parameters['applicationComponents'] = $this->storage->getApplicationComponents(); |
|
| 511 | + } elseif ($relativeCmsUri == '/configuration/application-components/new') { |
|
| 512 | + $this->subTemplate = 'cms/configuration/application-components-form'; |
|
| 513 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 514 | + if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
| 515 | + $this->storage->addApplicationComponent($request::$post); |
|
| 516 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/application-components'); |
|
| 517 | + exit; |
|
| 518 | + } |
|
| 519 | + } elseif ($relativeCmsUri == '/configuration/application-components/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
| 520 | + $this->subTemplate = 'cms/configuration/application-components-form'; |
|
| 521 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
|
| 522 | + $applicationComponent = $this->storage->getApplicationComponentBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
| 523 | + if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
|
| 524 | + $this->storage->saveApplicationComponent($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
|
| 525 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/application-components'); |
|
| 526 | + exit; |
|
| 527 | + } |
|
| 528 | + $this->parameters['applicationComponent'] = $applicationComponent; |
|
| 529 | + } elseif ($relativeCmsUri == '/configuration/application-components/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
|
| 530 | + $this->storage->deleteApplicationComponentBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
|
| 531 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/application-components'); |
|
| 532 | + exit; |
|
| 533 | + } |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + private function logOffRouting($request, $relativeCmsUri) |
|
| 537 | + { |
|
| 538 | + if ($relativeCmsUri == '/log-off') { |
|
| 539 | + $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = null; |
|
| 540 | + unset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]); |
|
| 541 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX]); |
|
| 542 | + exit; |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + public function setParameter($parameterName, $parameterValue) |
|
| 547 | + { |
|
| 548 | + $this->parameters[$parameterName] = $parameterValue; |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + public function getParameter($parameterName) |
|
| 552 | + { |
|
| 553 | + return $this->parameters[$parameterName]; |
|
| 554 | + } |
|
| 555 | + } |
|
| 556 | 556 | } |
| 557 | 557 | \ No newline at end of file |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | $whitelistIps = explode(',', $this->parameters[self::PARAMETER_WHITELIST_IPS]); |
| 192 | 192 | $whitelistIps = array_map("trim", $whitelistIps); |
| 193 | 193 | if (!in_array($remoteAddress, $whitelistIps)) { |
| 194 | - throw new \Exception('Ip address ' . $remoteAddress . ' is not on whitelist'); |
|
| 194 | + throw new \Exception('Ip address '.$remoteAddress.' is not on whitelist'); |
|
| 195 | 195 | } |
| 196 | 196 | } |
| 197 | 197 | } |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | $blacklistIps = explode(',', $this->parameters[self::PARAMETER_BLACKLIST_IPS]); |
| 207 | 207 | $blacklistIps = array_map("trim", $blacklistIps); |
| 208 | 208 | if (in_array($remoteAddress, $blacklistIps)) { |
| 209 | - throw new \Exception('Ip address ' . $remoteAddress . ' is on blacklist'); |
|
| 209 | + throw new \Exception('Ip address '.$remoteAddress.' is on blacklist'); |
|
| 210 | 210 | } |
| 211 | 211 | } |
| 212 | 212 | } |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_SITEMAP; |
| 245 | 245 | if (isset($request::$post[self::POST_PARAMETER_TITLE], $request::$post[self::POST_PARAMETER_TEMPLATE], $request::$post[self::POST_PARAMETER_COMPONENT])) { |
| 246 | 246 | $this->storage->addSitemapItem($request::$post); |
| 247 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/sitemap'); |
|
| 247 | + header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/sitemap'); |
|
| 248 | 248 | exit; |
| 249 | 249 | } |
| 250 | 250 | } elseif ($relativeCmsUri == '/sitemap/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
@@ -253,13 +253,13 @@ discard block |
||
| 253 | 253 | $sitemapItem = $this->storage->getSitemapItemBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
| 254 | 254 | if (isset($request::$post[self::POST_PARAMETER_TITLE], $request::$post[self::POST_PARAMETER_TEMPLATE], $request::$post[self::POST_PARAMETER_COMPONENT])) { |
| 255 | 255 | $this->storage->saveSitemapItem($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
| 256 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/sitemap'); |
|
| 256 | + header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/sitemap'); |
|
| 257 | 257 | exit; |
| 258 | 258 | } |
| 259 | 259 | $this->parameters[self::PARAMETER_SITEMAP_ITEM] = $sitemapItem; |
| 260 | 260 | } elseif ($relativeCmsUri == '/sitemap/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
| 261 | 261 | $this->storage->deleteSitemapItemBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
| 262 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/sitemap'); |
|
| 262 | + header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/sitemap'); |
|
| 263 | 263 | exit; |
| 264 | 264 | } |
| 265 | 265 | } |
@@ -296,14 +296,14 @@ discard block |
||
| 296 | 296 | $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::PARAMETER_FILES; |
| 297 | 297 | if (isset($_FILES[self::FILES_PARAMETER_FILE])) { |
| 298 | 298 | $this->storage->addFile($_FILES[self::FILES_PARAMETER_FILE]); |
| 299 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/files'); |
|
| 299 | + header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/files'); |
|
| 300 | 300 | exit; |
| 301 | 301 | } |
| 302 | 302 | } elseif ($relativeCmsUri == '/files/get' && isset($request::$get[self::FILES_PARAMETER_FILE])) { |
| 303 | 303 | $this->downloadFile($request::$get[self::FILES_PARAMETER_FILE]); |
| 304 | 304 | } elseif ($relativeCmsUri == '/files/delete' && isset($request::$get[self::FILES_PARAMETER_FILE])) { |
| 305 | 305 | $this->storage->deleteFileByName($request::$get[self::FILES_PARAMETER_FILE]); |
| 306 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/files'); |
|
| 306 | + header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/files'); |
|
| 307 | 307 | exit; |
| 308 | 308 | } |
| 309 | 309 | } |
@@ -314,21 +314,21 @@ discard block |
||
| 314 | 314 | private function downloadFile($slug) |
| 315 | 315 | { |
| 316 | 316 | $file = $this->storage->getFileByName($slug); |
| 317 | - $path = realpath(__DIR__ . '/../../www/files/'); |
|
| 318 | - $quoted = sprintf('"%s"', addcslashes(basename($path . '/' . $file->file), '"\\')); |
|
| 319 | - $size = filesize($path . '/' . $file->file); |
|
| 317 | + $path = realpath(__DIR__.'/../../www/files/'); |
|
| 318 | + $quoted = sprintf('"%s"', addcslashes(basename($path.'/'.$file->file), '"\\')); |
|
| 319 | + $size = filesize($path.'/'.$file->file); |
|
| 320 | 320 | |
| 321 | 321 | header('Content-Description: File Transfer'); |
| 322 | - header('Content-Type: ' . $file->type); |
|
| 323 | - header('Content-Disposition: attachment; filename=' . $quoted); |
|
| 322 | + header('Content-Type: '.$file->type); |
|
| 323 | + header('Content-Disposition: attachment; filename='.$quoted); |
|
| 324 | 324 | header('Content-Transfer-Encoding: binary'); |
| 325 | 325 | header('Connection: Keep-Alive'); |
| 326 | 326 | header('Expires: 0'); |
| 327 | 327 | header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
| 328 | 328 | header('Pragma: public'); |
| 329 | - header('Content-Length: ' . $size); |
|
| 329 | + header('Content-Length: '.$size); |
|
| 330 | 330 | |
| 331 | - readfile($path . '/' . $file->file); |
|
| 331 | + readfile($path.'/'.$file->file); |
|
| 332 | 332 | exit; |
| 333 | 333 | } |
| 334 | 334 | |
@@ -366,12 +366,12 @@ discard block |
||
| 366 | 366 | $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
| 367 | 367 | if (isset($_POST[self::POST_PARAMETER_USERNAME])) { |
| 368 | 368 | $this->storage->addUser($request::$post); |
| 369 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/users'); |
|
| 369 | + header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/users'); |
|
| 370 | 370 | exit; |
| 371 | 371 | } |
| 372 | 372 | } elseif ($relativeCmsUri == '/configuration/users/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
| 373 | 373 | $this->storage->deleteUserBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
| 374 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/users'); |
|
| 374 | + header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/users'); |
|
| 375 | 375 | exit; |
| 376 | 376 | } elseif ($relativeCmsUri == '/configuration/users/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
| 377 | 377 | $this->subTemplate = 'cms/configuration/users-form'; |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | $this->parameters[self::PARAMETER_USER] = $this->storage->getUserBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
| 380 | 380 | if (isset($_POST[self::POST_PARAMETER_USERNAME])) { |
| 381 | 381 | $this->storage->saveUser($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
| 382 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/users'); |
|
| 382 | + header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/users'); |
|
| 383 | 383 | exit; |
| 384 | 384 | } |
| 385 | 385 | } |
@@ -401,7 +401,7 @@ discard block |
||
| 401 | 401 | $bricks = $this->storage->getBricks(); |
| 402 | 402 | if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
| 403 | 403 | $this->storage->addDocumentType($request::$post); |
| 404 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/document-types'); |
|
| 404 | + header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/document-types'); |
|
| 405 | 405 | exit; |
| 406 | 406 | } |
| 407 | 407 | $this->parameters[self::PARAMETER_BRICKS] = $bricks; |
@@ -412,14 +412,14 @@ discard block |
||
| 412 | 412 | $bricks = $this->storage->getBricks(); |
| 413 | 413 | if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
| 414 | 414 | $this->storage->saveDocumentType($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
| 415 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/document-types'); |
|
| 415 | + header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/document-types'); |
|
| 416 | 416 | exit; |
| 417 | 417 | } |
| 418 | 418 | $this->parameters[self::PARAMETER_DOCUMENT_TYPE] = $documentType; |
| 419 | 419 | $this->parameters[self::PARAMETER_BRICKS] = $bricks; |
| 420 | 420 | } elseif ($relativeCmsUri == '/configuration/document-types/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
| 421 | 421 | $this->storage->deleteDocumentTypeBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
| 422 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/document-types'); |
|
| 422 | + header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/document-types'); |
|
| 423 | 423 | exit; |
| 424 | 424 | } |
| 425 | 425 | } |
@@ -439,7 +439,7 @@ discard block |
||
| 439 | 439 | $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
| 440 | 440 | if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
| 441 | 441 | $this->storage->addBrick($request::$post); |
| 442 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/bricks'); |
|
| 442 | + header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/bricks'); |
|
| 443 | 443 | exit; |
| 444 | 444 | } |
| 445 | 445 | } elseif ($relativeCmsUri == '/configuration/bricks/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
@@ -448,13 +448,13 @@ discard block |
||
| 448 | 448 | $brick = $this->storage->getBrickBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
| 449 | 449 | if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
| 450 | 450 | $this->storage->saveBrick($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
| 451 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/bricks'); |
|
| 451 | + header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/bricks'); |
|
| 452 | 452 | exit; |
| 453 | 453 | } |
| 454 | 454 | $this->parameters[self::PARAMETER_BRICK] = $brick; |
| 455 | 455 | } elseif ($relativeCmsUri == '/configuration/bricks/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
| 456 | 456 | $this->storage->deleteBrickBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
| 457 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/bricks'); |
|
| 457 | + header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/bricks'); |
|
| 458 | 458 | exit; |
| 459 | 459 | } elseif ($relativeCmsUri == '/configuration/image-set') { |
| 460 | 460 | $this->subTemplate = 'cms/configuration/image-set'; |
@@ -479,7 +479,7 @@ discard block |
||
| 479 | 479 | $imageSet = $this->storage->getImageSetBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
| 480 | 480 | if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
| 481 | 481 | $this->storage->saveImageSet($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
| 482 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/image-set'); |
|
| 482 | + header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/image-set'); |
|
| 483 | 483 | exit; |
| 484 | 484 | } |
| 485 | 485 | $this->parameters[self::PARAMETER_IMAGE_SET] = $imageSet; |
@@ -488,12 +488,12 @@ discard block |
||
| 488 | 488 | $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
| 489 | 489 | if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
| 490 | 490 | $this->storage->addImageSet($request::$post); |
| 491 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/image-set'); |
|
| 491 | + header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/image-set'); |
|
| 492 | 492 | exit; |
| 493 | 493 | } |
| 494 | 494 | } elseif ($relativeCmsUri == '/configuration/image-set/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
| 495 | 495 | $this->storage->deleteImageSetBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
| 496 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/image-set'); |
|
| 496 | + header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/image-set'); |
|
| 497 | 497 | exit; |
| 498 | 498 | } |
| 499 | 499 | } |
@@ -513,7 +513,7 @@ discard block |
||
| 513 | 513 | $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = 'configuration'; |
| 514 | 514 | if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
| 515 | 515 | $this->storage->addApplicationComponent($request::$post); |
| 516 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/application-components'); |
|
| 516 | + header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/application-components'); |
|
| 517 | 517 | exit; |
| 518 | 518 | } |
| 519 | 519 | } elseif ($relativeCmsUri == '/configuration/application-components/edit' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
@@ -522,13 +522,13 @@ discard block |
||
| 522 | 522 | $applicationComponent = $this->storage->getApplicationComponentBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
| 523 | 523 | if (isset($request::$post[self::POST_PARAMETER_TITLE])) { |
| 524 | 524 | $this->storage->saveApplicationComponent($request::$get[self::GET_PARAMETER_SLUG], $request::$post); |
| 525 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/application-components'); |
|
| 525 | + header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/application-components'); |
|
| 526 | 526 | exit; |
| 527 | 527 | } |
| 528 | 528 | $this->parameters['applicationComponent'] = $applicationComponent; |
| 529 | 529 | } elseif ($relativeCmsUri == '/configuration/application-components/delete' && isset($request::$get[self::GET_PARAMETER_SLUG])) { |
| 530 | 530 | $this->storage->deleteApplicationComponentBySlug($request::$get[self::GET_PARAMETER_SLUG]); |
| 531 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX] . '/configuration/application-components'); |
|
| 531 | + header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX].'/configuration/application-components'); |
|
| 532 | 532 | exit; |
| 533 | 533 | } |
| 534 | 534 | } |
@@ -538,7 +538,7 @@ discard block |
||
| 538 | 538 | if ($relativeCmsUri == '/log-off') { |
| 539 | 539 | $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = null; |
| 540 | 540 | unset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]); |
| 541 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX]); |
|
| 541 | + header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX]); |
|
| 542 | 542 | exit; |
| 543 | 543 | } |
| 544 | 544 | } |