@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | class FileHelper { |
10 | 10 | /** |
11 | - * @param mixed $data |
|
11 | + * @param string $data |
|
12 | 12 | * @param string $path |
13 | 13 | * @return int |
14 | 14 | */ |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | |
19 | 19 | /** |
20 | 20 | * @param string $path |
21 | - * @return mixed|bool |
|
21 | + * @return string|false |
|
22 | 22 | */ |
23 | 23 | public static function readFile($path) { |
24 | 24 | $data = false; |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
54 | - * @param $path |
|
55 | - * @return bool |
|
54 | + * @param string $path |
|
55 | + * @return boolean|null |
|
56 | 56 | */ |
57 | 57 | public static function deleteDir($path) { |
58 | 58 | (new Filesystem())->remove($path); |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | */ |
23 | 23 | public static function readFile($path) { |
24 | 24 | $data = false; |
25 | - if(file_exists($path)) { |
|
25 | + if (file_exists($path)) { |
|
26 | 26 | $data = file_get_contents($path); |
27 | 27 | } |
28 | 28 | return $data; |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * @return string |
36 | 36 | */ |
37 | 37 | public static function generateHashFilename($verb, $slug, array $query = []) { |
38 | - return sha1(strtolower($verb) . " " . $slug . " " . strtolower(http_build_query($query))); |
|
38 | + return sha1(strtolower($verb)." ".$slug." ".strtolower(http_build_query($query))); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -46,8 +46,8 @@ discard block |
||
46 | 46 | public static function generateCachePath(array $action, array $query = []) { |
47 | 47 | $class = GeneratorHelper::extractClassFromNamespace($action['class']); |
48 | 48 | $filename = self::generateHashFilename($action["http"], $action["slug"], $query); |
49 | - $subPath = substr($filename, 0, 2) . DIRECTORY_SEPARATOR . substr($filename, 2, 2); |
|
50 | - return $action['module'] . DIRECTORY_SEPARATOR . $class . DIRECTORY_SEPARATOR . $action['method'] . DIRECTORY_SEPARATOR . $subPath . DIRECTORY_SEPARATOR; |
|
49 | + $subPath = substr($filename, 0, 2).DIRECTORY_SEPARATOR.substr($filename, 2, 2); |
|
50 | + return $action['module'].DIRECTORY_SEPARATOR.$class.DIRECTORY_SEPARATOR.$action['method'].DIRECTORY_SEPARATOR.$subPath.DIRECTORY_SEPARATOR; |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -196,7 +196,7 @@ |
||
196 | 196 | /** |
197 | 197 | * Method that returns a config value |
198 | 198 | * @param string $param |
199 | - * @param mixed $defaultValue |
|
199 | + * @param string $defaultValue |
|
200 | 200 | * |
201 | 201 | * @return mixed|null |
202 | 202 | */ |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | */ |
73 | 73 | protected function init() |
74 | 74 | { |
75 | - if (file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . self::CONFIG_FILE)) { |
|
75 | + if (file_exists(CONFIG_DIR.DIRECTORY_SEPARATOR.self::CONFIG_FILE)) { |
|
76 | 76 | $this->loadConfigData(); |
77 | 77 | } |
78 | 78 | return $this; |
@@ -188,10 +188,10 @@ discard block |
||
188 | 188 | $final_data = array_filter($final_data, function($key, $value) { |
189 | 189 | return in_array($key, Config::$required) || !empty($value); |
190 | 190 | }, ARRAY_FILTER_USE_BOTH); |
191 | - $saved = (false !== file_put_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . self::CONFIG_FILE, json_encode($final_data, JSON_PRETTY_PRINT))); |
|
191 | + $saved = (false !== file_put_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.self::CONFIG_FILE, json_encode($final_data, JSON_PRETTY_PRINT))); |
|
192 | 192 | Config::getInstance()->loadConfigData(); |
193 | 193 | $saved = true; |
194 | - } catch (ConfigException $e) { |
|
194 | + }catch (ConfigException $e) { |
|
195 | 195 | Logger::log($e->getMessage(), LOG_ERR); |
196 | 196 | } |
197 | 197 | return $saved; |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | */ |
224 | 224 | public function loadConfigData() |
225 | 225 | { |
226 | - $this->config = json_decode(file_get_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . self::CONFIG_FILE), true) ?: []; |
|
226 | + $this->config = json_decode(file_get_contents(CONFIG_DIR.DIRECTORY_SEPARATOR.self::CONFIG_FILE), true) ?: []; |
|
227 | 227 | $this->debug = (array_key_exists('debug', $this->config)) ? (bool)$this->config['debug'] : FALSE; |
228 | 228 | } |
229 | 229 | |
@@ -244,9 +244,9 @@ discard block |
||
244 | 244 | */ |
245 | 245 | public static function getParam($key, $defaultValue = null, $module = null) |
246 | 246 | { |
247 | - if(null !== $module) { |
|
248 | - return self::getParam(strtolower($module) . '.' . $key, self::getParam($key, $defaultValue)); |
|
249 | - } else { |
|
247 | + if (null !== $module) { |
|
248 | + return self::getParam(strtolower($module).'.'.$key, self::getParam($key, $defaultValue)); |
|
249 | + }else { |
|
250 | 250 | $param = Config::getInstance()->get($key); |
251 | 251 | return (null !== $param) ? $param : $defaultValue; |
252 | 252 | } |
@@ -18,7 +18,7 @@ |
||
18 | 18 | |
19 | 19 | /** |
20 | 20 | * @param string $default |
21 | - * @return array|mixed|string |
|
21 | + * @return string |
|
22 | 22 | */ |
23 | 23 | private static function extractLocale($default = null) |
24 | 24 | { |
@@ -30,21 +30,21 @@ discard block |
||
30 | 30 | list($BrowserLocales[$i]) = explode(";", $BrowserLocales[$i]); //trick for "en;q=0.8" |
31 | 31 | } |
32 | 32 | $locale = array_shift($BrowserLocales); |
33 | - } else { |
|
33 | + }else { |
|
34 | 34 | $locale = strtolower($locale); |
35 | 35 | } |
36 | 36 | if (false !== strpos($locale, '_')) { |
37 | 37 | $locale = explode('_', $locale); |
38 | 38 | if ($locale[0] == 'en') { |
39 | - $locale = $locale[0] . '_GB'; |
|
40 | - } else { |
|
41 | - $locale = $locale[0] . '_' . strtoupper($locale[1]); |
|
39 | + $locale = $locale[0].'_GB'; |
|
40 | + }else { |
|
41 | + $locale = $locale[0].'_'.strtoupper($locale[1]); |
|
42 | 42 | } |
43 | - } else { |
|
43 | + }else { |
|
44 | 44 | if (strtolower($locale) === 'en') { |
45 | 45 | $locale = 'en_GB'; |
46 | - } else { |
|
47 | - $locale = $locale . '_' . strtoupper($locale); |
|
46 | + }else { |
|
47 | + $locale = $locale.'_'.strtoupper($locale); |
|
48 | 48 | } |
49 | 49 | } |
50 | 50 | if (!in_array($locale, self::$langs)) { |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | $translations = array(); |
66 | 66 | if (file_exists($absoluteTranslationFileName)) { |
67 | 67 | @include($absoluteTranslationFileName); |
68 | - } else { |
|
68 | + }else { |
|
69 | 69 | Cache::getInstance()->storeData($absoluteTranslationFileName, "<?php \$translations = array();\n", Cache::TEXT, TRUE); |
70 | 70 | } |
71 | 71 | |
@@ -78,13 +78,13 @@ discard block |
||
78 | 78 | public static function setLocale() |
79 | 79 | { |
80 | 80 | $locale = self::extractLocale('es_ES'); |
81 | - Logger::log('Set locale to project [' . $locale . ']'); |
|
81 | + Logger::log('Set locale to project ['.$locale.']'); |
|
82 | 82 | // Load translations |
83 | - putenv("LC_ALL=" . $locale); |
|
83 | + putenv("LC_ALL=".$locale); |
|
84 | 84 | setlocale(LC_ALL, $locale); |
85 | 85 | // Load the locale path |
86 | - $locale_path = BASE_DIR . DIRECTORY_SEPARATOR . 'locale'; |
|
87 | - Logger::log('Set locale dir ' . $locale_path); |
|
86 | + $locale_path = BASE_DIR.DIRECTORY_SEPARATOR.'locale'; |
|
87 | + Logger::log('Set locale dir '.$locale_path); |
|
88 | 88 | GeneratorHelper::createDir($locale_path); |
89 | 89 | bindtextdomain('translations', $locale_path); |
90 | 90 | textdomain('translations'); |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public static function checkI18Class($namespace) { |
121 | 121 | $isI18n = false; |
122 | - if(preg_match('/I18n$/i', $namespace)) { |
|
122 | + if (preg_match('/I18n$/i', $namespace)) { |
|
123 | 123 | $parentClass = preg_replace('/I18n$/i', '', $namespace); |
124 | - if(Router::exists($parentClass)) { |
|
124 | + if (Router::exists($parentClass)) { |
|
125 | 125 | $isI18n = true; |
126 | 126 | } |
127 | 127 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | $dump = ''; |
114 | 114 | try { |
115 | 115 | $dump = $this->tpl->render($tpl, $vars); |
116 | - } catch (\Exception $e) { |
|
116 | + }catch (\Exception $e) { |
|
117 | 117 | Logger::log($e->getMessage(), LOG_ERR); |
118 | 118 | } |
119 | 119 | return $dump; |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | public function regenerateTemplates() |
141 | 141 | { |
142 | 142 | $this->generateTemplatesCache(); |
143 | - $domains = Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", Cache::JSON, true); |
|
143 | + $domains = Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR."domains.json", Cache::JSON, true); |
|
144 | 144 | $translations = []; |
145 | 145 | if (is_array($domains)) { |
146 | 146 | $translations = $this->parsePathTranslations($domains); |
@@ -162,8 +162,8 @@ discard block |
||
162 | 162 | // force compilation |
163 | 163 | if ($file->isFile()) { |
164 | 164 | try { |
165 | - $this->tpl->load(str_replace($tplDir . '/', '', $file)); |
|
166 | - } catch (\Exception $e) { |
|
165 | + $this->tpl->load(str_replace($tplDir.'/', '', $file)); |
|
166 | + }catch (\Exception $e) { |
|
167 | 167 | Logger::log($e->getMessage(), LOG_ERR, ['file' => $e->getFile(), 'line' => $e->getLine()]); |
168 | 168 | } |
169 | 169 | } |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | 'getFlash' => TemplateFunctions::GET_FLASH_FUNCTION, |
225 | 225 | 'getQuery' => TemplateFunctions::GET_QUERY_FUNCTION, |
226 | 226 | ]; |
227 | - foreach($functions as $name => $function) { |
|
227 | + foreach ($functions as $name => $function) { |
|
228 | 228 | $this->addTemplateFunction($name, $function); |
229 | 229 | } |
230 | 230 | } |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | */ |
244 | 244 | private function loadDomains() |
245 | 245 | { |
246 | - $domains = Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', Cache::JSON, true); |
|
246 | + $domains = Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'domains.json', Cache::JSON, true); |
|
247 | 247 | if (null !== $domains) { |
248 | 248 | foreach ($domains as $domain => $paths) { |
249 | 249 | $this->addPath($paths['template'], preg_replace('/(@|\/)/', '', $domain)); |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | { |
259 | 259 | $loader = new \Twig_Loader_Filesystem(GeneratorHelper::getTemplatePath()); |
260 | 260 | $this->tpl = new \Twig_Environment($loader, array( |
261 | - 'cache' => CACHE_DIR . DIRECTORY_SEPARATOR . 'twig', |
|
261 | + 'cache' => CACHE_DIR.DIRECTORY_SEPARATOR.'twig', |
|
262 | 262 | 'debug' => (bool)$this->debug, |
263 | 263 | 'auto_reload' => Config::getParam('twig.autoreload', TRUE), |
264 | 264 | )); |
@@ -82,9 +82,9 @@ |
||
82 | 82 | "class" => "btn-warning md-default", |
83 | 83 | "icon" => "fa-plus", |
84 | 84 | ]; |
85 | - if(Config::getParam('admin.version', 'v1') === 'v1') { |
|
86 | - $add["onclick"] = "javascript:addNewField(document.getElementById('" . $this->getName() . "'));"; |
|
87 | - } else { |
|
85 | + if (Config::getParam('admin.version', 'v1') === 'v1') { |
|
86 | + $add["onclick"] = "javascript:addNewField(document.getElementById('".$this->getName()."'));"; |
|
87 | + }else { |
|
88 | 88 | $add["ng-click"] = "addNewField()"; |
89 | 89 | } |
90 | 90 | $this->addButton('submit', _("Guardar configuración"), "submit", array( |
@@ -65,21 +65,21 @@ discard block |
||
65 | 65 | if (count($pks) == 1) { |
66 | 66 | $pks = array_keys($pks); |
67 | 67 | return [ |
68 | - $tableMap::TABLE_NAME . '.' . $pks[0] => Api::API_MODEL_KEY_FIELD |
|
68 | + $tableMap::TABLE_NAME.'.'.$pks[0] => Api::API_MODEL_KEY_FIELD |
|
69 | 69 | ]; |
70 | 70 | } elseif (count($pks) > 1) { |
71 | 71 | $apiPks = []; |
72 | 72 | $principal = ''; |
73 | 73 | $sep = 'CONCAT('; |
74 | 74 | foreach ($pks as $pk) { |
75 | - $apiPks[$tableMap::TABLE_NAME . '.' . $pk->getName()] = $pk->getPhpName(); |
|
76 | - $principal .= $sep . $tableMap::TABLE_NAME . '.' . $pk->getName(); |
|
77 | - $sep = ', "' . Api::API_PK_SEPARATOR . '", '; |
|
75 | + $apiPks[$tableMap::TABLE_NAME.'.'.$pk->getName()] = $pk->getPhpName(); |
|
76 | + $principal .= $sep.$tableMap::TABLE_NAME.'.'.$pk->getName(); |
|
77 | + $sep = ', "'.Api::API_PK_SEPARATOR.'", '; |
|
78 | 78 | } |
79 | 79 | $principal .= ')'; |
80 | 80 | $apiPks[$principal] = Api::API_MODEL_KEY_FIELD; |
81 | 81 | return $apiPks; |
82 | - } else { |
|
82 | + }else { |
|
83 | 83 | throw new ApiException(_('El modelo de la API no está debidamente mapeado, no hay Primary Key o es compuesta')); |
84 | 84 | } |
85 | 85 | } |
@@ -102,10 +102,10 @@ discard block |
||
102 | 102 | $pks = ''; |
103 | 103 | $sep = ''; |
104 | 104 | foreach ($tableMap->getPrimaryKeys() as $pk) { |
105 | - $pks .= $sep . $pk->getFullyQualifiedName(); |
|
105 | + $pks .= $sep.$pk->getFullyQualifiedName(); |
|
106 | 106 | $sep = ', "|", '; |
107 | 107 | } |
108 | - $this->extraColumns['CONCAT("' . $tableMap->getPhpName() . ' #", ' . $pks . ')'] = Api::API_LIST_NAME_FIELD; |
|
108 | + $this->extraColumns['CONCAT("'.$tableMap->getPhpName().' #", '.$pks.')'] = Api::API_LIST_NAME_FIELD; |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | } |
128 | 128 | if (null !== $column) { |
129 | 129 | $this->extraColumns[$column->getFullyQualifiedName()] = Api::API_LIST_NAME_FIELD; |
130 | - } else { |
|
130 | + }else { |
|
131 | 131 | $this->addClassListName($tableMap); |
132 | 132 | } |
133 | 133 | } |
@@ -139,22 +139,22 @@ discard block |
||
139 | 139 | * @param ModelCriteria $query |
140 | 140 | * @param string $action |
141 | 141 | */ |
142 | - private function addExtraColumns(ModelCriteria &$query, $action) |
|
142 | + private function addExtraColumns(ModelCriteria & $query, $action) |
|
143 | 143 | { |
144 | 144 | if (Api::API_ACTION_LIST === $action) { |
145 | 145 | $this->addDefaultListField(); |
146 | 146 | $this->addPkToList(); |
147 | 147 | } |
148 | 148 | if (!empty($this->extraColumns)) { |
149 | - if(Config::getParam('api.extrafields.compat', true)) { |
|
149 | + if (Config::getParam('api.extrafields.compat', true)) { |
|
150 | 150 | $fields = array_values($this->extraColumns); |
151 | - } else { |
|
151 | + }else { |
|
152 | 152 | $returnFields = Request::getInstance()->getQuery(Api::API_FIELDS_RESULT_FIELD); |
153 | 153 | $fields = explode(',', $returnFields ?: ''); |
154 | 154 | $fields[] = self::API_MODEL_KEY_FIELD; |
155 | 155 | } |
156 | 156 | foreach ($this->extraColumns as $expression => $columnName) { |
157 | - if(empty($fields) || in_array($columnName, $fields)) { |
|
157 | + if (empty($fields) || in_array($columnName, $fields)) { |
|
158 | 158 | $query->withColumn($expression, $columnName); |
159 | 159 | } |
160 | 160 | } |
@@ -182,21 +182,21 @@ discard block |
||
182 | 182 | /** |
183 | 183 | * @param ModelCriteria $query |
184 | 184 | */ |
185 | - protected function checkI18n(ModelCriteria &$query) |
|
185 | + protected function checkI18n(ModelCriteria & $query) |
|
186 | 186 | { |
187 | 187 | $this->extractApiLang(); |
188 | 188 | $model = $this->getModelNamespace(); |
189 | - $modelI18n = $model . 'I18n'; |
|
189 | + $modelI18n = $model.'I18n'; |
|
190 | 190 | if (method_exists($query, 'useI18nQuery')) { |
191 | 191 | $query->useI18nQuery($this->lang); |
192 | - $modelI18nTableMapClass = str_replace('\\Models\\', '\\Models\\Map\\', $modelI18n) . 'TableMap'; |
|
192 | + $modelI18nTableMapClass = str_replace('\\Models\\', '\\Models\\Map\\', $modelI18n).'TableMap'; |
|
193 | 193 | /** @var TableMap $modelI18nTableMap */ |
194 | 194 | $modelI18nTableMap = $modelI18nTableMapClass::getTableMap(); |
195 | - foreach($modelI18nTableMap->getColumns() as $columnMap) { |
|
196 | - if(!$columnMap->isPrimaryKey()) { |
|
197 | - $query->withColumn($modelI18nTableMapClass::TABLE_NAME . '.' . $columnMap->getName(), $columnMap->getPhpName()); |
|
198 | - } elseif(!$columnMap->isForeignKey()) { |
|
199 | - $query->withColumn('IFNULL(' . $modelI18nTableMapClass::TABLE_NAME . '.' . $columnMap->getName() . ', "'.$this->lang.'")', $columnMap->getPhpName()); |
|
195 | + foreach ($modelI18nTableMap->getColumns() as $columnMap) { |
|
196 | + if (!$columnMap->isPrimaryKey()) { |
|
197 | + $query->withColumn($modelI18nTableMapClass::TABLE_NAME.'.'.$columnMap->getName(), $columnMap->getPhpName()); |
|
198 | + } elseif (!$columnMap->isForeignKey()) { |
|
199 | + $query->withColumn('IFNULL('.$modelI18nTableMapClass::TABLE_NAME.'.'.$columnMap->getName().', "'.$this->lang.'")', $columnMap->getPhpName()); |
|
200 | 200 | } |
201 | 201 | } |
202 | 202 | } |
@@ -206,23 +206,23 @@ discard block |
||
206 | 206 | * @param ActiveRecordInterface $model |
207 | 207 | * @param array $data |
208 | 208 | */ |
209 | - protected function hydrateModelFromRequest(ActiveRecordInterface &$model, array $data = []) { |
|
209 | + protected function hydrateModelFromRequest(ActiveRecordInterface & $model, array $data = []) { |
|
210 | 210 | $model->fromArray($data); |
211 | 211 | $tableMap = $this->getTableMap(); |
212 | 212 | try { |
213 | - $relateI18n = $tableMap->getRelation($tableMap->getPhpName() . 'I18n'); |
|
214 | - if(null !== $relateI18n) { |
|
213 | + $relateI18n = $tableMap->getRelation($tableMap->getPhpName().'I18n'); |
|
214 | + if (null !== $relateI18n) { |
|
215 | 215 | $i18NTableMap = $relateI18n->getLocalTable(); |
216 | - foreach($i18NTableMap->getColumns() as $columnMap) { |
|
217 | - $method = 'set' . $columnMap->getPhpName(); |
|
218 | - if(!($columnMap->isPrimaryKey() && $columnMap->isForeignKey()) |
|
216 | + foreach ($i18NTableMap->getColumns() as $columnMap) { |
|
217 | + $method = 'set'.$columnMap->getPhpName(); |
|
218 | + if (!($columnMap->isPrimaryKey() && $columnMap->isForeignKey()) |
|
219 | 219 | &&array_key_exists($columnMap->getPhpName(), $data) |
220 | 220 | && method_exists($model, $method)) { |
221 | 221 | $model->$method($data[$columnMap->getPhpName()]); |
222 | 222 | } |
223 | 223 | } |
224 | 224 | } |
225 | - } catch(\Exception $e) { |
|
225 | + }catch (\Exception $e) { |
|
226 | 226 | Logger::log($e->getMessage(), LOG_WARNING); |
227 | 227 | } |
228 | 228 | } |
@@ -70,22 +70,28 @@ discard block |
||
70 | 70 | if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ',') !== false) { |
71 | 71 | $iplist = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); |
72 | 72 | foreach ($iplist as $ip) { |
73 | - if (self::validateIpAddress($ip)) |
|
74 | - return $ip; |
|
73 | + if (self::validateIpAddress($ip)) { |
|
74 | + return $ip; |
|
75 | + } |
|
75 | 76 | } |
76 | 77 | } else { |
77 | - if (self::validateIpAddress($_SERVER['HTTP_X_FORWARDED_FOR'])) |
|
78 | - return $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
78 | + if (self::validateIpAddress($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
79 | + return $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
80 | + } |
|
79 | 81 | } |
80 | 82 | } |
81 | - if (!empty($_SERVER['HTTP_X_FORWARDED']) && self::validateIpAddress($_SERVER['HTTP_X_FORWARDED'])) |
|
82 | - return $_SERVER['HTTP_X_FORWARDED']; |
|
83 | - if (!empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && self::validateIpAddress($_SERVER['HTTP_X_CLUSTER_CLIENT_IP'])) |
|
84 | - return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP']; |
|
85 | - if (!empty($_SERVER['HTTP_FORWARDED_FOR']) && self::validateIpAddress($_SERVER['HTTP_FORWARDED_FOR'])) |
|
86 | - return $_SERVER['HTTP_FORWARDED_FOR']; |
|
87 | - if (!empty($_SERVER['HTTP_FORWARDED']) && self::validateIpAddress($_SERVER['HTTP_FORWARDED'])) |
|
88 | - return $_SERVER['HTTP_FORWARDED']; |
|
83 | + if (!empty($_SERVER['HTTP_X_FORWARDED']) && self::validateIpAddress($_SERVER['HTTP_X_FORWARDED'])) { |
|
84 | + return $_SERVER['HTTP_X_FORWARDED']; |
|
85 | + } |
|
86 | + if (!empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && self::validateIpAddress($_SERVER['HTTP_X_CLUSTER_CLIENT_IP'])) { |
|
87 | + return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP']; |
|
88 | + } |
|
89 | + if (!empty($_SERVER['HTTP_FORWARDED_FOR']) && self::validateIpAddress($_SERVER['HTTP_FORWARDED_FOR'])) { |
|
90 | + return $_SERVER['HTTP_FORWARDED_FOR']; |
|
91 | + } |
|
92 | + if (!empty($_SERVER['HTTP_FORWARDED']) && self::validateIpAddress($_SERVER['HTTP_FORWARDED'])) { |
|
93 | + return $_SERVER['HTTP_FORWARDED']; |
|
94 | + } |
|
89 | 95 | |
90 | 96 | // return unreliable ip since all else failed |
91 | 97 | return $_SERVER['REMOTE_ADDR']; |
@@ -96,8 +102,9 @@ discard block |
||
96 | 102 | * a private network range. |
97 | 103 | */ |
98 | 104 | public static function validateIpAddress($ip) { |
99 | - if (strtolower($ip) === 'unknown') |
|
100 | - return false; |
|
105 | + if (strtolower($ip) === 'unknown') { |
|
106 | + return false; |
|
107 | + } |
|
101 | 108 | |
102 | 109 | // generate ipv4 network address |
103 | 110 | $ip = ip2long($ip); |
@@ -109,14 +116,30 @@ discard block |
||
109 | 116 | // signed numbers (ints default to signed in PHP) |
110 | 117 | $ip = sprintf('%u', $ip); |
111 | 118 | // do private network range checking |
112 | - if ($ip >= 0 && $ip <= 50331647) return false; |
|
113 | - if ($ip >= 167772160 && $ip <= 184549375) return false; |
|
114 | - if ($ip >= 2130706432 && $ip <= 2147483647) return false; |
|
115 | - if ($ip >= 2851995648 && $ip <= 2852061183) return false; |
|
116 | - if ($ip >= 2886729728 && $ip <= 2887778303) return false; |
|
117 | - if ($ip >= 3221225984 && $ip <= 3221226239) return false; |
|
118 | - if ($ip >= 3232235520 && $ip <= 3232301055) return false; |
|
119 | - if ($ip >= 4294967040) return false; |
|
119 | + if ($ip >= 0 && $ip <= 50331647) { |
|
120 | + return false; |
|
121 | + } |
|
122 | + if ($ip >= 167772160 && $ip <= 184549375) { |
|
123 | + return false; |
|
124 | + } |
|
125 | + if ($ip >= 2130706432 && $ip <= 2147483647) { |
|
126 | + return false; |
|
127 | + } |
|
128 | + if ($ip >= 2851995648 && $ip <= 2852061183) { |
|
129 | + return false; |
|
130 | + } |
|
131 | + if ($ip >= 2886729728 && $ip <= 2887778303) { |
|
132 | + return false; |
|
133 | + } |
|
134 | + if ($ip >= 3221225984 && $ip <= 3221226239) { |
|
135 | + return false; |
|
136 | + } |
|
137 | + if ($ip >= 3232235520 && $ip <= 3232301055) { |
|
138 | + return false; |
|
139 | + } |
|
140 | + if ($ip >= 4294967040) { |
|
141 | + return false; |
|
142 | + } |
|
120 | 143 | } |
121 | 144 | return true; |
122 | 145 | } |
@@ -42,10 +42,10 @@ discard block |
||
42 | 42 | |
43 | 43 | // TODO include this headers in Template class output method |
44 | 44 | header("Access-Control-Allow-Credentials: true"); |
45 | - header("Access-Control-Allow-Origin: " . Request::getInstance()->getServer('HTTP_ORIGIN', '*')); |
|
45 | + header("Access-Control-Allow-Origin: ".Request::getInstance()->getServer('HTTP_ORIGIN', '*')); |
|
46 | 46 | header("Vary: Origin"); |
47 | 47 | header("Access-Control-Allow-Methods: GET, POST, DELETE, PUT, PATCH, OPTIONS"); |
48 | - header("Access-Control-Allow-Headers: " . implode(', ', self::getCorsHeaders())); |
|
48 | + header("Access-Control-Allow-Headers: ".implode(', ', self::getCorsHeaders())); |
|
49 | 49 | } |
50 | 50 | if (Request::getInstance()->getMethod() == 'OPTIONS') { |
51 | 51 | Logger::log('Returning OPTIONS header confirmation for CORS pre flight requests', LOG_DEBUG); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | if (self::validateIpAddress($ip)) |
75 | 75 | return $ip; |
76 | 76 | } |
77 | - } else { |
|
77 | + }else { |
|
78 | 78 | if (self::validateIpAddress($_SERVER['HTTP_X_FORWARDED_FOR'])) |
79 | 79 | return $_SERVER['HTTP_X_FORWARDED_FOR']; |
80 | 80 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | public function __construct($type = 'js') |
34 | 34 | { |
35 | 35 | $this->type = $type; |
36 | - $this->path = WEB_DIR . DIRECTORY_SEPARATOR; |
|
36 | + $this->path = WEB_DIR.DIRECTORY_SEPARATOR; |
|
37 | 37 | $this->domains = Template::getDomains(true); |
38 | 38 | $this->debug = Config::getInstance()->getDebugMode(); |
39 | 39 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | $source_file = explode("?", $source_file); |
56 | 56 | $source_file = $source_file[0]; |
57 | 57 | } |
58 | - $orig = realpath(dirname($filename_path) . DIRECTORY_SEPARATOR . $source_file); |
|
58 | + $orig = realpath(dirname($filename_path).DIRECTORY_SEPARATOR.$source_file); |
|
59 | 59 | return $orig; |
60 | 60 | } |
61 | 61 | |
@@ -68,12 +68,12 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function addFile($filename) |
70 | 70 | { |
71 | - if (file_exists($this->path . $filename) && preg_match('/\.' . $this->type . '$/i', $filename)) { |
|
71 | + if (file_exists($this->path.$filename) && preg_match('/\.'.$this->type.'$/i', $filename)) { |
|
72 | 72 | $this->files[] = $filename; |
73 | 73 | } elseif (!empty($this->domains)) { |
74 | 74 | foreach ($this->domains as $domain => $paths) { |
75 | 75 | $domain_filename = str_replace($domain, $paths["public"], $filename); |
76 | - if (file_exists($domain_filename) && preg_match('/\.' . $this->type . '$/i', $domain_filename)) { |
|
76 | + if (file_exists($domain_filename) && preg_match('/\.'.$this->type.'$/i', $domain_filename)) { |
|
77 | 77 | $this->files[] = $domain_filename; |
78 | 78 | } |
79 | 79 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | public function setHash($hash) |
91 | 91 | { |
92 | 92 | $cache = Config::getParam('cache.var', ''); |
93 | - $this->hash = $hash . (strlen($cache) ? '.' : '') . $cache; |
|
93 | + $this->hash = $hash.(strlen($cache) ? '.' : '').$cache; |
|
94 | 94 | return $this; |
95 | 95 | } |
96 | 96 | |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | */ |
125 | 125 | protected function compileCss() |
126 | 126 | { |
127 | - $base = $this->path . "css" . DIRECTORY_SEPARATOR; |
|
128 | - if ($this->debug || !file_exists($base . $this->hash . ".css")) { |
|
127 | + $base = $this->path."css".DIRECTORY_SEPARATOR; |
|
128 | + if ($this->debug || !file_exists($base.$this->hash.".css")) { |
|
129 | 129 | $data = ''; |
130 | 130 | if (0 < count($this->files)) { |
131 | 131 | $minifier = new CSS(); |
@@ -133,15 +133,15 @@ discard block |
||
133 | 133 | $data = $this->processCssLine($file, $base, $data); |
134 | 134 | } |
135 | 135 | } |
136 | - if($this->debug) { |
|
137 | - $this->storeContents($base . $this->hash . ".css", $data); |
|
138 | - } else { |
|
136 | + if ($this->debug) { |
|
137 | + $this->storeContents($base.$this->hash.".css", $data); |
|
138 | + }else { |
|
139 | 139 | $minifier = new CSS(); |
140 | 140 | $minifier->add($data); |
141 | 141 | ini_set('max_execution_time', -1); |
142 | 142 | ini_set('memory_limit', -1); |
143 | 143 | GeneratorHelper::createDir($base); |
144 | - $minifier->minify($base . $this->hash . ".css"); |
|
144 | + $minifier->minify($base.$this->hash.".css"); |
|
145 | 145 | unset($cssMinifier); |
146 | 146 | ini_restore('memory_limit'); |
147 | 147 | ini_restore('max_execution_time'); |
@@ -157,8 +157,8 @@ discard block |
||
157 | 157 | */ |
158 | 158 | protected function compileJs() |
159 | 159 | { |
160 | - $base = $this->path . "js" . DIRECTORY_SEPARATOR; |
|
161 | - if ($this->debug || !file_exists($base . $this->hash . ".js")) { |
|
160 | + $base = $this->path."js".DIRECTORY_SEPARATOR; |
|
161 | + if ($this->debug || !file_exists($base.$this->hash.".js")) { |
|
162 | 162 | $data = ''; |
163 | 163 | if (0 < count($this->files)) { |
164 | 164 | $minifier = new JS(); |
@@ -167,19 +167,19 @@ discard block |
||
167 | 167 | if (file_exists($file)) { |
168 | 168 | if ($this->debug) { |
169 | 169 | $data = $this->putDebugJs($path_parts, $base, $file); |
170 | - } elseif (!file_exists($base . $this->hash . ".js")) { |
|
170 | + } elseif (!file_exists($base.$this->hash.".js")) { |
|
171 | 171 | $minifier->add($file); |
172 | 172 | //$data = $this->putProductionJs($base, $file, $data); |
173 | 173 | } |
174 | 174 | } |
175 | 175 | } |
176 | - if($this->debug) { |
|
177 | - $this->storeContents($base . $this->hash . ".js", $data); |
|
178 | - } else { |
|
176 | + if ($this->debug) { |
|
177 | + $this->storeContents($base.$this->hash.".js", $data); |
|
178 | + }else { |
|
179 | 179 | ini_set('max_execution_time', -1); |
180 | 180 | ini_set('memory_limit', -1); |
181 | 181 | GeneratorHelper::createDir($base); |
182 | - $minifier->minify($base . $this->hash . ".js"); |
|
182 | + $minifier->minify($base.$this->hash.".js"); |
|
183 | 183 | ini_restore('memory_limit'); |
184 | 184 | ini_restore('max_execution_time'); |
185 | 185 | } |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | { |
200 | 200 | GeneratorHelper::createDir(dirname($path)); |
201 | 201 | if ("" !== $content && false === file_put_contents($path, $content)) { |
202 | - throw new ConfigException(_('No se tienen permisos para escribir en ' . $path)); |
|
202 | + throw new ConfigException(_('No se tienen permisos para escribir en '.$path)); |
|
203 | 203 | } |
204 | 204 | } |
205 | 205 | |
@@ -228,8 +228,8 @@ discard block |
||
228 | 228 | foreach ($this->compiled_files as $file) { |
229 | 229 | echo "\t\t<script type='text/javascript' src='{$file}'></script>\n"; |
230 | 230 | } |
231 | - } else { |
|
232 | - echo "\t\t<script type='text/javascript' src='/js/" . $this->hash . ".js'></script>\n"; |
|
231 | + }else { |
|
232 | + echo "\t\t<script type='text/javascript' src='/js/".$this->hash.".js'></script>\n"; |
|
233 | 233 | } |
234 | 234 | } |
235 | 235 | |
@@ -242,8 +242,8 @@ discard block |
||
242 | 242 | foreach ($this->compiled_files as $file) { |
243 | 243 | echo "\t\t<link href='{$file}' rel='stylesheet' media='screen, print'>"; |
244 | 244 | } |
245 | - } else { |
|
246 | - echo "\t\t<link href='/css/" . $this->hash . ".css' rel='stylesheet'>"; |
|
245 | + }else { |
|
246 | + echo "\t\t<link href='/css/".$this->hash.".css' rel='stylesheet'>"; |
|
247 | 247 | } |
248 | 248 | } |
249 | 249 | |
@@ -254,20 +254,20 @@ discard block |
||
254 | 254 | protected function extractCssResources($source, $file) |
255 | 255 | { |
256 | 256 | $source_file = $this->extractSourceFilename($source); |
257 | - $orig = realpath(dirname($file) . DIRECTORY_SEPARATOR . $source_file); |
|
257 | + $orig = realpath(dirname($file).DIRECTORY_SEPARATOR.$source_file); |
|
258 | 258 | $orig_part = preg_split('/(\/|\\\)public(\/|\\\)/i', $orig); |
259 | 259 | try { |
260 | 260 | if (count($source) > 1 && array_key_exists(1, $orig_part)) { |
261 | - $dest = $this->path . $orig_part[1]; |
|
261 | + $dest = $this->path.$orig_part[1]; |
|
262 | 262 | GeneratorHelper::createDir(dirname($dest)); |
263 | 263 | if (!file_exists($dest) || filemtime($orig) > filemtime($dest)) { |
264 | 264 | if (@copy($orig, $dest) === FALSE) { |
265 | - throw new \RuntimeException('Can\' copy ' . $dest . ''); |
|
265 | + throw new \RuntimeException('Can\' copy '.$dest.''); |
|
266 | 266 | } |
267 | 267 | Logger::log("$orig copiado a $dest", LOG_INFO); |
268 | 268 | } |
269 | 269 | } |
270 | - } catch (\Exception $e) { |
|
270 | + }catch (\Exception $e) { |
|
271 | 271 | Logger::log($e->getMessage(), LOG_ERR); |
272 | 272 | } |
273 | 273 | } |
@@ -284,21 +284,21 @@ discard block |
||
284 | 284 | { |
285 | 285 | if (file_exists($file)) { |
286 | 286 | $path_parts = explode("/", $file); |
287 | - $file_path = $this->hash . "_" . $path_parts[count($path_parts) - 1]; |
|
288 | - if (!file_exists($base . $file_path) || filemtime($base . $file_path) < filemtime($file) || $this->debug) { |
|
287 | + $file_path = $this->hash."_".$path_parts[count($path_parts) - 1]; |
|
288 | + if (!file_exists($base.$file_path) || filemtime($base.$file_path) < filemtime($file) || $this->debug) { |
|
289 | 289 | //Si tenemos modificaciones tenemos que compilar de nuevo todos los ficheros modificados |
290 | - if (file_exists($base . $this->hash . ".css") && @unlink($base . $this->hash . ".css") === false) { |
|
291 | - throw new ConfigException("Can't unlink file " . $base . $this->hash . ".css"); |
|
290 | + if (file_exists($base.$this->hash.".css") && @unlink($base.$this->hash.".css") === false) { |
|
291 | + throw new ConfigException("Can't unlink file ".$base.$this->hash.".css"); |
|
292 | 292 | } |
293 | 293 | $this->loopCssLines($file); |
294 | 294 | } |
295 | 295 | if ($this->debug) { |
296 | 296 | $data = file_get_contents($file); |
297 | - $this->storeContents($base . $file_path, $data); |
|
298 | - } else { |
|
297 | + $this->storeContents($base.$file_path, $data); |
|
298 | + }else { |
|
299 | 299 | $data .= file_get_contents($file); |
300 | 300 | } |
301 | - $this->compiled_files[] = "/css/" . $file_path; |
|
301 | + $this->compiled_files[] = "/css/".$file_path; |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | return $data; |
@@ -313,12 +313,12 @@ discard block |
||
313 | 313 | */ |
314 | 314 | protected function putDebugJs($path_parts, $base, $file) |
315 | 315 | { |
316 | - $file_path = $this->hash . "_" . $path_parts[count($path_parts) - 1]; |
|
317 | - $this->compiled_files[] = "/js/" . $file_path; |
|
316 | + $file_path = $this->hash."_".$path_parts[count($path_parts) - 1]; |
|
317 | + $this->compiled_files[] = "/js/".$file_path; |
|
318 | 318 | $data = ""; |
319 | - if (!file_exists($base . $file_path) || filemtime($base . $file_path) < filemtime($file)) { |
|
319 | + if (!file_exists($base.$file_path) || filemtime($base.$file_path) < filemtime($file)) { |
|
320 | 320 | $data = file_get_contents($file); |
321 | - $this->storeContents($base . $file_path, $data); |
|
321 | + $this->storeContents($base.$file_path, $data); |
|
322 | 322 | } |
323 | 323 | return $data; |
324 | 324 | } |
@@ -360,60 +360,60 @@ discard block |
||
360 | 360 | { |
361 | 361 | $ppath = explode("/", $string); |
362 | 362 | $original_filename = $ppath[count($ppath) - 1]; |
363 | - $base = WEB_DIR . DIRECTORY_SEPARATOR; |
|
363 | + $base = WEB_DIR.DIRECTORY_SEPARATOR; |
|
364 | 364 | $file = ""; |
365 | 365 | $html_base = ""; |
366 | 366 | $debug = Config::getInstance()->getDebugMode(); |
367 | 367 | $cache = Config::getInstance()->get('cache.var'); |
368 | - $cache = $cache ? '.' . $cache : ''; |
|
368 | + $cache = $cache ? '.'.$cache : ''; |
|
369 | 369 | $finfo = finfo_open(FILEINFO_MIME_TYPE); // devuelve el tipo mime de su extensión |
370 | 370 | $mime = finfo_file($finfo, $filename_path); |
371 | 371 | finfo_close($finfo); |
372 | 372 | if (preg_match('/\.css$/i', $string)) { |
373 | - $file = "/" . substr(md5($string), 0, 8) . "$cache.css"; |
|
373 | + $file = "/".substr(md5($string), 0, 8)."$cache.css"; |
|
374 | 374 | $html_base = "css"; |
375 | 375 | if ($debug) { |
376 | - $file = str_replace(".css", "_" . $original_filename, $file); |
|
376 | + $file = str_replace(".css", "_".$original_filename, $file); |
|
377 | 377 | } |
378 | 378 | } elseif (preg_match('/\.js$/i', $string)) { |
379 | - $file = "/" . substr(md5($string), 0, 8) . "$cache.js"; |
|
379 | + $file = "/".substr(md5($string), 0, 8)."$cache.js"; |
|
380 | 380 | $html_base = "js"; |
381 | 381 | if ($debug) { |
382 | - $file = str_replace(".js", "_" . $original_filename, $file); |
|
382 | + $file = str_replace(".js", "_".$original_filename, $file); |
|
383 | 383 | } |
384 | 384 | } elseif (preg_match("/image/i", $mime)) { |
385 | 385 | $ext = explode(".", $string); |
386 | - $file = "/" . substr(md5($string), 0, 8) . "." . $ext[count($ext) - 1]; |
|
386 | + $file = "/".substr(md5($string), 0, 8).".".$ext[count($ext) - 1]; |
|
387 | 387 | $html_base = "img"; |
388 | 388 | if ($debug) { |
389 | - $file = str_replace("." . $ext[count($ext) - 1], "_" . $original_filename, $file); |
|
389 | + $file = str_replace(".".$ext[count($ext) - 1], "_".$original_filename, $file); |
|
390 | 390 | } |
391 | 391 | } elseif (preg_match("/(doc|pdf)/i", $mime)) { |
392 | 392 | $ext = explode(".", $string); |
393 | - $file = "/" . substr(md5($string), 0, 8) . "." . $ext[count($ext) - 1]; |
|
393 | + $file = "/".substr(md5($string), 0, 8).".".$ext[count($ext) - 1]; |
|
394 | 394 | $html_base = "docs"; |
395 | 395 | if ($debug) { |
396 | - $file = str_replace("." . $ext[count($ext) - 1], "_" . $original_filename, $file); |
|
396 | + $file = str_replace(".".$ext[count($ext) - 1], "_".$original_filename, $file); |
|
397 | 397 | } |
398 | 398 | } elseif (preg_match("/(video|audio|ogg)/i", $mime)) { |
399 | 399 | $ext = explode(".", $string); |
400 | - $file = "/" . substr(md5($string), 0, 8) . "." . $ext[count($ext) - 1]; |
|
400 | + $file = "/".substr(md5($string), 0, 8).".".$ext[count($ext) - 1]; |
|
401 | 401 | $html_base = "media"; |
402 | 402 | if ($debug) { |
403 | - $file = str_replace("." . $ext[count($ext) - 1], "_" . $original_filename, $file); |
|
403 | + $file = str_replace(".".$ext[count($ext) - 1], "_".$original_filename, $file); |
|
404 | 404 | } |
405 | 405 | } elseif (preg_match("/(text|html)/i", $mime)) { |
406 | 406 | $ext = explode(".", $string); |
407 | - $file = "/" . substr(md5($string), 0, 8) . "." . $ext[count($ext) - 1]; |
|
407 | + $file = "/".substr(md5($string), 0, 8).".".$ext[count($ext) - 1]; |
|
408 | 408 | $html_base = "templates"; |
409 | 409 | if ($debug) { |
410 | - $file = str_replace("." . $ext[count($ext) - 1], "_" . $original_filename, $file); |
|
410 | + $file = str_replace(".".$ext[count($ext) - 1], "_".$original_filename, $file); |
|
411 | 411 | } |
412 | 412 | } elseif (!$return && !is_null($name)) { |
413 | 413 | $html_base = ''; |
414 | 414 | $file = $name; |
415 | 415 | } |
416 | - $file_path = $html_base . $file; |
|
416 | + $file_path = $html_base.$file; |
|
417 | 417 | |
418 | 418 | return array($base, $html_base, $file_path); |
419 | 419 | } |
@@ -431,15 +431,15 @@ discard block |
||
431 | 431 | if (preg_match_all('#url\((.*?)\)#', $line, $urls, PREG_SET_ORDER)) { |
432 | 432 | foreach ($urls as $source) { |
433 | 433 | $orig = self::calculateResourcePathname($filename_path, $source); |
434 | - if(!empty($orig)) { |
|
434 | + if (!empty($orig)) { |
|
435 | 435 | $orig_part = preg_split("/Public/i", $orig); |
436 | - $dest = WEB_DIR . $orig_part[1]; |
|
436 | + $dest = WEB_DIR.$orig_part[1]; |
|
437 | 437 | GeneratorHelper::createDir(dirname($dest)); |
438 | 438 | if (@copy($orig, $dest) === false) { |
439 | - throw new ConfigException("Can't copy " . $orig . " to " . $dest); |
|
439 | + throw new ConfigException("Can't copy ".$orig." to ".$dest); |
|
440 | 440 | } |
441 | - } else { |
|
442 | - Logger::log($filename_path . ' has an empty origin with the url ' . $source, LOG_WARNING); |
|
441 | + }else { |
|
442 | + Logger::log($filename_path.' has an empty origin with the url '.$source, LOG_WARNING); |
|
443 | 443 | } |
444 | 444 | } |
445 | 445 | } |
@@ -1,7 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace PSFS\base; |
3 | 3 | |
4 | -use PSFS\base\types\helpers\RequestHelper; |
|
5 | 4 | use PSFS\base\types\helpers\ResponseHelper; |
6 | 5 | use PSFS\base\types\traits\SecureTrait; |
7 | 6 | use PSFS\base\types\traits\SingletonTrait; |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | session_start(); |
77 | 77 | } |
78 | 78 | // Fix for phpunits |
79 | - if(!isset($_SESSION)) { |
|
79 | + if (!isset($_SESSION)) { |
|
80 | 80 | $_SESSION = []; |
81 | 81 | } |
82 | 82 | } |
@@ -136,12 +136,12 @@ discard block |
||
136 | 136 | { |
137 | 137 | $saved = true; |
138 | 138 | try { |
139 | - $admins = Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', Cache::JSONGZ, true) ?: []; |
|
140 | - $admins[$user['username']]['hash'] = sha1($user['username'] . $user['password']); |
|
139 | + $admins = Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', Cache::JSONGZ, true) ?: []; |
|
140 | + $admins[$user['username']]['hash'] = sha1($user['username'].$user['password']); |
|
141 | 141 | $admins[$user['username']]['profile'] = $user['profile']; |
142 | 142 | |
143 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', $admins, Cache::JSONGZ, true); |
|
144 | - } catch(\Exception $e) { |
|
143 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', $admins, Cache::JSONGZ, true); |
|
144 | + }catch (\Exception $e) { |
|
145 | 145 | Logger::log($e->getMessage(), LOG_ERR); |
146 | 146 | $saved = false; |
147 | 147 | } |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | */ |
179 | 179 | public function getAdmins() |
180 | 180 | { |
181 | - return Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', Cache::JSONGZ, true); |
|
181 | + return Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', Cache::JSONGZ, true); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | } |
207 | 207 | if (!empty($user) && !empty($admins[$user])) { |
208 | 208 | $auth = $admins[$user]['hash']; |
209 | - $this->authorized = ($auth == sha1($user . $pass)); |
|
209 | + $this->authorized = ($auth == sha1($user.$pass)); |
|
210 | 210 | if ($this->authorized) { |
211 | 211 | $this->admin = array( |
212 | 212 | 'alias' => $user, |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | ]); |
224 | 224 | $this->setSessionKey(self::LOGGED_USER_TOKEN, base64_encode("{$user}:{$pass}")); |
225 | 225 | } |
226 | - } else { |
|
226 | + }else { |
|
227 | 227 | $this->admin = null; |
228 | 228 | $this->setSessionKey(self::ADMIN_ID_TOKEN, null); |
229 | 229 | } |