@@ -83,6 +83,9 @@ discard block |
||
| 83 | 83 | $this->storage = new Storage($this->getStorageDir(), $this->config->imagesDir, $this->config->filesDir); |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | + /** |
|
| 87 | + * @param Request $request |
|
| 88 | + */ |
|
| 86 | 89 | private function redirectMatching($request) |
| 87 | 90 | { |
| 88 | 91 | $redirects = $this->storage->getRedirects()->getRedirects(); |
@@ -112,7 +115,7 @@ discard block |
||
| 112 | 115 | * Loop through sitemap items and see if one matches the requestUri. |
| 113 | 116 | * If it does, add it tot the matchedSitemapItems array |
| 114 | 117 | * |
| 115 | - * @param $request |
|
| 118 | + * @param Request $request |
|
| 116 | 119 | */ |
| 117 | 120 | private function sitemapMatching($request) |
| 118 | 121 | { |
@@ -177,7 +180,7 @@ discard block |
||
| 177 | 180 | * @param array $parameters |
| 178 | 181 | * @param \stdClass|null $matchedSitemapItem |
| 179 | 182 | * |
| 180 | - * @return mixed |
|
| 183 | + * @return Component |
|
| 181 | 184 | * @throws \Exception |
| 182 | 185 | */ |
| 183 | 186 | private function getComponentObject($class = '', $template = '', $parameters = array(), $matchedSitemapItem) |
@@ -268,6 +271,9 @@ discard block |
||
| 268 | 271 | return $this->config->templateDir; |
| 269 | 272 | } |
| 270 | 273 | |
| 274 | + /** |
|
| 275 | + * @return string |
|
| 276 | + */ |
|
| 271 | 277 | public function getStorageDir() |
| 272 | 278 | { |
| 273 | 279 | return $this->config->storageDir; |
@@ -2,280 +2,280 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace CloudControl\Cms\cc { |
| 4 | 4 | |
| 5 | - use CloudControl\Cms\components\Component; |
|
| 6 | - use CloudControl\Cms\storage\Storage; |
|
| 7 | - use Whoops\Handler\PrettyPageHandler; |
|
| 8 | - use Whoops\Run; |
|
| 9 | - |
|
| 10 | - class Application |
|
| 11 | - { |
|
| 12 | - /** |
|
| 13 | - * @var \stdClass |
|
| 14 | - */ |
|
| 15 | - private $config; |
|
| 16 | - /** |
|
| 17 | - * @var \CloudControl\Cms\storage\Storage |
|
| 18 | - */ |
|
| 19 | - private $storage; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @var \CloudControl\Cms\cc\Request |
|
| 23 | - */ |
|
| 24 | - private $request; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var array |
|
| 28 | - */ |
|
| 29 | - private $matchedSitemapItems = array(); |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var array |
|
| 33 | - */ |
|
| 34 | - private $applicationComponents = array(); |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Application constructor. |
|
| 38 | - */ |
|
| 39 | - public function __construct() |
|
| 40 | - { |
|
| 41 | - $this->config(); |
|
| 42 | - $this->storage(); |
|
| 43 | - |
|
| 44 | - $this->request = new Request(); |
|
| 45 | - |
|
| 46 | - $whoops = new Run; |
|
| 47 | - $whoops->pushHandler(new PrettyPageHandler); |
|
| 48 | - $whoops->register(); |
|
| 49 | - |
|
| 50 | - $this->redirectMatching($this->request); |
|
| 51 | - $this->sitemapMatching($this->request); |
|
| 52 | - |
|
| 53 | - $this->getApplicationComponents(); |
|
| 54 | - |
|
| 55 | - $this->runApplicationComponents(); |
|
| 56 | - $this->runSitemapComponents(); |
|
| 57 | - |
|
| 58 | - $this->renderApplicationComponents(); |
|
| 59 | - $this->renderSitemapComponents(); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Initialize the config |
|
| 64 | - * |
|
| 65 | - * @throws \Exception |
|
| 66 | - */ |
|
| 67 | - private function config() |
|
| 68 | - { |
|
| 69 | - $configPath = __DIR__ . '/../../config.json'; |
|
| 70 | - if (realpath($configPath) !== false) { |
|
| 71 | - $json = file_get_contents($configPath); |
|
| 72 | - $this->config = json_decode($json); |
|
| 73 | - } else { |
|
| 74 | - throw new \Exception('Framework not initialized yet. Consider running composer install'); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Initialize the storage |
|
| 80 | - */ |
|
| 81 | - private function storage() |
|
| 82 | - { |
|
| 83 | - $this->storage = new Storage($this->getStorageDir(), $this->config->imagesDir, $this->config->filesDir); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - private function redirectMatching($request) |
|
| 87 | - { |
|
| 88 | - $redirects = $this->storage->getRedirects()->getRedirects(); |
|
| 89 | - $relativeUri = '/' . $request::$relativeUri; |
|
| 90 | - |
|
| 91 | - foreach ($redirects as $redirect) { |
|
| 92 | - if (preg_match_all($redirect->fromUrl, $relativeUri, $matches)) { |
|
| 93 | - $toUrl = preg_replace($redirect->fromUrl, $redirect->toUrl, $relativeUri); |
|
| 94 | - if (substr($toUrl, 0, 1) == '/') { |
|
| 95 | - $toUrl = substr($toUrl, 1); |
|
| 96 | - } |
|
| 97 | - if ($redirect->type == '301') { |
|
| 98 | - header('HTTP/1.1 301 Moved Permanently'); |
|
| 99 | - header('Location: ' . $request::$subfolders . $toUrl); |
|
| 100 | - exit; |
|
| 101 | - } elseif ($redirect->type == '302') { |
|
| 102 | - header('Location: ' . $request::$subfolders . $toUrl, true, 302); |
|
| 103 | - exit; |
|
| 104 | - } else { |
|
| 105 | - throw new \Exception('Invalid redirect type.'); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Loop through sitemap items and see if one matches the requestUri. |
|
| 113 | - * If it does, add it tot the matchedSitemapItems array |
|
| 114 | - * |
|
| 115 | - * @param $request |
|
| 116 | - */ |
|
| 117 | - private function sitemapMatching($request) |
|
| 118 | - { |
|
| 119 | - $sitemap = $this->storage->getSitemap()->getSitemap(); |
|
| 120 | - $relativeUri = '/' . $request::$relativeUri; |
|
| 121 | - |
|
| 122 | - foreach ($sitemap as $sitemapItem) { |
|
| 123 | - if ($sitemapItem->regex) { |
|
| 124 | - $matches = array(); |
|
| 125 | - if (preg_match_all($sitemapItem->url, $relativeUri, $matches)) { |
|
| 126 | - // Make a clone, so it doesnt add the matches to the original |
|
| 127 | - $matchedClone = clone $sitemapItem; |
|
| 128 | - $matchedClone->matches = $matches; |
|
| 129 | - $this->matchedSitemapItems[] = $matchedClone; |
|
| 130 | - return; |
|
| 131 | - } |
|
| 132 | - } else { |
|
| 133 | - if ($sitemapItem->url == $relativeUri) { |
|
| 134 | - $this->matchedSitemapItems[] = $sitemapItem; |
|
| 135 | - return; |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Loop through all application components and run them |
|
| 143 | - * |
|
| 144 | - * @throws \Exception |
|
| 145 | - */ |
|
| 146 | - private function runApplicationComponents() |
|
| 147 | - { |
|
| 148 | - foreach ($this->applicationComponents as $key => $applicationComponent) { |
|
| 149 | - $class = $applicationComponent->component; |
|
| 150 | - $parameters = $applicationComponent->parameters; |
|
| 151 | - $this->applicationComponents[$key]->{'object'} = $this->getComponentObject($class, null, $parameters, null); |
|
| 152 | - $this->applicationComponents[$key]->{'object'}->run($this->storage); |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Loop through all (matched) sitemap components and run them |
|
| 158 | - * |
|
| 159 | - * @throws \Exception |
|
| 160 | - */ |
|
| 161 | - private function runSitemapComponents() |
|
| 162 | - { |
|
| 163 | - foreach ($this->matchedSitemapItems as $key => $sitemapItem) { |
|
| 164 | - $class = $sitemapItem->component; |
|
| 165 | - $template = $sitemapItem->template; |
|
| 166 | - $parameters = $sitemapItem->parameters; |
|
| 167 | - |
|
| 168 | - $this->matchedSitemapItems[$key]->object = $this->getComponentObject($class, $template, $parameters, $sitemapItem); |
|
| 169 | - |
|
| 170 | - $this->matchedSitemapItems[$key]->object->run($this->storage); |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * @param string $class |
|
| 176 | - * @param string $template |
|
| 177 | - * @param array $parameters |
|
| 178 | - * @param \stdClass|null $matchedSitemapItem |
|
| 179 | - * |
|
| 180 | - * @return mixed |
|
| 181 | - * @throws \Exception |
|
| 182 | - */ |
|
| 183 | - private function getComponentObject($class = '', $template = '', $parameters = array(), $matchedSitemapItem) |
|
| 184 | - { |
|
| 185 | - $libraryComponentName = '\\CloudControl\Cms\\components\\' . $class; |
|
| 186 | - $userComponentName = '\\components\\' . $class; |
|
| 187 | - |
|
| 188 | - if (!class_exists($libraryComponentName, false)) { |
|
| 189 | - $component = new $libraryComponentName($template, $this->request, $parameters, $matchedSitemapItem); |
|
| 190 | - } elseif (!class_exists($userComponentName, false)) { |
|
| 191 | - $component = new $userComponentName($template, $this->request, $parameters, $matchedSitemapItem); |
|
| 192 | - } else { |
|
| 193 | - throw new \Exception('Could not load component ' . $class); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - if (!$component instanceof Component) { |
|
| 197 | - throw new \Exception('Component not of type Component. Must inherit \CloudControl\Cms\components\Component'); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - return $component; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Loop through all application components and render them |
|
| 205 | - */ |
|
| 206 | - private function renderApplicationComponents() |
|
| 207 | - { |
|
| 208 | - foreach ($this->applicationComponents as $applicationComponent) { |
|
| 209 | - $applicationComponent->{'object'}->render(); |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * Loop through all (matched) sitemap components and render them |
|
| 215 | - */ |
|
| 216 | - private function renderSitemapComponents() |
|
| 217 | - { |
|
| 218 | - foreach ($this->matchedSitemapItems as $sitemapItem) { |
|
| 219 | - $this->setCachingHeaders(); |
|
| 220 | - $sitemapItem->object->render($this); |
|
| 221 | - ob_clean(); |
|
| 222 | - echo $sitemapItem->object->get(); |
|
| 223 | - ob_end_flush(); |
|
| 224 | - exit; |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - public function getAllApplicationComponentParameters() |
|
| 229 | - { |
|
| 230 | - $allParameters = array(); |
|
| 231 | - foreach ($this->applicationComponents as $applicationComponent) { |
|
| 232 | - $parameters = $applicationComponent->{'object'}->getParameters(); |
|
| 233 | - $allParameters[] = $parameters; |
|
| 234 | - } |
|
| 235 | - return $allParameters; |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - public function unlockApplicationComponentParameters() |
|
| 239 | - { |
|
| 240 | - foreach ($this->applicationComponents as $applicationComponent) { |
|
| 241 | - $parameters = $applicationComponent->{'object'}->getParameters(); |
|
| 242 | - extract($parameters); |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * Set the default caching of pages to 2 days |
|
| 248 | - */ |
|
| 249 | - public function setCachingHeaders() |
|
| 250 | - { |
|
| 251 | - header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60 * 24 * 2))); // 2 days |
|
| 252 | - header("Cache-Control: max-age=" . (60 * 60 * 24 * 2)); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * @return string |
|
| 257 | - */ |
|
| 258 | - public function getStoragePath() |
|
| 259 | - { |
|
| 260 | - return $this->config->storagePath; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * @return string |
|
| 265 | - */ |
|
| 266 | - public function getTemplatePath() |
|
| 267 | - { |
|
| 268 | - return $this->config->templateDir; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - public function getStorageDir() |
|
| 272 | - { |
|
| 273 | - return $this->config->storageDir; |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - public function getApplicationComponents() |
|
| 277 | - { |
|
| 278 | - $this->applicationComponents = $this->storage->getApplicationComponents()->getApplicationComponents(); |
|
| 279 | - } |
|
| 280 | - } |
|
| 5 | + use CloudControl\Cms\components\Component; |
|
| 6 | + use CloudControl\Cms\storage\Storage; |
|
| 7 | + use Whoops\Handler\PrettyPageHandler; |
|
| 8 | + use Whoops\Run; |
|
| 9 | + |
|
| 10 | + class Application |
|
| 11 | + { |
|
| 12 | + /** |
|
| 13 | + * @var \stdClass |
|
| 14 | + */ |
|
| 15 | + private $config; |
|
| 16 | + /** |
|
| 17 | + * @var \CloudControl\Cms\storage\Storage |
|
| 18 | + */ |
|
| 19 | + private $storage; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @var \CloudControl\Cms\cc\Request |
|
| 23 | + */ |
|
| 24 | + private $request; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var array |
|
| 28 | + */ |
|
| 29 | + private $matchedSitemapItems = array(); |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var array |
|
| 33 | + */ |
|
| 34 | + private $applicationComponents = array(); |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Application constructor. |
|
| 38 | + */ |
|
| 39 | + public function __construct() |
|
| 40 | + { |
|
| 41 | + $this->config(); |
|
| 42 | + $this->storage(); |
|
| 43 | + |
|
| 44 | + $this->request = new Request(); |
|
| 45 | + |
|
| 46 | + $whoops = new Run; |
|
| 47 | + $whoops->pushHandler(new PrettyPageHandler); |
|
| 48 | + $whoops->register(); |
|
| 49 | + |
|
| 50 | + $this->redirectMatching($this->request); |
|
| 51 | + $this->sitemapMatching($this->request); |
|
| 52 | + |
|
| 53 | + $this->getApplicationComponents(); |
|
| 54 | + |
|
| 55 | + $this->runApplicationComponents(); |
|
| 56 | + $this->runSitemapComponents(); |
|
| 57 | + |
|
| 58 | + $this->renderApplicationComponents(); |
|
| 59 | + $this->renderSitemapComponents(); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Initialize the config |
|
| 64 | + * |
|
| 65 | + * @throws \Exception |
|
| 66 | + */ |
|
| 67 | + private function config() |
|
| 68 | + { |
|
| 69 | + $configPath = __DIR__ . '/../../config.json'; |
|
| 70 | + if (realpath($configPath) !== false) { |
|
| 71 | + $json = file_get_contents($configPath); |
|
| 72 | + $this->config = json_decode($json); |
|
| 73 | + } else { |
|
| 74 | + throw new \Exception('Framework not initialized yet. Consider running composer install'); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Initialize the storage |
|
| 80 | + */ |
|
| 81 | + private function storage() |
|
| 82 | + { |
|
| 83 | + $this->storage = new Storage($this->getStorageDir(), $this->config->imagesDir, $this->config->filesDir); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + private function redirectMatching($request) |
|
| 87 | + { |
|
| 88 | + $redirects = $this->storage->getRedirects()->getRedirects(); |
|
| 89 | + $relativeUri = '/' . $request::$relativeUri; |
|
| 90 | + |
|
| 91 | + foreach ($redirects as $redirect) { |
|
| 92 | + if (preg_match_all($redirect->fromUrl, $relativeUri, $matches)) { |
|
| 93 | + $toUrl = preg_replace($redirect->fromUrl, $redirect->toUrl, $relativeUri); |
|
| 94 | + if (substr($toUrl, 0, 1) == '/') { |
|
| 95 | + $toUrl = substr($toUrl, 1); |
|
| 96 | + } |
|
| 97 | + if ($redirect->type == '301') { |
|
| 98 | + header('HTTP/1.1 301 Moved Permanently'); |
|
| 99 | + header('Location: ' . $request::$subfolders . $toUrl); |
|
| 100 | + exit; |
|
| 101 | + } elseif ($redirect->type == '302') { |
|
| 102 | + header('Location: ' . $request::$subfolders . $toUrl, true, 302); |
|
| 103 | + exit; |
|
| 104 | + } else { |
|
| 105 | + throw new \Exception('Invalid redirect type.'); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Loop through sitemap items and see if one matches the requestUri. |
|
| 113 | + * If it does, add it tot the matchedSitemapItems array |
|
| 114 | + * |
|
| 115 | + * @param $request |
|
| 116 | + */ |
|
| 117 | + private function sitemapMatching($request) |
|
| 118 | + { |
|
| 119 | + $sitemap = $this->storage->getSitemap()->getSitemap(); |
|
| 120 | + $relativeUri = '/' . $request::$relativeUri; |
|
| 121 | + |
|
| 122 | + foreach ($sitemap as $sitemapItem) { |
|
| 123 | + if ($sitemapItem->regex) { |
|
| 124 | + $matches = array(); |
|
| 125 | + if (preg_match_all($sitemapItem->url, $relativeUri, $matches)) { |
|
| 126 | + // Make a clone, so it doesnt add the matches to the original |
|
| 127 | + $matchedClone = clone $sitemapItem; |
|
| 128 | + $matchedClone->matches = $matches; |
|
| 129 | + $this->matchedSitemapItems[] = $matchedClone; |
|
| 130 | + return; |
|
| 131 | + } |
|
| 132 | + } else { |
|
| 133 | + if ($sitemapItem->url == $relativeUri) { |
|
| 134 | + $this->matchedSitemapItems[] = $sitemapItem; |
|
| 135 | + return; |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Loop through all application components and run them |
|
| 143 | + * |
|
| 144 | + * @throws \Exception |
|
| 145 | + */ |
|
| 146 | + private function runApplicationComponents() |
|
| 147 | + { |
|
| 148 | + foreach ($this->applicationComponents as $key => $applicationComponent) { |
|
| 149 | + $class = $applicationComponent->component; |
|
| 150 | + $parameters = $applicationComponent->parameters; |
|
| 151 | + $this->applicationComponents[$key]->{'object'} = $this->getComponentObject($class, null, $parameters, null); |
|
| 152 | + $this->applicationComponents[$key]->{'object'}->run($this->storage); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Loop through all (matched) sitemap components and run them |
|
| 158 | + * |
|
| 159 | + * @throws \Exception |
|
| 160 | + */ |
|
| 161 | + private function runSitemapComponents() |
|
| 162 | + { |
|
| 163 | + foreach ($this->matchedSitemapItems as $key => $sitemapItem) { |
|
| 164 | + $class = $sitemapItem->component; |
|
| 165 | + $template = $sitemapItem->template; |
|
| 166 | + $parameters = $sitemapItem->parameters; |
|
| 167 | + |
|
| 168 | + $this->matchedSitemapItems[$key]->object = $this->getComponentObject($class, $template, $parameters, $sitemapItem); |
|
| 169 | + |
|
| 170 | + $this->matchedSitemapItems[$key]->object->run($this->storage); |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * @param string $class |
|
| 176 | + * @param string $template |
|
| 177 | + * @param array $parameters |
|
| 178 | + * @param \stdClass|null $matchedSitemapItem |
|
| 179 | + * |
|
| 180 | + * @return mixed |
|
| 181 | + * @throws \Exception |
|
| 182 | + */ |
|
| 183 | + private function getComponentObject($class = '', $template = '', $parameters = array(), $matchedSitemapItem) |
|
| 184 | + { |
|
| 185 | + $libraryComponentName = '\\CloudControl\Cms\\components\\' . $class; |
|
| 186 | + $userComponentName = '\\components\\' . $class; |
|
| 187 | + |
|
| 188 | + if (!class_exists($libraryComponentName, false)) { |
|
| 189 | + $component = new $libraryComponentName($template, $this->request, $parameters, $matchedSitemapItem); |
|
| 190 | + } elseif (!class_exists($userComponentName, false)) { |
|
| 191 | + $component = new $userComponentName($template, $this->request, $parameters, $matchedSitemapItem); |
|
| 192 | + } else { |
|
| 193 | + throw new \Exception('Could not load component ' . $class); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + if (!$component instanceof Component) { |
|
| 197 | + throw new \Exception('Component not of type Component. Must inherit \CloudControl\Cms\components\Component'); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + return $component; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Loop through all application components and render them |
|
| 205 | + */ |
|
| 206 | + private function renderApplicationComponents() |
|
| 207 | + { |
|
| 208 | + foreach ($this->applicationComponents as $applicationComponent) { |
|
| 209 | + $applicationComponent->{'object'}->render(); |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * Loop through all (matched) sitemap components and render them |
|
| 215 | + */ |
|
| 216 | + private function renderSitemapComponents() |
|
| 217 | + { |
|
| 218 | + foreach ($this->matchedSitemapItems as $sitemapItem) { |
|
| 219 | + $this->setCachingHeaders(); |
|
| 220 | + $sitemapItem->object->render($this); |
|
| 221 | + ob_clean(); |
|
| 222 | + echo $sitemapItem->object->get(); |
|
| 223 | + ob_end_flush(); |
|
| 224 | + exit; |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + public function getAllApplicationComponentParameters() |
|
| 229 | + { |
|
| 230 | + $allParameters = array(); |
|
| 231 | + foreach ($this->applicationComponents as $applicationComponent) { |
|
| 232 | + $parameters = $applicationComponent->{'object'}->getParameters(); |
|
| 233 | + $allParameters[] = $parameters; |
|
| 234 | + } |
|
| 235 | + return $allParameters; |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + public function unlockApplicationComponentParameters() |
|
| 239 | + { |
|
| 240 | + foreach ($this->applicationComponents as $applicationComponent) { |
|
| 241 | + $parameters = $applicationComponent->{'object'}->getParameters(); |
|
| 242 | + extract($parameters); |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * Set the default caching of pages to 2 days |
|
| 248 | + */ |
|
| 249 | + public function setCachingHeaders() |
|
| 250 | + { |
|
| 251 | + header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60 * 24 * 2))); // 2 days |
|
| 252 | + header("Cache-Control: max-age=" . (60 * 60 * 24 * 2)); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * @return string |
|
| 257 | + */ |
|
| 258 | + public function getStoragePath() |
|
| 259 | + { |
|
| 260 | + return $this->config->storagePath; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * @return string |
|
| 265 | + */ |
|
| 266 | + public function getTemplatePath() |
|
| 267 | + { |
|
| 268 | + return $this->config->templateDir; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + public function getStorageDir() |
|
| 272 | + { |
|
| 273 | + return $this->config->storageDir; |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + public function getApplicationComponents() |
|
| 277 | + { |
|
| 278 | + $this->applicationComponents = $this->storage->getApplicationComponents()->getApplicationComponents(); |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | 281 | } |
| 282 | 282 | \ No newline at end of file |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | private function config() |
| 68 | 68 | { |
| 69 | - $configPath = __DIR__ . '/../../config.json'; |
|
| 69 | + $configPath = __DIR__.'/../../config.json'; |
|
| 70 | 70 | if (realpath($configPath) !== false) { |
| 71 | 71 | $json = file_get_contents($configPath); |
| 72 | 72 | $this->config = json_decode($json); |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | private function redirectMatching($request) |
| 87 | 87 | { |
| 88 | 88 | $redirects = $this->storage->getRedirects()->getRedirects(); |
| 89 | - $relativeUri = '/' . $request::$relativeUri; |
|
| 89 | + $relativeUri = '/'.$request::$relativeUri; |
|
| 90 | 90 | |
| 91 | 91 | foreach ($redirects as $redirect) { |
| 92 | 92 | if (preg_match_all($redirect->fromUrl, $relativeUri, $matches)) { |
@@ -96,10 +96,10 @@ discard block |
||
| 96 | 96 | } |
| 97 | 97 | if ($redirect->type == '301') { |
| 98 | 98 | header('HTTP/1.1 301 Moved Permanently'); |
| 99 | - header('Location: ' . $request::$subfolders . $toUrl); |
|
| 99 | + header('Location: '.$request::$subfolders.$toUrl); |
|
| 100 | 100 | exit; |
| 101 | 101 | } elseif ($redirect->type == '302') { |
| 102 | - header('Location: ' . $request::$subfolders . $toUrl, true, 302); |
|
| 102 | + header('Location: '.$request::$subfolders.$toUrl, true, 302); |
|
| 103 | 103 | exit; |
| 104 | 104 | } else { |
| 105 | 105 | throw new \Exception('Invalid redirect type.'); |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | private function sitemapMatching($request) |
| 118 | 118 | { |
| 119 | 119 | $sitemap = $this->storage->getSitemap()->getSitemap(); |
| 120 | - $relativeUri = '/' . $request::$relativeUri; |
|
| 120 | + $relativeUri = '/'.$request::$relativeUri; |
|
| 121 | 121 | |
| 122 | 122 | foreach ($sitemap as $sitemapItem) { |
| 123 | 123 | if ($sitemapItem->regex) { |
@@ -182,15 +182,15 @@ discard block |
||
| 182 | 182 | */ |
| 183 | 183 | private function getComponentObject($class = '', $template = '', $parameters = array(), $matchedSitemapItem) |
| 184 | 184 | { |
| 185 | - $libraryComponentName = '\\CloudControl\Cms\\components\\' . $class; |
|
| 186 | - $userComponentName = '\\components\\' . $class; |
|
| 185 | + $libraryComponentName = '\\CloudControl\Cms\\components\\'.$class; |
|
| 186 | + $userComponentName = '\\components\\'.$class; |
|
| 187 | 187 | |
| 188 | 188 | if (!class_exists($libraryComponentName, false)) { |
| 189 | 189 | $component = new $libraryComponentName($template, $this->request, $parameters, $matchedSitemapItem); |
| 190 | 190 | } elseif (!class_exists($userComponentName, false)) { |
| 191 | 191 | $component = new $userComponentName($template, $this->request, $parameters, $matchedSitemapItem); |
| 192 | 192 | } else { |
| 193 | - throw new \Exception('Could not load component ' . $class); |
|
| 193 | + throw new \Exception('Could not load component '.$class); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | if (!$component instanceof Component) { |
@@ -248,8 +248,8 @@ discard block |
||
| 248 | 248 | */ |
| 249 | 249 | public function setCachingHeaders() |
| 250 | 250 | { |
| 251 | - header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60 * 24 * 2))); // 2 days |
|
| 252 | - header("Cache-Control: max-age=" . (60 * 60 * 24 * 2)); |
|
| 251 | + header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60 * 24 * 2))); // 2 days |
|
| 252 | + header("Cache-Control: max-age=".(60 * 60 * 24 * 2)); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
@@ -141,8 +141,8 @@ |
||
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
| 144 | - * @param $template |
|
| 145 | - * @param null $application |
|
| 144 | + * @param string $template |
|
| 145 | + * @param null|Application $application |
|
| 146 | 146 | * @return string |
| 147 | 147 | */ |
| 148 | 148 | protected function getTemplatePath($template, $application=null) |
@@ -2,10 +2,10 @@ discard block |
||
| 2 | 2 | namespace CloudControl\Cms\components |
| 3 | 3 | { |
| 4 | 4 | |
| 5 | - use CloudControl\Cms\cc\Request; |
|
| 6 | - use CloudControl\Cms\storage\Storage; |
|
| 5 | + use CloudControl\Cms\cc\Request; |
|
| 6 | + use CloudControl\Cms\storage\Storage; |
|
| 7 | 7 | |
| 8 | - class BaseComponent implements Component |
|
| 8 | + class BaseComponent implements Component |
|
| 9 | 9 | { |
| 10 | 10 | /** |
| 11 | 11 | * @var string |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | */ |
| 94 | 94 | public function renderTemplate($template='', $obClean = true, $application=null) |
| 95 | 95 | { |
| 96 | - $templatePath = $this->getTemplatePath($template, $application); |
|
| 96 | + $templatePath = $this->getTemplatePath($template, $application); |
|
| 97 | 97 | if (realpath($templatePath) !== false) { |
| 98 | 98 | if ($obClean) { |
| 99 | 99 | ob_clean(); |
@@ -140,16 +140,16 @@ discard block |
||
| 140 | 140 | return $this->parameters; |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - /** |
|
| 144 | - * @param $template |
|
| 145 | - * @param null $application |
|
| 146 | - * @return string |
|
| 147 | - */ |
|
| 148 | - protected function getTemplatePath($template, $application=null) |
|
| 149 | - { |
|
| 150 | - $templatePath = $application->getTemplatePath(); |
|
| 151 | - $templatePath = $templatePath . DIRECTORY_SEPARATOR . $template . '.php'; |
|
| 152 | - return $templatePath; |
|
| 153 | - } |
|
| 154 | - } |
|
| 143 | + /** |
|
| 144 | + * @param $template |
|
| 145 | + * @param null $application |
|
| 146 | + * @return string |
|
| 147 | + */ |
|
| 148 | + protected function getTemplatePath($template, $application=null) |
|
| 149 | + { |
|
| 150 | + $templatePath = $application->getTemplatePath(); |
|
| 151 | + $templatePath = $templatePath . DIRECTORY_SEPARATOR . $template . '.php'; |
|
| 152 | + return $templatePath; |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | 155 | } |
| 156 | 156 | \ No newline at end of file |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * @param array $parameters |
| 41 | 41 | * @param $matchedSitemapItem |
| 42 | 42 | */ |
| 43 | - public function __construct($template='', Request $request, $parameters=array(), $matchedSitemapItem) |
|
| 43 | + public function __construct($template = '', Request $request, $parameters = array(), $matchedSitemapItem) |
|
| 44 | 44 | { |
| 45 | 45 | $this->template = $template; |
| 46 | 46 | $this->request = $request; |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * |
| 66 | 66 | * @throws \Exception |
| 67 | 67 | */ |
| 68 | - public function render($application=null) |
|
| 68 | + public function render($application = null) |
|
| 69 | 69 | { |
| 70 | 70 | $this->renderedContent = $this->renderTemplate($this->template, true, $application); |
| 71 | 71 | } |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | * @return string |
| 92 | 92 | * @throws \Exception |
| 93 | 93 | */ |
| 94 | - public function renderTemplate($template='', $obClean = true, $application=null) |
|
| 94 | + public function renderTemplate($template = '', $obClean = true, $application = null) |
|
| 95 | 95 | { |
| 96 | 96 | $templatePath = $this->getTemplatePath($template, $application); |
| 97 | 97 | if (realpath($templatePath) !== false) { |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | return ob_get_contents(); |
| 111 | 111 | } else { |
| 112 | 112 | if ($template !== null) { // If template is null, its a application component, which doesnt have a template |
| 113 | - throw new \Exception('Couldnt find template ' . $templatePath); |
|
| 113 | + throw new \Exception('Couldnt find template '.$templatePath); |
|
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | } |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | * @return string |
| 126 | 126 | * @throws \Exception |
| 127 | 127 | */ |
| 128 | - public function includeTemplate($template='', $parameters = array()) |
|
| 128 | + public function includeTemplate($template = '', $parameters = array()) |
|
| 129 | 129 | { |
| 130 | 130 | if (is_array($parameters)) { |
| 131 | 131 | foreach ($parameters as $name => $value) { |
@@ -145,10 +145,10 @@ discard block |
||
| 145 | 145 | * @param null $application |
| 146 | 146 | * @return string |
| 147 | 147 | */ |
| 148 | - protected function getTemplatePath($template, $application=null) |
|
| 148 | + protected function getTemplatePath($template, $application = null) |
|
| 149 | 149 | { |
| 150 | 150 | $templatePath = $application->getTemplatePath(); |
| 151 | - $templatePath = $templatePath . DIRECTORY_SEPARATOR . $template . '.php'; |
|
| 151 | + $templatePath = $templatePath.DIRECTORY_SEPARATOR.$template.'.php'; |
|
| 152 | 152 | return $templatePath; |
| 153 | 153 | } |
| 154 | 154 | } |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | - * @param $request |
|
| 71 | + * @param Request $request |
|
| 72 | 72 | * @param CmsComponent $cmsComponent |
| 73 | 73 | */ |
| 74 | 74 | private function newRoute($request, $cmsComponent) |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
| 86 | - * @param $request |
|
| 86 | + * @param Request $request |
|
| 87 | 87 | * @param CmsComponent $cmsComponent |
| 88 | 88 | */ |
| 89 | 89 | private function deleteRoute($request, $cmsComponent) |
@@ -40,21 +40,21 @@ discard block |
||
| 40 | 40 | { |
| 41 | 41 | $file = $cmsComponent->storage->getFiles()->getFileByName($slug); |
| 42 | 42 | // TODO FIX THIS PATH |
| 43 | - $path = realpath(__DIR__ . '/../www/files/'); |
|
| 44 | - $quoted = sprintf('"%s"', addcslashes(basename($path . '/' . $file->file), '"\\')); |
|
| 45 | - $size = filesize($path . '/' . $file->file); |
|
| 43 | + $path = realpath(__DIR__.'/../www/files/'); |
|
| 44 | + $quoted = sprintf('"%s"', addcslashes(basename($path.'/'.$file->file), '"\\')); |
|
| 45 | + $size = filesize($path.'/'.$file->file); |
|
| 46 | 46 | |
| 47 | 47 | header('Content-Description: File Transfer'); |
| 48 | - header('Content-Type: ' . $file->type); |
|
| 49 | - header('Content-Disposition: attachment; filename=' . $quoted); |
|
| 48 | + header('Content-Type: '.$file->type); |
|
| 49 | + header('Content-Disposition: attachment; filename='.$quoted); |
|
| 50 | 50 | header('Content-Transfer-Encoding: binary'); |
| 51 | 51 | header('Connection: Keep-Alive'); |
| 52 | 52 | header('Expires: 0'); |
| 53 | 53 | header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
| 54 | 54 | header('Pragma: public'); |
| 55 | - header('Content-Length: ' . $size); |
|
| 55 | + header('Content-Length: '.$size); |
|
| 56 | 56 | |
| 57 | - readfile($path . '/' . $file->file); |
|
| 57 | + readfile($path.'/'.$file->file); |
|
| 58 | 58 | exit; |
| 59 | 59 | } |
| 60 | 60 | |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_FILES); |
| 79 | 79 | if (isset($_FILES[CmsComponent::FILES_PARAMETER_FILE])) { |
| 80 | 80 | $cmsComponent->storage->getFiles()->addFile($_FILES[CmsComponent::FILES_PARAMETER_FILE]); |
| 81 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/files'); |
|
| 81 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/files'); |
|
| 82 | 82 | exit; |
| 83 | 83 | } |
| 84 | 84 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | private function deleteRoute($request, $cmsComponent) |
| 91 | 91 | { |
| 92 | 92 | $cmsComponent->storage->getFiles()->deleteFileByName($request::$get[CmsComponent::FILES_PARAMETER_FILE]); |
| 93 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/files'); |
|
| 93 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/files'); |
|
| 94 | 94 | exit; |
| 95 | 95 | } |
| 96 | 96 | |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /** |
| 183 | - * @param \cc\Request $request |
|
| 183 | + * @param \CloudControl\Cms\cc\Request $request |
|
| 184 | 184 | * @return array |
| 185 | 185 | */ |
| 186 | 186 | private function getPostValues($request) |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | /** |
| 294 | - * @return \cc\Request |
|
| 294 | + * @return \CloudControl\Cms\cc\Request |
|
| 295 | 295 | */ |
| 296 | 296 | private function setPathBackup() |
| 297 | 297 | { |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
| 308 | - * @param \cc\Request $request |
|
| 308 | + * @param \CloudControl\Cms\cc\Request $request |
|
| 309 | 309 | */ |
| 310 | 310 | private function resetPathBackup($request) |
| 311 | 311 | { |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | /** |
| 320 | - * @param $form |
|
| 320 | + * @param string|null $form |
|
| 321 | 321 | */ |
| 322 | 322 | private function setFormParameter($form) |
| 323 | 323 | { |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | if (isset($_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID])) { |
| 163 | 163 | $this->formId = $_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID]; |
| 164 | 164 | } else { |
| 165 | - $_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID] = (string)microtime(true); |
|
| 165 | + $_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID] = (string) microtime(true); |
|
| 166 | 166 | $_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName]['submitted'] = false; |
| 167 | 167 | $this->formId = $_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID]; |
| 168 | 168 | } |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | $postValues = $request::$post; |
| 191 | 191 | $postValues[self::PARAMETER_DOCUMENT_TYPE] = $this->documentType; |
| 192 | 192 | $postValues[self::GET_PARAMETER_PATH] = $this->responseFolder; |
| 193 | - $postValues['title'] = date('r') . ' - From: ' . $request::$requestUri; |
|
| 193 | + $postValues['title'] = date('r').' - From: '.$request::$requestUri; |
|
| 194 | 194 | |
| 195 | 195 | return $postValues; |
| 196 | 196 | } |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | private function setFormParameter($form) |
| 326 | 326 | { |
| 327 | 327 | if ($this->isFormSubmitted($this->request) || $this->isSubmitAllowed() === false) { |
| 328 | - $this->parameters[$this->formParameterName] = '<a name="' . $this->formId . '"></a>' . $this->thankYouMessage; |
|
| 328 | + $this->parameters[$this->formParameterName] = '<a name="'.$this->formId.'"></a>'.$this->thankYouMessage; |
|
| 329 | 329 | } else { |
| 330 | 330 | $this->parameters[$this->formParameterName] = $form; |
| 331 | 331 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * @param string $imagePath |
| 77 | 77 | * @param bool $getExtension |
| 78 | 78 | * |
| 79 | - * @return bool|int|string |
|
| 79 | + * @return integer |
|
| 80 | 80 | */ |
| 81 | 81 | public function getImageMimeType($imagePath, $getExtension = false) |
| 82 | 82 | { |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** |
| 152 | - * @param $pathToBitmapFile |
|
| 152 | + * @param string $pathToBitmapFile |
|
| 153 | 153 | * |
| 154 | 154 | * @return string |
| 155 | 155 | */ |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
| 168 | - * @param $header |
|
| 168 | + * @param string $header |
|
| 169 | 169 | * |
| 170 | 170 | * @return array |
| 171 | 171 | */ |
@@ -195,14 +195,14 @@ discard block |
||
| 195 | 195 | * Loop through the data in the body of the bitmap |
| 196 | 196 | * file and calculate each individual pixel based on the |
| 197 | 197 | * bytes |
| 198 | - * @param $bodySize |
|
| 199 | - * @param $x |
|
| 198 | + * @param integer $bodySize |
|
| 199 | + * @param integer $x |
|
| 200 | 200 | * @param $width |
| 201 | - * @param $usePadding |
|
| 202 | - * @param $y |
|
| 201 | + * @param boolean $usePadding |
|
| 202 | + * @param integer $y |
|
| 203 | 203 | * @param $height |
| 204 | - * @param $body |
|
| 205 | - * @param $image |
|
| 204 | + * @param string $body |
|
| 205 | + * @param resource $image |
|
| 206 | 206 | */ |
| 207 | 207 | private function loopThroughBodyAndCalculatePixels($bodySize, $x, $width, $usePadding, $y, $height, $body, $image) |
| 208 | 208 | { |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | } elseif (is_string($imageContainer)) { |
| 36 | 36 | $this->_imageResource = imagecreatefromstring($imageContainer); |
| 37 | 37 | } else { |
| 38 | - throw new \Exception('Could not create image resource, accepted inputs are: "resource of type (gd)", path_to_image and "string". <br /><pre>' . var_export($imageContainer, true) . '</pre>'); |
|
| 38 | + throw new \Exception('Could not create image resource, accepted inputs are: "resource of type (gd)", path_to_image and "string". <br /><pre>'.var_export($imageContainer, true).'</pre>'); |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
@@ -179,9 +179,9 @@ discard block |
||
| 179 | 179 | // Cut it in parts of 2 bytes |
| 180 | 180 | $header_parts = str_split($header, 2); |
| 181 | 181 | // Get the width 4 bytes |
| 182 | - $width = hexdec($header_parts[19] . $header_parts[18]); |
|
| 182 | + $width = hexdec($header_parts[19].$header_parts[18]); |
|
| 183 | 183 | // Get the height 4 bytes |
| 184 | - $height = hexdec($header_parts[23] . $header_parts[22]); |
|
| 184 | + $height = hexdec($header_parts[23].$header_parts[22]); |
|
| 185 | 185 | // Unset the header params |
| 186 | 186 | unset($header_parts); |
| 187 | 187 | |
@@ -226,9 +226,9 @@ discard block |
||
| 226 | 226 | } |
| 227 | 227 | // Calculation of the RGB-pixel (defined as BGR in image-data). Define $iPos as absolute position in the body |
| 228 | 228 | $iPos = $i * 2; |
| 229 | - $r = hexdec($body[$iPos + 4] . $body[$iPos + 5]); |
|
| 230 | - $g = hexdec($body[$iPos + 2] . $body[$iPos + 3]); |
|
| 231 | - $b = hexdec($body[$iPos] . $body[$iPos + 1]); |
|
| 229 | + $r = hexdec($body[$iPos + 4].$body[$iPos + 5]); |
|
| 230 | + $g = hexdec($body[$iPos + 2].$body[$iPos + 3]); |
|
| 231 | + $b = hexdec($body[$iPos].$body[$iPos + 1]); |
|
| 232 | 232 | // Calculate and draw the pixel |
| 233 | 233 | $color = imagecolorallocate($image, $r, $g, $b); |
| 234 | 234 | imagesetpixel($image, $x, $height - $y, $color); |
@@ -13,6 +13,10 @@ |
||
| 13 | 13 | { |
| 14 | 14 | protected $imagesDir; |
| 15 | 15 | |
| 16 | + /** |
|
| 17 | + * @param \CloudControl\Cms\storage\Repository $repository |
|
| 18 | + * @param string $imagesDir |
|
| 19 | + */ |
|
| 16 | 20 | public function __construct($repository, $imagesDir) |
| 17 | 21 | { |
| 18 | 22 | parent::__construct($repository); |
@@ -11,124 +11,124 @@ |
||
| 11 | 11 | |
| 12 | 12 | class ImagesStorage extends AbstractStorage |
| 13 | 13 | { |
| 14 | - protected $imagesDir; |
|
| 15 | - |
|
| 16 | - public function __construct($repository, $imagesDir) |
|
| 17 | - { |
|
| 18 | - parent::__construct($repository); |
|
| 19 | - $this->imagesDir = $imagesDir; |
|
| 20 | - } |
|
| 21 | - |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @var ImageSetStorage |
|
| 25 | - */ |
|
| 26 | - protected $imageSet; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Get all images |
|
| 30 | - * |
|
| 31 | - * @return array |
|
| 32 | - */ |
|
| 33 | - public function getImages() |
|
| 34 | - { |
|
| 35 | - return $this->repository->images; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @param $postValues |
|
| 40 | - * |
|
| 41 | - * @throws \Exception |
|
| 42 | - */ |
|
| 43 | - public function addImage($postValues) |
|
| 44 | - { |
|
| 45 | - $destinationPath = $this->getDestinationPath(); |
|
| 46 | - |
|
| 47 | - $filename = $this->validateFilename($postValues['name'], $destinationPath); |
|
| 48 | - $destination = $destinationPath . DIRECTORY_SEPARATOR . $filename; |
|
| 49 | - |
|
| 50 | - if ($postValues['error'] != '0') { |
|
| 51 | - throw new \Exception('Error uploading file. Error code: ' . $postValues['error']); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - if (move_uploaded_file($postValues['tmp_name'], $destination)) { |
|
| 55 | - $imageResizer = new ImageResizer($this->getImageSet()->getImageSet()); |
|
| 56 | - $fileNames = $imageResizer->applyImageSetToImage($destination); |
|
| 57 | - $fileNames['original'] = $filename; |
|
| 58 | - $imageObject = ImageFactory::createImageFromPostValues($postValues, $filename, $fileNames); |
|
| 59 | - |
|
| 60 | - $images = $this->repository->images; |
|
| 61 | - $images[] = $imageObject; |
|
| 62 | - $this->repository->images = $images; |
|
| 63 | - |
|
| 64 | - $this->save(); |
|
| 65 | - } else { |
|
| 66 | - throw new \Exception('Error moving uploaded file'); |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Delete image by name |
|
| 72 | - * @param $filename |
|
| 73 | - */ |
|
| 74 | - public function deleteImageByName($filename) |
|
| 75 | - { |
|
| 76 | - $destinationPath = $this->getDestinationPath(); |
|
| 77 | - |
|
| 78 | - $images = $this->getImages(); |
|
| 79 | - |
|
| 80 | - foreach ($images as $key => $image) { |
|
| 81 | - if ($image->file == $filename) { |
|
| 82 | - foreach ($image->set as $imageSetFilename) { |
|
| 83 | - $destination = $destinationPath . '/' . $imageSetFilename; |
|
| 84 | - if (file_exists($destination)) { |
|
| 85 | - unlink($destination); |
|
| 86 | - } else { |
|
| 87 | - dump($destination); |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - unset($images[$key]); |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - $this->repository->images = $images; |
|
| 95 | - $this->save(); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @param $filename |
|
| 100 | - * |
|
| 101 | - * @return null |
|
| 102 | - */ |
|
| 103 | - public function getImageByName($filename) |
|
| 104 | - { |
|
| 105 | - $images = $this->getImages(); |
|
| 106 | - foreach ($images as $image) { |
|
| 107 | - if ($image->file == $filename) { |
|
| 108 | - return $image; |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - return null; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @return \CloudControl\Cms\storage\storage\ImageSetStorage |
|
| 117 | - */ |
|
| 118 | - private function getImageSet() |
|
| 119 | - { |
|
| 120 | - if (!$this->imageSet instanceof ImageSetStorage) { |
|
| 121 | - $this->imageSet = new ImageSetStorage($this->repository); |
|
| 122 | - } |
|
| 123 | - return $this->imageSet; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @return bool|string |
|
| 128 | - */ |
|
| 129 | - private function getDestinationPath() |
|
| 130 | - { |
|
| 131 | - $destinationPath = realpath($this->imagesDir . DIRECTORY_SEPARATOR); |
|
| 132 | - return $destinationPath; |
|
| 133 | - } |
|
| 14 | + protected $imagesDir; |
|
| 15 | + |
|
| 16 | + public function __construct($repository, $imagesDir) |
|
| 17 | + { |
|
| 18 | + parent::__construct($repository); |
|
| 19 | + $this->imagesDir = $imagesDir; |
|
| 20 | + } |
|
| 21 | + |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @var ImageSetStorage |
|
| 25 | + */ |
|
| 26 | + protected $imageSet; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Get all images |
|
| 30 | + * |
|
| 31 | + * @return array |
|
| 32 | + */ |
|
| 33 | + public function getImages() |
|
| 34 | + { |
|
| 35 | + return $this->repository->images; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @param $postValues |
|
| 40 | + * |
|
| 41 | + * @throws \Exception |
|
| 42 | + */ |
|
| 43 | + public function addImage($postValues) |
|
| 44 | + { |
|
| 45 | + $destinationPath = $this->getDestinationPath(); |
|
| 46 | + |
|
| 47 | + $filename = $this->validateFilename($postValues['name'], $destinationPath); |
|
| 48 | + $destination = $destinationPath . DIRECTORY_SEPARATOR . $filename; |
|
| 49 | + |
|
| 50 | + if ($postValues['error'] != '0') { |
|
| 51 | + throw new \Exception('Error uploading file. Error code: ' . $postValues['error']); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + if (move_uploaded_file($postValues['tmp_name'], $destination)) { |
|
| 55 | + $imageResizer = new ImageResizer($this->getImageSet()->getImageSet()); |
|
| 56 | + $fileNames = $imageResizer->applyImageSetToImage($destination); |
|
| 57 | + $fileNames['original'] = $filename; |
|
| 58 | + $imageObject = ImageFactory::createImageFromPostValues($postValues, $filename, $fileNames); |
|
| 59 | + |
|
| 60 | + $images = $this->repository->images; |
|
| 61 | + $images[] = $imageObject; |
|
| 62 | + $this->repository->images = $images; |
|
| 63 | + |
|
| 64 | + $this->save(); |
|
| 65 | + } else { |
|
| 66 | + throw new \Exception('Error moving uploaded file'); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Delete image by name |
|
| 72 | + * @param $filename |
|
| 73 | + */ |
|
| 74 | + public function deleteImageByName($filename) |
|
| 75 | + { |
|
| 76 | + $destinationPath = $this->getDestinationPath(); |
|
| 77 | + |
|
| 78 | + $images = $this->getImages(); |
|
| 79 | + |
|
| 80 | + foreach ($images as $key => $image) { |
|
| 81 | + if ($image->file == $filename) { |
|
| 82 | + foreach ($image->set as $imageSetFilename) { |
|
| 83 | + $destination = $destinationPath . '/' . $imageSetFilename; |
|
| 84 | + if (file_exists($destination)) { |
|
| 85 | + unlink($destination); |
|
| 86 | + } else { |
|
| 87 | + dump($destination); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + unset($images[$key]); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + $this->repository->images = $images; |
|
| 95 | + $this->save(); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @param $filename |
|
| 100 | + * |
|
| 101 | + * @return null |
|
| 102 | + */ |
|
| 103 | + public function getImageByName($filename) |
|
| 104 | + { |
|
| 105 | + $images = $this->getImages(); |
|
| 106 | + foreach ($images as $image) { |
|
| 107 | + if ($image->file == $filename) { |
|
| 108 | + return $image; |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + return null; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @return \CloudControl\Cms\storage\storage\ImageSetStorage |
|
| 117 | + */ |
|
| 118 | + private function getImageSet() |
|
| 119 | + { |
|
| 120 | + if (!$this->imageSet instanceof ImageSetStorage) { |
|
| 121 | + $this->imageSet = new ImageSetStorage($this->repository); |
|
| 122 | + } |
|
| 123 | + return $this->imageSet; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @return bool|string |
|
| 128 | + */ |
|
| 129 | + private function getDestinationPath() |
|
| 130 | + { |
|
| 131 | + $destinationPath = realpath($this->imagesDir . DIRECTORY_SEPARATOR); |
|
| 132 | + return $destinationPath; |
|
| 133 | + } |
|
| 134 | 134 | } |
| 135 | 135 | \ No newline at end of file |
@@ -45,10 +45,10 @@ discard block |
||
| 45 | 45 | $destinationPath = $this->getDestinationPath(); |
| 46 | 46 | |
| 47 | 47 | $filename = $this->validateFilename($postValues['name'], $destinationPath); |
| 48 | - $destination = $destinationPath . DIRECTORY_SEPARATOR . $filename; |
|
| 48 | + $destination = $destinationPath.DIRECTORY_SEPARATOR.$filename; |
|
| 49 | 49 | |
| 50 | 50 | if ($postValues['error'] != '0') { |
| 51 | - throw new \Exception('Error uploading file. Error code: ' . $postValues['error']); |
|
| 51 | + throw new \Exception('Error uploading file. Error code: '.$postValues['error']); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | if (move_uploaded_file($postValues['tmp_name'], $destination)) { |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | foreach ($images as $key => $image) { |
| 81 | 81 | if ($image->file == $filename) { |
| 82 | 82 | foreach ($image->set as $imageSetFilename) { |
| 83 | - $destination = $destinationPath . '/' . $imageSetFilename; |
|
| 83 | + $destination = $destinationPath.'/'.$imageSetFilename; |
|
| 84 | 84 | if (file_exists($destination)) { |
| 85 | 85 | unlink($destination); |
| 86 | 86 | } else { |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | */ |
| 129 | 129 | private function getDestinationPath() |
| 130 | 130 | { |
| 131 | - $destinationPath = realpath($this->imagesDir . DIRECTORY_SEPARATOR); |
|
| 131 | + $destinationPath = realpath($this->imagesDir.DIRECTORY_SEPARATOR); |
|
| 132 | 132 | return $destinationPath; |
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | \ No newline at end of file |
@@ -25,5 +25,5 @@ |
||
| 25 | 25 | \CloudControl\Cms\CloudControl::run(); |
| 26 | 26 | |
| 27 | 27 | if (php_sapi_name() != "cli") { |
| 28 | - ob_end_flush(); |
|
| 28 | + ob_end_flush(); |
|
| 29 | 29 | } |
| 30 | 30 | \ No newline at end of file |
@@ -12,10 +12,10 @@ |
||
| 12 | 12 | namespace CloudControl\Cms\images\methods |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - use CloudControl\Cms\images\Image; |
|
| 16 | - use CloudControl\Cms\images\IMethod; |
|
| 15 | + use CloudControl\Cms\images\Image; |
|
| 16 | + use CloudControl\Cms\images\IMethod; |
|
| 17 | 17 | |
| 18 | - class Watermark extends IMethod |
|
| 18 | + class Watermark extends IMethod |
|
| 19 | 19 | { |
| 20 | 20 | protected $_x = 0; |
| 21 | 21 | protected $_y = 0; |
@@ -63,7 +63,9 @@ discard block |
||
| 63 | 63 | */ |
| 64 | 64 | protected function calculateX($imageResource) |
| 65 | 65 | { |
| 66 | - if (intval($this->_x) === $this->_x) return $this->_x; |
|
| 66 | + if (intval($this->_x) === $this->_x) { |
|
| 67 | + return $this->_x; |
|
| 68 | + } |
|
| 67 | 69 | |
| 68 | 70 | $x = strtolower($this->_x); |
| 69 | 71 | |
@@ -88,7 +90,9 @@ discard block |
||
| 88 | 90 | */ |
| 89 | 91 | public function calculateY($imageResource) |
| 90 | 92 | { |
| 91 | - if (intval($this->_y) === $this->_y) return $this->_y; |
|
| 93 | + if (intval($this->_y) === $this->_y) { |
|
| 94 | + return $this->_y; |
|
| 95 | + } |
|
| 92 | 96 | |
| 93 | 97 | $y = strtolower($this->_y); |
| 94 | 98 | |
@@ -125,7 +129,9 @@ discard block |
||
| 125 | 129 | */ |
| 126 | 130 | public function GetWatermark() |
| 127 | 131 | { |
| 128 | - if ($this->_watermark == null) throw new \Exception('A watermark is not set. Please supply a \CloudControl\Cms\image\Image using $this->SetWatermark'); |
|
| 132 | + if ($this->_watermark == null) { |
|
| 133 | + throw new \Exception('A watermark is not set. Please supply a \CloudControl\Cms\image\Image using $this->SetWatermark'); |
|
| 134 | + } |
|
| 129 | 135 | return $this->_watermark; |
| 130 | 136 | } |
| 131 | 137 | |
@@ -11,9 +11,9 @@ discard block |
||
| 11 | 11 | namespace CloudControl\Cms\images\methods |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - use CloudControl\Cms\images\IMethod; |
|
| 14 | + use CloudControl\Cms\images\IMethod; |
|
| 15 | 15 | |
| 16 | - class Crop extends IMethod |
|
| 16 | + class Crop extends IMethod |
|
| 17 | 17 | { |
| 18 | 18 | protected $_width; |
| 19 | 19 | protected $_height; |
@@ -116,8 +116,8 @@ discard block |
||
| 116 | 116 | |
| 117 | 117 | // Preserve transparency |
| 118 | 118 | imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127)); |
| 119 | - imagealphablending($new, false); |
|
| 120 | - imagesavealpha($new, true); |
|
| 119 | + imagealphablending($new, false); |
|
| 120 | + imagesavealpha($new, true); |
|
| 121 | 121 | |
| 122 | 122 | imagecopyresampled($new, $imageResource, $this->_destX, $this->_destY, $this->_x, $this->_y, $this->_destWidth, $this->_destHeight, $this->_destWidth, $this->_destHeight); |
| 123 | 123 | |