@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function getDocumentBySlug($slug) |
| 37 | 37 | { |
| 38 | - $path = '/' . $slug; |
|
| 38 | + $path = '/'.$slug; |
|
| 39 | 39 | |
| 40 | 40 | return $this->repository->getDocumentByPath($path); |
| 41 | 41 | } |
@@ -45,14 +45,14 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function saveDocument($postValues) |
| 47 | 47 | { |
| 48 | - $oldPath = '/' . $postValues['path']; |
|
| 48 | + $oldPath = '/'.$postValues['path']; |
|
| 49 | 49 | |
| 50 | 50 | $container = $this->getDocumentContainerByPath($oldPath); |
| 51 | 51 | $documentObject = DocumentFactory::createDocumentFromPostValues($postValues, new DocumentTypesStorage($this->repository)); |
| 52 | 52 | if ($container->path === '/') { |
| 53 | - $newPath = $container->path . $documentObject->slug; |
|
| 53 | + $newPath = $container->path.$documentObject->slug; |
|
| 54 | 54 | } else { |
| 55 | - $newPath = $container->path . '/' . $documentObject->slug; |
|
| 55 | + $newPath = $container->path.'/'.$documentObject->slug; |
|
| 56 | 56 | } |
| 57 | 57 | $documentObject->path = $newPath; |
| 58 | 58 | $this->repository->saveDocument($documentObject); |
@@ -65,9 +65,9 @@ discard block |
||
| 65 | 65 | { |
| 66 | 66 | $documentObject = DocumentFactory::createDocumentFromPostValues($postValues, new DocumentTypesStorage($this->repository)); |
| 67 | 67 | if ($postValues['path'] === '/') { |
| 68 | - $documentObject->path = $postValues['path'] . $documentObject->slug; |
|
| 68 | + $documentObject->path = $postValues['path'].$documentObject->slug; |
|
| 69 | 69 | } else { |
| 70 | - $documentObject->path = $postValues['path'] . '/' . $documentObject->slug; |
|
| 70 | + $documentObject->path = $postValues['path'].'/'.$documentObject->slug; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | $this->repository->saveDocument($documentObject); |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | public function deleteDocumentBySlug($slug) |
| 80 | 80 | { |
| 81 | - $path = '/' . $slug; |
|
| 81 | + $path = '/'.$slug; |
|
| 82 | 82 | $this->repository->deleteDocumentByPath($path); |
| 83 | 83 | } |
| 84 | 84 | |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | private function showJson($obj, $httpHeader = 'HTTP/1.0 200 OK') { |
| 75 | - header($_SERVER['SERVER_PROTOCOL'] . $httpHeader, true); |
|
| 75 | + header($_SERVER['SERVER_PROTOCOL'].$httpHeader, true); |
|
| 76 | 76 | header('Content-type: application/json'); |
| 77 | 77 | die(json_encode($obj)); |
| 78 | 78 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | private function stepRouting($step, $cmsComponent, $indexer) |
| 86 | 86 | { |
| 87 | - switch($step) { |
|
| 87 | + switch ($step) { |
|
| 88 | 88 | case 'resetIndex': $indexer->resetIndex(); break; |
| 89 | 89 | case 'createDocumentTermCount': |
| 90 | 90 | $documents = $cmsComponent->storage->getDocuments()->getDocuments(); |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | case 'createTermFieldLengthNorm': $indexer->createTermFieldLengthNorm(); break; |
| 95 | 95 | case 'createInverseDocumentFrequency': $indexer->createInverseDocumentFrequency(); break; |
| 96 | 96 | case 'replaceOldIndex': $indexer->replaceOldIndex(); break; |
| 97 | - default : $this->showJson('Invalid step: ' . $step . '.', 'HTTP/1.0 500 Internal Server Error'); break; |
|
| 97 | + default : $this->showJson('Invalid step: '.$step.'.', 'HTTP/1.0 500 Internal Server Error'); break; |
|
| 98 | 98 | } |
| 99 | 99 | $this->showJson('done'); |
| 100 | 100 | } |
@@ -21,134 +21,134 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class Repository |
| 23 | 23 | { |
| 24 | - protected $storagePath; |
|
| 25 | - |
|
| 26 | - protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users'); |
|
| 27 | - |
|
| 28 | - protected $sitemap; |
|
| 29 | - protected $sitemapChanges = false; |
|
| 30 | - |
|
| 31 | - protected $applicationComponents; |
|
| 32 | - protected $applicationComponentsChanges = false; |
|
| 33 | - |
|
| 34 | - protected $documentTypes; |
|
| 35 | - protected $documentTypesChanges = false; |
|
| 36 | - |
|
| 37 | - protected $bricks; |
|
| 38 | - protected $bricksChanges = false; |
|
| 39 | - |
|
| 40 | - protected $imageSet; |
|
| 41 | - protected $imageSetChanges = false; |
|
| 42 | - |
|
| 43 | - protected $images; |
|
| 44 | - protected $imagesChanges = false; |
|
| 45 | - |
|
| 46 | - protected $files; |
|
| 47 | - protected $filesChanges = false; |
|
| 48 | - |
|
| 49 | - protected $users; |
|
| 50 | - protected $usersChanges = false; |
|
| 51 | - |
|
| 52 | - protected $contentDbHandle; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Repository constructor. |
|
| 56 | - * @param $storagePath |
|
| 57 | - * @throws \Exception |
|
| 58 | - */ |
|
| 59 | - public function __construct($storagePath) |
|
| 60 | - { |
|
| 61 | - $storagePath = realpath($storagePath); |
|
| 62 | - if (is_dir($storagePath) && $storagePath !== false) { |
|
| 63 | - $this->storagePath = $storagePath; |
|
| 64 | - } else { |
|
| 65 | - throw new \Exception('Repository not yet initialized.'); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Creates the folder in which to create all storage related files |
|
| 71 | - * |
|
| 72 | - * @param $storagePath |
|
| 73 | - * @return bool |
|
| 74 | - */ |
|
| 75 | - public static function create($storagePath) |
|
| 76 | - { |
|
| 77 | - return mkdir($storagePath); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Initiates default storage |
|
| 82 | - * @throws \Exception |
|
| 83 | - */ |
|
| 84 | - public function init() |
|
| 85 | - { |
|
| 86 | - $storageDefaultPath = realpath('../library/cc/install/_storage.json'); |
|
| 87 | - $contentSqlPath = realpath('../library/cc/install/content.sql'); |
|
| 88 | - |
|
| 89 | - $this->initConfigStorage($storageDefaultPath); |
|
| 90 | - $this->initContentDb($contentSqlPath); |
|
| 91 | - |
|
| 92 | - $this->save(); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Load filebased subset and return it's contents |
|
| 97 | - * |
|
| 98 | - * @param $name |
|
| 99 | - * @return mixed|string |
|
| 100 | - * @throws \Exception |
|
| 101 | - */ |
|
| 102 | - public function __get($name) |
|
| 103 | - { |
|
| 104 | - if (isset($this->$name)) { |
|
| 105 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
| 106 | - return $this->$name; |
|
| 107 | - } else { |
|
| 108 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
| 109 | - } |
|
| 110 | - } else { |
|
| 111 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
| 112 | - return $this->loadSubset($name); |
|
| 113 | - } else { |
|
| 114 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Set filebased subset contents |
|
| 121 | - * @param $name |
|
| 122 | - * @param $value |
|
| 123 | - * @throws \Exception |
|
| 124 | - */ |
|
| 125 | - public function __set($name, $value) |
|
| 126 | - { |
|
| 127 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
| 128 | - $this->$name = $value; |
|
| 129 | - $changes = $name . 'Changes'; |
|
| 130 | - $this->$changes = true; |
|
| 131 | - } else { |
|
| 132 | - throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Persist all subsets |
|
| 138 | - */ |
|
| 139 | - public function save() |
|
| 140 | - { |
|
| 141 | - array_map(function ($value) { |
|
| 142 | - $this->saveSubset($value); |
|
| 24 | + protected $storagePath; |
|
| 25 | + |
|
| 26 | + protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users'); |
|
| 27 | + |
|
| 28 | + protected $sitemap; |
|
| 29 | + protected $sitemapChanges = false; |
|
| 30 | + |
|
| 31 | + protected $applicationComponents; |
|
| 32 | + protected $applicationComponentsChanges = false; |
|
| 33 | + |
|
| 34 | + protected $documentTypes; |
|
| 35 | + protected $documentTypesChanges = false; |
|
| 36 | + |
|
| 37 | + protected $bricks; |
|
| 38 | + protected $bricksChanges = false; |
|
| 39 | + |
|
| 40 | + protected $imageSet; |
|
| 41 | + protected $imageSetChanges = false; |
|
| 42 | + |
|
| 43 | + protected $images; |
|
| 44 | + protected $imagesChanges = false; |
|
| 45 | + |
|
| 46 | + protected $files; |
|
| 47 | + protected $filesChanges = false; |
|
| 48 | + |
|
| 49 | + protected $users; |
|
| 50 | + protected $usersChanges = false; |
|
| 51 | + |
|
| 52 | + protected $contentDbHandle; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Repository constructor. |
|
| 56 | + * @param $storagePath |
|
| 57 | + * @throws \Exception |
|
| 58 | + */ |
|
| 59 | + public function __construct($storagePath) |
|
| 60 | + { |
|
| 61 | + $storagePath = realpath($storagePath); |
|
| 62 | + if (is_dir($storagePath) && $storagePath !== false) { |
|
| 63 | + $this->storagePath = $storagePath; |
|
| 64 | + } else { |
|
| 65 | + throw new \Exception('Repository not yet initialized.'); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Creates the folder in which to create all storage related files |
|
| 71 | + * |
|
| 72 | + * @param $storagePath |
|
| 73 | + * @return bool |
|
| 74 | + */ |
|
| 75 | + public static function create($storagePath) |
|
| 76 | + { |
|
| 77 | + return mkdir($storagePath); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Initiates default storage |
|
| 82 | + * @throws \Exception |
|
| 83 | + */ |
|
| 84 | + public function init() |
|
| 85 | + { |
|
| 86 | + $storageDefaultPath = realpath('../library/cc/install/_storage.json'); |
|
| 87 | + $contentSqlPath = realpath('../library/cc/install/content.sql'); |
|
| 88 | + |
|
| 89 | + $this->initConfigStorage($storageDefaultPath); |
|
| 90 | + $this->initContentDb($contentSqlPath); |
|
| 91 | + |
|
| 92 | + $this->save(); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Load filebased subset and return it's contents |
|
| 97 | + * |
|
| 98 | + * @param $name |
|
| 99 | + * @return mixed|string |
|
| 100 | + * @throws \Exception |
|
| 101 | + */ |
|
| 102 | + public function __get($name) |
|
| 103 | + { |
|
| 104 | + if (isset($this->$name)) { |
|
| 105 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
| 106 | + return $this->$name; |
|
| 107 | + } else { |
|
| 108 | + throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
| 109 | + } |
|
| 110 | + } else { |
|
| 111 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
| 112 | + return $this->loadSubset($name); |
|
| 113 | + } else { |
|
| 114 | + throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Set filebased subset contents |
|
| 121 | + * @param $name |
|
| 122 | + * @param $value |
|
| 123 | + * @throws \Exception |
|
| 124 | + */ |
|
| 125 | + public function __set($name, $value) |
|
| 126 | + { |
|
| 127 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
| 128 | + $this->$name = $value; |
|
| 129 | + $changes = $name . 'Changes'; |
|
| 130 | + $this->$changes = true; |
|
| 131 | + } else { |
|
| 132 | + throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Persist all subsets |
|
| 138 | + */ |
|
| 139 | + public function save() |
|
| 140 | + { |
|
| 141 | + array_map(function ($value) { |
|
| 142 | + $this->saveSubset($value); |
|
| 143 | 143 | }, $this->fileBasedSubsets); |
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Persist subset to disk |
|
| 148 | - * @param $subset |
|
| 149 | - */ |
|
| 150 | - protected function saveSubset($subset) |
|
| 151 | - { |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Persist subset to disk |
|
| 148 | + * @param $subset |
|
| 149 | + */ |
|
| 150 | + protected function saveSubset($subset) |
|
| 151 | + { |
|
| 152 | 152 | $changes = $subset . 'Changes'; |
| 153 | 153 | if ($this->$changes === true) { |
| 154 | 154 | $json = json_encode($this->$subset, JSON_PRETTY_PRINT); |
@@ -157,89 +157,89 @@ discard block |
||
| 157 | 157 | |
| 158 | 158 | $this->$changes = false; |
| 159 | 159 | } |
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Load subset from disk |
|
| 164 | - * @param $subset |
|
| 165 | - * @return mixed|string |
|
| 166 | - */ |
|
| 167 | - protected function loadSubset($subset) |
|
| 168 | - { |
|
| 169 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
| 170 | - $json = file_get_contents($subsetStoragePath); |
|
| 171 | - $json = json_decode($json); |
|
| 172 | - $this->$subset = $json; |
|
| 173 | - return $json; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * @param $contentSqlPath |
|
| 178 | - */ |
|
| 179 | - protected function initContentDb($contentSqlPath) |
|
| 180 | - { |
|
| 181 | - $db = $this->getContentDbHandle(); |
|
| 182 | - $sql = file_get_contents($contentSqlPath); |
|
| 183 | - $db->exec($sql); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * @param $storageDefaultPath |
|
| 188 | - */ |
|
| 189 | - protected function initConfigStorage($storageDefaultPath) |
|
| 190 | - { |
|
| 191 | - $json = file_get_contents($storageDefaultPath); |
|
| 192 | - $json = json_decode($json); |
|
| 193 | - $this->sitemap = $json->sitemap; |
|
| 194 | - $this->sitemapChanges = true; |
|
| 195 | - $this->applicationComponents = $json->applicationComponents; |
|
| 196 | - $this->applicationComponentsChanges = true; |
|
| 197 | - $this->documentTypes = $json->documentTypes; |
|
| 198 | - $this->documentTypesChanges = true; |
|
| 199 | - $this->bricks = $json->bricks; |
|
| 200 | - $this->bricksChanges = true; |
|
| 201 | - $this->imageSet = $json->imageSet; |
|
| 202 | - $this->imageSetChanges = true; |
|
| 203 | - $this->images = $json->images; |
|
| 204 | - $this->imagesChanges = true; |
|
| 205 | - $this->files = $json->files; |
|
| 206 | - $this->filesChanges = true; |
|
| 207 | - $this->users = $json->users; |
|
| 208 | - $this->usersChanges = true; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * @return \PDO |
|
| 213 | - */ |
|
| 214 | - public function getContentDbHandle() |
|
| 215 | - { |
|
| 216 | - if ($this->contentDbHandle === null) { |
|
| 217 | - $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
| 218 | - } |
|
| 219 | - return $this->contentDbHandle; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * Get all documents |
|
| 224 | - * @return array |
|
| 225 | - */ |
|
| 226 | - public function getDocuments() |
|
| 227 | - { |
|
| 228 | - return $this->getDocumentsByPath('/'); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Get all documents and folders in a certain path |
|
| 233 | - * @param $folderPath |
|
| 234 | - * @return array |
|
| 235 | - * @throws \Exception |
|
| 236 | - */ |
|
| 237 | - public function getDocumentsByPath($folderPath) |
|
| 238 | - { |
|
| 239 | - $db = $this->getContentDbHandle(); |
|
| 240 | - $folderPathWithWildcard = $folderPath . '%'; |
|
| 241 | - |
|
| 242 | - $stmt = $this->getDbStatement(' |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Load subset from disk |
|
| 164 | + * @param $subset |
|
| 165 | + * @return mixed|string |
|
| 166 | + */ |
|
| 167 | + protected function loadSubset($subset) |
|
| 168 | + { |
|
| 169 | + $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
| 170 | + $json = file_get_contents($subsetStoragePath); |
|
| 171 | + $json = json_decode($json); |
|
| 172 | + $this->$subset = $json; |
|
| 173 | + return $json; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * @param $contentSqlPath |
|
| 178 | + */ |
|
| 179 | + protected function initContentDb($contentSqlPath) |
|
| 180 | + { |
|
| 181 | + $db = $this->getContentDbHandle(); |
|
| 182 | + $sql = file_get_contents($contentSqlPath); |
|
| 183 | + $db->exec($sql); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * @param $storageDefaultPath |
|
| 188 | + */ |
|
| 189 | + protected function initConfigStorage($storageDefaultPath) |
|
| 190 | + { |
|
| 191 | + $json = file_get_contents($storageDefaultPath); |
|
| 192 | + $json = json_decode($json); |
|
| 193 | + $this->sitemap = $json->sitemap; |
|
| 194 | + $this->sitemapChanges = true; |
|
| 195 | + $this->applicationComponents = $json->applicationComponents; |
|
| 196 | + $this->applicationComponentsChanges = true; |
|
| 197 | + $this->documentTypes = $json->documentTypes; |
|
| 198 | + $this->documentTypesChanges = true; |
|
| 199 | + $this->bricks = $json->bricks; |
|
| 200 | + $this->bricksChanges = true; |
|
| 201 | + $this->imageSet = $json->imageSet; |
|
| 202 | + $this->imageSetChanges = true; |
|
| 203 | + $this->images = $json->images; |
|
| 204 | + $this->imagesChanges = true; |
|
| 205 | + $this->files = $json->files; |
|
| 206 | + $this->filesChanges = true; |
|
| 207 | + $this->users = $json->users; |
|
| 208 | + $this->usersChanges = true; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * @return \PDO |
|
| 213 | + */ |
|
| 214 | + public function getContentDbHandle() |
|
| 215 | + { |
|
| 216 | + if ($this->contentDbHandle === null) { |
|
| 217 | + $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
| 218 | + } |
|
| 219 | + return $this->contentDbHandle; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * Get all documents |
|
| 224 | + * @return array |
|
| 225 | + */ |
|
| 226 | + public function getDocuments() |
|
| 227 | + { |
|
| 228 | + return $this->getDocumentsByPath('/'); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Get all documents and folders in a certain path |
|
| 233 | + * @param $folderPath |
|
| 234 | + * @return array |
|
| 235 | + * @throws \Exception |
|
| 236 | + */ |
|
| 237 | + public function getDocumentsByPath($folderPath) |
|
| 238 | + { |
|
| 239 | + $db = $this->getContentDbHandle(); |
|
| 240 | + $folderPathWithWildcard = $folderPath . '%'; |
|
| 241 | + |
|
| 242 | + $stmt = $this->getDbStatement(' |
|
| 243 | 243 | SELECT * |
| 244 | 244 | FROM documents |
| 245 | 245 | WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard) . ' |
@@ -248,53 +248,53 @@ discard block |
||
| 248 | 248 | ORDER BY `type` DESC, `path` ASC |
| 249 | 249 | '); |
| 250 | 250 | |
| 251 | - $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
| 252 | - foreach ($documents as $key => $document) { |
|
| 253 | - if ($document->type === 'folder') { |
|
| 254 | - $document->dbHandle = $db; |
|
| 255 | - $documents[$key] = $document; |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - return $documents; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * @param $path |
|
| 264 | - * @return bool|Document |
|
| 265 | - */ |
|
| 266 | - public function getDocumentContainerByPath($path) |
|
| 267 | - { |
|
| 268 | - $document = $this->getDocumentByPath($path); |
|
| 269 | - if ($document === false) { |
|
| 270 | - return false; |
|
| 271 | - } |
|
| 272 | - $slugLength = strlen($document->slug); |
|
| 273 | - $containerPath = substr($path, 0, -$slugLength); |
|
| 274 | - if ($containerPath === '/') { |
|
| 275 | - return $this->getRootFolder(); |
|
| 276 | - } |
|
| 277 | - $containerFolder = $this->getDocumentByPath($containerPath); |
|
| 278 | - return $containerFolder; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * @param $path |
|
| 283 | - * @return bool|Document |
|
| 284 | - */ |
|
| 285 | - public function getDocumentByPath($path) |
|
| 286 | - { |
|
| 287 | - $db = $this->getContentDbHandle(); |
|
| 288 | - $document = $this->fetchDocument(' |
|
| 251 | + $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
| 252 | + foreach ($documents as $key => $document) { |
|
| 253 | + if ($document->type === 'folder') { |
|
| 254 | + $document->dbHandle = $db; |
|
| 255 | + $documents[$key] = $document; |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + return $documents; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * @param $path |
|
| 264 | + * @return bool|Document |
|
| 265 | + */ |
|
| 266 | + public function getDocumentContainerByPath($path) |
|
| 267 | + { |
|
| 268 | + $document = $this->getDocumentByPath($path); |
|
| 269 | + if ($document === false) { |
|
| 270 | + return false; |
|
| 271 | + } |
|
| 272 | + $slugLength = strlen($document->slug); |
|
| 273 | + $containerPath = substr($path, 0, -$slugLength); |
|
| 274 | + if ($containerPath === '/') { |
|
| 275 | + return $this->getRootFolder(); |
|
| 276 | + } |
|
| 277 | + $containerFolder = $this->getDocumentByPath($containerPath); |
|
| 278 | + return $containerFolder; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * @param $path |
|
| 283 | + * @return bool|Document |
|
| 284 | + */ |
|
| 285 | + public function getDocumentByPath($path) |
|
| 286 | + { |
|
| 287 | + $db = $this->getContentDbHandle(); |
|
| 288 | + $document = $this->fetchDocument(' |
|
| 289 | 289 | SELECT * |
| 290 | 290 | FROM documents |
| 291 | 291 | WHERE path = ' . $db->quote($path) . ' |
| 292 | 292 | '); |
| 293 | - if ($document instanceof Document && $document->type === 'folder') { |
|
| 294 | - $document->dbHandle = $db; |
|
| 295 | - } |
|
| 296 | - return $document; |
|
| 297 | - } |
|
| 293 | + if ($document instanceof Document && $document->type === 'folder') { |
|
| 294 | + $document->dbHandle = $db; |
|
| 295 | + } |
|
| 296 | + return $document; |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | 299 | /** |
| 300 | 300 | * Returns the count of all documents stored in the db |
@@ -315,70 +315,70 @@ discard block |
||
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | /** |
| 318 | - * Return the results of the query as array of Documents |
|
| 319 | - * @param $sql |
|
| 320 | - * @return array |
|
| 321 | - * @throws \Exception |
|
| 322 | - */ |
|
| 323 | - protected function fetchAllDocuments($sql) |
|
| 324 | - { |
|
| 325 | - $stmt = $this->getDbStatement($sql); |
|
| 326 | - return $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * Return the result of the query as Document |
|
| 331 | - * @param $sql |
|
| 332 | - * @return mixed |
|
| 333 | - * @throws \Exception |
|
| 334 | - */ |
|
| 335 | - protected function fetchDocument($sql) |
|
| 336 | - { |
|
| 337 | - $stmt = $this->getDbStatement($sql); |
|
| 338 | - return $stmt->fetchObject('\library\storage\Document'); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * Prepare the sql statement |
|
| 343 | - * @param $sql |
|
| 344 | - * @return \PDOStatement |
|
| 345 | - * @throws \Exception |
|
| 346 | - */ |
|
| 347 | - protected function getDbStatement($sql) |
|
| 348 | - { |
|
| 349 | - $db = $this->getContentDbHandle(); |
|
| 350 | - $stmt = $db->query($sql); |
|
| 351 | - if ($stmt === false) { |
|
| 352 | - $errorInfo = $db->errorInfo(); |
|
| 353 | - $errorMsg = $errorInfo[2]; |
|
| 354 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
| 355 | - } |
|
| 356 | - return $stmt; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * Create a (non-existent) root folder Document and return it |
|
| 361 | - * @return Document |
|
| 362 | - */ |
|
| 363 | - protected function getRootFolder() |
|
| 364 | - { |
|
| 365 | - $rootFolder = new Document(); |
|
| 366 | - $rootFolder->path = '/'; |
|
| 367 | - $rootFolder->type = 'folder'; |
|
| 368 | - return $rootFolder; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * Save the document to the database |
|
| 373 | - * @param Document $documentObject |
|
| 374 | - * @return bool |
|
| 375 | - * @throws \Exception |
|
| 376 | - * @internal param $path |
|
| 377 | - */ |
|
| 378 | - public function saveDocument($documentObject) |
|
| 379 | - { |
|
| 380 | - $db = $this->getContentDbHandle(); |
|
| 381 | - $stmt = $this->getDbStatement(' |
|
| 318 | + * Return the results of the query as array of Documents |
|
| 319 | + * @param $sql |
|
| 320 | + * @return array |
|
| 321 | + * @throws \Exception |
|
| 322 | + */ |
|
| 323 | + protected function fetchAllDocuments($sql) |
|
| 324 | + { |
|
| 325 | + $stmt = $this->getDbStatement($sql); |
|
| 326 | + return $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * Return the result of the query as Document |
|
| 331 | + * @param $sql |
|
| 332 | + * @return mixed |
|
| 333 | + * @throws \Exception |
|
| 334 | + */ |
|
| 335 | + protected function fetchDocument($sql) |
|
| 336 | + { |
|
| 337 | + $stmt = $this->getDbStatement($sql); |
|
| 338 | + return $stmt->fetchObject('\library\storage\Document'); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * Prepare the sql statement |
|
| 343 | + * @param $sql |
|
| 344 | + * @return \PDOStatement |
|
| 345 | + * @throws \Exception |
|
| 346 | + */ |
|
| 347 | + protected function getDbStatement($sql) |
|
| 348 | + { |
|
| 349 | + $db = $this->getContentDbHandle(); |
|
| 350 | + $stmt = $db->query($sql); |
|
| 351 | + if ($stmt === false) { |
|
| 352 | + $errorInfo = $db->errorInfo(); |
|
| 353 | + $errorMsg = $errorInfo[2]; |
|
| 354 | + throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
| 355 | + } |
|
| 356 | + return $stmt; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * Create a (non-existent) root folder Document and return it |
|
| 361 | + * @return Document |
|
| 362 | + */ |
|
| 363 | + protected function getRootFolder() |
|
| 364 | + { |
|
| 365 | + $rootFolder = new Document(); |
|
| 366 | + $rootFolder->path = '/'; |
|
| 367 | + $rootFolder->type = 'folder'; |
|
| 368 | + return $rootFolder; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * Save the document to the database |
|
| 373 | + * @param Document $documentObject |
|
| 374 | + * @return bool |
|
| 375 | + * @throws \Exception |
|
| 376 | + * @internal param $path |
|
| 377 | + */ |
|
| 378 | + public function saveDocument($documentObject) |
|
| 379 | + { |
|
| 380 | + $db = $this->getContentDbHandle(); |
|
| 381 | + $stmt = $this->getDbStatement(' |
|
| 382 | 382 | INSERT OR REPLACE INTO documents (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
| 383 | 383 | VALUES( |
| 384 | 384 | ' . $db->quote($documentObject->path) . ', |
@@ -396,37 +396,37 @@ discard block |
||
| 396 | 396 | ' . $db->quote(json_encode($documentObject->dynamicBricks)) . ' |
| 397 | 397 | ) |
| 398 | 398 | '); |
| 399 | - $result = $stmt->execute(); |
|
| 400 | - return $result; |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * Delete the document from the database |
|
| 405 | - * If it's a folder, also delete it's contents |
|
| 406 | - * @param $path |
|
| 407 | - * @throws \Exception |
|
| 408 | - */ |
|
| 409 | - public function deleteDocumentByPath($path) |
|
| 410 | - { |
|
| 411 | - $db = $this->getContentDbHandle(); |
|
| 412 | - $documentToDelete = $this->getDocumentByPath($path); |
|
| 413 | - if ($documentToDelete instanceof Document) { |
|
| 414 | - if ($documentToDelete->type == 'document') { |
|
| 415 | - $stmt = $this->getDbStatement(' |
|
| 399 | + $result = $stmt->execute(); |
|
| 400 | + return $result; |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * Delete the document from the database |
|
| 405 | + * If it's a folder, also delete it's contents |
|
| 406 | + * @param $path |
|
| 407 | + * @throws \Exception |
|
| 408 | + */ |
|
| 409 | + public function deleteDocumentByPath($path) |
|
| 410 | + { |
|
| 411 | + $db = $this->getContentDbHandle(); |
|
| 412 | + $documentToDelete = $this->getDocumentByPath($path); |
|
| 413 | + if ($documentToDelete instanceof Document) { |
|
| 414 | + if ($documentToDelete->type == 'document') { |
|
| 415 | + $stmt = $this->getDbStatement(' |
|
| 416 | 416 | DELETE FROM documents |
| 417 | 417 | WHERE path = ' . $db->quote($path) . ' |
| 418 | 418 | '); |
| 419 | - $stmt->execute(); |
|
| 420 | - } elseif ($documentToDelete->type == 'folder') { |
|
| 421 | - $folderPathWithWildcard = $path . '%'; |
|
| 422 | - $stmt = $this->getDbStatement(' |
|
| 419 | + $stmt->execute(); |
|
| 420 | + } elseif ($documentToDelete->type == 'folder') { |
|
| 421 | + $folderPathWithWildcard = $path . '%'; |
|
| 422 | + $stmt = $this->getDbStatement(' |
|
| 423 | 423 | DELETE FROM documents |
| 424 | 424 | WHERE (path LIKE ' . $db->quote($folderPathWithWildcard) . ' |
| 425 | 425 | AND substr(`path`, ' . (strlen($path) + 1) . ', 1) = "/") |
| 426 | 426 | OR path = ' . $db->quote($path) . ' |
| 427 | 427 | '); |
| 428 | - $stmt->execute(); |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - } |
|
| 428 | + $stmt->execute(); |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | 432 | } |
| 433 | 433 | \ No newline at end of file |
@@ -105,13 +105,13 @@ discard block |
||
| 105 | 105 | if (in_array($name, $this->fileBasedSubsets)) { |
| 106 | 106 | return $this->$name; |
| 107 | 107 | } else { |
| 108 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
| 108 | + throw new \Exception('Trying to get undefined property from Repository: '.$name); |
|
| 109 | 109 | } |
| 110 | 110 | } else { |
| 111 | 111 | if (in_array($name, $this->fileBasedSubsets)) { |
| 112 | 112 | return $this->loadSubset($name); |
| 113 | 113 | } else { |
| 114 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
| 114 | + throw new \Exception('Trying to get undefined property from Repository: '.$name); |
|
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -126,10 +126,10 @@ discard block |
||
| 126 | 126 | { |
| 127 | 127 | if (in_array($name, $this->fileBasedSubsets)) { |
| 128 | 128 | $this->$name = $value; |
| 129 | - $changes = $name . 'Changes'; |
|
| 129 | + $changes = $name.'Changes'; |
|
| 130 | 130 | $this->$changes = true; |
| 131 | 131 | } else { |
| 132 | - throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
| 132 | + throw new \Exception('Trying to persist unknown subset in repository: '.$name.' <br /><pre>'.print_r($value, true).'</pre>'); |
|
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | */ |
| 139 | 139 | public function save() |
| 140 | 140 | { |
| 141 | - array_map(function ($value) { |
|
| 141 | + array_map(function($value) { |
|
| 142 | 142 | $this->saveSubset($value); |
| 143 | 143 | }, $this->fileBasedSubsets); |
| 144 | 144 | } |
@@ -149,10 +149,10 @@ discard block |
||
| 149 | 149 | */ |
| 150 | 150 | protected function saveSubset($subset) |
| 151 | 151 | { |
| 152 | - $changes = $subset . 'Changes'; |
|
| 152 | + $changes = $subset.'Changes'; |
|
| 153 | 153 | if ($this->$changes === true) { |
| 154 | 154 | $json = json_encode($this->$subset, JSON_PRETTY_PRINT); |
| 155 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
| 155 | + $subsetStoragePath = $this->storagePath.DIRECTORY_SEPARATOR.$subset.'.json'; |
|
| 156 | 156 | file_put_contents($subsetStoragePath, $json); |
| 157 | 157 | |
| 158 | 158 | $this->$changes = false; |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | */ |
| 167 | 167 | protected function loadSubset($subset) |
| 168 | 168 | { |
| 169 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
| 169 | + $subsetStoragePath = $this->storagePath.DIRECTORY_SEPARATOR.$subset.'.json'; |
|
| 170 | 170 | $json = file_get_contents($subsetStoragePath); |
| 171 | 171 | $json = json_decode($json); |
| 172 | 172 | $this->$subset = $json; |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | public function getContentDbHandle() |
| 215 | 215 | { |
| 216 | 216 | if ($this->contentDbHandle === null) { |
| 217 | - $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
| 217 | + $this->contentDbHandle = new \PDO('sqlite:'.$this->storagePath.DIRECTORY_SEPARATOR.'content.db'); |
|
| 218 | 218 | } |
| 219 | 219 | return $this->contentDbHandle; |
| 220 | 220 | } |
@@ -237,14 +237,14 @@ discard block |
||
| 237 | 237 | public function getDocumentsByPath($folderPath) |
| 238 | 238 | { |
| 239 | 239 | $db = $this->getContentDbHandle(); |
| 240 | - $folderPathWithWildcard = $folderPath . '%'; |
|
| 240 | + $folderPathWithWildcard = $folderPath.'%'; |
|
| 241 | 241 | |
| 242 | 242 | $stmt = $this->getDbStatement(' |
| 243 | 243 | SELECT * |
| 244 | 244 | FROM documents |
| 245 | - WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard) . ' |
|
| 246 | - AND substr(`path`, ' . (strlen($folderPath) + 1) . ') NOT LIKE "%/%" |
|
| 247 | - AND path != ' . $db->quote($folderPath) . ' |
|
| 245 | + WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard).' |
|
| 246 | + AND substr(`path`, ' . (strlen($folderPath) + 1).') NOT LIKE "%/%" |
|
| 247 | + AND path != ' . $db->quote($folderPath).' |
|
| 248 | 248 | ORDER BY `type` DESC, `path` ASC |
| 249 | 249 | '); |
| 250 | 250 | |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | $document = $this->fetchDocument(' |
| 289 | 289 | SELECT * |
| 290 | 290 | FROM documents |
| 291 | - WHERE path = ' . $db->quote($path) . ' |
|
| 291 | + WHERE path = ' . $db->quote($path).' |
|
| 292 | 292 | '); |
| 293 | 293 | if ($document instanceof Document && $document->type === 'folder') { |
| 294 | 294 | $document->dbHandle = $db; |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | FROM documents |
| 309 | 309 | '); |
| 310 | 310 | $result = $stmt->fetch(\PDO::FETCH_ASSOC); |
| 311 | - if (!is_array($result )) { |
|
| 311 | + if (!is_array($result)) { |
|
| 312 | 312 | return 0; |
| 313 | 313 | } |
| 314 | 314 | return intval(current($result)); |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | if ($stmt === false) { |
| 352 | 352 | $errorInfo = $db->errorInfo(); |
| 353 | 353 | $errorMsg = $errorInfo[2]; |
| 354 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
| 354 | + throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>'); |
|
| 355 | 355 | } |
| 356 | 356 | return $stmt; |
| 357 | 357 | } |
@@ -381,19 +381,19 @@ discard block |
||
| 381 | 381 | $stmt = $this->getDbStatement(' |
| 382 | 382 | INSERT OR REPLACE INTO documents (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
| 383 | 383 | VALUES( |
| 384 | - ' . $db->quote($documentObject->path) . ', |
|
| 385 | - ' . $db->quote($documentObject->title) . ', |
|
| 386 | - ' . $db->quote($documentObject->slug) . ', |
|
| 387 | - ' . $db->quote($documentObject->type) . ', |
|
| 388 | - ' . $db->quote($documentObject->documentType) . ', |
|
| 389 | - ' . $db->quote($documentObject->documentTypeSlug) . ', |
|
| 390 | - ' . $db->quote($documentObject->state) . ', |
|
| 391 | - ' . $db->quote($documentObject->lastModificationDate) . ', |
|
| 392 | - ' . $db->quote($documentObject->creationDate) . ', |
|
| 393 | - ' . $db->quote($documentObject->lastModifiedBy) . ', |
|
| 394 | - ' . $db->quote(json_encode($documentObject->fields)) . ', |
|
| 395 | - ' . $db->quote(json_encode($documentObject->bricks)) . ', |
|
| 396 | - ' . $db->quote(json_encode($documentObject->dynamicBricks)) . ' |
|
| 384 | + ' . $db->quote($documentObject->path).', |
|
| 385 | + ' . $db->quote($documentObject->title).', |
|
| 386 | + ' . $db->quote($documentObject->slug).', |
|
| 387 | + ' . $db->quote($documentObject->type).', |
|
| 388 | + ' . $db->quote($documentObject->documentType).', |
|
| 389 | + ' . $db->quote($documentObject->documentTypeSlug).', |
|
| 390 | + ' . $db->quote($documentObject->state).', |
|
| 391 | + ' . $db->quote($documentObject->lastModificationDate).', |
|
| 392 | + ' . $db->quote($documentObject->creationDate).', |
|
| 393 | + ' . $db->quote($documentObject->lastModifiedBy).', |
|
| 394 | + ' . $db->quote(json_encode($documentObject->fields)).', |
|
| 395 | + ' . $db->quote(json_encode($documentObject->bricks)).', |
|
| 396 | + ' . $db->quote(json_encode($documentObject->dynamicBricks)).' |
|
| 397 | 397 | ) |
| 398 | 398 | '); |
| 399 | 399 | $result = $stmt->execute(); |
@@ -414,16 +414,16 @@ discard block |
||
| 414 | 414 | if ($documentToDelete->type == 'document') { |
| 415 | 415 | $stmt = $this->getDbStatement(' |
| 416 | 416 | DELETE FROM documents |
| 417 | - WHERE path = ' . $db->quote($path) . ' |
|
| 417 | + WHERE path = ' . $db->quote($path).' |
|
| 418 | 418 | '); |
| 419 | 419 | $stmt->execute(); |
| 420 | 420 | } elseif ($documentToDelete->type == 'folder') { |
| 421 | - $folderPathWithWildcard = $path . '%'; |
|
| 421 | + $folderPathWithWildcard = $path.'%'; |
|
| 422 | 422 | $stmt = $this->getDbStatement(' |
| 423 | 423 | DELETE FROM documents |
| 424 | - WHERE (path LIKE ' . $db->quote($folderPathWithWildcard) . ' |
|
| 425 | - AND substr(`path`, ' . (strlen($path) + 1) . ', 1) = "/") |
|
| 426 | - OR path = ' . $db->quote($path) . ' |
|
| 424 | + WHERE (path LIKE ' . $db->quote($folderPathWithWildcard).' |
|
| 425 | + AND substr(`path`, ' . (strlen($path) + 1).', 1) = "/") |
|
| 426 | + OR path = ' . $db->quote($path).' |
|
| 427 | 427 | '); |
| 428 | 428 | $stmt->execute(); |
| 429 | 429 | } |
@@ -38,19 +38,19 @@ |
||
| 38 | 38 | array_pop($fileParts); |
| 39 | 39 | $fileNameWithoutExtension = implode('-', $fileParts); |
| 40 | 40 | $fileNameWithoutExtension = StringUtil::slugify($fileNameWithoutExtension); |
| 41 | - $filename = $fileNameWithoutExtension . '.' . $extension; |
|
| 41 | + $filename = $fileNameWithoutExtension.'.'.$extension; |
|
| 42 | 42 | } else { |
| 43 | 43 | $filename = StringUtil::slugify($filename); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - if (file_exists($path . '/' . $filename)) { |
|
| 46 | + if (file_exists($path.'/'.$filename)) { |
|
| 47 | 47 | $fileParts = explode('.', $filename); |
| 48 | 48 | if (count($fileParts) > 1) { |
| 49 | 49 | $extension = end($fileParts); |
| 50 | 50 | array_pop($fileParts); |
| 51 | 51 | $fileNameWithoutExtension = implode('-', $fileParts); |
| 52 | 52 | $fileNameWithoutExtension .= '-copy'; |
| 53 | - $filename = $fileNameWithoutExtension . '.' . $extension; |
|
| 53 | + $filename = $fileNameWithoutExtension.'.'.$extension; |
|
| 54 | 54 | } else { |
| 55 | 55 | $filename .= '-copy'; |
| 56 | 56 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | } |
| 46 | 46 | return $returnFileNames; |
| 47 | 47 | } else { |
| 48 | - throw new \Exception('Image doesnt exist: ' . $imagePath); |
|
| 48 | + throw new \Exception('Image doesnt exist: '.$imagePath); |
|
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
@@ -56,10 +56,10 @@ discard block |
||
| 56 | 56 | * @return string |
| 57 | 57 | * @throws \Exception |
| 58 | 58 | */ |
| 59 | - public function resize($imagePath='', $width='',$height='') |
|
| 59 | + public function resize($imagePath = '', $width = '', $height = '') |
|
| 60 | 60 | { |
| 61 | - $modifier = '-r' . $width . 'x' . $height; |
|
| 62 | - return $this->applyMethod('Resize', $imagePath, $width,$height, $modifier); |
|
| 61 | + $modifier = '-r'.$width.'x'.$height; |
|
| 62 | + return $this->applyMethod('Resize', $imagePath, $width, $height, $modifier); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -69,10 +69,10 @@ discard block |
||
| 69 | 69 | * @return string |
| 70 | 70 | * @throws \Exception |
| 71 | 71 | */ |
| 72 | - public function smartcrop($imagePath='', $width='',$height='') |
|
| 72 | + public function smartcrop($imagePath = '', $width = '', $height = '') |
|
| 73 | 73 | { |
| 74 | - $modifier = '-s' . $width . 'x' . $height; |
|
| 75 | - return $this->applyMethod('SmartCrop', $imagePath, $width,$height, $modifier); |
|
| 74 | + $modifier = '-s'.$width.'x'.$height; |
|
| 75 | + return $this->applyMethod('SmartCrop', $imagePath, $width, $height, $modifier); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -82,10 +82,10 @@ discard block |
||
| 82 | 82 | * @return string |
| 83 | 83 | * @throws \Exception |
| 84 | 84 | */ |
| 85 | - public function boxcrop($imagePath='', $width='',$height='') |
|
| 85 | + public function boxcrop($imagePath = '', $width = '', $height = '') |
|
| 86 | 86 | { |
| 87 | - $modifier = '-b' . $width . 'x' . $height; |
|
| 88 | - return $this->applyMethod('BoxCrop', $imagePath, $width,$height, $modifier); |
|
| 87 | + $modifier = '-b'.$width.'x'.$height; |
|
| 88 | + return $this->applyMethod('BoxCrop', $imagePath, $width, $height, $modifier); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * |
| 95 | 95 | * @return string |
| 96 | 96 | */ |
| 97 | - private function modifyName($imagePath, $modifier='') |
|
| 97 | + private function modifyName($imagePath, $modifier = '') |
|
| 98 | 98 | { |
| 99 | 99 | $filename = basename($imagePath); |
| 100 | 100 | $path = dirname($imagePath); |
@@ -104,30 +104,30 @@ discard block |
||
| 104 | 104 | array_pop($fileParts); |
| 105 | 105 | $fileNameWithoutExtension = implode('-', $fileParts); |
| 106 | 106 | $fileNameWithoutExtension = StringUtil::slugify($fileNameWithoutExtension); |
| 107 | - $filename = $fileNameWithoutExtension . $modifier . '.' . $extension; |
|
| 107 | + $filename = $fileNameWithoutExtension.$modifier.'.'.$extension; |
|
| 108 | 108 | } else { |
| 109 | 109 | $filename = StringUtil::slugify($filename); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - if (file_exists($path . '/' . $filename)) { |
|
| 112 | + if (file_exists($path.'/'.$filename)) { |
|
| 113 | 113 | $fileParts = explode('.', $filename); |
| 114 | 114 | if (count($fileParts) > 1) { |
| 115 | 115 | $extension = end($fileParts); |
| 116 | 116 | array_pop($fileParts); |
| 117 | 117 | $fileNameWithoutExtension = implode('-', $fileParts); |
| 118 | 118 | $fileNameWithoutExtension .= '-copy'; |
| 119 | - $filename = $fileNameWithoutExtension . '.' . $extension; |
|
| 119 | + $filename = $fileNameWithoutExtension.'.'.$extension; |
|
| 120 | 120 | } else { |
| 121 | 121 | $filename .= '-copy'; |
| 122 | 122 | } |
| 123 | - return $this->modifyName($path . '/' . $filename); |
|
| 123 | + return $this->modifyName($path.'/'.$filename); |
|
| 124 | 124 | } |
| 125 | - return $path . '/' . $filename; |
|
| 125 | + return $path.'/'.$filename; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | private function applyMethod($method, $imagePath, $width, $height, $modifier) |
| 129 | 129 | { |
| 130 | - $method = 'library\\images\\methods\\' . $method; |
|
| 130 | + $method = 'library\\images\\methods\\'.$method; |
|
| 131 | 131 | $destination = $this->modifyName($imagePath, $modifier); |
| 132 | 132 | if (file_exists($imagePath)) { |
| 133 | 133 | $image = new Image(); |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | $resizedImage->saveImage($destination, $resizedImage->getImageMimeType($imagePath), 80); |
| 142 | 142 | return basename($destination); |
| 143 | 143 | } else { |
| 144 | - throw new \Exception('Image doesnt exist: ' . $imagePath); |
|
| 144 | + throw new \Exception('Image doesnt exist: '.$imagePath); |
|
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | } |
@@ -37,13 +37,13 @@ discard block |
||
| 37 | 37 | { |
| 38 | 38 | $debug_backtrace = current(debug_backtrace()); |
| 39 | 39 | if (PHP_SAPI == 'cli') { |
| 40 | - echo 'Dump: ' . $debug_backtrace['file'] . ':' . $debug_backtrace['line'] . "\n"; |
|
| 40 | + echo 'Dump: '.$debug_backtrace['file'].':'.$debug_backtrace['line']."\n"; |
|
| 41 | 41 | foreach (func_get_args() as $data) { |
| 42 | 42 | var_dump($data); |
| 43 | 43 | } |
| 44 | 44 | } else { |
| 45 | 45 | ob_clean(); |
| 46 | - echo '<div>Dump: ' . $debug_backtrace['file'] . ':<b>' . $debug_backtrace['line'] . "</b></div>"; |
|
| 46 | + echo '<div>Dump: '.$debug_backtrace['file'].':<b>'.$debug_backtrace['line']."</b></div>"; |
|
| 47 | 47 | echo '<pre>'; |
| 48 | 48 | foreach (func_get_args() as $data) { |
| 49 | 49 | echo "<code>"; |
@@ -91,8 +91,8 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | function utf8Convert($array) |
| 93 | 93 | { |
| 94 | - array_walk_recursive($array, function(&$item){ |
|
| 95 | - if(!mb_detect_encoding($item, 'utf-8', true)){ |
|
| 94 | + array_walk_recursive($array, function(&$item) { |
|
| 95 | + if (!mb_detect_encoding($item, 'utf-8', true)) { |
|
| 96 | 96 | $item = utf8_encode($item); |
| 97 | 97 | } |
| 98 | 98 | }); |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | public static function slugify($str, $replace = array(), $delimiter = '-') |
| 21 | 21 | { |
| 22 | 22 | if (!empty($replace)) { |
| 23 | - $str = str_replace((array)$replace, ' ', $str); |
|
| 23 | + $str = str_replace((array) $replace, ' ', $str); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | $clean = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $str); |
@@ -79,13 +79,13 @@ discard block |
||
| 79 | 79 | public static function humanFileSize($size, $unit = "") |
| 80 | 80 | { |
| 81 | 81 | if ((!$unit && $size >= 1 << 30) || $unit == "GB") |
| 82 | - return number_format($size / (1 << 30), 2) . "GB"; |
|
| 82 | + return number_format($size / (1 << 30), 2)."GB"; |
|
| 83 | 83 | if ((!$unit && $size >= 1 << 20) || $unit == "MB") |
| 84 | - return number_format($size / (1 << 20), 2) . "MB"; |
|
| 84 | + return number_format($size / (1 << 20), 2)."MB"; |
|
| 85 | 85 | if ((!$unit && $size >= 1 << 10) || $unit == "KB") |
| 86 | - return number_format($size / (1 << 10), 2) . "KB"; |
|
| 86 | + return number_format($size / (1 << 10), 2)."KB"; |
|
| 87 | 87 | |
| 88 | - return number_format($size) . " bytes"; |
|
| 88 | + return number_format($size)." bytes"; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | if ($d >= 1) { |
| 122 | 122 | $r = round($d); |
| 123 | 123 | |
| 124 | - return $r . ' ' . ($r > 1 ? $a_plural[$str] : $str) . ' ago'; |
|
| 124 | + return $r.' '.($r > 1 ? $a_plural[$str] : $str).' ago'; |
|
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | |
@@ -78,12 +78,15 @@ |
||
| 78 | 78 | */ |
| 79 | 79 | public static function humanFileSize($size, $unit = "") |
| 80 | 80 | { |
| 81 | - if ((!$unit && $size >= 1 << 30) || $unit == "GB") |
|
| 82 | - return number_format($size / (1 << 30), 2) . "GB"; |
|
| 83 | - if ((!$unit && $size >= 1 << 20) || $unit == "MB") |
|
| 84 | - return number_format($size / (1 << 20), 2) . "MB"; |
|
| 85 | - if ((!$unit && $size >= 1 << 10) || $unit == "KB") |
|
| 86 | - return number_format($size / (1 << 10), 2) . "KB"; |
|
| 81 | + if ((!$unit && $size >= 1 << 30) || $unit == "GB") { |
|
| 82 | + return number_format($size / (1 << 30), 2) . "GB"; |
|
| 83 | + } |
|
| 84 | + if ((!$unit && $size >= 1 << 20) || $unit == "MB") { |
|
| 85 | + return number_format($size / (1 << 20), 2) . "MB"; |
|
| 86 | + } |
|
| 87 | + if ((!$unit && $size >= 1 << 10) || $unit == "KB") { |
|
| 88 | + return number_format($size / (1 << 10), 2) . "KB"; |
|
| 89 | + } |
|
| 87 | 90 | |
| 88 | 91 | return number_format($size) . " bytes"; |
| 89 | 92 | } |
@@ -10,22 +10,22 @@ |
||
| 10 | 10 | <div class="show-image"> |
| 11 | 11 | <label>File</label> |
| 12 | 12 | <div class="value"> |
| 13 | - <?=isset($image)? $image->file : '' ?> |
|
| 13 | + <?=isset($image) ? $image->file : '' ?> |
|
| 14 | 14 | </div> |
| 15 | 15 | <label>Type</label> |
| 16 | 16 | <div class="value"> |
| 17 | - <?=isset($image)? $image->type : '' ?> |
|
| 17 | + <?=isset($image) ? $image->type : '' ?> |
|
| 18 | 18 | </div> |
| 19 | 19 | <label>Size</label> |
| 20 | 20 | <div class="value"> |
| 21 | - <?=isset($image)? \library\cc\StringUtil::humanFileSize($image->size) : '' ?> |
|
| 21 | + <?=isset($image) ? \library\cc\StringUtil::humanFileSize($image->size) : '' ?> |
|
| 22 | 22 | </div> |
| 23 | 23 | <label>Set</label> |
| 24 | 24 | <? if (isset($image)) : ?> |
| 25 | 25 | <? foreach ($image->set as $key => $set) : ?> |
| 26 | 26 | <div class="sets"> |
| 27 | 27 | <label><?=$key?></label> |
| 28 | - <img src="<?=\library\cc\Request::$subfolders . 'images/' . $set?>" /> |
|
| 28 | + <img src="<?=\library\cc\Request::$subfolders.'images/'.$set?>" /> |
|
| 29 | 29 | </div> |
| 30 | 30 | <? endforeach ?> |
| 31 | 31 | <? endif ?> |