@@ -12,33 +12,33 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | class DocumentRouting implements CmsRouting |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * DocumentRouting constructor. |
|
| 17 | - * @param $request |
|
| 18 | - * @param $relativeCmsUri |
|
| 19 | - * @param CmsComponent $cmsComponent |
|
| 20 | - */ |
|
| 21 | - public function __construct($request, $relativeCmsUri, $cmsComponent) |
|
| 22 | - { |
|
| 23 | - if ($relativeCmsUri == '/documents') { |
|
| 24 | - $cmsComponent->subTemplate = 'cms/documents'; |
|
| 25 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENTS, $cmsComponent->storage->getDocuments()->getDocumentsWithState()); |
|
| 26 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_DOCUMENTS); |
|
| 27 | - } |
|
| 28 | - $this->documentRouting($request, $relativeCmsUri, $cmsComponent); |
|
| 29 | - $this->folderRouting($request, $relativeCmsUri, $cmsComponent); |
|
| 15 | + /** |
|
| 16 | + * DocumentRouting constructor. |
|
| 17 | + * @param $request |
|
| 18 | + * @param $relativeCmsUri |
|
| 19 | + * @param CmsComponent $cmsComponent |
|
| 20 | + */ |
|
| 21 | + public function __construct($request, $relativeCmsUri, $cmsComponent) |
|
| 22 | + { |
|
| 23 | + if ($relativeCmsUri == '/documents') { |
|
| 24 | + $cmsComponent->subTemplate = 'cms/documents'; |
|
| 25 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENTS, $cmsComponent->storage->getDocuments()->getDocumentsWithState()); |
|
| 26 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_DOCUMENTS); |
|
| 27 | + } |
|
| 28 | + $this->documentRouting($request, $relativeCmsUri, $cmsComponent); |
|
| 29 | + $this->folderRouting($request, $relativeCmsUri, $cmsComponent); |
|
| 30 | 30 | $this->valuelistsRouting($request, $relativeCmsUri, $cmsComponent); |
| 31 | - } |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @param $request |
|
| 36 | - * @param $relativeCmsUri |
|
| 37 | - * @param CmsComponent $cmsComponent |
|
| 38 | - * @throws \Exception |
|
| 39 | - */ |
|
| 40 | - private function documentRouting($request, $relativeCmsUri, $cmsComponent) |
|
| 41 | - { |
|
| 34 | + /** |
|
| 35 | + * @param $request |
|
| 36 | + * @param $relativeCmsUri |
|
| 37 | + * @param CmsComponent $cmsComponent |
|
| 38 | + * @throws \Exception |
|
| 39 | + */ |
|
| 40 | + private function documentRouting($request, $relativeCmsUri, $cmsComponent) |
|
| 41 | + { |
|
| 42 | 42 | if ($relativeCmsUri == '/documents/new-document' && isset($request::$get[CmsComponent::GET_PARAMETER_PATH])) { |
| 43 | 43 | $this->documentNewRoute($request, $cmsComponent); |
| 44 | 44 | } elseif (isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])){ |
@@ -50,23 +50,23 @@ discard block |
||
| 50 | 50 | case '/documents/unpublish-document': $this->unpublishDocumentRoute($request, $cmsComponent); break; |
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | - } |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @param $request |
|
| 57 | - * @param $relativeCmsUri |
|
| 58 | - * @param CmsComponent $cmsComponent |
|
| 59 | - */ |
|
| 60 | - private function folderRouting($request, $relativeCmsUri, $cmsComponent) |
|
| 61 | - { |
|
| 62 | - if ($relativeCmsUri == '/documents/new-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_PATH])) { |
|
| 55 | + /** |
|
| 56 | + * @param $request |
|
| 57 | + * @param $relativeCmsUri |
|
| 58 | + * @param CmsComponent $cmsComponent |
|
| 59 | + */ |
|
| 60 | + private function folderRouting($request, $relativeCmsUri, $cmsComponent) |
|
| 61 | + { |
|
| 62 | + if ($relativeCmsUri == '/documents/new-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_PATH])) { |
|
| 63 | 63 | $this->newFolderRoute($request, $cmsComponent); |
| 64 | - } else if ($relativeCmsUri == '/documents/edit-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
| 64 | + } else if ($relativeCmsUri == '/documents/edit-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
| 65 | 65 | $this->editFolderRoute($request, $cmsComponent); |
| 66 | - } else if ($relativeCmsUri == '/documents/delete-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
| 66 | + } else if ($relativeCmsUri == '/documents/delete-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
| 67 | 67 | $this->deleteFolderRoute($request, $cmsComponent); |
| 68 | - } |
|
| 69 | - } |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | 71 | private function valuelistsRouting($request, $relativeCmsUri, $cmsComponent) |
| 72 | 72 | { |
@@ -12,10 +12,10 @@ |
||
| 12 | 12 | |
| 13 | 13 | class NotFoundComponent extends BaseComponent |
| 14 | 14 | { |
| 15 | - public function run(Storage $storage) |
|
| 16 | - { |
|
| 17 | - parent::run($storage); |
|
| 18 | - header("HTTP/1.0 404 Not Found"); |
|
| 19 | - } |
|
| 15 | + public function run(Storage $storage) |
|
| 16 | + { |
|
| 17 | + parent::run($storage); |
|
| 18 | + header("HTTP/1.0 404 Not Found"); |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | 21 | } |
| 22 | 22 | \ No newline at end of file |
@@ -10,91 +10,91 @@ |
||
| 10 | 10 | |
| 11 | 11 | class RedirectsStorage extends AbstractStorage |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * Get all redirects |
|
| 15 | - * |
|
| 16 | - * @return mixed |
|
| 17 | - */ |
|
| 18 | - public function getRedirects() |
|
| 19 | - { |
|
| 20 | - $redirects = $this->repository->redirects; |
|
| 21 | - usort($redirects, array($this, 'cmp')); |
|
| 22 | - return $redirects; |
|
| 23 | - } |
|
| 13 | + /** |
|
| 14 | + * Get all redirects |
|
| 15 | + * |
|
| 16 | + * @return mixed |
|
| 17 | + */ |
|
| 18 | + public function getRedirects() |
|
| 19 | + { |
|
| 20 | + $redirects = $this->repository->redirects; |
|
| 21 | + usort($redirects, array($this, 'cmp')); |
|
| 22 | + return $redirects; |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Add a new redirect |
|
| 27 | - * @param $postValues |
|
| 28 | - */ |
|
| 29 | - public function addRedirect($postValues) { |
|
| 30 | - $redirectObject = RedirectsFactory::createRedirectFromPostValues($postValues); |
|
| 31 | - $redirects = $this->repository->redirects; |
|
| 32 | - $redirects[] = $redirectObject; |
|
| 33 | - $this->repository->redirects = $redirects; |
|
| 34 | - $this->save(); |
|
| 35 | - } |
|
| 25 | + /** |
|
| 26 | + * Add a new redirect |
|
| 27 | + * @param $postValues |
|
| 28 | + */ |
|
| 29 | + public function addRedirect($postValues) { |
|
| 30 | + $redirectObject = RedirectsFactory::createRedirectFromPostValues($postValues); |
|
| 31 | + $redirects = $this->repository->redirects; |
|
| 32 | + $redirects[] = $redirectObject; |
|
| 33 | + $this->repository->redirects = $redirects; |
|
| 34 | + $this->save(); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Get a redirect by it's slug |
|
| 39 | - * |
|
| 40 | - * @param $slug |
|
| 41 | - * @return \stdClass|null |
|
| 42 | - */ |
|
| 43 | - public function getRedirectBySlug($slug) |
|
| 44 | - { |
|
| 45 | - $redirects = $this->repository->redirects; |
|
| 46 | - foreach ($redirects as $redirect) { |
|
| 47 | - if ($redirect->slug == $slug) { |
|
| 48 | - return $redirect; |
|
| 49 | - } |
|
| 50 | - } |
|
| 37 | + /** |
|
| 38 | + * Get a redirect by it's slug |
|
| 39 | + * |
|
| 40 | + * @param $slug |
|
| 41 | + * @return \stdClass|null |
|
| 42 | + */ |
|
| 43 | + public function getRedirectBySlug($slug) |
|
| 44 | + { |
|
| 45 | + $redirects = $this->repository->redirects; |
|
| 46 | + foreach ($redirects as $redirect) { |
|
| 47 | + if ($redirect->slug == $slug) { |
|
| 48 | + return $redirect; |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - return null; |
|
| 53 | - } |
|
| 52 | + return null; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Save a redirect by it's slug |
|
| 57 | - * @param $slug |
|
| 58 | - * @param $postValues |
|
| 59 | - */ |
|
| 60 | - public function saveRedirect($slug, $postValues) |
|
| 61 | - { |
|
| 62 | - $redirectObject = RedirectsFactory::createRedirectFromPostValues($postValues); |
|
| 55 | + /** |
|
| 56 | + * Save a redirect by it's slug |
|
| 57 | + * @param $slug |
|
| 58 | + * @param $postValues |
|
| 59 | + */ |
|
| 60 | + public function saveRedirect($slug, $postValues) |
|
| 61 | + { |
|
| 62 | + $redirectObject = RedirectsFactory::createRedirectFromPostValues($postValues); |
|
| 63 | 63 | |
| 64 | - $redirects = $this->repository->redirects; |
|
| 65 | - foreach ($redirects as $key => $redirect) { |
|
| 66 | - if ($redirect->slug == $slug) { |
|
| 67 | - $redirects[$key] = $redirectObject; |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - $this->repository->redirects = $redirects; |
|
| 71 | - $this->save(); |
|
| 72 | - } |
|
| 64 | + $redirects = $this->repository->redirects; |
|
| 65 | + foreach ($redirects as $key => $redirect) { |
|
| 66 | + if ($redirect->slug == $slug) { |
|
| 67 | + $redirects[$key] = $redirectObject; |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + $this->repository->redirects = $redirects; |
|
| 71 | + $this->save(); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Delete a redirect by it's slug |
|
| 76 | - * @param $slug |
|
| 77 | - */ |
|
| 78 | - public function deleteRedirectBySlug($slug) |
|
| 79 | - { |
|
| 80 | - $redirects = $this->repository->redirects; |
|
| 81 | - foreach ($redirects as $key => $redirect) { |
|
| 82 | - if ($redirect->slug == $slug) { |
|
| 83 | - unset($redirects[$key]); |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - $redirects = array_values($redirects); |
|
| 87 | - $this->repository->redirects = $redirects; |
|
| 88 | - $this->save(); |
|
| 89 | - } |
|
| 74 | + /** |
|
| 75 | + * Delete a redirect by it's slug |
|
| 76 | + * @param $slug |
|
| 77 | + */ |
|
| 78 | + public function deleteRedirectBySlug($slug) |
|
| 79 | + { |
|
| 80 | + $redirects = $this->repository->redirects; |
|
| 81 | + foreach ($redirects as $key => $redirect) { |
|
| 82 | + if ($redirect->slug == $slug) { |
|
| 83 | + unset($redirects[$key]); |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + $redirects = array_values($redirects); |
|
| 87 | + $this->repository->redirects = $redirects; |
|
| 88 | + $this->save(); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Compare a redirect by it's title |
|
| 93 | - * @param $a |
|
| 94 | - * @param $b |
|
| 95 | - * @return int |
|
| 96 | - */ |
|
| 97 | - public static function cmp($a, $b) { |
|
| 98 | - return strcmp($a->title, $b->title); |
|
| 99 | - } |
|
| 91 | + /** |
|
| 92 | + * Compare a redirect by it's title |
|
| 93 | + * @param $a |
|
| 94 | + * @param $b |
|
| 95 | + * @return int |
|
| 96 | + */ |
|
| 97 | + public static function cmp($a, $b) { |
|
| 98 | + return strcmp($a->title, $b->title); |
|
| 99 | + } |
|
| 100 | 100 | } |
| 101 | 101 | \ No newline at end of file |
@@ -10,26 +10,26 @@ |
||
| 10 | 10 | |
| 11 | 11 | class RedirectsFactory |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * Create a new redirect object from postvalues |
|
| 15 | - * |
|
| 16 | - * @param $postValues |
|
| 17 | - * @return \stdClass |
|
| 18 | - * @throws \Exception |
|
| 19 | - */ |
|
| 20 | - public static function createRedirectFromPostValues($postValues) |
|
| 21 | - { |
|
| 22 | - if (isset($postValues['title'], $postValues['fromUrl'], $postValues['toUrl'])) { |
|
| 23 | - $redirectObject = new \stdClass(); |
|
| 24 | - $redirectObject->title = $postValues['title']; |
|
| 25 | - $redirectObject->slug = StringUtil::slugify($postValues['title']); |
|
| 26 | - $redirectObject->fromUrl = $postValues['fromUrl']; |
|
| 27 | - $redirectObject->toUrl = $postValues['toUrl']; |
|
| 28 | - $redirectObject->type = $postValues['type']; |
|
| 13 | + /** |
|
| 14 | + * Create a new redirect object from postvalues |
|
| 15 | + * |
|
| 16 | + * @param $postValues |
|
| 17 | + * @return \stdClass |
|
| 18 | + * @throws \Exception |
|
| 19 | + */ |
|
| 20 | + public static function createRedirectFromPostValues($postValues) |
|
| 21 | + { |
|
| 22 | + if (isset($postValues['title'], $postValues['fromUrl'], $postValues['toUrl'])) { |
|
| 23 | + $redirectObject = new \stdClass(); |
|
| 24 | + $redirectObject->title = $postValues['title']; |
|
| 25 | + $redirectObject->slug = StringUtil::slugify($postValues['title']); |
|
| 26 | + $redirectObject->fromUrl = $postValues['fromUrl']; |
|
| 27 | + $redirectObject->toUrl = $postValues['toUrl']; |
|
| 28 | + $redirectObject->type = $postValues['type']; |
|
| 29 | 29 | |
| 30 | - return $redirectObject; |
|
| 31 | - } else { |
|
| 32 | - throw new \Exception('Trying to create valuelist with invalid data.'); |
|
| 33 | - } |
|
| 34 | - } |
|
| 30 | + return $redirectObject; |
|
| 31 | + } else { |
|
| 32 | + throw new \Exception('Trying to create valuelist with invalid data.'); |
|
| 33 | + } |
|
| 34 | + } |
|
| 35 | 35 | } |
| 36 | 36 | \ No newline at end of file |
@@ -1,22 +1,22 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace library\storage { |
| 3 | 3 | |
| 4 | - use library\storage\factories\DocumentFolderFactory; |
|
| 5 | - use library\storage\storage\ApplicationComponentsStorage; |
|
| 6 | - use library\storage\storage\BricksStorage; |
|
| 7 | - use library\storage\storage\DocumentStorage; |
|
| 8 | - use library\storage\storage\DocumentTypesStorage; |
|
| 9 | - use library\storage\storage\FilesStorage; |
|
| 10 | - use library\storage\storage\ImageSetStorage; |
|
| 11 | - use library\storage\storage\ImagesStorage; |
|
| 12 | - use library\storage\storage\RedirectsStorage; |
|
| 13 | - use library\storage\storage\SitemapStorage; |
|
| 14 | - use library\storage\storage\UsersStorage; |
|
| 15 | - use library\storage\storage\ValuelistsStorage; |
|
| 4 | + use library\storage\factories\DocumentFolderFactory; |
|
| 5 | + use library\storage\storage\ApplicationComponentsStorage; |
|
| 6 | + use library\storage\storage\BricksStorage; |
|
| 7 | + use library\storage\storage\DocumentStorage; |
|
| 8 | + use library\storage\storage\DocumentTypesStorage; |
|
| 9 | + use library\storage\storage\FilesStorage; |
|
| 10 | + use library\storage\storage\ImageSetStorage; |
|
| 11 | + use library\storage\storage\ImagesStorage; |
|
| 12 | + use library\storage\storage\RedirectsStorage; |
|
| 13 | + use library\storage\storage\SitemapStorage; |
|
| 14 | + use library\storage\storage\UsersStorage; |
|
| 15 | + use library\storage\storage\ValuelistsStorage; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 17 | + /** |
|
| 18 | 18 | * Class JsonStorage |
| 19 | - * @package library\storage |
|
| 19 | + * @package library\storage |
|
| 20 | 20 | */ |
| 21 | 21 | class Storage |
| 22 | 22 | { |
@@ -61,10 +61,10 @@ discard block |
||
| 61 | 61 | * @var DocumentStorage |
| 62 | 62 | */ |
| 63 | 63 | protected $documents; |
| 64 | - /** |
|
| 65 | - * @var RedirectsStorage |
|
| 66 | - */ |
|
| 67 | - protected $redirects; |
|
| 64 | + /** |
|
| 65 | + * @var RedirectsStorage |
|
| 66 | + */ |
|
| 67 | + protected $redirects; |
|
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * @var String |
@@ -325,16 +325,16 @@ discard block |
||
| 325 | 325 | return $this->valuelists; |
| 326 | 326 | } |
| 327 | 327 | |
| 328 | - /** |
|
| 329 | - * @return RedirectsStorage |
|
| 330 | - */ |
|
| 331 | - public function getRedirects() |
|
| 332 | - { |
|
| 333 | - if (!$this->redirects instanceof RedirectsStorage) { |
|
| 334 | - $this->redirects = new RedirectsStorage($this->repository); |
|
| 335 | - } |
|
| 336 | - return $this->redirects; |
|
| 337 | - } |
|
| 328 | + /** |
|
| 329 | + * @return RedirectsStorage |
|
| 330 | + */ |
|
| 331 | + public function getRedirects() |
|
| 332 | + { |
|
| 333 | + if (!$this->redirects instanceof RedirectsStorage) { |
|
| 334 | + $this->redirects = new RedirectsStorage($this->repository); |
|
| 335 | + } |
|
| 336 | + return $this->redirects; |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | 339 | } |
| 340 | 340 | } |
| 341 | 341 | \ No newline at end of file |
@@ -14,26 +14,26 @@ discard block |
||
| 14 | 14 | class SitemapRouting implements CmsRouting |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * SitemapRouting constructor. |
|
| 19 | - * @param \library\cc\Request $request |
|
| 20 | - * @param mixed|string $relativeCmsUri |
|
| 21 | - * @param CmsComponent $cmsComponent |
|
| 22 | - */ |
|
| 23 | - public function __construct($request, $relativeCmsUri, $cmsComponent) |
|
| 24 | - { |
|
| 25 | - if ($relativeCmsUri == '/sitemap') { |
|
| 17 | + /** |
|
| 18 | + * SitemapRouting constructor. |
|
| 19 | + * @param \library\cc\Request $request |
|
| 20 | + * @param mixed|string $relativeCmsUri |
|
| 21 | + * @param CmsComponent $cmsComponent |
|
| 22 | + */ |
|
| 23 | + public function __construct($request, $relativeCmsUri, $cmsComponent) |
|
| 24 | + { |
|
| 25 | + if ($relativeCmsUri == '/sitemap') { |
|
| 26 | 26 | $this->overviewRoute($request, $cmsComponent); |
| 27 | - } elseif ($relativeCmsUri == '/sitemap/new') { |
|
| 27 | + } elseif ($relativeCmsUri == '/sitemap/new') { |
|
| 28 | 28 | $this->newRoute($request, $cmsComponent); |
| 29 | - } elseif ($relativeCmsUri == '/sitemap/edit' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
| 29 | + } elseif ($relativeCmsUri == '/sitemap/edit' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
| 30 | 30 | $this->editRoute($request, $cmsComponent); |
| 31 | - } elseif ($relativeCmsUri == '/sitemap/delete' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
| 31 | + } elseif ($relativeCmsUri == '/sitemap/delete' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
| 32 | 32 | $this->deleteRoute($request, $cmsComponent); |
| 33 | - } else { |
|
| 34 | - $this->redirectRoutes($relativeCmsUri, $request, $cmsComponent); |
|
| 35 | - } |
|
| 36 | - } |
|
| 33 | + } else { |
|
| 34 | + $this->redirectRoutes($relativeCmsUri, $request, $cmsComponent); |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * @param $request |
@@ -92,54 +92,54 @@ discard block |
||
| 92 | 92 | exit; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - private function redirectRoutes($relativeCmsUri, $request, $cmsComponent) |
|
| 96 | - { |
|
| 97 | - if ($relativeCmsUri == '/sitemap/redirects') { |
|
| 98 | - $this->redirectsOverviewRoute($cmsComponent); |
|
| 99 | - } elseif ($relativeCmsUri == '/sitemap/redirects/new') { |
|
| 100 | - $this->redirectsNewRoute($request, $cmsComponent); |
|
| 101 | - } elseif ($relativeCmsUri == '/sitemap/redirects/edit' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
| 102 | - $this->redirectEditRoute($request, $cmsComponent); |
|
| 103 | - } elseif ($relativeCmsUri == '/sitemap/redirects/delete' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
| 104 | - $this->redirectDeleteRoute($request, $cmsComponent); |
|
| 105 | - } |
|
| 106 | - } |
|
| 95 | + private function redirectRoutes($relativeCmsUri, $request, $cmsComponent) |
|
| 96 | + { |
|
| 97 | + if ($relativeCmsUri == '/sitemap/redirects') { |
|
| 98 | + $this->redirectsOverviewRoute($cmsComponent); |
|
| 99 | + } elseif ($relativeCmsUri == '/sitemap/redirects/new') { |
|
| 100 | + $this->redirectsNewRoute($request, $cmsComponent); |
|
| 101 | + } elseif ($relativeCmsUri == '/sitemap/redirects/edit' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
| 102 | + $this->redirectEditRoute($request, $cmsComponent); |
|
| 103 | + } elseif ($relativeCmsUri == '/sitemap/redirects/delete' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
| 104 | + $this->redirectDeleteRoute($request, $cmsComponent); |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - private function redirectsOverviewRoute($cmsComponent) |
|
| 109 | - { |
|
| 110 | - $cmsComponent->subTemplate = 'cms/sitemap/redirects'; |
|
| 111 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_SITEMAP); |
|
| 112 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_REDIRECTS, $cmsComponent->storage->getRedirects()->getRedirects()); |
|
| 113 | - } |
|
| 108 | + private function redirectsOverviewRoute($cmsComponent) |
|
| 109 | + { |
|
| 110 | + $cmsComponent->subTemplate = 'cms/sitemap/redirects'; |
|
| 111 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_SITEMAP); |
|
| 112 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_REDIRECTS, $cmsComponent->storage->getRedirects()->getRedirects()); |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - private function redirectsNewRoute($request, $cmsComponent) |
|
| 116 | - { |
|
| 117 | - $cmsComponent->subTemplate = 'cms/sitemap/redirects-form'; |
|
| 118 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_SITEMAP); |
|
| 119 | - if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE], $request::$post[CmsComponent::POST_PARAMETER_FROM_URL], $request::$post[CmsComponent::POST_PARAMETER_TO_URL])) { |
|
| 120 | - $cmsComponent->storage->getRedirects()->addRedirect($request::$post); |
|
| 121 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/sitemap/redirects'); |
|
| 122 | - exit; |
|
| 123 | - } |
|
| 124 | - } |
|
| 115 | + private function redirectsNewRoute($request, $cmsComponent) |
|
| 116 | + { |
|
| 117 | + $cmsComponent->subTemplate = 'cms/sitemap/redirects-form'; |
|
| 118 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_SITEMAP); |
|
| 119 | + if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE], $request::$post[CmsComponent::POST_PARAMETER_FROM_URL], $request::$post[CmsComponent::POST_PARAMETER_TO_URL])) { |
|
| 120 | + $cmsComponent->storage->getRedirects()->addRedirect($request::$post); |
|
| 121 | + header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/sitemap/redirects'); |
|
| 122 | + exit; |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - private function redirectEditRoute($request, $cmsComponent) |
|
| 127 | - { |
|
| 128 | - $cmsComponent->subTemplate = 'cms/sitemap/redirects-form'; |
|
| 129 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_SITEMAP); |
|
| 130 | - $redirect = $cmsComponent->storage->getRedirects()->getRedirectBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
|
| 131 | - if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE], $request::$post[CmsComponent::POST_PARAMETER_FROM_URL], $request::$post[CmsComponent::POST_PARAMETER_TO_URL])) { |
|
| 132 | - $cmsComponent->storage->getRedirects()->saveRedirect($request::$get[CmsComponent::GET_PARAMETER_SLUG], $request::$post); |
|
| 133 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/sitemap/redirects'); |
|
| 134 | - exit; |
|
| 135 | - } |
|
| 136 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_REDIRECT, $redirect); |
|
| 137 | - } |
|
| 126 | + private function redirectEditRoute($request, $cmsComponent) |
|
| 127 | + { |
|
| 128 | + $cmsComponent->subTemplate = 'cms/sitemap/redirects-form'; |
|
| 129 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_SITEMAP); |
|
| 130 | + $redirect = $cmsComponent->storage->getRedirects()->getRedirectBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
|
| 131 | + if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE], $request::$post[CmsComponent::POST_PARAMETER_FROM_URL], $request::$post[CmsComponent::POST_PARAMETER_TO_URL])) { |
|
| 132 | + $cmsComponent->storage->getRedirects()->saveRedirect($request::$get[CmsComponent::GET_PARAMETER_SLUG], $request::$post); |
|
| 133 | + header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/sitemap/redirects'); |
|
| 134 | + exit; |
|
| 135 | + } |
|
| 136 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_REDIRECT, $redirect); |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - private function redirectDeleteRoute($request, $cmsComponent) |
|
| 140 | - { |
|
| 141 | - $cmsComponent->storage->getRedirects()->deleteRedirectBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
|
| 142 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/sitemap/redirects'); |
|
| 143 | - exit; |
|
| 144 | - } |
|
| 139 | + private function redirectDeleteRoute($request, $cmsComponent) |
|
| 140 | + { |
|
| 141 | + $cmsComponent->storage->getRedirects()->deleteRedirectBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
|
| 142 | + header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/sitemap/redirects'); |
|
| 143 | + exit; |
|
| 144 | + } |
|
| 145 | 145 | } |
| 146 | 146 | \ No newline at end of file |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | class CmsComponent extends BaseComponent |
| 14 | 14 | { |
| 15 | - /** |
|
| 15 | + /** |
|
| 16 | 16 | * @var \library\storage\Storage |
| 17 | 17 | */ |
| 18 | 18 | public $storage; |
@@ -41,8 +41,8 @@ discard block |
||
| 41 | 41 | const PARAMETER_IMAGE_SET = 'imageSet'; |
| 42 | 42 | const PARAMETER_MAIN_NAV_CLASS = 'mainNavClass'; |
| 43 | 43 | const PARAMETER_MY_BRICK_SLUG = 'myBrickSlug'; |
| 44 | - const PARAMETER_REDIRECT = 'redirect'; |
|
| 45 | - const PARAMETER_REDIRECTS = 'redirects'; |
|
| 44 | + const PARAMETER_REDIRECT = 'redirect'; |
|
| 45 | + const PARAMETER_REDIRECTS = 'redirects'; |
|
| 46 | 46 | const PARAMETER_SEARCH = 'search'; |
| 47 | 47 | const PARAMETER_SEARCH_LOG = "searchLog"; |
| 48 | 48 | const PARAMETER_SEARCH_NEEDS_UPDATE = "searchNeedsUpdate"; |
@@ -57,14 +57,14 @@ discard block |
||
| 57 | 57 | const PARAMETER_VALUELISTS = "valuelists"; |
| 58 | 58 | const PARAMETER_WHITELIST_IPS = 'whitelistIps'; |
| 59 | 59 | |
| 60 | - const POST_PARAMETER_COMPONENT = 'component'; |
|
| 61 | - const POST_PARAMETER_FROM_URL = "fromUrl"; |
|
| 62 | - const POST_PARAMETER_PASSWORD = 'password'; |
|
| 63 | - const POST_PARAMETER_SAVE = 'save'; |
|
| 64 | - const POST_PARAMETER_TEMPLATE = 'template'; |
|
| 65 | - const POST_PARAMETER_TITLE = 'title'; |
|
| 66 | - const POST_PARAMETER_TO_URL = "toUrl"; |
|
| 67 | - const POST_PARAMETER_USERNAME = 'username'; |
|
| 60 | + const POST_PARAMETER_COMPONENT = 'component'; |
|
| 61 | + const POST_PARAMETER_FROM_URL = "fromUrl"; |
|
| 62 | + const POST_PARAMETER_PASSWORD = 'password'; |
|
| 63 | + const POST_PARAMETER_SAVE = 'save'; |
|
| 64 | + const POST_PARAMETER_TEMPLATE = 'template'; |
|
| 65 | + const POST_PARAMETER_TITLE = 'title'; |
|
| 66 | + const POST_PARAMETER_TO_URL = "toUrl"; |
|
| 67 | + const POST_PARAMETER_USERNAME = 'username'; |
|
| 68 | 68 | |
| 69 | 69 | const GET_PARAMETER_PATH = 'path'; |
| 70 | 70 | const GET_PARAMETER_SLUG = 'slug'; |
@@ -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 |
@@ -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 |