@@ -20,60 +20,60 @@ discard block |
||
20 | 20 | */ |
21 | 21 | class Document |
22 | 22 | { |
23 | - public $id; |
|
24 | - public $path; |
|
25 | - public $title; |
|
26 | - public $slug; |
|
27 | - public $type; |
|
28 | - public $documentType; |
|
29 | - public $documentTypeSlug; |
|
30 | - public $state; |
|
31 | - public $lastModificationDate; |
|
32 | - public $creationDate; |
|
33 | - public $lastModifiedBy; |
|
34 | - protected $fields; |
|
35 | - protected $bricks; |
|
36 | - protected $dynamicBricks; |
|
37 | - protected $content; |
|
23 | + public $id; |
|
24 | + public $path; |
|
25 | + public $title; |
|
26 | + public $slug; |
|
27 | + public $type; |
|
28 | + public $documentType; |
|
29 | + public $documentTypeSlug; |
|
30 | + public $state; |
|
31 | + public $lastModificationDate; |
|
32 | + public $creationDate; |
|
33 | + public $lastModifiedBy; |
|
34 | + protected $fields; |
|
35 | + protected $bricks; |
|
36 | + protected $dynamicBricks; |
|
37 | + protected $content; |
|
38 | 38 | |
39 | - protected $dbHandle; |
|
39 | + protected $dbHandle; |
|
40 | 40 | |
41 | - protected $jsonEncodedFields = array('fields', 'bricks', 'dynamicBricks'); |
|
42 | - protected $orderableFields = array('title', 'slug', 'type', 'documentType', 'documentTypeSlug', 'state', 'lastModificationDate', 'creationDate', 'lastModifiedBy'); |
|
41 | + protected $jsonEncodedFields = array('fields', 'bricks', 'dynamicBricks'); |
|
42 | + protected $orderableFields = array('title', 'slug', 'type', 'documentType', 'documentTypeSlug', 'state', 'lastModificationDate', 'creationDate', 'lastModifiedBy'); |
|
43 | 43 | |
44 | - public static $DOCUMENT_STATES = array('published', 'unpublished'); |
|
44 | + public static $DOCUMENT_STATES = array('published', 'unpublished'); |
|
45 | 45 | |
46 | - public function __get($name) { |
|
47 | - if (in_array($name, $this->jsonEncodedFields)) { |
|
48 | - if (is_string($this->$name)) { |
|
49 | - return json_decode($this->$name); |
|
50 | - } else { |
|
51 | - return $this->$name; |
|
52 | - } |
|
53 | - } elseif ($name === 'content') { |
|
54 | - if ($this->dbHandle === null) { |
|
55 | - throw new \Exception('Document doesnt have a dbHandle handle. (path: ' . $this->path . ')'); |
|
56 | - } else { |
|
57 | - if ($this->content === null) { |
|
58 | - return $this->getContent(); |
|
59 | - } |
|
60 | - } |
|
61 | - } elseif ($name === 'dbHandle') { |
|
62 | - throw new \Exception('Trying to get protected property repository.'); |
|
63 | - } |
|
64 | - return $this->$name; |
|
65 | - } |
|
46 | + public function __get($name) { |
|
47 | + if (in_array($name, $this->jsonEncodedFields)) { |
|
48 | + if (is_string($this->$name)) { |
|
49 | + return json_decode($this->$name); |
|
50 | + } else { |
|
51 | + return $this->$name; |
|
52 | + } |
|
53 | + } elseif ($name === 'content') { |
|
54 | + if ($this->dbHandle === null) { |
|
55 | + throw new \Exception('Document doesnt have a dbHandle handle. (path: ' . $this->path . ')'); |
|
56 | + } else { |
|
57 | + if ($this->content === null) { |
|
58 | + return $this->getContent(); |
|
59 | + } |
|
60 | + } |
|
61 | + } elseif ($name === 'dbHandle') { |
|
62 | + throw new \Exception('Trying to get protected property repository.'); |
|
63 | + } |
|
64 | + return $this->$name; |
|
65 | + } |
|
66 | 66 | |
67 | - public function __set($name, $value) { |
|
68 | - if (in_array($name, $this->jsonEncodedFields)) { |
|
69 | - $this->$name = json_encode($value); |
|
70 | - } elseif ($name === 'content') { |
|
71 | - // Dont do anything for now.. |
|
72 | - return; |
|
73 | - } |
|
67 | + public function __set($name, $value) { |
|
68 | + if (in_array($name, $this->jsonEncodedFields)) { |
|
69 | + $this->$name = json_encode($value); |
|
70 | + } elseif ($name === 'content') { |
|
71 | + // Dont do anything for now.. |
|
72 | + return; |
|
73 | + } |
|
74 | 74 | |
75 | - $this->$name = $value; |
|
76 | - } |
|
75 | + $this->$name = $value; |
|
76 | + } |
|
77 | 77 | |
78 | 78 | /** |
79 | 79 | * @param string $orderBy |
@@ -82,15 +82,15 @@ discard block |
||
82 | 82 | * @return array |
83 | 83 | * @throws \Exception |
84 | 84 | */ |
85 | - public function getContent($orderBy = 'title', $order = 'ASC') |
|
86 | - { |
|
87 | - if (empty($this->content)) { |
|
88 | - $docs = $this->documentStorage->getDocumentsWithState($this->path); |
|
89 | - $this->content = $docs; |
|
90 | - } |
|
85 | + public function getContent($orderBy = 'title', $order = 'ASC') |
|
86 | + { |
|
87 | + if (empty($this->content)) { |
|
88 | + $docs = $this->documentStorage->getDocumentsWithState($this->path); |
|
89 | + $this->content = $docs; |
|
90 | + } |
|
91 | 91 | |
92 | - return $this->content; |
|
93 | - } |
|
92 | + return $this->content; |
|
93 | + } |
|
94 | 94 | |
95 | 95 | /** |
96 | 96 | * @return string |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | } |
53 | 53 | } elseif ($name === 'content') { |
54 | 54 | if ($this->dbHandle === null) { |
55 | - throw new \Exception('Document doesnt have a dbHandle handle. (path: ' . $this->path . ')'); |
|
55 | + throw new \Exception('Document doesnt have a dbHandle handle. (path: '.$this->path.')'); |
|
56 | 56 | } else { |
57 | 57 | if ($this->content === null) { |
58 | 58 | return $this->getContent(); |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function __toString() |
99 | 99 | { |
100 | - return 'Document:' . $this->title; |
|
100 | + return 'Document:'.$this->title; |
|
101 | 101 | } |
102 | 102 | |
103 | 103 |
@@ -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 |
@@ -12,34 +12,34 @@ |
||
12 | 12 | |
13 | 13 | class ValuelistFactory |
14 | 14 | { |
15 | - /** |
|
16 | - * Create a sitemap item from post values |
|
17 | - * |
|
18 | - * @param $postValues |
|
19 | - * |
|
20 | - * @return \stdClass |
|
21 | - * @throws \Exception |
|
22 | - */ |
|
23 | - public static function createValuelistFromPostValues($postValues) |
|
24 | - { |
|
25 | - if (isset($postValues['title'])) { |
|
26 | - $valuelistObject = new \stdClass(); |
|
27 | - $valuelistObject->title = $postValues['title']; |
|
28 | - $valuelistObject->slug = StringUtil::slugify($postValues['title']); |
|
29 | - $valuelistObject->pairs = new \stdClass(); |
|
30 | - if (isset($postValues['keys'], $postValues['values'])) { |
|
31 | - foreach ($postValues['keys'] as $key => $value) { |
|
32 | - $valuelistObject->pairs->$value = $postValues['values'][$key]; |
|
33 | - } |
|
34 | - } |
|
35 | - $object_vars = get_object_vars($valuelistObject->pairs); |
|
36 | - ksort($object_vars); |
|
37 | - $valuelistObject->pairs = (object) $object_vars; |
|
15 | + /** |
|
16 | + * Create a sitemap item from post values |
|
17 | + * |
|
18 | + * @param $postValues |
|
19 | + * |
|
20 | + * @return \stdClass |
|
21 | + * @throws \Exception |
|
22 | + */ |
|
23 | + public static function createValuelistFromPostValues($postValues) |
|
24 | + { |
|
25 | + if (isset($postValues['title'])) { |
|
26 | + $valuelistObject = new \stdClass(); |
|
27 | + $valuelistObject->title = $postValues['title']; |
|
28 | + $valuelistObject->slug = StringUtil::slugify($postValues['title']); |
|
29 | + $valuelistObject->pairs = new \stdClass(); |
|
30 | + if (isset($postValues['keys'], $postValues['values'])) { |
|
31 | + foreach ($postValues['keys'] as $key => $value) { |
|
32 | + $valuelistObject->pairs->$value = $postValues['values'][$key]; |
|
33 | + } |
|
34 | + } |
|
35 | + $object_vars = get_object_vars($valuelistObject->pairs); |
|
36 | + ksort($object_vars); |
|
37 | + $valuelistObject->pairs = (object) $object_vars; |
|
38 | 38 | |
39 | - return $valuelistObject; |
|
40 | - } else { |
|
41 | - throw new \Exception('Trying to create valuelist with invalid data.'); |
|
42 | - } |
|
43 | - } |
|
39 | + return $valuelistObject; |
|
40 | + } else { |
|
41 | + throw new \Exception('Trying to create valuelist with invalid data.'); |
|
42 | + } |
|
43 | + } |
|
44 | 44 | |
45 | 45 | } |
46 | 46 | \ No newline at end of file |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | public function getDocuments($state = 'published') |
22 | 22 | { |
23 | 23 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
24 | - throw new \Exception('Unsupported document state: ' . $state); |
|
24 | + throw new \Exception('Unsupported document state: '.$state); |
|
25 | 25 | } |
26 | 26 | return $this->repository->getDocuments($state); |
27 | 27 | } |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | public function getDocumentBySlug($slug, $state = 'published') |
51 | 51 | { |
52 | 52 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
53 | - throw new \Exception('Unsupported document state: ' . $state); |
|
53 | + throw new \Exception('Unsupported document state: '.$state); |
|
54 | 54 | } |
55 | - $path = '/' . $slug; |
|
55 | + $path = '/'.$slug; |
|
56 | 56 | |
57 | 57 | return $this->repository->getDocumentByPath($path, $state); |
58 | 58 | } |
@@ -66,16 +66,16 @@ discard block |
||
66 | 66 | public function saveDocument($postValues, $state = 'unpublished') |
67 | 67 | { |
68 | 68 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
69 | - throw new \Exception('Unsupported document state: ' . $state); |
|
69 | + throw new \Exception('Unsupported document state: '.$state); |
|
70 | 70 | } |
71 | - $oldPath = '/' . $postValues['path']; |
|
71 | + $oldPath = '/'.$postValues['path']; |
|
72 | 72 | |
73 | 73 | $container = $this->getDocumentContainerByPath($oldPath); |
74 | 74 | $documentObject = DocumentFactory::createDocumentFromPostValues($postValues, new DocumentTypesStorage($this->repository)); |
75 | 75 | if ($container->path === '/') { |
76 | - $newPath = $container->path . $documentObject->slug; |
|
76 | + $newPath = $container->path.$documentObject->slug; |
|
77 | 77 | } else { |
78 | - $newPath = $container->path . '/' . $documentObject->slug; |
|
78 | + $newPath = $container->path.'/'.$documentObject->slug; |
|
79 | 79 | } |
80 | 80 | $documentObject->path = $newPath; |
81 | 81 | $this->repository->saveDocument($documentObject, $state); |
@@ -89,9 +89,9 @@ discard block |
||
89 | 89 | { |
90 | 90 | $documentObject = DocumentFactory::createDocumentFromPostValues($postValues, new DocumentTypesStorage($this->repository)); |
91 | 91 | if ($postValues['path'] === '/') { |
92 | - $documentObject->path = $postValues['path'] . $documentObject->slug; |
|
92 | + $documentObject->path = $postValues['path'].$documentObject->slug; |
|
93 | 93 | } else { |
94 | - $documentObject->path = $postValues['path'] . '/' . $documentObject->slug; |
|
94 | + $documentObject->path = $postValues['path'].'/'.$documentObject->slug; |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | $this->repository->saveDocument($documentObject, $state); |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | public function deleteDocumentBySlug($slug) |
104 | 104 | { |
105 | - $path = '/' . $slug; |
|
105 | + $path = '/'.$slug; |
|
106 | 106 | $this->repository->deleteDocumentByPath($path); |
107 | 107 | } |
108 | 108 |
@@ -38,19 +38,19 @@ |
||
38 | 38 | array_pop($fileParts); |
39 | 39 | $fileNameWithoutExtension = implode('-', $fileParts); |
40 | 40 | $fileNameWithoutExtension = StringUtil::slugify($fileNameWithoutExtension); |
41 | - $filename = $fileNameWithoutExtension . '.' . $extension; |
|
41 | + $filename = $fileNameWithoutExtension.'.'.$extension; |
|
42 | 42 | } else { |
43 | 43 | $filename = StringUtil::slugify($filename); |
44 | 44 | } |
45 | 45 | |
46 | - if (file_exists($path . '/' . $filename)) { |
|
46 | + if (file_exists($path.'/'.$filename)) { |
|
47 | 47 | $fileParts = explode('.', $filename); |
48 | 48 | if (count($fileParts) > 1) { |
49 | 49 | $extension = end($fileParts); |
50 | 50 | array_pop($fileParts); |
51 | 51 | $fileNameWithoutExtension = implode('-', $fileParts); |
52 | 52 | $fileNameWithoutExtension .= '-copy'; |
53 | - $filename = $fileNameWithoutExtension . '.' . $extension; |
|
53 | + $filename = $fileNameWithoutExtension.'.'.$extension; |
|
54 | 54 | } else { |
55 | 55 | $filename .= '-copy'; |
56 | 56 | } |
@@ -12,83 +12,83 @@ |
||
12 | 12 | |
13 | 13 | class ValuelistsStorage extends AbstractStorage |
14 | 14 | { |
15 | - /** |
|
16 | - * Get all valuelists |
|
17 | - * |
|
18 | - * @return mixed |
|
19 | - */ |
|
20 | - public function getValuelists() |
|
21 | - { |
|
22 | - return $this->repository->valuelists; |
|
23 | - } |
|
15 | + /** |
|
16 | + * Get all valuelists |
|
17 | + * |
|
18 | + * @return mixed |
|
19 | + */ |
|
20 | + public function getValuelists() |
|
21 | + { |
|
22 | + return $this->repository->valuelists; |
|
23 | + } |
|
24 | 24 | |
25 | - public function addValuelist($postValues) |
|
26 | - { |
|
27 | - $valueListObject = ValuelistFactory::createValuelistFromPostValues($postValues); |
|
28 | - $valuelists = $this->repository->valuelists; |
|
29 | - $valuelists[] = $valueListObject; |
|
30 | - $this->repository->valuelists = $valuelists; |
|
31 | - $this->save(); |
|
32 | - } |
|
25 | + public function addValuelist($postValues) |
|
26 | + { |
|
27 | + $valueListObject = ValuelistFactory::createValuelistFromPostValues($postValues); |
|
28 | + $valuelists = $this->repository->valuelists; |
|
29 | + $valuelists[] = $valueListObject; |
|
30 | + $this->repository->valuelists = $valuelists; |
|
31 | + $this->save(); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Save changes to a valuelist |
|
36 | - * |
|
37 | - * @param $slug |
|
38 | - * @param $postValues |
|
39 | - * |
|
40 | - * @throws \Exception |
|
41 | - */ |
|
42 | - public function saveValuelist($slug, $postValues) |
|
43 | - { |
|
44 | - $valuelistObject = ValuelistFactory::createValuelistFromPostValues($postValues); |
|
34 | + /** |
|
35 | + * Save changes to a valuelist |
|
36 | + * |
|
37 | + * @param $slug |
|
38 | + * @param $postValues |
|
39 | + * |
|
40 | + * @throws \Exception |
|
41 | + */ |
|
42 | + public function saveValuelist($slug, $postValues) |
|
43 | + { |
|
44 | + $valuelistObject = ValuelistFactory::createValuelistFromPostValues($postValues); |
|
45 | 45 | |
46 | - $valuelists = $this->repository->valuelists; |
|
47 | - foreach ($valuelists as $key => $valuelist) { |
|
48 | - if ($valuelist->slug == $slug) { |
|
49 | - $valuelists[$key] = $valuelistObject; |
|
50 | - } |
|
51 | - } |
|
52 | - $this->repository->valuelists = $valuelists; |
|
53 | - $this->save(); |
|
54 | - } |
|
46 | + $valuelists = $this->repository->valuelists; |
|
47 | + foreach ($valuelists as $key => $valuelist) { |
|
48 | + if ($valuelist->slug == $slug) { |
|
49 | + $valuelists[$key] = $valuelistObject; |
|
50 | + } |
|
51 | + } |
|
52 | + $this->repository->valuelists = $valuelists; |
|
53 | + $this->save(); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Get a valuelist by its slug |
|
58 | - * |
|
59 | - * @param $slug |
|
60 | - * |
|
61 | - * @return mixed |
|
62 | - */ |
|
63 | - public function getValuelistBySlug($slug) |
|
64 | - { |
|
65 | - $valuelists = $this->repository->valuelists; |
|
66 | - foreach ($valuelists as $valuelist) { |
|
67 | - if ($valuelist->slug == $slug) { |
|
68 | - return $valuelist; |
|
69 | - } |
|
70 | - } |
|
56 | + /** |
|
57 | + * Get a valuelist by its slug |
|
58 | + * |
|
59 | + * @param $slug |
|
60 | + * |
|
61 | + * @return mixed |
|
62 | + */ |
|
63 | + public function getValuelistBySlug($slug) |
|
64 | + { |
|
65 | + $valuelists = $this->repository->valuelists; |
|
66 | + foreach ($valuelists as $valuelist) { |
|
67 | + if ($valuelist->slug == $slug) { |
|
68 | + return $valuelist; |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | - return null; |
|
73 | - } |
|
72 | + return null; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Delete a sitemap item by its slug |
|
77 | - * |
|
78 | - * @param $slug |
|
79 | - * |
|
80 | - * @throws \Exception |
|
81 | - */ |
|
82 | - public function deleteValuelistBySlug($slug) |
|
83 | - { |
|
84 | - $valuelists = $this->repository->valuelists; |
|
85 | - foreach ($valuelists as $key => $valuelist) { |
|
86 | - if ($valuelist->slug == $slug) { |
|
87 | - unset($valuelists[$key]); |
|
88 | - } |
|
89 | - } |
|
90 | - $valuelists = array_values($valuelists); |
|
91 | - $this->repository->valuelists = $valuelists; |
|
92 | - $this->save(); |
|
93 | - } |
|
75 | + /** |
|
76 | + * Delete a sitemap item by its slug |
|
77 | + * |
|
78 | + * @param $slug |
|
79 | + * |
|
80 | + * @throws \Exception |
|
81 | + */ |
|
82 | + public function deleteValuelistBySlug($slug) |
|
83 | + { |
|
84 | + $valuelists = $this->repository->valuelists; |
|
85 | + foreach ($valuelists as $key => $valuelist) { |
|
86 | + if ($valuelist->slug == $slug) { |
|
87 | + unset($valuelists[$key]); |
|
88 | + } |
|
89 | + } |
|
90 | + $valuelists = array_values($valuelists); |
|
91 | + $this->repository->valuelists = $valuelists; |
|
92 | + $this->save(); |
|
93 | + } |
|
94 | 94 | } |
95 | 95 | \ No newline at end of file |
@@ -37,10 +37,10 @@ discard block |
||
37 | 37 | $destinationPath = $this->getDestinationPath(); |
38 | 38 | |
39 | 39 | $filename = $this->validateFilename($postValues['name'], $destinationPath); |
40 | - $destination = $destinationPath . '/' . $filename; |
|
40 | + $destination = $destinationPath.'/'.$filename; |
|
41 | 41 | |
42 | 42 | if ($postValues['error'] != '0') { |
43 | - throw new \Exception('Error uploading file. Error code: ' . $postValues['error']); |
|
43 | + throw new \Exception('Error uploading file. Error code: '.$postValues['error']); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | if (move_uploaded_file($postValues['tmp_name'], $destination)) { |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | public function deleteFileByName($filename) |
84 | 84 | { |
85 | 85 | $destinationPath = $this->getDestinationPath(); |
86 | - $destination = $destinationPath . '/' . $filename; |
|
86 | + $destination = $destinationPath.'/'.$filename; |
|
87 | 87 | |
88 | 88 | if (file_exists($destination)) { |
89 | 89 | $files = $this->getFiles(); |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | |
114 | 114 | protected function getDestinationPath() |
115 | 115 | { |
116 | - $destinationPath = realpath($this->filesDir . DIRECTORY_SEPARATOR); |
|
116 | + $destinationPath = realpath($this->filesDir.DIRECTORY_SEPARATOR); |
|
117 | 117 | return $destinationPath; |
118 | 118 | } |
119 | 119 | } |
120 | 120 | \ No newline at end of file |
@@ -10,6 +10,10 @@ discard block |
||
10 | 10 | { |
11 | 11 | protected $filesDir; |
12 | 12 | |
13 | + /** |
|
14 | + * @param \CloudControl\Cms\storage\Repository $repository |
|
15 | + * @param string $filesDir |
|
16 | + */ |
|
13 | 17 | public function __construct($repository, $filesDir) |
14 | 18 | { |
15 | 19 | parent::__construct($repository); |
@@ -101,7 +105,7 @@ discard block |
||
101 | 105 | } |
102 | 106 | |
103 | 107 | /** |
104 | - * @return mixed |
|
108 | + * @return string |
|
105 | 109 | */ |
106 | 110 | public function getFilesDir() |
107 | 111 | { |
@@ -8,16 +8,16 @@ discard block |
||
8 | 8 | |
9 | 9 | class FilesStorage extends AbstractStorage |
10 | 10 | { |
11 | - protected $filesDir; |
|
11 | + protected $filesDir; |
|
12 | 12 | |
13 | - public function __construct($repository, $filesDir) |
|
14 | - { |
|
15 | - parent::__construct($repository); |
|
16 | - $this->filesDir = $filesDir; |
|
17 | - } |
|
13 | + public function __construct($repository, $filesDir) |
|
14 | + { |
|
15 | + parent::__construct($repository); |
|
16 | + $this->filesDir = $filesDir; |
|
17 | + } |
|
18 | 18 | |
19 | 19 | |
20 | - /** |
|
20 | + /** |
|
21 | 21 | * @return array |
22 | 22 | */ |
23 | 23 | public function getFiles() { |
@@ -100,15 +100,15 @@ discard block |
||
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
103 | - /** |
|
104 | - * @return mixed |
|
105 | - */ |
|
106 | - public function getFilesDir() |
|
107 | - { |
|
108 | - return $this->filesDir; |
|
109 | - } |
|
103 | + /** |
|
104 | + * @return mixed |
|
105 | + */ |
|
106 | + public function getFilesDir() |
|
107 | + { |
|
108 | + return $this->filesDir; |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
111 | + /** |
|
112 | 112 | * @param $a |
113 | 113 | * @param $b |
114 | 114 | * |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | return strcmp($a->file, $b->file); |
120 | 120 | } |
121 | 121 | |
122 | - protected function getDestinationPath() |
|
123 | - { |
|
124 | - $destinationPath = realpath($this->filesDir . DIRECTORY_SEPARATOR); |
|
125 | - return $destinationPath; |
|
126 | - } |
|
122 | + protected function getDestinationPath() |
|
123 | + { |
|
124 | + $destinationPath = realpath($this->filesDir . DIRECTORY_SEPARATOR); |
|
125 | + return $destinationPath; |
|
126 | + } |
|
127 | 127 | } |
128 | 128 | \ No newline at end of file |
@@ -83,6 +83,9 @@ discard block |
||
83 | 83 | $this->storage = new Storage($this->config->rootDir . DIRECTORY_SEPARATOR . $this->config->storageDir, $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) |
@@ -2,277 +2,277 @@ |
||
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->config->rootDir . DIRECTORY_SEPARATOR . $this->config->storageDir, $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 getTemplateDir() |
|
259 | - { |
|
260 | - return $this->config->templateDir; |
|
261 | - } |
|
262 | - |
|
263 | - public function getStorageDir() |
|
264 | - { |
|
265 | - return $this->config->storageDir; |
|
266 | - } |
|
267 | - |
|
268 | - public function getApplicationComponents() |
|
269 | - { |
|
270 | - $this->applicationComponents = $this->storage->getApplicationComponents()->getApplicationComponents(); |
|
271 | - } |
|
272 | - |
|
273 | - public function getRootDir() |
|
274 | - { |
|
275 | - return $this->config->rootDir; |
|
276 | - } |
|
277 | - } |
|
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->config->rootDir . DIRECTORY_SEPARATOR . $this->config->storageDir, $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 getTemplateDir() |
|
259 | + { |
|
260 | + return $this->config->templateDir; |
|
261 | + } |
|
262 | + |
|
263 | + public function getStorageDir() |
|
264 | + { |
|
265 | + return $this->config->storageDir; |
|
266 | + } |
|
267 | + |
|
268 | + public function getApplicationComponents() |
|
269 | + { |
|
270 | + $this->applicationComponents = $this->storage->getApplicationComponents()->getApplicationComponents(); |
|
271 | + } |
|
272 | + |
|
273 | + public function getRootDir() |
|
274 | + { |
|
275 | + return $this->config->rootDir; |
|
276 | + } |
|
277 | + } |
|
278 | 278 | } |
279 | 279 | \ 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); |
@@ -80,13 +80,13 @@ discard block |
||
80 | 80 | */ |
81 | 81 | private function storage() |
82 | 82 | { |
83 | - $this->storage = new Storage($this->config->rootDir . DIRECTORY_SEPARATOR . $this->config->storageDir, $this->config->imagesDir, $this->config->filesDir); |
|
83 | + $this->storage = new Storage($this->config->rootDir.DIRECTORY_SEPARATOR.$this->config->storageDir, $this->config->imagesDir, $this->config->filesDir); |
|
84 | 84 | } |
85 | 85 | |
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 | /** |
@@ -1,18 +1,18 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace CloudControl\Cms\components { |
3 | 3 | |
4 | - use CloudControl\Cms\components\cms\ConfigurationRouting; |
|
5 | - use CloudControl\Cms\components\cms\DocumentRouting; |
|
6 | - use CloudControl\Cms\components\cms\FilesRouting; |
|
7 | - use CloudControl\Cms\components\cms\ImagesRouting; |
|
8 | - use CloudControl\Cms\components\cms\SearchRouting; |
|
9 | - use CloudControl\Cms\components\cms\SitemapRouting; |
|
10 | - use CloudControl\Cms\crypt\Crypt; |
|
11 | - use CloudControl\Cms\storage\Storage; |
|
12 | - |
|
13 | - class CmsComponent extends BaseComponent |
|
4 | + use CloudControl\Cms\components\cms\ConfigurationRouting; |
|
5 | + use CloudControl\Cms\components\cms\DocumentRouting; |
|
6 | + use CloudControl\Cms\components\cms\FilesRouting; |
|
7 | + use CloudControl\Cms\components\cms\ImagesRouting; |
|
8 | + use CloudControl\Cms\components\cms\SearchRouting; |
|
9 | + use CloudControl\Cms\components\cms\SitemapRouting; |
|
10 | + use CloudControl\Cms\crypt\Crypt; |
|
11 | + use CloudControl\Cms\storage\Storage; |
|
12 | + |
|
13 | + class CmsComponent extends BaseComponent |
|
14 | 14 | { |
15 | - /** |
|
15 | + /** |
|
16 | 16 | * @var \CloudControl\Cms\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'; |
@@ -369,9 +369,9 @@ discard block |
||
369 | 369 | } |
370 | 370 | } |
371 | 371 | |
372 | - protected function getTemplateDir($template, $application = null) |
|
373 | - { |
|
374 | - return __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $template . '.php'; |
|
375 | - } |
|
376 | - } |
|
372 | + protected function getTemplateDir($template, $application = null) |
|
373 | + { |
|
374 | + return __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $template . '.php'; |
|
375 | + } |
|
376 | + } |
|
377 | 377 | } |
378 | 378 | \ No newline at end of file |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | $whitelistIps = explode(',', $this->parameters[self::PARAMETER_WHITELIST_IPS]); |
171 | 171 | $whitelistIps = array_map("trim", $whitelistIps); |
172 | 172 | if (!in_array($remoteAddress, $whitelistIps)) { |
173 | - throw new \Exception('Ip address ' . $remoteAddress . ' is not on whitelist'); |
|
173 | + throw new \Exception('Ip address '.$remoteAddress.' is not on whitelist'); |
|
174 | 174 | } |
175 | 175 | } |
176 | 176 | } |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | $blacklistIps = explode(',', $this->parameters[self::PARAMETER_BLACKLIST_IPS]); |
187 | 187 | $blacklistIps = array_map("trim", $blacklistIps); |
188 | 188 | if (in_array($remoteAddress, $blacklistIps)) { |
189 | - throw new \Exception('Ip address ' . $remoteAddress . ' is on blacklist'); |
|
189 | + throw new \Exception('Ip address '.$remoteAddress.' is on blacklist'); |
|
190 | 190 | } |
191 | 191 | } |
192 | 192 | } |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | if ($relativeCmsUri == '/log-off') { |
231 | 231 | $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = null; |
232 | 232 | unset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]); |
233 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX]); |
|
233 | + header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX]); |
|
234 | 234 | exit; |
235 | 235 | } |
236 | 236 | } |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | |
372 | 372 | protected function getTemplateDir($template, $application = null) |
373 | 373 | { |
374 | - return __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $template . '.php'; |
|
374 | + return __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR.$template.'.php'; |
|
375 | 375 | } |
376 | 376 | } |
377 | 377 | } |
378 | 378 | \ No newline at end of file |