@@ -49,7 +49,7 @@ |
||
49 | 49 | $output = ''; |
50 | 50 | for ($i = 0; $i < $count; $i += 16) { |
51 | 51 | $random_state = |
52 | - md5(microtime() . $random_state); |
|
52 | + md5(microtime().$random_state); |
|
53 | 53 | $output .= |
54 | 54 | pack('H*', md5($random_state)); |
55 | 55 | } |
@@ -1,129 +1,129 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace CloudControl\Cms\crypt |
3 | 3 | { |
4 | - /** |
|
5 | - * Class Crypt |
|
6 | - * @package CloudControl\Cms\crypt |
|
7 | - */ |
|
8 | - class Crypt |
|
9 | - { |
|
10 | - /** |
|
11 | - * @var string |
|
12 | - */ |
|
13 | - private $lastSalt; |
|
4 | + /** |
|
5 | + * Class Crypt |
|
6 | + * @package CloudControl\Cms\crypt |
|
7 | + */ |
|
8 | + class Crypt |
|
9 | + { |
|
10 | + /** |
|
11 | + * @var string |
|
12 | + */ |
|
13 | + private $lastSalt; |
|
14 | 14 | |
15 | - /** |
|
16 | - * Encrypts the given value using the blowfish algorithm |
|
17 | - * |
|
18 | - * @param string $value The sting to be encrypted |
|
19 | - * @param int $encryptionIterations The amount of iterations used for encryption, 13 by default, resulting in aprox. 0.5 seconds of encrypting. Each raise, will result in about double the time |
|
20 | - * @return string The hash |
|
21 | - */ |
|
22 | - public function encrypt($value, $encryptionIterations = 13) |
|
23 | - { |
|
24 | - $random = $this->getRandomBytes(16); |
|
25 | - $this->lastSalt = $this->getSalt($random, $encryptionIterations); |
|
26 | - $hash = crypt($value, $this->lastSalt); |
|
27 | - return $hash; |
|
28 | - } |
|
15 | + /** |
|
16 | + * Encrypts the given value using the blowfish algorithm |
|
17 | + * |
|
18 | + * @param string $value The sting to be encrypted |
|
19 | + * @param int $encryptionIterations The amount of iterations used for encryption, 13 by default, resulting in aprox. 0.5 seconds of encrypting. Each raise, will result in about double the time |
|
20 | + * @return string The hash |
|
21 | + */ |
|
22 | + public function encrypt($value, $encryptionIterations = 13) |
|
23 | + { |
|
24 | + $random = $this->getRandomBytes(16); |
|
25 | + $this->lastSalt = $this->getSalt($random, $encryptionIterations); |
|
26 | + $hash = crypt($value, $this->lastSalt); |
|
27 | + return $hash; |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * If on Linux, tries to use built in random byte feed |
|
32 | - * else generates its own feed |
|
33 | - * |
|
34 | - * @param int $count The amount of bytes to generates |
|
35 | - * @return string The bytes |
|
36 | - */ |
|
37 | - private function getRandomBytes($count) |
|
38 | - { |
|
39 | - $output = ''; |
|
40 | - $random_state = microtime(); |
|
30 | + /** |
|
31 | + * If on Linux, tries to use built in random byte feed |
|
32 | + * else generates its own feed |
|
33 | + * |
|
34 | + * @param int $count The amount of bytes to generates |
|
35 | + * @return string The bytes |
|
36 | + */ |
|
37 | + private function getRandomBytes($count) |
|
38 | + { |
|
39 | + $output = ''; |
|
40 | + $random_state = microtime(); |
|
41 | 41 | |
42 | - $openBasedir = ini_get('open_basedir'); |
|
43 | - if (empty($openBasedir) && |
|
44 | - is_readable('/dev/urandom') && |
|
45 | - ($fh = @fopen('/dev/urandom', 'rb'))) { |
|
46 | - $output = fread($fh, $count); |
|
47 | - fclose($fh); |
|
48 | - } |
|
42 | + $openBasedir = ini_get('open_basedir'); |
|
43 | + if (empty($openBasedir) && |
|
44 | + is_readable('/dev/urandom') && |
|
45 | + ($fh = @fopen('/dev/urandom', 'rb'))) { |
|
46 | + $output = fread($fh, $count); |
|
47 | + fclose($fh); |
|
48 | + } |
|
49 | 49 | |
50 | - if (strlen($output) < $count) { |
|
51 | - $output = ''; |
|
52 | - for ($i = 0; $i < $count; $i += 16) { |
|
53 | - $random_state = |
|
54 | - md5(microtime() . $random_state); |
|
55 | - $output .= |
|
56 | - pack('H*', md5($random_state)); |
|
57 | - } |
|
58 | - $output = substr($output, 0, $count); |
|
59 | - } |
|
50 | + if (strlen($output) < $count) { |
|
51 | + $output = ''; |
|
52 | + for ($i = 0; $i < $count; $i += 16) { |
|
53 | + $random_state = |
|
54 | + md5(microtime() . $random_state); |
|
55 | + $output .= |
|
56 | + pack('H*', md5($random_state)); |
|
57 | + } |
|
58 | + $output = substr($output, 0, $count); |
|
59 | + } |
|
60 | 60 | |
61 | - return $output; |
|
62 | - } |
|
61 | + return $output; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Generates the salt used for encryption |
|
66 | - * |
|
67 | - * @param string $input Feed for iteration |
|
68 | - * @param int $iterations Amount of iterations |
|
69 | - * |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - private function getSalt($input, $iterations) |
|
73 | - { |
|
74 | - $itoa64 = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
|
64 | + /** |
|
65 | + * Generates the salt used for encryption |
|
66 | + * |
|
67 | + * @param string $input Feed for iteration |
|
68 | + * @param int $iterations Amount of iterations |
|
69 | + * |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + private function getSalt($input, $iterations) |
|
73 | + { |
|
74 | + $itoa64 = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
|
75 | 75 | |
76 | - $output = '$2a$'; |
|
77 | - $output .= chr(ord('0') + $iterations / 10); |
|
78 | - $output .= chr(ord('0') + $iterations % 10); |
|
79 | - $output .= '$'; |
|
76 | + $output = '$2a$'; |
|
77 | + $output .= chr(ord('0') + $iterations / 10); |
|
78 | + $output .= chr(ord('0') + $iterations % 10); |
|
79 | + $output .= '$'; |
|
80 | 80 | |
81 | - $i = 0; |
|
82 | - do { |
|
83 | - $c1 = ord($input[$i++]); |
|
84 | - $output .= $itoa64[$c1 >> 2]; |
|
85 | - $c1 = ($c1 & 0x03) << 4; |
|
86 | - if ($i >= 16) { |
|
87 | - $output .= $itoa64[$c1]; |
|
88 | - break; |
|
89 | - } |
|
81 | + $i = 0; |
|
82 | + do { |
|
83 | + $c1 = ord($input[$i++]); |
|
84 | + $output .= $itoa64[$c1 >> 2]; |
|
85 | + $c1 = ($c1 & 0x03) << 4; |
|
86 | + if ($i >= 16) { |
|
87 | + $output .= $itoa64[$c1]; |
|
88 | + break; |
|
89 | + } |
|
90 | 90 | |
91 | - $c2 = ord($input[$i++]); |
|
92 | - $c1 |= $c2 >> 4; |
|
93 | - $output .= $itoa64[$c1]; |
|
94 | - $c1 = ($c2 & 0x0f) << 2; |
|
91 | + $c2 = ord($input[$i++]); |
|
92 | + $c1 |= $c2 >> 4; |
|
93 | + $output .= $itoa64[$c1]; |
|
94 | + $c1 = ($c2 & 0x0f) << 2; |
|
95 | 95 | |
96 | - $c2 = ord($input[$i++]); |
|
97 | - $c1 |= $c2 >> 6; |
|
98 | - $output .= $itoa64[$c1]; |
|
99 | - $output .= $itoa64[$c2 & 0x3f]; |
|
100 | - } while (1); |
|
96 | + $c2 = ord($input[$i++]); |
|
97 | + $c1 |= $c2 >> 6; |
|
98 | + $output .= $itoa64[$c1]; |
|
99 | + $output .= $itoa64[$c2 & 0x3f]; |
|
100 | + } while (1); |
|
101 | 101 | |
102 | - return $output; |
|
103 | - } |
|
102 | + return $output; |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Returns the last used salt for encryption |
|
107 | - * |
|
108 | - * @return string | NULL |
|
109 | - */ |
|
110 | - public function getLastSalt() |
|
111 | - { |
|
112 | - return $this->lastSalt; |
|
113 | - } |
|
105 | + /** |
|
106 | + * Returns the last used salt for encryption |
|
107 | + * |
|
108 | + * @return string | NULL |
|
109 | + */ |
|
110 | + public function getLastSalt() |
|
111 | + { |
|
112 | + return $this->lastSalt; |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * Compare the input with a known hash and salt |
|
117 | - * |
|
118 | - * @param $input |
|
119 | - * @param $hash |
|
120 | - * @param $salt |
|
121 | - * @return bool |
|
122 | - */ |
|
123 | - public function compare($input, $hash, $salt) |
|
124 | - { |
|
125 | - $newHash = crypt($input, $salt); |
|
126 | - return $newHash == $hash; |
|
127 | - } |
|
128 | - } |
|
115 | + /** |
|
116 | + * Compare the input with a known hash and salt |
|
117 | + * |
|
118 | + * @param $input |
|
119 | + * @param $hash |
|
120 | + * @param $salt |
|
121 | + * @return bool |
|
122 | + */ |
|
123 | + public function compare($input, $hash, $salt) |
|
124 | + { |
|
125 | + $newHash = crypt($input, $salt); |
|
126 | + return $newHash == $hash; |
|
127 | + } |
|
128 | + } |
|
129 | 129 | } |
130 | 130 | \ No newline at end of file |
@@ -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 |
@@ -75,13 +75,13 @@ discard block |
||
75 | 75 | $this->$name = $value; |
76 | 76 | } |
77 | 77 | |
78 | - /** |
|
79 | - * @param string $orderBy |
|
80 | - * @param string $order |
|
81 | - * |
|
82 | - * @return array |
|
83 | - * @throws \Exception |
|
84 | - */ |
|
78 | + /** |
|
79 | + * @param string $orderBy |
|
80 | + * @param string $order |
|
81 | + * |
|
82 | + * @return array |
|
83 | + * @throws \Exception |
|
84 | + */ |
|
85 | 85 | public function getContent($orderBy = 'title', $order = 'ASC') |
86 | 86 | { |
87 | 87 | if (empty($this->content)) { |
@@ -89,16 +89,16 @@ discard block |
||
89 | 89 | $this->content = $docs; |
90 | 90 | } |
91 | 91 | |
92 | - return $this->content; |
|
92 | + return $this->content; |
|
93 | 93 | } |
94 | 94 | |
95 | - /** |
|
96 | - * @return string |
|
97 | - */ |
|
98 | - public function __toString() |
|
99 | - { |
|
100 | - return 'Document:' . $this->title; |
|
101 | - } |
|
95 | + /** |
|
96 | + * @return string |
|
97 | + */ |
|
98 | + public function __toString() |
|
99 | + { |
|
100 | + return 'Document:' . $this->title; |
|
101 | + } |
|
102 | 102 | |
103 | 103 | |
104 | 104 | } |
105 | 105 | \ 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 |
@@ -10,123 +10,123 @@ |
||
10 | 10 | |
11 | 11 | class DocumentStorage extends AbstractStorage |
12 | 12 | { |
13 | - /** |
|
14 | - * Get documents |
|
15 | - * |
|
16 | - * @param string $state |
|
17 | - * |
|
18 | - * @return array |
|
19 | - * @throws \Exception |
|
20 | - */ |
|
21 | - public function getDocuments($state = 'published') |
|
22 | - { |
|
23 | - if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
24 | - throw new \Exception('Unsupported document state: ' . $state); |
|
25 | - } |
|
26 | - return $this->repository->getDocuments($state); |
|
27 | - } |
|
28 | - |
|
29 | - public function getDocumentsWithState($folderPath = '/') |
|
30 | - { |
|
31 | - return $this->repository->getDocumentsWithState($folderPath); |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * @return int |
|
36 | - */ |
|
37 | - public function getTotalDocumentCount() |
|
38 | - { |
|
39 | - return $this->repository->getTotalDocumentCount(); |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * @param string $slug |
|
44 | - * |
|
45 | - * @param string $state |
|
46 | - * |
|
47 | - * @return mixed |
|
48 | - * @throws \Exception |
|
49 | - */ |
|
50 | - public function getDocumentBySlug($slug, $state = 'published') |
|
51 | - { |
|
52 | - if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
53 | - throw new \Exception('Unsupported document state: ' . $state); |
|
54 | - } |
|
55 | - $path = '/' . $slug; |
|
56 | - |
|
57 | - return $this->repository->getDocumentByPath($path, $state); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * @param $postValues |
|
62 | - * @param $state |
|
63 | - * |
|
64 | - * @throws \Exception |
|
65 | - */ |
|
66 | - public function saveDocument($postValues, $state = 'unpublished') |
|
67 | - { |
|
68 | - if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
69 | - throw new \Exception('Unsupported document state: ' . $state); |
|
70 | - } |
|
71 | - $oldPath = '/' . $postValues['path']; |
|
72 | - |
|
73 | - $container = $this->getDocumentContainerByPath($oldPath); |
|
74 | - $documentObject = DocumentFactory::createDocumentFromPostValues($postValues, new DocumentTypesStorage($this->repository)); |
|
75 | - if ($container->path === '/') { |
|
76 | - $newPath = $container->path . $documentObject->slug; |
|
77 | - } else { |
|
78 | - $newPath = $container->path . '/' . $documentObject->slug; |
|
79 | - } |
|
80 | - $documentObject->path = $newPath; |
|
81 | - $this->repository->saveDocument($documentObject, $state); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * @param $postValues |
|
86 | - * @param string $state |
|
87 | - */ |
|
88 | - public function addDocument($postValues, $state = 'unpublished') |
|
89 | - { |
|
90 | - $documentObject = DocumentFactory::createDocumentFromPostValues($postValues, new DocumentTypesStorage($this->repository)); |
|
91 | - if ($postValues['path'] === '/') { |
|
92 | - $documentObject->path = $postValues['path'] . $documentObject->slug; |
|
93 | - } else { |
|
94 | - $documentObject->path = $postValues['path'] . '/' . $documentObject->slug; |
|
95 | - } |
|
96 | - |
|
97 | - $this->repository->saveDocument($documentObject, $state); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * @param $slug |
|
102 | - */ |
|
103 | - public function deleteDocumentBySlug($slug) |
|
104 | - { |
|
105 | - $path = '/' . $slug; |
|
106 | - $this->repository->deleteDocumentByPath($path); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Returns the folder containing the document |
|
111 | - * |
|
112 | - * @param $path |
|
113 | - * |
|
114 | - * @return bool|\CloudControl\Cms\storage\Document |
|
115 | - * @throws \Exception |
|
116 | - */ |
|
117 | - private function getDocumentContainerByPath($path) |
|
118 | - { |
|
119 | - return $this->repository->getDocumentContainerByPath($path); |
|
120 | - } |
|
121 | - |
|
122 | - public function getPublishedDocumentsNoFolders() |
|
123 | - { |
|
124 | - return $this->repository->getPublishedDocumentsNoFolders(); |
|
125 | - } |
|
126 | - |
|
127 | - public function cleanPublishedDeletedDocuments() |
|
128 | - { |
|
129 | - $this->repository->cleanPublishedDeletedDocuments(); |
|
130 | - } |
|
13 | + /** |
|
14 | + * Get documents |
|
15 | + * |
|
16 | + * @param string $state |
|
17 | + * |
|
18 | + * @return array |
|
19 | + * @throws \Exception |
|
20 | + */ |
|
21 | + public function getDocuments($state = 'published') |
|
22 | + { |
|
23 | + if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
24 | + throw new \Exception('Unsupported document state: ' . $state); |
|
25 | + } |
|
26 | + return $this->repository->getDocuments($state); |
|
27 | + } |
|
28 | + |
|
29 | + public function getDocumentsWithState($folderPath = '/') |
|
30 | + { |
|
31 | + return $this->repository->getDocumentsWithState($folderPath); |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * @return int |
|
36 | + */ |
|
37 | + public function getTotalDocumentCount() |
|
38 | + { |
|
39 | + return $this->repository->getTotalDocumentCount(); |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * @param string $slug |
|
44 | + * |
|
45 | + * @param string $state |
|
46 | + * |
|
47 | + * @return mixed |
|
48 | + * @throws \Exception |
|
49 | + */ |
|
50 | + public function getDocumentBySlug($slug, $state = 'published') |
|
51 | + { |
|
52 | + if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
53 | + throw new \Exception('Unsupported document state: ' . $state); |
|
54 | + } |
|
55 | + $path = '/' . $slug; |
|
56 | + |
|
57 | + return $this->repository->getDocumentByPath($path, $state); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * @param $postValues |
|
62 | + * @param $state |
|
63 | + * |
|
64 | + * @throws \Exception |
|
65 | + */ |
|
66 | + public function saveDocument($postValues, $state = 'unpublished') |
|
67 | + { |
|
68 | + if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
69 | + throw new \Exception('Unsupported document state: ' . $state); |
|
70 | + } |
|
71 | + $oldPath = '/' . $postValues['path']; |
|
72 | + |
|
73 | + $container = $this->getDocumentContainerByPath($oldPath); |
|
74 | + $documentObject = DocumentFactory::createDocumentFromPostValues($postValues, new DocumentTypesStorage($this->repository)); |
|
75 | + if ($container->path === '/') { |
|
76 | + $newPath = $container->path . $documentObject->slug; |
|
77 | + } else { |
|
78 | + $newPath = $container->path . '/' . $documentObject->slug; |
|
79 | + } |
|
80 | + $documentObject->path = $newPath; |
|
81 | + $this->repository->saveDocument($documentObject, $state); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * @param $postValues |
|
86 | + * @param string $state |
|
87 | + */ |
|
88 | + public function addDocument($postValues, $state = 'unpublished') |
|
89 | + { |
|
90 | + $documentObject = DocumentFactory::createDocumentFromPostValues($postValues, new DocumentTypesStorage($this->repository)); |
|
91 | + if ($postValues['path'] === '/') { |
|
92 | + $documentObject->path = $postValues['path'] . $documentObject->slug; |
|
93 | + } else { |
|
94 | + $documentObject->path = $postValues['path'] . '/' . $documentObject->slug; |
|
95 | + } |
|
96 | + |
|
97 | + $this->repository->saveDocument($documentObject, $state); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * @param $slug |
|
102 | + */ |
|
103 | + public function deleteDocumentBySlug($slug) |
|
104 | + { |
|
105 | + $path = '/' . $slug; |
|
106 | + $this->repository->deleteDocumentByPath($path); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Returns the folder containing the document |
|
111 | + * |
|
112 | + * @param $path |
|
113 | + * |
|
114 | + * @return bool|\CloudControl\Cms\storage\Document |
|
115 | + * @throws \Exception |
|
116 | + */ |
|
117 | + private function getDocumentContainerByPath($path) |
|
118 | + { |
|
119 | + return $this->repository->getDocumentContainerByPath($path); |
|
120 | + } |
|
121 | + |
|
122 | + public function getPublishedDocumentsNoFolders() |
|
123 | + { |
|
124 | + return $this->repository->getPublishedDocumentsNoFolders(); |
|
125 | + } |
|
126 | + |
|
127 | + public function cleanPublishedDeletedDocuments() |
|
128 | + { |
|
129 | + $this->repository->cleanPublishedDeletedDocuments(); |
|
130 | + } |
|
131 | 131 | |
132 | 132 | } |
133 | 133 | \ No newline at end of file |
@@ -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 | } |
@@ -11,63 +11,63 @@ |
||
11 | 11 | |
12 | 12 | abstract class AbstractStorage |
13 | 13 | { |
14 | - /** |
|
15 | - * @var Repository |
|
16 | - */ |
|
17 | - protected $repository; |
|
14 | + /** |
|
15 | + * @var Repository |
|
16 | + */ |
|
17 | + protected $repository; |
|
18 | 18 | |
19 | - public function __construct($repository) |
|
20 | - { |
|
21 | - $this->repository = $repository; |
|
22 | - } |
|
19 | + public function __construct($repository) |
|
20 | + { |
|
21 | + $this->repository = $repository; |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * Converts filename to lowercase, remove non-ascii chars |
|
26 | - * And adds "-copy" if the file already exists |
|
27 | - * |
|
28 | - * @param $filename |
|
29 | - * @param $path |
|
30 | - * |
|
31 | - * @return string |
|
32 | - */ |
|
33 | - protected function validateFilename($filename, $path) |
|
34 | - { |
|
35 | - $fileParts = explode('.', $filename); |
|
36 | - if (count($fileParts) > 1) { |
|
37 | - $extension = end($fileParts); |
|
38 | - array_pop($fileParts); |
|
39 | - $fileNameWithoutExtension = implode('-', $fileParts); |
|
40 | - $fileNameWithoutExtension = StringUtil::slugify($fileNameWithoutExtension); |
|
41 | - $filename = $fileNameWithoutExtension . '.' . $extension; |
|
42 | - } else { |
|
43 | - $filename = StringUtil::slugify($filename); |
|
44 | - } |
|
24 | + /** |
|
25 | + * Converts filename to lowercase, remove non-ascii chars |
|
26 | + * And adds "-copy" if the file already exists |
|
27 | + * |
|
28 | + * @param $filename |
|
29 | + * @param $path |
|
30 | + * |
|
31 | + * @return string |
|
32 | + */ |
|
33 | + protected function validateFilename($filename, $path) |
|
34 | + { |
|
35 | + $fileParts = explode('.', $filename); |
|
36 | + if (count($fileParts) > 1) { |
|
37 | + $extension = end($fileParts); |
|
38 | + array_pop($fileParts); |
|
39 | + $fileNameWithoutExtension = implode('-', $fileParts); |
|
40 | + $fileNameWithoutExtension = StringUtil::slugify($fileNameWithoutExtension); |
|
41 | + $filename = $fileNameWithoutExtension . '.' . $extension; |
|
42 | + } else { |
|
43 | + $filename = StringUtil::slugify($filename); |
|
44 | + } |
|
45 | 45 | |
46 | - if (file_exists($path . '/' . $filename)) { |
|
47 | - $fileParts = explode('.', $filename); |
|
48 | - if (count($fileParts) > 1) { |
|
49 | - $extension = end($fileParts); |
|
50 | - array_pop($fileParts); |
|
51 | - $fileNameWithoutExtension = implode('-', $fileParts); |
|
52 | - $fileNameWithoutExtension .= '-copy'; |
|
53 | - $filename = $fileNameWithoutExtension . '.' . $extension; |
|
54 | - } else { |
|
55 | - $filename .= '-copy'; |
|
56 | - } |
|
46 | + if (file_exists($path . '/' . $filename)) { |
|
47 | + $fileParts = explode('.', $filename); |
|
48 | + if (count($fileParts) > 1) { |
|
49 | + $extension = end($fileParts); |
|
50 | + array_pop($fileParts); |
|
51 | + $fileNameWithoutExtension = implode('-', $fileParts); |
|
52 | + $fileNameWithoutExtension .= '-copy'; |
|
53 | + $filename = $fileNameWithoutExtension . '.' . $extension; |
|
54 | + } else { |
|
55 | + $filename .= '-copy'; |
|
56 | + } |
|
57 | 57 | |
58 | - return $this->validateFilename($filename, $path); |
|
59 | - } |
|
58 | + return $this->validateFilename($filename, $path); |
|
59 | + } |
|
60 | 60 | |
61 | - return $filename; |
|
62 | - } |
|
61 | + return $filename; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Save changes made to the repository |
|
66 | - * |
|
67 | - * @throws \Exception |
|
68 | - */ |
|
69 | - protected function save() |
|
70 | - { |
|
71 | - $this->repository->save(); |
|
72 | - } |
|
64 | + /** |
|
65 | + * Save changes made to the repository |
|
66 | + * |
|
67 | + * @throws \Exception |
|
68 | + */ |
|
69 | + protected function save() |
|
70 | + { |
|
71 | + $this->repository->save(); |
|
72 | + } |
|
73 | 73 | } |
74 | 74 | \ 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 | { |
@@ -18,87 +18,87 @@ discard block |
||
18 | 18 | |
19 | 19 | |
20 | 20 | /** |
21 | - * @return array |
|
22 | - */ |
|
23 | - public function getFiles() { |
|
24 | - $files = $this->repository->files; |
|
25 | - usort($files, array($this, 'compareFiles')); |
|
26 | - |
|
27 | - return $files; |
|
28 | - } |
|
29 | - |
|
30 | - /** |
|
31 | - * @param $postValues |
|
32 | - * |
|
33 | - * @throws \Exception |
|
34 | - */ |
|
35 | - public function addFile($postValues) |
|
36 | - { |
|
37 | - $destinationPath = $this->getDestinationPath(); |
|
38 | - |
|
39 | - $filename = $this->validateFilename($postValues['name'], $destinationPath); |
|
40 | - $destination = $destinationPath . '/' . $filename; |
|
41 | - |
|
42 | - if ($postValues['error'] != '0') { |
|
43 | - throw new \Exception('Error uploading file. Error code: ' . $postValues['error']); |
|
44 | - } |
|
45 | - |
|
46 | - if (move_uploaded_file($postValues['tmp_name'], $destination)) { |
|
47 | - $file = new \stdClass(); |
|
48 | - $file->file = $filename; |
|
49 | - $file->type = $postValues['type']; |
|
50 | - $file->size = $postValues['size']; |
|
51 | - |
|
52 | - $files = $this->repository->files; |
|
53 | - $files[] = $file; |
|
54 | - $this->repository->files = $files; |
|
55 | - $this->save(); |
|
56 | - } else { |
|
57 | - throw new \Exception('Error moving uploaded file'); |
|
58 | - } |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * @param $filename |
|
63 | - * |
|
64 | - * @return null |
|
65 | - */ |
|
66 | - public function getFileByName($filename) |
|
67 | - { |
|
68 | - $files = $this->getFiles(); |
|
69 | - foreach ($files as $file) { |
|
70 | - if ($filename == $file->file) { |
|
71 | - return $file; |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - return null; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * @param $filename |
|
80 | - * |
|
81 | - * @throws \Exception |
|
82 | - */ |
|
83 | - public function deleteFileByName($filename) |
|
84 | - { |
|
85 | - $destinationPath = $this->getDestinationPath(); |
|
86 | - $destination = $destinationPath . '/' . $filename; |
|
87 | - |
|
88 | - if (file_exists($destination)) { |
|
89 | - $files = $this->getFiles(); |
|
90 | - foreach ($files as $key => $file) { |
|
91 | - if ($file->file == $filename) { |
|
92 | - unlink($destination); |
|
93 | - unset($files[$key]); |
|
94 | - } |
|
95 | - } |
|
96 | - |
|
97 | - $files = array_values($files); |
|
98 | - $this->repository->files = $files; |
|
99 | - $this->save(); |
|
100 | - } |
|
101 | - } |
|
21 | + * @return array |
|
22 | + */ |
|
23 | + public function getFiles() { |
|
24 | + $files = $this->repository->files; |
|
25 | + usort($files, array($this, 'compareFiles')); |
|
26 | + |
|
27 | + return $files; |
|
28 | + } |
|
29 | + |
|
30 | + /** |
|
31 | + * @param $postValues |
|
32 | + * |
|
33 | + * @throws \Exception |
|
34 | + */ |
|
35 | + public function addFile($postValues) |
|
36 | + { |
|
37 | + $destinationPath = $this->getDestinationPath(); |
|
38 | + |
|
39 | + $filename = $this->validateFilename($postValues['name'], $destinationPath); |
|
40 | + $destination = $destinationPath . '/' . $filename; |
|
41 | + |
|
42 | + if ($postValues['error'] != '0') { |
|
43 | + throw new \Exception('Error uploading file. Error code: ' . $postValues['error']); |
|
44 | + } |
|
45 | + |
|
46 | + if (move_uploaded_file($postValues['tmp_name'], $destination)) { |
|
47 | + $file = new \stdClass(); |
|
48 | + $file->file = $filename; |
|
49 | + $file->type = $postValues['type']; |
|
50 | + $file->size = $postValues['size']; |
|
51 | + |
|
52 | + $files = $this->repository->files; |
|
53 | + $files[] = $file; |
|
54 | + $this->repository->files = $files; |
|
55 | + $this->save(); |
|
56 | + } else { |
|
57 | + throw new \Exception('Error moving uploaded file'); |
|
58 | + } |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * @param $filename |
|
63 | + * |
|
64 | + * @return null |
|
65 | + */ |
|
66 | + public function getFileByName($filename) |
|
67 | + { |
|
68 | + $files = $this->getFiles(); |
|
69 | + foreach ($files as $file) { |
|
70 | + if ($filename == $file->file) { |
|
71 | + return $file; |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + return null; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * @param $filename |
|
80 | + * |
|
81 | + * @throws \Exception |
|
82 | + */ |
|
83 | + public function deleteFileByName($filename) |
|
84 | + { |
|
85 | + $destinationPath = $this->getDestinationPath(); |
|
86 | + $destination = $destinationPath . '/' . $filename; |
|
87 | + |
|
88 | + if (file_exists($destination)) { |
|
89 | + $files = $this->getFiles(); |
|
90 | + foreach ($files as $key => $file) { |
|
91 | + if ($file->file == $filename) { |
|
92 | + unlink($destination); |
|
93 | + unset($files[$key]); |
|
94 | + } |
|
95 | + } |
|
96 | + |
|
97 | + $files = array_values($files); |
|
98 | + $this->repository->files = $files; |
|
99 | + $this->save(); |
|
100 | + } |
|
101 | + } |
|
102 | 102 | |
103 | 103 | /** |
104 | 104 | * @return mixed |
@@ -109,15 +109,15 @@ discard block |
||
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
112 | - * @param $a |
|
113 | - * @param $b |
|
114 | - * |
|
115 | - * @return int |
|
116 | - */ |
|
117 | - private function compareFiles($a, $b) |
|
118 | - { |
|
119 | - return strcmp($a->file, $b->file); |
|
120 | - } |
|
112 | + * @param $a |
|
113 | + * @param $b |
|
114 | + * |
|
115 | + * @return int |
|
116 | + */ |
|
117 | + private function compareFiles($a, $b) |
|
118 | + { |
|
119 | + return strcmp($a->file, $b->file); |
|
120 | + } |
|
121 | 121 | |
122 | 122 | protected function getDestinationPath() |
123 | 123 | { |
@@ -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) |
@@ -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 | /** |
@@ -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 |
@@ -11,51 +11,51 @@ discard block |
||
11 | 11 | use CloudControl\Cms\storage\Storage; |
12 | 12 | |
13 | 13 | class CmsComponent extends BaseComponent |
14 | - { |
|
14 | + { |
|
15 | 15 | /** |
16 | - * @var \CloudControl\Cms\storage\Storage |
|
17 | - */ |
|
18 | - public $storage; |
|
19 | - |
|
20 | - const INVALID_CREDENTIALS_MESSAGE = 'Invalid username / password combination'; |
|
21 | - |
|
22 | - const MAIN_NAV_CLASS = 'default'; |
|
23 | - |
|
24 | - const PARAMETER_APPLICATION_COMPONENT = 'applicationComponent'; |
|
25 | - const PARAMETER_APPLICATION_COMPONENTS = 'applicationComponents'; |
|
26 | - const PARAMETER_BLACKLIST_IPS = 'blacklistIps'; |
|
27 | - const PARAMETER_BODY = 'body'; |
|
28 | - const PARAMETER_BRICK = 'brick'; |
|
29 | - const PARAMETER_BRICKS = 'bricks'; |
|
30 | - const PARAMETER_CMS_PREFIX = 'cmsPrefix'; |
|
31 | - const PARAMETER_CONFIGURATION = 'configuration'; |
|
32 | - const PARAMETER_DOCUMENT = 'document'; |
|
33 | - const PARAMETER_DOCUMENTS = 'documents'; |
|
34 | - const PARAMETER_DOCUMENT_TYPE = 'documentType'; |
|
35 | - const PARAMETER_DOCUMENT_TYPES = 'documentTypes'; |
|
36 | - const PARAMETER_ERROR_MESSAGE = 'errorMsg'; |
|
37 | - const PARAMETER_FILES = 'files'; |
|
38 | - const PARAMETER_FOLDER = 'folder'; |
|
39 | - const PARAMETER_IMAGE = 'image'; |
|
40 | - const PARAMETER_IMAGES = 'images'; |
|
41 | - const PARAMETER_IMAGE_SET = 'imageSet'; |
|
42 | - const PARAMETER_MAIN_NAV_CLASS = 'mainNavClass'; |
|
43 | - const PARAMETER_MY_BRICK_SLUG = 'myBrickSlug'; |
|
16 | + * @var \CloudControl\Cms\storage\Storage |
|
17 | + */ |
|
18 | + public $storage; |
|
19 | + |
|
20 | + const INVALID_CREDENTIALS_MESSAGE = 'Invalid username / password combination'; |
|
21 | + |
|
22 | + const MAIN_NAV_CLASS = 'default'; |
|
23 | + |
|
24 | + const PARAMETER_APPLICATION_COMPONENT = 'applicationComponent'; |
|
25 | + const PARAMETER_APPLICATION_COMPONENTS = 'applicationComponents'; |
|
26 | + const PARAMETER_BLACKLIST_IPS = 'blacklistIps'; |
|
27 | + const PARAMETER_BODY = 'body'; |
|
28 | + const PARAMETER_BRICK = 'brick'; |
|
29 | + const PARAMETER_BRICKS = 'bricks'; |
|
30 | + const PARAMETER_CMS_PREFIX = 'cmsPrefix'; |
|
31 | + const PARAMETER_CONFIGURATION = 'configuration'; |
|
32 | + const PARAMETER_DOCUMENT = 'document'; |
|
33 | + const PARAMETER_DOCUMENTS = 'documents'; |
|
34 | + const PARAMETER_DOCUMENT_TYPE = 'documentType'; |
|
35 | + const PARAMETER_DOCUMENT_TYPES = 'documentTypes'; |
|
36 | + const PARAMETER_ERROR_MESSAGE = 'errorMsg'; |
|
37 | + const PARAMETER_FILES = 'files'; |
|
38 | + const PARAMETER_FOLDER = 'folder'; |
|
39 | + const PARAMETER_IMAGE = 'image'; |
|
40 | + const PARAMETER_IMAGES = 'images'; |
|
41 | + const PARAMETER_IMAGE_SET = 'imageSet'; |
|
42 | + const PARAMETER_MAIN_NAV_CLASS = 'mainNavClass'; |
|
43 | + const PARAMETER_MY_BRICK_SLUG = 'myBrickSlug'; |
|
44 | 44 | const PARAMETER_REDIRECT = 'redirect'; |
45 | 45 | const PARAMETER_REDIRECTS = 'redirects'; |
46 | - const PARAMETER_SEARCH = 'search'; |
|
47 | - const PARAMETER_SEARCH_LOG = "searchLog"; |
|
48 | - const PARAMETER_SEARCH_NEEDS_UPDATE = "searchNeedsUpdate"; |
|
49 | - const PARAMETER_SITEMAP = 'sitemap'; |
|
50 | - const PARAMETER_SITEMAP_ITEM = 'sitemapItem'; |
|
51 | - const PARAMETER_SMALLEST_IMAGE = 'smallestImage'; |
|
52 | - const PARAMETER_STATIC = 'static'; |
|
53 | - const PARAMETER_USER = 'user'; |
|
54 | - const PARAMETER_USERS = 'users'; |
|
55 | - const PARAMETER_USER_RIGHTS = 'userRights'; |
|
56 | - const PARAMETER_VALUELIST = "valuelist"; |
|
57 | - const PARAMETER_VALUELISTS = "valuelists"; |
|
58 | - const PARAMETER_WHITELIST_IPS = 'whitelistIps'; |
|
46 | + const PARAMETER_SEARCH = 'search'; |
|
47 | + const PARAMETER_SEARCH_LOG = "searchLog"; |
|
48 | + const PARAMETER_SEARCH_NEEDS_UPDATE = "searchNeedsUpdate"; |
|
49 | + const PARAMETER_SITEMAP = 'sitemap'; |
|
50 | + const PARAMETER_SITEMAP_ITEM = 'sitemapItem'; |
|
51 | + const PARAMETER_SMALLEST_IMAGE = 'smallestImage'; |
|
52 | + const PARAMETER_STATIC = 'static'; |
|
53 | + const PARAMETER_USER = 'user'; |
|
54 | + const PARAMETER_USERS = 'users'; |
|
55 | + const PARAMETER_USER_RIGHTS = 'userRights'; |
|
56 | + const PARAMETER_VALUELIST = "valuelist"; |
|
57 | + const PARAMETER_VALUELISTS = "valuelists"; |
|
58 | + const PARAMETER_WHITELIST_IPS = 'whitelistIps'; |
|
59 | 59 | |
60 | 60 | const POST_PARAMETER_COMPONENT = 'component'; |
61 | 61 | const POST_PARAMETER_FROM_URL = "fromUrl"; |
@@ -66,308 +66,308 @@ discard block |
||
66 | 66 | const POST_PARAMETER_TO_URL = "toUrl"; |
67 | 67 | const POST_PARAMETER_USERNAME = 'username'; |
68 | 68 | |
69 | - const GET_PARAMETER_PATH = 'path'; |
|
70 | - const GET_PARAMETER_SLUG = 'slug'; |
|
71 | - |
|
72 | - const FILES_PARAMETER_FILE = 'file'; |
|
73 | - |
|
74 | - const SESSION_PARAMETER_CLOUD_CONTROL = 'cloudcontrol'; |
|
75 | - |
|
76 | - const LOGIN_TEMPLATE_PATH = 'login'; |
|
77 | - |
|
78 | - const CONTENT_TYPE_APPLICATION_JSON = 'Content-type:application/json'; |
|
79 | - |
|
80 | - public $subTemplate = null; |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * @param Storage $storage |
|
85 | - * |
|
86 | - * @return void |
|
87 | - */ |
|
88 | - public function run(Storage $storage) |
|
89 | - { |
|
90 | - $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::MAIN_NAV_CLASS; |
|
91 | - $this->storage = $storage; |
|
92 | - |
|
93 | - $remoteAddress = $_SERVER['REMOTE_ADDR']; |
|
94 | - $this->checkWhiteList($remoteAddress); |
|
95 | - $this->checkBlackList($remoteAddress); |
|
96 | - |
|
97 | - $this->checkLogin(); |
|
98 | - |
|
99 | - $this->parameters[self::PARAMETER_USER_RIGHTS] = $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]->rights; |
|
100 | - |
|
101 | - $this->routing(); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * See if a user is logged or wants to log in and |
|
106 | - * takes appropriate actions. |
|
107 | - * |
|
108 | - * @throws \Exception |
|
109 | - */ |
|
110 | - protected function checkLogin() |
|
111 | - { |
|
112 | - $request = $this->request; |
|
113 | - |
|
114 | - if (!isset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL])) { |
|
115 | - if (isset($request::$post[self::POST_PARAMETER_USERNAME], $request::$post[self::POST_PARAMETER_PASSWORD])) { |
|
116 | - $this->checkLoginAttempt($request); |
|
117 | - } else { |
|
118 | - $this->showLogin(); |
|
119 | - } |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Overrides normal behaviour and only renders the |
|
125 | - * login screen |
|
126 | - * |
|
127 | - * @throws \Exception |
|
128 | - */ |
|
129 | - protected function showLogin() |
|
130 | - { |
|
131 | - $loginTemplatePath = self::LOGIN_TEMPLATE_PATH; |
|
132 | - $this->renderTemplate($loginTemplatePath); |
|
133 | - ob_end_flush(); |
|
134 | - exit; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * As an exception, to keep the initial file structure simple |
|
139 | - * the cms implements it's own routing, apart from the regular sitemap functionality |
|
140 | - * |
|
141 | - * @throws \Exception |
|
142 | - */ |
|
143 | - protected function routing() |
|
144 | - { |
|
145 | - $relativeCmsUri = $this->getRelativeCmsUri($this->request); |
|
146 | - |
|
147 | - $userRights = $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]->rights; |
|
148 | - |
|
149 | - $this->dashboardRouting($relativeCmsUri); |
|
150 | - $this->logOffRouting($this->request, $relativeCmsUri); |
|
151 | - $this->apiRouting($relativeCmsUri); |
|
152 | - $this->documentRouting($userRights, $relativeCmsUri); |
|
153 | - $this->sitemapRouting($userRights, $relativeCmsUri); |
|
154 | - $this->imageRouting($userRights, $relativeCmsUri); |
|
155 | - $this->filesRouting($userRights, $relativeCmsUri); |
|
156 | - $this->configurationRouting($userRights, $relativeCmsUri); |
|
157 | - $this->searchRouting($userRights, $relativeCmsUri); |
|
158 | - |
|
159 | - $this->renderBody(); |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * @param $remoteAddress |
|
164 | - * |
|
165 | - * @throws \Exception |
|
166 | - */ |
|
167 | - private function checkWhiteList($remoteAddress) |
|
168 | - { |
|
169 | - if (isset($this->parameters[self::PARAMETER_WHITELIST_IPS])) { |
|
170 | - $whitelistIps = explode(',', $this->parameters[self::PARAMETER_WHITELIST_IPS]); |
|
171 | - $whitelistIps = array_map("trim", $whitelistIps); |
|
172 | - if (!in_array($remoteAddress, $whitelistIps)) { |
|
173 | - throw new \Exception('Ip address ' . $remoteAddress . ' is not on whitelist'); |
|
174 | - } |
|
175 | - } |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * @param $remoteAddress |
|
180 | - * |
|
181 | - * @throws \Exception |
|
182 | - */ |
|
183 | - private function checkBlackList($remoteAddress) |
|
184 | - { |
|
185 | - if (isset($this->parameters[self::PARAMETER_BLACKLIST_IPS])) { |
|
186 | - $blacklistIps = explode(',', $this->parameters[self::PARAMETER_BLACKLIST_IPS]); |
|
187 | - $blacklistIps = array_map("trim", $blacklistIps); |
|
188 | - if (in_array($remoteAddress, $blacklistIps)) { |
|
189 | - throw new \Exception('Ip address ' . $remoteAddress . ' is on blacklist'); |
|
190 | - } |
|
191 | - } |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * @param $request |
|
196 | - * |
|
197 | - * @return mixed|string |
|
198 | - */ |
|
199 | - private function getRelativeCmsUri($request) |
|
200 | - { |
|
201 | - // TODO Use regex match parameter instead of calculating relative uri |
|
202 | - $pos = strpos($request::$relativeUri, $this->parameters[self::PARAMETER_CMS_PREFIX]); |
|
203 | - $relativeCmsUri = '/'; |
|
204 | - if ($pos !== false) { |
|
205 | - $relativeCmsUri = substr_replace($request::$relativeUri, '', $pos, strlen($this->parameters[self::PARAMETER_CMS_PREFIX])); |
|
206 | - } |
|
207 | - |
|
208 | - return $relativeCmsUri; |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * @param $relativeCmsUri |
|
213 | - */ |
|
214 | - private function apiRouting($relativeCmsUri) |
|
215 | - { |
|
216 | - if ($relativeCmsUri == '/images.json') { |
|
217 | - header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
218 | - die(json_encode($this->storage->getImages()->getImages())); |
|
219 | - } elseif ($relativeCmsUri == '/files.json') { |
|
220 | - header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
221 | - die(json_encode($this->storage->getFiles()->getFiles())); |
|
222 | - } elseif ($relativeCmsUri == '/documents.json') { |
|
223 | - header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
224 | - die(json_encode($this->storage->getDocuments()->getDocuments())); |
|
225 | - } |
|
226 | - } |
|
227 | - |
|
228 | - private function logOffRouting($request, $relativeCmsUri) |
|
229 | - { |
|
230 | - if ($relativeCmsUri == '/log-off') { |
|
231 | - $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = null; |
|
232 | - unset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]); |
|
233 | - header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX]); |
|
234 | - exit; |
|
235 | - } |
|
236 | - } |
|
237 | - |
|
238 | - public function setParameter($parameterName, $parameterValue) |
|
239 | - { |
|
240 | - $this->parameters[$parameterName] = $parameterValue; |
|
241 | - } |
|
242 | - |
|
243 | - public function getParameter($parameterName) |
|
244 | - { |
|
245 | - return $this->parameters[$parameterName]; |
|
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * @param $relativeCmsUri |
|
250 | - */ |
|
251 | - protected function dashboardRouting($relativeCmsUri) |
|
252 | - { |
|
253 | - if ($relativeCmsUri == '' || $relativeCmsUri == '/') { |
|
254 | - $this->subTemplate = 'dashboard'; |
|
255 | - } |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * @param $userRights |
|
260 | - * @param $relativeCmsUri |
|
261 | - */ |
|
262 | - protected function documentRouting($userRights, $relativeCmsUri) |
|
263 | - { |
|
264 | - if (in_array(self::PARAMETER_DOCUMENTS, $userRights)) { |
|
265 | - new DocumentRouting($this->request, $relativeCmsUri, $this); |
|
266 | - } |
|
267 | - } |
|
268 | - |
|
269 | - /** |
|
270 | - * @param $userRights |
|
271 | - * @param $relativeCmsUri |
|
272 | - */ |
|
273 | - protected function sitemapRouting($userRights, $relativeCmsUri) |
|
274 | - { |
|
275 | - if (in_array(self::PARAMETER_SITEMAP, $userRights)) { |
|
276 | - new SitemapRouting($this->request, $relativeCmsUri, $this); |
|
277 | - } |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * @param $userRights |
|
282 | - * @param $relativeCmsUri |
|
283 | - */ |
|
284 | - protected function imageRouting($userRights, $relativeCmsUri) |
|
285 | - { |
|
286 | - if (in_array(self::PARAMETER_IMAGES, $userRights)) { |
|
287 | - new ImagesRouting($this->request, $relativeCmsUri, $this); |
|
288 | - } |
|
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * @param $userRights |
|
293 | - * @param $relativeCmsUri |
|
294 | - */ |
|
295 | - protected function filesRouting($userRights, $relativeCmsUri) |
|
296 | - { |
|
297 | - if (in_array(self::PARAMETER_FILES, $userRights)) { |
|
298 | - new FilesRouting($this->request, $relativeCmsUri, $this); |
|
299 | - } |
|
300 | - } |
|
301 | - |
|
302 | - /** |
|
303 | - * @param $userRights |
|
304 | - * @param $relativeCmsUri |
|
305 | - */ |
|
306 | - protected function configurationRouting($userRights, $relativeCmsUri) |
|
307 | - { |
|
308 | - if (in_array('configuration', $userRights)) { |
|
309 | - new ConfigurationRouting($this->request, $relativeCmsUri, $this); |
|
310 | - } |
|
311 | - } |
|
312 | - |
|
313 | - protected function renderBody() |
|
314 | - { |
|
315 | - if ($this->subTemplate !== null) { |
|
316 | - $this->parameters[self::PARAMETER_BODY] = $this->renderTemplate($this->subTemplate); |
|
317 | - } |
|
318 | - } |
|
319 | - |
|
320 | - /** |
|
321 | - * @param $crypt |
|
322 | - * @param $request |
|
323 | - */ |
|
324 | - protected function invalidCredentials($crypt, $request) |
|
325 | - { |
|
326 | - $crypt->encrypt($request::$post[self::POST_PARAMETER_PASSWORD], 16); // Buy time, to avoid brute forcing |
|
327 | - $this->parameters[self::PARAMETER_ERROR_MESSAGE] = self::INVALID_CREDENTIALS_MESSAGE; |
|
328 | - $this->showLogin(); |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * @param $user |
|
333 | - * @param $crypt |
|
334 | - * @param $request |
|
335 | - */ |
|
336 | - protected function checkPassword($user, $crypt, $request) |
|
337 | - { |
|
338 | - $salt = $user->salt; |
|
339 | - $password = $user->password; |
|
340 | - |
|
341 | - $passwordCorrect = $crypt->compare($request::$post[self::POST_PARAMETER_PASSWORD], $password, $salt); |
|
342 | - |
|
343 | - if ($passwordCorrect) { |
|
344 | - $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = $user; |
|
345 | - } else { |
|
346 | - $this->parameters[self::PARAMETER_ERROR_MESSAGE] = self::INVALID_CREDENTIALS_MESSAGE; |
|
347 | - $this->showLogin(); |
|
348 | - } |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * @param $request |
|
353 | - */ |
|
354 | - protected function checkLoginAttempt($request) |
|
355 | - { |
|
356 | - $user = $this->storage->getUsers()->getUserByUsername($request::$post[self::POST_PARAMETER_USERNAME]); |
|
357 | - $crypt = new Crypt(); |
|
358 | - if (empty($user)) { |
|
359 | - $this->invalidCredentials($crypt, $request); |
|
360 | - } else { |
|
361 | - $this->checkPassword($user, $crypt, $request); |
|
362 | - } |
|
363 | - } |
|
364 | - |
|
365 | - private function searchRouting($userRights, $relativeCmsUri) |
|
366 | - { |
|
367 | - if (in_array(self::PARAMETER_SEARCH, $userRights)) { |
|
368 | - new SearchRouting($this->request, $relativeCmsUri, $this); |
|
369 | - } |
|
370 | - } |
|
69 | + const GET_PARAMETER_PATH = 'path'; |
|
70 | + const GET_PARAMETER_SLUG = 'slug'; |
|
71 | + |
|
72 | + const FILES_PARAMETER_FILE = 'file'; |
|
73 | + |
|
74 | + const SESSION_PARAMETER_CLOUD_CONTROL = 'cloudcontrol'; |
|
75 | + |
|
76 | + const LOGIN_TEMPLATE_PATH = 'login'; |
|
77 | + |
|
78 | + const CONTENT_TYPE_APPLICATION_JSON = 'Content-type:application/json'; |
|
79 | + |
|
80 | + public $subTemplate = null; |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * @param Storage $storage |
|
85 | + * |
|
86 | + * @return void |
|
87 | + */ |
|
88 | + public function run(Storage $storage) |
|
89 | + { |
|
90 | + $this->parameters[self::PARAMETER_MAIN_NAV_CLASS] = self::MAIN_NAV_CLASS; |
|
91 | + $this->storage = $storage; |
|
92 | + |
|
93 | + $remoteAddress = $_SERVER['REMOTE_ADDR']; |
|
94 | + $this->checkWhiteList($remoteAddress); |
|
95 | + $this->checkBlackList($remoteAddress); |
|
96 | + |
|
97 | + $this->checkLogin(); |
|
98 | + |
|
99 | + $this->parameters[self::PARAMETER_USER_RIGHTS] = $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]->rights; |
|
100 | + |
|
101 | + $this->routing(); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * See if a user is logged or wants to log in and |
|
106 | + * takes appropriate actions. |
|
107 | + * |
|
108 | + * @throws \Exception |
|
109 | + */ |
|
110 | + protected function checkLogin() |
|
111 | + { |
|
112 | + $request = $this->request; |
|
113 | + |
|
114 | + if (!isset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL])) { |
|
115 | + if (isset($request::$post[self::POST_PARAMETER_USERNAME], $request::$post[self::POST_PARAMETER_PASSWORD])) { |
|
116 | + $this->checkLoginAttempt($request); |
|
117 | + } else { |
|
118 | + $this->showLogin(); |
|
119 | + } |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Overrides normal behaviour and only renders the |
|
125 | + * login screen |
|
126 | + * |
|
127 | + * @throws \Exception |
|
128 | + */ |
|
129 | + protected function showLogin() |
|
130 | + { |
|
131 | + $loginTemplatePath = self::LOGIN_TEMPLATE_PATH; |
|
132 | + $this->renderTemplate($loginTemplatePath); |
|
133 | + ob_end_flush(); |
|
134 | + exit; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * As an exception, to keep the initial file structure simple |
|
139 | + * the cms implements it's own routing, apart from the regular sitemap functionality |
|
140 | + * |
|
141 | + * @throws \Exception |
|
142 | + */ |
|
143 | + protected function routing() |
|
144 | + { |
|
145 | + $relativeCmsUri = $this->getRelativeCmsUri($this->request); |
|
146 | + |
|
147 | + $userRights = $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]->rights; |
|
148 | + |
|
149 | + $this->dashboardRouting($relativeCmsUri); |
|
150 | + $this->logOffRouting($this->request, $relativeCmsUri); |
|
151 | + $this->apiRouting($relativeCmsUri); |
|
152 | + $this->documentRouting($userRights, $relativeCmsUri); |
|
153 | + $this->sitemapRouting($userRights, $relativeCmsUri); |
|
154 | + $this->imageRouting($userRights, $relativeCmsUri); |
|
155 | + $this->filesRouting($userRights, $relativeCmsUri); |
|
156 | + $this->configurationRouting($userRights, $relativeCmsUri); |
|
157 | + $this->searchRouting($userRights, $relativeCmsUri); |
|
158 | + |
|
159 | + $this->renderBody(); |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * @param $remoteAddress |
|
164 | + * |
|
165 | + * @throws \Exception |
|
166 | + */ |
|
167 | + private function checkWhiteList($remoteAddress) |
|
168 | + { |
|
169 | + if (isset($this->parameters[self::PARAMETER_WHITELIST_IPS])) { |
|
170 | + $whitelistIps = explode(',', $this->parameters[self::PARAMETER_WHITELIST_IPS]); |
|
171 | + $whitelistIps = array_map("trim", $whitelistIps); |
|
172 | + if (!in_array($remoteAddress, $whitelistIps)) { |
|
173 | + throw new \Exception('Ip address ' . $remoteAddress . ' is not on whitelist'); |
|
174 | + } |
|
175 | + } |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * @param $remoteAddress |
|
180 | + * |
|
181 | + * @throws \Exception |
|
182 | + */ |
|
183 | + private function checkBlackList($remoteAddress) |
|
184 | + { |
|
185 | + if (isset($this->parameters[self::PARAMETER_BLACKLIST_IPS])) { |
|
186 | + $blacklistIps = explode(',', $this->parameters[self::PARAMETER_BLACKLIST_IPS]); |
|
187 | + $blacklistIps = array_map("trim", $blacklistIps); |
|
188 | + if (in_array($remoteAddress, $blacklistIps)) { |
|
189 | + throw new \Exception('Ip address ' . $remoteAddress . ' is on blacklist'); |
|
190 | + } |
|
191 | + } |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * @param $request |
|
196 | + * |
|
197 | + * @return mixed|string |
|
198 | + */ |
|
199 | + private function getRelativeCmsUri($request) |
|
200 | + { |
|
201 | + // TODO Use regex match parameter instead of calculating relative uri |
|
202 | + $pos = strpos($request::$relativeUri, $this->parameters[self::PARAMETER_CMS_PREFIX]); |
|
203 | + $relativeCmsUri = '/'; |
|
204 | + if ($pos !== false) { |
|
205 | + $relativeCmsUri = substr_replace($request::$relativeUri, '', $pos, strlen($this->parameters[self::PARAMETER_CMS_PREFIX])); |
|
206 | + } |
|
207 | + |
|
208 | + return $relativeCmsUri; |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * @param $relativeCmsUri |
|
213 | + */ |
|
214 | + private function apiRouting($relativeCmsUri) |
|
215 | + { |
|
216 | + if ($relativeCmsUri == '/images.json') { |
|
217 | + header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
218 | + die(json_encode($this->storage->getImages()->getImages())); |
|
219 | + } elseif ($relativeCmsUri == '/files.json') { |
|
220 | + header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
221 | + die(json_encode($this->storage->getFiles()->getFiles())); |
|
222 | + } elseif ($relativeCmsUri == '/documents.json') { |
|
223 | + header(self::CONTENT_TYPE_APPLICATION_JSON); |
|
224 | + die(json_encode($this->storage->getDocuments()->getDocuments())); |
|
225 | + } |
|
226 | + } |
|
227 | + |
|
228 | + private function logOffRouting($request, $relativeCmsUri) |
|
229 | + { |
|
230 | + if ($relativeCmsUri == '/log-off') { |
|
231 | + $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = null; |
|
232 | + unset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]); |
|
233 | + header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX]); |
|
234 | + exit; |
|
235 | + } |
|
236 | + } |
|
237 | + |
|
238 | + public function setParameter($parameterName, $parameterValue) |
|
239 | + { |
|
240 | + $this->parameters[$parameterName] = $parameterValue; |
|
241 | + } |
|
242 | + |
|
243 | + public function getParameter($parameterName) |
|
244 | + { |
|
245 | + return $this->parameters[$parameterName]; |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * @param $relativeCmsUri |
|
250 | + */ |
|
251 | + protected function dashboardRouting($relativeCmsUri) |
|
252 | + { |
|
253 | + if ($relativeCmsUri == '' || $relativeCmsUri == '/') { |
|
254 | + $this->subTemplate = 'dashboard'; |
|
255 | + } |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * @param $userRights |
|
260 | + * @param $relativeCmsUri |
|
261 | + */ |
|
262 | + protected function documentRouting($userRights, $relativeCmsUri) |
|
263 | + { |
|
264 | + if (in_array(self::PARAMETER_DOCUMENTS, $userRights)) { |
|
265 | + new DocumentRouting($this->request, $relativeCmsUri, $this); |
|
266 | + } |
|
267 | + } |
|
268 | + |
|
269 | + /** |
|
270 | + * @param $userRights |
|
271 | + * @param $relativeCmsUri |
|
272 | + */ |
|
273 | + protected function sitemapRouting($userRights, $relativeCmsUri) |
|
274 | + { |
|
275 | + if (in_array(self::PARAMETER_SITEMAP, $userRights)) { |
|
276 | + new SitemapRouting($this->request, $relativeCmsUri, $this); |
|
277 | + } |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * @param $userRights |
|
282 | + * @param $relativeCmsUri |
|
283 | + */ |
|
284 | + protected function imageRouting($userRights, $relativeCmsUri) |
|
285 | + { |
|
286 | + if (in_array(self::PARAMETER_IMAGES, $userRights)) { |
|
287 | + new ImagesRouting($this->request, $relativeCmsUri, $this); |
|
288 | + } |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * @param $userRights |
|
293 | + * @param $relativeCmsUri |
|
294 | + */ |
|
295 | + protected function filesRouting($userRights, $relativeCmsUri) |
|
296 | + { |
|
297 | + if (in_array(self::PARAMETER_FILES, $userRights)) { |
|
298 | + new FilesRouting($this->request, $relativeCmsUri, $this); |
|
299 | + } |
|
300 | + } |
|
301 | + |
|
302 | + /** |
|
303 | + * @param $userRights |
|
304 | + * @param $relativeCmsUri |
|
305 | + */ |
|
306 | + protected function configurationRouting($userRights, $relativeCmsUri) |
|
307 | + { |
|
308 | + if (in_array('configuration', $userRights)) { |
|
309 | + new ConfigurationRouting($this->request, $relativeCmsUri, $this); |
|
310 | + } |
|
311 | + } |
|
312 | + |
|
313 | + protected function renderBody() |
|
314 | + { |
|
315 | + if ($this->subTemplate !== null) { |
|
316 | + $this->parameters[self::PARAMETER_BODY] = $this->renderTemplate($this->subTemplate); |
|
317 | + } |
|
318 | + } |
|
319 | + |
|
320 | + /** |
|
321 | + * @param $crypt |
|
322 | + * @param $request |
|
323 | + */ |
|
324 | + protected function invalidCredentials($crypt, $request) |
|
325 | + { |
|
326 | + $crypt->encrypt($request::$post[self::POST_PARAMETER_PASSWORD], 16); // Buy time, to avoid brute forcing |
|
327 | + $this->parameters[self::PARAMETER_ERROR_MESSAGE] = self::INVALID_CREDENTIALS_MESSAGE; |
|
328 | + $this->showLogin(); |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * @param $user |
|
333 | + * @param $crypt |
|
334 | + * @param $request |
|
335 | + */ |
|
336 | + protected function checkPassword($user, $crypt, $request) |
|
337 | + { |
|
338 | + $salt = $user->salt; |
|
339 | + $password = $user->password; |
|
340 | + |
|
341 | + $passwordCorrect = $crypt->compare($request::$post[self::POST_PARAMETER_PASSWORD], $password, $salt); |
|
342 | + |
|
343 | + if ($passwordCorrect) { |
|
344 | + $_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = $user; |
|
345 | + } else { |
|
346 | + $this->parameters[self::PARAMETER_ERROR_MESSAGE] = self::INVALID_CREDENTIALS_MESSAGE; |
|
347 | + $this->showLogin(); |
|
348 | + } |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * @param $request |
|
353 | + */ |
|
354 | + protected function checkLoginAttempt($request) |
|
355 | + { |
|
356 | + $user = $this->storage->getUsers()->getUserByUsername($request::$post[self::POST_PARAMETER_USERNAME]); |
|
357 | + $crypt = new Crypt(); |
|
358 | + if (empty($user)) { |
|
359 | + $this->invalidCredentials($crypt, $request); |
|
360 | + } else { |
|
361 | + $this->checkPassword($user, $crypt, $request); |
|
362 | + } |
|
363 | + } |
|
364 | + |
|
365 | + private function searchRouting($userRights, $relativeCmsUri) |
|
366 | + { |
|
367 | + if (in_array(self::PARAMETER_SEARCH, $userRights)) { |
|
368 | + new SearchRouting($this->request, $relativeCmsUri, $this); |
|
369 | + } |
|
370 | + } |
|
371 | 371 | |
372 | 372 | protected function getTemplateDir($template, $application = null) |
373 | 373 | { |
@@ -116,13 +116,13 @@ discard block |
||
116 | 116 | if (in_array($name, $this->fileBasedSubsets)) { |
117 | 117 | return $this->$name; |
118 | 118 | } else { |
119 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
119 | + throw new \Exception('Trying to get undefined property from Repository: '.$name); |
|
120 | 120 | } |
121 | 121 | } else { |
122 | 122 | if (in_array($name, $this->fileBasedSubsets)) { |
123 | 123 | return $this->loadSubset($name); |
124 | 124 | } else { |
125 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
125 | + throw new \Exception('Trying to get undefined property from Repository: '.$name); |
|
126 | 126 | } |
127 | 127 | } |
128 | 128 | } |
@@ -137,10 +137,10 @@ discard block |
||
137 | 137 | { |
138 | 138 | if (in_array($name, $this->fileBasedSubsets)) { |
139 | 139 | $this->$name = $value; |
140 | - $changes = $name . 'Changes'; |
|
140 | + $changes = $name.'Changes'; |
|
141 | 141 | $this->$changes = true; |
142 | 142 | } else { |
143 | - throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
143 | + throw new \Exception('Trying to persist unknown subset in repository: '.$name.' <br /><pre>'.print_r($value, true).'</pre>'); |
|
144 | 144 | } |
145 | 145 | } |
146 | 146 | |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | public function save() |
151 | 151 | { |
152 | 152 | $host = $this; |
153 | - array_map(function ($value) use ($host) { |
|
153 | + array_map(function($value) use ($host) { |
|
154 | 154 | $host->saveSubset($value); |
155 | 155 | }, $this->fileBasedSubsets); |
156 | 156 | } |
@@ -161,14 +161,14 @@ discard block |
||
161 | 161 | */ |
162 | 162 | public function saveSubset($subset) |
163 | 163 | { |
164 | - $changes = $subset . 'Changes'; |
|
164 | + $changes = $subset.'Changes'; |
|
165 | 165 | if ($this->$changes === true) { |
166 | 166 | if (!defined('JSON_PRETTY_PRINT')) { |
167 | 167 | $json = json_encode($this->$subset); |
168 | 168 | } else { |
169 | 169 | $json = json_encode($this->$subset, JSON_PRETTY_PRINT); |
170 | 170 | } |
171 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
171 | + $subsetStoragePath = $this->storagePath.DIRECTORY_SEPARATOR.$subset.'.json'; |
|
172 | 172 | file_put_contents($subsetStoragePath, $json); |
173 | 173 | |
174 | 174 | $this->$changes = false; |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | */ |
183 | 183 | protected function loadSubset($subset) |
184 | 184 | { |
185 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
185 | + $subsetStoragePath = $this->storagePath.DIRECTORY_SEPARATOR.$subset.'.json'; |
|
186 | 186 | $json = file_get_contents($subsetStoragePath); |
187 | 187 | $json = json_decode($json); |
188 | 188 | $this->$subset = $json; |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | public function getContentDbHandle() |
225 | 225 | { |
226 | 226 | if ($this->contentDbHandle === null) { |
227 | - $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
227 | + $this->contentDbHandle = new \PDO('sqlite:'.$this->storagePath.DIRECTORY_SEPARATOR.'content.db'); |
|
228 | 228 | } |
229 | 229 | return $this->contentDbHandle; |
230 | 230 | } |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | public function getDocuments($state = 'published') |
241 | 241 | { |
242 | 242 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
243 | - throw new \Exception('Unsupported document state: ' . $state); |
|
243 | + throw new \Exception('Unsupported document state: '.$state); |
|
244 | 244 | } |
245 | 245 | return $this->getDocumentsByPath('/', $state); |
246 | 246 | } |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | public function getDocumentsWithState($folderPath = '/') |
249 | 249 | { |
250 | 250 | $db = $this->getContentDbHandle(); |
251 | - $folderPathWithWildcard = $folderPath . '%'; |
|
251 | + $folderPathWithWildcard = $folderPath.'%'; |
|
252 | 252 | |
253 | 253 | $ifRootIndex = 1; |
254 | 254 | if ($folderPath == '/') { |
@@ -263,10 +263,10 @@ discard block |
||
263 | 263 | FROM documents_unpublished |
264 | 264 | LEFT JOIN documents_published |
265 | 265 | ON documents_published.path = documents_unpublished.path |
266 | - WHERE documents_unpublished.`path` LIKE ' . $db->quote($folderPathWithWildcard) . ' |
|
267 | - AND substr(documents_unpublished.`path`, ' . (strlen($folderPath) + $ifRootIndex + 1) . ') NOT LIKE "%/%" |
|
268 | - AND length(documents_unpublished.`path`) > ' . (strlen($folderPath) + $ifRootIndex) . ' |
|
269 | - AND documents_unpublished.path != ' . $db->quote($folderPath) . ' |
|
266 | + WHERE documents_unpublished.`path` LIKE ' . $db->quote($folderPathWithWildcard).' |
|
267 | + AND substr(documents_unpublished.`path`, ' . (strlen($folderPath) + $ifRootIndex + 1).') NOT LIKE "%/%" |
|
268 | + AND length(documents_unpublished.`path`) > ' . (strlen($folderPath) + $ifRootIndex).' |
|
269 | + AND documents_unpublished.path != ' . $db->quote($folderPath).' |
|
270 | 270 | ORDER BY documents_unpublished.`type` DESC, documents_unpublished.`path` ASC |
271 | 271 | '; |
272 | 272 | $stmt = $this->getDbStatement($sql); |
@@ -293,16 +293,16 @@ discard block |
||
293 | 293 | public function getDocumentsByPath($folderPath, $state = 'published') |
294 | 294 | { |
295 | 295 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
296 | - throw new \Exception('Unsupported document state: ' . $state); |
|
296 | + throw new \Exception('Unsupported document state: '.$state); |
|
297 | 297 | } |
298 | 298 | $db = $this->getContentDbHandle(); |
299 | - $folderPathWithWildcard = $folderPath . '%'; |
|
299 | + $folderPathWithWildcard = $folderPath.'%'; |
|
300 | 300 | |
301 | 301 | $sql = 'SELECT * |
302 | - FROM documents_' . $state . ' |
|
303 | - WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard) . ' |
|
304 | - AND substr(`path`, ' . (strlen($folderPath) + 1) . ') NOT LIKE "%/%" |
|
305 | - AND path != ' . $db->quote($folderPath) . ' |
|
302 | + FROM documents_' . $state.' |
|
303 | + WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard).' |
|
304 | + AND substr(`path`, ' . (strlen($folderPath) + 1).') NOT LIKE "%/%" |
|
305 | + AND path != ' . $db->quote($folderPath).' |
|
306 | 306 | ORDER BY `type` DESC, `path` ASC'; |
307 | 307 | $stmt = $this->getDbStatement($sql); |
308 | 308 | |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | if ($containerPath === '/') { |
330 | 330 | return $this->getRootFolder(); |
331 | 331 | } |
332 | - if (substr($containerPath, -1) === '/'){ |
|
332 | + if (substr($containerPath, -1) === '/') { |
|
333 | 333 | $containerPath = substr($containerPath, 0, -1); |
334 | 334 | } |
335 | 335 | $containerFolder = $this->getDocumentByPath($containerPath, 'unpublished'); |
@@ -346,13 +346,13 @@ discard block |
||
346 | 346 | public function getDocumentByPath($path, $state = 'published') |
347 | 347 | { |
348 | 348 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
349 | - throw new \Exception('Unsupported document state: ' . $state); |
|
349 | + throw new \Exception('Unsupported document state: '.$state); |
|
350 | 350 | } |
351 | 351 | $db = $this->getContentDbHandle(); |
352 | 352 | $document = $this->fetchDocument(' |
353 | 353 | SELECT * |
354 | - FROM documents_' . $state . ' |
|
355 | - WHERE path = ' . $db->quote($path) . ' |
|
354 | + FROM documents_' . $state.' |
|
355 | + WHERE path = ' . $db->quote($path).' |
|
356 | 356 | '); |
357 | 357 | if ($document instanceof Document && $document->type === 'folder') { |
358 | 358 | $document->dbHandle = $db; |
@@ -372,16 +372,16 @@ discard block |
||
372 | 372 | public function getTotalDocumentCount($state = 'published') |
373 | 373 | { |
374 | 374 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
375 | - throw new \Exception('Unsupported document state: ' . $state); |
|
375 | + throw new \Exception('Unsupported document state: '.$state); |
|
376 | 376 | } |
377 | 377 | $db = $this->getContentDbHandle(); |
378 | 378 | $stmt = $db->query(' |
379 | 379 | SELECT count(*) |
380 | - FROM documents_' . $state . ' |
|
380 | + FROM documents_' . $state.' |
|
381 | 381 | WHERE `type` != "folder" |
382 | 382 | '); |
383 | 383 | $result = $stmt->fetch(\PDO::FETCH_ASSOC); |
384 | - if (!is_array($result )) { |
|
384 | + if (!is_array($result)) { |
|
385 | 385 | return 0; |
386 | 386 | } |
387 | 387 | return intval(current($result)); |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | if ($stmt === false || !$stmt->execute()) { |
401 | 401 | $errorInfo = $db->errorInfo(); |
402 | 402 | $errorMsg = $errorInfo[2]; |
403 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
403 | + throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>'); |
|
404 | 404 | } |
405 | 405 | return $result; |
406 | 406 | } |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | $sql = ' |
411 | 411 | INSERT OR REPLACE INTO documents_published |
412 | 412 | (`id`,`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`publicationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
413 | - SELECT `id`,`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,"published" as state,`lastModificationDate`,`creationDate`,' . time() . ' as publicationDate, `lastModifiedBy`,`fields`,`bricks`,`dynamicBricks` |
|
413 | + SELECT `id`,`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,"published" as state,`lastModificationDate`,`creationDate`,' . time().' as publicationDate, `lastModifiedBy`,`fields`,`bricks`,`dynamicBricks` |
|
414 | 414 | FROM documents_unpublished |
415 | 415 | WHERE `path` = :path |
416 | 416 | '; |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | if ($stmt === false) { |
424 | 424 | $errorInfo = $db->errorInfo(); |
425 | 425 | $errorMsg = $errorInfo[2]; |
426 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
426 | + throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>'); |
|
427 | 427 | } |
428 | 428 | $stmt->bindValue(':path', $path); |
429 | 429 | $stmt->execute(); |
@@ -490,7 +490,7 @@ discard block |
||
490 | 490 | if ($stmt === false) { |
491 | 491 | $errorInfo = $db->errorInfo(); |
492 | 492 | $errorMsg = $errorInfo[2]; |
493 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
493 | + throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>'); |
|
494 | 494 | } |
495 | 495 | return $stmt; |
496 | 496 | } |
@@ -520,25 +520,25 @@ discard block |
||
520 | 520 | public function saveDocument($documentObject, $state = 'published') |
521 | 521 | { |
522 | 522 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
523 | - throw new \Exception('Unsupported document state: ' . $state); |
|
523 | + throw new \Exception('Unsupported document state: '.$state); |
|
524 | 524 | } |
525 | 525 | $db = $this->getContentDbHandle(); |
526 | 526 | $stmt = $this->getDbStatement(' |
527 | - INSERT OR REPLACE INTO documents_' . $state . ' (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
|
527 | + INSERT OR REPLACE INTO documents_' . $state.' (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
|
528 | 528 | VALUES( |
529 | - ' . $db->quote($documentObject->path) . ', |
|
530 | - ' . $db->quote($documentObject->title) . ', |
|
531 | - ' . $db->quote($documentObject->slug) . ', |
|
532 | - ' . $db->quote($documentObject->type) . ', |
|
533 | - ' . $db->quote($documentObject->documentType) . ', |
|
534 | - ' . $db->quote($documentObject->documentTypeSlug) . ', |
|
535 | - ' . $db->quote($documentObject->state) . ', |
|
536 | - ' . $db->quote($documentObject->lastModificationDate) . ', |
|
537 | - ' . $db->quote($documentObject->creationDate) . ', |
|
538 | - ' . $db->quote($documentObject->lastModifiedBy) . ', |
|
539 | - ' . $db->quote(json_encode($documentObject->fields)) . ', |
|
540 | - ' . $db->quote(json_encode($documentObject->bricks)) . ', |
|
541 | - ' . $db->quote(json_encode($documentObject->dynamicBricks)) . ' |
|
529 | + ' . $db->quote($documentObject->path).', |
|
530 | + ' . $db->quote($documentObject->title).', |
|
531 | + ' . $db->quote($documentObject->slug).', |
|
532 | + ' . $db->quote($documentObject->type).', |
|
533 | + ' . $db->quote($documentObject->documentType).', |
|
534 | + ' . $db->quote($documentObject->documentTypeSlug).', |
|
535 | + ' . $db->quote($documentObject->state).', |
|
536 | + ' . $db->quote($documentObject->lastModificationDate).', |
|
537 | + ' . $db->quote($documentObject->creationDate).', |
|
538 | + ' . $db->quote($documentObject->lastModifiedBy).', |
|
539 | + ' . $db->quote(json_encode($documentObject->fields)).', |
|
540 | + ' . $db->quote(json_encode($documentObject->bricks)).', |
|
541 | + ' . $db->quote(json_encode($documentObject->dynamicBricks)).' |
|
542 | 542 | ) |
543 | 543 | '); |
544 | 544 | $result = $stmt->execute(); |
@@ -562,16 +562,16 @@ discard block |
||
562 | 562 | if ($documentToDelete->type == 'document') { |
563 | 563 | $stmt = $this->getDbStatement(' |
564 | 564 | DELETE FROM documents_unpublished |
565 | - WHERE path = ' . $db->quote($path) . ' |
|
565 | + WHERE path = ' . $db->quote($path).' |
|
566 | 566 | '); |
567 | 567 | $stmt->execute(); |
568 | 568 | } elseif ($documentToDelete->type == 'folder') { |
569 | - $folderPathWithWildcard = $path . '%'; |
|
569 | + $folderPathWithWildcard = $path.'%'; |
|
570 | 570 | $stmt = $this->getDbStatement(' |
571 | 571 | DELETE FROM documents_unpublished |
572 | - WHERE (path LIKE ' . $db->quote($folderPathWithWildcard) . ' |
|
573 | - AND substr(`path`, ' . (strlen($path) + 1) . ', 1) = "/") |
|
574 | - OR path = ' . $db->quote($path) . ' |
|
572 | + WHERE (path LIKE ' . $db->quote($folderPathWithWildcard).' |
|
573 | + AND substr(`path`, ' . (strlen($path) + 1).', 1) = "/") |
|
574 | + OR path = ' . $db->quote($path).' |
|
575 | 575 | '); |
576 | 576 | $stmt->execute(); |
577 | 577 | } |
@@ -599,11 +599,11 @@ discard block |
||
599 | 599 | |
600 | 600 | private function initConfigIfNotExists($json, $subsetName) |
601 | 601 | { |
602 | - $subsetFileName = $this->storagePath . DIRECTORY_SEPARATOR . $subsetName . '.json'; |
|
602 | + $subsetFileName = $this->storagePath.DIRECTORY_SEPARATOR.$subsetName.'.json'; |
|
603 | 603 | if (file_exists($subsetFileName)) { |
604 | 604 | $this->loadSubset($subsetName); |
605 | 605 | } else { |
606 | - $changes = $subsetName . 'Changes'; |
|
606 | + $changes = $subsetName.'Changes'; |
|
607 | 607 | $this->$subsetName = $json->$subsetName; |
608 | 608 | $this->$changes = true; |
609 | 609 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | $host = $this; |
153 | 153 | array_map(function ($value) use ($host) { |
154 | 154 | $host->saveSubset($value); |
155 | - }, $this->fileBasedSubsets); |
|
155 | + }, $this->fileBasedSubsets); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
@@ -161,18 +161,18 @@ discard block |
||
161 | 161 | */ |
162 | 162 | public function saveSubset($subset) |
163 | 163 | { |
164 | - $changes = $subset . 'Changes'; |
|
165 | - if ($this->$changes === true) { |
|
164 | + $changes = $subset . 'Changes'; |
|
165 | + if ($this->$changes === true) { |
|
166 | 166 | if (!defined('JSON_PRETTY_PRINT')) { |
167 | 167 | $json = json_encode($this->$subset); |
168 | 168 | } else { |
169 | 169 | $json = json_encode($this->$subset, JSON_PRETTY_PRINT); |
170 | 170 | } |
171 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
172 | - file_put_contents($subsetStoragePath, $json); |
|
171 | + $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
172 | + file_put_contents($subsetStoragePath, $json); |
|
173 | 173 | |
174 | - $this->$changes = false; |
|
175 | - } |
|
174 | + $this->$changes = false; |
|
175 | + } |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -229,33 +229,33 @@ discard block |
||
229 | 229 | return $this->contentDbHandle; |
230 | 230 | } |
231 | 231 | |
232 | - /** |
|
233 | - * Get all documents |
|
234 | - * |
|
235 | - * @param string $state |
|
236 | - * |
|
237 | - * @return array |
|
238 | - * @throws \Exception |
|
239 | - */ |
|
232 | + /** |
|
233 | + * Get all documents |
|
234 | + * |
|
235 | + * @param string $state |
|
236 | + * |
|
237 | + * @return array |
|
238 | + * @throws \Exception |
|
239 | + */ |
|
240 | 240 | public function getDocuments($state = 'published') |
241 | 241 | { |
242 | - if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
243 | - throw new \Exception('Unsupported document state: ' . $state); |
|
244 | - } |
|
242 | + if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
243 | + throw new \Exception('Unsupported document state: ' . $state); |
|
244 | + } |
|
245 | 245 | return $this->getDocumentsByPath('/', $state); |
246 | 246 | } |
247 | 247 | |
248 | - public function getDocumentsWithState($folderPath = '/') |
|
249 | - { |
|
250 | - $db = $this->getContentDbHandle(); |
|
251 | - $folderPathWithWildcard = $folderPath . '%'; |
|
248 | + public function getDocumentsWithState($folderPath = '/') |
|
249 | + { |
|
250 | + $db = $this->getContentDbHandle(); |
|
251 | + $folderPathWithWildcard = $folderPath . '%'; |
|
252 | 252 | |
253 | - $ifRootIndex = 1; |
|
254 | - if ($folderPath == '/') { |
|
255 | - $ifRootIndex = 0; |
|
256 | - } |
|
253 | + $ifRootIndex = 1; |
|
254 | + if ($folderPath == '/') { |
|
255 | + $ifRootIndex = 0; |
|
256 | + } |
|
257 | 257 | |
258 | - $sql = ' |
|
258 | + $sql = ' |
|
259 | 259 | SELECT documents_unpublished.*, |
260 | 260 | IFNULL(documents_published.state,"unpublished") as state, |
261 | 261 | IFNULL(documents_published.publicationDate,NULL) as publicationDate, |
@@ -269,32 +269,32 @@ discard block |
||
269 | 269 | AND documents_unpublished.path != ' . $db->quote($folderPath) . ' |
270 | 270 | ORDER BY documents_unpublished.`type` DESC, documents_unpublished.`path` ASC |
271 | 271 | '; |
272 | - $stmt = $this->getDbStatement($sql); |
|
273 | - |
|
274 | - |
|
275 | - |
|
276 | - $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\CloudControl\Cms\storage\Document'); |
|
277 | - foreach ($documents as $key => $document) { |
|
278 | - $documents = $this->setAssetsToDocumentFolders($document, $db, $documents, $key); |
|
279 | - } |
|
280 | - //dump($documents); |
|
281 | - return $documents; |
|
282 | - } |
|
283 | - |
|
284 | - /** |
|
285 | - * Get all documents and folders in a certain path |
|
286 | - * |
|
287 | - * @param $folderPath |
|
288 | - * @param string $state |
|
289 | - * |
|
290 | - * @return array |
|
291 | - * @throws \Exception |
|
292 | - */ |
|
272 | + $stmt = $this->getDbStatement($sql); |
|
273 | + |
|
274 | + |
|
275 | + |
|
276 | + $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\CloudControl\Cms\storage\Document'); |
|
277 | + foreach ($documents as $key => $document) { |
|
278 | + $documents = $this->setAssetsToDocumentFolders($document, $db, $documents, $key); |
|
279 | + } |
|
280 | + //dump($documents); |
|
281 | + return $documents; |
|
282 | + } |
|
283 | + |
|
284 | + /** |
|
285 | + * Get all documents and folders in a certain path |
|
286 | + * |
|
287 | + * @param $folderPath |
|
288 | + * @param string $state |
|
289 | + * |
|
290 | + * @return array |
|
291 | + * @throws \Exception |
|
292 | + */ |
|
293 | 293 | public function getDocumentsByPath($folderPath, $state = 'published') |
294 | 294 | { |
295 | - if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
296 | - throw new \Exception('Unsupported document state: ' . $state); |
|
297 | - } |
|
295 | + if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
296 | + throw new \Exception('Unsupported document state: ' . $state); |
|
297 | + } |
|
298 | 298 | $db = $this->getContentDbHandle(); |
299 | 299 | $folderPathWithWildcard = $folderPath . '%'; |
300 | 300 | |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | |
309 | 309 | $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\CloudControl\Cms\storage\Document'); |
310 | 310 | foreach ($documents as $key => $document) { |
311 | - $documents = $this->setAssetsToDocumentFolders($document, $db, $documents, $key); |
|
311 | + $documents = $this->setAssetsToDocumentFolders($document, $db, $documents, $key); |
|
312 | 312 | } |
313 | 313 | return $documents; |
314 | 314 | } |
@@ -330,24 +330,24 @@ discard block |
||
330 | 330 | return $this->getRootFolder(); |
331 | 331 | } |
332 | 332 | if (substr($containerPath, -1) === '/'){ |
333 | - $containerPath = substr($containerPath, 0, -1); |
|
334 | - } |
|
333 | + $containerPath = substr($containerPath, 0, -1); |
|
334 | + } |
|
335 | 335 | $containerFolder = $this->getDocumentByPath($containerPath, 'unpublished'); |
336 | 336 | return $containerFolder; |
337 | 337 | } |
338 | 338 | |
339 | - /** |
|
340 | - * @param $path |
|
341 | - * @param string $state |
|
342 | - * |
|
343 | - * @return bool|\CloudControl\Cms\storage\Document |
|
344 | - * @throws \Exception |
|
345 | - */ |
|
339 | + /** |
|
340 | + * @param $path |
|
341 | + * @param string $state |
|
342 | + * |
|
343 | + * @return bool|\CloudControl\Cms\storage\Document |
|
344 | + * @throws \Exception |
|
345 | + */ |
|
346 | 346 | public function getDocumentByPath($path, $state = 'published') |
347 | 347 | { |
348 | - if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
349 | - throw new \Exception('Unsupported document state: ' . $state); |
|
350 | - } |
|
348 | + if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
349 | + throw new \Exception('Unsupported document state: ' . $state); |
|
350 | + } |
|
351 | 351 | $db = $this->getContentDbHandle(); |
352 | 352 | $document = $this->fetchDocument(' |
353 | 353 | SELECT * |
@@ -361,87 +361,87 @@ discard block |
||
361 | 361 | return $document; |
362 | 362 | } |
363 | 363 | |
364 | - /** |
|
365 | - * Returns the count of all documents stored in the db |
|
366 | - * |
|
367 | - * @param string $state |
|
368 | - * |
|
369 | - * @return int |
|
370 | - * @throws \Exception |
|
371 | - */ |
|
372 | - public function getTotalDocumentCount($state = 'published') |
|
373 | - { |
|
374 | - if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
375 | - throw new \Exception('Unsupported document state: ' . $state); |
|
376 | - } |
|
377 | - $db = $this->getContentDbHandle(); |
|
378 | - $stmt = $db->query(' |
|
364 | + /** |
|
365 | + * Returns the count of all documents stored in the db |
|
366 | + * |
|
367 | + * @param string $state |
|
368 | + * |
|
369 | + * @return int |
|
370 | + * @throws \Exception |
|
371 | + */ |
|
372 | + public function getTotalDocumentCount($state = 'published') |
|
373 | + { |
|
374 | + if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
375 | + throw new \Exception('Unsupported document state: ' . $state); |
|
376 | + } |
|
377 | + $db = $this->getContentDbHandle(); |
|
378 | + $stmt = $db->query(' |
|
379 | 379 | SELECT count(*) |
380 | 380 | FROM documents_' . $state . ' |
381 | 381 | WHERE `type` != "folder" |
382 | 382 | '); |
383 | - $result = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
384 | - if (!is_array($result )) { |
|
385 | - return 0; |
|
386 | - } |
|
387 | - return intval(current($result)); |
|
388 | - } |
|
389 | - |
|
390 | - public function getPublishedDocumentsNoFolders() |
|
391 | - { |
|
392 | - $db = $this->getContentDbHandle(); |
|
393 | - $sql = ' |
|
383 | + $result = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
384 | + if (!is_array($result )) { |
|
385 | + return 0; |
|
386 | + } |
|
387 | + return intval(current($result)); |
|
388 | + } |
|
389 | + |
|
390 | + public function getPublishedDocumentsNoFolders() |
|
391 | + { |
|
392 | + $db = $this->getContentDbHandle(); |
|
393 | + $sql = ' |
|
394 | 394 | SELECT * |
395 | 395 | FROM documents_published |
396 | 396 | WHERE `type` != "folder" |
397 | 397 | '; |
398 | - $stmt = $db->query($sql); |
|
399 | - $result = $stmt->fetchAll(\PDO::FETCH_CLASS, '\CloudControl\Cms\storage\Document'); |
|
400 | - if ($stmt === false || !$stmt->execute()) { |
|
401 | - $errorInfo = $db->errorInfo(); |
|
402 | - $errorMsg = $errorInfo[2]; |
|
403 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
404 | - } |
|
405 | - return $result; |
|
406 | - } |
|
407 | - |
|
408 | - private function publishOrUnpublishDocumentByPath($path, $publish = true) { |
|
409 | - if ($publish) { |
|
410 | - $sql = ' |
|
398 | + $stmt = $db->query($sql); |
|
399 | + $result = $stmt->fetchAll(\PDO::FETCH_CLASS, '\CloudControl\Cms\storage\Document'); |
|
400 | + if ($stmt === false || !$stmt->execute()) { |
|
401 | + $errorInfo = $db->errorInfo(); |
|
402 | + $errorMsg = $errorInfo[2]; |
|
403 | + throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
404 | + } |
|
405 | + return $result; |
|
406 | + } |
|
407 | + |
|
408 | + private function publishOrUnpublishDocumentByPath($path, $publish = true) { |
|
409 | + if ($publish) { |
|
410 | + $sql = ' |
|
411 | 411 | INSERT OR REPLACE INTO documents_published |
412 | 412 | (`id`,`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`publicationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
413 | 413 | SELECT `id`,`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,"published" as state,`lastModificationDate`,`creationDate`,' . time() . ' as publicationDate, `lastModifiedBy`,`fields`,`bricks`,`dynamicBricks` |
414 | 414 | FROM documents_unpublished |
415 | 415 | WHERE `path` = :path |
416 | 416 | '; |
417 | - } else { |
|
418 | - $sql = 'DELETE FROM documents_published |
|
417 | + } else { |
|
418 | + $sql = 'DELETE FROM documents_published |
|
419 | 419 | WHERE `path` = :path'; |
420 | - } |
|
421 | - $db = $this->getContentDbHandle(); |
|
422 | - $stmt = $db->prepare($sql); |
|
423 | - if ($stmt === false) { |
|
424 | - $errorInfo = $db->errorInfo(); |
|
425 | - $errorMsg = $errorInfo[2]; |
|
426 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
427 | - } |
|
428 | - $stmt->bindValue(':path', $path); |
|
429 | - $stmt->execute(); |
|
430 | - } |
|
431 | - |
|
432 | - public function publishDocumentByPath($path) |
|
433 | - { |
|
434 | - $this->publishOrUnpublishDocumentByPath($path); |
|
435 | - } |
|
436 | - |
|
437 | - public function unpublishDocumentByPath($path) |
|
438 | - { |
|
439 | - $this->publishOrUnpublishDocumentByPath($path, false); |
|
440 | - } |
|
441 | - |
|
442 | - public function cleanPublishedDeletedDocuments() |
|
443 | - { |
|
444 | - $sql = ' DELETE FROM documents_published |
|
420 | + } |
|
421 | + $db = $this->getContentDbHandle(); |
|
422 | + $stmt = $db->prepare($sql); |
|
423 | + if ($stmt === false) { |
|
424 | + $errorInfo = $db->errorInfo(); |
|
425 | + $errorMsg = $errorInfo[2]; |
|
426 | + throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
427 | + } |
|
428 | + $stmt->bindValue(':path', $path); |
|
429 | + $stmt->execute(); |
|
430 | + } |
|
431 | + |
|
432 | + public function publishDocumentByPath($path) |
|
433 | + { |
|
434 | + $this->publishOrUnpublishDocumentByPath($path); |
|
435 | + } |
|
436 | + |
|
437 | + public function unpublishDocumentByPath($path) |
|
438 | + { |
|
439 | + $this->publishOrUnpublishDocumentByPath($path, false); |
|
440 | + } |
|
441 | + |
|
442 | + public function cleanPublishedDeletedDocuments() |
|
443 | + { |
|
444 | + $sql = ' DELETE FROM documents_published |
|
445 | 445 | WHERE documents_published.path IN ( |
446 | 446 | SELECT documents_published.path |
447 | 447 | FROM documents_published |
@@ -449,11 +449,11 @@ discard block |
||
449 | 449 | ON documents_unpublished.path = documents_published.path |
450 | 450 | WHERE documents_unpublished.path IS NULL |
451 | 451 | )'; |
452 | - $stmt = $this->getDbStatement($sql); |
|
453 | - $stmt->execute(); |
|
454 | - } |
|
452 | + $stmt = $this->getDbStatement($sql); |
|
453 | + $stmt->execute(); |
|
454 | + } |
|
455 | 455 | |
456 | - /** |
|
456 | + /** |
|
457 | 457 | * Return the results of the query as array of Documents |
458 | 458 | * @param $sql |
459 | 459 | * @return array |
@@ -507,21 +507,21 @@ discard block |
||
507 | 507 | return $rootFolder; |
508 | 508 | } |
509 | 509 | |
510 | - /** |
|
511 | - * Save the document to the database |
|
512 | - * |
|
513 | - * @param Document $documentObject |
|
514 | - * @param string $state |
|
515 | - * |
|
516 | - * @return bool |
|
517 | - * @throws \Exception |
|
518 | - * @internal param $path |
|
519 | - */ |
|
510 | + /** |
|
511 | + * Save the document to the database |
|
512 | + * |
|
513 | + * @param Document $documentObject |
|
514 | + * @param string $state |
|
515 | + * |
|
516 | + * @return bool |
|
517 | + * @throws \Exception |
|
518 | + * @internal param $path |
|
519 | + */ |
|
520 | 520 | public function saveDocument($documentObject, $state = 'published') |
521 | 521 | { |
522 | - if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
523 | - throw new \Exception('Unsupported document state: ' . $state); |
|
524 | - } |
|
522 | + if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
523 | + throw new \Exception('Unsupported document state: ' . $state); |
|
524 | + } |
|
525 | 525 | $db = $this->getContentDbHandle(); |
526 | 526 | $stmt = $this->getDbStatement(' |
527 | 527 | INSERT OR REPLACE INTO documents_' . $state . ' (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
@@ -545,15 +545,15 @@ discard block |
||
545 | 545 | return $result; |
546 | 546 | } |
547 | 547 | |
548 | - /** |
|
549 | - * Delete the document from the database |
|
550 | - * If it's a folder, also delete it's contents |
|
551 | - * |
|
552 | - * @param $path |
|
553 | - * |
|
554 | - * @internal param string $state |
|
555 | - * |
|
556 | - */ |
|
548 | + /** |
|
549 | + * Delete the document from the database |
|
550 | + * If it's a folder, also delete it's contents |
|
551 | + * |
|
552 | + * @param $path |
|
553 | + * |
|
554 | + * @internal param string $state |
|
555 | + * |
|
556 | + */ |
|
557 | 557 | public function deleteDocumentByPath($path) |
558 | 558 | { |
559 | 559 | $db = $this->getContentDbHandle(); |
@@ -578,24 +578,24 @@ discard block |
||
578 | 578 | } |
579 | 579 | } |
580 | 580 | |
581 | - /** |
|
582 | - * @param $document |
|
583 | - * @param $db |
|
584 | - * @param $documents |
|
585 | - * @param $key |
|
586 | - * |
|
587 | - * @return mixed |
|
588 | - */ |
|
589 | - private function setAssetsToDocumentFolders($document, $db, $documents, $key) |
|
590 | - { |
|
591 | - if ($document->type === 'folder') { |
|
592 | - $document->dbHandle = $db; |
|
593 | - $document->documentStorage = new DocumentStorage($this); |
|
594 | - $documents[$key] = $document; |
|
595 | - } |
|
596 | - |
|
597 | - return $documents; |
|
598 | - } |
|
581 | + /** |
|
582 | + * @param $document |
|
583 | + * @param $db |
|
584 | + * @param $documents |
|
585 | + * @param $key |
|
586 | + * |
|
587 | + * @return mixed |
|
588 | + */ |
|
589 | + private function setAssetsToDocumentFolders($document, $db, $documents, $key) |
|
590 | + { |
|
591 | + if ($document->type === 'folder') { |
|
592 | + $document->dbHandle = $db; |
|
593 | + $document->documentStorage = new DocumentStorage($this); |
|
594 | + $documents[$key] = $document; |
|
595 | + } |
|
596 | + |
|
597 | + return $documents; |
|
598 | + } |
|
599 | 599 | |
600 | 600 | private function initConfigIfNotExists($json, $subsetName) |
601 | 601 | { |
@@ -150,9 +150,9 @@ discard block |
||
150 | 150 | { |
151 | 151 | $documentFolderObject = DocumentFolderFactory::createDocumentFolderFromPostValues($postValues); |
152 | 152 | if ($postValues['path'] === '/') { |
153 | - $documentFolderObject->path = $postValues['path'] . $documentFolderObject->slug; |
|
153 | + $documentFolderObject->path = $postValues['path'].$documentFolderObject->slug; |
|
154 | 154 | } else { |
155 | - $documentFolderObject->path = $postValues['path'] . '/' . $documentFolderObject->slug; |
|
155 | + $documentFolderObject->path = $postValues['path'].'/'.$documentFolderObject->slug; |
|
156 | 156 | } |
157 | 157 | $this->repository->saveDocument($documentFolderObject, 'published'); |
158 | 158 | $this->repository->saveDocument($documentFolderObject, 'unpublished'); |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | */ |
168 | 168 | public function deleteDocumentFolderBySlug($slug) |
169 | 169 | { |
170 | - $path = '/' . $slug; |
|
170 | + $path = '/'.$slug; |
|
171 | 171 | $this->repository->deleteDocumentByPath($path, 'published'); |
172 | 172 | $this->repository->deleteDocumentByPath($path, 'unpublished'); |
173 | 173 | $this->repository->cleanPublishedDeletedDocuments(); |
@@ -175,13 +175,13 @@ discard block |
||
175 | 175 | |
176 | 176 | public function publishDocumentBySlug($slug) |
177 | 177 | { |
178 | - $path = '/' . $slug; |
|
178 | + $path = '/'.$slug; |
|
179 | 179 | $this->repository->publishDocumentByPath($path); |
180 | 180 | } |
181 | 181 | |
182 | 182 | public function unpublishDocumentBySlug($slug) |
183 | 183 | { |
184 | - $path = '/' . $slug; |
|
184 | + $path = '/'.$slug; |
|
185 | 185 | $this->repository->unpublishDocumentByPath($path); |
186 | 186 | } |
187 | 187 | |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | */ |
196 | 196 | public function getDocumentFolderBySlug($slug) |
197 | 197 | { |
198 | - $path = '/' . $slug; |
|
198 | + $path = '/'.$slug; |
|
199 | 199 | |
200 | 200 | return $this->repository->getDocumentByPath($path); |
201 | 201 | } |
@@ -15,52 +15,52 @@ discard block |
||
15 | 15 | use CloudControl\Cms\storage\storage\ValuelistsStorage; |
16 | 16 | |
17 | 17 | /** |
18 | - * Class JsonStorage |
|
18 | + * Class JsonStorage |
|
19 | 19 | * @package CloudControl\Cms\storage |
20 | - */ |
|
21 | - class Storage |
|
22 | - { |
|
23 | - /** |
|
24 | - * @var SitemapStorage |
|
25 | - */ |
|
26 | - protected $sitemap; |
|
27 | - /** |
|
28 | - * @var ImagesStorage |
|
29 | - */ |
|
30 | - protected $images; |
|
31 | - /** |
|
32 | - * @var ImageSetStorage |
|
33 | - */ |
|
34 | - protected $imageSet; |
|
35 | - /** |
|
36 | - * @var FilesStorage |
|
37 | - */ |
|
38 | - protected $files; |
|
39 | - /** |
|
40 | - * @var UsersStorage |
|
41 | - */ |
|
42 | - protected $users; |
|
43 | - /** |
|
44 | - * @var DocumentTypesStorage |
|
45 | - */ |
|
46 | - protected $documentTypes; |
|
47 | - /** |
|
48 | - * @var BricksStorage |
|
49 | - */ |
|
50 | - protected $bricks; |
|
51 | - /** |
|
52 | - * @var ApplicationComponentsStorage |
|
53 | - */ |
|
54 | - protected $applicationComponents; |
|
20 | + */ |
|
21 | + class Storage |
|
22 | + { |
|
23 | + /** |
|
24 | + * @var SitemapStorage |
|
25 | + */ |
|
26 | + protected $sitemap; |
|
27 | + /** |
|
28 | + * @var ImagesStorage |
|
29 | + */ |
|
30 | + protected $images; |
|
31 | + /** |
|
32 | + * @var ImageSetStorage |
|
33 | + */ |
|
34 | + protected $imageSet; |
|
35 | + /** |
|
36 | + * @var FilesStorage |
|
37 | + */ |
|
38 | + protected $files; |
|
39 | + /** |
|
40 | + * @var UsersStorage |
|
41 | + */ |
|
42 | + protected $users; |
|
43 | + /** |
|
44 | + * @var DocumentTypesStorage |
|
45 | + */ |
|
46 | + protected $documentTypes; |
|
47 | + /** |
|
48 | + * @var BricksStorage |
|
49 | + */ |
|
50 | + protected $bricks; |
|
51 | + /** |
|
52 | + * @var ApplicationComponentsStorage |
|
53 | + */ |
|
54 | + protected $applicationComponents; |
|
55 | 55 | |
56 | - /** |
|
57 | - * @var ValuelistsStorage |
|
58 | - */ |
|
59 | - protected $valuelists; |
|
60 | - /** |
|
61 | - * @var DocumentStorage |
|
62 | - */ |
|
63 | - protected $documents; |
|
56 | + /** |
|
57 | + * @var ValuelistsStorage |
|
58 | + */ |
|
59 | + protected $valuelists; |
|
60 | + /** |
|
61 | + * @var DocumentStorage |
|
62 | + */ |
|
63 | + protected $documents; |
|
64 | 64 | /** |
65 | 65 | * @var RedirectsStorage |
66 | 66 | */ |
@@ -75,13 +75,13 @@ discard block |
||
75 | 75 | protected $filesDir; |
76 | 76 | |
77 | 77 | /** |
78 | - * @var String |
|
79 | - */ |
|
80 | - private $storageDir; |
|
81 | - /** |
|
82 | - * @var Repository |
|
83 | - */ |
|
84 | - private $repository; |
|
78 | + * @var String |
|
79 | + */ |
|
80 | + private $storageDir; |
|
81 | + /** |
|
82 | + * @var Repository |
|
83 | + */ |
|
84 | + private $repository; |
|
85 | 85 | |
86 | 86 | /** |
87 | 87 | * JsonStorage constructor. |
@@ -91,245 +91,245 @@ discard block |
||
91 | 91 | * @param $filesDir |
92 | 92 | */ |
93 | 93 | public function __construct($storageDir, $imagesDir, $filesDir) |
94 | - { |
|
95 | - $this->storageDir = $storageDir; |
|
94 | + { |
|
95 | + $this->storageDir = $storageDir; |
|
96 | 96 | $this->imagesDir = $imagesDir; |
97 | 97 | $this->filesDir = $filesDir; |
98 | - $this->config(); |
|
99 | - } |
|
98 | + $this->config(); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Retrieve the data from the storagepath |
|
103 | - * so it can be interacted with |
|
104 | - * |
|
105 | - * @throws \Exception |
|
106 | - */ |
|
107 | - private function config() |
|
108 | - { |
|
109 | - $storagePath = $this->storageDir; |
|
110 | - if (realpath($storagePath) === false) { |
|
111 | - throw new \Exception('Storage doesnt seem to be initialized, consider running composer install to do so.'); |
|
112 | - } else { |
|
113 | - $this->repository = new Repository($storagePath); |
|
114 | - } |
|
101 | + /** |
|
102 | + * Retrieve the data from the storagepath |
|
103 | + * so it can be interacted with |
|
104 | + * |
|
105 | + * @throws \Exception |
|
106 | + */ |
|
107 | + private function config() |
|
108 | + { |
|
109 | + $storagePath = $this->storageDir; |
|
110 | + if (realpath($storagePath) === false) { |
|
111 | + throw new \Exception('Storage doesnt seem to be initialized, consider running composer install to do so.'); |
|
112 | + } else { |
|
113 | + $this->repository = new Repository($storagePath); |
|
114 | + } |
|
115 | 115 | |
116 | - } |
|
116 | + } |
|
117 | 117 | |
118 | - /** |
|
119 | - * @return \CloudControl\Cms\storage\storage\UsersStorage |
|
120 | - */ |
|
121 | - public function getUsers() |
|
122 | - { |
|
123 | - if (!$this->users instanceof UsersStorage) { |
|
124 | - $this->users = new UsersStorage($this->repository); |
|
125 | - } |
|
126 | - return $this->users; |
|
127 | - } |
|
118 | + /** |
|
119 | + * @return \CloudControl\Cms\storage\storage\UsersStorage |
|
120 | + */ |
|
121 | + public function getUsers() |
|
122 | + { |
|
123 | + if (!$this->users instanceof UsersStorage) { |
|
124 | + $this->users = new UsersStorage($this->repository); |
|
125 | + } |
|
126 | + return $this->users; |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * Get documents |
|
131 | - * |
|
132 | - * @return DocumentStorage |
|
133 | - */ |
|
134 | - public function getDocuments() |
|
135 | - { |
|
136 | - if (!$this->documents instanceof DocumentStorage) { |
|
137 | - $this->documents = new DocumentStorage($this->repository); |
|
138 | - } |
|
139 | - return $this->documents; |
|
140 | - } |
|
129 | + /** |
|
130 | + * Get documents |
|
131 | + * |
|
132 | + * @return DocumentStorage |
|
133 | + */ |
|
134 | + public function getDocuments() |
|
135 | + { |
|
136 | + if (!$this->documents instanceof DocumentStorage) { |
|
137 | + $this->documents = new DocumentStorage($this->repository); |
|
138 | + } |
|
139 | + return $this->documents; |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * Add new document in given path |
|
144 | - * |
|
145 | - * @param array $postValues |
|
146 | - * |
|
147 | - * @throws \Exception |
|
148 | - */ |
|
149 | - public function addDocumentFolder($postValues) |
|
150 | - { |
|
151 | - $documentFolderObject = DocumentFolderFactory::createDocumentFolderFromPostValues($postValues); |
|
152 | - if ($postValues['path'] === '/') { |
|
153 | - $documentFolderObject->path = $postValues['path'] . $documentFolderObject->slug; |
|
154 | - } else { |
|
155 | - $documentFolderObject->path = $postValues['path'] . '/' . $documentFolderObject->slug; |
|
156 | - } |
|
157 | - $this->repository->saveDocument($documentFolderObject, 'published'); |
|
158 | - $this->repository->saveDocument($documentFolderObject, 'unpublished'); |
|
159 | - } |
|
142 | + /** |
|
143 | + * Add new document in given path |
|
144 | + * |
|
145 | + * @param array $postValues |
|
146 | + * |
|
147 | + * @throws \Exception |
|
148 | + */ |
|
149 | + public function addDocumentFolder($postValues) |
|
150 | + { |
|
151 | + $documentFolderObject = DocumentFolderFactory::createDocumentFolderFromPostValues($postValues); |
|
152 | + if ($postValues['path'] === '/') { |
|
153 | + $documentFolderObject->path = $postValues['path'] . $documentFolderObject->slug; |
|
154 | + } else { |
|
155 | + $documentFolderObject->path = $postValues['path'] . '/' . $documentFolderObject->slug; |
|
156 | + } |
|
157 | + $this->repository->saveDocument($documentFolderObject, 'published'); |
|
158 | + $this->repository->saveDocument($documentFolderObject, 'unpublished'); |
|
159 | + } |
|
160 | 160 | |
161 | - /** |
|
162 | - * Delete a folder by its compound slug |
|
163 | - * |
|
164 | - * @param $slug |
|
165 | - * |
|
166 | - * @throws \Exception |
|
167 | - */ |
|
168 | - public function deleteDocumentFolderBySlug($slug) |
|
169 | - { |
|
170 | - $path = '/' . $slug; |
|
171 | - $this->repository->deleteDocumentByPath($path, 'published'); |
|
172 | - $this->repository->deleteDocumentByPath($path, 'unpublished'); |
|
173 | - $this->repository->cleanPublishedDeletedDocuments(); |
|
174 | - } |
|
161 | + /** |
|
162 | + * Delete a folder by its compound slug |
|
163 | + * |
|
164 | + * @param $slug |
|
165 | + * |
|
166 | + * @throws \Exception |
|
167 | + */ |
|
168 | + public function deleteDocumentFolderBySlug($slug) |
|
169 | + { |
|
170 | + $path = '/' . $slug; |
|
171 | + $this->repository->deleteDocumentByPath($path, 'published'); |
|
172 | + $this->repository->deleteDocumentByPath($path, 'unpublished'); |
|
173 | + $this->repository->cleanPublishedDeletedDocuments(); |
|
174 | + } |
|
175 | 175 | |
176 | - public function publishDocumentBySlug($slug) |
|
177 | - { |
|
178 | - $path = '/' . $slug; |
|
179 | - $this->repository->publishDocumentByPath($path); |
|
180 | - } |
|
176 | + public function publishDocumentBySlug($slug) |
|
177 | + { |
|
178 | + $path = '/' . $slug; |
|
179 | + $this->repository->publishDocumentByPath($path); |
|
180 | + } |
|
181 | 181 | |
182 | - public function unpublishDocumentBySlug($slug) |
|
183 | - { |
|
184 | - $path = '/' . $slug; |
|
185 | - $this->repository->unpublishDocumentByPath($path); |
|
186 | - } |
|
182 | + public function unpublishDocumentBySlug($slug) |
|
183 | + { |
|
184 | + $path = '/' . $slug; |
|
185 | + $this->repository->unpublishDocumentByPath($path); |
|
186 | + } |
|
187 | 187 | |
188 | - /** |
|
189 | - * Retrieve a folder by its compound slug |
|
190 | - * |
|
191 | - * @param $slug |
|
192 | - * |
|
193 | - * @return mixed |
|
194 | - * @throws \Exception |
|
195 | - */ |
|
196 | - public function getDocumentFolderBySlug($slug) |
|
197 | - { |
|
198 | - $path = '/' . $slug; |
|
188 | + /** |
|
189 | + * Retrieve a folder by its compound slug |
|
190 | + * |
|
191 | + * @param $slug |
|
192 | + * |
|
193 | + * @return mixed |
|
194 | + * @throws \Exception |
|
195 | + */ |
|
196 | + public function getDocumentFolderBySlug($slug) |
|
197 | + { |
|
198 | + $path = '/' . $slug; |
|
199 | 199 | |
200 | - return $this->repository->getDocumentByPath($path); |
|
201 | - } |
|
200 | + return $this->repository->getDocumentByPath($path); |
|
201 | + } |
|
202 | 202 | |
203 | - /** |
|
204 | - * Save changes to folder |
|
205 | - * |
|
206 | - * @param $postValues |
|
207 | - * |
|
208 | - * @throws \Exception |
|
209 | - */ |
|
210 | - public function saveDocumentFolder($postValues) |
|
211 | - { |
|
212 | - $this->addDocumentFolder($postValues); |
|
213 | - } |
|
203 | + /** |
|
204 | + * Save changes to folder |
|
205 | + * |
|
206 | + * @param $postValues |
|
207 | + * |
|
208 | + * @throws \Exception |
|
209 | + */ |
|
210 | + public function saveDocumentFolder($postValues) |
|
211 | + { |
|
212 | + $this->addDocumentFolder($postValues); |
|
213 | + } |
|
214 | 214 | |
215 | - /** |
|
216 | - * @return SitemapStorage |
|
217 | - */ |
|
218 | - public function getSitemap() |
|
219 | - { |
|
220 | - if (!$this->sitemap instanceof SitemapStorage) { |
|
221 | - $this->sitemap = new SitemapStorage($this->repository); |
|
222 | - } |
|
223 | - return $this->sitemap; |
|
224 | - } |
|
215 | + /** |
|
216 | + * @return SitemapStorage |
|
217 | + */ |
|
218 | + public function getSitemap() |
|
219 | + { |
|
220 | + if (!$this->sitemap instanceof SitemapStorage) { |
|
221 | + $this->sitemap = new SitemapStorage($this->repository); |
|
222 | + } |
|
223 | + return $this->sitemap; |
|
224 | + } |
|
225 | 225 | |
226 | - /** |
|
227 | - * Get all images |
|
228 | - * |
|
229 | - * @return ImagesStorage |
|
230 | - */ |
|
231 | - public function getImages() |
|
232 | - { |
|
233 | - if (!$this->images instanceof ImagesStorage) { |
|
226 | + /** |
|
227 | + * Get all images |
|
228 | + * |
|
229 | + * @return ImagesStorage |
|
230 | + */ |
|
231 | + public function getImages() |
|
232 | + { |
|
233 | + if (!$this->images instanceof ImagesStorage) { |
|
234 | 234 | |
235 | 235 | $this->images = new ImagesStorage($this->repository, $this->imagesDir); |
236 | - } |
|
237 | - return $this->images; |
|
238 | - } |
|
236 | + } |
|
237 | + return $this->images; |
|
238 | + } |
|
239 | 239 | |
240 | - /** |
|
241 | - * Get all files |
|
242 | - * |
|
243 | - * @return FilesStorage |
|
244 | - */ |
|
245 | - public function getFiles() |
|
246 | - { |
|
247 | - if (!$this->files instanceof FilesStorage) { |
|
248 | - $this->files = new FilesStorage($this->repository, $this->filesDir); |
|
249 | - } |
|
250 | - return $this->files; |
|
251 | - } |
|
240 | + /** |
|
241 | + * Get all files |
|
242 | + * |
|
243 | + * @return FilesStorage |
|
244 | + */ |
|
245 | + public function getFiles() |
|
246 | + { |
|
247 | + if (!$this->files instanceof FilesStorage) { |
|
248 | + $this->files = new FilesStorage($this->repository, $this->filesDir); |
|
249 | + } |
|
250 | + return $this->files; |
|
251 | + } |
|
252 | 252 | |
253 | - /** |
|
254 | - * @return string |
|
255 | - */ |
|
256 | - public function getStorageDir() |
|
257 | - { |
|
258 | - return $this->storageDir; |
|
259 | - } |
|
253 | + /** |
|
254 | + * @return string |
|
255 | + */ |
|
256 | + public function getStorageDir() |
|
257 | + { |
|
258 | + return $this->storageDir; |
|
259 | + } |
|
260 | 260 | |
261 | - /** |
|
262 | - * @return \PDO |
|
263 | - */ |
|
264 | - public function getContentDbHandle() |
|
265 | - { |
|
266 | - return $this->repository->getContentDbHandle(); |
|
267 | - } |
|
261 | + /** |
|
262 | + * @return \PDO |
|
263 | + */ |
|
264 | + public function getContentDbHandle() |
|
265 | + { |
|
266 | + return $this->repository->getContentDbHandle(); |
|
267 | + } |
|
268 | 268 | |
269 | - /** |
|
270 | - * @return DocumentTypesStorage |
|
271 | - */ |
|
272 | - public function getDocumentTypes() |
|
273 | - { |
|
274 | - if (!$this->documentTypes instanceof DocumentTypesStorage) { |
|
275 | - $this->documentTypes = new DocumentTypesStorage($this->repository); |
|
276 | - } |
|
277 | - return $this->documentTypes; |
|
278 | - } |
|
269 | + /** |
|
270 | + * @return DocumentTypesStorage |
|
271 | + */ |
|
272 | + public function getDocumentTypes() |
|
273 | + { |
|
274 | + if (!$this->documentTypes instanceof DocumentTypesStorage) { |
|
275 | + $this->documentTypes = new DocumentTypesStorage($this->repository); |
|
276 | + } |
|
277 | + return $this->documentTypes; |
|
278 | + } |
|
279 | 279 | |
280 | - /** |
|
281 | - * @return BricksStorage |
|
282 | - */ |
|
283 | - public function getBricks() |
|
284 | - { |
|
285 | - if (!$this->bricks instanceof BricksStorage) { |
|
286 | - $this->bricks = new BricksStorage($this->repository); |
|
287 | - } |
|
288 | - return $this->bricks; |
|
289 | - } |
|
280 | + /** |
|
281 | + * @return BricksStorage |
|
282 | + */ |
|
283 | + public function getBricks() |
|
284 | + { |
|
285 | + if (!$this->bricks instanceof BricksStorage) { |
|
286 | + $this->bricks = new BricksStorage($this->repository); |
|
287 | + } |
|
288 | + return $this->bricks; |
|
289 | + } |
|
290 | 290 | |
291 | - /** |
|
292 | - * Get the image set |
|
293 | - * |
|
294 | - * @return ImageSetStorage |
|
295 | - */ |
|
296 | - public function getImageSet() |
|
297 | - { |
|
298 | - if (!$this->imageSet instanceof ImageSetStorage) { |
|
299 | - $this->imageSet = new ImageSetStorage($this->repository); |
|
300 | - } |
|
301 | - return $this->imageSet; |
|
302 | - } |
|
291 | + /** |
|
292 | + * Get the image set |
|
293 | + * |
|
294 | + * @return ImageSetStorage |
|
295 | + */ |
|
296 | + public function getImageSet() |
|
297 | + { |
|
298 | + if (!$this->imageSet instanceof ImageSetStorage) { |
|
299 | + $this->imageSet = new ImageSetStorage($this->repository); |
|
300 | + } |
|
301 | + return $this->imageSet; |
|
302 | + } |
|
303 | 303 | |
304 | - /** |
|
305 | - * @return ApplicationComponentsStorage |
|
306 | - */ |
|
307 | - public function getApplicationComponents() |
|
308 | - { |
|
309 | - if (!$this->applicationComponents instanceof ApplicationComponentsStorage) { |
|
310 | - $this->applicationComponents = new ApplicationComponentsStorage($this->repository); |
|
311 | - } |
|
312 | - return $this->applicationComponents; |
|
313 | - } |
|
304 | + /** |
|
305 | + * @return ApplicationComponentsStorage |
|
306 | + */ |
|
307 | + public function getApplicationComponents() |
|
308 | + { |
|
309 | + if (!$this->applicationComponents instanceof ApplicationComponentsStorage) { |
|
310 | + $this->applicationComponents = new ApplicationComponentsStorage($this->repository); |
|
311 | + } |
|
312 | + return $this->applicationComponents; |
|
313 | + } |
|
314 | 314 | |
315 | - /** |
|
316 | - * @return \CloudControl\Cms\storage\Repository |
|
317 | - */ |
|
318 | - public function getRepository() |
|
319 | - { |
|
320 | - return $this->repository; |
|
321 | - } |
|
315 | + /** |
|
316 | + * @return \CloudControl\Cms\storage\Repository |
|
317 | + */ |
|
318 | + public function getRepository() |
|
319 | + { |
|
320 | + return $this->repository; |
|
321 | + } |
|
322 | 322 | |
323 | - /** |
|
324 | - * @return \CloudControl\Cms\storage\storage\ValuelistsStorage |
|
325 | - */ |
|
326 | - public function getValuelists() |
|
327 | - { |
|
328 | - if (!$this->valuelists instanceof ValuelistsStorage) { |
|
329 | - $this->valuelists = new ValuelistsStorage($this->repository); |
|
330 | - } |
|
331 | - return $this->valuelists; |
|
332 | - } |
|
323 | + /** |
|
324 | + * @return \CloudControl\Cms\storage\storage\ValuelistsStorage |
|
325 | + */ |
|
326 | + public function getValuelists() |
|
327 | + { |
|
328 | + if (!$this->valuelists instanceof ValuelistsStorage) { |
|
329 | + $this->valuelists = new ValuelistsStorage($this->repository); |
|
330 | + } |
|
331 | + return $this->valuelists; |
|
332 | + } |
|
333 | 333 | |
334 | 334 | /** |
335 | 335 | * @return \CloudControl\Cms\storage\storage\RedirectsStorage |
@@ -342,5 +342,5 @@ discard block |
||
342 | 342 | return $this->redirects; |
343 | 343 | } |
344 | 344 | |
345 | - } |
|
345 | + } |
|
346 | 346 | } |
347 | 347 | \ No newline at end of file |