@@ -2,271 +2,271 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace library\cc { |
| 4 | 4 | |
| 5 | - use library\components\Component; |
|
| 6 | - use library\storage\Storage; |
|
| 7 | - |
|
| 8 | - /** |
|
| 9 | - * Class Application |
|
| 10 | - * @package library\cc |
|
| 11 | - */ |
|
| 12 | - class Application |
|
| 13 | - { |
|
| 14 | - /** |
|
| 15 | - * @var \stdClass |
|
| 16 | - */ |
|
| 17 | - private $config; |
|
| 18 | - /** |
|
| 19 | - * @var \library\storage\Storage $config |
|
| 20 | - */ |
|
| 21 | - private $storage; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @var Request |
|
| 25 | - */ |
|
| 26 | - private $request; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - private $matchedSitemapItems = array(); |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var array |
|
| 35 | - */ |
|
| 36 | - private $applicationComponents = array(); |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Application constructor. |
|
| 40 | - */ |
|
| 41 | - public function __construct() |
|
| 42 | - { |
|
| 43 | - $this->config(); |
|
| 44 | - $this->storage(); |
|
| 45 | - |
|
| 46 | - $this->request = new Request(); |
|
| 47 | - |
|
| 48 | - $this->redirectMatching($this->request); |
|
| 49 | - $this->sitemapMatching($this->request); |
|
| 50 | - |
|
| 51 | - $this->getApplicationComponents(); |
|
| 52 | - |
|
| 53 | - $this->runApplicationComponents(); |
|
| 54 | - $this->runSitemapComponents(); |
|
| 55 | - |
|
| 56 | - $this->renderApplicationComponents(); |
|
| 57 | - $this->renderSitemapComponents(); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Initialize the config |
|
| 62 | - * |
|
| 63 | - * @throws \Exception |
|
| 64 | - */ |
|
| 65 | - private function config() |
|
| 66 | - { |
|
| 67 | - $configPath = __DIR__ . '/../../config.json'; |
|
| 68 | - if (realpath($configPath) !== false) { |
|
| 69 | - $json = file_get_contents($configPath); |
|
| 70 | - $this->config = json_decode($json); |
|
| 71 | - } else { |
|
| 72 | - initFramework(); |
|
| 73 | - $this->config(); |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Initialize the storage |
|
| 79 | - */ |
|
| 80 | - private function storage() |
|
| 81 | - { |
|
| 82 | - $this->storage = new Storage($this->getStorageDir()); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - private function redirectMatching($request) |
|
| 86 | - { |
|
| 87 | - $redirects = $this->storage->getRedirects()->getRedirects(); |
|
| 88 | - $relativeUri = '/' . $request::$relativeUri; |
|
| 89 | - |
|
| 90 | - foreach ($redirects as $redirect) { |
|
| 91 | - if (preg_match_all($redirect->fromUrl, $relativeUri, $matches)) { |
|
| 92 | - $toUrl = preg_replace($redirect->fromUrl, $redirect->toUrl, $relativeUri); |
|
| 93 | - if (substr($toUrl, 0, 1) == '/') { |
|
| 94 | - $toUrl = substr($toUrl, 1); |
|
| 95 | - } |
|
| 96 | - if ($redirect->type == '301') { |
|
| 97 | - header('HTTP/1.1 301 Moved Permanently'); |
|
| 98 | - header('Location: ' . $request::$subfolders . $toUrl); |
|
| 99 | - exit; |
|
| 100 | - } elseif ($redirect->type == '302') { |
|
| 101 | - header('Location: ' . $request::$subfolders . $toUrl, true, 302); |
|
| 102 | - exit; |
|
| 103 | - } else { |
|
| 104 | - throw new \Exception('Invalid redirect type.'); |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Loop through sitemap items and see if one matches the requestUri. |
|
| 112 | - * If it does, add it tot the matchedSitemapItems array |
|
| 113 | - * |
|
| 114 | - * @param $request |
|
| 115 | - */ |
|
| 116 | - private function sitemapMatching($request) |
|
| 117 | - { |
|
| 118 | - $sitemap = $this->storage->getSitemap()->getSitemap(); |
|
| 119 | - $relativeUri = '/' . $request::$relativeUri; |
|
| 120 | - |
|
| 121 | - foreach ($sitemap as $sitemapItem) { |
|
| 122 | - if ($sitemapItem->regex) { |
|
| 123 | - $matches = array(); |
|
| 124 | - if (preg_match_all($sitemapItem->url, $relativeUri, $matches)) { |
|
| 125 | - // Make a clone, so it doesnt add the matches to the original |
|
| 126 | - $matchedClone = clone $sitemapItem; |
|
| 127 | - $matchedClone->matches = $matches; |
|
| 128 | - $this->matchedSitemapItems[] = $matchedClone; |
|
| 129 | - return; |
|
| 130 | - } |
|
| 131 | - } else { |
|
| 132 | - if ($sitemapItem->url == $relativeUri) { |
|
| 133 | - $this->matchedSitemapItems[] = $sitemapItem; |
|
| 134 | - return; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Loop through all application components and run them |
|
| 142 | - * |
|
| 143 | - * @throws \Exception |
|
| 144 | - */ |
|
| 145 | - private function runApplicationComponents() |
|
| 146 | - { |
|
| 147 | - foreach ($this->applicationComponents as $key => $applicationComponent) { |
|
| 148 | - $class = $applicationComponent->component; |
|
| 149 | - $parameters = $applicationComponent->parameters; |
|
| 150 | - $this->applicationComponents[$key]->{'object'} = $this->getComponentObject($class, null, $parameters, null); |
|
| 151 | - $this->applicationComponents[$key]->{'object'}->run($this->storage); |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Loop through all (matched) sitemap components and run them |
|
| 157 | - * |
|
| 158 | - * @throws \Exception |
|
| 159 | - */ |
|
| 160 | - private function runSitemapComponents() |
|
| 161 | - { |
|
| 162 | - foreach ($this->matchedSitemapItems as $key => $sitemapItem) { |
|
| 163 | - $class = $sitemapItem->component; |
|
| 164 | - $template = $sitemapItem->template; |
|
| 165 | - $parameters = $sitemapItem->parameters; |
|
| 166 | - |
|
| 167 | - $this->matchedSitemapItems[$key]->object = $this->getComponentObject($class, $template, $parameters, $sitemapItem); |
|
| 168 | - |
|
| 169 | - $this->matchedSitemapItems[$key]->object->run($this->storage); |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * @param string $class |
|
| 175 | - * @param string $template |
|
| 176 | - * @param array $parameters |
|
| 177 | - * @param \stdClass|null $matchedSitemapItem |
|
| 178 | - * |
|
| 179 | - * @return mixed |
|
| 180 | - * @throws \Exception |
|
| 181 | - */ |
|
| 182 | - private function getComponentObject($class = '', $template = '', $parameters = array(), $matchedSitemapItem) |
|
| 183 | - { |
|
| 184 | - $libraryComponentName = '\\library\\components\\' . $class; |
|
| 185 | - $userComponentName = '\\components\\' . $class; |
|
| 186 | - |
|
| 187 | - if (AutoloadUtil::autoLoad($libraryComponentName, false)) { |
|
| 188 | - $component = new $libraryComponentName($template, $this->request, $parameters, $matchedSitemapItem); |
|
| 189 | - } elseif (AutoloadUtil::autoLoad($userComponentName, false)) { |
|
| 190 | - $component = new $userComponentName($template, $this->request, $parameters, $matchedSitemapItem); |
|
| 191 | - } else { |
|
| 192 | - throw new \Exception('Could not load component ' . $class); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - if (!$component instanceof Component) { |
|
| 196 | - throw new \Exception('Component not of type Component. Must inherit \library\components\Component'); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - return $component; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Loop through all application components and render them |
|
| 204 | - */ |
|
| 205 | - private function renderApplicationComponents() |
|
| 206 | - { |
|
| 207 | - foreach ($this->applicationComponents as $applicationComponent) { |
|
| 208 | - $applicationComponent->{'object'}->render(); |
|
| 209 | - } |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Loop through all (matched) sitemap components and render them |
|
| 214 | - */ |
|
| 215 | - private function renderSitemapComponents() |
|
| 216 | - { |
|
| 217 | - foreach ($this->matchedSitemapItems as $sitemapItem) { |
|
| 218 | - $this->setCachingHeaders(); |
|
| 219 | - $sitemapItem->object->render($this); |
|
| 220 | - ob_clean(); |
|
| 221 | - echo $sitemapItem->object->get(); |
|
| 222 | - ob_end_flush(); |
|
| 223 | - exit; |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - public function getAllApplicationComponentParameters() |
|
| 228 | - { |
|
| 229 | - $allParameters = array(); |
|
| 230 | - foreach ($this->applicationComponents as $applicationComponent) { |
|
| 231 | - $parameters = $applicationComponent->{'object'}->getParameters(); |
|
| 232 | - $allParameters[] = $parameters; |
|
| 233 | - } |
|
| 234 | - return $allParameters; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - public function unlockApplicationComponentParameters() |
|
| 238 | - { |
|
| 239 | - foreach ($this->applicationComponents as $applicationComponent) { |
|
| 240 | - $parameters = $applicationComponent->{'object'}->getParameters(); |
|
| 241 | - extract($parameters); |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * Set the default caching of pages to 2 days |
|
| 247 | - */ |
|
| 248 | - public function setCachingHeaders() |
|
| 249 | - { |
|
| 250 | - header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60 * 24 * 2))); // 2 days |
|
| 251 | - header("Cache-Control: max-age=" . (60 * 60 * 24 * 2)); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * @return string |
|
| 256 | - */ |
|
| 257 | - public function getStoragePath() |
|
| 258 | - { |
|
| 259 | - return $this->config->storagePath; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - public function getStorageDir() |
|
| 263 | - { |
|
| 264 | - return $this->config->storageDir; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - public function getApplicationComponents() |
|
| 268 | - { |
|
| 269 | - $this->applicationComponents = $this->storage->getApplicationComponents()->getApplicationComponents(); |
|
| 270 | - } |
|
| 271 | - } |
|
| 5 | + use library\components\Component; |
|
| 6 | + use library\storage\Storage; |
|
| 7 | + |
|
| 8 | + /** |
|
| 9 | + * Class Application |
|
| 10 | + * @package library\cc |
|
| 11 | + */ |
|
| 12 | + class Application |
|
| 13 | + { |
|
| 14 | + /** |
|
| 15 | + * @var \stdClass |
|
| 16 | + */ |
|
| 17 | + private $config; |
|
| 18 | + /** |
|
| 19 | + * @var \library\storage\Storage $config |
|
| 20 | + */ |
|
| 21 | + private $storage; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @var Request |
|
| 25 | + */ |
|
| 26 | + private $request; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + private $matchedSitemapItems = array(); |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var array |
|
| 35 | + */ |
|
| 36 | + private $applicationComponents = array(); |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Application constructor. |
|
| 40 | + */ |
|
| 41 | + public function __construct() |
|
| 42 | + { |
|
| 43 | + $this->config(); |
|
| 44 | + $this->storage(); |
|
| 45 | + |
|
| 46 | + $this->request = new Request(); |
|
| 47 | + |
|
| 48 | + $this->redirectMatching($this->request); |
|
| 49 | + $this->sitemapMatching($this->request); |
|
| 50 | + |
|
| 51 | + $this->getApplicationComponents(); |
|
| 52 | + |
|
| 53 | + $this->runApplicationComponents(); |
|
| 54 | + $this->runSitemapComponents(); |
|
| 55 | + |
|
| 56 | + $this->renderApplicationComponents(); |
|
| 57 | + $this->renderSitemapComponents(); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Initialize the config |
|
| 62 | + * |
|
| 63 | + * @throws \Exception |
|
| 64 | + */ |
|
| 65 | + private function config() |
|
| 66 | + { |
|
| 67 | + $configPath = __DIR__ . '/../../config.json'; |
|
| 68 | + if (realpath($configPath) !== false) { |
|
| 69 | + $json = file_get_contents($configPath); |
|
| 70 | + $this->config = json_decode($json); |
|
| 71 | + } else { |
|
| 72 | + initFramework(); |
|
| 73 | + $this->config(); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Initialize the storage |
|
| 79 | + */ |
|
| 80 | + private function storage() |
|
| 81 | + { |
|
| 82 | + $this->storage = new Storage($this->getStorageDir()); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + private function redirectMatching($request) |
|
| 86 | + { |
|
| 87 | + $redirects = $this->storage->getRedirects()->getRedirects(); |
|
| 88 | + $relativeUri = '/' . $request::$relativeUri; |
|
| 89 | + |
|
| 90 | + foreach ($redirects as $redirect) { |
|
| 91 | + if (preg_match_all($redirect->fromUrl, $relativeUri, $matches)) { |
|
| 92 | + $toUrl = preg_replace($redirect->fromUrl, $redirect->toUrl, $relativeUri); |
|
| 93 | + if (substr($toUrl, 0, 1) == '/') { |
|
| 94 | + $toUrl = substr($toUrl, 1); |
|
| 95 | + } |
|
| 96 | + if ($redirect->type == '301') { |
|
| 97 | + header('HTTP/1.1 301 Moved Permanently'); |
|
| 98 | + header('Location: ' . $request::$subfolders . $toUrl); |
|
| 99 | + exit; |
|
| 100 | + } elseif ($redirect->type == '302') { |
|
| 101 | + header('Location: ' . $request::$subfolders . $toUrl, true, 302); |
|
| 102 | + exit; |
|
| 103 | + } else { |
|
| 104 | + throw new \Exception('Invalid redirect type.'); |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Loop through sitemap items and see if one matches the requestUri. |
|
| 112 | + * If it does, add it tot the matchedSitemapItems array |
|
| 113 | + * |
|
| 114 | + * @param $request |
|
| 115 | + */ |
|
| 116 | + private function sitemapMatching($request) |
|
| 117 | + { |
|
| 118 | + $sitemap = $this->storage->getSitemap()->getSitemap(); |
|
| 119 | + $relativeUri = '/' . $request::$relativeUri; |
|
| 120 | + |
|
| 121 | + foreach ($sitemap as $sitemapItem) { |
|
| 122 | + if ($sitemapItem->regex) { |
|
| 123 | + $matches = array(); |
|
| 124 | + if (preg_match_all($sitemapItem->url, $relativeUri, $matches)) { |
|
| 125 | + // Make a clone, so it doesnt add the matches to the original |
|
| 126 | + $matchedClone = clone $sitemapItem; |
|
| 127 | + $matchedClone->matches = $matches; |
|
| 128 | + $this->matchedSitemapItems[] = $matchedClone; |
|
| 129 | + return; |
|
| 130 | + } |
|
| 131 | + } else { |
|
| 132 | + if ($sitemapItem->url == $relativeUri) { |
|
| 133 | + $this->matchedSitemapItems[] = $sitemapItem; |
|
| 134 | + return; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Loop through all application components and run them |
|
| 142 | + * |
|
| 143 | + * @throws \Exception |
|
| 144 | + */ |
|
| 145 | + private function runApplicationComponents() |
|
| 146 | + { |
|
| 147 | + foreach ($this->applicationComponents as $key => $applicationComponent) { |
|
| 148 | + $class = $applicationComponent->component; |
|
| 149 | + $parameters = $applicationComponent->parameters; |
|
| 150 | + $this->applicationComponents[$key]->{'object'} = $this->getComponentObject($class, null, $parameters, null); |
|
| 151 | + $this->applicationComponents[$key]->{'object'}->run($this->storage); |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Loop through all (matched) sitemap components and run them |
|
| 157 | + * |
|
| 158 | + * @throws \Exception |
|
| 159 | + */ |
|
| 160 | + private function runSitemapComponents() |
|
| 161 | + { |
|
| 162 | + foreach ($this->matchedSitemapItems as $key => $sitemapItem) { |
|
| 163 | + $class = $sitemapItem->component; |
|
| 164 | + $template = $sitemapItem->template; |
|
| 165 | + $parameters = $sitemapItem->parameters; |
|
| 166 | + |
|
| 167 | + $this->matchedSitemapItems[$key]->object = $this->getComponentObject($class, $template, $parameters, $sitemapItem); |
|
| 168 | + |
|
| 169 | + $this->matchedSitemapItems[$key]->object->run($this->storage); |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * @param string $class |
|
| 175 | + * @param string $template |
|
| 176 | + * @param array $parameters |
|
| 177 | + * @param \stdClass|null $matchedSitemapItem |
|
| 178 | + * |
|
| 179 | + * @return mixed |
|
| 180 | + * @throws \Exception |
|
| 181 | + */ |
|
| 182 | + private function getComponentObject($class = '', $template = '', $parameters = array(), $matchedSitemapItem) |
|
| 183 | + { |
|
| 184 | + $libraryComponentName = '\\library\\components\\' . $class; |
|
| 185 | + $userComponentName = '\\components\\' . $class; |
|
| 186 | + |
|
| 187 | + if (AutoloadUtil::autoLoad($libraryComponentName, false)) { |
|
| 188 | + $component = new $libraryComponentName($template, $this->request, $parameters, $matchedSitemapItem); |
|
| 189 | + } elseif (AutoloadUtil::autoLoad($userComponentName, false)) { |
|
| 190 | + $component = new $userComponentName($template, $this->request, $parameters, $matchedSitemapItem); |
|
| 191 | + } else { |
|
| 192 | + throw new \Exception('Could not load component ' . $class); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + if (!$component instanceof Component) { |
|
| 196 | + throw new \Exception('Component not of type Component. Must inherit \library\components\Component'); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + return $component; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Loop through all application components and render them |
|
| 204 | + */ |
|
| 205 | + private function renderApplicationComponents() |
|
| 206 | + { |
|
| 207 | + foreach ($this->applicationComponents as $applicationComponent) { |
|
| 208 | + $applicationComponent->{'object'}->render(); |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Loop through all (matched) sitemap components and render them |
|
| 214 | + */ |
|
| 215 | + private function renderSitemapComponents() |
|
| 216 | + { |
|
| 217 | + foreach ($this->matchedSitemapItems as $sitemapItem) { |
|
| 218 | + $this->setCachingHeaders(); |
|
| 219 | + $sitemapItem->object->render($this); |
|
| 220 | + ob_clean(); |
|
| 221 | + echo $sitemapItem->object->get(); |
|
| 222 | + ob_end_flush(); |
|
| 223 | + exit; |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + public function getAllApplicationComponentParameters() |
|
| 228 | + { |
|
| 229 | + $allParameters = array(); |
|
| 230 | + foreach ($this->applicationComponents as $applicationComponent) { |
|
| 231 | + $parameters = $applicationComponent->{'object'}->getParameters(); |
|
| 232 | + $allParameters[] = $parameters; |
|
| 233 | + } |
|
| 234 | + return $allParameters; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + public function unlockApplicationComponentParameters() |
|
| 238 | + { |
|
| 239 | + foreach ($this->applicationComponents as $applicationComponent) { |
|
| 240 | + $parameters = $applicationComponent->{'object'}->getParameters(); |
|
| 241 | + extract($parameters); |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * Set the default caching of pages to 2 days |
|
| 247 | + */ |
|
| 248 | + public function setCachingHeaders() |
|
| 249 | + { |
|
| 250 | + header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60 * 24 * 2))); // 2 days |
|
| 251 | + header("Cache-Control: max-age=" . (60 * 60 * 24 * 2)); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * @return string |
|
| 256 | + */ |
|
| 257 | + public function getStoragePath() |
|
| 258 | + { |
|
| 259 | + return $this->config->storagePath; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + public function getStorageDir() |
|
| 263 | + { |
|
| 264 | + return $this->config->storageDir; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + public function getApplicationComponents() |
|
| 268 | + { |
|
| 269 | + $this->applicationComponents = $this->storage->getApplicationComponents()->getApplicationComponents(); |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | 272 | } |
| 273 | 273 | \ No newline at end of file |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | private function config() |
| 66 | 66 | { |
| 67 | - $configPath = __DIR__ . '/../../config.json'; |
|
| 67 | + $configPath = __DIR__.'/../../config.json'; |
|
| 68 | 68 | if (realpath($configPath) !== false) { |
| 69 | 69 | $json = file_get_contents($configPath); |
| 70 | 70 | $this->config = json_decode($json); |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | private function redirectMatching($request) |
| 86 | 86 | { |
| 87 | 87 | $redirects = $this->storage->getRedirects()->getRedirects(); |
| 88 | - $relativeUri = '/' . $request::$relativeUri; |
|
| 88 | + $relativeUri = '/'.$request::$relativeUri; |
|
| 89 | 89 | |
| 90 | 90 | foreach ($redirects as $redirect) { |
| 91 | 91 | if (preg_match_all($redirect->fromUrl, $relativeUri, $matches)) { |
@@ -95,10 +95,10 @@ discard block |
||
| 95 | 95 | } |
| 96 | 96 | if ($redirect->type == '301') { |
| 97 | 97 | header('HTTP/1.1 301 Moved Permanently'); |
| 98 | - header('Location: ' . $request::$subfolders . $toUrl); |
|
| 98 | + header('Location: '.$request::$subfolders.$toUrl); |
|
| 99 | 99 | exit; |
| 100 | 100 | } elseif ($redirect->type == '302') { |
| 101 | - header('Location: ' . $request::$subfolders . $toUrl, true, 302); |
|
| 101 | + header('Location: '.$request::$subfolders.$toUrl, true, 302); |
|
| 102 | 102 | exit; |
| 103 | 103 | } else { |
| 104 | 104 | throw new \Exception('Invalid redirect type.'); |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | private function sitemapMatching($request) |
| 117 | 117 | { |
| 118 | 118 | $sitemap = $this->storage->getSitemap()->getSitemap(); |
| 119 | - $relativeUri = '/' . $request::$relativeUri; |
|
| 119 | + $relativeUri = '/'.$request::$relativeUri; |
|
| 120 | 120 | |
| 121 | 121 | foreach ($sitemap as $sitemapItem) { |
| 122 | 122 | if ($sitemapItem->regex) { |
@@ -181,15 +181,15 @@ discard block |
||
| 181 | 181 | */ |
| 182 | 182 | private function getComponentObject($class = '', $template = '', $parameters = array(), $matchedSitemapItem) |
| 183 | 183 | { |
| 184 | - $libraryComponentName = '\\library\\components\\' . $class; |
|
| 185 | - $userComponentName = '\\components\\' . $class; |
|
| 184 | + $libraryComponentName = '\\library\\components\\'.$class; |
|
| 185 | + $userComponentName = '\\components\\'.$class; |
|
| 186 | 186 | |
| 187 | 187 | if (AutoloadUtil::autoLoad($libraryComponentName, false)) { |
| 188 | 188 | $component = new $libraryComponentName($template, $this->request, $parameters, $matchedSitemapItem); |
| 189 | 189 | } elseif (AutoloadUtil::autoLoad($userComponentName, false)) { |
| 190 | 190 | $component = new $userComponentName($template, $this->request, $parameters, $matchedSitemapItem); |
| 191 | 191 | } else { |
| 192 | - throw new \Exception('Could not load component ' . $class); |
|
| 192 | + throw new \Exception('Could not load component '.$class); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | if (!$component instanceof Component) { |
@@ -247,8 +247,8 @@ discard block |
||
| 247 | 247 | */ |
| 248 | 248 | public function setCachingHeaders() |
| 249 | 249 | { |
| 250 | - header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60 * 24 * 2))); // 2 days |
|
| 251 | - header("Cache-Control: max-age=" . (60 * 60 * 24 * 2)); |
|
| 250 | + header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60 * 24 * 2))); // 2 days |
|
| 251 | + header("Cache-Control: max-age=".(60 * 60 * 24 * 2)); |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | /** |
@@ -20,60 +20,60 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | class Document |
| 22 | 22 | { |
| 23 | - public $id; |
|
| 24 | - public $path; |
|
| 25 | - public $title; |
|
| 26 | - public $slug; |
|
| 27 | - public $type; |
|
| 28 | - public $documentType; |
|
| 29 | - public $documentTypeSlug; |
|
| 30 | - public $state; |
|
| 31 | - public $lastModificationDate; |
|
| 32 | - public $creationDate; |
|
| 33 | - public $lastModifiedBy; |
|
| 34 | - protected $fields; |
|
| 35 | - protected $bricks; |
|
| 36 | - protected $dynamicBricks; |
|
| 37 | - protected $content; |
|
| 23 | + public $id; |
|
| 24 | + public $path; |
|
| 25 | + public $title; |
|
| 26 | + public $slug; |
|
| 27 | + public $type; |
|
| 28 | + public $documentType; |
|
| 29 | + public $documentTypeSlug; |
|
| 30 | + public $state; |
|
| 31 | + public $lastModificationDate; |
|
| 32 | + public $creationDate; |
|
| 33 | + public $lastModifiedBy; |
|
| 34 | + protected $fields; |
|
| 35 | + protected $bricks; |
|
| 36 | + protected $dynamicBricks; |
|
| 37 | + protected $content; |
|
| 38 | 38 | |
| 39 | - protected $dbHandle; |
|
| 39 | + protected $dbHandle; |
|
| 40 | 40 | |
| 41 | - protected $jsonEncodedFields = array('fields', 'bricks', 'dynamicBricks'); |
|
| 42 | - protected $orderableFields = array('title', 'slug', 'type', 'documentType', 'documentTypeSlug', 'state', 'lastModificationDate', 'creationDate', 'lastModifiedBy'); |
|
| 41 | + protected $jsonEncodedFields = array('fields', 'bricks', 'dynamicBricks'); |
|
| 42 | + protected $orderableFields = array('title', 'slug', 'type', 'documentType', 'documentTypeSlug', 'state', 'lastModificationDate', 'creationDate', 'lastModifiedBy'); |
|
| 43 | 43 | |
| 44 | - public static $DOCUMENT_STATES = array('published', 'unpublished'); |
|
| 44 | + public static $DOCUMENT_STATES = array('published', 'unpublished'); |
|
| 45 | 45 | |
| 46 | - public function __get($name) { |
|
| 47 | - if (in_array($name, $this->jsonEncodedFields)) { |
|
| 48 | - if (is_string($this->$name)) { |
|
| 49 | - return json_decode($this->$name); |
|
| 50 | - } else { |
|
| 51 | - return $this->$name; |
|
| 52 | - } |
|
| 53 | - } elseif ($name === 'content') { |
|
| 54 | - if ($this->dbHandle === null) { |
|
| 55 | - throw new \Exception('Document doesnt have a dbHandle handle. (path: ' . $this->path . ')'); |
|
| 56 | - } else { |
|
| 57 | - if ($this->content === null) { |
|
| 58 | - return $this->getContent(); |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - } elseif ($name === 'dbHandle') { |
|
| 62 | - throw new \Exception('Trying to get protected property repository.'); |
|
| 63 | - } |
|
| 64 | - return $this->$name; |
|
| 65 | - } |
|
| 46 | + public function __get($name) { |
|
| 47 | + if (in_array($name, $this->jsonEncodedFields)) { |
|
| 48 | + if (is_string($this->$name)) { |
|
| 49 | + return json_decode($this->$name); |
|
| 50 | + } else { |
|
| 51 | + return $this->$name; |
|
| 52 | + } |
|
| 53 | + } elseif ($name === 'content') { |
|
| 54 | + if ($this->dbHandle === null) { |
|
| 55 | + throw new \Exception('Document doesnt have a dbHandle handle. (path: ' . $this->path . ')'); |
|
| 56 | + } else { |
|
| 57 | + if ($this->content === null) { |
|
| 58 | + return $this->getContent(); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + } elseif ($name === 'dbHandle') { |
|
| 62 | + throw new \Exception('Trying to get protected property repository.'); |
|
| 63 | + } |
|
| 64 | + return $this->$name; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - public function __set($name, $value) { |
|
| 68 | - if (in_array($name, $this->jsonEncodedFields)) { |
|
| 69 | - $this->$name = json_encode($value); |
|
| 70 | - } elseif ($name === 'content') { |
|
| 71 | - // Dont do anything for now.. |
|
| 72 | - return; |
|
| 73 | - } |
|
| 67 | + public function __set($name, $value) { |
|
| 68 | + if (in_array($name, $this->jsonEncodedFields)) { |
|
| 69 | + $this->$name = json_encode($value); |
|
| 70 | + } elseif ($name === 'content') { |
|
| 71 | + // Dont do anything for now.. |
|
| 72 | + return; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - $this->$name = $value; |
|
| 76 | - } |
|
| 75 | + $this->$name = $value; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | 79 | * @param string $orderBy |
@@ -82,15 +82,15 @@ discard block |
||
| 82 | 82 | * @return array |
| 83 | 83 | * @throws \Exception |
| 84 | 84 | */ |
| 85 | - public function getContent($orderBy = 'title', $order = 'ASC') |
|
| 86 | - { |
|
| 87 | - if (empty($this->content)) { |
|
| 88 | - $docs = $this->documentStorage->getDocumentsWithState($this->path); |
|
| 89 | - $this->content = $docs; |
|
| 90 | - } |
|
| 85 | + public function getContent($orderBy = 'title', $order = 'ASC') |
|
| 86 | + { |
|
| 87 | + if (empty($this->content)) { |
|
| 88 | + $docs = $this->documentStorage->getDocumentsWithState($this->path); |
|
| 89 | + $this->content = $docs; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - return $this->content; |
|
| 93 | - } |
|
| 92 | + return $this->content; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | 95 | /** |
| 96 | 96 | * @return string |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | } |
| 53 | 53 | } elseif ($name === 'content') { |
| 54 | 54 | if ($this->dbHandle === null) { |
| 55 | - throw new \Exception('Document doesnt have a dbHandle handle. (path: ' . $this->path . ')'); |
|
| 55 | + throw new \Exception('Document doesnt have a dbHandle handle. (path: '.$this->path.')'); |
|
| 56 | 56 | } else { |
| 57 | 57 | if ($this->content === null) { |
| 58 | 58 | return $this->getContent(); |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | */ |
| 98 | 98 | public function __toString() |
| 99 | 99 | { |
| 100 | - return 'Document:' . $this->title; |
|
| 100 | + return 'Document:'.$this->title; |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | |
@@ -24,217 +24,217 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | class Repository |
| 26 | 26 | { |
| 27 | - protected $storagePath; |
|
| 28 | - |
|
| 29 | - protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users', 'valuelists', 'redirects'); |
|
| 30 | - |
|
| 31 | - protected $sitemap; |
|
| 32 | - protected $sitemapChanges = false; |
|
| 33 | - |
|
| 34 | - protected $applicationComponents; |
|
| 35 | - protected $applicationComponentsChanges = false; |
|
| 36 | - |
|
| 37 | - protected $documentTypes; |
|
| 38 | - protected $documentTypesChanges = false; |
|
| 39 | - |
|
| 40 | - protected $bricks; |
|
| 41 | - protected $bricksChanges = false; |
|
| 42 | - |
|
| 43 | - protected $imageSet; |
|
| 44 | - protected $imageSetChanges = false; |
|
| 45 | - |
|
| 46 | - protected $images; |
|
| 47 | - protected $imagesChanges = false; |
|
| 48 | - |
|
| 49 | - protected $files; |
|
| 50 | - protected $filesChanges = false; |
|
| 51 | - |
|
| 52 | - protected $users; |
|
| 53 | - protected $usersChanges = false; |
|
| 54 | - |
|
| 55 | - protected $valuelists; |
|
| 56 | - protected $valuelistsChanges = false; |
|
| 57 | - |
|
| 58 | - protected $redirects; |
|
| 59 | - protected $redirectsChanges = false; |
|
| 60 | - |
|
| 61 | - protected $contentDbHandle; |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Repository constructor. |
|
| 66 | - * @param $storagePath |
|
| 67 | - * @throws \Exception |
|
| 68 | - */ |
|
| 69 | - public function __construct($storagePath) |
|
| 70 | - { |
|
| 71 | - $storagePath = realpath($storagePath); |
|
| 72 | - if (is_dir($storagePath) && $storagePath !== false) { |
|
| 73 | - $this->storagePath = $storagePath; |
|
| 74 | - } else { |
|
| 75 | - throw new \Exception('Repository not yet initialized.'); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Creates the folder in which to create all storage related files |
|
| 81 | - * |
|
| 82 | - * @param $storagePath |
|
| 83 | - * @return bool |
|
| 84 | - */ |
|
| 85 | - public static function create($storagePath) |
|
| 86 | - { |
|
| 87 | - return mkdir($storagePath); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Initiates default storage |
|
| 92 | - * @throws \Exception |
|
| 93 | - */ |
|
| 94 | - public function init() |
|
| 95 | - { |
|
| 96 | - $storageDefaultPath = realpath('../library/cc/install/_storage.json'); |
|
| 97 | - $contentSqlPath = realpath('../library/cc/install/content.sql'); |
|
| 98 | - |
|
| 99 | - $this->initConfigStorage($storageDefaultPath); |
|
| 100 | - $this->initContentDb($contentSqlPath); |
|
| 101 | - |
|
| 102 | - $this->save(); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Load filebased subset and return it's contents |
|
| 107 | - * |
|
| 108 | - * @param $name |
|
| 109 | - * @return mixed|string |
|
| 110 | - * @throws \Exception |
|
| 111 | - */ |
|
| 112 | - public function __get($name) |
|
| 113 | - { |
|
| 114 | - if (isset($this->$name)) { |
|
| 115 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
| 116 | - return $this->$name; |
|
| 117 | - } else { |
|
| 118 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
| 119 | - } |
|
| 120 | - } else { |
|
| 121 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
| 122 | - return $this->loadSubset($name); |
|
| 123 | - } else { |
|
| 124 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Set filebased subset contents |
|
| 131 | - * @param $name |
|
| 132 | - * @param $value |
|
| 133 | - * @throws \Exception |
|
| 134 | - */ |
|
| 135 | - public function __set($name, $value) |
|
| 136 | - { |
|
| 137 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
| 138 | - $this->$name = $value; |
|
| 139 | - $changes = $name . 'Changes'; |
|
| 140 | - $this->$changes = true; |
|
| 141 | - } else { |
|
| 142 | - throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Persist all subsets |
|
| 148 | - */ |
|
| 149 | - public function save() |
|
| 150 | - { |
|
| 151 | - $host = $this; |
|
| 152 | - array_map(function ($value) use ($host) { |
|
| 153 | - $host->saveSubset($value); |
|
| 27 | + protected $storagePath; |
|
| 28 | + |
|
| 29 | + protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users', 'valuelists', 'redirects'); |
|
| 30 | + |
|
| 31 | + protected $sitemap; |
|
| 32 | + protected $sitemapChanges = false; |
|
| 33 | + |
|
| 34 | + protected $applicationComponents; |
|
| 35 | + protected $applicationComponentsChanges = false; |
|
| 36 | + |
|
| 37 | + protected $documentTypes; |
|
| 38 | + protected $documentTypesChanges = false; |
|
| 39 | + |
|
| 40 | + protected $bricks; |
|
| 41 | + protected $bricksChanges = false; |
|
| 42 | + |
|
| 43 | + protected $imageSet; |
|
| 44 | + protected $imageSetChanges = false; |
|
| 45 | + |
|
| 46 | + protected $images; |
|
| 47 | + protected $imagesChanges = false; |
|
| 48 | + |
|
| 49 | + protected $files; |
|
| 50 | + protected $filesChanges = false; |
|
| 51 | + |
|
| 52 | + protected $users; |
|
| 53 | + protected $usersChanges = false; |
|
| 54 | + |
|
| 55 | + protected $valuelists; |
|
| 56 | + protected $valuelistsChanges = false; |
|
| 57 | + |
|
| 58 | + protected $redirects; |
|
| 59 | + protected $redirectsChanges = false; |
|
| 60 | + |
|
| 61 | + protected $contentDbHandle; |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Repository constructor. |
|
| 66 | + * @param $storagePath |
|
| 67 | + * @throws \Exception |
|
| 68 | + */ |
|
| 69 | + public function __construct($storagePath) |
|
| 70 | + { |
|
| 71 | + $storagePath = realpath($storagePath); |
|
| 72 | + if (is_dir($storagePath) && $storagePath !== false) { |
|
| 73 | + $this->storagePath = $storagePath; |
|
| 74 | + } else { |
|
| 75 | + throw new \Exception('Repository not yet initialized.'); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Creates the folder in which to create all storage related files |
|
| 81 | + * |
|
| 82 | + * @param $storagePath |
|
| 83 | + * @return bool |
|
| 84 | + */ |
|
| 85 | + public static function create($storagePath) |
|
| 86 | + { |
|
| 87 | + return mkdir($storagePath); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Initiates default storage |
|
| 92 | + * @throws \Exception |
|
| 93 | + */ |
|
| 94 | + public function init() |
|
| 95 | + { |
|
| 96 | + $storageDefaultPath = realpath('../library/cc/install/_storage.json'); |
|
| 97 | + $contentSqlPath = realpath('../library/cc/install/content.sql'); |
|
| 98 | + |
|
| 99 | + $this->initConfigStorage($storageDefaultPath); |
|
| 100 | + $this->initContentDb($contentSqlPath); |
|
| 101 | + |
|
| 102 | + $this->save(); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Load filebased subset and return it's contents |
|
| 107 | + * |
|
| 108 | + * @param $name |
|
| 109 | + * @return mixed|string |
|
| 110 | + * @throws \Exception |
|
| 111 | + */ |
|
| 112 | + public function __get($name) |
|
| 113 | + { |
|
| 114 | + if (isset($this->$name)) { |
|
| 115 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
| 116 | + return $this->$name; |
|
| 117 | + } else { |
|
| 118 | + throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
| 119 | + } |
|
| 120 | + } else { |
|
| 121 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
| 122 | + return $this->loadSubset($name); |
|
| 123 | + } else { |
|
| 124 | + throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Set filebased subset contents |
|
| 131 | + * @param $name |
|
| 132 | + * @param $value |
|
| 133 | + * @throws \Exception |
|
| 134 | + */ |
|
| 135 | + public function __set($name, $value) |
|
| 136 | + { |
|
| 137 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
| 138 | + $this->$name = $value; |
|
| 139 | + $changes = $name . 'Changes'; |
|
| 140 | + $this->$changes = true; |
|
| 141 | + } else { |
|
| 142 | + throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Persist all subsets |
|
| 148 | + */ |
|
| 149 | + public function save() |
|
| 150 | + { |
|
| 151 | + $host = $this; |
|
| 152 | + array_map(function ($value) use ($host) { |
|
| 153 | + $host->saveSubset($value); |
|
| 154 | 154 | }, $this->fileBasedSubsets); |
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Persist subset to disk |
|
| 159 | - * @param $subset |
|
| 160 | - */ |
|
| 161 | - public function saveSubset($subset) |
|
| 162 | - { |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Persist subset to disk |
|
| 159 | + * @param $subset |
|
| 160 | + */ |
|
| 161 | + public function saveSubset($subset) |
|
| 162 | + { |
|
| 163 | 163 | $changes = $subset . 'Changes'; |
| 164 | 164 | if ($this->$changes === true) { |
| 165 | - if (!defined('JSON_PRETTY_PRINT')) { |
|
| 166 | - $json = json_encode($this->$subset); |
|
| 167 | - } else { |
|
| 168 | - $json = json_encode($this->$subset, JSON_PRETTY_PRINT); |
|
| 169 | - } |
|
| 165 | + if (!defined('JSON_PRETTY_PRINT')) { |
|
| 166 | + $json = json_encode($this->$subset); |
|
| 167 | + } else { |
|
| 168 | + $json = json_encode($this->$subset, JSON_PRETTY_PRINT); |
|
| 169 | + } |
|
| 170 | 170 | $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
| 171 | 171 | file_put_contents($subsetStoragePath, $json); |
| 172 | 172 | |
| 173 | 173 | $this->$changes = false; |
| 174 | 174 | } |
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Load subset from disk |
|
| 179 | - * @param $subset |
|
| 180 | - * @return mixed|string |
|
| 181 | - */ |
|
| 182 | - protected function loadSubset($subset) |
|
| 183 | - { |
|
| 184 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
| 185 | - $json = file_get_contents($subsetStoragePath); |
|
| 186 | - $json = json_decode($json); |
|
| 187 | - $this->$subset = $json; |
|
| 188 | - return $json; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * @param $contentSqlPath |
|
| 193 | - */ |
|
| 194 | - protected function initContentDb($contentSqlPath) |
|
| 195 | - { |
|
| 196 | - $db = $this->getContentDbHandle(); |
|
| 197 | - $sql = file_get_contents($contentSqlPath); |
|
| 198 | - $db->exec($sql); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * @param $storageDefaultPath |
|
| 203 | - */ |
|
| 204 | - protected function initConfigStorage($storageDefaultPath) |
|
| 205 | - { |
|
| 206 | - $json = file_get_contents($storageDefaultPath); |
|
| 207 | - $json = json_decode($json); |
|
| 208 | - $this->sitemap = $json->sitemap; |
|
| 209 | - $this->sitemapChanges = true; |
|
| 210 | - $this->applicationComponents = $json->applicationComponents; |
|
| 211 | - $this->applicationComponentsChanges = true; |
|
| 212 | - $this->documentTypes = $json->documentTypes; |
|
| 213 | - $this->documentTypesChanges = true; |
|
| 214 | - $this->bricks = $json->bricks; |
|
| 215 | - $this->bricksChanges = true; |
|
| 216 | - $this->imageSet = $json->imageSet; |
|
| 217 | - $this->imageSetChanges = true; |
|
| 218 | - $this->images = $json->images; |
|
| 219 | - $this->imagesChanges = true; |
|
| 220 | - $this->files = $json->files; |
|
| 221 | - $this->filesChanges = true; |
|
| 222 | - $this->users = $json->users; |
|
| 223 | - $this->usersChanges = true; |
|
| 224 | - $this->valuelists = $json->valuelists; |
|
| 225 | - $this->valuelistsChanges = true; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * @return \PDO |
|
| 230 | - */ |
|
| 231 | - public function getContentDbHandle() |
|
| 232 | - { |
|
| 233 | - if ($this->contentDbHandle === null) { |
|
| 234 | - $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
| 235 | - } |
|
| 236 | - return $this->contentDbHandle; |
|
| 237 | - } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Load subset from disk |
|
| 179 | + * @param $subset |
|
| 180 | + * @return mixed|string |
|
| 181 | + */ |
|
| 182 | + protected function loadSubset($subset) |
|
| 183 | + { |
|
| 184 | + $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
| 185 | + $json = file_get_contents($subsetStoragePath); |
|
| 186 | + $json = json_decode($json); |
|
| 187 | + $this->$subset = $json; |
|
| 188 | + return $json; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * @param $contentSqlPath |
|
| 193 | + */ |
|
| 194 | + protected function initContentDb($contentSqlPath) |
|
| 195 | + { |
|
| 196 | + $db = $this->getContentDbHandle(); |
|
| 197 | + $sql = file_get_contents($contentSqlPath); |
|
| 198 | + $db->exec($sql); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * @param $storageDefaultPath |
|
| 203 | + */ |
|
| 204 | + protected function initConfigStorage($storageDefaultPath) |
|
| 205 | + { |
|
| 206 | + $json = file_get_contents($storageDefaultPath); |
|
| 207 | + $json = json_decode($json); |
|
| 208 | + $this->sitemap = $json->sitemap; |
|
| 209 | + $this->sitemapChanges = true; |
|
| 210 | + $this->applicationComponents = $json->applicationComponents; |
|
| 211 | + $this->applicationComponentsChanges = true; |
|
| 212 | + $this->documentTypes = $json->documentTypes; |
|
| 213 | + $this->documentTypesChanges = true; |
|
| 214 | + $this->bricks = $json->bricks; |
|
| 215 | + $this->bricksChanges = true; |
|
| 216 | + $this->imageSet = $json->imageSet; |
|
| 217 | + $this->imageSetChanges = true; |
|
| 218 | + $this->images = $json->images; |
|
| 219 | + $this->imagesChanges = true; |
|
| 220 | + $this->files = $json->files; |
|
| 221 | + $this->filesChanges = true; |
|
| 222 | + $this->users = $json->users; |
|
| 223 | + $this->usersChanges = true; |
|
| 224 | + $this->valuelists = $json->valuelists; |
|
| 225 | + $this->valuelistsChanges = true; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * @return \PDO |
|
| 230 | + */ |
|
| 231 | + public function getContentDbHandle() |
|
| 232 | + { |
|
| 233 | + if ($this->contentDbHandle === null) { |
|
| 234 | + $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
| 235 | + } |
|
| 236 | + return $this->contentDbHandle; |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | 239 | /** |
| 240 | 240 | * Get all documents |
@@ -244,13 +244,13 @@ discard block |
||
| 244 | 244 | * @return array |
| 245 | 245 | * @throws \Exception |
| 246 | 246 | */ |
| 247 | - public function getDocuments($state = 'published') |
|
| 248 | - { |
|
| 247 | + public function getDocuments($state = 'published') |
|
| 248 | + { |
|
| 249 | 249 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
| 250 | 250 | throw new \Exception('Unsupported document state: ' . $state); |
| 251 | 251 | } |
| 252 | - return $this->getDocumentsByPath('/', $state); |
|
| 253 | - } |
|
| 252 | + return $this->getDocumentsByPath('/', $state); |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | 255 | public function getDocumentsWithState($folderPath = '/') |
| 256 | 256 | { |
@@ -297,51 +297,51 @@ discard block |
||
| 297 | 297 | * @return array |
| 298 | 298 | * @throws \Exception |
| 299 | 299 | */ |
| 300 | - public function getDocumentsByPath($folderPath, $state = 'published') |
|
| 301 | - { |
|
| 302 | - if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
| 303 | - throw new \Exception('Unsupported document state: ' . $state); |
|
| 300 | + public function getDocumentsByPath($folderPath, $state = 'published') |
|
| 301 | + { |
|
| 302 | + if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
| 303 | + throw new \Exception('Unsupported document state: ' . $state); |
|
| 304 | 304 | } |
| 305 | - $db = $this->getContentDbHandle(); |
|
| 306 | - $folderPathWithWildcard = $folderPath . '%'; |
|
| 305 | + $db = $this->getContentDbHandle(); |
|
| 306 | + $folderPathWithWildcard = $folderPath . '%'; |
|
| 307 | 307 | |
| 308 | - $sql = 'SELECT * |
|
| 308 | + $sql = 'SELECT * |
|
| 309 | 309 | FROM documents_' . $state . ' |
| 310 | 310 | WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard) . ' |
| 311 | 311 | AND substr(`path`, ' . (strlen($folderPath) + 1) . ') NOT LIKE "%/%" |
| 312 | 312 | AND path != ' . $db->quote($folderPath) . ' |
| 313 | 313 | ORDER BY `type` DESC, `path` ASC'; |
| 314 | - $stmt = $this->getDbStatement($sql); |
|
| 314 | + $stmt = $this->getDbStatement($sql); |
|
| 315 | 315 | |
| 316 | - $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
| 317 | - foreach ($documents as $key => $document) { |
|
| 316 | + $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
| 317 | + foreach ($documents as $key => $document) { |
|
| 318 | 318 | $documents = $this->setAssetsToDocumentFolders($document, $db, $documents, $key); |
| 319 | - } |
|
| 320 | - return $documents; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * @param $path |
|
| 326 | - * @return bool|Document |
|
| 327 | - */ |
|
| 328 | - public function getDocumentContainerByPath($path) |
|
| 329 | - { |
|
| 330 | - $document = $this->getDocumentByPath($path, 'unpublished'); |
|
| 331 | - if ($document === false) { |
|
| 332 | - return false; |
|
| 333 | - } |
|
| 334 | - $slugLength = strlen($document->slug); |
|
| 335 | - $containerPath = substr($path, 0, -$slugLength); |
|
| 336 | - if ($containerPath === '/') { |
|
| 337 | - return $this->getRootFolder(); |
|
| 338 | - } |
|
| 339 | - if (substr($containerPath, -1) === '/'){ |
|
| 319 | + } |
|
| 320 | + return $documents; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * @param $path |
|
| 326 | + * @return bool|Document |
|
| 327 | + */ |
|
| 328 | + public function getDocumentContainerByPath($path) |
|
| 329 | + { |
|
| 330 | + $document = $this->getDocumentByPath($path, 'unpublished'); |
|
| 331 | + if ($document === false) { |
|
| 332 | + return false; |
|
| 333 | + } |
|
| 334 | + $slugLength = strlen($document->slug); |
|
| 335 | + $containerPath = substr($path, 0, -$slugLength); |
|
| 336 | + if ($containerPath === '/') { |
|
| 337 | + return $this->getRootFolder(); |
|
| 338 | + } |
|
| 339 | + if (substr($containerPath, -1) === '/'){ |
|
| 340 | 340 | $containerPath = substr($containerPath, 0, -1); |
| 341 | 341 | } |
| 342 | - $containerFolder = $this->getDocumentByPath($containerPath, 'unpublished'); |
|
| 343 | - return $containerFolder; |
|
| 344 | - } |
|
| 342 | + $containerFolder = $this->getDocumentByPath($containerPath, 'unpublished'); |
|
| 343 | + return $containerFolder; |
|
| 344 | + } |
|
| 345 | 345 | |
| 346 | 346 | /** |
| 347 | 347 | * @param $path |
@@ -350,23 +350,23 @@ discard block |
||
| 350 | 350 | * @return bool|\library\storage\Document |
| 351 | 351 | * @throws \Exception |
| 352 | 352 | */ |
| 353 | - public function getDocumentByPath($path, $state = 'published') |
|
| 354 | - { |
|
| 353 | + public function getDocumentByPath($path, $state = 'published') |
|
| 354 | + { |
|
| 355 | 355 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
| 356 | 356 | throw new \Exception('Unsupported document state: ' . $state); |
| 357 | 357 | } |
| 358 | - $db = $this->getContentDbHandle(); |
|
| 359 | - $document = $this->fetchDocument(' |
|
| 358 | + $db = $this->getContentDbHandle(); |
|
| 359 | + $document = $this->fetchDocument(' |
|
| 360 | 360 | SELECT * |
| 361 | 361 | FROM documents_' . $state . ' |
| 362 | 362 | WHERE path = ' . $db->quote($path) . ' |
| 363 | 363 | '); |
| 364 | - if ($document instanceof Document && $document->type === 'folder') { |
|
| 365 | - $document->dbHandle = $db; |
|
| 366 | - $document->documentStorage = new DocumentStorage($this); |
|
| 367 | - } |
|
| 368 | - return $document; |
|
| 369 | - } |
|
| 364 | + if ($document instanceof Document && $document->type === 'folder') { |
|
| 365 | + $document->dbHandle = $db; |
|
| 366 | + $document->documentStorage = new DocumentStorage($this); |
|
| 367 | + } |
|
| 368 | + return $document; |
|
| 369 | + } |
|
| 370 | 370 | |
| 371 | 371 | /** |
| 372 | 372 | * Returns the count of all documents stored in the db |
@@ -461,58 +461,58 @@ discard block |
||
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | /** |
| 464 | - * Return the results of the query as array of Documents |
|
| 465 | - * @param $sql |
|
| 466 | - * @return array |
|
| 467 | - * @throws \Exception |
|
| 468 | - */ |
|
| 469 | - protected function fetchAllDocuments($sql) |
|
| 470 | - { |
|
| 471 | - $stmt = $this->getDbStatement($sql); |
|
| 472 | - return $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - /** |
|
| 476 | - * Return the result of the query as Document |
|
| 477 | - * @param $sql |
|
| 478 | - * @return mixed |
|
| 479 | - * @throws \Exception |
|
| 480 | - */ |
|
| 481 | - protected function fetchDocument($sql) |
|
| 482 | - { |
|
| 483 | - $stmt = $this->getDbStatement($sql); |
|
| 484 | - return $stmt->fetchObject('\library\storage\Document'); |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * Prepare the sql statement |
|
| 489 | - * @param $sql |
|
| 490 | - * @return \PDOStatement |
|
| 491 | - * @throws \Exception |
|
| 492 | - */ |
|
| 493 | - protected function getDbStatement($sql) |
|
| 494 | - { |
|
| 495 | - $db = $this->getContentDbHandle(); |
|
| 496 | - $stmt = $db->query($sql); |
|
| 497 | - if ($stmt === false) { |
|
| 498 | - $errorInfo = $db->errorInfo(); |
|
| 499 | - $errorMsg = $errorInfo[2]; |
|
| 500 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
| 501 | - } |
|
| 502 | - return $stmt; |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * Create a (non-existent) root folder Document and return it |
|
| 507 | - * @return Document |
|
| 508 | - */ |
|
| 509 | - protected function getRootFolder() |
|
| 510 | - { |
|
| 511 | - $rootFolder = new Document(); |
|
| 512 | - $rootFolder->path = '/'; |
|
| 513 | - $rootFolder->type = 'folder'; |
|
| 514 | - return $rootFolder; |
|
| 515 | - } |
|
| 464 | + * Return the results of the query as array of Documents |
|
| 465 | + * @param $sql |
|
| 466 | + * @return array |
|
| 467 | + * @throws \Exception |
|
| 468 | + */ |
|
| 469 | + protected function fetchAllDocuments($sql) |
|
| 470 | + { |
|
| 471 | + $stmt = $this->getDbStatement($sql); |
|
| 472 | + return $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + /** |
|
| 476 | + * Return the result of the query as Document |
|
| 477 | + * @param $sql |
|
| 478 | + * @return mixed |
|
| 479 | + * @throws \Exception |
|
| 480 | + */ |
|
| 481 | + protected function fetchDocument($sql) |
|
| 482 | + { |
|
| 483 | + $stmt = $this->getDbStatement($sql); |
|
| 484 | + return $stmt->fetchObject('\library\storage\Document'); |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * Prepare the sql statement |
|
| 489 | + * @param $sql |
|
| 490 | + * @return \PDOStatement |
|
| 491 | + * @throws \Exception |
|
| 492 | + */ |
|
| 493 | + protected function getDbStatement($sql) |
|
| 494 | + { |
|
| 495 | + $db = $this->getContentDbHandle(); |
|
| 496 | + $stmt = $db->query($sql); |
|
| 497 | + if ($stmt === false) { |
|
| 498 | + $errorInfo = $db->errorInfo(); |
|
| 499 | + $errorMsg = $errorInfo[2]; |
|
| 500 | + throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
| 501 | + } |
|
| 502 | + return $stmt; |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * Create a (non-existent) root folder Document and return it |
|
| 507 | + * @return Document |
|
| 508 | + */ |
|
| 509 | + protected function getRootFolder() |
|
| 510 | + { |
|
| 511 | + $rootFolder = new Document(); |
|
| 512 | + $rootFolder->path = '/'; |
|
| 513 | + $rootFolder->type = 'folder'; |
|
| 514 | + return $rootFolder; |
|
| 515 | + } |
|
| 516 | 516 | |
| 517 | 517 | /** |
| 518 | 518 | * Save the document to the database |
@@ -524,13 +524,13 @@ discard block |
||
| 524 | 524 | * @throws \Exception |
| 525 | 525 | * @internal param $path |
| 526 | 526 | */ |
| 527 | - public function saveDocument($documentObject, $state = 'published') |
|
| 528 | - { |
|
| 527 | + public function saveDocument($documentObject, $state = 'published') |
|
| 528 | + { |
|
| 529 | 529 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
| 530 | 530 | throw new \Exception('Unsupported document state: ' . $state); |
| 531 | 531 | } |
| 532 | - $db = $this->getContentDbHandle(); |
|
| 533 | - $stmt = $this->getDbStatement(' |
|
| 532 | + $db = $this->getContentDbHandle(); |
|
| 533 | + $stmt = $this->getDbStatement(' |
|
| 534 | 534 | INSERT OR REPLACE INTO documents_' . $state . ' (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
| 535 | 535 | VALUES( |
| 536 | 536 | ' . $db->quote($documentObject->path) . ', |
@@ -548,9 +548,9 @@ discard block |
||
| 548 | 548 | ' . $db->quote(json_encode($documentObject->dynamicBricks)) . ' |
| 549 | 549 | ) |
| 550 | 550 | '); |
| 551 | - $result = $stmt->execute(); |
|
| 552 | - return $result; |
|
| 553 | - } |
|
| 551 | + $result = $stmt->execute(); |
|
| 552 | + return $result; |
|
| 553 | + } |
|
| 554 | 554 | |
| 555 | 555 | /** |
| 556 | 556 | * Delete the document from the database |
@@ -561,29 +561,29 @@ discard block |
||
| 561 | 561 | * @internal param string $state |
| 562 | 562 | * |
| 563 | 563 | */ |
| 564 | - public function deleteDocumentByPath($path) |
|
| 565 | - { |
|
| 566 | - $db = $this->getContentDbHandle(); |
|
| 567 | - $documentToDelete = $this->getDocumentByPath($path, 'unpublished'); |
|
| 568 | - if ($documentToDelete instanceof Document) { |
|
| 569 | - if ($documentToDelete->type == 'document') { |
|
| 570 | - $stmt = $this->getDbStatement(' |
|
| 564 | + public function deleteDocumentByPath($path) |
|
| 565 | + { |
|
| 566 | + $db = $this->getContentDbHandle(); |
|
| 567 | + $documentToDelete = $this->getDocumentByPath($path, 'unpublished'); |
|
| 568 | + if ($documentToDelete instanceof Document) { |
|
| 569 | + if ($documentToDelete->type == 'document') { |
|
| 570 | + $stmt = $this->getDbStatement(' |
|
| 571 | 571 | DELETE FROM documents_unpublished |
| 572 | 572 | WHERE path = ' . $db->quote($path) . ' |
| 573 | 573 | '); |
| 574 | - $stmt->execute(); |
|
| 575 | - } elseif ($documentToDelete->type == 'folder') { |
|
| 576 | - $folderPathWithWildcard = $path . '%'; |
|
| 577 | - $stmt = $this->getDbStatement(' |
|
| 574 | + $stmt->execute(); |
|
| 575 | + } elseif ($documentToDelete->type == 'folder') { |
|
| 576 | + $folderPathWithWildcard = $path . '%'; |
|
| 577 | + $stmt = $this->getDbStatement(' |
|
| 578 | 578 | DELETE FROM documents_unpublished |
| 579 | 579 | WHERE (path LIKE ' . $db->quote($folderPathWithWildcard) . ' |
| 580 | 580 | AND substr(`path`, ' . (strlen($path) + 1) . ', 1) = "/") |
| 581 | 581 | OR path = ' . $db->quote($path) . ' |
| 582 | 582 | '); |
| 583 | - $stmt->execute(); |
|
| 584 | - } |
|
| 585 | - } |
|
| 586 | - } |
|
| 583 | + $stmt->execute(); |
|
| 584 | + } |
|
| 585 | + } |
|
| 586 | + } |
|
| 587 | 587 | |
| 588 | 588 | /** |
| 589 | 589 | * @param $document |
@@ -115,13 +115,13 @@ discard block |
||
| 115 | 115 | if (in_array($name, $this->fileBasedSubsets)) { |
| 116 | 116 | return $this->$name; |
| 117 | 117 | } else { |
| 118 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
| 118 | + throw new \Exception('Trying to get undefined property from Repository: '.$name); |
|
| 119 | 119 | } |
| 120 | 120 | } else { |
| 121 | 121 | if (in_array($name, $this->fileBasedSubsets)) { |
| 122 | 122 | return $this->loadSubset($name); |
| 123 | 123 | } else { |
| 124 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
| 124 | + throw new \Exception('Trying to get undefined property from Repository: '.$name); |
|
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | } |
@@ -136,10 +136,10 @@ discard block |
||
| 136 | 136 | { |
| 137 | 137 | if (in_array($name, $this->fileBasedSubsets)) { |
| 138 | 138 | $this->$name = $value; |
| 139 | - $changes = $name . 'Changes'; |
|
| 139 | + $changes = $name.'Changes'; |
|
| 140 | 140 | $this->$changes = true; |
| 141 | 141 | } else { |
| 142 | - throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
| 142 | + throw new \Exception('Trying to persist unknown subset in repository: '.$name.' <br /><pre>'.print_r($value, true).'</pre>'); |
|
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | 145 | |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | public function save() |
| 150 | 150 | { |
| 151 | 151 | $host = $this; |
| 152 | - array_map(function ($value) use ($host) { |
|
| 152 | + array_map(function($value) use ($host) { |
|
| 153 | 153 | $host->saveSubset($value); |
| 154 | 154 | }, $this->fileBasedSubsets); |
| 155 | 155 | } |
@@ -160,14 +160,14 @@ discard block |
||
| 160 | 160 | */ |
| 161 | 161 | public function saveSubset($subset) |
| 162 | 162 | { |
| 163 | - $changes = $subset . 'Changes'; |
|
| 163 | + $changes = $subset.'Changes'; |
|
| 164 | 164 | if ($this->$changes === true) { |
| 165 | 165 | if (!defined('JSON_PRETTY_PRINT')) { |
| 166 | 166 | $json = json_encode($this->$subset); |
| 167 | 167 | } else { |
| 168 | 168 | $json = json_encode($this->$subset, JSON_PRETTY_PRINT); |
| 169 | 169 | } |
| 170 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
| 170 | + $subsetStoragePath = $this->storagePath.DIRECTORY_SEPARATOR.$subset.'.json'; |
|
| 171 | 171 | file_put_contents($subsetStoragePath, $json); |
| 172 | 172 | |
| 173 | 173 | $this->$changes = false; |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | */ |
| 182 | 182 | protected function loadSubset($subset) |
| 183 | 183 | { |
| 184 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
| 184 | + $subsetStoragePath = $this->storagePath.DIRECTORY_SEPARATOR.$subset.'.json'; |
|
| 185 | 185 | $json = file_get_contents($subsetStoragePath); |
| 186 | 186 | $json = json_decode($json); |
| 187 | 187 | $this->$subset = $json; |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | public function getContentDbHandle() |
| 232 | 232 | { |
| 233 | 233 | if ($this->contentDbHandle === null) { |
| 234 | - $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
| 234 | + $this->contentDbHandle = new \PDO('sqlite:'.$this->storagePath.DIRECTORY_SEPARATOR.'content.db'); |
|
| 235 | 235 | } |
| 236 | 236 | return $this->contentDbHandle; |
| 237 | 237 | } |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | public function getDocuments($state = 'published') |
| 248 | 248 | { |
| 249 | 249 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
| 250 | - throw new \Exception('Unsupported document state: ' . $state); |
|
| 250 | + throw new \Exception('Unsupported document state: '.$state); |
|
| 251 | 251 | } |
| 252 | 252 | return $this->getDocumentsByPath('/', $state); |
| 253 | 253 | } |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | public function getDocumentsWithState($folderPath = '/') |
| 256 | 256 | { |
| 257 | 257 | $db = $this->getContentDbHandle(); |
| 258 | - $folderPathWithWildcard = $folderPath . '%'; |
|
| 258 | + $folderPathWithWildcard = $folderPath.'%'; |
|
| 259 | 259 | |
| 260 | 260 | $ifRootIndex = 1; |
| 261 | 261 | if ($folderPath == '/') { |
@@ -270,10 +270,10 @@ discard block |
||
| 270 | 270 | FROM documents_unpublished |
| 271 | 271 | LEFT JOIN documents_published |
| 272 | 272 | ON documents_published.path = documents_unpublished.path |
| 273 | - WHERE documents_unpublished.`path` LIKE ' . $db->quote($folderPathWithWildcard) . ' |
|
| 274 | - AND substr(documents_unpublished.`path`, ' . (strlen($folderPath) + $ifRootIndex + 1) . ') NOT LIKE "%/%" |
|
| 275 | - AND length(documents_unpublished.`path`) > ' . (strlen($folderPath) + $ifRootIndex) . ' |
|
| 276 | - AND documents_unpublished.path != ' . $db->quote($folderPath) . ' |
|
| 273 | + WHERE documents_unpublished.`path` LIKE ' . $db->quote($folderPathWithWildcard).' |
|
| 274 | + AND substr(documents_unpublished.`path`, ' . (strlen($folderPath) + $ifRootIndex + 1).') NOT LIKE "%/%" |
|
| 275 | + AND length(documents_unpublished.`path`) > ' . (strlen($folderPath) + $ifRootIndex).' |
|
| 276 | + AND documents_unpublished.path != ' . $db->quote($folderPath).' |
|
| 277 | 277 | ORDER BY documents_unpublished.`type` DESC, documents_unpublished.`path` ASC |
| 278 | 278 | '; |
| 279 | 279 | $stmt = $this->getDbStatement($sql); |
@@ -300,16 +300,16 @@ discard block |
||
| 300 | 300 | public function getDocumentsByPath($folderPath, $state = 'published') |
| 301 | 301 | { |
| 302 | 302 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
| 303 | - throw new \Exception('Unsupported document state: ' . $state); |
|
| 303 | + throw new \Exception('Unsupported document state: '.$state); |
|
| 304 | 304 | } |
| 305 | 305 | $db = $this->getContentDbHandle(); |
| 306 | - $folderPathWithWildcard = $folderPath . '%'; |
|
| 306 | + $folderPathWithWildcard = $folderPath.'%'; |
|
| 307 | 307 | |
| 308 | 308 | $sql = 'SELECT * |
| 309 | - FROM documents_' . $state . ' |
|
| 310 | - WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard) . ' |
|
| 311 | - AND substr(`path`, ' . (strlen($folderPath) + 1) . ') NOT LIKE "%/%" |
|
| 312 | - AND path != ' . $db->quote($folderPath) . ' |
|
| 309 | + FROM documents_' . $state.' |
|
| 310 | + WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard).' |
|
| 311 | + AND substr(`path`, ' . (strlen($folderPath) + 1).') NOT LIKE "%/%" |
|
| 312 | + AND path != ' . $db->quote($folderPath).' |
|
| 313 | 313 | ORDER BY `type` DESC, `path` ASC'; |
| 314 | 314 | $stmt = $this->getDbStatement($sql); |
| 315 | 315 | |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | if ($containerPath === '/') { |
| 337 | 337 | return $this->getRootFolder(); |
| 338 | 338 | } |
| 339 | - if (substr($containerPath, -1) === '/'){ |
|
| 339 | + if (substr($containerPath, -1) === '/') { |
|
| 340 | 340 | $containerPath = substr($containerPath, 0, -1); |
| 341 | 341 | } |
| 342 | 342 | $containerFolder = $this->getDocumentByPath($containerPath, 'unpublished'); |
@@ -353,13 +353,13 @@ discard block |
||
| 353 | 353 | public function getDocumentByPath($path, $state = 'published') |
| 354 | 354 | { |
| 355 | 355 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
| 356 | - throw new \Exception('Unsupported document state: ' . $state); |
|
| 356 | + throw new \Exception('Unsupported document state: '.$state); |
|
| 357 | 357 | } |
| 358 | 358 | $db = $this->getContentDbHandle(); |
| 359 | 359 | $document = $this->fetchDocument(' |
| 360 | 360 | SELECT * |
| 361 | - FROM documents_' . $state . ' |
|
| 362 | - WHERE path = ' . $db->quote($path) . ' |
|
| 361 | + FROM documents_' . $state.' |
|
| 362 | + WHERE path = ' . $db->quote($path).' |
|
| 363 | 363 | '); |
| 364 | 364 | if ($document instanceof Document && $document->type === 'folder') { |
| 365 | 365 | $document->dbHandle = $db; |
@@ -379,16 +379,16 @@ discard block |
||
| 379 | 379 | public function getTotalDocumentCount($state = 'published') |
| 380 | 380 | { |
| 381 | 381 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
| 382 | - throw new \Exception('Unsupported document state: ' . $state); |
|
| 382 | + throw new \Exception('Unsupported document state: '.$state); |
|
| 383 | 383 | } |
| 384 | 384 | $db = $this->getContentDbHandle(); |
| 385 | 385 | $stmt = $db->query(' |
| 386 | 386 | SELECT count(*) |
| 387 | - FROM documents_' . $state . ' |
|
| 387 | + FROM documents_' . $state.' |
|
| 388 | 388 | WHERE `type` != "folder" |
| 389 | 389 | '); |
| 390 | 390 | $result = $stmt->fetch(\PDO::FETCH_ASSOC); |
| 391 | - if (!is_array($result )) { |
|
| 391 | + if (!is_array($result)) { |
|
| 392 | 392 | return 0; |
| 393 | 393 | } |
| 394 | 394 | return intval(current($result)); |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | if ($stmt === false || !$stmt->execute()) { |
| 408 | 408 | $errorInfo = $db->errorInfo(); |
| 409 | 409 | $errorMsg = $errorInfo[2]; |
| 410 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
| 410 | + throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>'); |
|
| 411 | 411 | } |
| 412 | 412 | return $result; |
| 413 | 413 | } |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | $sql = ' |
| 418 | 418 | INSERT OR REPLACE INTO documents_published |
| 419 | 419 | (`id`,`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`publicationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
| 420 | - SELECT `id`,`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,"published" as state,`lastModificationDate`,`creationDate`,' . time() . ' as publicationDate, `lastModifiedBy`,`fields`,`bricks`,`dynamicBricks` |
|
| 420 | + SELECT `id`,`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,"published" as state,`lastModificationDate`,`creationDate`,' . time().' as publicationDate, `lastModifiedBy`,`fields`,`bricks`,`dynamicBricks` |
|
| 421 | 421 | FROM documents_unpublished |
| 422 | 422 | WHERE `path` = :path |
| 423 | 423 | '; |
@@ -430,7 +430,7 @@ discard block |
||
| 430 | 430 | if ($stmt === false) { |
| 431 | 431 | $errorInfo = $db->errorInfo(); |
| 432 | 432 | $errorMsg = $errorInfo[2]; |
| 433 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
| 433 | + throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>'); |
|
| 434 | 434 | } |
| 435 | 435 | $stmt->bindValue(':path', $path); |
| 436 | 436 | $stmt->execute(); |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | if ($stmt === false) { |
| 498 | 498 | $errorInfo = $db->errorInfo(); |
| 499 | 499 | $errorMsg = $errorInfo[2]; |
| 500 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
| 500 | + throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>'); |
|
| 501 | 501 | } |
| 502 | 502 | return $stmt; |
| 503 | 503 | } |
@@ -527,25 +527,25 @@ discard block |
||
| 527 | 527 | public function saveDocument($documentObject, $state = 'published') |
| 528 | 528 | { |
| 529 | 529 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
| 530 | - throw new \Exception('Unsupported document state: ' . $state); |
|
| 530 | + throw new \Exception('Unsupported document state: '.$state); |
|
| 531 | 531 | } |
| 532 | 532 | $db = $this->getContentDbHandle(); |
| 533 | 533 | $stmt = $this->getDbStatement(' |
| 534 | - INSERT OR REPLACE INTO documents_' . $state . ' (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
|
| 534 | + INSERT OR REPLACE INTO documents_' . $state.' (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
|
| 535 | 535 | VALUES( |
| 536 | - ' . $db->quote($documentObject->path) . ', |
|
| 537 | - ' . $db->quote($documentObject->title) . ', |
|
| 538 | - ' . $db->quote($documentObject->slug) . ', |
|
| 539 | - ' . $db->quote($documentObject->type) . ', |
|
| 540 | - ' . $db->quote($documentObject->documentType) . ', |
|
| 541 | - ' . $db->quote($documentObject->documentTypeSlug) . ', |
|
| 542 | - ' . $db->quote($documentObject->state) . ', |
|
| 543 | - ' . $db->quote($documentObject->lastModificationDate) . ', |
|
| 544 | - ' . $db->quote($documentObject->creationDate) . ', |
|
| 545 | - ' . $db->quote($documentObject->lastModifiedBy) . ', |
|
| 546 | - ' . $db->quote(json_encode($documentObject->fields)) . ', |
|
| 547 | - ' . $db->quote(json_encode($documentObject->bricks)) . ', |
|
| 548 | - ' . $db->quote(json_encode($documentObject->dynamicBricks)) . ' |
|
| 536 | + ' . $db->quote($documentObject->path).', |
|
| 537 | + ' . $db->quote($documentObject->title).', |
|
| 538 | + ' . $db->quote($documentObject->slug).', |
|
| 539 | + ' . $db->quote($documentObject->type).', |
|
| 540 | + ' . $db->quote($documentObject->documentType).', |
|
| 541 | + ' . $db->quote($documentObject->documentTypeSlug).', |
|
| 542 | + ' . $db->quote($documentObject->state).', |
|
| 543 | + ' . $db->quote($documentObject->lastModificationDate).', |
|
| 544 | + ' . $db->quote($documentObject->creationDate).', |
|
| 545 | + ' . $db->quote($documentObject->lastModifiedBy).', |
|
| 546 | + ' . $db->quote(json_encode($documentObject->fields)).', |
|
| 547 | + ' . $db->quote(json_encode($documentObject->bricks)).', |
|
| 548 | + ' . $db->quote(json_encode($documentObject->dynamicBricks)).' |
|
| 549 | 549 | ) |
| 550 | 550 | '); |
| 551 | 551 | $result = $stmt->execute(); |
@@ -569,16 +569,16 @@ discard block |
||
| 569 | 569 | if ($documentToDelete->type == 'document') { |
| 570 | 570 | $stmt = $this->getDbStatement(' |
| 571 | 571 | DELETE FROM documents_unpublished |
| 572 | - WHERE path = ' . $db->quote($path) . ' |
|
| 572 | + WHERE path = ' . $db->quote($path).' |
|
| 573 | 573 | '); |
| 574 | 574 | $stmt->execute(); |
| 575 | 575 | } elseif ($documentToDelete->type == 'folder') { |
| 576 | - $folderPathWithWildcard = $path . '%'; |
|
| 576 | + $folderPathWithWildcard = $path.'%'; |
|
| 577 | 577 | $stmt = $this->getDbStatement(' |
| 578 | 578 | DELETE FROM documents_unpublished |
| 579 | - WHERE (path LIKE ' . $db->quote($folderPathWithWildcard) . ' |
|
| 580 | - AND substr(`path`, ' . (strlen($path) + 1) . ', 1) = "/") |
|
| 581 | - OR path = ' . $db->quote($path) . ' |
|
| 579 | + WHERE (path LIKE ' . $db->quote($folderPathWithWildcard).' |
|
| 580 | + AND substr(`path`, ' . (strlen($path) + 1).', 1) = "/") |
|
| 581 | + OR path = ' . $db->quote($path).' |
|
| 582 | 582 | '); |
| 583 | 583 | $stmt->execute(); |
| 584 | 584 | } |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | $string = strip_tags($string); |
| 49 | 49 | $string = trim($string); |
| 50 | 50 | $string = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $string); // Remove special alphanumeric characters |
| 51 | - $string = str_replace(array('+', '=', '!', ',', '.',';', ':', '?'), ' ', $string); // Replace sentence breaking charaters with spaces |
|
| 51 | + $string = str_replace(array('+', '=', '!', ',', '.', ';', ':', '?'), ' ', $string); // Replace sentence breaking charaters with spaces |
|
| 52 | 52 | $string = preg_replace("/[\r\n]+/", " ", $string); // Replace multiple newlines with a single space. |
| 53 | 53 | $string = preg_replace("/[\t]+/", " ", $string); // Replace multiple tabs with a single space. |
| 54 | 54 | $string = preg_replace("/[^a-zA-Z0-9 ]/", '', $string); // Filter out everything that is not alphanumeric or a space |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | { |
| 67 | 67 | $encoding = mb_detect_encoding($string, mb_detect_order(), false); |
| 68 | 68 | |
| 69 | - if($encoding == "UTF-8") { |
|
| 69 | + if ($encoding == "UTF-8") { |
|
| 70 | 70 | $string = mb_convert_encoding($string, 'UTF-8', 'UTF-8'); |
| 71 | 71 | } |
| 72 | 72 | |
@@ -15,23 +15,23 @@ |
||
| 15 | 15 | |
| 16 | 16 | function sanitize_output($buffer) { |
| 17 | 17 | |
| 18 | - $search = array( |
|
| 19 | - '/\>[^\S ]+/s', // strip whitespaces after tags, except space |
|
| 20 | - '/[^\S ]+\</s', // strip whitespaces before tags, except space |
|
| 21 | - '/(\s)+/s', // shorten multiple whitespace sequences |
|
| 22 | - '/<!--(.|\s)*?-->/' // Remove HTML comments |
|
| 23 | - ); |
|
| 24 | - |
|
| 25 | - $replace = array( |
|
| 26 | - '>', |
|
| 27 | - '<', |
|
| 28 | - '\\1', |
|
| 29 | - '' |
|
| 30 | - ); |
|
| 31 | - |
|
| 32 | - $buffer = preg_replace($search, $replace, $buffer); |
|
| 33 | - |
|
| 34 | - return $buffer; |
|
| 18 | + $search = array( |
|
| 19 | + '/\>[^\S ]+/s', // strip whitespaces after tags, except space |
|
| 20 | + '/[^\S ]+\</s', // strip whitespaces before tags, except space |
|
| 21 | + '/(\s)+/s', // shorten multiple whitespace sequences |
|
| 22 | + '/<!--(.|\s)*?-->/' // Remove HTML comments |
|
| 23 | + ); |
|
| 24 | + |
|
| 25 | + $replace = array( |
|
| 26 | + '>', |
|
| 27 | + '<', |
|
| 28 | + '\\1', |
|
| 29 | + '' |
|
| 30 | + ); |
|
| 31 | + |
|
| 32 | + $buffer = preg_replace($search, $replace, $buffer); |
|
| 33 | + |
|
| 34 | + return $buffer; |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | ob_start("sanitize_output"); |
@@ -16,9 +16,9 @@ discard block |
||
| 16 | 16 | function sanitize_output($buffer) { |
| 17 | 17 | |
| 18 | 18 | $search = array( |
| 19 | - '/\>[^\S ]+/s', // strip whitespaces after tags, except space |
|
| 20 | - '/[^\S ]+\</s', // strip whitespaces before tags, except space |
|
| 21 | - '/(\s)+/s', // shorten multiple whitespace sequences |
|
| 19 | + '/\>[^\S ]+/s', // strip whitespaces after tags, except space |
|
| 20 | + '/[^\S ]+\</s', // strip whitespaces before tags, except space |
|
| 21 | + '/(\s)+/s', // shorten multiple whitespace sequences |
|
| 22 | 22 | '/<!--(.|\s)*?-->/' // Remove HTML comments |
| 23 | 23 | ); |
| 24 | 24 | |
@@ -58,14 +58,14 @@ discard block |
||
| 58 | 58 | { |
| 59 | 59 | $debug_backtrace = current(debug_backtrace()); |
| 60 | 60 | if (PHP_SAPI == 'cli') { |
| 61 | - echo 'Dump: ' . $debug_backtrace['file'] . ':' . $debug_backtrace['line'] . "\n"; |
|
| 61 | + echo 'Dump: '.$debug_backtrace['file'].':'.$debug_backtrace['line']."\n"; |
|
| 62 | 62 | foreach (func_get_args() as $data) { |
| 63 | 63 | var_dump($data); |
| 64 | 64 | } |
| 65 | 65 | } else { |
| 66 | 66 | ob_end_clean(); |
| 67 | 67 | ob_start(); |
| 68 | - echo '<div>Dump: ' . $debug_backtrace['file'] . ':<b>' . $debug_backtrace['line'] . "</b></div>"; |
|
| 68 | + echo '<div>Dump: '.$debug_backtrace['file'].':<b>'.$debug_backtrace['line']."</b></div>"; |
|
| 69 | 69 | echo '<pre>'; |
| 70 | 70 | foreach (func_get_args() as $data) { |
| 71 | 71 | echo "<code>"; |
@@ -113,8 +113,8 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | function utf8Convert($array) |
| 115 | 115 | { |
| 116 | - array_walk_recursive($array, function(&$item){ |
|
| 117 | - if(!mb_detect_encoding($item, 'utf-8', true)){ |
|
| 116 | + array_walk_recursive($array, function(&$item) { |
|
| 117 | + if (!mb_detect_encoding($item, 'utf-8', true)) { |
|
| 118 | 118 | $item = utf8_encode($item); |
| 119 | 119 | } |
| 120 | 120 | }); |
@@ -6,12 +6,12 @@ discard block |
||
| 6 | 6 | } |
| 7 | 7 | ?> |
| 8 | 8 | <div class="rte"> |
| 9 | - <div id="summernote_<?=str_replace(']', '-', str_replace('[','-', $fieldPrefix)) . $field->slug?>_rte_<?=$summernoteInstances?>" class="summernote"><?=isset($value) ? $value : '' ?></div> |
|
| 9 | + <div id="summernote_<?=str_replace(']', '-', str_replace('[', '-', $fieldPrefix)).$field->slug?>_rte_<?=$summernoteInstances?>" class="summernote"><?=isset($value) ? $value : '' ?></div> |
|
| 10 | 10 | </div> |
| 11 | 11 | <textarea style="display:none;" id="summernote_<?=$field->slug?>_container_<?=$summernoteInstances?>" name="<?=$fieldPrefix?>[<?=$field->slug?>][]"></textarea> |
| 12 | 12 | <script> |
| 13 | 13 | $(document).ready(function () { |
| 14 | - $('#summernote_<?=str_replace(']', '-', str_replace('[','-', $fieldPrefix)) . $field->slug?>_rte_<?=$summernoteInstances?>').summernote({ |
|
| 14 | + $('#summernote_<?=str_replace(']', '-', str_replace('[', '-', $fieldPrefix)).$field->slug?>_rte_<?=$summernoteInstances?>').summernote({ |
|
| 15 | 15 | height: 300, |
| 16 | 16 | toolbar: [ |
| 17 | 17 | /*[groupname, [button list]]*/ |
@@ -28,4 +28,4 @@ discard block |
||
| 28 | 28 | if (!isset($GLOBALS['rteList'])) { |
| 29 | 29 | $GLOBALS['rteList'] = array(); |
| 30 | 30 | } |
| 31 | -$GLOBALS['rteList'][] = 'summernote_' . str_replace(']', '-', str_replace('[','-', $fieldPrefix)) . $field->slug . '_rte_' . $summernoteInstances ?> |
|
| 31 | +$GLOBALS['rteList'][] = 'summernote_'.str_replace(']', '-', str_replace('[', '-', $fieldPrefix)).$field->slug.'_rte_'.$summernoteInstances ?> |
|