@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | public function getAdmins() |
| 62 | 62 | { |
| 63 | - return Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', Cache::JSONGZ, true); |
|
| 63 | + return Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', Cache::JSONGZ, true); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -77,12 +77,12 @@ discard block |
||
| 77 | 77 | $admins = $this->getAdmins(); |
| 78 | 78 | $token = null; |
| 79 | 79 | if (null !== $admins) { |
| 80 | - if(empty($user)) { |
|
| 80 | + if (empty($user)) { |
|
| 81 | 81 | // First try, traditional basic auth |
| 82 | 82 | Inspector::stats('[Auth] Checking Basic Auth'); |
| 83 | 83 | list($user, $token) = AuthHelper::checkBasicAuth($user, $pass, $admins); |
| 84 | 84 | } |
| 85 | - if(empty($user)) { |
|
| 85 | + if (empty($user)) { |
|
| 86 | 86 | // Second try, cookie auth |
| 87 | 87 | Inspector::stats('[Auth] Checking Basic Auth PSFS'); |
| 88 | 88 | list($user, $token) = AuthHelper::checkComplexAuth($admins); |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | ]); |
| 104 | 104 | $this->setSessionKey(AuthHelper::ADMIN_ID_TOKEN, $encrypted); |
| 105 | 105 | } |
| 106 | - } else { |
|
| 106 | + }else { |
|
| 107 | 107 | $this->admin = null; |
| 108 | 108 | $this->setSessionKey(AuthHelper::ADMIN_ID_TOKEN, null); |
| 109 | 109 | } |
@@ -58,14 +58,14 @@ discard block |
||
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | 60 | $dto[$property->getName()] = $value; |
| 61 | - } else { |
|
| 61 | + }else { |
|
| 62 | 62 | $type = InjectorHelper::extractVarType($property->getDocComment()); |
| 63 | 63 | $dto[$property->getName()] = $this->checkCastedValue($property->getValue($this), $type ?: 'string'); |
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | - } catch (\Exception $e) { |
|
| 68 | - Logger::log(get_class($this) . ': ' . $e->getMessage(), LOG_ERR); |
|
| 67 | + }catch (\Exception $e) { |
|
| 68 | + Logger::log(get_class($this).': '.$e->getMessage(), LOG_ERR); |
|
| 69 | 69 | } |
| 70 | 70 | return $dto; |
| 71 | 71 | } |
@@ -102,12 +102,12 @@ discard block |
||
| 102 | 102 | $this->$key[] = $dto; |
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | - } else { |
|
| 105 | + }else { |
|
| 106 | 106 | $this->$key = clone $this->__cache[$type]; |
| 107 | 107 | $this->$key->fromArray($value); |
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | - } else { |
|
| 110 | + }else { |
|
| 111 | 111 | $this->castValue($key, $value, $type); |
| 112 | 112 | } |
| 113 | 113 | } |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | /** |
| 135 | 135 | * @return mixed |
| 136 | 136 | */ |
| 137 | - public function jsonSerialize(): array|string|null |
|
| 137 | + public function jsonSerialize(): array | string | null |
|
| 138 | 138 | { |
| 139 | 139 | return $this->toArray(); |
| 140 | 140 | } |
@@ -180,14 +180,14 @@ discard block |
||
| 180 | 180 | default: |
| 181 | 181 | case 'string': |
| 182 | 182 | // Cleaning HTML dangerous tags |
| 183 | - if(is_array($rawValue)) { |
|
| 184 | - foreach($rawValue as &$item) { |
|
| 183 | + if (is_array($rawValue)) { |
|
| 184 | + foreach ($rawValue as &$item) { |
|
| 185 | 185 | $item = $this->checkCastedValue($item, $type); |
| 186 | 186 | } |
| 187 | 187 | $value = $rawValue; |
| 188 | - } elseif(is_string($rawValue)) { |
|
| 188 | + } elseif (is_string($rawValue)) { |
|
| 189 | 189 | $value = I18nHelper::cleanHtmlAttacks($rawValue); |
| 190 | - } else { |
|
| 190 | + }else { |
|
| 191 | 191 | $value = $rawValue; |
| 192 | 192 | } |
| 193 | 193 | break; |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | $value = (bool)$rawValue; |
| 205 | 205 | break; |
| 206 | 206 | } |
| 207 | - } else { |
|
| 207 | + }else { |
|
| 208 | 208 | $value = $rawValue; |
| 209 | 209 | } |
| 210 | 210 | return $value; |
@@ -26,10 +26,10 @@ discard block |
||
| 26 | 26 | $objects = scandir($dir); |
| 27 | 27 | foreach ($objects as $object) { |
| 28 | 28 | if ($object != "." && $object != "..") { |
| 29 | - if (filetype($dir . "/" . $object) == "dir") { |
|
| 30 | - self::deleteDir($dir . "/" . $object); |
|
| 31 | - } else { |
|
| 32 | - unlink($dir . "/" . $object); |
|
| 29 | + if (filetype($dir."/".$object) == "dir") { |
|
| 30 | + self::deleteDir($dir."/".$object); |
|
| 31 | + }else { |
|
| 32 | + unlink($dir."/".$object); |
|
| 33 | 33 | } |
| 34 | 34 | } |
| 35 | 35 | } |
@@ -44,10 +44,10 @@ discard block |
||
| 44 | 44 | { |
| 45 | 45 | $rootDirs = array("css", "js", "media", "font"); |
| 46 | 46 | foreach ($rootDirs as $dir) { |
| 47 | - if (file_exists(WEB_DIR . DIRECTORY_SEPARATOR . $dir)) { |
|
| 47 | + if (file_exists(WEB_DIR.DIRECTORY_SEPARATOR.$dir)) { |
|
| 48 | 48 | try { |
| 49 | - self::deleteDir(WEB_DIR . DIRECTORY_SEPARATOR . $dir); |
|
| 50 | - } catch (\Exception $e) { |
|
| 49 | + self::deleteDir(WEB_DIR.DIRECTORY_SEPARATOR.$dir); |
|
| 50 | + }catch (\Exception $e) { |
|
| 51 | 51 | syslog(LOG_INFO, $e->getMessage()); |
| 52 | 52 | } |
| 53 | 53 | } |
@@ -64,12 +64,12 @@ discard block |
||
| 64 | 64 | if (!empty($dir)) { |
| 65 | 65 | try { |
| 66 | 66 | if (!is_dir($dir) && @mkdir($dir, 0775, true) === false) { |
| 67 | - throw new Exception(t('Can\'t create directory ') . $dir); |
|
| 67 | + throw new Exception(t('Can\'t create directory ').$dir); |
|
| 68 | 68 | } |
| 69 | - } catch (\Exception $e) { |
|
| 69 | + }catch (\Exception $e) { |
|
| 70 | 70 | syslog(LOG_WARNING, $e->getMessage()); |
| 71 | 71 | if (!file_exists(dirname($dir))) { |
| 72 | - throw new GeneratorException($e->getMessage() . $dir); |
|
| 72 | + throw new GeneratorException($e->getMessage().$dir); |
|
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | } |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | public static function getTemplatePath(): string |
| 83 | 83 | { |
| 84 | - $path = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR; |
|
| 84 | + $path = __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR; |
|
| 85 | 85 | return realpath($path); |
| 86 | 86 | } |
| 87 | 87 | |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | } elseif (!$reflector->isAbstract()) { |
| 110 | 110 | throw new GeneratorException(t('La clase definida debe ser abstracta'), 501); |
| 111 | 111 | } |
| 112 | - } else { |
|
| 112 | + }else { |
|
| 113 | 113 | throw new GeneratorException(t('La clase definida para extender la API no existe'), 501); |
| 114 | 114 | } |
| 115 | 115 | } |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | GeneratorHelper::createDir($path); |
| 132 | 132 | $paths = array("js", "css", "img", "media", "font"); |
| 133 | 133 | foreach ($paths as $htmlPath) { |
| 134 | - GeneratorHelper::createDir($path . DIRECTORY_SEPARATOR . $htmlPath); |
|
| 134 | + GeneratorHelper::createDir($path.DIRECTORY_SEPARATOR.$htmlPath); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | // Generates the root needed files |
@@ -141,35 +141,35 @@ discard block |
||
| 141 | 141 | 'crossdomain' => 'crossdomain.xml', |
| 142 | 142 | 'humans' => 'humans.txt', |
| 143 | 143 | 'robots' => 'robots.txt', |
| 144 | - 'docker' => '..' . DIRECTORY_SEPARATOR . 'docker-compose.yml', |
|
| 144 | + 'docker' => '..'.DIRECTORY_SEPARATOR.'docker-compose.yml', |
|
| 145 | 145 | ]; |
| 146 | 146 | $verificable = ['humans', 'robots', 'docker']; |
| 147 | 147 | if (!$quiet) { |
| 148 | 148 | $output->writeln('Start creating html files'); |
| 149 | 149 | } |
| 150 | 150 | foreach ($files as $template => $filename) { |
| 151 | - if (in_array($template, $verificable) && file_exists($path . DIRECTORY_SEPARATOR . $filename)) { |
|
| 151 | + if (in_array($template, $verificable) && file_exists($path.DIRECTORY_SEPARATOR.$filename)) { |
|
| 152 | 152 | if (!$quiet) { |
| 153 | - $output->writeln($filename . ' already exists'); |
|
| 153 | + $output->writeln($filename.' already exists'); |
|
| 154 | 154 | } |
| 155 | 155 | continue; |
| 156 | 156 | } |
| 157 | - $text = Template::getInstance()->dump("generator/html/" . $template . '.html.twig'); |
|
| 158 | - if (false === file_put_contents($path . DIRECTORY_SEPARATOR . $filename, $text)) { |
|
| 157 | + $text = Template::getInstance()->dump("generator/html/".$template.'.html.twig'); |
|
| 158 | + if (false === file_put_contents($path.DIRECTORY_SEPARATOR.$filename, $text)) { |
|
| 159 | 159 | if (!$quiet) { |
| 160 | - $output->writeln('Can\t create the file ' . $filename); |
|
| 160 | + $output->writeln('Can\t create the file '.$filename); |
|
| 161 | 161 | } |
| 162 | - } else { |
|
| 162 | + }else { |
|
| 163 | 163 | if (!$quiet) { |
| 164 | - $output->writeln($filename . ' created successfully'); |
|
| 164 | + $output->writeln($filename.' created successfully'); |
|
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | //Export base locale translations |
| 170 | - if (!file_exists(BASE_DIR . DIRECTORY_SEPARATOR . 'locale')) { |
|
| 171 | - GeneratorHelper::createDir(BASE_DIR . DIRECTORY_SEPARATOR . 'locale'); |
|
| 172 | - self::copyr(SOURCE_DIR . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'locale', BASE_DIR . DIRECTORY_SEPARATOR . 'locale'); |
|
| 170 | + if (!file_exists(BASE_DIR.DIRECTORY_SEPARATOR.'locale')) { |
|
| 171 | + GeneratorHelper::createDir(BASE_DIR.DIRECTORY_SEPARATOR.'locale'); |
|
| 172 | + self::copyr(SOURCE_DIR.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'locale', BASE_DIR.DIRECTORY_SEPARATOR.'locale'); |
|
| 173 | 173 | } |
| 174 | 174 | } |
| 175 | 175 | |
@@ -185,12 +185,12 @@ discard block |
||
| 185 | 185 | { |
| 186 | 186 | if (file_exists($filenamePath)) { |
| 187 | 187 | $destfolder = basename($filenamePath); |
| 188 | - if (!file_exists(WEB_DIR . $dest . DIRECTORY_SEPARATOR . $destfolder) || $debug || $force) { |
|
| 188 | + if (!file_exists(WEB_DIR.$dest.DIRECTORY_SEPARATOR.$destfolder) || $debug || $force) { |
|
| 189 | 189 | if (is_dir($filenamePath)) { |
| 190 | - self::copyr($filenamePath, WEB_DIR . $dest . DIRECTORY_SEPARATOR . $destfolder); |
|
| 191 | - } else { |
|
| 192 | - if (@copy($filenamePath, WEB_DIR . $dest . DIRECTORY_SEPARATOR . $destfolder) === FALSE) { |
|
| 193 | - throw new ConfigException("Can't copy " . $filenamePath . " to " . WEB_DIR . $dest . DIRECTORY_SEPARATOR . $destfolder); |
|
| 190 | + self::copyr($filenamePath, WEB_DIR.$dest.DIRECTORY_SEPARATOR.$destfolder); |
|
| 191 | + }else { |
|
| 192 | + if (@copy($filenamePath, WEB_DIR.$dest.DIRECTORY_SEPARATOR.$destfolder) === FALSE) { |
|
| 193 | + throw new ConfigException("Can't copy ".$filenamePath." to ".WEB_DIR.$dest.DIRECTORY_SEPARATOR.$destfolder); |
|
| 194 | 194 | } |
| 195 | 195 | } |
| 196 | 196 | } |
@@ -209,10 +209,10 @@ discard block |
||
| 209 | 209 | self::createDir($dst); |
| 210 | 210 | while (false !== ($file = readdir($dir))) { |
| 211 | 211 | if (($file != '.') && ($file != '..')) { |
| 212 | - if (is_dir($src . '/' . $file)) { |
|
| 213 | - self::copyr($src . '/' . $file, $dst . '/' . $file); |
|
| 214 | - } elseif (@copy($src . '/' . $file, $dst . '/' . $file) === false) { |
|
| 215 | - throw new ConfigException("Can't copy " . $src . " to " . $dst); |
|
| 212 | + if (is_dir($src.'/'.$file)) { |
|
| 213 | + self::copyr($src.'/'.$file, $dst.'/'.$file); |
|
| 214 | + } elseif (@copy($src.'/'.$file, $dst.'/'.$file) === false) { |
|
| 215 | + throw new ConfigException("Can't copy ".$src." to ".$dst); |
|
| 216 | 216 | } |
| 217 | 217 | } |
| 218 | 218 | } |
@@ -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 | /** |
@@ -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 | |
@@ -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 | } |