@@ -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 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | if (!preg_match('/^\@ROOT/i', $domain)) { |
34 | 34 | $modules[] = str_replace('/', '', str_replace('@', '', $domain)); |
35 | 35 | } |
36 | - } catch (\Exception $e) { |
|
36 | + }catch (\Exception $e) { |
|
37 | 37 | $modules[] = $e->getMessage(); |
38 | 38 | } |
39 | 39 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function extractApiEndpoints($module) |
53 | 53 | { |
54 | - $module_path = CORE_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . "Api"; |
|
54 | + $module_path = CORE_DIR.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR."Api"; |
|
55 | 55 | $endpoints = []; |
56 | 56 | if (file_exists($module_path)) { |
57 | 57 | $finder = new Finder(); |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | if (count($finder)) { |
60 | 60 | /** @var \SplFileInfo $file */ |
61 | 61 | foreach ($finder as $file) { |
62 | - $namespace = "\\{$module}\\Api\\" . str_replace('.php', '', $file->getFilename()); |
|
62 | + $namespace = "\\{$module}\\Api\\".str_replace('.php', '', $file->getFilename()); |
|
63 | 63 | $endpoints[$namespace] = $this->extractApiInfo($namespace); |
64 | 64 | } |
65 | 65 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | if (NULL !== $mInfo) { |
89 | 89 | $info[] = $mInfo; |
90 | 90 | } |
91 | - } catch (\Exception $e) { |
|
91 | + }catch (\Exception $e) { |
|
92 | 92 | Logger::getInstance()->errorLog($e->getMessage()); |
93 | 93 | } |
94 | 94 | } |
@@ -221,9 +221,9 @@ discard block |
||
221 | 221 | if ($reflector->isSubclassOf(self::DTO_INTERFACE)) { |
222 | 222 | foreach ($reflector->getProperties(\ReflectionMethod::IS_PUBLIC) as $property) { |
223 | 223 | $type = $this->extractVarType($property->getDocComment()); |
224 | - if(class_exists($type)) { |
|
224 | + if (class_exists($type)) { |
|
225 | 225 | $properties[$property->getName()] = $this->extractModelFields($type); |
226 | - } else { |
|
226 | + }else { |
|
227 | 227 | $properties[$property->getName()] = $type; |
228 | 228 | } |
229 | 229 | } |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | */ |
243 | 243 | protected function extractReturn($model, $comments = '') |
244 | 244 | { |
245 | - $modelDto = []; |
|
245 | + $modelDto = []; |
|
246 | 246 | preg_match('/\@return\ (.*)\((.*)\)\n/i', $comments, $returnTypes); |
247 | 247 | if (count($returnTypes)) { |
248 | 248 | // Extract principal DTO information |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | } elseif (null !== $reflector && $reflector->isSubclassOf(self::DTO_INTERFACE)) { |
296 | 296 | $payload = $this->extractDtoProperties($namespace); |
297 | 297 | } |
298 | - } catch (\Exception $e) { |
|
298 | + }catch (\Exception $e) { |
|
299 | 299 | Logger::getInstance()->errorLog($e->getMessage()); |
300 | 300 | } |
301 | 301 | |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | if (in_array($methodInfo['method'], ['POST', 'PUT'])) { |
332 | 332 | $methodInfo['payload'] = $this->extractPayload($modelNamespace, $docComments); |
333 | 333 | } |
334 | - } catch (\Exception $e) { |
|
334 | + }catch (\Exception $e) { |
|
335 | 335 | jpre($e->getMessage()); |
336 | 336 | Logger::getInstance()->errorLog($e->getMessage()); |
337 | 337 | } |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | */ |
350 | 350 | public static function translateSwaggerFormats($format) |
351 | 351 | { |
352 | - switch(strtolower($format)) { |
|
352 | + switch (strtolower($format)) { |
|
353 | 353 | case 'bool': |
354 | 354 | case 'boolean': |
355 | 355 | $swaggerType = 'boolean'; |
@@ -410,13 +410,13 @@ discard block |
||
410 | 410 | ]]); |
411 | 411 | if (array_key_exists($subDtoName, $subDto)) { |
412 | 412 | $definitions = $subDto; |
413 | - } else { |
|
413 | + }else { |
|
414 | 414 | $definitions[$subDtoName] = $subDto; |
415 | 415 | } |
416 | 416 | $dto['properties'][$field] = [ |
417 | - '$ref' => "#/definitions/" . $subDtoName, |
|
417 | + '$ref' => "#/definitions/".$subDtoName, |
|
418 | 418 | ]; |
419 | - } else { |
|
419 | + }else { |
|
420 | 420 | list($type, $format) = self::translateSwaggerFormats($format); |
421 | 421 | $dto['properties'][$field] = [ |
422 | 422 | "type" => $type, |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | "url" => Router::getInstance()->getRoute(''), |
454 | 454 | ] |
455 | 455 | ]; |
456 | - foreach($endpoints as $model) { |
|
456 | + foreach ($endpoints as $model) { |
|
457 | 457 | foreach ($model as $endpoint) { |
458 | 458 | $dtos += self::extractSwaggerDefinition($endpoint); |
459 | 459 | } |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | protected function extractDtoName($dto, $isArray = false) |
473 | 473 | { |
474 | 474 | $dto = explode('\\', $dto); |
475 | - $modelDto = array_pop($dto) . "Dto"; |
|
475 | + $modelDto = array_pop($dto)."Dto"; |
|
476 | 476 | if ($isArray) { |
477 | 477 | $modelDto .= "List"; |
478 | 478 | } |
@@ -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 | } |
@@ -317,19 +317,19 @@ discard block |
||
317 | 317 | $this->routing = $this->inspectDir($base, "PSFS", array()); |
318 | 318 | if (file_exists($modules)) { |
319 | 319 | $module = ""; |
320 | - if(file_exists($modules . DIRECTORY_SEPARATOR . 'module.json')) { |
|
321 | - $mod_cfg = json_decode(file_get_contents($modules . DIRECTORY_SEPARATOR . 'module.json'), true); |
|
320 | + if (file_exists($modules.DIRECTORY_SEPARATOR.'module.json')) { |
|
321 | + $mod_cfg = json_decode(file_get_contents($modules.DIRECTORY_SEPARATOR.'module.json'), true); |
|
322 | 322 | $module = $mod_cfg['module']; |
323 | 323 | } |
324 | 324 | $this->routing = $this->inspectDir($modules, $module, $this->routing); |
325 | 325 | } |
326 | - $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->domains, Cache::JSON, TRUE); |
|
326 | + $this->cache->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", $this->domains, Cache::JSON, TRUE); |
|
327 | 327 | $home = Config::getInstance()->get('home_action'); |
328 | 328 | if (NULL !== $home || $home !== '') { |
329 | 329 | $home_params = NULL; |
330 | 330 | foreach ($this->routing as $pattern => $params) { |
331 | 331 | list($method, $route) = $this->extractHttpRoute($pattern); |
332 | - if (preg_match("/" . preg_quote($route, "/") . "$/i", "/" . $home)) { |
|
332 | + if (preg_match("/".preg_quote($route, "/")."$/i", "/".$home)) { |
|
333 | 333 | $home_params = $params; |
334 | 334 | } |
335 | 335 | } |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->name("*.php"); |
355 | 355 | foreach ($files as $file) { |
356 | 356 | $filename = str_replace("/", '\\', str_replace($origen, '', $file->getPathname())); |
357 | - $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing); |
|
357 | + $routing = $this->addRouting($namespace.str_replace('.php', '', $filename), $routing); |
|
358 | 358 | } |
359 | 359 | $this->finder = new Finder(); |
360 | 360 | |
@@ -404,7 +404,7 @@ discard block |
||
404 | 404 | $httpMethod = $this->extractReflectionHttpMethod($docComments); |
405 | 405 | $visible = $this->extractReflectionVisibility($docComments); |
406 | 406 | $expiration = $this->extractReflectionCacheability($docComments); |
407 | - $routing[$httpMethod . "#|#" . $regex] = array( |
|
407 | + $routing[$httpMethod."#|#".$regex] = array( |
|
408 | 408 | "class" => $namespace, |
409 | 409 | "method" => $method->getName(), |
410 | 410 | "params" => $params, |
@@ -434,9 +434,9 @@ discard block |
||
434 | 434 | { |
435 | 435 | //Calculamos los dominios para las plantillas |
436 | 436 | if ($class->hasConstant("DOMAIN")) { |
437 | - $domain = "@" . $class->getConstant("DOMAIN") . "/"; |
|
438 | - $path = dirname($class->getFileName()) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR; |
|
439 | - $path = realpath($path) . DIRECTORY_SEPARATOR; |
|
437 | + $domain = "@".$class->getConstant("DOMAIN")."/"; |
|
438 | + $path = dirname($class->getFileName()).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR; |
|
439 | + $path = realpath($path).DIRECTORY_SEPARATOR; |
|
440 | 440 | $tpl_path = "templates"; |
441 | 441 | $public_path = "public"; |
442 | 442 | $model_path = "models"; |
@@ -446,12 +446,12 @@ discard block |
||
446 | 446 | $model_path = ucfirst($model_path); |
447 | 447 | } |
448 | 448 | if ($class->hasConstant("TPL")) { |
449 | - $tpl_path .= DIRECTORY_SEPARATOR . $class->getConstant("TPL"); |
|
449 | + $tpl_path .= DIRECTORY_SEPARATOR.$class->getConstant("TPL"); |
|
450 | 450 | } |
451 | 451 | $this->domains[$domain] = array( |
452 | - "template" => $path . $tpl_path, |
|
453 | - "model" => $path . $model_path, |
|
454 | - "public" => $path . $public_path, |
|
452 | + "template" => $path.$tpl_path, |
|
453 | + "model" => $path.$model_path, |
|
454 | + "public" => $path.$public_path, |
|
455 | 455 | ); |
456 | 456 | } |
457 | 457 | |
@@ -464,11 +464,11 @@ discard block |
||
464 | 464 | */ |
465 | 465 | public function simpatize() |
466 | 466 | { |
467 | - $translationFileName = "translations" . DIRECTORY_SEPARATOR . "routes_translations.php"; |
|
468 | - $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName; |
|
467 | + $translationFileName = "translations".DIRECTORY_SEPARATOR."routes_translations.php"; |
|
468 | + $absoluteTranslationFileName = CACHE_DIR.DIRECTORY_SEPARATOR.$translationFileName; |
|
469 | 469 | $this->generateSlugs($absoluteTranslationFileName); |
470 | 470 | Config::createDir(CONFIG_DIR); |
471 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
471 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR."urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
472 | 472 | |
473 | 473 | return $this; |
474 | 474 | } |
@@ -519,16 +519,16 @@ discard block |
||
519 | 519 | public function getRoute($slug = '', $absolute = FALSE, $params = NULL) |
520 | 520 | { |
521 | 521 | if (strlen($slug) === 0) { |
522 | - return ($absolute) ? Request::getInstance()->getRootUrl() . '/' : '/'; |
|
522 | + return ($absolute) ? Request::getInstance()->getRootUrl().'/' : '/'; |
|
523 | 523 | } |
524 | 524 | if (NULL === $slug || !array_key_exists($slug, $this->slugs)) { |
525 | 525 | throw new RouterException(_("No existe la ruta especificada")); |
526 | 526 | } |
527 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug]; |
|
527 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->slugs[$slug] : $this->slugs[$slug]; |
|
528 | 528 | if (!empty($params)) foreach ($params as $key => $value) { |
529 | - $url = str_replace("{" . $key . "}", $value, $url); |
|
529 | + $url = str_replace("{".$key."}", $value, $url); |
|
530 | 530 | } elseif (!empty($this->routing[$this->slugs[$slug]]["default"])) { |
531 | - $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
|
531 | + $url = ($absolute) ? Request::getInstance()->getRootUrl().$this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
|
532 | 532 | } |
533 | 533 | |
534 | 534 | return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url); |
@@ -546,7 +546,7 @@ discard block |
||
546 | 546 | if (preg_match('/^\/admin(\/|$)/', $routePattern)) { |
547 | 547 | if (preg_match('/^\\\?PSFS/', $params["class"])) { |
548 | 548 | $profile = "superadmin"; |
549 | - } else { |
|
549 | + }else { |
|
550 | 550 | $profile = "admin"; |
551 | 551 | } |
552 | 552 | if (!empty($params["default"]) && preg_match('/(GET|ALL)/i', $httpMethod)) { |
@@ -598,7 +598,7 @@ discard block |
||
598 | 598 | protected function getClassToCall($action) |
599 | 599 | { |
600 | 600 | Logger::log('Getting class to call for executing the request action', LOG_DEBUG, $action); |
601 | - $actionClass = class_exists($action["class"]) ? $action["class"] : "\\" . $action["class"]; |
|
601 | + $actionClass = class_exists($action["class"]) ? $action["class"] : "\\".$action["class"]; |
|
602 | 602 | $class = (method_exists($actionClass, "getInstance")) ? $actionClass::getInstance() : new $actionClass; |
603 | 603 | return $class; |
604 | 604 | } |
@@ -617,7 +617,7 @@ discard block |
||
617 | 617 | $expr = preg_quote($expr, '/'); |
618 | 618 | $expr = str_replace('###', '(.*)', $expr); |
619 | 619 | $expr2 = preg_replace('/\(\.\*\)$/', '', $expr); |
620 | - $matched = preg_match('/^' . $expr . '\/?$/i', $path) || preg_match('/^' . $expr2 . '?$/i', $path); |
|
620 | + $matched = preg_match('/^'.$expr.'\/?$/i', $path) || preg_match('/^'.$expr2.'?$/i', $path); |
|
621 | 621 | return $matched; |
622 | 622 | } |
623 | 623 | |
@@ -654,9 +654,9 @@ discard block |
||
654 | 654 | if (count($parameters) > 0) foreach ($parameters as $param) { |
655 | 655 | if ($param->isOptional() && !is_array($param->getDefaultValue())) { |
656 | 656 | $params[$param->getName()] = $param->getDefaultValue(); |
657 | - $default = str_replace('{' . $param->getName() . '}', $param->getDefaultValue(), $regex); |
|
657 | + $default = str_replace('{'.$param->getName().'}', $param->getDefaultValue(), $regex); |
|
658 | 658 | } |
659 | - } else $default = $regex; |
|
659 | + }else $default = $regex; |
|
660 | 660 | |
661 | 661 | return array($regex, $default, $params); |
662 | 662 | } |
@@ -712,16 +712,16 @@ discard block |
||
712 | 712 | */ |
713 | 713 | protected function executeCachedRoute($route, $action, $class, $params = NULL) |
714 | 714 | { |
715 | - Logger::log('Executing route ' . $route); |
|
715 | + Logger::log('Executing route '.$route); |
|
716 | 716 | Security::getInstance()->setSessionKey("__CACHE__", $action); |
717 | 717 | $cache = Cache::needCache(); |
718 | 718 | $execute = TRUE; |
719 | 719 | if (FALSE !== $cache && Config::getInstance()->getDebugMode() === FALSE) { |
720 | 720 | $cacheDataName = $this->cache->getRequestCacheHash(); |
721 | - $cachedData = $this->cache->readFromCache("templates" . DIRECTORY_SEPARATOR . $cacheDataName, $cache, function () { |
|
721 | + $cachedData = $this->cache->readFromCache("templates".DIRECTORY_SEPARATOR.$cacheDataName, $cache, function() { |
|
722 | 722 | }); |
723 | 723 | if (NULL !== $cachedData) { |
724 | - $headers = $this->cache->readFromCache("templates" . DIRECTORY_SEPARATOR . $cacheDataName . ".headers", $cache, function () { |
|
724 | + $headers = $this->cache->readFromCache("templates".DIRECTORY_SEPARATOR.$cacheDataName.".headers", $cache, function() { |
|
725 | 725 | }, Cache::JSON); |
726 | 726 | Template::getInstance()->renderCache($cachedData, $headers); |
727 | 727 | $execute = FALSE; |
@@ -768,7 +768,7 @@ discard block |
||
768 | 768 | $translations = array(); |
769 | 769 | if (file_exists($absoluteTranslationFileName)) { |
770 | 770 | include($absoluteTranslationFileName); |
771 | - } else { |
|
771 | + }else { |
|
772 | 772 | Cache::getInstance()->storeData($absoluteTranslationFileName, "<?php \$translations = array();\n", Cache::TEXT, TRUE); |
773 | 773 | } |
774 | 774 |
@@ -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 |