@@ -10,129 +10,129 @@ |
||
| 10 | 10 | |
| 11 | 11 | class UsersStorage extends AbstractStorage |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * Get all users |
|
| 15 | - * |
|
| 16 | - * @return mixed |
|
| 17 | - */ |
|
| 18 | - public function getUsers() |
|
| 19 | - { |
|
| 20 | - return $this->repository->users; |
|
| 21 | - } |
|
| 13 | + /** |
|
| 14 | + * Get all users |
|
| 15 | + * |
|
| 16 | + * @return mixed |
|
| 17 | + */ |
|
| 18 | + public function getUsers() |
|
| 19 | + { |
|
| 20 | + return $this->repository->users; |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Get user by slug |
|
| 25 | - * |
|
| 26 | - * @param $slug |
|
| 27 | - * |
|
| 28 | - * @return array |
|
| 29 | - */ |
|
| 30 | - public function getUserBySlug($slug) |
|
| 31 | - { |
|
| 32 | - $return = array(); |
|
| 23 | + /** |
|
| 24 | + * Get user by slug |
|
| 25 | + * |
|
| 26 | + * @param $slug |
|
| 27 | + * |
|
| 28 | + * @return array |
|
| 29 | + */ |
|
| 30 | + public function getUserBySlug($slug) |
|
| 31 | + { |
|
| 32 | + $return = array(); |
|
| 33 | 33 | |
| 34 | - $users = $this->repository->users; |
|
| 35 | - foreach ($users as $user) { |
|
| 36 | - if ($user->slug == $slug) { |
|
| 37 | - $return = $user; |
|
| 38 | - break; |
|
| 39 | - } |
|
| 40 | - } |
|
| 34 | + $users = $this->repository->users; |
|
| 35 | + foreach ($users as $user) { |
|
| 36 | + if ($user->slug == $slug) { |
|
| 37 | + $return = $user; |
|
| 38 | + break; |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - return $return; |
|
| 43 | - } |
|
| 42 | + return $return; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Save user |
|
| 47 | - * |
|
| 48 | - * @param $slug |
|
| 49 | - * @param $postValues |
|
| 50 | - * |
|
| 51 | - * @throws \Exception |
|
| 52 | - */ |
|
| 53 | - public function saveUser($slug, $postValues) |
|
| 54 | - { |
|
| 55 | - $userObj = UserFactory::createUserFromPostValues($postValues); |
|
| 56 | - if ($userObj->slug != $slug) { |
|
| 57 | - // If the username changed, check for duplicates |
|
| 58 | - $doesItExist = $this->getUserBySlug($userObj->slug); |
|
| 59 | - if (!empty($doesItExist)) { |
|
| 60 | - throw new \Exception('Trying to rename user to existing username'); |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - $users = $this->getUsers(); |
|
| 64 | - foreach ($users as $key => $user) { |
|
| 65 | - if ($user->slug == $slug) { |
|
| 66 | - $users[$key] = $userObj; |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - $this->repository->users = $users; |
|
| 70 | - $this->save(); |
|
| 71 | - } |
|
| 45 | + /** |
|
| 46 | + * Save user |
|
| 47 | + * |
|
| 48 | + * @param $slug |
|
| 49 | + * @param $postValues |
|
| 50 | + * |
|
| 51 | + * @throws \Exception |
|
| 52 | + */ |
|
| 53 | + public function saveUser($slug, $postValues) |
|
| 54 | + { |
|
| 55 | + $userObj = UserFactory::createUserFromPostValues($postValues); |
|
| 56 | + if ($userObj->slug != $slug) { |
|
| 57 | + // If the username changed, check for duplicates |
|
| 58 | + $doesItExist = $this->getUserBySlug($userObj->slug); |
|
| 59 | + if (!empty($doesItExist)) { |
|
| 60 | + throw new \Exception('Trying to rename user to existing username'); |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + $users = $this->getUsers(); |
|
| 64 | + foreach ($users as $key => $user) { |
|
| 65 | + if ($user->slug == $slug) { |
|
| 66 | + $users[$key] = $userObj; |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + $this->repository->users = $users; |
|
| 70 | + $this->save(); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Add user |
|
| 75 | - * |
|
| 76 | - * @param $postValues |
|
| 77 | - * |
|
| 78 | - * @throws \Exception |
|
| 79 | - */ |
|
| 80 | - public function addUser($postValues) |
|
| 81 | - { |
|
| 82 | - $userObj = UserFactory::createUserFromPostValues($postValues); |
|
| 73 | + /** |
|
| 74 | + * Add user |
|
| 75 | + * |
|
| 76 | + * @param $postValues |
|
| 77 | + * |
|
| 78 | + * @throws \Exception |
|
| 79 | + */ |
|
| 80 | + public function addUser($postValues) |
|
| 81 | + { |
|
| 82 | + $userObj = UserFactory::createUserFromPostValues($postValues); |
|
| 83 | 83 | |
| 84 | - $doesItExist = $this->getUserBySlug($userObj->slug); |
|
| 85 | - if (!empty($doesItExist)) { |
|
| 86 | - throw new \Exception('Trying to add username that already exists.'); |
|
| 87 | - } |
|
| 88 | - $users = $this->repository->users; |
|
| 89 | - $users[] = $userObj; |
|
| 90 | - $this->repository->users = $users; |
|
| 91 | - $this->save(); |
|
| 92 | - } |
|
| 84 | + $doesItExist = $this->getUserBySlug($userObj->slug); |
|
| 85 | + if (!empty($doesItExist)) { |
|
| 86 | + throw new \Exception('Trying to add username that already exists.'); |
|
| 87 | + } |
|
| 88 | + $users = $this->repository->users; |
|
| 89 | + $users[] = $userObj; |
|
| 90 | + $this->repository->users = $users; |
|
| 91 | + $this->save(); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Delete user by slug |
|
| 96 | - * |
|
| 97 | - * @param $slug |
|
| 98 | - * |
|
| 99 | - * @throws \Exception |
|
| 100 | - */ |
|
| 101 | - public function deleteUserBySlug($slug) |
|
| 102 | - { |
|
| 103 | - $userToDelete = $this->getUserBySlug($slug); |
|
| 104 | - if (empty($userToDelete)) { |
|
| 105 | - throw new \Exception('Trying to delete a user that doesn\'t exist.'); |
|
| 106 | - } |
|
| 107 | - $users = $this->getUsers(); |
|
| 108 | - foreach ($users as $key => $user) { |
|
| 109 | - if ($user->slug == $userToDelete->slug) { |
|
| 110 | - unset($users[$key]); |
|
| 111 | - $this->repository->users = array_values($users); |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - $this->save(); |
|
| 115 | - } |
|
| 94 | + /** |
|
| 95 | + * Delete user by slug |
|
| 96 | + * |
|
| 97 | + * @param $slug |
|
| 98 | + * |
|
| 99 | + * @throws \Exception |
|
| 100 | + */ |
|
| 101 | + public function deleteUserBySlug($slug) |
|
| 102 | + { |
|
| 103 | + $userToDelete = $this->getUserBySlug($slug); |
|
| 104 | + if (empty($userToDelete)) { |
|
| 105 | + throw new \Exception('Trying to delete a user that doesn\'t exist.'); |
|
| 106 | + } |
|
| 107 | + $users = $this->getUsers(); |
|
| 108 | + foreach ($users as $key => $user) { |
|
| 109 | + if ($user->slug == $userToDelete->slug) { |
|
| 110 | + unset($users[$key]); |
|
| 111 | + $this->repository->users = array_values($users); |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + $this->save(); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Get user by username |
|
| 119 | - * |
|
| 120 | - * @param $username |
|
| 121 | - * |
|
| 122 | - * @return array |
|
| 123 | - */ |
|
| 124 | - public function getUserByUsername($username) |
|
| 125 | - { |
|
| 126 | - $return = array(); |
|
| 117 | + /** |
|
| 118 | + * Get user by username |
|
| 119 | + * |
|
| 120 | + * @param $username |
|
| 121 | + * |
|
| 122 | + * @return array |
|
| 123 | + */ |
|
| 124 | + public function getUserByUsername($username) |
|
| 125 | + { |
|
| 126 | + $return = array(); |
|
| 127 | 127 | |
| 128 | - $users = $this->repository->users; |
|
| 129 | - foreach ($users as $user) { |
|
| 130 | - if ($user->username == $username) { |
|
| 131 | - $return = $user; |
|
| 132 | - break; |
|
| 133 | - } |
|
| 134 | - } |
|
| 128 | + $users = $this->repository->users; |
|
| 129 | + foreach ($users as $user) { |
|
| 130 | + if ($user->username == $username) { |
|
| 131 | + $return = $user; |
|
| 132 | + break; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - return $return; |
|
| 137 | - } |
|
| 136 | + return $return; |
|
| 137 | + } |
|
| 138 | 138 | } |
| 139 | 139 | \ No newline at end of file |
@@ -8,97 +8,97 @@ |
||
| 8 | 8 | |
| 9 | 9 | class FilesStorage extends AbstractStorage |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * @return array |
|
| 13 | - */ |
|
| 14 | - public function getFiles() { |
|
| 15 | - $files = $this->repository->files; |
|
| 16 | - usort($files, array($this, 'compareFiles')); |
|
| 11 | + /** |
|
| 12 | + * @return array |
|
| 13 | + */ |
|
| 14 | + public function getFiles() { |
|
| 15 | + $files = $this->repository->files; |
|
| 16 | + usort($files, array($this, 'compareFiles')); |
|
| 17 | 17 | |
| 18 | - return $files; |
|
| 19 | - } |
|
| 18 | + return $files; |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @param $postValues |
|
| 23 | - * |
|
| 24 | - * @throws \Exception |
|
| 25 | - */ |
|
| 26 | - public function addFile($postValues) |
|
| 27 | - { |
|
| 28 | - $destinationPath = realpath(__DIR__ . '/../../../www/files/'); |
|
| 21 | + /** |
|
| 22 | + * @param $postValues |
|
| 23 | + * |
|
| 24 | + * @throws \Exception |
|
| 25 | + */ |
|
| 26 | + public function addFile($postValues) |
|
| 27 | + { |
|
| 28 | + $destinationPath = realpath(__DIR__ . '/../../../www/files/'); |
|
| 29 | 29 | |
| 30 | - $filename = $this->validateFilename($postValues['name'], $destinationPath); |
|
| 31 | - $destination = $destinationPath . '/' . $filename; |
|
| 30 | + $filename = $this->validateFilename($postValues['name'], $destinationPath); |
|
| 31 | + $destination = $destinationPath . '/' . $filename; |
|
| 32 | 32 | |
| 33 | - if ($postValues['error'] != '0') { |
|
| 34 | - throw new \Exception('Error uploading file. Error code: ' . $postValues['error']); |
|
| 35 | - } |
|
| 33 | + if ($postValues['error'] != '0') { |
|
| 34 | + throw new \Exception('Error uploading file. Error code: ' . $postValues['error']); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - if (move_uploaded_file($postValues['tmp_name'], $destination)) { |
|
| 38 | - $file = new \stdClass(); |
|
| 39 | - $file->file = $filename; |
|
| 40 | - $file->type = $postValues['type']; |
|
| 41 | - $file->size = $postValues['size']; |
|
| 37 | + if (move_uploaded_file($postValues['tmp_name'], $destination)) { |
|
| 38 | + $file = new \stdClass(); |
|
| 39 | + $file->file = $filename; |
|
| 40 | + $file->type = $postValues['type']; |
|
| 41 | + $file->size = $postValues['size']; |
|
| 42 | 42 | |
| 43 | - $files = $this->repository->files; |
|
| 44 | - $files[] = $file; |
|
| 45 | - $this->repository->files = $files; |
|
| 46 | - $this->save(); |
|
| 47 | - } else { |
|
| 48 | - throw new \Exception('Error moving uploaded file'); |
|
| 49 | - } |
|
| 50 | - } |
|
| 43 | + $files = $this->repository->files; |
|
| 44 | + $files[] = $file; |
|
| 45 | + $this->repository->files = $files; |
|
| 46 | + $this->save(); |
|
| 47 | + } else { |
|
| 48 | + throw new \Exception('Error moving uploaded file'); |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @param $filename |
|
| 54 | - * |
|
| 55 | - * @return null |
|
| 56 | - */ |
|
| 57 | - public function getFileByName($filename) |
|
| 58 | - { |
|
| 59 | - $files = $this->getFiles(); |
|
| 60 | - foreach ($files as $file) { |
|
| 61 | - if ($filename == $file->file) { |
|
| 62 | - return $file; |
|
| 63 | - } |
|
| 64 | - } |
|
| 52 | + /** |
|
| 53 | + * @param $filename |
|
| 54 | + * |
|
| 55 | + * @return null |
|
| 56 | + */ |
|
| 57 | + public function getFileByName($filename) |
|
| 58 | + { |
|
| 59 | + $files = $this->getFiles(); |
|
| 60 | + foreach ($files as $file) { |
|
| 61 | + if ($filename == $file->file) { |
|
| 62 | + return $file; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - return null; |
|
| 67 | - } |
|
| 66 | + return null; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @param $filename |
|
| 71 | - * |
|
| 72 | - * @throws \Exception |
|
| 73 | - */ |
|
| 74 | - public function deleteFileByName($filename) |
|
| 75 | - { |
|
| 76 | - $destinationPath = realpath(__DIR__ . '/../../../www/files/'); |
|
| 77 | - $destination = $destinationPath . '/' . $filename; |
|
| 69 | + /** |
|
| 70 | + * @param $filename |
|
| 71 | + * |
|
| 72 | + * @throws \Exception |
|
| 73 | + */ |
|
| 74 | + public function deleteFileByName($filename) |
|
| 75 | + { |
|
| 76 | + $destinationPath = realpath(__DIR__ . '/../../../www/files/'); |
|
| 77 | + $destination = $destinationPath . '/' . $filename; |
|
| 78 | 78 | |
| 79 | - if (file_exists($destination)) { |
|
| 80 | - $files = $this->getFiles(); |
|
| 81 | - foreach ($files as $key => $file) { |
|
| 82 | - if ($file->file == $filename) { |
|
| 83 | - unlink($destination); |
|
| 84 | - unset($files[$key]); |
|
| 85 | - } |
|
| 86 | - } |
|
| 79 | + if (file_exists($destination)) { |
|
| 80 | + $files = $this->getFiles(); |
|
| 81 | + foreach ($files as $key => $file) { |
|
| 82 | + if ($file->file == $filename) { |
|
| 83 | + unlink($destination); |
|
| 84 | + unset($files[$key]); |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - $files = array_values($files); |
|
| 89 | - $this->repository->files = $files; |
|
| 90 | - $this->save(); |
|
| 91 | - } |
|
| 92 | - } |
|
| 88 | + $files = array_values($files); |
|
| 89 | + $this->repository->files = $files; |
|
| 90 | + $this->save(); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * @param $a |
|
| 96 | - * @param $b |
|
| 97 | - * |
|
| 98 | - * @return int |
|
| 99 | - */ |
|
| 100 | - private function compareFiles($a, $b) |
|
| 101 | - { |
|
| 102 | - return strcmp($a->file, $b->file); |
|
| 103 | - } |
|
| 94 | + /** |
|
| 95 | + * @param $a |
|
| 96 | + * @param $b |
|
| 97 | + * |
|
| 98 | + * @return int |
|
| 99 | + */ |
|
| 100 | + private function compareFiles($a, $b) |
|
| 101 | + { |
|
| 102 | + return strcmp($a->file, $b->file); |
|
| 103 | + } |
|
| 104 | 104 | } |
| 105 | 105 | \ No newline at end of file |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | $host = $this; |
| 154 | 154 | array_map(function ($value) use ($host) { |
| 155 | 155 | $host->saveSubset($value); |
| 156 | - }, $this->fileBasedSubsets); |
|
| 156 | + }, $this->fileBasedSubsets); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -162,18 +162,18 @@ discard block |
||
| 162 | 162 | */ |
| 163 | 163 | public function saveSubset($subset) |
| 164 | 164 | { |
| 165 | - $changes = $subset . 'Changes'; |
|
| 166 | - if ($this->$changes === true) { |
|
| 165 | + $changes = $subset . 'Changes'; |
|
| 166 | + if ($this->$changes === true) { |
|
| 167 | 167 | if (!defined('JSON_PRETTY_PRINT')) { |
| 168 | 168 | $json = json_encode($this->$subset); |
| 169 | 169 | } else { |
| 170 | 170 | $json = json_encode($this->$subset, JSON_PRETTY_PRINT); |
| 171 | 171 | } |
| 172 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
| 173 | - file_put_contents($subsetStoragePath, $json); |
|
| 172 | + $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
| 173 | + file_put_contents($subsetStoragePath, $json); |
|
| 174 | 174 | |
| 175 | - $this->$changes = false; |
|
| 176 | - } |
|
| 175 | + $this->$changes = false; |
|
| 176 | + } |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -240,33 +240,33 @@ discard block |
||
| 240 | 240 | return $this->contentDbHandle; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - /** |
|
| 244 | - * Get all documents |
|
| 245 | - * |
|
| 246 | - * @param string $state |
|
| 247 | - * |
|
| 248 | - * @return array |
|
| 249 | - * @throws \Exception |
|
| 250 | - */ |
|
| 243 | + /** |
|
| 244 | + * Get all documents |
|
| 245 | + * |
|
| 246 | + * @param string $state |
|
| 247 | + * |
|
| 248 | + * @return array |
|
| 249 | + * @throws \Exception |
|
| 250 | + */ |
|
| 251 | 251 | public function getDocuments($state = 'published') |
| 252 | 252 | { |
| 253 | - if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
| 254 | - throw new \Exception('Unsupported document state: ' . $state); |
|
| 255 | - } |
|
| 253 | + if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
| 254 | + throw new \Exception('Unsupported document state: ' . $state); |
|
| 255 | + } |
|
| 256 | 256 | return $this->getDocumentsByPath('/', $state); |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - public function getDocumentsWithState($folderPath = '/') |
|
| 260 | - { |
|
| 261 | - $db = $this->getContentDbHandle(); |
|
| 262 | - $folderPathWithWildcard = $folderPath . '%'; |
|
| 259 | + public function getDocumentsWithState($folderPath = '/') |
|
| 260 | + { |
|
| 261 | + $db = $this->getContentDbHandle(); |
|
| 262 | + $folderPathWithWildcard = $folderPath . '%'; |
|
| 263 | 263 | |
| 264 | - $ifRootIndex = 1; |
|
| 265 | - if ($folderPath == '/') { |
|
| 266 | - $ifRootIndex = 0; |
|
| 267 | - } |
|
| 264 | + $ifRootIndex = 1; |
|
| 265 | + if ($folderPath == '/') { |
|
| 266 | + $ifRootIndex = 0; |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | - $sql = ' |
|
| 269 | + $sql = ' |
|
| 270 | 270 | SELECT documents_unpublished.*, |
| 271 | 271 | IFNULL(documents_published.state,"unpublished") as state, |
| 272 | 272 | IFNULL(documents_published.publicationDate,NULL) as publicationDate, |
@@ -280,32 +280,32 @@ discard block |
||
| 280 | 280 | AND documents_unpublished.path != ' . $db->quote($folderPath) . ' |
| 281 | 281 | ORDER BY documents_unpublished.`type` DESC, documents_unpublished.`path` ASC |
| 282 | 282 | '; |
| 283 | - $stmt = $this->getDbStatement($sql); |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - |
|
| 287 | - $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\CloudControl\Cms\storage\Document'); |
|
| 288 | - foreach ($documents as $key => $document) { |
|
| 289 | - $documents = $this->setAssetsToDocumentFolders($document, $db, $documents, $key); |
|
| 290 | - } |
|
| 291 | - //dump($documents); |
|
| 292 | - return $documents; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * Get all documents and folders in a certain path |
|
| 297 | - * |
|
| 298 | - * @param $folderPath |
|
| 299 | - * @param string $state |
|
| 300 | - * |
|
| 301 | - * @return array |
|
| 302 | - * @throws \Exception |
|
| 303 | - */ |
|
| 283 | + $stmt = $this->getDbStatement($sql); |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + |
|
| 287 | + $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\CloudControl\Cms\storage\Document'); |
|
| 288 | + foreach ($documents as $key => $document) { |
|
| 289 | + $documents = $this->setAssetsToDocumentFolders($document, $db, $documents, $key); |
|
| 290 | + } |
|
| 291 | + //dump($documents); |
|
| 292 | + return $documents; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * Get all documents and folders in a certain path |
|
| 297 | + * |
|
| 298 | + * @param $folderPath |
|
| 299 | + * @param string $state |
|
| 300 | + * |
|
| 301 | + * @return array |
|
| 302 | + * @throws \Exception |
|
| 303 | + */ |
|
| 304 | 304 | public function getDocumentsByPath($folderPath, $state = 'published') |
| 305 | 305 | { |
| 306 | - if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
| 307 | - throw new \Exception('Unsupported document state: ' . $state); |
|
| 308 | - } |
|
| 306 | + if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
| 307 | + throw new \Exception('Unsupported document state: ' . $state); |
|
| 308 | + } |
|
| 309 | 309 | $db = $this->getContentDbHandle(); |
| 310 | 310 | $folderPathWithWildcard = $folderPath . '%'; |
| 311 | 311 | |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | |
| 320 | 320 | $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\CloudControl\Cms\storage\Document'); |
| 321 | 321 | foreach ($documents as $key => $document) { |
| 322 | - $documents = $this->setAssetsToDocumentFolders($document, $db, $documents, $key); |
|
| 322 | + $documents = $this->setAssetsToDocumentFolders($document, $db, $documents, $key); |
|
| 323 | 323 | } |
| 324 | 324 | return $documents; |
| 325 | 325 | } |
@@ -341,24 +341,24 @@ discard block |
||
| 341 | 341 | return $this->getRootFolder(); |
| 342 | 342 | } |
| 343 | 343 | if (substr($containerPath, -1) === '/'){ |
| 344 | - $containerPath = substr($containerPath, 0, -1); |
|
| 345 | - } |
|
| 344 | + $containerPath = substr($containerPath, 0, -1); |
|
| 345 | + } |
|
| 346 | 346 | $containerFolder = $this->getDocumentByPath($containerPath, 'unpublished'); |
| 347 | 347 | return $containerFolder; |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | - /** |
|
| 351 | - * @param $path |
|
| 352 | - * @param string $state |
|
| 353 | - * |
|
| 354 | - * @return bool|\CloudControl\Cms\storage\Document |
|
| 355 | - * @throws \Exception |
|
| 356 | - */ |
|
| 350 | + /** |
|
| 351 | + * @param $path |
|
| 352 | + * @param string $state |
|
| 353 | + * |
|
| 354 | + * @return bool|\CloudControl\Cms\storage\Document |
|
| 355 | + * @throws \Exception |
|
| 356 | + */ |
|
| 357 | 357 | public function getDocumentByPath($path, $state = 'published') |
| 358 | 358 | { |
| 359 | - if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
| 360 | - throw new \Exception('Unsupported document state: ' . $state); |
|
| 361 | - } |
|
| 359 | + if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
| 360 | + throw new \Exception('Unsupported document state: ' . $state); |
|
| 361 | + } |
|
| 362 | 362 | $db = $this->getContentDbHandle(); |
| 363 | 363 | $document = $this->fetchDocument(' |
| 364 | 364 | SELECT * |
@@ -372,87 +372,87 @@ discard block |
||
| 372 | 372 | return $document; |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - /** |
|
| 376 | - * Returns the count of all documents stored in the db |
|
| 377 | - * |
|
| 378 | - * @param string $state |
|
| 379 | - * |
|
| 380 | - * @return int |
|
| 381 | - * @throws \Exception |
|
| 382 | - */ |
|
| 383 | - public function getTotalDocumentCount($state = 'published') |
|
| 384 | - { |
|
| 385 | - if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
| 386 | - throw new \Exception('Unsupported document state: ' . $state); |
|
| 387 | - } |
|
| 388 | - $db = $this->getContentDbHandle(); |
|
| 389 | - $stmt = $db->query(' |
|
| 375 | + /** |
|
| 376 | + * Returns the count of all documents stored in the db |
|
| 377 | + * |
|
| 378 | + * @param string $state |
|
| 379 | + * |
|
| 380 | + * @return int |
|
| 381 | + * @throws \Exception |
|
| 382 | + */ |
|
| 383 | + public function getTotalDocumentCount($state = 'published') |
|
| 384 | + { |
|
| 385 | + if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
| 386 | + throw new \Exception('Unsupported document state: ' . $state); |
|
| 387 | + } |
|
| 388 | + $db = $this->getContentDbHandle(); |
|
| 389 | + $stmt = $db->query(' |
|
| 390 | 390 | SELECT count(*) |
| 391 | 391 | FROM documents_' . $state . ' |
| 392 | 392 | WHERE `type` != "folder" |
| 393 | 393 | '); |
| 394 | - $result = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
| 395 | - if (!is_array($result )) { |
|
| 396 | - return 0; |
|
| 397 | - } |
|
| 398 | - return intval(current($result)); |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - public function getPublishedDocumentsNoFolders() |
|
| 402 | - { |
|
| 403 | - $db = $this->getContentDbHandle(); |
|
| 404 | - $sql = ' |
|
| 394 | + $result = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
| 395 | + if (!is_array($result )) { |
|
| 396 | + return 0; |
|
| 397 | + } |
|
| 398 | + return intval(current($result)); |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + public function getPublishedDocumentsNoFolders() |
|
| 402 | + { |
|
| 403 | + $db = $this->getContentDbHandle(); |
|
| 404 | + $sql = ' |
|
| 405 | 405 | SELECT * |
| 406 | 406 | FROM documents_published |
| 407 | 407 | WHERE `type` != "folder" |
| 408 | 408 | '; |
| 409 | - $stmt = $db->query($sql); |
|
| 410 | - $result = $stmt->fetchAll(\PDO::FETCH_CLASS, '\CloudControl\Cms\storage\Document'); |
|
| 411 | - if ($stmt === false || !$stmt->execute()) { |
|
| 412 | - $errorInfo = $db->errorInfo(); |
|
| 413 | - $errorMsg = $errorInfo[2]; |
|
| 414 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
| 415 | - } |
|
| 416 | - return $result; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - private function publishOrUnpublishDocumentByPath($path, $publish = true) { |
|
| 420 | - if ($publish) { |
|
| 421 | - $sql = ' |
|
| 409 | + $stmt = $db->query($sql); |
|
| 410 | + $result = $stmt->fetchAll(\PDO::FETCH_CLASS, '\CloudControl\Cms\storage\Document'); |
|
| 411 | + if ($stmt === false || !$stmt->execute()) { |
|
| 412 | + $errorInfo = $db->errorInfo(); |
|
| 413 | + $errorMsg = $errorInfo[2]; |
|
| 414 | + throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
| 415 | + } |
|
| 416 | + return $result; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + private function publishOrUnpublishDocumentByPath($path, $publish = true) { |
|
| 420 | + if ($publish) { |
|
| 421 | + $sql = ' |
|
| 422 | 422 | INSERT OR REPLACE INTO documents_published |
| 423 | 423 | (`id`,`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`publicationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
| 424 | 424 | SELECT `id`,`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,"published" as state,`lastModificationDate`,`creationDate`,' . time() . ' as publicationDate, `lastModifiedBy`,`fields`,`bricks`,`dynamicBricks` |
| 425 | 425 | FROM documents_unpublished |
| 426 | 426 | WHERE `path` = :path |
| 427 | 427 | '; |
| 428 | - } else { |
|
| 429 | - $sql = 'DELETE FROM documents_published |
|
| 428 | + } else { |
|
| 429 | + $sql = 'DELETE FROM documents_published |
|
| 430 | 430 | WHERE `path` = :path'; |
| 431 | - } |
|
| 432 | - $db = $this->getContentDbHandle(); |
|
| 433 | - $stmt = $db->prepare($sql); |
|
| 434 | - if ($stmt === false) { |
|
| 435 | - $errorInfo = $db->errorInfo(); |
|
| 436 | - $errorMsg = $errorInfo[2]; |
|
| 437 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
| 438 | - } |
|
| 439 | - $stmt->bindValue(':path', $path); |
|
| 440 | - $stmt->execute(); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - public function publishDocumentByPath($path) |
|
| 444 | - { |
|
| 445 | - $this->publishOrUnpublishDocumentByPath($path); |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - public function unpublishDocumentByPath($path) |
|
| 449 | - { |
|
| 450 | - $this->publishOrUnpublishDocumentByPath($path, false); |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - public function cleanPublishedDeletedDocuments() |
|
| 454 | - { |
|
| 455 | - $sql = ' DELETE FROM documents_published |
|
| 431 | + } |
|
| 432 | + $db = $this->getContentDbHandle(); |
|
| 433 | + $stmt = $db->prepare($sql); |
|
| 434 | + if ($stmt === false) { |
|
| 435 | + $errorInfo = $db->errorInfo(); |
|
| 436 | + $errorMsg = $errorInfo[2]; |
|
| 437 | + throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
| 438 | + } |
|
| 439 | + $stmt->bindValue(':path', $path); |
|
| 440 | + $stmt->execute(); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + public function publishDocumentByPath($path) |
|
| 444 | + { |
|
| 445 | + $this->publishOrUnpublishDocumentByPath($path); |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + public function unpublishDocumentByPath($path) |
|
| 449 | + { |
|
| 450 | + $this->publishOrUnpublishDocumentByPath($path, false); |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + public function cleanPublishedDeletedDocuments() |
|
| 454 | + { |
|
| 455 | + $sql = ' DELETE FROM documents_published |
|
| 456 | 456 | WHERE documents_published.path IN ( |
| 457 | 457 | SELECT documents_published.path |
| 458 | 458 | FROM documents_published |
@@ -460,11 +460,11 @@ discard block |
||
| 460 | 460 | ON documents_unpublished.path = documents_published.path |
| 461 | 461 | WHERE documents_unpublished.path IS NULL |
| 462 | 462 | )'; |
| 463 | - $stmt = $this->getDbStatement($sql); |
|
| 464 | - $stmt->execute(); |
|
| 465 | - } |
|
| 463 | + $stmt = $this->getDbStatement($sql); |
|
| 464 | + $stmt->execute(); |
|
| 465 | + } |
|
| 466 | 466 | |
| 467 | - /** |
|
| 467 | + /** |
|
| 468 | 468 | * Return the results of the query as array of Documents |
| 469 | 469 | * @param $sql |
| 470 | 470 | * @return array |
@@ -518,21 +518,21 @@ discard block |
||
| 518 | 518 | return $rootFolder; |
| 519 | 519 | } |
| 520 | 520 | |
| 521 | - /** |
|
| 522 | - * Save the document to the database |
|
| 523 | - * |
|
| 524 | - * @param Document $documentObject |
|
| 525 | - * @param string $state |
|
| 526 | - * |
|
| 527 | - * @return bool |
|
| 528 | - * @throws \Exception |
|
| 529 | - * @internal param $path |
|
| 530 | - */ |
|
| 521 | + /** |
|
| 522 | + * Save the document to the database |
|
| 523 | + * |
|
| 524 | + * @param Document $documentObject |
|
| 525 | + * @param string $state |
|
| 526 | + * |
|
| 527 | + * @return bool |
|
| 528 | + * @throws \Exception |
|
| 529 | + * @internal param $path |
|
| 530 | + */ |
|
| 531 | 531 | public function saveDocument($documentObject, $state = 'published') |
| 532 | 532 | { |
| 533 | - if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
| 534 | - throw new \Exception('Unsupported document state: ' . $state); |
|
| 535 | - } |
|
| 533 | + if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
| 534 | + throw new \Exception('Unsupported document state: ' . $state); |
|
| 535 | + } |
|
| 536 | 536 | $db = $this->getContentDbHandle(); |
| 537 | 537 | $stmt = $this->getDbStatement(' |
| 538 | 538 | INSERT OR REPLACE INTO documents_' . $state . ' (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
@@ -556,15 +556,15 @@ discard block |
||
| 556 | 556 | return $result; |
| 557 | 557 | } |
| 558 | 558 | |
| 559 | - /** |
|
| 560 | - * Delete the document from the database |
|
| 561 | - * If it's a folder, also delete it's contents |
|
| 562 | - * |
|
| 563 | - * @param $path |
|
| 564 | - * |
|
| 565 | - * @internal param string $state |
|
| 566 | - * |
|
| 567 | - */ |
|
| 559 | + /** |
|
| 560 | + * Delete the document from the database |
|
| 561 | + * If it's a folder, also delete it's contents |
|
| 562 | + * |
|
| 563 | + * @param $path |
|
| 564 | + * |
|
| 565 | + * @internal param string $state |
|
| 566 | + * |
|
| 567 | + */ |
|
| 568 | 568 | public function deleteDocumentByPath($path) |
| 569 | 569 | { |
| 570 | 570 | $db = $this->getContentDbHandle(); |
@@ -589,22 +589,22 @@ discard block |
||
| 589 | 589 | } |
| 590 | 590 | } |
| 591 | 591 | |
| 592 | - /** |
|
| 593 | - * @param $document |
|
| 594 | - * @param $db |
|
| 595 | - * @param $documents |
|
| 596 | - * @param $key |
|
| 597 | - * |
|
| 598 | - * @return mixed |
|
| 599 | - */ |
|
| 600 | - private function setAssetsToDocumentFolders($document, $db, $documents, $key) |
|
| 601 | - { |
|
| 602 | - if ($document->type === 'folder') { |
|
| 603 | - $document->dbHandle = $db; |
|
| 604 | - $document->documentStorage = new DocumentStorage($this); |
|
| 605 | - $documents[$key] = $document; |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - return $documents; |
|
| 609 | - } |
|
| 592 | + /** |
|
| 593 | + * @param $document |
|
| 594 | + * @param $db |
|
| 595 | + * @param $documents |
|
| 596 | + * @param $key |
|
| 597 | + * |
|
| 598 | + * @return mixed |
|
| 599 | + */ |
|
| 600 | + private function setAssetsToDocumentFolders($document, $db, $documents, $key) |
|
| 601 | + { |
|
| 602 | + if ($document->type === 'folder') { |
|
| 603 | + $document->dbHandle = $db; |
|
| 604 | + $document->documentStorage = new DocumentStorage($this); |
|
| 605 | + $documents[$key] = $document; |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + return $documents; |
|
| 609 | + } |
|
| 610 | 610 | } |
| 611 | 611 | \ No newline at end of file |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | public function save() |
| 152 | 152 | { |
| 153 | 153 | $host = $this; |
| 154 | - array_map(function ($value) use ($host) { |
|
| 154 | + array_map(function($value) use ($host) { |
|
| 155 | 155 | $host->saveSubset($value); |
| 156 | 156 | }, $this->fileBasedSubsets); |
| 157 | 157 | } |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | if ($containerPath === '/') { |
| 341 | 341 | return $this->getRootFolder(); |
| 342 | 342 | } |
| 343 | - if (substr($containerPath, -1) === '/'){ |
|
| 343 | + if (substr($containerPath, -1) === '/') { |
|
| 344 | 344 | $containerPath = substr($containerPath, 0, -1); |
| 345 | 345 | } |
| 346 | 346 | $containerFolder = $this->getDocumentByPath($containerPath, 'unpublished'); |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | WHERE `type` != "folder" |
| 393 | 393 | '); |
| 394 | 394 | $result = $stmt->fetch(\PDO::FETCH_ASSOC); |
| 395 | - if (!is_array($result )) { |
|
| 395 | + if (!is_array($result)) { |
|
| 396 | 396 | return 0; |
| 397 | 397 | } |
| 398 | 398 | return intval(current($result)); |
@@ -15,52 +15,52 @@ discard block |
||
| 15 | 15 | use CloudControl\Cms\storage\storage\ValuelistsStorage; |
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | - * Class JsonStorage |
|
| 18 | + * Class JsonStorage |
|
| 19 | 19 | * @package CloudControl\Cms\storage |
| 20 | - */ |
|
| 21 | - class Storage |
|
| 22 | - { |
|
| 23 | - /** |
|
| 24 | - * @var SitemapStorage |
|
| 25 | - */ |
|
| 26 | - protected $sitemap; |
|
| 27 | - /** |
|
| 28 | - * @var ImagesStorage |
|
| 29 | - */ |
|
| 30 | - protected $images; |
|
| 31 | - /** |
|
| 32 | - * @var ImageSetStorage |
|
| 33 | - */ |
|
| 34 | - protected $imageSet; |
|
| 35 | - /** |
|
| 36 | - * @var FilesStorage |
|
| 37 | - */ |
|
| 38 | - protected $files; |
|
| 39 | - /** |
|
| 40 | - * @var UsersStorage |
|
| 41 | - */ |
|
| 42 | - protected $users; |
|
| 43 | - /** |
|
| 44 | - * @var DocumentTypesStorage |
|
| 45 | - */ |
|
| 46 | - protected $documentTypes; |
|
| 47 | - /** |
|
| 48 | - * @var BricksStorage |
|
| 49 | - */ |
|
| 50 | - protected $bricks; |
|
| 51 | - /** |
|
| 52 | - * @var ApplicationComponentsStorage |
|
| 53 | - */ |
|
| 54 | - protected $applicationComponents; |
|
| 20 | + */ |
|
| 21 | + class Storage |
|
| 22 | + { |
|
| 23 | + /** |
|
| 24 | + * @var SitemapStorage |
|
| 25 | + */ |
|
| 26 | + protected $sitemap; |
|
| 27 | + /** |
|
| 28 | + * @var ImagesStorage |
|
| 29 | + */ |
|
| 30 | + protected $images; |
|
| 31 | + /** |
|
| 32 | + * @var ImageSetStorage |
|
| 33 | + */ |
|
| 34 | + protected $imageSet; |
|
| 35 | + /** |
|
| 36 | + * @var FilesStorage |
|
| 37 | + */ |
|
| 38 | + protected $files; |
|
| 39 | + /** |
|
| 40 | + * @var UsersStorage |
|
| 41 | + */ |
|
| 42 | + protected $users; |
|
| 43 | + /** |
|
| 44 | + * @var DocumentTypesStorage |
|
| 45 | + */ |
|
| 46 | + protected $documentTypes; |
|
| 47 | + /** |
|
| 48 | + * @var BricksStorage |
|
| 49 | + */ |
|
| 50 | + protected $bricks; |
|
| 51 | + /** |
|
| 52 | + * @var ApplicationComponentsStorage |
|
| 53 | + */ |
|
| 54 | + protected $applicationComponents; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @var ValuelistsStorage |
|
| 58 | - */ |
|
| 59 | - protected $valuelists; |
|
| 60 | - /** |
|
| 61 | - * @var DocumentStorage |
|
| 62 | - */ |
|
| 63 | - protected $documents; |
|
| 56 | + /** |
|
| 57 | + * @var ValuelistsStorage |
|
| 58 | + */ |
|
| 59 | + protected $valuelists; |
|
| 60 | + /** |
|
| 61 | + * @var DocumentStorage |
|
| 62 | + */ |
|
| 63 | + protected $documents; |
|
| 64 | 64 | /** |
| 65 | 65 | * @var RedirectsStorage |
| 66 | 66 | */ |
@@ -75,13 +75,13 @@ discard block |
||
| 75 | 75 | protected $filesDir; |
| 76 | 76 | |
| 77 | 77 | /** |
| 78 | - * @var String |
|
| 79 | - */ |
|
| 80 | - private $storageDir; |
|
| 81 | - /** |
|
| 82 | - * @var Repository |
|
| 83 | - */ |
|
| 84 | - private $repository; |
|
| 78 | + * @var String |
|
| 79 | + */ |
|
| 80 | + private $storageDir; |
|
| 81 | + /** |
|
| 82 | + * @var Repository |
|
| 83 | + */ |
|
| 84 | + private $repository; |
|
| 85 | 85 | |
| 86 | 86 | /** |
| 87 | 87 | * JsonStorage constructor. |
@@ -91,251 +91,251 @@ discard block |
||
| 91 | 91 | * @param $filesDir |
| 92 | 92 | */ |
| 93 | 93 | public function __construct($storageDir, $imagesDir, $filesDir) |
| 94 | - { |
|
| 95 | - $this->storageDir = $storageDir; |
|
| 94 | + { |
|
| 95 | + $this->storageDir = $storageDir; |
|
| 96 | 96 | $this->imagesDir = $imagesDir; |
| 97 | 97 | $this->filesDir = $filesDir; |
| 98 | - $this->config(); |
|
| 99 | - } |
|
| 98 | + $this->config(); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Retrieve the data from the storagepath |
|
| 103 | - * so it can be interacted with |
|
| 104 | - * |
|
| 105 | - * @throws \Exception |
|
| 106 | - */ |
|
| 107 | - private function config() |
|
| 108 | - { |
|
| 109 | - $storagePath = $this->storageDir; |
|
| 110 | - if (realpath($storagePath) === false) { |
|
| 111 | - if (Repository::create($storagePath)) { |
|
| 112 | - $repository = new Repository($storagePath); |
|
| 113 | - $repository->init(); |
|
| 114 | - $this->repository = $repository; |
|
| 115 | - } else { |
|
| 116 | - throw new \Exception('Could not create repository directory: ' . $storagePath); |
|
| 117 | - } |
|
| 118 | - } else { |
|
| 119 | - $this->repository = new Repository($storagePath); |
|
| 120 | - } |
|
| 101 | + /** |
|
| 102 | + * Retrieve the data from the storagepath |
|
| 103 | + * so it can be interacted with |
|
| 104 | + * |
|
| 105 | + * @throws \Exception |
|
| 106 | + */ |
|
| 107 | + private function config() |
|
| 108 | + { |
|
| 109 | + $storagePath = $this->storageDir; |
|
| 110 | + if (realpath($storagePath) === false) { |
|
| 111 | + if (Repository::create($storagePath)) { |
|
| 112 | + $repository = new Repository($storagePath); |
|
| 113 | + $repository->init(); |
|
| 114 | + $this->repository = $repository; |
|
| 115 | + } else { |
|
| 116 | + throw new \Exception('Could not create repository directory: ' . $storagePath); |
|
| 117 | + } |
|
| 118 | + } else { |
|
| 119 | + $this->repository = new Repository($storagePath); |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - } |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * @return \CloudControl\Cms\storage\storage\UsersStorage |
|
| 126 | - */ |
|
| 127 | - public function getUsers() |
|
| 128 | - { |
|
| 129 | - if (!$this->users instanceof UsersStorage) { |
|
| 130 | - $this->users = new UsersStorage($this->repository); |
|
| 131 | - } |
|
| 132 | - return $this->users; |
|
| 133 | - } |
|
| 124 | + /** |
|
| 125 | + * @return \CloudControl\Cms\storage\storage\UsersStorage |
|
| 126 | + */ |
|
| 127 | + public function getUsers() |
|
| 128 | + { |
|
| 129 | + if (!$this->users instanceof UsersStorage) { |
|
| 130 | + $this->users = new UsersStorage($this->repository); |
|
| 131 | + } |
|
| 132 | + return $this->users; |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * Get documents |
|
| 137 | - * |
|
| 138 | - * @return DocumentStorage |
|
| 139 | - */ |
|
| 140 | - public function getDocuments() |
|
| 141 | - { |
|
| 142 | - if (!$this->documents instanceof DocumentStorage) { |
|
| 143 | - $this->documents = new DocumentStorage($this->repository); |
|
| 144 | - } |
|
| 145 | - return $this->documents; |
|
| 146 | - } |
|
| 135 | + /** |
|
| 136 | + * Get documents |
|
| 137 | + * |
|
| 138 | + * @return DocumentStorage |
|
| 139 | + */ |
|
| 140 | + public function getDocuments() |
|
| 141 | + { |
|
| 142 | + if (!$this->documents instanceof DocumentStorage) { |
|
| 143 | + $this->documents = new DocumentStorage($this->repository); |
|
| 144 | + } |
|
| 145 | + return $this->documents; |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - /** |
|
| 149 | - * Add new document in given path |
|
| 150 | - * |
|
| 151 | - * @param array $postValues |
|
| 152 | - * |
|
| 153 | - * @throws \Exception |
|
| 154 | - */ |
|
| 155 | - public function addDocumentFolder($postValues) |
|
| 156 | - { |
|
| 157 | - $documentFolderObject = DocumentFolderFactory::createDocumentFolderFromPostValues($postValues); |
|
| 158 | - if ($postValues['path'] === '/') { |
|
| 159 | - $documentFolderObject->path = $postValues['path'] . $documentFolderObject->slug; |
|
| 160 | - } else { |
|
| 161 | - $documentFolderObject->path = $postValues['path'] . '/' . $documentFolderObject->slug; |
|
| 162 | - } |
|
| 163 | - $this->repository->saveDocument($documentFolderObject, 'published'); |
|
| 164 | - $this->repository->saveDocument($documentFolderObject, 'unpublished'); |
|
| 165 | - } |
|
| 148 | + /** |
|
| 149 | + * Add new document in given path |
|
| 150 | + * |
|
| 151 | + * @param array $postValues |
|
| 152 | + * |
|
| 153 | + * @throws \Exception |
|
| 154 | + */ |
|
| 155 | + public function addDocumentFolder($postValues) |
|
| 156 | + { |
|
| 157 | + $documentFolderObject = DocumentFolderFactory::createDocumentFolderFromPostValues($postValues); |
|
| 158 | + if ($postValues['path'] === '/') { |
|
| 159 | + $documentFolderObject->path = $postValues['path'] . $documentFolderObject->slug; |
|
| 160 | + } else { |
|
| 161 | + $documentFolderObject->path = $postValues['path'] . '/' . $documentFolderObject->slug; |
|
| 162 | + } |
|
| 163 | + $this->repository->saveDocument($documentFolderObject, 'published'); |
|
| 164 | + $this->repository->saveDocument($documentFolderObject, 'unpublished'); |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * Delete a folder by its compound slug |
|
| 169 | - * |
|
| 170 | - * @param $slug |
|
| 171 | - * |
|
| 172 | - * @throws \Exception |
|
| 173 | - */ |
|
| 174 | - public function deleteDocumentFolderBySlug($slug) |
|
| 175 | - { |
|
| 176 | - $path = '/' . $slug; |
|
| 177 | - $this->repository->deleteDocumentByPath($path, 'published'); |
|
| 178 | - $this->repository->deleteDocumentByPath($path, 'unpublished'); |
|
| 179 | - $this->repository->cleanPublishedDeletedDocuments(); |
|
| 180 | - } |
|
| 167 | + /** |
|
| 168 | + * Delete a folder by its compound slug |
|
| 169 | + * |
|
| 170 | + * @param $slug |
|
| 171 | + * |
|
| 172 | + * @throws \Exception |
|
| 173 | + */ |
|
| 174 | + public function deleteDocumentFolderBySlug($slug) |
|
| 175 | + { |
|
| 176 | + $path = '/' . $slug; |
|
| 177 | + $this->repository->deleteDocumentByPath($path, 'published'); |
|
| 178 | + $this->repository->deleteDocumentByPath($path, 'unpublished'); |
|
| 179 | + $this->repository->cleanPublishedDeletedDocuments(); |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - public function publishDocumentBySlug($slug) |
|
| 183 | - { |
|
| 184 | - $path = '/' . $slug; |
|
| 185 | - $this->repository->publishDocumentByPath($path); |
|
| 186 | - } |
|
| 182 | + public function publishDocumentBySlug($slug) |
|
| 183 | + { |
|
| 184 | + $path = '/' . $slug; |
|
| 185 | + $this->repository->publishDocumentByPath($path); |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - public function unpublishDocumentBySlug($slug) |
|
| 189 | - { |
|
| 190 | - $path = '/' . $slug; |
|
| 191 | - $this->repository->unpublishDocumentByPath($path); |
|
| 192 | - } |
|
| 188 | + public function unpublishDocumentBySlug($slug) |
|
| 189 | + { |
|
| 190 | + $path = '/' . $slug; |
|
| 191 | + $this->repository->unpublishDocumentByPath($path); |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | - /** |
|
| 195 | - * Retrieve a folder by its compound slug |
|
| 196 | - * |
|
| 197 | - * @param $slug |
|
| 198 | - * |
|
| 199 | - * @return mixed |
|
| 200 | - * @throws \Exception |
|
| 201 | - */ |
|
| 202 | - public function getDocumentFolderBySlug($slug) |
|
| 203 | - { |
|
| 204 | - $path = '/' . $slug; |
|
| 194 | + /** |
|
| 195 | + * Retrieve a folder by its compound slug |
|
| 196 | + * |
|
| 197 | + * @param $slug |
|
| 198 | + * |
|
| 199 | + * @return mixed |
|
| 200 | + * @throws \Exception |
|
| 201 | + */ |
|
| 202 | + public function getDocumentFolderBySlug($slug) |
|
| 203 | + { |
|
| 204 | + $path = '/' . $slug; |
|
| 205 | 205 | |
| 206 | - return $this->repository->getDocumentByPath($path); |
|
| 207 | - } |
|
| 206 | + return $this->repository->getDocumentByPath($path); |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Save changes to folder |
|
| 211 | - * |
|
| 212 | - * @param $postValues |
|
| 213 | - * |
|
| 214 | - * @throws \Exception |
|
| 215 | - */ |
|
| 216 | - public function saveDocumentFolder($postValues) |
|
| 217 | - { |
|
| 218 | - $this->addDocumentFolder($postValues); |
|
| 219 | - } |
|
| 209 | + /** |
|
| 210 | + * Save changes to folder |
|
| 211 | + * |
|
| 212 | + * @param $postValues |
|
| 213 | + * |
|
| 214 | + * @throws \Exception |
|
| 215 | + */ |
|
| 216 | + public function saveDocumentFolder($postValues) |
|
| 217 | + { |
|
| 218 | + $this->addDocumentFolder($postValues); |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - /** |
|
| 222 | - * @return SitemapStorage |
|
| 223 | - */ |
|
| 224 | - public function getSitemap() |
|
| 225 | - { |
|
| 226 | - if (!$this->sitemap instanceof SitemapStorage) { |
|
| 227 | - $this->sitemap = new SitemapStorage($this->repository); |
|
| 228 | - } |
|
| 229 | - return $this->sitemap; |
|
| 230 | - } |
|
| 221 | + /** |
|
| 222 | + * @return SitemapStorage |
|
| 223 | + */ |
|
| 224 | + public function getSitemap() |
|
| 225 | + { |
|
| 226 | + if (!$this->sitemap instanceof SitemapStorage) { |
|
| 227 | + $this->sitemap = new SitemapStorage($this->repository); |
|
| 228 | + } |
|
| 229 | + return $this->sitemap; |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - /** |
|
| 233 | - * Get all images |
|
| 234 | - * |
|
| 235 | - * @return ImagesStorage |
|
| 236 | - */ |
|
| 237 | - public function getImages() |
|
| 238 | - { |
|
| 239 | - if (!$this->images instanceof ImagesStorage) { |
|
| 232 | + /** |
|
| 233 | + * Get all images |
|
| 234 | + * |
|
| 235 | + * @return ImagesStorage |
|
| 236 | + */ |
|
| 237 | + public function getImages() |
|
| 238 | + { |
|
| 239 | + if (!$this->images instanceof ImagesStorage) { |
|
| 240 | 240 | |
| 241 | 241 | $this->images = new ImagesStorage($this->repository, $this->imagesDir); |
| 242 | - } |
|
| 243 | - return $this->images; |
|
| 244 | - } |
|
| 242 | + } |
|
| 243 | + return $this->images; |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - /** |
|
| 247 | - * Get all files |
|
| 248 | - * |
|
| 249 | - * @return FilesStorage |
|
| 250 | - */ |
|
| 251 | - public function getFiles() |
|
| 252 | - { |
|
| 253 | - if (!$this->files instanceof FilesStorage) { |
|
| 254 | - $this->files = new FilesStorage($this->repository); |
|
| 255 | - } |
|
| 256 | - return $this->files; |
|
| 257 | - } |
|
| 246 | + /** |
|
| 247 | + * Get all files |
|
| 248 | + * |
|
| 249 | + * @return FilesStorage |
|
| 250 | + */ |
|
| 251 | + public function getFiles() |
|
| 252 | + { |
|
| 253 | + if (!$this->files instanceof FilesStorage) { |
|
| 254 | + $this->files = new FilesStorage($this->repository); |
|
| 255 | + } |
|
| 256 | + return $this->files; |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | - /** |
|
| 260 | - * @return string |
|
| 261 | - */ |
|
| 262 | - public function getStorageDir() |
|
| 263 | - { |
|
| 264 | - return $this->storageDir; |
|
| 265 | - } |
|
| 259 | + /** |
|
| 260 | + * @return string |
|
| 261 | + */ |
|
| 262 | + public function getStorageDir() |
|
| 263 | + { |
|
| 264 | + return $this->storageDir; |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - /** |
|
| 268 | - * @return \PDO |
|
| 269 | - */ |
|
| 270 | - public function getContentDbHandle() |
|
| 271 | - { |
|
| 272 | - return $this->repository->getContentDbHandle(); |
|
| 273 | - } |
|
| 267 | + /** |
|
| 268 | + * @return \PDO |
|
| 269 | + */ |
|
| 270 | + public function getContentDbHandle() |
|
| 271 | + { |
|
| 272 | + return $this->repository->getContentDbHandle(); |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | - /** |
|
| 276 | - * @return DocumentTypesStorage |
|
| 277 | - */ |
|
| 278 | - public function getDocumentTypes() |
|
| 279 | - { |
|
| 280 | - if (!$this->documentTypes instanceof DocumentTypesStorage) { |
|
| 281 | - $this->documentTypes = new DocumentTypesStorage($this->repository); |
|
| 282 | - } |
|
| 283 | - return $this->documentTypes; |
|
| 284 | - } |
|
| 275 | + /** |
|
| 276 | + * @return DocumentTypesStorage |
|
| 277 | + */ |
|
| 278 | + public function getDocumentTypes() |
|
| 279 | + { |
|
| 280 | + if (!$this->documentTypes instanceof DocumentTypesStorage) { |
|
| 281 | + $this->documentTypes = new DocumentTypesStorage($this->repository); |
|
| 282 | + } |
|
| 283 | + return $this->documentTypes; |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | - /** |
|
| 287 | - * @return BricksStorage |
|
| 288 | - */ |
|
| 289 | - public function getBricks() |
|
| 290 | - { |
|
| 291 | - if (!$this->bricks instanceof BricksStorage) { |
|
| 292 | - $this->bricks = new BricksStorage($this->repository); |
|
| 293 | - } |
|
| 294 | - return $this->bricks; |
|
| 295 | - } |
|
| 286 | + /** |
|
| 287 | + * @return BricksStorage |
|
| 288 | + */ |
|
| 289 | + public function getBricks() |
|
| 290 | + { |
|
| 291 | + if (!$this->bricks instanceof BricksStorage) { |
|
| 292 | + $this->bricks = new BricksStorage($this->repository); |
|
| 293 | + } |
|
| 294 | + return $this->bricks; |
|
| 295 | + } |
|
| 296 | 296 | |
| 297 | - /** |
|
| 298 | - * Get the image set |
|
| 299 | - * |
|
| 300 | - * @return ImageSetStorage |
|
| 301 | - */ |
|
| 302 | - public function getImageSet() |
|
| 303 | - { |
|
| 304 | - if (!$this->imageSet instanceof ImageSetStorage) { |
|
| 305 | - $this->imageSet = new ImageSetStorage($this->repository); |
|
| 306 | - } |
|
| 307 | - return $this->imageSet; |
|
| 308 | - } |
|
| 297 | + /** |
|
| 298 | + * Get the image set |
|
| 299 | + * |
|
| 300 | + * @return ImageSetStorage |
|
| 301 | + */ |
|
| 302 | + public function getImageSet() |
|
| 303 | + { |
|
| 304 | + if (!$this->imageSet instanceof ImageSetStorage) { |
|
| 305 | + $this->imageSet = new ImageSetStorage($this->repository); |
|
| 306 | + } |
|
| 307 | + return $this->imageSet; |
|
| 308 | + } |
|
| 309 | 309 | |
| 310 | - /** |
|
| 311 | - * @return ApplicationComponentsStorage |
|
| 312 | - */ |
|
| 313 | - public function getApplicationComponents() |
|
| 314 | - { |
|
| 315 | - if (!$this->applicationComponents instanceof ApplicationComponentsStorage) { |
|
| 316 | - $this->applicationComponents = new ApplicationComponentsStorage($this->repository); |
|
| 317 | - } |
|
| 318 | - return $this->applicationComponents; |
|
| 319 | - } |
|
| 310 | + /** |
|
| 311 | + * @return ApplicationComponentsStorage |
|
| 312 | + */ |
|
| 313 | + public function getApplicationComponents() |
|
| 314 | + { |
|
| 315 | + if (!$this->applicationComponents instanceof ApplicationComponentsStorage) { |
|
| 316 | + $this->applicationComponents = new ApplicationComponentsStorage($this->repository); |
|
| 317 | + } |
|
| 318 | + return $this->applicationComponents; |
|
| 319 | + } |
|
| 320 | 320 | |
| 321 | - /** |
|
| 322 | - * @return \CloudControl\Cms\storage\Repository |
|
| 323 | - */ |
|
| 324 | - public function getRepository() |
|
| 325 | - { |
|
| 326 | - return $this->repository; |
|
| 327 | - } |
|
| 321 | + /** |
|
| 322 | + * @return \CloudControl\Cms\storage\Repository |
|
| 323 | + */ |
|
| 324 | + public function getRepository() |
|
| 325 | + { |
|
| 326 | + return $this->repository; |
|
| 327 | + } |
|
| 328 | 328 | |
| 329 | - /** |
|
| 330 | - * @return \CloudControl\Cms\storage\storage\ValuelistsStorage |
|
| 331 | - */ |
|
| 332 | - public function getValuelists() |
|
| 333 | - { |
|
| 334 | - if (!$this->valuelists instanceof ValuelistsStorage) { |
|
| 335 | - $this->valuelists = new ValuelistsStorage($this->repository); |
|
| 336 | - } |
|
| 337 | - return $this->valuelists; |
|
| 338 | - } |
|
| 329 | + /** |
|
| 330 | + * @return \CloudControl\Cms\storage\storage\ValuelistsStorage |
|
| 331 | + */ |
|
| 332 | + public function getValuelists() |
|
| 333 | + { |
|
| 334 | + if (!$this->valuelists instanceof ValuelistsStorage) { |
|
| 335 | + $this->valuelists = new ValuelistsStorage($this->repository); |
|
| 336 | + } |
|
| 337 | + return $this->valuelists; |
|
| 338 | + } |
|
| 339 | 339 | |
| 340 | 340 | /** |
| 341 | 341 | * @return \CloudControl\Cms\storage\storage\RedirectsStorage |
@@ -348,5 +348,5 @@ discard block |
||
| 348 | 348 | return $this->redirects; |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | - } |
|
| 351 | + } |
|
| 352 | 352 | } |
| 353 | 353 | \ No newline at end of file |
@@ -9,14 +9,14 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | function dump() |
| 11 | 11 | { |
| 12 | - $debug_backtrace = current(debug_backtrace()); |
|
| 13 | - if (PHP_SAPI == 'cli') { |
|
| 14 | - echo 'Dump: ' . $debug_backtrace['file'] . ':' . $debug_backtrace['line'] . "\n"; |
|
| 15 | - foreach (func_get_args() as $data) { |
|
| 16 | - var_dump($data); |
|
| 17 | - } |
|
| 18 | - } else { |
|
| 19 | - ob_clean(); |
|
| 12 | + $debug_backtrace = current(debug_backtrace()); |
|
| 13 | + if (PHP_SAPI == 'cli') { |
|
| 14 | + echo 'Dump: ' . $debug_backtrace['file'] . ':' . $debug_backtrace['line'] . "\n"; |
|
| 15 | + foreach (func_get_args() as $data) { |
|
| 16 | + var_dump($data); |
|
| 17 | + } |
|
| 18 | + } else { |
|
| 19 | + ob_clean(); |
|
| 20 | 20 | echo <<<END |
| 21 | 21 | <!DOCTYPE html> |
| 22 | 22 | <html> |
@@ -29,20 +29,20 @@ discard block |
||
| 29 | 29 | <body> |
| 30 | 30 | END; |
| 31 | 31 | |
| 32 | - echo '<div>Dump: ' . $debug_backtrace['file'] . ':<b>' . $debug_backtrace['line'] . "</b></div>"; |
|
| 33 | - echo '<pre>'; |
|
| 34 | - foreach (func_get_args() as $data) { |
|
| 35 | - echo "<code>"; |
|
| 36 | - var_dump($data); |
|
| 37 | - echo "</code>"; |
|
| 38 | - } |
|
| 39 | - echo '</pre>'; |
|
| 40 | - echo <<<END |
|
| 32 | + echo '<div>Dump: ' . $debug_backtrace['file'] . ':<b>' . $debug_backtrace['line'] . "</b></div>"; |
|
| 33 | + echo '<pre>'; |
|
| 34 | + foreach (func_get_args() as $data) { |
|
| 35 | + echo "<code>"; |
|
| 36 | + var_dump($data); |
|
| 37 | + echo "</code>"; |
|
| 38 | + } |
|
| 39 | + echo '</pre>'; |
|
| 40 | + echo <<<END |
|
| 41 | 41 | </body> |
| 42 | 42 | </html> |
| 43 | 43 | END; |
| 44 | - } |
|
| 45 | - die; |
|
| 44 | + } |
|
| 45 | + die; |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -53,11 +53,11 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | function utf8Convert($array) |
| 55 | 55 | { |
| 56 | - array_walk_recursive($array, function(&$item){ |
|
| 57 | - if(!mb_detect_encoding($item, 'utf-8', true)){ |
|
| 58 | - $item = utf8_encode($item); |
|
| 59 | - } |
|
| 60 | - }); |
|
| 56 | + array_walk_recursive($array, function(&$item){ |
|
| 57 | + if(!mb_detect_encoding($item, 'utf-8', true)){ |
|
| 58 | + $item = utf8_encode($item); |
|
| 59 | + } |
|
| 60 | + }); |
|
| 61 | 61 | |
| 62 | - return $array; |
|
| 62 | + return $array; |
|
| 63 | 63 | } |
| 64 | 64 | \ No newline at end of file |
@@ -53,8 +53,8 @@ |
||
| 53 | 53 | */ |
| 54 | 54 | function utf8Convert($array) |
| 55 | 55 | { |
| 56 | - array_walk_recursive($array, function(&$item){ |
|
| 57 | - if(!mb_detect_encoding($item, 'utf-8', true)){ |
|
| 56 | + array_walk_recursive($array, function(&$item) { |
|
| 57 | + if (!mb_detect_encoding($item, 'utf-8', true)) { |
|
| 58 | 58 | $item = utf8_encode($item); |
| 59 | 59 | } |
| 60 | 60 | }); |
@@ -98,7 +98,7 @@ |
||
| 98 | 98 | $this->sessionValues = $_SESSION['LanguageComponent']; |
| 99 | 99 | |
| 100 | 100 | if ($this->forceRedirect === true) { |
| 101 | - if (substr($request::$relativeUri, 0, 2) !== $lang ) { |
|
| 101 | + if (substr($request::$relativeUri, 0, 2) !== $lang) { |
|
| 102 | 102 | if ($lang !== $this->defaultLanguage) { |
| 103 | 103 | header('Location: ' . $request::$subfolders . $lang . '/' . $request::$relativeUri); |
| 104 | 104 | exit; |
@@ -11,51 +11,51 @@ discard block |
||
| 11 | 11 | use CloudControl\Cms\storage\Storage; |
| 12 | 12 | |
| 13 | 13 | class CmsComponent extends BaseComponent |
| 14 | - { |
|
| 14 | + { |
|
| 15 | 15 | /** |
| 16 | - * @var \CloudControl\Cms\storage\Storage |
|
| 17 | - */ |
|
| 18 | - public $storage; |
|
| 19 | - |
|
| 20 | - const INVALID_CREDENTIALS_MESSAGE = 'Invalid username / password combination'; |
|
| 21 | - |
|
| 22 | - const MAIN_NAV_CLASS = 'default'; |
|
| 23 | - |
|
| 24 | - const PARAMETER_APPLICATION_COMPONENT = 'applicationComponent'; |
|
| 25 | - const PARAMETER_APPLICATION_COMPONENTS = 'applicationComponents'; |
|
| 26 | - const PARAMETER_BLACKLIST_IPS = 'blacklistIps'; |
|
| 27 | - const PARAMETER_BODY = 'body'; |
|
| 28 | - const PARAMETER_BRICK = 'brick'; |
|
| 29 | - const PARAMETER_BRICKS = 'bricks'; |
|
| 30 | - const PARAMETER_CMS_PREFIX = 'cmsPrefix'; |
|
| 31 | - const PARAMETER_CONFIGURATION = 'configuration'; |
|
| 32 | - const PARAMETER_DOCUMENT = 'document'; |
|
| 33 | - const PARAMETER_DOCUMENTS = 'documents'; |
|
| 34 | - const PARAMETER_DOCUMENT_TYPE = 'documentType'; |
|
| 35 | - const PARAMETER_DOCUMENT_TYPES = 'documentTypes'; |
|
| 36 | - const PARAMETER_ERROR_MESSAGE = 'errorMsg'; |
|
| 37 | - const PARAMETER_FILES = 'files'; |
|
| 38 | - const PARAMETER_FOLDER = 'folder'; |
|
| 39 | - const PARAMETER_IMAGE = 'image'; |
|
| 40 | - const PARAMETER_IMAGES = 'images'; |
|
| 41 | - const PARAMETER_IMAGE_SET = 'imageSet'; |
|
| 42 | - const PARAMETER_MAIN_NAV_CLASS = 'mainNavClass'; |
|
| 43 | - const PARAMETER_MY_BRICK_SLUG = 'myBrickSlug'; |
|
| 16 | + * @var \CloudControl\Cms\storage\Storage |
|
| 17 | + */ |
|
| 18 | + public $storage; |
|
| 19 | + |
|
| 20 | + const INVALID_CREDENTIALS_MESSAGE = 'Invalid username / password combination'; |
|
| 21 | + |
|
| 22 | + const MAIN_NAV_CLASS = 'default'; |
|
| 23 | + |
|
| 24 | + const PARAMETER_APPLICATION_COMPONENT = 'applicationComponent'; |
|
| 25 | + const PARAMETER_APPLICATION_COMPONENTS = 'applicationComponents'; |
|
| 26 | + const PARAMETER_BLACKLIST_IPS = 'blacklistIps'; |
|
| 27 | + const PARAMETER_BODY = 'body'; |
|
| 28 | + const PARAMETER_BRICK = 'brick'; |
|
| 29 | + const PARAMETER_BRICKS = 'bricks'; |
|
| 30 | + const PARAMETER_CMS_PREFIX = 'cmsPrefix'; |
|
| 31 | + const PARAMETER_CONFIGURATION = 'configuration'; |
|
| 32 | + const PARAMETER_DOCUMENT = 'document'; |
|
| 33 | + const PARAMETER_DOCUMENTS = 'documents'; |
|
| 34 | + const PARAMETER_DOCUMENT_TYPE = 'documentType'; |
|
| 35 | + const PARAMETER_DOCUMENT_TYPES = 'documentTypes'; |
|
| 36 | + const PARAMETER_ERROR_MESSAGE = 'errorMsg'; |
|
| 37 | + const PARAMETER_FILES = 'files'; |
|
| 38 | + const PARAMETER_FOLDER = 'folder'; |
|
| 39 | + const PARAMETER_IMAGE = 'image'; |
|
| 40 | + const PARAMETER_IMAGES = 'images'; |
|
| 41 | + const PARAMETER_IMAGE_SET = 'imageSet'; |
|
| 42 | + const PARAMETER_MAIN_NAV_CLASS = 'mainNavClass'; |
|
| 43 | + const PARAMETER_MY_BRICK_SLUG = 'myBrickSlug'; |
|
| 44 | 44 | const PARAMETER_REDIRECT = 'redirect'; |
| 45 | 45 | const PARAMETER_REDIRECTS = 'redirects'; |
| 46 | - const PARAMETER_SEARCH = 'search'; |
|
| 47 | - const PARAMETER_SEARCH_LOG = "searchLog"; |
|
| 48 | - const PARAMETER_SEARCH_NEEDS_UPDATE = "searchNeedsUpdate"; |
|
| 49 | - const PARAMETER_SITEMAP = 'sitemap'; |
|
| 50 | - const PARAMETER_SITEMAP_ITEM = 'sitemapItem'; |
|
| 51 | - const PARAMETER_SMALLEST_IMAGE = 'smallestImage'; |
|
| 52 | - const PARAMETER_STATIC = 'static'; |
|
| 53 | - const PARAMETER_USER = 'user'; |
|
| 54 | - const PARAMETER_USERS = 'users'; |
|
| 55 | - const PARAMETER_USER_RIGHTS = 'userRights'; |
|
| 56 | - const PARAMETER_VALUELIST = "valuelist"; |
|
| 57 | - const PARAMETER_VALUELISTS = "valuelists"; |
|
| 58 | - const PARAMETER_WHITELIST_IPS = 'whitelistIps'; |
|
| 46 | + const PARAMETER_SEARCH = 'search'; |
|
| 47 | + const PARAMETER_SEARCH_LOG = "searchLog"; |
|
| 48 | + const PARAMETER_SEARCH_NEEDS_UPDATE = "searchNeedsUpdate"; |
|
| 49 | + const PARAMETER_SITEMAP = 'sitemap'; |
|
| 50 | + const PARAMETER_SITEMAP_ITEM = 'sitemapItem'; |
|
| 51 | + const PARAMETER_SMALLEST_IMAGE = 'smallestImage'; |
|
| 52 | + const PARAMETER_STATIC = 'static'; |
|
| 53 | + const PARAMETER_USER = 'user'; |
|
| 54 | + const PARAMETER_USERS = 'users'; |
|
| 55 | + const PARAMETER_USER_RIGHTS = 'userRights'; |
|
| 56 | + const PARAMETER_VALUELIST = "valuelist"; |
|
| 57 | + const PARAMETER_VALUELISTS = "valuelists"; |
|
| 58 | + const PARAMETER_WHITELIST_IPS = 'whitelistIps'; |
|
| 59 | 59 | |
| 60 | 60 | const POST_PARAMETER_COMPONENT = 'component'; |
| 61 | 61 | const POST_PARAMETER_FROM_URL = "fromUrl"; |
@@ -66,308 +66,308 @@ discard block |
||
| 66 | 66 | const POST_PARAMETER_TO_URL = "toUrl"; |
| 67 | 67 | const POST_PARAMETER_USERNAME = 'username'; |
| 68 | 68 | |
| 69 | - const GET_PARAMETER_PATH = 'path'; |
|
| 70 | - const GET_PARAMETER_SLUG = 'slug'; |
|
| 71 | - |
|
| 72 | - const FILES_PARAMETER_FILE = 'file'; |
|
| 73 | - |
|
| 74 | - const SESSION_PARAMETER_CLOUD_CONTROL = 'cloudcontrol'; |
|
| 75 | - |
|
| 76 | - const LOGIN_TEMPLATE_PATH = 'login'; |
|
| 77 | - |
|
| 78 | - const CONTENT_TYPE_APPLICATION_JSON = 'Content-type:application/json'; |
|
| 79 | - |
|
| 80 | - public $subTemplate = null; |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @param Storage $storage |
|
| 85 | - * |
|
| 86 | - * @return void |
|
| 87 | - */ |
|
| 88 | - public function run(Storage $storage) |
|
| 89 | - { |
|
| 90 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::MAIN_NAV_CLASS; |
|
| 91 | - $this->storage = $storage; |
|
| 92 | - |
|
| 93 | - $remoteAddress = $_SERVER['REMOTE_ADDR']; |
|
| 94 | - $this->checkWhiteList($remoteAddress); |
|
| 95 | - $this->checkBlackList($remoteAddress); |
|
| 96 | - |
|
| 97 | - $this->checkLogin(); |
|
| 98 | - |
|
| 99 | - $this->parameters[self::PARAMETER_USER_RIGHTS] = $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]->rights; |
|
| 100 | - |
|
| 101 | - $this->routing(); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * See if a user is logged or wants to log in and |
|
| 106 | - * takes appropriate actions. |
|
| 107 | - * |
|
| 108 | - * @throws \Exception |
|
| 109 | - */ |
|
| 110 | - protected function checkLogin() |
|
| 111 | - { |
|
| 112 | - $request = $this->request; |
|
| 113 | - |
|
| 114 | - if (!isset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL])) { |
|
| 115 | - if (isset($request::$post[self::POST_PARAMETER_USERNAME], $request::$post[self::POST_PARAMETER_PASSWORD])) { |
|
| 116 | - $this->checkLoginAttempt($request); |
|
| 117 | - } else { |
|
| 118 | - $this->showLogin(); |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Overrides normal behaviour and only renders the |
|
| 125 | - * login screen |
|
| 126 | - * |
|
| 127 | - * @throws \Exception |
|
| 128 | - */ |
|
| 129 | - protected function showLogin() |
|
| 130 | - { |
|
| 131 | - $loginTemplatePath = self::LOGIN_TEMPLATE_PATH; |
|
| 132 | - $this->renderTemplate($loginTemplatePath); |
|
| 133 | - ob_end_flush(); |
|
| 134 | - exit; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * As an exception, to keep the initial file structure simple |
|
| 139 | - * the cms implements it's own routing, apart from the regular sitemap functionality |
|
| 140 | - * |
|
| 141 | - * @throws \Exception |
|
| 142 | - */ |
|
| 143 | - protected function routing() |
|
| 144 | - { |
|
| 145 | - $relativeCmsUri = $this->getRelativeCmsUri($this->request); |
|
| 146 | - |
|
| 147 | - $userRights = $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]->rights; |
|
| 148 | - |
|
| 149 | - $this->dashboardRouting($relativeCmsUri); |
|
| 150 | - $this->logOffRouting($this->request, $relativeCmsUri); |
|
| 151 | - $this->apiRouting($relativeCmsUri); |
|
| 152 | - $this->documentRouting($userRights, $relativeCmsUri); |
|
| 153 | - $this->sitemapRouting($userRights, $relativeCmsUri); |
|
| 154 | - $this->imageRouting($userRights, $relativeCmsUri); |
|
| 155 | - $this->filesRouting($userRights, $relativeCmsUri); |
|
| 156 | - $this->configurationRouting($userRights, $relativeCmsUri); |
|
| 157 | - $this->searchRouting($userRights, $relativeCmsUri); |
|
| 158 | - |
|
| 159 | - $this->renderBody(); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * @param $remoteAddress |
|
| 164 | - * |
|
| 165 | - * @throws \Exception |
|
| 166 | - */ |
|
| 167 | - private function checkWhiteList($remoteAddress) |
|
| 168 | - { |
|
| 169 | - if (isset($this->parameters[self::PARAMETER_WHITELIST_IPS])) { |
|
| 170 | - $whitelistIps = explode(',', $this->parameters[self::PARAMETER_WHITELIST_IPS]); |
|
| 171 | - $whitelistIps = array_map("trim", $whitelistIps); |
|
| 172 | - if (!in_array($remoteAddress, $whitelistIps)) { |
|
| 173 | - throw new \Exception('Ip address ' . $remoteAddress . ' is not on whitelist'); |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * @param $remoteAddress |
|
| 180 | - * |
|
| 181 | - * @throws \Exception |
|
| 182 | - */ |
|
| 183 | - private function checkBlackList($remoteAddress) |
|
| 184 | - { |
|
| 185 | - if (isset($this->parameters[self::PARAMETER_BLACKLIST_IPS])) { |
|
| 186 | - $blacklistIps = explode(',', $this->parameters[self::PARAMETER_BLACKLIST_IPS]); |
|
| 187 | - $blacklistIps = array_map("trim", $blacklistIps); |
|
| 188 | - if (in_array($remoteAddress, $blacklistIps)) { |
|
| 189 | - throw new \Exception('Ip address ' . $remoteAddress . ' is on blacklist'); |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * @param $request |
|
| 196 | - * |
|
| 197 | - * @return mixed|string |
|
| 198 | - */ |
|
| 199 | - private function getRelativeCmsUri($request) |
|
| 200 | - { |
|
| 201 | - // TODO Use regex match parameter instead of calculating relative uri |
|
| 202 | - $pos = strpos($request::$relativeUri, $this->parameters[self::PARAMETER_CMS_PREFIX]); |
|
| 203 | - $relativeCmsUri = '/'; |
|
| 204 | - if ($pos !== false) { |
|
| 205 | - $relativeCmsUri = substr_replace($request::$relativeUri, '', $pos, strlen($this->parameters[self::PARAMETER_CMS_PREFIX])); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - return $relativeCmsUri; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * @param $relativeCmsUri |
|
| 213 | - */ |
|
| 214 | - private function apiRouting($relativeCmsUri) |
|
| 215 | - { |
|
| 216 | - if ($relativeCmsUri == '/images.json') { |
|
| 217 | - header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
| 218 | - die(json_encode($this->storage->getImages()->getImages())); |
|
| 219 | - } elseif ($relativeCmsUri == '/files.json') { |
|
| 220 | - header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
| 221 | - die(json_encode($this->storage->getFiles()->getFiles())); |
|
| 222 | - } elseif ($relativeCmsUri == '/documents.json') { |
|
| 223 | - header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
| 224 | - die(json_encode($this->storage->getDocuments()->getDocuments())); |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - private function logOffRouting($request, $relativeCmsUri) |
|
| 229 | - { |
|
| 230 | - if ($relativeCmsUri == '/log-off') { |
|
| 231 | - $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = null; |
|
| 232 | - unset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]); |
|
| 233 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX]); |
|
| 234 | - exit; |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - public function setParameter($parameterName, $parameterValue) |
|
| 239 | - { |
|
| 240 | - $this->parameters[$parameterName] = $parameterValue; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - public function getParameter($parameterName) |
|
| 244 | - { |
|
| 245 | - return $this->parameters[$parameterName]; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * @param $relativeCmsUri |
|
| 250 | - */ |
|
| 251 | - protected function dashboardRouting($relativeCmsUri) |
|
| 252 | - { |
|
| 253 | - if ($relativeCmsUri == '' || $relativeCmsUri == '/') { |
|
| 254 | - $this->subTemplate = 'dashboard'; |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * @param $userRights |
|
| 260 | - * @param $relativeCmsUri |
|
| 261 | - */ |
|
| 262 | - protected function documentRouting($userRights, $relativeCmsUri) |
|
| 263 | - { |
|
| 264 | - if (in_array(self::PARAMETER_DOCUMENTS, $userRights)) { |
|
| 265 | - new DocumentRouting($this->request, $relativeCmsUri, $this); |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * @param $userRights |
|
| 271 | - * @param $relativeCmsUri |
|
| 272 | - */ |
|
| 273 | - protected function sitemapRouting($userRights, $relativeCmsUri) |
|
| 274 | - { |
|
| 275 | - if (in_array(self::PARAMETER_SITEMAP, $userRights)) { |
|
| 276 | - new SitemapRouting($this->request, $relativeCmsUri, $this); |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * @param $userRights |
|
| 282 | - * @param $relativeCmsUri |
|
| 283 | - */ |
|
| 284 | - protected function imageRouting($userRights, $relativeCmsUri) |
|
| 285 | - { |
|
| 286 | - if (in_array(self::PARAMETER_IMAGES, $userRights)) { |
|
| 287 | - new ImagesRouting($this->request, $relativeCmsUri, $this); |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * @param $userRights |
|
| 293 | - * @param $relativeCmsUri |
|
| 294 | - */ |
|
| 295 | - protected function filesRouting($userRights, $relativeCmsUri) |
|
| 296 | - { |
|
| 297 | - if (in_array(self::PARAMETER_FILES, $userRights)) { |
|
| 298 | - new FilesRouting($this->request, $relativeCmsUri, $this); |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * @param $userRights |
|
| 304 | - * @param $relativeCmsUri |
|
| 305 | - */ |
|
| 306 | - protected function configurationRouting($userRights, $relativeCmsUri) |
|
| 307 | - { |
|
| 308 | - if (in_array('configuration', $userRights)) { |
|
| 309 | - new ConfigurationRouting($this->request, $relativeCmsUri, $this); |
|
| 310 | - } |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - protected function renderBody() |
|
| 314 | - { |
|
| 315 | - if ($this->subTemplate !== null) { |
|
| 316 | - $this->parameters[self::PARAMETER_BODY] = $this->renderTemplate($this->subTemplate); |
|
| 317 | - } |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * @param $crypt |
|
| 322 | - * @param $request |
|
| 323 | - */ |
|
| 324 | - protected function invalidCredentials($crypt, $request) |
|
| 325 | - { |
|
| 326 | - $crypt->encrypt($request::$post[self::POST_PARAMETER_PASSWORD], 16); // Buy time, to avoid brute forcing |
|
| 327 | - $this->parameters[self::PARAMETER_ERROR_MESSAGE] = self::INVALID_CREDENTIALS_MESSAGE; |
|
| 328 | - $this->showLogin(); |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - /** |
|
| 332 | - * @param $user |
|
| 333 | - * @param $crypt |
|
| 334 | - * @param $request |
|
| 335 | - */ |
|
| 336 | - protected function checkPassword($user, $crypt, $request) |
|
| 337 | - { |
|
| 338 | - $salt = $user->salt; |
|
| 339 | - $password = $user->password; |
|
| 340 | - |
|
| 341 | - $passwordCorrect = $crypt->compare($request::$post[self::POST_PARAMETER_PASSWORD], $password, $salt); |
|
| 342 | - |
|
| 343 | - if ($passwordCorrect) { |
|
| 344 | - $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = $user; |
|
| 345 | - } else { |
|
| 346 | - $this->parameters[self::PARAMETER_ERROR_MESSAGE] = self::INVALID_CREDENTIALS_MESSAGE; |
|
| 347 | - $this->showLogin(); |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * @param $request |
|
| 353 | - */ |
|
| 354 | - protected function checkLoginAttempt($request) |
|
| 355 | - { |
|
| 356 | - $user = $this->storage->getUsers()->getUserByUsername($request::$post[self::POST_PARAMETER_USERNAME]); |
|
| 357 | - $crypt = new Crypt(); |
|
| 358 | - if (empty($user)) { |
|
| 359 | - $this->invalidCredentials($crypt, $request); |
|
| 360 | - } else { |
|
| 361 | - $this->checkPassword($user, $crypt, $request); |
|
| 362 | - } |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - private function searchRouting($userRights, $relativeCmsUri) |
|
| 366 | - { |
|
| 367 | - if (in_array(self::PARAMETER_SEARCH, $userRights)) { |
|
| 368 | - new SearchRouting($this->request, $relativeCmsUri, $this); |
|
| 369 | - } |
|
| 370 | - } |
|
| 69 | + const GET_PARAMETER_PATH = 'path'; |
|
| 70 | + const GET_PARAMETER_SLUG = 'slug'; |
|
| 71 | + |
|
| 72 | + const FILES_PARAMETER_FILE = 'file'; |
|
| 73 | + |
|
| 74 | + const SESSION_PARAMETER_CLOUD_CONTROL = 'cloudcontrol'; |
|
| 75 | + |
|
| 76 | + const LOGIN_TEMPLATE_PATH = 'login'; |
|
| 77 | + |
|
| 78 | + const CONTENT_TYPE_APPLICATION_JSON = 'Content-type:application/json'; |
|
| 79 | + |
|
| 80 | + public $subTemplate = null; |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @param Storage $storage |
|
| 85 | + * |
|
| 86 | + * @return void |
|
| 87 | + */ |
|
| 88 | + public function run(Storage $storage) |
|
| 89 | + { |
|
| 90 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::MAIN_NAV_CLASS; |
|
| 91 | + $this->storage = $storage; |
|
| 92 | + |
|
| 93 | + $remoteAddress = $_SERVER['REMOTE_ADDR']; |
|
| 94 | + $this->checkWhiteList($remoteAddress); |
|
| 95 | + $this->checkBlackList($remoteAddress); |
|
| 96 | + |
|
| 97 | + $this->checkLogin(); |
|
| 98 | + |
|
| 99 | + $this->parameters[self::PARAMETER_USER_RIGHTS] = $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]->rights; |
|
| 100 | + |
|
| 101 | + $this->routing(); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * See if a user is logged or wants to log in and |
|
| 106 | + * takes appropriate actions. |
|
| 107 | + * |
|
| 108 | + * @throws \Exception |
|
| 109 | + */ |
|
| 110 | + protected function checkLogin() |
|
| 111 | + { |
|
| 112 | + $request = $this->request; |
|
| 113 | + |
|
| 114 | + if (!isset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL])) { |
|
| 115 | + if (isset($request::$post[self::POST_PARAMETER_USERNAME], $request::$post[self::POST_PARAMETER_PASSWORD])) { |
|
| 116 | + $this->checkLoginAttempt($request); |
|
| 117 | + } else { |
|
| 118 | + $this->showLogin(); |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Overrides normal behaviour and only renders the |
|
| 125 | + * login screen |
|
| 126 | + * |
|
| 127 | + * @throws \Exception |
|
| 128 | + */ |
|
| 129 | + protected function showLogin() |
|
| 130 | + { |
|
| 131 | + $loginTemplatePath = self::LOGIN_TEMPLATE_PATH; |
|
| 132 | + $this->renderTemplate($loginTemplatePath); |
|
| 133 | + ob_end_flush(); |
|
| 134 | + exit; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * As an exception, to keep the initial file structure simple |
|
| 139 | + * the cms implements it's own routing, apart from the regular sitemap functionality |
|
| 140 | + * |
|
| 141 | + * @throws \Exception |
|
| 142 | + */ |
|
| 143 | + protected function routing() |
|
| 144 | + { |
|
| 145 | + $relativeCmsUri = $this->getRelativeCmsUri($this->request); |
|
| 146 | + |
|
| 147 | + $userRights = $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]->rights; |
|
| 148 | + |
|
| 149 | + $this->dashboardRouting($relativeCmsUri); |
|
| 150 | + $this->logOffRouting($this->request, $relativeCmsUri); |
|
| 151 | + $this->apiRouting($relativeCmsUri); |
|
| 152 | + $this->documentRouting($userRights, $relativeCmsUri); |
|
| 153 | + $this->sitemapRouting($userRights, $relativeCmsUri); |
|
| 154 | + $this->imageRouting($userRights, $relativeCmsUri); |
|
| 155 | + $this->filesRouting($userRights, $relativeCmsUri); |
|
| 156 | + $this->configurationRouting($userRights, $relativeCmsUri); |
|
| 157 | + $this->searchRouting($userRights, $relativeCmsUri); |
|
| 158 | + |
|
| 159 | + $this->renderBody(); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * @param $remoteAddress |
|
| 164 | + * |
|
| 165 | + * @throws \Exception |
|
| 166 | + */ |
|
| 167 | + private function checkWhiteList($remoteAddress) |
|
| 168 | + { |
|
| 169 | + if (isset($this->parameters[self::PARAMETER_WHITELIST_IPS])) { |
|
| 170 | + $whitelistIps = explode(',', $this->parameters[self::PARAMETER_WHITELIST_IPS]); |
|
| 171 | + $whitelistIps = array_map("trim", $whitelistIps); |
|
| 172 | + if (!in_array($remoteAddress, $whitelistIps)) { |
|
| 173 | + throw new \Exception('Ip address ' . $remoteAddress . ' is not on whitelist'); |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * @param $remoteAddress |
|
| 180 | + * |
|
| 181 | + * @throws \Exception |
|
| 182 | + */ |
|
| 183 | + private function checkBlackList($remoteAddress) |
|
| 184 | + { |
|
| 185 | + if (isset($this->parameters[self::PARAMETER_BLACKLIST_IPS])) { |
|
| 186 | + $blacklistIps = explode(',', $this->parameters[self::PARAMETER_BLACKLIST_IPS]); |
|
| 187 | + $blacklistIps = array_map("trim", $blacklistIps); |
|
| 188 | + if (in_array($remoteAddress, $blacklistIps)) { |
|
| 189 | + throw new \Exception('Ip address ' . $remoteAddress . ' is on blacklist'); |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * @param $request |
|
| 196 | + * |
|
| 197 | + * @return mixed|string |
|
| 198 | + */ |
|
| 199 | + private function getRelativeCmsUri($request) |
|
| 200 | + { |
|
| 201 | + // TODO Use regex match parameter instead of calculating relative uri |
|
| 202 | + $pos = strpos($request::$relativeUri, $this->parameters[self::PARAMETER_CMS_PREFIX]); |
|
| 203 | + $relativeCmsUri = '/'; |
|
| 204 | + if ($pos !== false) { |
|
| 205 | + $relativeCmsUri = substr_replace($request::$relativeUri, '', $pos, strlen($this->parameters[self::PARAMETER_CMS_PREFIX])); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + return $relativeCmsUri; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * @param $relativeCmsUri |
|
| 213 | + */ |
|
| 214 | + private function apiRouting($relativeCmsUri) |
|
| 215 | + { |
|
| 216 | + if ($relativeCmsUri == '/images.json') { |
|
| 217 | + header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
| 218 | + die(json_encode($this->storage->getImages()->getImages())); |
|
| 219 | + } elseif ($relativeCmsUri == '/files.json') { |
|
| 220 | + header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
| 221 | + die(json_encode($this->storage->getFiles()->getFiles())); |
|
| 222 | + } elseif ($relativeCmsUri == '/documents.json') { |
|
| 223 | + header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
| 224 | + die(json_encode($this->storage->getDocuments()->getDocuments())); |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + private function logOffRouting($request, $relativeCmsUri) |
|
| 229 | + { |
|
| 230 | + if ($relativeCmsUri == '/log-off') { |
|
| 231 | + $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = null; |
|
| 232 | + unset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]); |
|
| 233 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX]); |
|
| 234 | + exit; |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + public function setParameter($parameterName, $parameterValue) |
|
| 239 | + { |
|
| 240 | + $this->parameters[$parameterName] = $parameterValue; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + public function getParameter($parameterName) |
|
| 244 | + { |
|
| 245 | + return $this->parameters[$parameterName]; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * @param $relativeCmsUri |
|
| 250 | + */ |
|
| 251 | + protected function dashboardRouting($relativeCmsUri) |
|
| 252 | + { |
|
| 253 | + if ($relativeCmsUri == '' || $relativeCmsUri == '/') { |
|
| 254 | + $this->subTemplate = 'dashboard'; |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * @param $userRights |
|
| 260 | + * @param $relativeCmsUri |
|
| 261 | + */ |
|
| 262 | + protected function documentRouting($userRights, $relativeCmsUri) |
|
| 263 | + { |
|
| 264 | + if (in_array(self::PARAMETER_DOCUMENTS, $userRights)) { |
|
| 265 | + new DocumentRouting($this->request, $relativeCmsUri, $this); |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * @param $userRights |
|
| 271 | + * @param $relativeCmsUri |
|
| 272 | + */ |
|
| 273 | + protected function sitemapRouting($userRights, $relativeCmsUri) |
|
| 274 | + { |
|
| 275 | + if (in_array(self::PARAMETER_SITEMAP, $userRights)) { |
|
| 276 | + new SitemapRouting($this->request, $relativeCmsUri, $this); |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * @param $userRights |
|
| 282 | + * @param $relativeCmsUri |
|
| 283 | + */ |
|
| 284 | + protected function imageRouting($userRights, $relativeCmsUri) |
|
| 285 | + { |
|
| 286 | + if (in_array(self::PARAMETER_IMAGES, $userRights)) { |
|
| 287 | + new ImagesRouting($this->request, $relativeCmsUri, $this); |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * @param $userRights |
|
| 293 | + * @param $relativeCmsUri |
|
| 294 | + */ |
|
| 295 | + protected function filesRouting($userRights, $relativeCmsUri) |
|
| 296 | + { |
|
| 297 | + if (in_array(self::PARAMETER_FILES, $userRights)) { |
|
| 298 | + new FilesRouting($this->request, $relativeCmsUri, $this); |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * @param $userRights |
|
| 304 | + * @param $relativeCmsUri |
|
| 305 | + */ |
|
| 306 | + protected function configurationRouting($userRights, $relativeCmsUri) |
|
| 307 | + { |
|
| 308 | + if (in_array('configuration', $userRights)) { |
|
| 309 | + new ConfigurationRouting($this->request, $relativeCmsUri, $this); |
|
| 310 | + } |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + protected function renderBody() |
|
| 314 | + { |
|
| 315 | + if ($this->subTemplate !== null) { |
|
| 316 | + $this->parameters[self::PARAMETER_BODY] = $this->renderTemplate($this->subTemplate); |
|
| 317 | + } |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * @param $crypt |
|
| 322 | + * @param $request |
|
| 323 | + */ |
|
| 324 | + protected function invalidCredentials($crypt, $request) |
|
| 325 | + { |
|
| 326 | + $crypt->encrypt($request::$post[self::POST_PARAMETER_PASSWORD], 16); // Buy time, to avoid brute forcing |
|
| 327 | + $this->parameters[self::PARAMETER_ERROR_MESSAGE] = self::INVALID_CREDENTIALS_MESSAGE; |
|
| 328 | + $this->showLogin(); |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + /** |
|
| 332 | + * @param $user |
|
| 333 | + * @param $crypt |
|
| 334 | + * @param $request |
|
| 335 | + */ |
|
| 336 | + protected function checkPassword($user, $crypt, $request) |
|
| 337 | + { |
|
| 338 | + $salt = $user->salt; |
|
| 339 | + $password = $user->password; |
|
| 340 | + |
|
| 341 | + $passwordCorrect = $crypt->compare($request::$post[self::POST_PARAMETER_PASSWORD], $password, $salt); |
|
| 342 | + |
|
| 343 | + if ($passwordCorrect) { |
|
| 344 | + $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = $user; |
|
| 345 | + } else { |
|
| 346 | + $this->parameters[self::PARAMETER_ERROR_MESSAGE] = self::INVALID_CREDENTIALS_MESSAGE; |
|
| 347 | + $this->showLogin(); |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * @param $request |
|
| 353 | + */ |
|
| 354 | + protected function checkLoginAttempt($request) |
|
| 355 | + { |
|
| 356 | + $user = $this->storage->getUsers()->getUserByUsername($request::$post[self::POST_PARAMETER_USERNAME]); |
|
| 357 | + $crypt = new Crypt(); |
|
| 358 | + if (empty($user)) { |
|
| 359 | + $this->invalidCredentials($crypt, $request); |
|
| 360 | + } else { |
|
| 361 | + $this->checkPassword($user, $crypt, $request); |
|
| 362 | + } |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + private function searchRouting($userRights, $relativeCmsUri) |
|
| 366 | + { |
|
| 367 | + if (in_array(self::PARAMETER_SEARCH, $userRights)) { |
|
| 368 | + new SearchRouting($this->request, $relativeCmsUri, $this); |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | 371 | |
| 372 | 372 | protected function getTemplatePath($template, $application = null) |
| 373 | 373 | { |