@@ -26,13 +26,13 @@ |
||
26 | 26 | { |
27 | 27 | $namespace = explode('\\', $this->getModelTableMap()); |
28 | 28 | $module = strtolower($namespace[0]); |
29 | - $secret = Config::getInstance()->get($module . '.api.secret'); |
|
29 | + $secret = Config::getInstance()->get($module.'.api.secret'); |
|
30 | 30 | if (NULL === $secret) { |
31 | 31 | $secret = Config::getInstance()->get("api.secret"); |
32 | 32 | } |
33 | 33 | if (NULL === $secret) { |
34 | 34 | $auth = TRUE; |
35 | - } else { |
|
35 | + }else { |
|
36 | 36 | $token = Request::getInstance()->getHeader('X-API-SEC-TOKEN'); |
37 | 37 | if (array_key_exists('API_TOKEN', $this->query)) { |
38 | 38 | $token = $this->query['API_TOKEN']; |
@@ -7,7 +7,19 @@ |
||
7 | 7 | * @package PSFS\base\types\interfaces |
8 | 8 | */ |
9 | 9 | interface AuthInterface { |
10 | + |
|
11 | + /** |
|
12 | + * @return boolean |
|
13 | + */ |
|
10 | 14 | function isLogged(); |
15 | + |
|
16 | + /** |
|
17 | + * @return boolean |
|
18 | + */ |
|
11 | 19 | function isAdmin(); |
20 | + |
|
21 | + /** |
|
22 | + * @return boolean |
|
23 | + */ |
|
12 | 24 | function canDo($action); |
13 | 25 | } |
@@ -7,6 +7,14 @@ |
||
7 | 7 | * @package PSFS\base\types\interfaces |
8 | 8 | */ |
9 | 9 | interface ControllerInterface { |
10 | + |
|
11 | + /** |
|
12 | + * @return string|null |
|
13 | + */ |
|
10 | 14 | public function render($template, Array $vars = null); |
15 | + |
|
16 | + /** |
|
17 | + * @return void |
|
18 | + */ |
|
11 | 19 | public function response($response, $type = 'text/html'); |
12 | 20 | } |
@@ -371,7 +371,7 @@ |
||
371 | 371 | * @param array $parts |
372 | 372 | * @param int $partLength |
373 | 373 | * |
374 | - * @return array |
|
374 | + * @return string[] |
|
375 | 375 | */ |
376 | 376 | private static function extractTsAndMod(array &$parts, $partLength) |
377 | 377 | { |
@@ -422,7 +422,7 @@ |
||
422 | 422 | "type" => $type, |
423 | 423 | ]; |
424 | 424 | if (strlen($format)) { |
425 | - $dto['properties'][$field]['format'] = $format; |
|
425 | + $dto['properties'][$field]['format'] = $format; |
|
426 | 426 | } |
427 | 427 | } |
428 | 428 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | if (!preg_match('/^\@ROOT/i', $domain)) { |
35 | 35 | $modules[] = str_replace('/', '', str_replace('@', '', $domain)); |
36 | 36 | } |
37 | - } catch (\Exception $e) { |
|
37 | + }catch (\Exception $e) { |
|
38 | 38 | $modules[] = $e->getMessage(); |
39 | 39 | } |
40 | 40 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public function extractApiEndpoints($module) |
54 | 54 | { |
55 | - $module_path = CORE_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . "Api"; |
|
55 | + $module_path = CORE_DIR.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR."Api"; |
|
56 | 56 | $endpoints = []; |
57 | 57 | if (file_exists($module_path)) { |
58 | 58 | $finder = new Finder(); |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | if (count($finder)) { |
61 | 61 | /** @var \SplFileInfo $file */ |
62 | 62 | foreach ($finder as $file) { |
63 | - $namespace = "\\{$module}\\Api\\" . str_replace('.php', '', $file->getFilename()); |
|
63 | + $namespace = "\\{$module}\\Api\\".str_replace('.php', '', $file->getFilename()); |
|
64 | 64 | $endpoints[$namespace] = $this->extractApiInfo($namespace); |
65 | 65 | } |
66 | 66 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | if (NULL !== $mInfo) { |
90 | 90 | $info[] = $mInfo; |
91 | 91 | } |
92 | - } catch (\Exception $e) { |
|
92 | + }catch (\Exception $e) { |
|
93 | 93 | Logger::getInstance()->errorLog($e->getMessage()); |
94 | 94 | } |
95 | 95 | } |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | */ |
237 | 237 | protected function extractReturn($model, $comments = '') |
238 | 238 | { |
239 | - $modelDto = []; |
|
239 | + $modelDto = []; |
|
240 | 240 | preg_match('/\@return\ (.*)\((.*)\)\n/i', $comments, $returnTypes); |
241 | 241 | if (count($returnTypes)) { |
242 | 242 | // Extract principal DTO information |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | } elseif (null !== $reflector && $reflector->isSubclassOf(self::DTO_INTERFACE)) { |
290 | 290 | $payload = $this->extractDtoProperties($namespace); |
291 | 291 | } |
292 | - } catch (\Exception $e) { |
|
292 | + }catch (\Exception $e) { |
|
293 | 293 | Logger::getInstance()->errorLog($e->getMessage()); |
294 | 294 | } |
295 | 295 | |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | if (in_array($methodInfo['method'], ['POST', 'PUT'])) { |
326 | 326 | $methodInfo['payload'] = $this->extractPayload($modelNamespace, $docComments); |
327 | 327 | } |
328 | - } catch (\Exception $e) { |
|
328 | + }catch (\Exception $e) { |
|
329 | 329 | jpre($e->getMessage()); |
330 | 330 | Logger::getInstance()->errorLog($e->getMessage()); |
331 | 331 | } |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | */ |
344 | 344 | public static function translateSwaggerFormats($format) |
345 | 345 | { |
346 | - switch(strtolower($format)) { |
|
346 | + switch (strtolower($format)) { |
|
347 | 347 | case 'bool': |
348 | 348 | case 'boolean': |
349 | 349 | $swaggerType = 'boolean'; |
@@ -404,13 +404,13 @@ discard block |
||
404 | 404 | ]]); |
405 | 405 | if (array_key_exists($subDtoName, $subDto)) { |
406 | 406 | $definitions = $subDto; |
407 | - } else { |
|
407 | + }else { |
|
408 | 408 | $definitions[$subDtoName] = $subDto; |
409 | 409 | } |
410 | 410 | $dto['properties'][$field] = [ |
411 | - '$ref' => "#/definitions/" . $subDtoName, |
|
411 | + '$ref' => "#/definitions/".$subDtoName, |
|
412 | 412 | ]; |
413 | - } else { |
|
413 | + }else { |
|
414 | 414 | list($type, $format) = self::translateSwaggerFormats($format); |
415 | 415 | $dto['properties'][$field] = [ |
416 | 416 | "type" => $type, |
@@ -447,7 +447,7 @@ discard block |
||
447 | 447 | "url" => Router::getInstance()->getRoute(''), |
448 | 448 | ] |
449 | 449 | ]; |
450 | - foreach($endpoints as $model) { |
|
450 | + foreach ($endpoints as $model) { |
|
451 | 451 | foreach ($model as $endpoint) { |
452 | 452 | $dtos += self::extractSwaggerDefinition($endpoint); |
453 | 453 | } |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | protected function extractDtoName($dto, $isArray = false) |
467 | 467 | { |
468 | 468 | $dto = explode('\\', $dto); |
469 | - $modelDto = array_pop($dto) . "Dto"; |
|
469 | + $modelDto = array_pop($dto)."Dto"; |
|
470 | 470 | if ($isArray) { |
471 | 471 | $modelDto .= "List"; |
472 | 472 | } |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | * |
181 | 181 | * @param ModelCriteria $query |
182 | 182 | */ |
183 | - private function addOrders(ModelCriteria &$query) |
|
183 | + private function addOrders(ModelCriteria & $query) |
|
184 | 184 | { |
185 | 185 | $orderAdded = FALSE; |
186 | 186 | foreach ($this->order->getOrders() as $field => $direction) { |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | $orderAdded = TRUE; |
189 | 189 | if ($direction === Order::ASC) { |
190 | 190 | $query->addAscendingOrderByColumn($field); |
191 | - } else { |
|
191 | + }else { |
|
192 | 192 | $query->addDescendingOrderByColumn($field); |
193 | 193 | } |
194 | 194 | } |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * |
204 | 204 | * @param ModelCriteria $query |
205 | 205 | */ |
206 | - private function addExtraColumns(ModelCriteria &$query) |
|
206 | + private function addExtraColumns(ModelCriteria & $query) |
|
207 | 207 | { |
208 | 208 | if (!empty($this->extraColumns)) { |
209 | 209 | foreach ($this->extraColumns as $expression => $columnName) { |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * |
218 | 218 | * @param ModelCriteria $query |
219 | 219 | */ |
220 | - protected function joinTables(ModelCriteria &$query) |
|
220 | + protected function joinTables(ModelCriteria & $query) |
|
221 | 221 | { |
222 | 222 | //TODO for specific implementations |
223 | 223 | } |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | * |
228 | 228 | * @param ModelCriteria $query |
229 | 229 | */ |
230 | - private function addFilters(ModelCriteria &$query) |
|
230 | + private function addFilters(ModelCriteria & $query) |
|
231 | 231 | { |
232 | 232 | if (count($this->query) > 0) { |
233 | 233 | foreach ($this->query as $field => $value) { |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | $text = preg_replace('/(\'|\")/', '', $value); |
246 | 246 | $text = preg_replace('/\ /', '%', $text); |
247 | 247 | $query->filterBy($tableField, '%'.$text.'%', Criteria::LIKE); |
248 | - } else { |
|
248 | + }else { |
|
249 | 249 | $query->filterBy($tableField, $value, Criteria::EQUAL); |
250 | 250 | } |
251 | 251 | } |
@@ -268,10 +268,10 @@ discard block |
||
268 | 268 | list($page, $limit) = $this->extractPagination(); |
269 | 269 | if ($limit == -1) { |
270 | 270 | $this->list = $query->find($this->con); |
271 | - } else { |
|
271 | + }else { |
|
272 | 272 | $this->list = $query->paginate($page, $limit, $this->con); |
273 | 273 | } |
274 | - } catch (\Exception $e) { |
|
274 | + }catch (\Exception $e) { |
|
275 | 275 | Logger::getInstance(get_class($this))->errorLog($e->getMessage()); |
276 | 276 | } |
277 | 277 | } |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | $this->joinTables($query); |
289 | 289 | $this->addExtraColumns($query); |
290 | 290 | $this->model = $query->findPk($pk); |
291 | - } catch (\Exception $e) { |
|
291 | + }catch (\Exception $e) { |
|
292 | 292 | Logger::getInstance(get_class($this))->errorLog($e->getMessage()); |
293 | 293 | } |
294 | 294 | } |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | $saved = TRUE; |
377 | 377 | $model = $this->model->toArray(); |
378 | 378 | } |
379 | - } catch (\Exception $e) { |
|
379 | + }catch (\Exception $e) { |
|
380 | 380 | jpre($e->getMessage(), TRUE); |
381 | 381 | Logger::getInstance()->errorLog($e->getMessage()); |
382 | 382 | } |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | $this->model->delete($this->con); |
406 | 406 | $deleted = TRUE; |
407 | 407 | } |
408 | - } catch (\Exception $e) { |
|
408 | + }catch (\Exception $e) { |
|
409 | 409 | Logger::getInstance(get_class($this->model))->errorLog($e->getMessage()); |
410 | 410 | } |
411 | 411 | } |
@@ -449,7 +449,7 @@ discard block |
||
449 | 449 | */ |
450 | 450 | private function extractQuery() |
451 | 451 | { |
452 | - $queryReflector = new \ReflectionClass($this->getModelNamespace() . "Query"); |
|
452 | + $queryReflector = new \ReflectionClass($this->getModelNamespace()."Query"); |
|
453 | 453 | /** @var \Propel\Runtime\ActiveQuery\ModelCriteria $query */ |
454 | 454 | $query = $queryReflector->getMethod('create')->invoke(NULL); |
455 | 455 | |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | if ($this->con->inTransaction()) { |
494 | 494 | if ($status === 200) { |
495 | 495 | $this->con->commit(); |
496 | - } else { |
|
496 | + }else { |
|
497 | 497 | $this->con->rollBack(); |
498 | 498 | } |
499 | 499 | } |
@@ -537,7 +537,7 @@ discard block |
||
537 | 537 | return $this->render('api.admin.html.twig', array( |
538 | 538 | "api" => $this->getApi(), |
539 | 539 | "domain" => $this->domain, |
540 | - "url" => preg_replace('/\/\{(.*)\}$/i', '', $this->getRoute(strtolower('api-' . $this->getApi() . "-pk"), TRUE)), |
|
540 | + "url" => preg_replace('/\/\{(.*)\}$/i', '', $this->getRoute(strtolower('api-'.$this->getApi()."-pk"), TRUE)), |
|
541 | 541 | )); |
542 | 542 | } |
543 | 543 | |
@@ -559,16 +559,16 @@ discard block |
||
559 | 559 | /** @var TableMap $map */ |
560 | 560 | $map = $this->getModelTableMap(); |
561 | 561 | $fields = $map::getTableMap(); |
562 | - foreach($fields->getFieldNames() as $field) { |
|
562 | + foreach ($fields->getFieldNames() as $field) { |
|
563 | 563 | $fDto = new Field($field, _($field)); |
564 | 564 | /** @var ColumnMap $mappedColumn */ |
565 | 565 | $mappedColumn = $fields->getColumn($field); |
566 | - if($mappedColumn->isForeignKey()) { |
|
566 | + if ($mappedColumn->isForeignKey()) { |
|
567 | 567 | $fDto->type = Field::COMBO_TYPE; |
568 | 568 | $fDto->required = $mappedColumn->isNotNull(); |
569 | 569 | $relatedModel = strtolower($mappedColumn->getRelation()->getForeignTable()->getPhpName()); |
570 | 570 | $fDto->entity = $relatedModel; |
571 | - $fDto->url = Router::getInstance()->getRoute('api-' . $relatedModel . '-pk'); |
|
571 | + $fDto->url = Router::getInstance()->getRoute('api-'.$relatedModel.'-pk'); |
|
572 | 572 | } elseif ($mappedColumn->isPrimaryKey()) { |
573 | 573 | $fDto->type = Field::HIDDEN_TYPE; |
574 | 574 | $fDto->required = false; |
@@ -595,7 +595,7 @@ discard block |
||
595 | 595 | $return = $this->list->toArray(); |
596 | 596 | $total = $this->list->getNbResults(); |
597 | 597 | $pages = $this->list->getLastPage(); |
598 | - } catch (\Exception $e) { |
|
598 | + }catch (\Exception $e) { |
|
599 | 599 | Logger::getInstance(get_class($this))->errorLog($e->getMessage()); |
600 | 600 | } |
601 | 601 | |
@@ -615,7 +615,7 @@ discard block |
||
615 | 615 | $return = array(); |
616 | 616 | if (NULL === $model) { |
617 | 617 | $code = 404; |
618 | - } else { |
|
618 | + }else { |
|
619 | 619 | $return = $model->toArray(); |
620 | 620 | } |
621 | 621 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | use PSFS\controller\Admin; |
7 | 7 | use Symfony\Component\Finder\Finder; |
8 | 8 | |
9 | - class AdminServices extends Service{ |
|
9 | + class AdminServices extends Service { |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * @Inyectable |
@@ -30,10 +30,10 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function setAdminHeaders() |
32 | 32 | { |
33 | - if("login" === $this->config->get("admin_login")) return Admin::getInstance()->adminLogin("admin-setup"); |
|
33 | + if ("login" === $this->config->get("admin_login")) return Admin::getInstance()->adminLogin("admin-setup"); |
|
34 | 34 | $platform = trim(Config::getInstance()->get("platform_name")); |
35 | 35 | header('HTTP/1.1 401 Unauthorized'); |
36 | - header('WWW-Authenticate: Basic Realm="' . $platform. '"'); |
|
36 | + header('WWW-Authenticate: Basic Realm="'.$platform.'"'); |
|
37 | 37 | echo _("Zona restringida"); |
38 | 38 | exit(); |
39 | 39 | } |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | public function getAdmins() |
46 | 46 | { |
47 | 47 | $admins = $this->security->getAdmins(); |
48 | - if(!empty($admins)) |
|
48 | + if (!empty($admins)) |
|
49 | 49 | { |
50 | - if(!$this->security->checkAdmin()) |
|
50 | + if (!$this->security->checkAdmin()) |
|
51 | 51 | { |
52 | 52 | $this->setAdminHeaders(); |
53 | 53 | } |
@@ -62,17 +62,17 @@ discard block |
||
62 | 62 | */ |
63 | 63 | private function parseAdmins(&$admins) |
64 | 64 | { |
65 | - if(!empty($admins)) foreach($admins as &$admin) |
|
65 | + if (!empty($admins)) foreach ($admins as &$admin) |
|
66 | 66 | { |
67 | - if(isset($admin["profile"])) |
|
67 | + if (isset($admin["profile"])) |
|
68 | 68 | { |
69 | - switch($admin["profile"]) { |
|
69 | + switch ($admin["profile"]) { |
|
70 | 70 | case sha1('admin'): $admin['class'] = 'warning'; break; |
71 | 71 | case sha1('superadmin'): $admin['class'] = 'info'; break; |
72 | 72 | default: |
73 | 73 | case sha1('user'): $admin['class'] = 'primary'; break; |
74 | 74 | } |
75 | - }else{ |
|
75 | + }else { |
|
76 | 76 | $admin["class"] = "primary"; |
77 | 77 | } |
78 | 78 | } |
@@ -88,12 +88,12 @@ discard block |
||
88 | 88 | $files->files()->in(LOG_DIR)->name("*.log")->sortByModifiedTime(); |
89 | 89 | $logs = array(); |
90 | 90 | /** @var \SplFileInfo $file */ |
91 | - foreach($files as $file) |
|
91 | + foreach ($files as $file) |
|
92 | 92 | { |
93 | - $size = $file->getSize() / 8 / 1024; |
|
93 | + $size = $file->getSize()/8/1024; |
|
94 | 94 | $time = date("c", $file->getMTime()); |
95 | 95 | $dateTime = new \DateTime($time); |
96 | - if(!isset($logs[$dateTime->format("Y")])) $logs[$dateTime->format("Y")] = array(); |
|
96 | + if (!isset($logs[$dateTime->format("Y")])) $logs[$dateTime->format("Y")] = array(); |
|
97 | 97 | $logs[$dateTime->format("Y")][$dateTime->format("m")][$time] = array( |
98 | 98 | "filename" => $file->getFilename(), |
99 | 99 | "size" => round($size, 3) |
@@ -117,27 +117,27 @@ discard block |
||
117 | 117 | $files->files()->in(LOG_DIR)->name($selectedLog); |
118 | 118 | $file = null; |
119 | 119 | $log = array(); |
120 | - foreach($files as $match) |
|
120 | + foreach ($files as $match) |
|
121 | 121 | { |
122 | 122 | $file = $match; |
123 | 123 | break; |
124 | 124 | } |
125 | 125 | /** @var \SplFileInfo $file */ |
126 | - if(!empty($file)) |
|
126 | + if (!empty($file)) |
|
127 | 127 | { |
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 | - foreach($content as &$line) |
|
134 | + foreach ($content as &$line) |
|
135 | 135 | { |
136 | 136 | list($line, $detail) = $this->parseLogLine($line, $match); |
137 | 137 | $detailLog[] = array_merge(array( |
138 | 138 | "log" => $line, |
139 | 139 | ), $detail); |
140 | - if(count($detailLog) >= 1000) break; |
|
140 | + if (count($detailLog) >= 1000) break; |
|
141 | 141 | } |
142 | 142 | $log = $detailLog; |
143 | 143 | } |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | |
167 | 167 | $type = (isset($match[1][0])) ? $match[1][0] : ''; |
168 | 168 | $type = explode(".", $type); |
169 | - $type = count($type)>1 ? $type[1] : $type[0]; |
|
169 | + $type = count($type) > 1 ? $type[1] : $type[0]; |
|
170 | 170 | switch ($type) { |
171 | 171 | case 'INFO': |
172 | 172 | $detail["type"] = "success"; |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | break; |
183 | 183 | } |
184 | 184 | |
185 | - } catch (\Exception $e) { |
|
185 | + }catch (\Exception $e) { |
|
186 | 186 | $detail = array( |
187 | 187 | "type" => "danger", |
188 | 188 | ); |
@@ -31,7 +31,9 @@ discard block |
||
31 | 31 | */ |
32 | 32 | public function setAdminHeaders() |
33 | 33 | { |
34 | - if("login" === $this->config->get("admin_login")) return Admin::getInstance()->adminLogin("admin-setup"); |
|
34 | + if("login" === $this->config->get("admin_login")) { |
|
35 | + return Admin::getInstance()->adminLogin("admin-setup"); |
|
36 | + } |
|
35 | 37 | $platform = trim(Config::getInstance()->get("platform_name")); |
36 | 38 | header('HTTP/1.1 401 Unauthorized'); |
37 | 39 | header('WWW-Authenticate: Basic Realm="' . $platform. '"'); |
@@ -63,17 +65,20 @@ discard block |
||
63 | 65 | */ |
64 | 66 | private function parseAdmins(&$admins) |
65 | 67 | { |
66 | - if(!empty($admins)) foreach($admins as &$admin) |
|
68 | + if(!empty($admins)) { |
|
69 | + foreach($admins as &$admin) |
|
67 | 70 | { |
68 | 71 | if(isset($admin["profile"])) |
69 | 72 | { |
70 | 73 | switch($admin["profile"]) { |
71 | - case Security::MANAGER_ID_TOKEN: $admin['class'] = 'warning'; break; |
|
74 | + case Security::MANAGER_ID_TOKEN: $admin['class'] = 'warning'; |
|
75 | + } |
|
76 | + break; |
|
72 | 77 | case Security::ADMIN_ID_TOKEN: $admin['class'] = 'info'; break; |
73 | 78 | default: |
74 | 79 | case Security::USER_ID_TOKEN: $admin['class'] = 'primary'; break; |
75 | 80 | } |
76 | - }else{ |
|
81 | + } else{ |
|
77 | 82 | $admin["class"] = "primary"; |
78 | 83 | } |
79 | 84 | } |
@@ -94,7 +99,9 @@ discard block |
||
94 | 99 | $size = $file->getSize() / 8 / 1024; |
95 | 100 | $time = date("c", $file->getMTime()); |
96 | 101 | $dateTime = new \DateTime($time); |
97 | - if(!isset($logs[$dateTime->format("Y")])) $logs[$dateTime->format("Y")] = array(); |
|
102 | + if(!isset($logs[$dateTime->format("Y")])) { |
|
103 | + $logs[$dateTime->format("Y")] = array(); |
|
104 | + } |
|
98 | 105 | $logs[$dateTime->format("Y")][$dateTime->format("m")][$time] = array( |
99 | 106 | "filename" => $file->getFilename(), |
100 | 107 | "size" => round($size, 3) |
@@ -138,7 +145,9 @@ discard block |
||
138 | 145 | $detailLog[] = array_merge(array( |
139 | 146 | "log" => $line, |
140 | 147 | ), $detail); |
141 | - if(count($detailLog) >= 1000) break; |
|
148 | + if(count($detailLog) >= 1000) { |
|
149 | + break; |
|
150 | + } |
|
142 | 151 | } |
143 | 152 | $log = $detailLog; |
144 | 153 | } |
@@ -162,7 +171,9 @@ discard block |
||
162 | 171 | |
163 | 172 | $detail = json_decode($match[0][0], TRUE); |
164 | 173 | } |
165 | - if (empty($detail)) $detail = array(); |
|
174 | + if (empty($detail)) { |
|
175 | + $detail = array(); |
|
176 | + } |
|
166 | 177 | preg_match_all('/\>\ (.*):/i', $line, $match); |
167 | 178 | |
168 | 179 | $type = (isset($match[1][0])) ? $match[1][0] : ''; |
@@ -121,6 +121,9 @@ |
||
121 | 121 | return self::getInstance()->getHeader($name); |
122 | 122 | } |
123 | 123 | |
124 | + /** |
|
125 | + * @return string |
|
126 | + */ |
|
124 | 127 | public function getHeader($name) |
125 | 128 | { |
126 | 129 | $header = null; |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | { |
217 | 217 | if (null === $url) $url = $this->server['HTTP_ORIGIN']; |
218 | 218 | ob_start(); |
219 | - header('Location: ' . $url); |
|
219 | + header('Location: '.$url); |
|
220 | 220 | ob_end_clean(); |
221 | 221 | exit(_("Redireccionando...")); |
222 | 222 | } |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | $host = $this->getServerName(); |
261 | 261 | $protocol = $protocol ? $this->getProtocol() : ''; |
262 | 262 | $url = ''; |
263 | - if (!empty($host) && !empty($protocol)) $url = $protocol . $host; |
|
263 | + if (!empty($host) && !empty($protocol)) $url = $protocol.$host; |
|
264 | 264 | return $url; |
265 | 265 | } |
266 | 266 |
@@ -8,9 +8,10 @@ discard block |
||
8 | 8 | function getallheaders() |
9 | 9 | { |
10 | 10 | $headers = array(); |
11 | - foreach ($_SERVER as $h => $v) |
|
12 | - if (preg_match('/HTTP_(.+)/', $h, $hp)) |
|
11 | + foreach ($_SERVER as $h => $v) { |
|
12 | + if (preg_match('/HTTP_(.+)/', $h, $hp)) |
|
13 | 13 | $headers[$hp[1]] = $v; |
14 | + } |
|
14 | 15 | return $headers; |
15 | 16 | } |
16 | 17 | } |
@@ -214,7 +215,9 @@ discard block |
||
214 | 215 | */ |
215 | 216 | public function redirect($url = null) |
216 | 217 | { |
217 | - if (null === $url) $url = $this->server['HTTP_ORIGIN']; |
|
218 | + if (null === $url) { |
|
219 | + $url = $this->server['HTTP_ORIGIN']; |
|
220 | + } |
|
218 | 221 | ob_start(); |
219 | 222 | header('Location: ' . $url); |
220 | 223 | ob_end_clean(); |
@@ -260,7 +263,9 @@ discard block |
||
260 | 263 | $host = $this->getServerName(); |
261 | 264 | $protocol = $protocol ? $this->getProtocol() : ''; |
262 | 265 | $url = ''; |
263 | - if (!empty($host) && !empty($protocol)) $url = $protocol . $host; |
|
266 | + if (!empty($host) && !empty($protocol)) { |
|
267 | + $url = $protocol . $host; |
|
268 | + } |
|
264 | 269 | return $url; |
265 | 270 | } |
266 | 271 |
@@ -617,7 +617,7 @@ discard block |
||
617 | 617 | /** |
618 | 618 | * Método que extrae los parámetros de una función |
619 | 619 | * |
620 | - * @param array $sr |
|
620 | + * @param string[] $sr |
|
621 | 621 | * @param \ReflectionMethod $method |
622 | 622 | * |
623 | 623 | * @return array |
@@ -670,7 +670,7 @@ discard block |
||
670 | 670 | * |
671 | 671 | * @param string $docComments |
672 | 672 | * |
673 | - * @return bool |
|
673 | + * @return string |
|
674 | 674 | */ |
675 | 675 | private function extractReflectionCacheability($docComments) |
676 | 676 | { |
@@ -286,8 +286,10 @@ discard block |
||
286 | 286 | $_route = explode("/", $url['path']); |
287 | 287 | $_pattern = explode("/", $pattern); |
288 | 288 | $get = array(); |
289 | - if (!empty($_pattern)) foreach ($_pattern as $index => $component) { |
|
289 | + if (!empty($_pattern)) { |
|
290 | + foreach ($_pattern as $index => $component) { |
|
290 | 291 | $_get = array(); |
292 | + } |
|
291 | 293 | preg_match_all('/^\{(.*)\}$/i', $component, $_get); |
292 | 294 | if (!empty($_get[1]) && isset($_route[$index])) { |
293 | 295 | $get[array_pop($_get[1])] = $_route[$index]; |
@@ -502,8 +504,10 @@ discard block |
||
502 | 504 | throw new RouterException(_("No existe la ruta especificada")); |
503 | 505 | } |
504 | 506 | $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug]; |
505 | - if (!empty($params)) foreach ($params as $key => $value) { |
|
507 | + if (!empty($params)) { |
|
508 | + foreach ($params as $key => $value) { |
|
506 | 509 | $url = str_replace("{" . $key . "}", $value, $url); |
510 | + } |
|
507 | 511 | } elseif (!empty($this->routing[$this->slugs[$slug]]["default"])) { |
508 | 512 | $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
509 | 513 | } |
@@ -628,12 +632,16 @@ discard block |
||
628 | 632 | $default = ''; |
629 | 633 | $params = array(); |
630 | 634 | $parameters = $method->getParameters(); |
631 | - if (count($parameters) > 0) foreach ($parameters as $param) { |
|
635 | + if (count($parameters) > 0) { |
|
636 | + foreach ($parameters as $param) { |
|
632 | 637 | if ($param->isOptional() && !is_array($param->getDefaultValue())) { |
633 | 638 | $params[$param->getName()] = $param->getDefaultValue(); |
639 | + } |
|
634 | 640 | $default = str_replace('{' . $param->getName() . '}', $param->getDefaultValue(), $regex); |
635 | 641 | } |
636 | - } else $default = $regex; |
|
642 | + } else { |
|
643 | + $default = $regex; |
|
644 | + } |
|
637 | 645 | |
638 | 646 | return array($regex, $default, $params); |
639 | 647 | } |
@@ -54,12 +54,12 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function init() |
56 | 56 | { |
57 | - if (!file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json") || Config::getInstance()->getDebugMode()) { |
|
57 | + if (!file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json") || Config::getInstance()->getDebugMode()) { |
|
58 | 58 | $this->hydrateRouting(); |
59 | 59 | $this->simpatize(); |
60 | - } else { |
|
61 | - list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", Cache::JSON, TRUE); |
|
62 | - $this->domains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", Cache::JSON, TRUE); |
|
60 | + }else { |
|
61 | + list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", Cache::JSON, TRUE); |
|
62 | + $this->domains = $this->cache->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", Cache::JSON, TRUE); |
|
63 | 63 | } |
64 | 64 | } |
65 | 65 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | "success" => FALSE, |
80 | 80 | "error" => $e->getMessage(), |
81 | 81 | )), 'application/json'); |
82 | - } else { |
|
82 | + }else { |
|
83 | 83 | if (NULL === $e) { |
84 | 84 | Logger::log('Not found page throwed without previus exception'); |
85 | 85 | $e = new \Exception(_('Page not found'), 404); |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public function getAllRoutes() { |
110 | 110 | $routes = []; |
111 | - foreach($this->routing as $path => $route) { |
|
112 | - if(array_key_exists('slug', $route)) { |
|
111 | + foreach ($this->routing as $path => $route) { |
|
112 | + if (array_key_exists('slug', $route)) { |
|
113 | 113 | $routes[$route['slug']] = $path; |
114 | 114 | } |
115 | 115 | } |
@@ -134,24 +134,24 @@ discard block |
||
134 | 134 | $this->checkRestrictedAccess($route); |
135 | 135 | //Search action and execute |
136 | 136 | $this->searchAction($route); |
137 | - } catch (AccessDeniedException $e) { |
|
137 | + }catch (AccessDeniedException $e) { |
|
138 | 138 | Logger::log(_('Solicitamos credenciales de acceso a zona restringida')); |
139 | 139 | if ('login' === Config::getInstance()->get('admin_login')) { |
140 | 140 | return $this->redirectLogin($route); |
141 | - } else { |
|
141 | + }else { |
|
142 | 142 | return $this->sentAuthHeader(); |
143 | 143 | } |
144 | - } catch (RouterException $r) { |
|
144 | + }catch (RouterException $r) { |
|
145 | 145 | if (FALSE !== preg_match('/\/$/', $route)) { |
146 | 146 | if (preg_match('/admin/', $route)) { |
147 | 147 | $default = Config::getInstance()->get('admin_action'); |
148 | - } else { |
|
148 | + }else { |
|
149 | 149 | $default = Config::getInstance()->get('home_action'); |
150 | 150 | } |
151 | 151 | |
152 | 152 | return $this->execute($this->getRoute($default)); |
153 | 153 | } |
154 | - } catch (\Exception $e) { |
|
154 | + }catch (\Exception $e) { |
|
155 | 155 | Logger::log($e->getMessage(), LOG_ERR); |
156 | 156 | throw $e; |
157 | 157 | } |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | $class = $this->getClassToCall($action); |
229 | 229 | try { |
230 | 230 | $this->executeCachedRoute($route, $action, $class, $get); |
231 | - } catch (\Exception $e) { |
|
231 | + }catch (\Exception $e) { |
|
232 | 232 | Logger::log($e->getMessage(), LOG_ERR); |
233 | 233 | throw new RouterException($e->getMessage(), 404, $e); |
234 | 234 | } |
@@ -316,13 +316,13 @@ discard block |
||
316 | 316 | $this->routing = $this->inspectDir($base, "PSFS", array()); |
317 | 317 | if (file_exists($modules)) { |
318 | 318 | $module = ""; |
319 | - if(file_exists($modules . DIRECTORY_SEPARATOR . 'module.json')) { |
|
320 | - $mod_cfg = json_decode(file_get_contents($modules . DIRECTORY_SEPARATOR . 'module.json'), true); |
|
319 | + if (file_exists($modules.DIRECTORY_SEPARATOR.'module.json')) { |
|
320 | + $mod_cfg = json_decode(file_get_contents($modules.DIRECTORY_SEPARATOR.'module.json'), true); |
|
321 | 321 | $module = $mod_cfg['module']; |
322 | 322 | } |
323 | 323 | $this->routing = $this->inspectDir($modules, $module, $this->routing); |
324 | 324 | } |
325 | - $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->domains, Cache::JSON, TRUE); |
|
325 | + $this->cache->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", $this->domains, Cache::JSON, TRUE); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | /** |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | $home_params = NULL; |
338 | 338 | foreach ($this->routing as $pattern => $params) { |
339 | 339 | list($method, $route) = $this->extractHttpRoute($pattern); |
340 | - if (preg_match("/" . preg_quote($route, "/") . "$/i", "/" . $home)) { |
|
340 | + if (preg_match("/".preg_quote($route, "/")."$/i", "/".$home)) { |
|
341 | 341 | $home_params = $params; |
342 | 342 | } |
343 | 343 | } |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->name("*.php"); |
363 | 363 | foreach ($files as $file) { |
364 | 364 | $filename = str_replace("/", '\\', str_replace($origen, '', $file->getPathname())); |
365 | - $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing); |
|
365 | + $routing = $this->addRouting($namespace.str_replace('.php', '', $filename), $routing); |
|
366 | 366 | } |
367 | 367 | $this->finder = new Finder(); |
368 | 368 | |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | $httpMethod = $this->extractReflectionHttpMethod($docComments); |
413 | 413 | $visible = $this->extractReflectionVisibility($docComments); |
414 | 414 | $expiration = $this->extractReflectionCacheability($docComments); |
415 | - $routing[$httpMethod . "#|#" . $regex] = array( |
|
415 | + $routing[$httpMethod."#|#".$regex] = array( |
|
416 | 416 | "class" => $namespace, |
417 | 417 | "method" => $method->getName(), |
418 | 418 | "params" => $params, |
@@ -442,9 +442,9 @@ discard block |
||
442 | 442 | { |
443 | 443 | //Calculamos los dominios para las plantillas |
444 | 444 | if ($class->hasConstant("DOMAIN")) { |
445 | - $domain = "@" . $class->getConstant("DOMAIN") . "/"; |
|
446 | - $path = dirname($class->getFileName()) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR; |
|
447 | - $path = realpath($path) . DIRECTORY_SEPARATOR; |
|
445 | + $domain = "@".$class->getConstant("DOMAIN")."/"; |
|
446 | + $path = dirname($class->getFileName()).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR; |
|
447 | + $path = realpath($path).DIRECTORY_SEPARATOR; |
|
448 | 448 | $tpl_path = "templates"; |
449 | 449 | $public_path = "public"; |
450 | 450 | $model_path = "models"; |
@@ -454,12 +454,12 @@ discard block |
||
454 | 454 | $model_path = ucfirst($model_path); |
455 | 455 | } |
456 | 456 | if ($class->hasConstant("TPL")) { |
457 | - $tpl_path .= DIRECTORY_SEPARATOR . $class->getConstant("TPL"); |
|
457 | + $tpl_path .= DIRECTORY_SEPARATOR.$class->getConstant("TPL"); |
|
458 | 458 | } |
459 | 459 | $this->domains[$domain] = array( |
460 | - "template" => $path . $tpl_path, |
|
461 | - "model" => $path . $model_path, |
|
462 | - "public" => $path . $public_path, |
|
460 | + "template" => $path.$tpl_path, |
|
461 | + "model" => $path.$model_path, |
|
462 | + "public" => $path.$public_path, |
|
463 | 463 | ); |
464 | 464 | } |
465 | 465 | |
@@ -472,11 +472,11 @@ discard block |
||
472 | 472 | */ |
473 | 473 | public function simpatize() |
474 | 474 | { |
475 | - $translationFileName = "translations" . DIRECTORY_SEPARATOR . "routes_translations.php"; |
|
476 | - $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName; |
|
475 | + $translationFileName = "translations".DIRECTORY_SEPARATOR."routes_translations.php"; |
|
476 | + $absoluteTranslationFileName = CACHE_DIR.DIRECTORY_SEPARATOR.$translationFileName; |
|
477 | 477 | $this->generateSlugs($absoluteTranslationFileName); |
478 | 478 | Config::createDir(CONFIG_DIR); |
479 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
479 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
480 | 480 | |
481 | 481 | return $this; |
482 | 482 | } |
@@ -527,16 +527,16 @@ discard block |
||
527 | 527 | public function getRoute($slug = '', $absolute = FALSE, $params = []) |
528 | 528 | { |
529 | 529 | if (strlen($slug) === 0) { |
530 | - return ($absolute) ? Request::getInstance()->getRootUrl() . '/' : '/'; |
|
530 | + return ($absolute) ? Request::getInstance()->getRootUrl().'/' : '/'; |
|
531 | 531 | } |
532 | 532 | if (NULL === $slug || !array_key_exists($slug, $this->slugs)) { |
533 | 533 | throw new RouterException(_("No existe la ruta especificada")); |
534 | 534 | } |
535 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug]; |
|
535 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->slugs[$slug] : $this->slugs[$slug]; |
|
536 | 536 | if (!empty($params)) foreach ($params as $key => $value) { |
537 | - $url = str_replace("{" . $key . "}", $value, $url); |
|
537 | + $url = str_replace("{".$key."}", $value, $url); |
|
538 | 538 | } elseif (!empty($this->routing[$this->slugs[$slug]]["default"])) { |
539 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
|
539 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
|
540 | 540 | } |
541 | 541 | |
542 | 542 | return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url); |
@@ -554,7 +554,7 @@ discard block |
||
554 | 554 | if (preg_match('/^\/admin(\/|$)/', $routePattern)) { |
555 | 555 | if (preg_match('/^\\\?PSFS/', $params["class"])) { |
556 | 556 | $profile = "superadmin"; |
557 | - } else { |
|
557 | + }else { |
|
558 | 558 | $profile = "admin"; |
559 | 559 | } |
560 | 560 | if (!empty($params["default"]) && preg_match('/(GET|ALL)/i', $httpMethod)) { |
@@ -606,7 +606,7 @@ discard block |
||
606 | 606 | protected function getClassToCall($action) |
607 | 607 | { |
608 | 608 | Logger::log('Getting class to call for executing the request action', LOG_DEBUG, $action); |
609 | - $actionClass = class_exists($action["class"]) ? $action["class"] : "\\" . $action["class"]; |
|
609 | + $actionClass = class_exists($action["class"]) ? $action["class"] : "\\".$action["class"]; |
|
610 | 610 | $class = (method_exists($actionClass, "getInstance")) ? $actionClass::getInstance() : new $actionClass; |
611 | 611 | return $class; |
612 | 612 | } |
@@ -625,7 +625,7 @@ discard block |
||
625 | 625 | $expr = preg_quote($expr, '/'); |
626 | 626 | $expr = str_replace('###', '(.*)', $expr); |
627 | 627 | $expr2 = preg_replace('/\(\.\*\)$/', '', $expr); |
628 | - $matched = preg_match('/^' . $expr . '\/?$/i', $path) || preg_match('/^' . $expr2 . '?$/i', $path); |
|
628 | + $matched = preg_match('/^'.$expr.'\/?$/i', $path) || preg_match('/^'.$expr2.'?$/i', $path); |
|
629 | 629 | return $matched; |
630 | 630 | } |
631 | 631 | |
@@ -662,9 +662,9 @@ discard block |
||
662 | 662 | if (count($parameters) > 0) foreach ($parameters as $param) { |
663 | 663 | if ($param->isOptional() && !is_array($param->getDefaultValue())) { |
664 | 664 | $params[$param->getName()] = $param->getDefaultValue(); |
665 | - $default = str_replace('{' . $param->getName() . '}', $param->getDefaultValue(), $regex); |
|
665 | + $default = str_replace('{'.$param->getName().'}', $param->getDefaultValue(), $regex); |
|
666 | 666 | } |
667 | - } else $default = $regex; |
|
667 | + }else $default = $regex; |
|
668 | 668 | |
669 | 669 | return array($regex, $default, $params); |
670 | 670 | } |
@@ -720,17 +720,17 @@ discard block |
||
720 | 720 | */ |
721 | 721 | protected function executeCachedRoute($route, $action, $class, $params = NULL) |
722 | 722 | { |
723 | - Logger::log('Executing route ' . $route); |
|
723 | + Logger::log('Executing route '.$route); |
|
724 | 724 | Security::getInstance()->setSessionKey("__CACHE__", $action); |
725 | 725 | $cache = Cache::needCache(); |
726 | 726 | $execute = TRUE; |
727 | 727 | if (FALSE !== $cache && Config::getInstance()->getDebugMode() === FALSE) { |
728 | 728 | $cacheDataName = $this->cache->getRequestCacheHash(); |
729 | - $cachedData = $this->cache->readFromCache("templates" . DIRECTORY_SEPARATOR . $cacheDataName, |
|
730 | - $cache, function () {}); |
|
729 | + $cachedData = $this->cache->readFromCache("templates".DIRECTORY_SEPARATOR.$cacheDataName, |
|
730 | + $cache, function() {}); |
|
731 | 731 | if (NULL !== $cachedData) { |
732 | - $headers = $this->cache->readFromCache("templates" . DIRECTORY_SEPARATOR . $cacheDataName . ".headers", |
|
733 | - $cache, function () {}, Cache::JSON); |
|
732 | + $headers = $this->cache->readFromCache("templates".DIRECTORY_SEPARATOR.$cacheDataName.".headers", |
|
733 | + $cache, function() {}, Cache::JSON); |
|
734 | 734 | Template::getInstance()->renderCache($cachedData, $headers); |
735 | 735 | $execute = FALSE; |
736 | 736 | } |
@@ -776,7 +776,7 @@ discard block |
||
776 | 776 | $translations = array(); |
777 | 777 | if (file_exists($absoluteTranslationFileName)) { |
778 | 778 | include($absoluteTranslationFileName); |
779 | - } else { |
|
779 | + }else { |
|
780 | 780 | Cache::getInstance()->storeData($absoluteTranslationFileName, "<?php \$translations = array();\n", Cache::TEXT, TRUE); |
781 | 781 | } |
782 | 782 |
@@ -415,7 +415,7 @@ |
||
415 | 415 | * @param array $parts |
416 | 416 | * @param int $partLength |
417 | 417 | * |
418 | - * @return array |
|
418 | + * @return string[] |
|
419 | 419 | */ |
420 | 420 | private static function extractTsAndMod(array &$parts, $partLength) |
421 | 421 | { |
@@ -105,13 +105,13 @@ discard block |
||
105 | 105 | public static function save($user) |
106 | 106 | { |
107 | 107 | $admins = array(); |
108 | - if (file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json')) { |
|
109 | - $admins = json_decode(file_get_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json'), TRUE); |
|
108 | + if (file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json')) { |
|
109 | + $admins = json_decode(file_get_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json'), TRUE); |
|
110 | 110 | } |
111 | - $admins[$user['username']]['hash'] = sha1($user['username'] . $user['password']); |
|
111 | + $admins[$user['username']]['hash'] = sha1($user['username'].$user['password']); |
|
112 | 112 | $admins[$user['username']]['profile'] = $user['profile']; |
113 | 113 | |
114 | - return (FALSE !== file_put_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', json_encode($admins, JSON_PRETTY_PRINT))); |
|
114 | + return (FALSE !== file_put_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', json_encode($admins, JSON_PRETTY_PRINT))); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -145,8 +145,8 @@ discard block |
||
145 | 145 | public function getAdmins() |
146 | 146 | { |
147 | 147 | $admins = array(); |
148 | - if (file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json')) { |
|
149 | - $admins = json_decode(file_get_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json'), TRUE); |
|
148 | + if (file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json')) { |
|
149 | + $admins = json_decode(file_get_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json'), TRUE); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | return $admins; |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | Logger::log('Checking admin session'); |
167 | 167 | if (!$this->authorized) { |
168 | 168 | $request = Request::getInstance(); |
169 | - if (!file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json')) { |
|
169 | + if (!file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json')) { |
|
170 | 170 | //Si no hay fichero de usuarios redirigimos directamente al gestor |
171 | 171 | return Router::getInstance()->getAdmin()->adminers(); |
172 | 172 | } |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | } |
180 | 180 | if (!empty($user) && !empty($admins[$user])) { |
181 | 181 | $auth = $admins[$user]['hash']; |
182 | - $this->authorized = ($auth == sha1($user . $pass)); |
|
182 | + $this->authorized = ($auth == sha1($user.$pass)); |
|
183 | 183 | $this->admin = array( |
184 | 184 | 'alias' => $user, |
185 | 185 | 'profile' => $admins[$user]['profile'], |
@@ -398,12 +398,12 @@ discard block |
||
398 | 398 | $axis = 0; |
399 | 399 | $parts = array(); |
400 | 400 | try { |
401 | - $partLength = floor(strlen($token) / 10); |
|
402 | - for ($i = 0, $ct = ceil(strlen($token) / $partLength); $i < $ct; $i++) { |
|
401 | + $partLength = floor(strlen($token)/10); |
|
402 | + for ($i = 0, $ct = ceil(strlen($token)/$partLength); $i < $ct; $i++) { |
|
403 | 403 | $parts[] = substr($token, $axis, $partLength); |
404 | 404 | $axis += $partLength; |
405 | 405 | } |
406 | - } catch (\Exception $e) { |
|
406 | + }catch (\Exception $e) { |
|
407 | 407 | $partLength = 0; |
408 | 408 | } |
409 | 409 | |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | $decoded = NULL; |
444 | 444 | list($partLength, $parts) = self::extractTokenParts($token); |
445 | 445 | list($ts, $mod) = self::extractTsAndMod($parts, $partLength); |
446 | - $hashMod = substr(strtoupper(sha1($module)), strlen($ts) / 2, strlen($ts) * 2); |
|
446 | + $hashMod = substr(strtoupper(sha1($module)), strlen($ts)/2, strlen($ts)*2); |
|
447 | 447 | if (time() - (integer)$ts < 300 && $hashMod === $mod) { |
448 | 448 | $decoded = implode('', $parts); |
449 | 449 | } |
@@ -460,16 +460,16 @@ discard block |
||
460 | 460 | public static function generateToken($secret, $module = 'PSFS') |
461 | 461 | { |
462 | 462 | $ts = time(); |
463 | - $hashModule = substr(strtoupper(sha1($module)), strlen($ts) / 2, strlen($ts) * 2); |
|
463 | + $hashModule = substr(strtoupper(sha1($module)), strlen($ts)/2, strlen($ts)*2); |
|
464 | 464 | $hash = hash('sha256', $secret); |
465 | - $insert = floor(strlen($hash) / strlen($ts)); |
|
465 | + $insert = floor(strlen($hash)/strlen($ts)); |
|
466 | 466 | $j = 0; |
467 | 467 | $token = ''; |
468 | 468 | for ($i = 0, $ct = strlen($ts); $i < $ct; $i++) { |
469 | - $token .= substr($ts, $i, 1) . substr($hash, $j, $insert) . substr($hashModule, $i, 2); |
|
469 | + $token .= substr($ts, $i, 1).substr($hash, $j, $insert).substr($hashModule, $i, 2); |
|
470 | 470 | $j += $insert; |
471 | 471 | } |
472 | - $token .= substr($hash, ($insert * strlen($ts)), strlen($hash) - ($insert * strlen($ts))); |
|
472 | + $token .= substr($hash, ($insert*strlen($ts)), strlen($hash) - ($insert*strlen($ts))); |
|
473 | 473 | return $token; |
474 | 474 | } |
475 | 475 |