@@ -11,20 +11,20 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | // Load custom config |
| 13 | 13 | $pwd = getcwd(); |
| 14 | -$dir = $pwd . DIRECTORY_SEPARATOR . "vendor" . DIRECTORY_SEPARATOR; |
|
| 14 | +$dir = $pwd.DIRECTORY_SEPARATOR."vendor".DIRECTORY_SEPARATOR; |
|
| 15 | 15 | |
| 16 | -require_once $dir . 'autoload.php'; |
|
| 16 | +require_once $dir.'autoload.php'; |
|
| 17 | 17 | |
| 18 | 18 | |
| 19 | -$project_path = $pwd . DIRECTORY_SEPARATOR . "src" . DIRECTORY_SEPARATOR; |
|
| 20 | -if (file_exists($project_path . "bootstrap.php")) { |
|
| 21 | - include_once($project_path . "bootstrap.php"); |
|
| 19 | +$project_path = $pwd.DIRECTORY_SEPARATOR."src".DIRECTORY_SEPARATOR; |
|
| 20 | +if (file_exists($project_path."bootstrap.php")) { |
|
| 21 | + include_once($project_path."bootstrap.php"); |
|
| 22 | 22 | } |
| 23 | -if (file_exists($project_path . "autoload.php")) { |
|
| 24 | - include_once($project_path . "autoload.php"); |
|
| 23 | +if (file_exists($project_path."autoload.php")) { |
|
| 24 | + include_once($project_path."autoload.php"); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | -require_once __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'bootstrap.php'; |
|
| 27 | +require_once __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'bootstrap.php'; |
|
| 28 | 28 | |
| 29 | 29 | $console = new Application(); |
| 30 | 30 | //Hidratamos con los comandos de PSFS |
@@ -30,7 +30,9 @@ discard block |
||
| 30 | 30 | //Hidratamos con los comandos de PSFS |
| 31 | 31 | $commands = new Finder(); |
| 32 | 32 | $commands->in(__DIR__)->notName("PSFSConsole.php"); |
| 33 | -foreach ($commands as $com) include_once($com->getRealPath()); |
|
| 33 | +foreach ($commands as $com) { |
|
| 34 | + include_once($com->getRealPath()); |
|
| 35 | +} |
|
| 34 | 36 | |
| 35 | 37 | //Hidratamos con los comandos de los módulos |
| 36 | 38 | $domains = Router::getInstance()->getDomains(); |
@@ -38,7 +40,9 @@ discard block |
||
| 38 | 40 | if (!preg_match('/ROOT/i', $domain)) { |
| 39 | 41 | $commands = new Finder(); |
| 40 | 42 | $commands->in($paths['base'])->path("Command")->name("*.php"); |
| 41 | - foreach ($commands as $com) include_once($com->getRealPath()); |
|
| 43 | + foreach ($commands as $com) { |
|
| 44 | + include_once($com->getRealPath()); |
|
| 45 | + } |
|
| 42 | 46 | } |
| 43 | 47 | } |
| 44 | 48 | |
@@ -122,12 +122,12 @@ discard block |
||
| 122 | 122 | { |
| 123 | 123 | $saved = true; |
| 124 | 124 | try { |
| 125 | - $admins = Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', Cache::JSONGZ, true) ?: []; |
|
| 126 | - $admins[$user['username']]['hash'] = sha1($user['username'] . $user['password']); |
|
| 125 | + $admins = Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', Cache::JSONGZ, true) ?: []; |
|
| 126 | + $admins[$user['username']]['hash'] = sha1($user['username'].$user['password']); |
|
| 127 | 127 | $admins[$user['username']]['profile'] = $user['profile']; |
| 128 | 128 | |
| 129 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', $admins, Cache::JSONGZ, true); |
|
| 130 | - } catch(\Exception $e) { |
|
| 129 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', $admins, Cache::JSONGZ, true); |
|
| 130 | + }catch (\Exception $e) { |
|
| 131 | 131 | Logger::log($e->getMessage(), LOG_ERR); |
| 132 | 132 | $saved = false; |
| 133 | 133 | } |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | */ |
| 165 | 165 | public function getAdmins() |
| 166 | 166 | { |
| 167 | - return Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', Cache::JSONGZ, true); |
|
| 167 | + return Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', Cache::JSONGZ, true); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | } |
| 192 | 192 | if (!empty($user) && !empty($admins[$user])) { |
| 193 | 193 | $auth = $admins[$user]['hash']; |
| 194 | - $this->authorized = ($auth == sha1($user . $pass)); |
|
| 194 | + $this->authorized = ($auth == sha1($user.$pass)); |
|
| 195 | 195 | if ($this->authorized) { |
| 196 | 196 | $this->admin = array( |
| 197 | 197 | 'alias' => $user, |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | if (!Config::getInstance()->checkTryToSaveConfig() |
| 30 | 30 | && (preg_match('/^\/(admin|setup\-admin)/i', $route) || NULL !== Config::getInstance()->get('restricted')) |
| 31 | 31 | ) { |
| 32 | - if (null === Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', Cache::JSONGZ, true)) { |
|
| 32 | + if (null === Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', Cache::JSONGZ, true)) { |
|
| 33 | 33 | throw new AdminCredentialsException(); |
| 34 | 34 | } |
| 35 | 35 | if (!Security::getInstance()->checkAdmin()) { |
@@ -49,8 +49,8 @@ discard block |
||
| 49 | 49 | $token = ''; |
| 50 | 50 | $ct = strlen($ts); |
| 51 | 51 | for ($i = 0; $i < $ct; $i++) { |
| 52 | - $token = substr($hash, $i, 1) . |
|
| 53 | - substr($ts, $i, 1) . |
|
| 52 | + $token = substr($hash, $i, 1). |
|
| 53 | + substr($ts, $i, 1). |
|
| 54 | 54 | $token; |
| 55 | 55 | } |
| 56 | 56 | return $token; |
@@ -68,16 +68,16 @@ discard block |
||
| 68 | 68 | $charsLength = strlen(self::RAND_SEP) - 1; |
| 69 | 69 | $tsLength = strlen($ts); |
| 70 | 70 | $i = 0; |
| 71 | - $ct = ceil($hashRest / 4); |
|
| 72 | - $part = substr($hash, $tsLength + $ct * $i, $ct); |
|
| 73 | - while(false !== $part) { |
|
| 74 | - $mixedToken .= $part . |
|
| 75 | - substr(self::RAND_SEP, round(rand(0, $charsLength), 0, PHP_ROUND_HALF_DOWN), 1) . |
|
| 71 | + $ct = ceil($hashRest/4); |
|
| 72 | + $part = substr($hash, $tsLength + $ct*$i, $ct); |
|
| 73 | + while (false !== $part) { |
|
| 74 | + $mixedToken .= $part. |
|
| 75 | + substr(self::RAND_SEP, round(rand(0, $charsLength), 0, PHP_ROUND_HALF_DOWN), 1). |
|
| 76 | 76 | substr(self::RAND_SEP, round(rand(0, $charsLength), 0, PHP_ROUND_HALF_DOWN), 1); |
| 77 | - $part = substr($hash, $tsLength + $ct * $i, $ct); |
|
| 77 | + $part = substr($hash, $tsLength + $ct*$i, $ct); |
|
| 78 | 78 | $i++; |
| 79 | 79 | } |
| 80 | - return $mixedToken . $token; |
|
| 80 | + return $mixedToken.$token; |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | /** |
@@ -86,10 +86,10 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | private static function getTs($isOdd = null) { |
| 88 | 88 | $ts = time(); |
| 89 | - $tsIsOdd = (bool)((int)substr($ts, -1) % 2); |
|
| 90 | - if(false === $isOdd && !$tsIsOdd) { |
|
| 89 | + $tsIsOdd = (bool)((int)substr($ts, -1)%2); |
|
| 90 | + if (false === $isOdd && !$tsIsOdd) { |
|
| 91 | 91 | $ts--; |
| 92 | - } elseif(true === $isOdd && !$tsIsOdd) { |
|
| 92 | + } elseif (true === $isOdd && !$tsIsOdd) { |
|
| 93 | 93 | $ts--; |
| 94 | 94 | } |
| 95 | 95 | return $ts; |
@@ -121,10 +121,10 @@ discard block |
||
| 121 | 121 | $partToken = ''; |
| 122 | 122 | $ts = ''; |
| 123 | 123 | $part = strrev($part); |
| 124 | - for($i = 0, $ct = strlen($part); $i < $ct; $i++) { |
|
| 125 | - if($i % 2 == 0) { |
|
| 124 | + for ($i = 0, $ct = strlen($part); $i < $ct; $i++) { |
|
| 125 | + if ($i%2 == 0) { |
|
| 126 | 126 | $ts .= substr($part, $i, 1); |
| 127 | - } else { |
|
| 127 | + }else { |
|
| 128 | 128 | $partToken .= substr($part, $i, 1); |
| 129 | 129 | } |
| 130 | 130 | } |
@@ -139,11 +139,11 @@ discard block |
||
| 139 | 139 | private static function parseTokenParts(array $parts) { |
| 140 | 140 | $token = ''; |
| 141 | 141 | list($partToken, $ts) = self::extractTs(array_pop($parts)); |
| 142 | - if($ts > 0) { |
|
| 143 | - foreach($parts as $part) { |
|
| 142 | + if ($ts > 0) { |
|
| 143 | + foreach ($parts as $part) { |
|
| 144 | 144 | $token .= $part; |
| 145 | 145 | } |
| 146 | - $token = $partToken . $token; |
|
| 146 | + $token = $partToken.$token; |
|
| 147 | 147 | } |
| 148 | 148 | return [$token, $ts]; |
| 149 | 149 | } |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | * @return array |
| 172 | 172 | */ |
| 173 | 173 | private static function extractTokenParts($token) { |
| 174 | - for($i = 0, $ct = strlen(self::RAND_SEP); $i < $ct; $i++) { |
|
| 174 | + for ($i = 0, $ct = strlen(self::RAND_SEP); $i < $ct; $i++) { |
|
| 175 | 175 | $token = str_replace(self::RAND_SEP[$i], "|", $token); |
| 176 | 176 | } |
| 177 | 177 | return array_unique(explode('||', $token)); |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | use PSFS\controller\ConfigController; |
| 19 | 19 | use PSFS\controller\UserController; |
| 20 | 20 | |
| 21 | -require_once __DIR__ . DIRECTORY_SEPARATOR . "bootstrap.php"; |
|
| 21 | +require_once __DIR__.DIRECTORY_SEPARATOR."bootstrap.php"; |
|
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * Class Dispatcher |
@@ -79,13 +79,13 @@ discard block |
||
| 79 | 79 | private function setLocale() |
| 80 | 80 | { |
| 81 | 81 | $this->locale = $this->config->get("default_language"); |
| 82 | - Logger::log('Set locale to project [' . $this->locale . ']'); |
|
| 82 | + Logger::log('Set locale to project ['.$this->locale.']'); |
|
| 83 | 83 | // Load translations |
| 84 | - putenv("LC_ALL=" . $this->locale); |
|
| 84 | + putenv("LC_ALL=".$this->locale); |
|
| 85 | 85 | setlocale(LC_ALL, $this->locale); |
| 86 | 86 | // Load the locale path |
| 87 | - $locale_path = BASE_DIR . DIRECTORY_SEPARATOR . 'locale'; |
|
| 88 | - Logger::log('Set locale dir ' . $locale_path); |
|
| 87 | + $locale_path = BASE_DIR.DIRECTORY_SEPARATOR.'locale'; |
|
| 88 | + Logger::log('Set locale dir '.$locale_path); |
|
| 89 | 89 | GeneratorHelper::createDir($locale_path); |
| 90 | 90 | bindtextdomain('translations', $locale_path); |
| 91 | 91 | textdomain('translations'); |
@@ -106,20 +106,20 @@ discard block |
||
| 106 | 106 | if (!$this->parser->isFile()) { |
| 107 | 107 | return $this->router->execute($this->actualUri); |
| 108 | 108 | } |
| 109 | - } else { |
|
| 109 | + }else { |
|
| 110 | 110 | return ConfigController::getInstance()->config(); |
| 111 | 111 | } |
| 112 | - } catch (AdminCredentialsException $a) { |
|
| 112 | + }catch (AdminCredentialsException $a) { |
|
| 113 | 113 | return UserController::showAdminManager(); |
| 114 | - } catch (ConfigException $c) { |
|
| 114 | + }catch (ConfigException $c) { |
|
| 115 | 115 | return $this->dumpException($c); |
| 116 | - } catch (SecurityException $s) { |
|
| 116 | + }catch (SecurityException $s) { |
|
| 117 | 117 | return $this->security->notAuthorized($this->actualUri); |
| 118 | - } catch (UserAuthException $u) { |
|
| 118 | + }catch (UserAuthException $u) { |
|
| 119 | 119 | $this->redirectToHome(); |
| 120 | - } catch (RouterException $r) { |
|
| 120 | + }catch (RouterException $r) { |
|
| 121 | 121 | return $this->router->httpNotFound($r); |
| 122 | - } catch (\Exception $e) { |
|
| 122 | + }catch (\Exception $e) { |
|
| 123 | 123 | return $this->dumpException($e); |
| 124 | 124 | } |
| 125 | 125 | } |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | $use /= 1024; |
| 167 | 167 | break; |
| 168 | 168 | case "MBytes": |
| 169 | - $use /= (1024 * 1024); |
|
| 169 | + $use /= (1024*1024); |
|
| 170 | 170 | break; |
| 171 | 171 | case "Bytes": |
| 172 | 172 | default: |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | if ($this->config->getDebugMode() && $this->config->get('errors.strict', false)) { |
| 193 | 193 | Logger::log('Added handlers for errors'); |
| 194 | 194 | //Warning & Notice handler |
| 195 | - set_error_handler(function ($errno, $errstr, $errfile, $errline) { |
|
| 195 | + set_error_handler(function($errno, $errstr, $errfile, $errline) { |
|
| 196 | 196 | Logger::log($errstr, LOG_CRIT, ['file' => $errfile, 'line' => $errline]); |
| 197 | 197 | throw new \Exception($errstr, 500); |
| 198 | 198 | }); |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | Logger::log('Initializing stats (mem + ts)'); |
| 208 | 208 | if (null !== $_SERVER && array_key_exists('REQUEST_TIME_FLOAT', $_SERVER)) { |
| 209 | 209 | $this->ts = (float)$_SERVER['REQUEST_TIME_FLOAT']; |
| 210 | - } else { |
|
| 210 | + }else { |
|
| 211 | 211 | $this->ts = $this->parser->getTs(); |
| 212 | 212 | } |
| 213 | 213 | $this->mem = memory_get_usage(); |