@@ -27,16 +27,16 @@ |
||
27 | 27 | { |
28 | 28 | $html = '<style>*{margin: 0} body{background: rgb(36,36,36); padding: 5px;}</style>'; |
29 | 29 | $html .= '<pre style="padding: 10px; margin: 5px; display: block; background: rgb(41,41,41); color: white; border-radius: 5px;">'; |
30 | - if(is_null($var)) { |
|
31 | - if($varName) $html .= $varName . ' ==> <b>NULL</b>'; |
|
32 | - } else { |
|
33 | - $html .= print_r('(' . gettype($var) . ') ', TRUE); |
|
34 | - if($varName) $html .= $varName . ' ==> '; |
|
35 | - if("boolean" === gettype($var)) { |
|
30 | + if (is_null($var)) { |
|
31 | + if ($varName) $html .= $varName.' ==> <b>NULL</b>'; |
|
32 | + }else { |
|
33 | + $html .= print_r('('.gettype($var).') ', TRUE); |
|
34 | + if ($varName) $html .= $varName.' ==> '; |
|
35 | + if ("boolean" === gettype($var)) { |
|
36 | 36 | $html .= print_r($var ? "TRUE" : "FALSE", TRUE); |
37 | - } else if((is_array($var) && !empty($var)) || (!is_array($var)) || ($var === 0)) { |
|
37 | + }else if ((is_array($var) && !empty($var)) || (!is_array($var)) || ($var === 0)) { |
|
38 | 38 | $html .= print_r($var, TRUE); |
39 | - } else { |
|
39 | + }else { |
|
40 | 40 | $html .= 'empty'; |
41 | 41 | } |
42 | 42 | } |
@@ -28,10 +28,14 @@ |
||
28 | 28 | $html = '<style>*{margin: 0} body{background: rgb(36,36,36); padding: 5px;}</style>'; |
29 | 29 | $html .= '<pre style="padding: 10px; margin: 5px; display: block; background: rgb(41,41,41); color: white; border-radius: 5px;">'; |
30 | 30 | if(is_null($var)) { |
31 | - if($varName) $html .= $varName . ' ==> <b>NULL</b>'; |
|
31 | + if($varName) { |
|
32 | + $html .= $varName . ' ==> <b>NULL</b>'; |
|
33 | + } |
|
32 | 34 | } else { |
33 | 35 | $html .= print_r('(' . gettype($var) . ') ', TRUE); |
34 | - if($varName) $html .= $varName . ' ==> '; |
|
36 | + if($varName) { |
|
37 | + $html .= $varName . ' ==> '; |
|
38 | + } |
|
35 | 39 | if("boolean" === gettype($var)) { |
36 | 40 | $html .= print_r($var ? "TRUE" : "FALSE", TRUE); |
37 | 41 | } else if((is_array($var) && !empty($var)) || (!is_array($var)) || ($var === 0)) { |
@@ -46,8 +46,8 @@ discard block |
||
46 | 46 | // TODO check more en locales |
47 | 47 | if (strtolower($locale) === 'en') { |
48 | 48 | $locale = 'en_GB'; |
49 | - } else { |
|
50 | - $locale = $locale . '_' . strtoupper($locale); |
|
49 | + }else { |
|
50 | + $locale = $locale.'_'.strtoupper($locale); |
|
51 | 51 | } |
52 | 52 | $defaultLocales = explode(',', Config::getParam('i18n.locales', '')); |
53 | 53 | if (!in_array($locale, array_merge($defaultLocales, self::$langs))) { |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | $translations = array(); |
67 | 67 | if (file_exists($absoluteFileName)) { |
68 | 68 | @include($absoluteFileName); |
69 | - } else { |
|
69 | + }else { |
|
70 | 70 | Cache::getInstance()->storeData($absoluteFileName, "<?php \$translations = array();\n", Cache::TEXT, TRUE); |
71 | 71 | } |
72 | 72 | |
@@ -83,13 +83,13 @@ discard block |
||
83 | 83 | public static function setLocale(string $default = null, string $customKey = null, bool $force = false): void |
84 | 84 | { |
85 | 85 | $locale = $force ? $default : self::extractLocale($default); |
86 | - Inspector::stats('[i18NHelper] Set locale to project [' . $locale . ']', Inspector::SCOPE_DEBUG); |
|
86 | + Inspector::stats('[i18NHelper] Set locale to project ['.$locale.']', Inspector::SCOPE_DEBUG); |
|
87 | 87 | // Load translations |
88 | - putenv("LC_ALL=" . $locale); |
|
88 | + putenv("LC_ALL=".$locale); |
|
89 | 89 | setlocale(LC_ALL, $locale); |
90 | 90 | // Load the locale path |
91 | - $localePath = BASE_DIR . DIRECTORY_SEPARATOR . 'locale'; |
|
92 | - Logger::log('Set locale dir ' . $localePath); |
|
91 | + $localePath = BASE_DIR.DIRECTORY_SEPARATOR.'locale'; |
|
92 | + Logger::log('Set locale dir '.$localePath); |
|
93 | 93 | GeneratorHelper::createDir($localePath); |
94 | 94 | bindtextdomain('translations', $localePath); |
95 | 95 | textdomain('translations'); |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | } |
113 | 113 | } elseif (is_object($data)) { |
114 | 114 | $properties = get_class_vars($data); |
115 | - if(is_array($properties)) { |
|
115 | + if (is_array($properties)) { |
|
116 | 116 | foreach (array_keys($properties) as $property) { |
117 | 117 | $data->$property = self::utf8Encode($data->$property); |
118 | 118 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | ['i', 'i', 'i', 'i', 'I', 'I', 'I', 'I'], |
160 | 160 | ['o', 'o', 'o', 'o', 'O', 'O', 'O', 'O'], |
161 | 161 | ['u', 'u', 'u', 'u', 'U', 'U', 'U', 'U'], |
162 | - ['n', 'N', 'c', 'C',], |
|
162 | + ['n', 'N', 'c', 'C', ], |
|
163 | 163 | ]; |
164 | 164 | |
165 | 165 | $text = htmlspecialchars($string); |
@@ -179,24 +179,24 @@ discard block |
||
179 | 179 | */ |
180 | 180 | public static function findTranslations(string $path, string $locale): array |
181 | 181 | { |
182 | - $localePath = realpath(BASE_DIR . DIRECTORY_SEPARATOR . 'locale'); |
|
183 | - $localePath .= DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . 'LC_MESSAGES' . DIRECTORY_SEPARATOR; |
|
182 | + $localePath = realpath(BASE_DIR.DIRECTORY_SEPARATOR.'locale'); |
|
183 | + $localePath .= DIRECTORY_SEPARATOR.$locale.DIRECTORY_SEPARATOR.'LC_MESSAGES'.DIRECTORY_SEPARATOR; |
|
184 | 184 | |
185 | 185 | $translations = array(); |
186 | 186 | if (file_exists($path)) { |
187 | 187 | $directory = dir($path); |
188 | 188 | while (false !== ($fileName = $directory->read())) { |
189 | 189 | GeneratorHelper::createDir($localePath); |
190 | - if (!file_exists($localePath . 'translations.po')) { |
|
191 | - file_put_contents($localePath . 'translations.po', ''); |
|
190 | + if (!file_exists($localePath.'translations.po')) { |
|
191 | + file_put_contents($localePath.'translations.po', ''); |
|
192 | 192 | } |
193 | - $inspectPath = realpath($path . DIRECTORY_SEPARATOR . $fileName); |
|
194 | - $cmdPhp = "export PATH=\$PATH:/opt/local/bin; xgettext " . |
|
195 | - $inspectPath . DIRECTORY_SEPARATOR . |
|
193 | + $inspectPath = realpath($path.DIRECTORY_SEPARATOR.$fileName); |
|
194 | + $cmdPhp = "export PATH=\$PATH:/opt/local/bin; xgettext ". |
|
195 | + $inspectPath.DIRECTORY_SEPARATOR. |
|
196 | 196 | "*.php --from-code=UTF-8 -j -L PHP --debug --force-po -o {$localePath}translations.po"; |
197 | - if (is_dir($path . DIRECTORY_SEPARATOR . $fileName) && preg_match('/^\./', $fileName) == 0) { |
|
198 | - $res = t('Revisando directorio: ') . $inspectPath; |
|
199 | - $res .= t('Comando ejecutado: ') . $cmdPhp; |
|
197 | + if (is_dir($path.DIRECTORY_SEPARATOR.$fileName) && preg_match('/^\./', $fileName) == 0) { |
|
198 | + $res = t('Revisando directorio: ').$inspectPath; |
|
199 | + $res .= t('Comando ejecutado: ').$cmdPhp; |
|
200 | 200 | $res .= shell_exec($cmdPhp); |
201 | 201 | usleep(10); |
202 | 202 | $translations[] = $res; |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | if (NULL === $user || (array_key_exists($user, $admins) && empty($admins[$user]))) { |
48 | 48 | list($user, $pass) = self::getAdminFromCookie(); |
49 | 49 | } |
50 | - return array_key_exists($user, $admins) ? [$user, sha1($user . $pass)] : [null, null]; |
|
50 | + return array_key_exists($user, $admins) ? [$user, sha1($user.$pass)] : [null, null]; |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | public static function checkComplexAuth(array $admins) |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | foreach ($admins as $admin => $profile) { |
63 | 63 | list($decrypted_user, $timestamp, $userAgent) = self::decodeToken($token, $profile['hash']); |
64 | 64 | if (!empty($decrypted_user) && !empty($timestamp)) { |
65 | - if(!empty($userAgent) && $userAgent === $reqUserAgent) { |
|
65 | + if (!empty($userAgent) && $userAgent === $reqUserAgent) { |
|
66 | 66 | $expiration = \DateTime::createFromFormat(self::EXPIRATION_TIMESTAMP_FORMAT, $timestamp); |
67 | 67 | if (false !== $expiration && $decrypted_user === $admin && $expiration > $now) { |
68 | 68 | $user = $admin; |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | return base64_encode($encrypted_data); |
90 | 90 | } |
91 | 91 | |
92 | - public static function decrypt(string $encrypted_data, string $key): false|string |
|
92 | + public static function decrypt(string $encrypted_data, string $key): false | string |
|
93 | 93 | { |
94 | 94 | $encrypted_data = base64_decode($encrypted_data); |
95 | 95 | $data = ''; |
@@ -110,15 +110,15 @@ discard block |
||
110 | 110 | if (null === $userAgent && array_key_exists('HTTP_USER_AGENT', $_SERVER)) { |
111 | 111 | $userAgent = $_SERVER['HTTP_USER_AGENT']; |
112 | 112 | } |
113 | - $data = $user . Security::LOGGED_USER_TOKEN . $timestamp->format(self::EXPIRATION_TIMESTAMP_FORMAT) . Security::LOGGED_USER_TOKEN . ($userAgent ?? 'psfs'); |
|
114 | - return self::encrypt($data, sha1($user . $password)); |
|
113 | + $data = $user.Security::LOGGED_USER_TOKEN.$timestamp->format(self::EXPIRATION_TIMESTAMP_FORMAT).Security::LOGGED_USER_TOKEN.($userAgent ?? 'psfs'); |
|
114 | + return self::encrypt($data, sha1($user.$password)); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | public static function decodeToken(string $token, string $password): array |
118 | 118 | { |
119 | 119 | $user = $timestamp = $userAgent = null; |
120 | 120 | $secret = self::decrypt($token, $password); |
121 | - if(!empty($secret) && str_contains($secret, Security::LOGGED_USER_TOKEN)) { |
|
121 | + if (!empty($secret) && str_contains($secret, Security::LOGGED_USER_TOKEN)) { |
|
122 | 122 | list($user, $timestamp, $userAgent) = explode(Security::LOGGED_USER_TOKEN, $secret); |
123 | 123 | } |
124 | 124 | return [$user, $timestamp, $userAgent]; |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | $this->setStatusCode(Template::STATUS_OK); |
128 | 128 | break; |
129 | 129 | default: |
130 | - $this->setStatusCode('HTTP/1.0 ' . ($status ?: 200)); |
|
130 | + $this->setStatusCode('HTTP/1.0 '.($status ?: 200)); |
|
131 | 131 | break; |
132 | 132 | } |
133 | 133 | return $this; |
@@ -140,11 +140,11 @@ discard block |
||
140 | 140 | */ |
141 | 141 | private function setResponseHeaders($contentType = 'text/html', array $cookies = array()): void |
142 | 142 | { |
143 | - ResponseHelper::setHeader('X-Powered-By: ' . Config::getParam('poweredBy', 'PSFS')); |
|
143 | + ResponseHelper::setHeader('X-Powered-By: '.Config::getParam('poweredBy', 'PSFS')); |
|
144 | 144 | ResponseHelper::setStatusHeader($this->getStatusCode()); |
145 | 145 | ResponseHelper::setAuthHeaders($this->isPublicZone()); |
146 | 146 | ResponseHelper::setCookieHeaders($cookies); |
147 | - ResponseHelper::setHeader('Content-type: ' . $contentType); |
|
147 | + ResponseHelper::setHeader('Content-type: '.$contentType); |
|
148 | 148 | |
149 | 149 | } |
150 | 150 | |
@@ -162,16 +162,16 @@ discard block |
||
162 | 162 | Logger::log('Start output response'); |
163 | 163 | ob_start(); |
164 | 164 | $this->setResponseHeaders($contentType, $cookies); |
165 | - ResponseHelper::setHeader('Content-length: ' . strlen($output)); |
|
166 | - ResponseHelper::setHeader('CRC: ' . crc32($output)); |
|
165 | + ResponseHelper::setHeader('Content-length: '.strlen($output)); |
|
166 | + ResponseHelper::setHeader('CRC: '.crc32($output)); |
|
167 | 167 | |
168 | 168 | $needCache = Cache::needCache(); |
169 | 169 | $cache = Cache::getInstance(); |
170 | 170 | list($path, $cacheDataName) = $cache->getRequestCacheHash(); |
171 | 171 | if (null !== $cacheDataName && false !== $needCache && $this->getStatusCode() === Template::STATUS_OK) { |
172 | 172 | Logger::log('Saving output response into cache'); |
173 | - $cache->storeData('json' . DIRECTORY_SEPARATOR . $path . $cacheDataName, $output); |
|
174 | - $cache->storeData('json' . DIRECTORY_SEPARATOR . $path . $cacheDataName . '.headers', headers_list(), Cache::JSON); |
|
173 | + $cache->storeData('json'.DIRECTORY_SEPARATOR.$path.$cacheDataName, $output); |
|
174 | + $cache->storeData('json'.DIRECTORY_SEPARATOR.$path.$cacheDataName.'.headers', headers_list(), Cache::JSON); |
|
175 | 175 | } elseif (Request::getInstance()->getMethod() !== 'GET') { |
176 | 176 | $cache->flushCache(); |
177 | 177 | } |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | ob_end_clean(); |
182 | 182 | Logger::log('End output response'); |
183 | 183 | $this->closeRender(); |
184 | - } else { |
|
184 | + }else { |
|
185 | 185 | return $output; |
186 | 186 | } |
187 | 187 | } |
@@ -194,12 +194,12 @@ discard block |
||
194 | 194 | Logger::log('Close template render'); |
195 | 195 | $uri = Request::requestUri(); |
196 | 196 | Security::getInstance()->setSessionKey('lastRequest', array( |
197 | - 'url' => Request::getInstance()->getRootUrl() . $uri, |
|
197 | + 'url' => Request::getInstance()->getRootUrl().$uri, |
|
198 | 198 | 'ts' => microtime(true), |
199 | 199 | )); |
200 | 200 | Security::getInstance()->updateSession(); |
201 | 201 | EventHelper::handleEvents(EventHelper::EVENT_END_REQUEST); |
202 | - Logger::log('End request: ' . Request::requestUri(), LOG_INFO); |
|
202 | + Logger::log('End request: '.Request::requestUri(), LOG_INFO); |
|
203 | 203 | exit; |
204 | 204 | } |
205 | 205 | |
@@ -237,17 +237,17 @@ discard block |
||
237 | 237 | ///////////////////////////////////////////////////////////// |
238 | 238 | // Date in the past sets the value to already have been expired. |
239 | 239 | ResponseHelper::setHeader('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); |
240 | - ResponseHelper::setHeader('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
|
240 | + ResponseHelper::setHeader('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); |
|
241 | 241 | ResponseHelper::setHeader('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1 |
242 | 242 | ResponseHelper::setHeader('Cache-Control: pre-check=0, post-check=0, max-age=0'); // HTTP/1.1 |
243 | 243 | ResponseHelper::setHeader('Pragma: no-cache'); |
244 | 244 | ResponseHelper::setHeader('Expires: 0'); |
245 | 245 | ResponseHelper::setHeader('Content-Transfer-Encoding: binary'); |
246 | - ResponseHelper::setHeader('Content-type: ' . $content); |
|
247 | - ResponseHelper::setHeader('Content-length: ' . strlen($data)); |
|
248 | - ResponseHelper::setHeader('Content-Disposition: attachment; filename="' . $filename . '"'); |
|
246 | + ResponseHelper::setHeader('Content-type: '.$content); |
|
247 | + ResponseHelper::setHeader('Content-length: '.strlen($data)); |
|
248 | + ResponseHelper::setHeader('Content-Disposition: attachment; filename="'.$filename.'"'); |
|
249 | 249 | ResponseHelper::setHeader('Access-Control-Expose-Headers: Filename'); |
250 | - ResponseHelper::setHeader('Filename: ' . $filename); |
|
250 | + ResponseHelper::setHeader('Filename: '.$filename); |
|
251 | 251 | echo $data; |
252 | 252 | ob_flush(); |
253 | 253 | ob_end_clean(); |
@@ -89,11 +89,11 @@ discard block |
||
89 | 89 | public static function save($user) |
90 | 90 | { |
91 | 91 | $saved = true; |
92 | - $admins = Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', Cache::JSONGZ, true) ?: []; |
|
93 | - $admins[$user['username']]['hash'] = sha1($user['username'] . $user['password']); |
|
92 | + $admins = Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', Cache::JSONGZ, true) ?: []; |
|
93 | + $admins[$user['username']]['hash'] = sha1($user['username'].$user['password']); |
|
94 | 94 | $admins[$user['username']]['profile'] = $user['profile']; |
95 | 95 | |
96 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', $admins, Cache::JSONGZ, true); |
|
96 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', $admins, Cache::JSONGZ, true); |
|
97 | 97 | return $saved; |
98 | 98 | } |
99 | 99 | |
@@ -113,9 +113,9 @@ discard block |
||
113 | 113 | |
114 | 114 | public function deleteUser($user) |
115 | 115 | { |
116 | - $admins = Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', Cache::JSONGZ, true) ?: []; |
|
116 | + $admins = Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', Cache::JSONGZ, true) ?: []; |
|
117 | 117 | unset($admins[$user]); |
118 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', $admins, Cache::JSONGZ, true); |
|
118 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', $admins, Cache::JSONGZ, true); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -54,10 +54,10 @@ |
||
54 | 54 | public function getServerName() |
55 | 55 | { |
56 | 56 | $serverName = $this->getServer('SERVER_NAME'); |
57 | - if(empty($serverName)) { |
|
57 | + if (empty($serverName)) { |
|
58 | 58 | $serverName = $this->getServer('HTTP_HOST'); |
59 | 59 | } |
60 | - if(str_contains($serverName, ':')) { |
|
60 | + if (str_contains($serverName, ':')) { |
|
61 | 61 | $pieces = explode(':', $serverName); |
62 | 62 | $serverName = $pieces[0]; |
63 | 63 | } |
@@ -100,7 +100,7 @@ |
||
100 | 100 | $this->params = []; |
101 | 101 | $this->headers = []; |
102 | 102 | $this->debug = 'debug' === strtolower(Config::getParam('log.level', 'notice')); |
103 | - Logger::log('Context service for ' . static::class . ' cleared!'); |
|
103 | + Logger::log('Context service for '.static::class.' cleared!'); |
|
104 | 104 | $this->closeConnection(); |
105 | 105 | } |
106 | 106 |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function admin() |
39 | 39 | { |
40 | - if(Security::getInstance()->isUser()) { |
|
40 | + if (Security::getInstance()->isUser()) { |
|
41 | 41 | throw new ApiException(t('You are not authorized to access this resource'), 403); |
42 | 42 | } |
43 | 43 | return AuthAdminController::getInstance()->render('api.admin.html.twig', array( |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | "domain" => $this->getDomain(), |
46 | 46 | "listLabel" => Api::API_LIST_NAME_FIELD, |
47 | 47 | 'modelId' => Api::API_MODEL_KEY_FIELD, |
48 | - 'formUrl' => preg_replace('/\/\{(.*)\}$/i', '', $this->getRoute(strtolower('admin-api-form-' . $this->getDomain() . '-' . $this->getApi()), TRUE)), |
|
49 | - "url" => preg_replace('/\/\{(.*)\}$/i', '', $this->getRoute(strtolower($this->getDomain() . '-' . 'api-' . $this->getApi() . "-pk"), TRUE)), |
|
48 | + 'formUrl' => preg_replace('/\/\{(.*)\}$/i', '', $this->getRoute(strtolower('admin-api-form-'.$this->getDomain().'-'.$this->getApi()), TRUE)), |
|
49 | + "url" => preg_replace('/\/\{(.*)\}$/i', '', $this->getRoute(strtolower($this->getDomain().'-'.'api-'.$this->getApi()."-pk"), TRUE)), |
|
50 | 50 | ), [], ''); |
51 | 51 | } |
52 | 52 |