@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | if (!Config::getInstance()->checkTryToSaveConfig() |
30 | 30 | && (preg_match('/^\/(admin|setup\-admin)/i', $route) || Config::getParam('restricted', false)) |
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,8 +171,8 @@ 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++) { |
|
175 | - $token = str_replace(substr(self::RAND_SEP,$i,1), "|", $token); |
|
174 | + for ($i = 0, $ct = strlen(self::RAND_SEP); $i < $ct; $i++) { |
|
175 | + $token = str_replace(substr(self::RAND_SEP, $i, 1), "|", $token); |
|
176 | 176 | } |
177 | 177 | return array_unique(explode('||', $token)); |
178 | 178 | } |
@@ -63,11 +63,11 @@ discard block |
||
63 | 63 | */ |
64 | 64 | public function init() |
65 | 65 | { |
66 | - list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", $this->cacheType, TRUE); |
|
66 | + list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", $this->cacheType, TRUE); |
|
67 | 67 | if (empty($this->routing) || Config::getInstance()->getDebugMode()) { |
68 | 68 | $this->debugLoad(); |
69 | - } else { |
|
70 | - $this->domains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->cacheType, TRUE); |
|
69 | + }else { |
|
70 | + $this->domains = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", $this->cacheType, TRUE); |
|
71 | 71 | } |
72 | 72 | $this->checkExternalModules(false); |
73 | 73 | $this->setLoaded(true); |
@@ -102,11 +102,11 @@ discard block |
||
102 | 102 | if (preg_match('/json/i', Request::getInstance()->getServer('CONTENT_TYPE')) || $isJson) { |
103 | 103 | $response = new JsonResponse(null, false, 0, 0, $e->getMessage()); |
104 | 104 | return $template->output(json_encode($response), 'application/json'); |
105 | - } else { |
|
105 | + }else { |
|
106 | 106 | $not_found_route = Config::getParam('route.404'); |
107 | - if(null !== $not_found_route) { |
|
107 | + if (null !== $not_found_route) { |
|
108 | 108 | Request::getInstance()->redirect($this->getRoute($not_found_route, true)); |
109 | - } else { |
|
109 | + }else { |
|
110 | 110 | return $template->render('error.html.twig', array( |
111 | 111 | 'exception' => $e, |
112 | 112 | 'trace' => $e->getTraceAsString(), |
@@ -161,12 +161,12 @@ discard block |
||
161 | 161 | try { |
162 | 162 | //Search action and execute |
163 | 163 | $this->searchAction($route); |
164 | - } catch (AccessDeniedException $e) { |
|
165 | - Logger::log(_('Solicitamos credenciales de acceso a zona restringida'), LOG_WARNING, ['file' => $e->getFile() . '[' . $e->getLine() . ']']); |
|
164 | + }catch (AccessDeniedException $e) { |
|
165 | + Logger::log(_('Solicitamos credenciales de acceso a zona restringida'), LOG_WARNING, ['file' => $e->getFile().'['.$e->getLine().']']); |
|
166 | 166 | return Admin::staticAdminLogon($route); |
167 | - } catch (RouterException $r) { |
|
167 | + }catch (RouterException $r) { |
|
168 | 168 | Logger::log($r->getMessage(), LOG_WARNING); |
169 | - } catch (\Exception $e) { |
|
169 | + }catch (\Exception $e) { |
|
170 | 170 | Logger::log($e->getMessage(), LOG_ERR); |
171 | 171 | throw $e; |
172 | 172 | } |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | */ |
184 | 184 | protected function searchAction($route) |
185 | 185 | { |
186 | - Logger::log('Searching action to execute: ' . $route, LOG_INFO); |
|
186 | + Logger::log('Searching action to execute: '.$route, LOG_INFO); |
|
187 | 187 | //Revisamos si tenemos la ruta registrada |
188 | 188 | $parts = parse_url($route); |
189 | 189 | $path = (array_key_exists('path', $parts)) ? $parts['path'] : $route; |
@@ -198,12 +198,12 @@ discard block |
||
198 | 198 | /** @var $class \PSFS\base\types\Controller */ |
199 | 199 | $class = RouterHelper::getClassToCall($action); |
200 | 200 | try { |
201 | - if($this->checkRequirements($action, $get)) { |
|
201 | + if ($this->checkRequirements($action, $get)) { |
|
202 | 202 | $this->executeCachedRoute($route, $action, $class, $get); |
203 | - } else { |
|
203 | + }else { |
|
204 | 204 | throw new RouterException(_('La ruta no es válida'), 400); |
205 | 205 | } |
206 | - } catch (\Exception $e) { |
|
206 | + }catch (\Exception $e) { |
|
207 | 207 | Logger::log($e->getMessage(), LOG_ERR); |
208 | 208 | throw $e; |
209 | 209 | } |
@@ -218,15 +218,15 @@ discard block |
||
218 | 218 | * @return bool |
219 | 219 | */ |
220 | 220 | private function checkRequirements(array $action, array $params = []) { |
221 | - if(!empty($action['requirements']) && !empty($params)) { |
|
221 | + if (!empty($action['requirements']) && !empty($params)) { |
|
222 | 222 | $checked = 0; |
223 | - foreach(array_keys($params) as $key) { |
|
224 | - if(in_array($key, $action['requirements'])) { |
|
223 | + foreach (array_keys($params) as $key) { |
|
224 | + if (in_array($key, $action['requirements'])) { |
|
225 | 225 | $checked++; |
226 | 226 | } |
227 | 227 | } |
228 | 228 | $valid = count($action['requirements']) == $checked; |
229 | - } else { |
|
229 | + }else { |
|
230 | 230 | $valid = true; |
231 | 231 | } |
232 | 232 | return $valid; |
@@ -278,10 +278,10 @@ discard block |
||
278 | 278 | $modules = $this->finder->directories()->in($modulesPath)->depth(0); |
279 | 279 | foreach ($modules as $modulePath) { |
280 | 280 | $module = $modulePath->getBasename(); |
281 | - $this->routing = $this->inspectDir($modulesPath . DIRECTORY_SEPARATOR . $module, $module, $this->routing); |
|
281 | + $this->routing = $this->inspectDir($modulesPath.DIRECTORY_SEPARATOR.$module, $module, $this->routing); |
|
282 | 282 | } |
283 | 283 | } |
284 | - $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->domains, Cache::JSON, TRUE); |
|
284 | + $this->cache->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", $this->domains, Cache::JSON, TRUE); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | $home_params = NULL; |
297 | 297 | foreach ($this->routing as $pattern => $params) { |
298 | 298 | list($method, $route) = RouterHelper::extractHttpRoute($pattern); |
299 | - if (preg_match("/" . preg_quote($route, "/") . "$/i", "/" . $home)) { |
|
299 | + if (preg_match("/".preg_quote($route, "/")."$/i", "/".$home)) { |
|
300 | 300 | $home_params = $params; |
301 | 301 | } |
302 | 302 | } |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->depth(1)->name("*.php"); |
322 | 322 | foreach ($files as $file) { |
323 | 323 | $filename = str_replace("/", '\\', str_replace($origen, '', $file->getPathname())); |
324 | - $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing, $namespace); |
|
324 | + $routing = $this->addRouting($namespace.str_replace('.php', '', $filename), $routing, $namespace); |
|
325 | 325 | } |
326 | 326 | $this->finder = new Finder(); |
327 | 327 | |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | private function addRouting($namespace, &$routing, $module = 'PSFS') |
352 | 352 | { |
353 | 353 | if (self::exists($namespace)) { |
354 | - if(I18nHelper::checkI18Class($namespace)) { |
|
354 | + if (I18nHelper::checkI18Class($namespace)) { |
|
355 | 355 | return $routing; |
356 | 356 | } |
357 | 357 | $reflection = new \ReflectionClass($namespace); |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | if (!$this->domains) { |
395 | 395 | $this->domains = []; |
396 | 396 | } |
397 | - $domain = "@" . $class->getConstant("DOMAIN") . "/"; |
|
397 | + $domain = "@".$class->getConstant("DOMAIN")."/"; |
|
398 | 398 | if (!array_key_exists($domain, $this->domains)) { |
399 | 399 | $this->domains[$domain] = RouterHelper::extractDomainInfo($class, $domain); |
400 | 400 | } |
@@ -409,11 +409,11 @@ discard block |
||
409 | 409 | */ |
410 | 410 | public function simpatize() |
411 | 411 | { |
412 | - $translationFileName = "translations" . DIRECTORY_SEPARATOR . "routes_translations.php"; |
|
413 | - $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName; |
|
412 | + $translationFileName = "translations".DIRECTORY_SEPARATOR."routes_translations.php"; |
|
413 | + $absoluteTranslationFileName = CACHE_DIR.DIRECTORY_SEPARATOR.$translationFileName; |
|
414 | 414 | $this->generateSlugs($absoluteTranslationFileName); |
415 | 415 | GeneratorHelper::createDir(CONFIG_DIR); |
416 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
416 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
417 | 417 | |
418 | 418 | return $this; |
419 | 419 | } |
@@ -431,16 +431,16 @@ discard block |
||
431 | 431 | public function getRoute($slug = '', $absolute = FALSE, $params = []) |
432 | 432 | { |
433 | 433 | if (strlen($slug) === 0) { |
434 | - return ($absolute) ? Request::getInstance()->getRootUrl() . '/' : '/'; |
|
434 | + return ($absolute) ? Request::getInstance()->getRootUrl().'/' : '/'; |
|
435 | 435 | } |
436 | 436 | if (!is_array($this->slugs) || !array_key_exists($slug, $this->slugs)) { |
437 | 437 | throw new RouterException(_("No existe la ruta especificada")); |
438 | 438 | } |
439 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug]; |
|
439 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->slugs[$slug] : $this->slugs[$slug]; |
|
440 | 440 | if (!empty($params)) foreach ($params as $key => $value) { |
441 | - $url = str_replace("{" . $key . "}", $value, $url); |
|
441 | + $url = str_replace("{".$key."}", $value, $url); |
|
442 | 442 | } elseif (!empty($this->routing[$this->slugs[$slug]]["default"])) { |
443 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
|
443 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
|
444 | 444 | } |
445 | 445 | |
446 | 446 | return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url); |
@@ -485,17 +485,17 @@ discard block |
||
485 | 485 | */ |
486 | 486 | protected function executeCachedRoute($route, $action, $class, $params = NULL) |
487 | 487 | { |
488 | - Logger::log('Executing route ' . $route, LOG_INFO); |
|
488 | + Logger::log('Executing route '.$route, LOG_INFO); |
|
489 | 489 | $action['params'] = array_merge($action['params'], $params, Request::getInstance()->getQueryParams()); |
490 | 490 | Security::getInstance()->setSessionKey("__CACHE__", $action); |
491 | 491 | $cache = Cache::needCache(); |
492 | 492 | $execute = TRUE; |
493 | 493 | if (FALSE !== $cache && Config::getParam('debug') === FALSE && $action['http'] === 'GET') { |
494 | 494 | list($path, $cacheDataName) = $this->cache->getRequestCacheHash(); |
495 | - $cachedData = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $path . $cacheDataName, |
|
495 | + $cachedData = $this->cache->readFromCache("json".DIRECTORY_SEPARATOR.$path.$cacheDataName, |
|
496 | 496 | $cache, null); |
497 | 497 | if (NULL !== $cachedData) { |
498 | - $headers = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $path . $cacheDataName . ".headers", |
|
498 | + $headers = $this->cache->readFromCache("json".DIRECTORY_SEPARATOR.$path.$cacheDataName.".headers", |
|
499 | 499 | $cache, null, Cache::JSON); |
500 | 500 | Template::getInstance()->renderCache($cachedData, $headers); |
501 | 501 | $execute = FALSE; |
@@ -538,10 +538,10 @@ discard block |
||
538 | 538 | private function loadExternalAutoloader($hydrateRoute, SplFileInfo $modulePath, $externalModulePath) |
539 | 539 | { |
540 | 540 | $extModule = $modulePath->getBasename(); |
541 | - $moduleAutoloader = realpath($externalModulePath . DIRECTORY_SEPARATOR . $extModule . DIRECTORY_SEPARATOR . 'autoload.php'); |
|
541 | + $moduleAutoloader = realpath($externalModulePath.DIRECTORY_SEPARATOR.$extModule.DIRECTORY_SEPARATOR.'autoload.php'); |
|
542 | 542 | @include $moduleAutoloader; |
543 | 543 | if ($hydrateRoute) { |
544 | - $this->routing = $this->inspectDir($externalModulePath . DIRECTORY_SEPARATOR . $extModule, '\\' . $extModule, $this->routing); |
|
544 | + $this->routing = $this->inspectDir($externalModulePath.DIRECTORY_SEPARATOR.$extModule, '\\'.$extModule, $this->routing); |
|
545 | 545 | } |
546 | 546 | } |
547 | 547 | |
@@ -554,12 +554,12 @@ discard block |
||
554 | 554 | { |
555 | 555 | try { |
556 | 556 | $module = preg_replace('/(\\\|\/)/', DIRECTORY_SEPARATOR, $module); |
557 | - $externalModulePath = VENDOR_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'src'; |
|
557 | + $externalModulePath = VENDOR_DIR.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'src'; |
|
558 | 558 | $externalModule = $this->finder->directories()->in($externalModulePath)->depth(0); |
559 | 559 | foreach ($externalModule as $modulePath) { |
560 | 560 | $this->loadExternalAutoloader($hydrateRoute, $modulePath, $externalModulePath); |
561 | 561 | } |
562 | - } catch (\Exception $e) { |
|
562 | + }catch (\Exception $e) { |
|
563 | 563 | Logger::log($e->getMessage(), LOG_WARNING); |
564 | 564 | $module = null; |
565 | 565 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | { |
35 | 35 | $platform = trim(Config::getInstance()->get("platform.name")); |
36 | 36 | header('HTTP/1.1 401 Unauthorized'); |
37 | - header('WWW-Authenticate: Basic Realm="' . $platform . '"'); |
|
37 | + header('WWW-Authenticate: Basic Realm="'.$platform.'"'); |
|
38 | 38 | echo _("Zona restringida"); |
39 | 39 | exit(); |
40 | 40 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | $admin['class'] = 'primary'; |
76 | 76 | break; |
77 | 77 | } |
78 | - } else { |
|
78 | + }else { |
|
79 | 79 | $admin["class"] = "primary"; |
80 | 80 | } |
81 | 81 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | $logs = array(); |
93 | 93 | /** @var \SplFileInfo $file */ |
94 | 94 | foreach ($files as $file) { |
95 | - $size = $file->getSize() / 8 / 1024; |
|
95 | + $size = $file->getSize()/8/1024; |
|
96 | 96 | $time = date("c", $file->getMTime()); |
97 | 97 | $dateTime = new \DateTime($time); |
98 | 98 | if (!isset($logs[$dateTime->format("Y")])) $logs[$dateTime->format("Y")] = array(); |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | $time = date("c", $file->getMTime()); |
129 | 129 | $dateTime = new \DateTime($time); |
130 | 130 | $monthOpen = $dateTime->format("m"); |
131 | - $content = file($file->getPath() . DIRECTORY_SEPARATOR . $file->getFilename()); |
|
131 | + $content = file($file->getPath().DIRECTORY_SEPARATOR.$file->getFilename()); |
|
132 | 132 | krsort($content); |
133 | 133 | $detailLog = array(); |
134 | 134 | foreach ($content as &$line) { |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | break; |
182 | 182 | } |
183 | 183 | |
184 | - } catch (\Exception $e) { |
|
184 | + }catch (\Exception $e) { |
|
185 | 185 | $detail = array( |
186 | 186 | "type" => "danger", |
187 | 187 | ); |