@@ -109,8 +109,8 @@ |
||
109 | 109 | |
110 | 110 | // Preserve transparency |
111 | 111 | imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127)); |
112 | - imagealphablending($new, false); |
|
113 | - imagesavealpha($new, true); |
|
112 | + imagealphablending($new, false); |
|
113 | + imagesavealpha($new, true); |
|
114 | 114 | |
115 | 115 | imagecopyresampled($new, $imageResource, $this->_destX, $this->_destY, $this->_x, $this->_y, $this->_destWidth, $this->_destHeight, $this->_destWidth, $this->_destHeight); |
116 | 116 |
@@ -62,8 +62,8 @@ |
||
62 | 62 | |
63 | 63 | // Preserve transparency |
64 | 64 | imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127)); |
65 | - imagealphablending($new, false); |
|
66 | - imagesavealpha($new, true); |
|
65 | + imagealphablending($new, false); |
|
66 | + imagesavealpha($new, true); |
|
67 | 67 | |
68 | 68 | imagecopyresampled($new, $imageResource, $this->_destX, $this->_destY, $this->_x, $this->_y, $this->_destWidth, $this->_destHeight, $originalWidth, $originalHeight); |
69 | 69 |
@@ -17,7 +17,7 @@ |
||
17 | 17 | /** |
18 | 18 | * @param resource $imageResource |
19 | 19 | * @return resource |
20 | - */ |
|
20 | + */ |
|
21 | 21 | public function Execute($imageResource) |
22 | 22 | { |
23 | 23 | // Define the origial width and height |
@@ -31,11 +31,11 @@ discard block |
||
31 | 31 | */ |
32 | 32 | function shutdownHandler () { |
33 | 33 | $error = error_get_last(); |
34 | - if (isset($error['type'], $error['message'], $error['file'], $error['line'])) { |
|
35 | - errorHandler($error['type'],$error['message'],$error['file'],$error['line']); |
|
36 | - }elseif ($error['type'] == 1) { |
|
37 | - dump($error); |
|
38 | - } |
|
34 | + if (isset($error['type'], $error['message'], $error['file'], $error['line'])) { |
|
35 | + errorHandler($error['type'],$error['message'],$error['file'],$error['line']); |
|
36 | + }elseif ($error['type'] == 1) { |
|
37 | + dump($error); |
|
38 | + } |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -49,28 +49,28 @@ discard block |
||
49 | 49 | $jsonErrorNr = json_last_error(); |
50 | 50 | $errstr = ''; |
51 | 51 | switch ($jsonErrorNr) { |
52 | - case JSON_ERROR_NONE: |
|
53 | - $errstr .= ' - No errors' . PHP_EOL; |
|
54 | - break; |
|
55 | - case JSON_ERROR_DEPTH: |
|
56 | - $errstr .= ' - Maximum stack depth exceeded' . PHP_EOL; |
|
57 | - break; |
|
58 | - case JSON_ERROR_STATE_MISMATCH: |
|
59 | - $errstr .= ' - Underflow or the modes mismatch' . PHP_EOL; |
|
60 | - break; |
|
61 | - case JSON_ERROR_CTRL_CHAR: |
|
62 | - $errstr .= ' - Unexpected control character found' . PHP_EOL; |
|
63 | - break; |
|
64 | - case JSON_ERROR_SYNTAX: |
|
65 | - $errstr .= ' - Syntax error, malformed JSON' . PHP_EOL; |
|
66 | - break; |
|
67 | - case JSON_ERROR_UTF8: |
|
68 | - $errstr .= ' - Malformed UTF-8 characters, possibly incorrectly encoded' . PHP_EOL; |
|
69 | - break; |
|
70 | - default: |
|
71 | - $errstr = ' - Unknown error' . PHP_EOL; |
|
72 | - break; |
|
73 | - } |
|
52 | + case JSON_ERROR_NONE: |
|
53 | + $errstr .= ' - No errors' . PHP_EOL; |
|
54 | + break; |
|
55 | + case JSON_ERROR_DEPTH: |
|
56 | + $errstr .= ' - Maximum stack depth exceeded' . PHP_EOL; |
|
57 | + break; |
|
58 | + case JSON_ERROR_STATE_MISMATCH: |
|
59 | + $errstr .= ' - Underflow or the modes mismatch' . PHP_EOL; |
|
60 | + break; |
|
61 | + case JSON_ERROR_CTRL_CHAR: |
|
62 | + $errstr .= ' - Unexpected control character found' . PHP_EOL; |
|
63 | + break; |
|
64 | + case JSON_ERROR_SYNTAX: |
|
65 | + $errstr .= ' - Syntax error, malformed JSON' . PHP_EOL; |
|
66 | + break; |
|
67 | + case JSON_ERROR_UTF8: |
|
68 | + $errstr .= ' - Malformed UTF-8 characters, possibly incorrectly encoded' . PHP_EOL; |
|
69 | + break; |
|
70 | + default: |
|
71 | + $errstr = ' - Unknown error' . PHP_EOL; |
|
72 | + break; |
|
73 | + } |
|
74 | 74 | errorHandler ($jsonErrorNr, $errstr, $file, $line); |
75 | 75 | } |
76 | 76 | |
@@ -85,102 +85,102 @@ discard block |
||
85 | 85 | * @param string $httpHeader |
86 | 86 | */ |
87 | 87 | function renderError ($message='', $file='', $line='', $code=0, $trace=array(), $httpHeader = 'HTTP/1.0 500 Internal Server Error') { |
88 | - if (ob_get_contents()) ob_end_clean(); |
|
88 | + if (ob_get_contents()) ob_end_clean(); |
|
89 | 89 | |
90 | - if (canShowError()) { |
|
91 | - $file_lines = file_exists($file) ? file($file) : array(); |
|
92 | - $range = ($line - 15) < 0 ? range(1, 30) : range($line - 15, $line + 15); |
|
93 | - $lines = array(); |
|
90 | + if (canShowError()) { |
|
91 | + $file_lines = file_exists($file) ? file($file) : array(); |
|
92 | + $range = ($line - 15) < 0 ? range(1, 30) : range($line - 15, $line + 15); |
|
93 | + $lines = array(); |
|
94 | 94 | |
95 | - foreach ($range as $line_number) { |
|
96 | - if(isset($file_lines[$line_number-1])) { |
|
97 | - $lines[$line_number] = $file_lines[$line_number-1]; |
|
98 | - } |
|
99 | - } |
|
95 | + foreach ($range as $line_number) { |
|
96 | + if(isset($file_lines[$line_number-1])) { |
|
97 | + $lines[$line_number] = $file_lines[$line_number-1]; |
|
98 | + } |
|
99 | + } |
|
100 | 100 | |
101 | - $error = array( |
|
102 | - 'message' => $message, |
|
103 | - 'file' => $file, |
|
104 | - 'line' => $line, |
|
105 | - 'code' => $code, |
|
106 | - 'lines' => $lines, |
|
107 | - 'trace' => $trace, |
|
108 | - 'httpHeader' => $httpHeader, |
|
109 | - ); |
|
101 | + $error = array( |
|
102 | + 'message' => $message, |
|
103 | + 'file' => $file, |
|
104 | + 'line' => $line, |
|
105 | + 'code' => $code, |
|
106 | + 'lines' => $lines, |
|
107 | + 'trace' => $trace, |
|
108 | + 'httpHeader' => $httpHeader, |
|
109 | + ); |
|
110 | 110 | |
111 | - if (PHP_SAPI === 'cli') { |
|
112 | - renderCliException($message, $file, $line, $code, $trace, $lines); |
|
113 | - } |
|
111 | + if (PHP_SAPI === 'cli') { |
|
112 | + renderCliException($message, $file, $line, $code, $trace, $lines); |
|
113 | + } |
|
114 | 114 | |
115 | - if (file_exists(realpath(__DIR__) . '/errorviewdetailed.php')) { |
|
116 | - include(realpath(__DIR__) . '/errorviewdetailed.php'); |
|
117 | - } else { |
|
118 | - header('Content-type: application/json'); |
|
119 | - die(json_encode($error)); |
|
120 | - } |
|
121 | - exit; |
|
122 | - } else { |
|
123 | - header($_SERVER['SERVER_PROTOCOL'] . $httpHeader, true); |
|
124 | - header('X-Error-Message: ' . $message); |
|
125 | - header('X-Error-File: ' . $file); |
|
126 | - header('X-Error-Line: ' . $line); |
|
127 | - if (file_exists(realpath(__DIR__) . '/errorviewcompact.php')) { |
|
128 | - include(realpath(__DIR__) . '/errorviewcompact.php'); |
|
129 | - } else { |
|
130 | - header('Content-type: application/json'); |
|
131 | - die(json_encode('An error occured.')); |
|
132 | - } |
|
133 | - } |
|
115 | + if (file_exists(realpath(__DIR__) . '/errorviewdetailed.php')) { |
|
116 | + include(realpath(__DIR__) . '/errorviewdetailed.php'); |
|
117 | + } else { |
|
118 | + header('Content-type: application/json'); |
|
119 | + die(json_encode($error)); |
|
120 | + } |
|
121 | + exit; |
|
122 | + } else { |
|
123 | + header($_SERVER['SERVER_PROTOCOL'] . $httpHeader, true); |
|
124 | + header('X-Error-Message: ' . $message); |
|
125 | + header('X-Error-File: ' . $file); |
|
126 | + header('X-Error-Line: ' . $line); |
|
127 | + if (file_exists(realpath(__DIR__) . '/errorviewcompact.php')) { |
|
128 | + include(realpath(__DIR__) . '/errorviewcompact.php'); |
|
129 | + } else { |
|
130 | + header('Content-type: application/json'); |
|
131 | + die(json_encode('An error occured.')); |
|
132 | + } |
|
133 | + } |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | function canShowError() |
137 | 137 | { |
138 | - if (PHP_SAPI === 'cli') { |
|
139 | - return true; |
|
140 | - } |
|
141 | - if (file_exists('../config.json') && !isset($_SESSION['cloudcontrol'])) { |
|
142 | - $config = file_get_contents('../config.json'); |
|
143 | - $config = json_decode($config); |
|
144 | - if (isset($config->showErrorsToAll)) { |
|
145 | - return $config->showErrorsToAll; |
|
146 | - } |
|
147 | - } else { |
|
148 | - return true; |
|
149 | - } |
|
138 | + if (PHP_SAPI === 'cli') { |
|
139 | + return true; |
|
140 | + } |
|
141 | + if (file_exists('../config.json') && !isset($_SESSION['cloudcontrol'])) { |
|
142 | + $config = file_get_contents('../config.json'); |
|
143 | + $config = json_decode($config); |
|
144 | + if (isset($config->showErrorsToAll)) { |
|
145 | + return $config->showErrorsToAll; |
|
146 | + } |
|
147 | + } else { |
|
148 | + return true; |
|
149 | + } |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | function renderCliException($message, $file, $line, $code, $trace, $lines) |
153 | 153 | { |
154 | - echo PHP_EOL; |
|
155 | - echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
156 | - echo '| THE FOLLOWING ERROR OCCURED |' . PHP_EOL; |
|
157 | - echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
158 | - echo PHP_EOL; |
|
159 | - echo ' ' . $message . PHP_EOL; |
|
160 | - echo PHP_EOL; |
|
161 | - echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
162 | - echo '| IN FILE |' . PHP_EOL; |
|
163 | - echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
164 | - echo PHP_EOL; |
|
165 | - echo ' ' . $file . ':' . $line . PHP_EOL; |
|
166 | - echo PHP_EOL; |
|
167 | - echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
168 | - echo '| CONTENTS OF THE FILE |' . PHP_EOL; |
|
169 | - echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
170 | - echo PHP_EOL; |
|
171 | - foreach($lines as $nr => $currentLine) { |
|
172 | - echo ($nr == $line ? '* ' : ' ' ) . str_pad($nr, 3, "0", STR_PAD_LEFT) . ' ' . $currentLine; |
|
173 | - } |
|
174 | - echo PHP_EOL; |
|
175 | - echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
176 | - echo '| STACK TRACE |' . PHP_EOL; |
|
177 | - echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
178 | - foreach($trace as $row) { |
|
179 | - echo (isset($row['file']) ? basename($row['file']) : '') . ':' |
|
180 | - . (isset($row['line']) ? $row['line'] : '') . "\t\t\t" |
|
181 | - . (isset($row['class']) ? $row['class'] : ' ') . "\t\t\t" |
|
182 | - . (isset($row['type']) ? $row['type'] : ' ') . "\t\t\t" |
|
183 | - . (isset($row['function']) ? $row['function'] : ' ') . PHP_EOL; |
|
184 | - } |
|
185 | - exit; |
|
154 | + echo PHP_EOL; |
|
155 | + echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
156 | + echo '| THE FOLLOWING ERROR OCCURED |' . PHP_EOL; |
|
157 | + echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
158 | + echo PHP_EOL; |
|
159 | + echo ' ' . $message . PHP_EOL; |
|
160 | + echo PHP_EOL; |
|
161 | + echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
162 | + echo '| IN FILE |' . PHP_EOL; |
|
163 | + echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
164 | + echo PHP_EOL; |
|
165 | + echo ' ' . $file . ':' . $line . PHP_EOL; |
|
166 | + echo PHP_EOL; |
|
167 | + echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
168 | + echo '| CONTENTS OF THE FILE |' . PHP_EOL; |
|
169 | + echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
170 | + echo PHP_EOL; |
|
171 | + foreach($lines as $nr => $currentLine) { |
|
172 | + echo ($nr == $line ? '* ' : ' ' ) . str_pad($nr, 3, "0", STR_PAD_LEFT) . ' ' . $currentLine; |
|
173 | + } |
|
174 | + echo PHP_EOL; |
|
175 | + echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
176 | + echo '| STACK TRACE |' . PHP_EOL; |
|
177 | + echo '------------------------------------------------------------------------------------------------------------------------------------------------' . PHP_EOL; |
|
178 | + foreach($trace as $row) { |
|
179 | + echo (isset($row['file']) ? basename($row['file']) : '') . ':' |
|
180 | + . (isset($row['line']) ? $row['line'] : '') . "\t\t\t" |
|
181 | + . (isset($row['class']) ? $row['class'] : ' ') . "\t\t\t" |
|
182 | + . (isset($row['type']) ? $row['type'] : ' ') . "\t\t\t" |
|
183 | + . (isset($row['function']) ? $row['function'] : ' ') . PHP_EOL; |
|
184 | + } |
|
185 | + exit; |
|
186 | 186 | } |
187 | 187 | \ No newline at end of file |
@@ -7,124 +7,124 @@ |
||
7 | 7 | |
8 | 8 | class LanguageComponent implements Component |
9 | 9 | { |
10 | - protected $request; |
|
11 | - protected $parameters; |
|
12 | - |
|
13 | - protected $defaultLanguage = 'en'; |
|
14 | - protected $acceptedLanguages = null; |
|
15 | - protected $languageParameterName = 'language'; |
|
16 | - protected $forceRedirect = false; |
|
17 | - protected $sessionValues; |
|
18 | - |
|
19 | - /** |
|
20 | - * Component constructor. |
|
21 | - * |
|
22 | - * @param $template |
|
23 | - * @param Request $request |
|
24 | - * @param $parameters |
|
25 | - * @param $matchedSitemapItem |
|
26 | - */ |
|
27 | - public function __construct($template, Request $request, $parameters, $matchedSitemapItem) |
|
28 | - { |
|
29 | - $this->parameters = (array) $parameters; |
|
30 | - $this->checkParameters(); |
|
31 | - |
|
32 | - $lang = substr(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : $this->defaultLanguage, 0, 2); |
|
33 | - $_SESSION['LanguageComponent']['detectedLanguage'] = $lang; |
|
34 | - |
|
35 | - $this->checkLanguageSwitch($request); |
|
36 | - |
|
37 | - if (!isset($_SESSION['LanguageComponent'][$this->languageParameterName])) { |
|
38 | - $this->detectLanguage($lang, $request); |
|
39 | - } else { |
|
40 | - if ($this->forceRedirect === true) { |
|
41 | - $this->detectLanguage($_SESSION['LanguageComponent'][$this->languageParameterName], $request); |
|
42 | - } |
|
43 | - } |
|
44 | - |
|
45 | - $this->parameters[$this->languageParameterName] = $_SESSION['LanguageComponent'][$this->languageParameterName]; |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Checks to see if any parameters are given from the configuration in the CMS |
|
50 | - */ |
|
51 | - private function checkParameters() |
|
52 | - { |
|
53 | - if (isset($this->parameters['defaultLanguage'])) { |
|
54 | - $this->defaultLanguage = $this->parameters['defaultLanguage']; |
|
55 | - unset($this->parameters['defaultLanguage']); |
|
56 | - } |
|
57 | - if (isset($this->parameters['acceptedLanguages'])) { |
|
58 | - $this->acceptedLanguages = explode(',', $this->parameters['acceptedLanguages']); |
|
59 | - unset($this->parameters['acceptedLanguages']); |
|
60 | - } |
|
61 | - if (isset($this->parameters['languageParameterName'])) { |
|
62 | - $this->languageParameterName = $this->parameters['languageParameterName']; |
|
63 | - unset($this->parameters['languageParameterName']); |
|
64 | - } |
|
65 | - if (isset($this->parameters['forceRedirect'])) { |
|
66 | - $this->forceRedirect = (bool) $this->parameters['forceRedirect']; |
|
67 | - unset($this->parameters['forceRedirect']); |
|
68 | - } |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @return array |
|
73 | - */ |
|
74 | - public function getParameters() |
|
75 | - { |
|
76 | - return $this->parameters; |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * Check if the found language is allowed and |
|
82 | - * if an action is to be taken. |
|
83 | - * |
|
84 | - * @param $lang |
|
85 | - * @param $request |
|
86 | - */ |
|
87 | - private function detectLanguage($lang, $request) |
|
88 | - { |
|
89 | - $_SESSION['LanguageComponent'][$this->languageParameterName] = $this->defaultLanguage; |
|
90 | - |
|
91 | - if ($this->acceptedLanguages === null) { |
|
92 | - $_SESSION['LanguageComponent'][$this->languageParameterName] = $lang; |
|
93 | - } else if (in_array($lang, $this->acceptedLanguages)) { |
|
94 | - $_SESSION['LanguageComponent'][$this->languageParameterName] = $lang; |
|
95 | - } else { |
|
96 | - $lang = $this->defaultLanguage; |
|
97 | - } |
|
98 | - |
|
99 | - $this->sessionValues = $_SESSION['LanguageComponent']; |
|
100 | - |
|
101 | - if ($this->forceRedirect === true) { |
|
102 | - if (substr($request::$relativeUri, 0, 2) !== $lang ) { |
|
103 | - if ($lang !== $this->defaultLanguage) { |
|
104 | - header('Location: ' . $request::$subfolders . $lang . '/' . $request::$relativeUri); |
|
105 | - exit; |
|
106 | - } |
|
107 | - } |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Detect if the language is switched manually |
|
113 | - * |
|
114 | - * @param $request |
|
115 | - */ |
|
116 | - private function checkLanguageSwitch($request) |
|
117 | - { |
|
118 | - if (isset($request::$get['langSwitch'])) { |
|
119 | - $this->forceRedirect = true; |
|
120 | - $this->detectLanguage($request::$get['langSwitch'], $request); |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - /* |
|
10 | + protected $request; |
|
11 | + protected $parameters; |
|
12 | + |
|
13 | + protected $defaultLanguage = 'en'; |
|
14 | + protected $acceptedLanguages = null; |
|
15 | + protected $languageParameterName = 'language'; |
|
16 | + protected $forceRedirect = false; |
|
17 | + protected $sessionValues; |
|
18 | + |
|
19 | + /** |
|
20 | + * Component constructor. |
|
21 | + * |
|
22 | + * @param $template |
|
23 | + * @param Request $request |
|
24 | + * @param $parameters |
|
25 | + * @param $matchedSitemapItem |
|
26 | + */ |
|
27 | + public function __construct($template, Request $request, $parameters, $matchedSitemapItem) |
|
28 | + { |
|
29 | + $this->parameters = (array) $parameters; |
|
30 | + $this->checkParameters(); |
|
31 | + |
|
32 | + $lang = substr(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : $this->defaultLanguage, 0, 2); |
|
33 | + $_SESSION['LanguageComponent']['detectedLanguage'] = $lang; |
|
34 | + |
|
35 | + $this->checkLanguageSwitch($request); |
|
36 | + |
|
37 | + if (!isset($_SESSION['LanguageComponent'][$this->languageParameterName])) { |
|
38 | + $this->detectLanguage($lang, $request); |
|
39 | + } else { |
|
40 | + if ($this->forceRedirect === true) { |
|
41 | + $this->detectLanguage($_SESSION['LanguageComponent'][$this->languageParameterName], $request); |
|
42 | + } |
|
43 | + } |
|
44 | + |
|
45 | + $this->parameters[$this->languageParameterName] = $_SESSION['LanguageComponent'][$this->languageParameterName]; |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Checks to see if any parameters are given from the configuration in the CMS |
|
50 | + */ |
|
51 | + private function checkParameters() |
|
52 | + { |
|
53 | + if (isset($this->parameters['defaultLanguage'])) { |
|
54 | + $this->defaultLanguage = $this->parameters['defaultLanguage']; |
|
55 | + unset($this->parameters['defaultLanguage']); |
|
56 | + } |
|
57 | + if (isset($this->parameters['acceptedLanguages'])) { |
|
58 | + $this->acceptedLanguages = explode(',', $this->parameters['acceptedLanguages']); |
|
59 | + unset($this->parameters['acceptedLanguages']); |
|
60 | + } |
|
61 | + if (isset($this->parameters['languageParameterName'])) { |
|
62 | + $this->languageParameterName = $this->parameters['languageParameterName']; |
|
63 | + unset($this->parameters['languageParameterName']); |
|
64 | + } |
|
65 | + if (isset($this->parameters['forceRedirect'])) { |
|
66 | + $this->forceRedirect = (bool) $this->parameters['forceRedirect']; |
|
67 | + unset($this->parameters['forceRedirect']); |
|
68 | + } |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @return array |
|
73 | + */ |
|
74 | + public function getParameters() |
|
75 | + { |
|
76 | + return $this->parameters; |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * Check if the found language is allowed and |
|
82 | + * if an action is to be taken. |
|
83 | + * |
|
84 | + * @param $lang |
|
85 | + * @param $request |
|
86 | + */ |
|
87 | + private function detectLanguage($lang, $request) |
|
88 | + { |
|
89 | + $_SESSION['LanguageComponent'][$this->languageParameterName] = $this->defaultLanguage; |
|
90 | + |
|
91 | + if ($this->acceptedLanguages === null) { |
|
92 | + $_SESSION['LanguageComponent'][$this->languageParameterName] = $lang; |
|
93 | + } else if (in_array($lang, $this->acceptedLanguages)) { |
|
94 | + $_SESSION['LanguageComponent'][$this->languageParameterName] = $lang; |
|
95 | + } else { |
|
96 | + $lang = $this->defaultLanguage; |
|
97 | + } |
|
98 | + |
|
99 | + $this->sessionValues = $_SESSION['LanguageComponent']; |
|
100 | + |
|
101 | + if ($this->forceRedirect === true) { |
|
102 | + if (substr($request::$relativeUri, 0, 2) !== $lang ) { |
|
103 | + if ($lang !== $this->defaultLanguage) { |
|
104 | + header('Location: ' . $request::$subfolders . $lang . '/' . $request::$relativeUri); |
|
105 | + exit; |
|
106 | + } |
|
107 | + } |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Detect if the language is switched manually |
|
113 | + * |
|
114 | + * @param $request |
|
115 | + */ |
|
116 | + private function checkLanguageSwitch($request) |
|
117 | + { |
|
118 | + if (isset($request::$get['langSwitch'])) { |
|
119 | + $this->forceRedirect = true; |
|
120 | + $this->detectLanguage($request::$get['langSwitch'], $request); |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + /* |
|
125 | 125 | * These functions are required by the interface, but not for the functionality |
126 | 126 | */ |
127 | - public function run(Storage $storage) {} |
|
128 | - public function render() {} |
|
129 | - public function get() {} |
|
127 | + public function run(Storage $storage) {} |
|
128 | + public function render() {} |
|
129 | + public function get() {} |
|
130 | 130 | } |
131 | 131 | \ No newline at end of file |
@@ -14,24 +14,24 @@ |
||
14 | 14 | class SitemapRouting implements CmsRouting |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * SitemapRouting constructor. |
|
19 | - * @param \library\cc\Request $request |
|
20 | - * @param mixed|string $relativeCmsUri |
|
21 | - * @param CmsComponent $cmsComponent |
|
22 | - */ |
|
23 | - public function __construct($request, $relativeCmsUri, $cmsComponent) |
|
24 | - { |
|
25 | - if ($relativeCmsUri == '/sitemap') { |
|
17 | + /** |
|
18 | + * SitemapRouting constructor. |
|
19 | + * @param \library\cc\Request $request |
|
20 | + * @param mixed|string $relativeCmsUri |
|
21 | + * @param CmsComponent $cmsComponent |
|
22 | + */ |
|
23 | + public function __construct($request, $relativeCmsUri, $cmsComponent) |
|
24 | + { |
|
25 | + if ($relativeCmsUri == '/sitemap') { |
|
26 | 26 | $this->overviewRoute($request, $cmsComponent); |
27 | - } elseif ($relativeCmsUri == '/sitemap/new') { |
|
27 | + } elseif ($relativeCmsUri == '/sitemap/new') { |
|
28 | 28 | $this->newRoute($request, $cmsComponent); |
29 | - } elseif ($relativeCmsUri == '/sitemap/edit' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
29 | + } elseif ($relativeCmsUri == '/sitemap/edit' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
30 | 30 | $this->editRoute($request, $cmsComponent); |
31 | - } elseif ($relativeCmsUri == '/sitemap/delete' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
31 | + } elseif ($relativeCmsUri == '/sitemap/delete' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
32 | 32 | $this->deleteRoute($request, $cmsComponent); |
33 | - } |
|
34 | - } |
|
33 | + } |
|
34 | + } |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * @param $request |
@@ -13,26 +13,26 @@ |
||
13 | 13 | class ImagesRouting implements CmsRouting |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * ImagesRouting constructor. |
|
18 | - * @param \library\cc\Request $request |
|
19 | - * @param mixed|string $relativeCmsUri |
|
20 | - * @param CmsComponent $cmsComponent |
|
21 | - */ |
|
22 | - public function __construct($request, $relativeCmsUri, $cmsComponent) |
|
23 | - { |
|
24 | - if ($relativeCmsUri == '/images') { |
|
16 | + /** |
|
17 | + * ImagesRouting constructor. |
|
18 | + * @param \library\cc\Request $request |
|
19 | + * @param mixed|string $relativeCmsUri |
|
20 | + * @param CmsComponent $cmsComponent |
|
21 | + */ |
|
22 | + public function __construct($request, $relativeCmsUri, $cmsComponent) |
|
23 | + { |
|
24 | + if ($relativeCmsUri == '/images') { |
|
25 | 25 | $this->overviewRoute($cmsComponent); |
26 | - } elseif ($relativeCmsUri == '/images.json') { |
|
26 | + } elseif ($relativeCmsUri == '/images.json') { |
|
27 | 27 | $this->jsonRoute($cmsComponent); |
28 | - } elseif ($relativeCmsUri == '/images/new') { |
|
28 | + } elseif ($relativeCmsUri == '/images/new') { |
|
29 | 29 | $this->newRoute($request, $cmsComponent); |
30 | - } elseif ($relativeCmsUri == '/images/delete' && isset($request::$get[CmsComponent::FILES_PARAMETER_FILE])) { |
|
30 | + } elseif ($relativeCmsUri == '/images/delete' && isset($request::$get[CmsComponent::FILES_PARAMETER_FILE])) { |
|
31 | 31 | $this->deleteRoute($request, $cmsComponent); |
32 | - } elseif ($relativeCmsUri == '/images/show' && isset($request::$get[CmsComponent::FILES_PARAMETER_FILE])) { |
|
32 | + } elseif ($relativeCmsUri == '/images/show' && isset($request::$get[CmsComponent::FILES_PARAMETER_FILE])) { |
|
33 | 33 | $this->showRoute($request, $cmsComponent); |
34 | - } |
|
35 | - } |
|
34 | + } |
|
35 | + } |
|
36 | 36 | |
37 | 37 | /** |
38 | 38 | * @param $cmsComponent |
@@ -12,58 +12,58 @@ |
||
12 | 12 | |
13 | 13 | class DocumentRouting implements CmsRouting |
14 | 14 | { |
15 | - /** |
|
16 | - * DocumentRouting constructor. |
|
17 | - * @param $request |
|
18 | - * @param $relativeCmsUri |
|
19 | - * @param CmsComponent $cmsComponent |
|
20 | - */ |
|
21 | - public function __construct($request, $relativeCmsUri, $cmsComponent) |
|
22 | - { |
|
23 | - if ($relativeCmsUri == '/documents') { |
|
24 | - $cmsComponent->subTemplate = 'cms/documents'; |
|
25 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENTS, $cmsComponent->storage->getDocuments()); |
|
26 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_DOCUMENTS); |
|
27 | - } |
|
28 | - $this->documentRouting($request, $relativeCmsUri, $cmsComponent); |
|
29 | - $this->folderRouting($request, $relativeCmsUri, $cmsComponent); |
|
30 | - } |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * @param $request |
|
35 | - * @param $relativeCmsUri |
|
36 | - * @param CmsComponent $cmsComponent |
|
37 | - * @throws \Exception |
|
38 | - */ |
|
39 | - private function documentRouting($request, $relativeCmsUri, $cmsComponent) |
|
40 | - { |
|
41 | - if ($relativeCmsUri == '/documents/new-document' && isset($request::$get[CmsComponent::GET_PARAMETER_PATH])) { |
|
15 | + /** |
|
16 | + * DocumentRouting constructor. |
|
17 | + * @param $request |
|
18 | + * @param $relativeCmsUri |
|
19 | + * @param CmsComponent $cmsComponent |
|
20 | + */ |
|
21 | + public function __construct($request, $relativeCmsUri, $cmsComponent) |
|
22 | + { |
|
23 | + if ($relativeCmsUri == '/documents') { |
|
24 | + $cmsComponent->subTemplate = 'cms/documents'; |
|
25 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENTS, $cmsComponent->storage->getDocuments()); |
|
26 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_DOCUMENTS); |
|
27 | + } |
|
28 | + $this->documentRouting($request, $relativeCmsUri, $cmsComponent); |
|
29 | + $this->folderRouting($request, $relativeCmsUri, $cmsComponent); |
|
30 | + } |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * @param $request |
|
35 | + * @param $relativeCmsUri |
|
36 | + * @param CmsComponent $cmsComponent |
|
37 | + * @throws \Exception |
|
38 | + */ |
|
39 | + private function documentRouting($request, $relativeCmsUri, $cmsComponent) |
|
40 | + { |
|
41 | + if ($relativeCmsUri == '/documents/new-document' && isset($request::$get[CmsComponent::GET_PARAMETER_PATH])) { |
|
42 | 42 | $this->documentOverviewRoute($request, $cmsComponent); |
43 | - } elseif ($relativeCmsUri == '/documents/edit-document' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
43 | + } elseif ($relativeCmsUri == '/documents/edit-document' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
44 | 44 | $this->editDocumentRoute($request, $cmsComponent); |
45 | - } elseif ($relativeCmsUri == '/documents/get-brick' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
45 | + } elseif ($relativeCmsUri == '/documents/get-brick' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
46 | 46 | $this->getBrickRoute($request, $cmsComponent); |
47 | - } else if ($relativeCmsUri == '/documents/delete-document' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
47 | + } else if ($relativeCmsUri == '/documents/delete-document' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
48 | 48 | $this->deleteDocumentRoute($request, $cmsComponent); |
49 | - } |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * @param $request |
|
54 | - * @param $relativeCmsUri |
|
55 | - * @param CmsComponent $cmsComponent |
|
56 | - */ |
|
57 | - private function folderRouting($request, $relativeCmsUri, $cmsComponent) |
|
58 | - { |
|
59 | - if ($relativeCmsUri == '/documents/new-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_PATH])) { |
|
49 | + } |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * @param $request |
|
54 | + * @param $relativeCmsUri |
|
55 | + * @param CmsComponent $cmsComponent |
|
56 | + */ |
|
57 | + private function folderRouting($request, $relativeCmsUri, $cmsComponent) |
|
58 | + { |
|
59 | + if ($relativeCmsUri == '/documents/new-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_PATH])) { |
|
60 | 60 | $this->newFolderRoute($request, $cmsComponent); |
61 | - } else if ($relativeCmsUri == '/documents/edit-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
61 | + } else if ($relativeCmsUri == '/documents/edit-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
62 | 62 | $this->editFolderRoute($request, $cmsComponent); |
63 | - } else if ($relativeCmsUri == '/documents/delete-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
63 | + } else if ($relativeCmsUri == '/documents/delete-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
64 | 64 | $this->deleteFolderRoute($request, $cmsComponent); |
65 | - } |
|
66 | - } |
|
65 | + } |
|
66 | + } |
|
67 | 67 | |
68 | 68 | /** |
69 | 69 | * @param $request |
@@ -19,192 +19,192 @@ discard block |
||
19 | 19 | |
20 | 20 | class Repository |
21 | 21 | { |
22 | - protected $storagePath; |
|
23 | - |
|
24 | - protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users'); |
|
25 | - |
|
26 | - protected $sitemap; |
|
27 | - protected $sitemapChanges = false; |
|
28 | - |
|
29 | - protected $applicationComponents; |
|
30 | - protected $applicationComponentsChanges = false; |
|
31 | - |
|
32 | - protected $documentTypes; |
|
33 | - protected $documentTypesChanges = false; |
|
34 | - |
|
35 | - protected $bricks; |
|
36 | - protected $bricksChanges = false; |
|
37 | - |
|
38 | - protected $imageSet; |
|
39 | - protected $imageSetChanges = false; |
|
40 | - |
|
41 | - protected $images; |
|
42 | - protected $imagesChanges = false; |
|
43 | - |
|
44 | - protected $files; |
|
45 | - protected $filesChanges = false; |
|
46 | - |
|
47 | - protected $users; |
|
48 | - protected $usersChanges = false; |
|
49 | - |
|
50 | - protected $contentDbHandle; |
|
51 | - |
|
52 | - /** |
|
53 | - * Repository constructor. |
|
54 | - * @param $storagePath |
|
55 | - * @throws \Exception |
|
56 | - */ |
|
57 | - public function __construct($storagePath) |
|
58 | - { |
|
59 | - $storagePath = realpath($storagePath); |
|
60 | - if (is_dir($storagePath) && $storagePath !== false) { |
|
61 | - $this->storagePath = $storagePath; |
|
62 | - } else { |
|
63 | - throw new \Exception('Repository not yet initialized.'); |
|
64 | - } |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Creates the folder in which to create all storage related files |
|
69 | - * |
|
70 | - * @param $storagePath |
|
71 | - * @return bool |
|
72 | - */ |
|
73 | - public static function create($storagePath) |
|
74 | - { |
|
75 | - return mkdir($storagePath); |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Initiates default storage |
|
80 | - * @throws \Exception |
|
81 | - */ |
|
82 | - public function init() |
|
83 | - { |
|
84 | - $storageDefaultPath = realpath('../library/cc/install/_storage.json'); |
|
85 | - $contentSqlPath = realpath('../library/cc/install/content.sql'); |
|
86 | - |
|
87 | - $this->initConfigStorage($storageDefaultPath); |
|
88 | - $this->initContentDb($contentSqlPath); |
|
89 | - |
|
90 | - $this->save(); |
|
91 | - } |
|
92 | - |
|
93 | - public function __get($name) |
|
94 | - { |
|
95 | - if (isset($this->$name)) { |
|
96 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
97 | - return $this->$name; |
|
98 | - } else { |
|
99 | - dump(); |
|
100 | - } |
|
101 | - } else { |
|
102 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
103 | - return $this->loadSubset($name); |
|
104 | - } else { |
|
105 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
106 | - } |
|
107 | - } |
|
108 | - } |
|
109 | - |
|
110 | - public function __set($name, $value) |
|
111 | - { |
|
112 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
113 | - $this->$name = $value; |
|
114 | - $changes = $name . 'Changes'; |
|
115 | - $this->$changes = true; |
|
116 | - } else { |
|
117 | - throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
118 | - } |
|
119 | - } |
|
120 | - |
|
121 | - public function save() |
|
122 | - { |
|
123 | - $this->sitemapChanges ? $this->saveSubset('sitemap') : null; |
|
124 | - $this->applicationComponentsChanges ? $this->saveSubset('applicationComponents') : null; |
|
125 | - $this->documentTypesChanges ? $this->saveSubset('documentTypes') : null; |
|
126 | - $this->bricksChanges ? $this->saveSubset('bricks') : null; |
|
127 | - $this->imageSetChanges ? $this->saveSubset('imageSet') : null; |
|
128 | - $this->imagesChanges ? $this->saveSubset('images') : null; |
|
129 | - $this->filesChanges ? $this->saveSubset('files') : null; |
|
130 | - $this->usersChanges ? $this->saveSubset('users') : null; |
|
131 | - } |
|
132 | - |
|
133 | - protected function saveSubset($subset) |
|
134 | - { |
|
135 | - $json = json_encode($this->$subset); |
|
136 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
137 | - file_put_contents($subsetStoragePath, $json); |
|
138 | - $changes = $subset . 'Changes'; |
|
139 | - $this->$changes = false; |
|
140 | - } |
|
141 | - |
|
142 | - protected function loadSubset($subset) |
|
143 | - { |
|
144 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
145 | - $json = file_get_contents($subsetStoragePath); |
|
146 | - $json = json_decode($json); |
|
147 | - $this->$subset = $json; |
|
148 | - return $json; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * @param $contentSqlPath |
|
153 | - */ |
|
154 | - protected function initContentDb($contentSqlPath) |
|
155 | - { |
|
156 | - $db = $this->getContentDbHandle(); |
|
157 | - $sql = file_get_contents($contentSqlPath); |
|
158 | - $db->exec($sql); |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * @param $storageDefaultPath |
|
163 | - */ |
|
164 | - protected function initConfigStorage($storageDefaultPath) |
|
165 | - { |
|
166 | - $json = file_get_contents($storageDefaultPath); |
|
167 | - $json = json_decode($json); |
|
168 | - $this->sitemap = $json->sitemap; |
|
169 | - $this->sitemapChanges = true; |
|
170 | - $this->applicationComponents = $json->applicationComponents; |
|
171 | - $this->applicationComponentsChanges = true; |
|
172 | - $this->documentTypes = $json->documentTypes; |
|
173 | - $this->documentTypesChanges = true; |
|
174 | - $this->bricks = $json->bricks; |
|
175 | - $this->bricksChanges = true; |
|
176 | - $this->imageSet = $json->imageSet; |
|
177 | - $this->imageSetChanges = true; |
|
178 | - $this->images = $json->images; |
|
179 | - $this->imagesChanges = true; |
|
180 | - $this->files = $json->files; |
|
181 | - $this->filesChanges = true; |
|
182 | - $this->users = $json->users; |
|
183 | - $this->usersChanges = true; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * @return \PDO |
|
188 | - */ |
|
189 | - protected function getContentDbHandle() |
|
190 | - { |
|
191 | - if ($this->contentDbHandle === null) { |
|
192 | - $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
193 | - } |
|
194 | - return $this->contentDbHandle; |
|
195 | - } |
|
196 | - |
|
197 | - public function getDocuments() |
|
198 | - { |
|
199 | - return $this->getDocumentsByPath('/'); |
|
200 | - } |
|
201 | - |
|
202 | - public function getDocumentsByPath($folderPath) |
|
203 | - { |
|
204 | - $db = $this->getContentDbHandle(); |
|
205 | - $folderPathWithWildcard = $folderPath . '%'; |
|
206 | - |
|
207 | - $stmt = $this->getDbStatement(' |
|
22 | + protected $storagePath; |
|
23 | + |
|
24 | + protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users'); |
|
25 | + |
|
26 | + protected $sitemap; |
|
27 | + protected $sitemapChanges = false; |
|
28 | + |
|
29 | + protected $applicationComponents; |
|
30 | + protected $applicationComponentsChanges = false; |
|
31 | + |
|
32 | + protected $documentTypes; |
|
33 | + protected $documentTypesChanges = false; |
|
34 | + |
|
35 | + protected $bricks; |
|
36 | + protected $bricksChanges = false; |
|
37 | + |
|
38 | + protected $imageSet; |
|
39 | + protected $imageSetChanges = false; |
|
40 | + |
|
41 | + protected $images; |
|
42 | + protected $imagesChanges = false; |
|
43 | + |
|
44 | + protected $files; |
|
45 | + protected $filesChanges = false; |
|
46 | + |
|
47 | + protected $users; |
|
48 | + protected $usersChanges = false; |
|
49 | + |
|
50 | + protected $contentDbHandle; |
|
51 | + |
|
52 | + /** |
|
53 | + * Repository constructor. |
|
54 | + * @param $storagePath |
|
55 | + * @throws \Exception |
|
56 | + */ |
|
57 | + public function __construct($storagePath) |
|
58 | + { |
|
59 | + $storagePath = realpath($storagePath); |
|
60 | + if (is_dir($storagePath) && $storagePath !== false) { |
|
61 | + $this->storagePath = $storagePath; |
|
62 | + } else { |
|
63 | + throw new \Exception('Repository not yet initialized.'); |
|
64 | + } |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Creates the folder in which to create all storage related files |
|
69 | + * |
|
70 | + * @param $storagePath |
|
71 | + * @return bool |
|
72 | + */ |
|
73 | + public static function create($storagePath) |
|
74 | + { |
|
75 | + return mkdir($storagePath); |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Initiates default storage |
|
80 | + * @throws \Exception |
|
81 | + */ |
|
82 | + public function init() |
|
83 | + { |
|
84 | + $storageDefaultPath = realpath('../library/cc/install/_storage.json'); |
|
85 | + $contentSqlPath = realpath('../library/cc/install/content.sql'); |
|
86 | + |
|
87 | + $this->initConfigStorage($storageDefaultPath); |
|
88 | + $this->initContentDb($contentSqlPath); |
|
89 | + |
|
90 | + $this->save(); |
|
91 | + } |
|
92 | + |
|
93 | + public function __get($name) |
|
94 | + { |
|
95 | + if (isset($this->$name)) { |
|
96 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
97 | + return $this->$name; |
|
98 | + } else { |
|
99 | + dump(); |
|
100 | + } |
|
101 | + } else { |
|
102 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
103 | + return $this->loadSubset($name); |
|
104 | + } else { |
|
105 | + throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
106 | + } |
|
107 | + } |
|
108 | + } |
|
109 | + |
|
110 | + public function __set($name, $value) |
|
111 | + { |
|
112 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
113 | + $this->$name = $value; |
|
114 | + $changes = $name . 'Changes'; |
|
115 | + $this->$changes = true; |
|
116 | + } else { |
|
117 | + throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
118 | + } |
|
119 | + } |
|
120 | + |
|
121 | + public function save() |
|
122 | + { |
|
123 | + $this->sitemapChanges ? $this->saveSubset('sitemap') : null; |
|
124 | + $this->applicationComponentsChanges ? $this->saveSubset('applicationComponents') : null; |
|
125 | + $this->documentTypesChanges ? $this->saveSubset('documentTypes') : null; |
|
126 | + $this->bricksChanges ? $this->saveSubset('bricks') : null; |
|
127 | + $this->imageSetChanges ? $this->saveSubset('imageSet') : null; |
|
128 | + $this->imagesChanges ? $this->saveSubset('images') : null; |
|
129 | + $this->filesChanges ? $this->saveSubset('files') : null; |
|
130 | + $this->usersChanges ? $this->saveSubset('users') : null; |
|
131 | + } |
|
132 | + |
|
133 | + protected function saveSubset($subset) |
|
134 | + { |
|
135 | + $json = json_encode($this->$subset); |
|
136 | + $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
137 | + file_put_contents($subsetStoragePath, $json); |
|
138 | + $changes = $subset . 'Changes'; |
|
139 | + $this->$changes = false; |
|
140 | + } |
|
141 | + |
|
142 | + protected function loadSubset($subset) |
|
143 | + { |
|
144 | + $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
145 | + $json = file_get_contents($subsetStoragePath); |
|
146 | + $json = json_decode($json); |
|
147 | + $this->$subset = $json; |
|
148 | + return $json; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * @param $contentSqlPath |
|
153 | + */ |
|
154 | + protected function initContentDb($contentSqlPath) |
|
155 | + { |
|
156 | + $db = $this->getContentDbHandle(); |
|
157 | + $sql = file_get_contents($contentSqlPath); |
|
158 | + $db->exec($sql); |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * @param $storageDefaultPath |
|
163 | + */ |
|
164 | + protected function initConfigStorage($storageDefaultPath) |
|
165 | + { |
|
166 | + $json = file_get_contents($storageDefaultPath); |
|
167 | + $json = json_decode($json); |
|
168 | + $this->sitemap = $json->sitemap; |
|
169 | + $this->sitemapChanges = true; |
|
170 | + $this->applicationComponents = $json->applicationComponents; |
|
171 | + $this->applicationComponentsChanges = true; |
|
172 | + $this->documentTypes = $json->documentTypes; |
|
173 | + $this->documentTypesChanges = true; |
|
174 | + $this->bricks = $json->bricks; |
|
175 | + $this->bricksChanges = true; |
|
176 | + $this->imageSet = $json->imageSet; |
|
177 | + $this->imageSetChanges = true; |
|
178 | + $this->images = $json->images; |
|
179 | + $this->imagesChanges = true; |
|
180 | + $this->files = $json->files; |
|
181 | + $this->filesChanges = true; |
|
182 | + $this->users = $json->users; |
|
183 | + $this->usersChanges = true; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * @return \PDO |
|
188 | + */ |
|
189 | + protected function getContentDbHandle() |
|
190 | + { |
|
191 | + if ($this->contentDbHandle === null) { |
|
192 | + $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
193 | + } |
|
194 | + return $this->contentDbHandle; |
|
195 | + } |
|
196 | + |
|
197 | + public function getDocuments() |
|
198 | + { |
|
199 | + return $this->getDocumentsByPath('/'); |
|
200 | + } |
|
201 | + |
|
202 | + public function getDocumentsByPath($folderPath) |
|
203 | + { |
|
204 | + $db = $this->getContentDbHandle(); |
|
205 | + $folderPathWithWildcard = $folderPath . '%'; |
|
206 | + |
|
207 | + $stmt = $this->getDbStatement(' |
|
208 | 208 | SELECT * |
209 | 209 | FROM documents |
210 | 210 | WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard) . ' |
@@ -213,100 +213,100 @@ discard block |
||
213 | 213 | ORDER BY `type` DESC, `path` ASC |
214 | 214 | '); |
215 | 215 | |
216 | - $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
217 | - foreach ($documents as $key => $document) { |
|
218 | - if ($document->type === 'folder') { |
|
219 | - $document->dbHandle = $db; |
|
220 | - $documents[$key] = $document; |
|
221 | - } |
|
222 | - } |
|
223 | - return $documents; |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - /** |
|
228 | - * @param $path |
|
229 | - * @return bool|Document |
|
230 | - */ |
|
231 | - public function getDocumentContainerByPath($path) |
|
232 | - { |
|
233 | - $document = $this->getDocumentByPath($path); |
|
234 | - if ($document === false) { |
|
235 | - return false; |
|
236 | - } |
|
237 | - $slugLength = strlen($document->slug); |
|
238 | - $containerPath = substr($path, 0, -$slugLength); |
|
239 | - if ($containerPath === '/') { |
|
240 | - return $this->getRootFolder(); |
|
241 | - } |
|
242 | - $containerFolder = $this->getDocumentByPath($containerPath); |
|
243 | - return $containerFolder; |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * @param $path |
|
248 | - * @return bool|Document |
|
249 | - */ |
|
250 | - public function getDocumentByPath($path) |
|
251 | - { |
|
252 | - $db = $this->getContentDbHandle(); |
|
253 | - $document = $this->fetchDocument(' |
|
216 | + $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
217 | + foreach ($documents as $key => $document) { |
|
218 | + if ($document->type === 'folder') { |
|
219 | + $document->dbHandle = $db; |
|
220 | + $documents[$key] = $document; |
|
221 | + } |
|
222 | + } |
|
223 | + return $documents; |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + /** |
|
228 | + * @param $path |
|
229 | + * @return bool|Document |
|
230 | + */ |
|
231 | + public function getDocumentContainerByPath($path) |
|
232 | + { |
|
233 | + $document = $this->getDocumentByPath($path); |
|
234 | + if ($document === false) { |
|
235 | + return false; |
|
236 | + } |
|
237 | + $slugLength = strlen($document->slug); |
|
238 | + $containerPath = substr($path, 0, -$slugLength); |
|
239 | + if ($containerPath === '/') { |
|
240 | + return $this->getRootFolder(); |
|
241 | + } |
|
242 | + $containerFolder = $this->getDocumentByPath($containerPath); |
|
243 | + return $containerFolder; |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * @param $path |
|
248 | + * @return bool|Document |
|
249 | + */ |
|
250 | + public function getDocumentByPath($path) |
|
251 | + { |
|
252 | + $db = $this->getContentDbHandle(); |
|
253 | + $document = $this->fetchDocument(' |
|
254 | 254 | SELECT * |
255 | 255 | FROM documents |
256 | 256 | WHERE path = ' . $db->quote($path) . ' |
257 | 257 | '); |
258 | - if ($document instanceof Document && $document->type === 'folder') { |
|
259 | - $document->dbHandle = $db; |
|
260 | - } |
|
261 | - return $document; |
|
262 | - } |
|
263 | - |
|
264 | - protected function fetchAllDocuments($sql) |
|
265 | - { |
|
266 | - $stmt = $this->getDbStatement($sql); |
|
267 | - return $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
268 | - } |
|
269 | - |
|
270 | - protected function fetchDocument($sql) |
|
271 | - { |
|
272 | - $stmt = $this->getDbStatement($sql); |
|
273 | - return $stmt->fetchObject('\library\storage\Document'); |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * @param $sql |
|
278 | - * @return \PDOStatement |
|
279 | - * @throws \Exception |
|
280 | - */ |
|
281 | - protected function getDbStatement($sql) |
|
282 | - { |
|
283 | - $db = $this->getContentDbHandle(); |
|
284 | - $stmt = $db->query($sql); |
|
285 | - if ($stmt === false) { |
|
286 | - $errorInfo = $db->errorInfo(); |
|
287 | - $errorMsg = $errorInfo[2]; |
|
288 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
289 | - } |
|
290 | - return $stmt; |
|
291 | - } |
|
292 | - |
|
293 | - protected function getRootFolder() |
|
294 | - { |
|
295 | - $rootFolder = new Document(); |
|
296 | - $rootFolder->path = '/'; |
|
297 | - $rootFolder->type = 'folder'; |
|
298 | - return $rootFolder; |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * @param $path |
|
303 | - * @param Document $documentObject |
|
304 | - * @return bool |
|
305 | - */ |
|
306 | - public function saveDocument($documentObject) |
|
307 | - { |
|
308 | - $db = $this->getContentDbHandle(); |
|
309 | - $stmt = $this->getDbStatement(' |
|
258 | + if ($document instanceof Document && $document->type === 'folder') { |
|
259 | + $document->dbHandle = $db; |
|
260 | + } |
|
261 | + return $document; |
|
262 | + } |
|
263 | + |
|
264 | + protected function fetchAllDocuments($sql) |
|
265 | + { |
|
266 | + $stmt = $this->getDbStatement($sql); |
|
267 | + return $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
268 | + } |
|
269 | + |
|
270 | + protected function fetchDocument($sql) |
|
271 | + { |
|
272 | + $stmt = $this->getDbStatement($sql); |
|
273 | + return $stmt->fetchObject('\library\storage\Document'); |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * @param $sql |
|
278 | + * @return \PDOStatement |
|
279 | + * @throws \Exception |
|
280 | + */ |
|
281 | + protected function getDbStatement($sql) |
|
282 | + { |
|
283 | + $db = $this->getContentDbHandle(); |
|
284 | + $stmt = $db->query($sql); |
|
285 | + if ($stmt === false) { |
|
286 | + $errorInfo = $db->errorInfo(); |
|
287 | + $errorMsg = $errorInfo[2]; |
|
288 | + throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
289 | + } |
|
290 | + return $stmt; |
|
291 | + } |
|
292 | + |
|
293 | + protected function getRootFolder() |
|
294 | + { |
|
295 | + $rootFolder = new Document(); |
|
296 | + $rootFolder->path = '/'; |
|
297 | + $rootFolder->type = 'folder'; |
|
298 | + return $rootFolder; |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | + * @param $path |
|
303 | + * @param Document $documentObject |
|
304 | + * @return bool |
|
305 | + */ |
|
306 | + public function saveDocument($documentObject) |
|
307 | + { |
|
308 | + $db = $this->getContentDbHandle(); |
|
309 | + $stmt = $this->getDbStatement(' |
|
310 | 310 | INSERT OR REPLACE INTO documents (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
311 | 311 | VALUES( |
312 | 312 | ' . $db->quote($documentObject->path) . ', |
@@ -324,31 +324,31 @@ discard block |
||
324 | 324 | ' . $db->quote(json_encode($documentObject->dynamicBricks)) . ' |
325 | 325 | ) |
326 | 326 | '); |
327 | - $result = $stmt->execute(); |
|
328 | - return $result; |
|
329 | - } |
|
330 | - |
|
331 | - public function deleteDocumentByPath($path) |
|
332 | - { |
|
333 | - $db = $this->getContentDbHandle(); |
|
334 | - $documentToDelete = $this->getDocumentByPath($path); |
|
335 | - if ($documentToDelete instanceof Document) { |
|
336 | - if ($documentToDelete->type == 'document') { |
|
337 | - $stmt = $this->getDbStatement(' |
|
327 | + $result = $stmt->execute(); |
|
328 | + return $result; |
|
329 | + } |
|
330 | + |
|
331 | + public function deleteDocumentByPath($path) |
|
332 | + { |
|
333 | + $db = $this->getContentDbHandle(); |
|
334 | + $documentToDelete = $this->getDocumentByPath($path); |
|
335 | + if ($documentToDelete instanceof Document) { |
|
336 | + if ($documentToDelete->type == 'document') { |
|
337 | + $stmt = $this->getDbStatement(' |
|
338 | 338 | DELETE FROM documents |
339 | 339 | WHERE path = ' . $db->quote($path) . ' |
340 | 340 | '); |
341 | - } elseif ($documentToDelete->type == 'folder') { |
|
342 | - $folderPathWithWildcard = $path . '%'; |
|
343 | - $stmt = $this->getDbStatement(' |
|
341 | + } elseif ($documentToDelete->type == 'folder') { |
|
342 | + $folderPathWithWildcard = $path . '%'; |
|
343 | + $stmt = $this->getDbStatement(' |
|
344 | 344 | DELETE FROM documents |
345 | 345 | WHERE (path LIKE ' . $db->quote($folderPathWithWildcard) . ' |
346 | 346 | AND substr(`path`, ' . (strlen($path) + 1) . ', 1) = "/") |
347 | 347 | OR path = ' . $db->quote($path) . ' |
348 | 348 | '); |
349 | - } |
|
350 | - } |
|
349 | + } |
|
350 | + } |
|
351 | 351 | |
352 | - $stmt->execute(); |
|
353 | - } |
|
352 | + $stmt->execute(); |
|
353 | + } |
|
354 | 354 | } |
355 | 355 | \ No newline at end of file |