@@ -140,12 +140,12 @@ discard block |
||
140 | 140 | * @return bool true: Cuando el inicio de sesión es correcto |
141 | 141 | * false: Cuando el inicio de sesión no es correcto |
142 | 142 | */ |
143 | - private function authentication(string $email,string $pass) : bool { |
|
143 | + private function authentication(string $email, string $pass) : bool { |
|
144 | 144 | $email = $this->db->scape($email); |
145 | - $query = $this->db->select('id_user,pass','users',"email='$email'",'LIMIT 1'); |
|
145 | + $query = $this->db->select('id_user,pass', 'users', "email='$email'", 'LIMIT 1'); |
|
146 | 146 | |
147 | 147 | # Incio de sesión con éxito |
148 | - if(false !== $query && Strings::chash($query[0]['pass'],$pass)) { |
|
148 | + if (false !== $query && Strings::chash($query[0]['pass'], $pass)) { |
|
149 | 149 | |
150 | 150 | # Restaurar intentos |
151 | 151 | $this->restoreAttempts($email); |
@@ -335,30 +335,30 @@ discard block |
||
335 | 335 | $pass = uniqid(); |
336 | 336 | |
337 | 337 | # Construir mensaje y enviar mensaje |
338 | - $HTML = 'Hola <b>'. $user_data[0]['name'] .'</b>, ha solicitado recuperar su contraseña perdida, si no ha realizado esta acción no necesita hacer nada. |
|
338 | + $HTML = 'Hola <b>' . $user_data[0]['name'] . '</b>, ha solicitado recuperar su contraseña perdida, si no ha realizado esta acción no necesita hacer nada. |
|
339 | 339 | <br /> |
340 | 340 | <br /> |
341 | - Para cambiar su contraseña por <b>'. $pass .'</b> haga <a href="'. $config['site']['url'] . 'lostpass/cambiar/&token='.$token.'&user='.$user_data[0]['id_user'].'" target="_blank">clic aquí</a>.'; |
|
341 | + Para cambiar su contraseña por <b>'. $pass . '</b> haga <a href="' . $config['site']['url'] . 'lostpass/cambiar/&token=' . $token . '&user=' . $user_data[0]['id_user'] . '" target="_blank">clic aquí</a>.'; |
|
342 | 342 | |
343 | 343 | # Enviar el correo electrónico |
344 | 344 | $dest = array(); |
345 | 345 | $dest[$email] = $user_data[0]['name']; |
346 | - $email = Emails::send_mail($dest,Emails::plantilla($HTML),'Recuperar contraseña perdida'); |
|
346 | + $email = Emails::send_mail($dest, Emails::plantilla($HTML), 'Recuperar contraseña perdida'); |
|
347 | 347 | |
348 | 348 | # Verificar si hubo algún problema con el envío del correo |
349 | - if(false === $email) { |
|
349 | + if (false === $email) { |
|
350 | 350 | throw new ModelsException('No se ha podido enviar el correo electrónico.'); |
351 | 351 | } |
352 | 352 | |
353 | 353 | # Actualizar datos |
354 | 354 | $id_user = $user_data[0]['id_user']; |
355 | - $this->db->update('users',array( |
|
355 | + $this->db->update('users', array( |
|
356 | 356 | 'tmp_pass' => Strings::hash($pass), |
357 | 357 | 'token' => $token |
358 | - ),"id_user='$id_user'",'LIMIT 1'); |
|
358 | + ), "id_user='$id_user'", 'LIMIT 1'); |
|
359 | 359 | |
360 | 360 | return array('success' => 1, 'message' => 'Se ha enviado un enlace a su correo electrónico.'); |
361 | - } catch(ModelsException $e) { |
|
361 | + } catch (ModelsException $e) { |
|
362 | 362 | return array('success' => 0, 'message' => $e->getMessage()); |
363 | 363 | } |
364 | 364 | } |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | * @return false|array con información del usuario |
418 | 418 | */ |
419 | 419 | public function getUserById(int $id, string $select = '*') { |
420 | - return $this->db->select($select,'users',"id_user='$id'",'LIMIT 1'); |
|
420 | + return $this->db->select($select, 'users', "id_user='$id'", 'LIMIT 1'); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | /** |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | * @return false|array con información de los usuarios |
429 | 429 | */ |
430 | 430 | public function getUsers(string $select = '*') { |
431 | - return $this->db->select($select,'users'); |
|
431 | + return $this->db->select($select, 'users'); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | /** |
@@ -440,12 +440,12 @@ discard block |
||
440 | 440 | * @return array con datos del usuario conectado |
441 | 441 | */ |
442 | 442 | public function getOwnerUser(string $select = '*') : array { |
443 | - if(null !== $this->id_user) { |
|
443 | + if (null !== $this->id_user) { |
|
444 | 444 | |
445 | - $user = $this->db->select($select,'users',"id_user='$this->id_user'",'LIMIT 1'); |
|
445 | + $user = $this->db->select($select, 'users', "id_user='$this->id_user'", 'LIMIT 1'); |
|
446 | 446 | |
447 | 447 | # Si se borra al usuario desde la base de datos y sigue con la sesión activa |
448 | - if(false === $user) { |
|
448 | + if (false === $user) { |
|
449 | 449 | $this->logout(); |
450 | 450 | } |
451 | 451 |
@@ -55,16 +55,16 @@ |
||
55 | 55 | $this->databaseConfig['new_instance'] = false; |
56 | 56 | |
57 | 57 | # Añadir según lo pasado por $databaseConfig |
58 | - if(is_array($databaseConfig)) { |
|
59 | - if(array_key_exists('name',$databaseConfig)) { |
|
60 | - $this->databaseConfig['name'] = $databaseConfig['name']; |
|
58 | + if (is_array($databaseConfig)) { |
|
59 | + if (array_key_exists('name', $databaseConfig)) { |
|
60 | + $this->databaseConfig['name'] = $databaseConfig['name']; |
|
61 | 61 | } |
62 | 62 | |
63 | - if(array_key_exists('motor',$databaseConfig)) { |
|
64 | - $this->databaseConfig['motor'] = $databaseConfig['motor']; |
|
63 | + if (array_key_exists('motor', $databaseConfig)) { |
|
64 | + $this->databaseConfig['motor'] = $databaseConfig['motor']; |
|
65 | 65 | } |
66 | 66 | |
67 | - if(array_key_exists('new_instance',$databaseConfig)) { |
|
67 | + if (array_key_exists('new_instance', $databaseConfig)) { |
|
68 | 68 | $this->databaseConfig['new_instance'] = (bool) $databaseConfig['new_instance']; |
69 | 69 | } |
70 | 70 | } |
@@ -62,7 +62,7 @@ |
||
62 | 62 | $this->functions = new Functions(); |
63 | 63 | |
64 | 64 | # Verificar sesión del usuario |
65 | - if(null !== $session->get('user_id') && $session->get('unique_session') == $config['sessions']['unique']) { |
|
65 | + if (null !== $session->get('user_id') && $session->get('unique_session') == $config['sessions']['unique']) { |
|
66 | 66 | $this->id_user = $session->get('user_id'); |
67 | 67 | } |
68 | 68 | } |
@@ -99,9 +99,9 @@ discard block |
||
99 | 99 | * |
100 | 100 | */ |
101 | 101 | final public static function date_difference(string $ini, string $fin) : int { |
102 | - $ini_i = explode('-',str_replace('/','-',$ini)); |
|
103 | - $fin_i = explode('-',str_replace('/','-',$fin)); |
|
104 | - return (int) floor((mktime(0, 0, 0, $fin_i[1], $fin_i[0], $fin_i[2]) - mktime(0, 0, 0, $ini_i[1], $ini_i[0], $ini_i[2])) / 86400); |
|
102 | + $ini_i = explode('-', str_replace('/', '-', $ini)); |
|
103 | + $fin_i = explode('-', str_replace('/', '-', $fin)); |
|
104 | + return (int) floor((mktime(0, 0, 0, $fin_i[1], $fin_i[0], $fin_i[2]) - mktime(0, 0, 0, $ini_i[1], $ini_i[0], $ini_i[2]))/86400); |
|
105 | 105 | } |
106 | 106 | //------------------------------------------------ |
107 | 107 | /** |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | * |
125 | 125 | */ |
126 | 126 | final public static function days_of_month() : int { |
127 | - return cal_days_in_month(CAL_GREGORIAN, (int) date('m',time()), (int) date('Y',time())); |
|
127 | + return cal_days_in_month(CAL_GREGORIAN, (int) date('m', time()), (int) date('Y', time())); |
|
128 | 128 | } |
129 | 129 | //------------------------------------------------ |
130 | 130 | /** |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | * @return int Cantidad de palabras |
295 | 295 | */ |
296 | 296 | final public static function count_words(string $s) : int { |
297 | - return (int) str_word_count($s,0); |
|
297 | + return (int) str_word_count($s, 0); |
|
298 | 298 | } |
299 | 299 | //------------------------------------------------ |
300 | 300 | /** |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @return bool con el resultado de la comparación |
30 | 30 | */ |
31 | 31 | final private function check_str_to_time(int $index, array $detail, int $max) : bool { |
32 | - return !array_key_exists($index,$detail) || !is_numeric($detail[$index]) || intval($detail[$index]) < $max; |
|
32 | + return !array_key_exists($index, $detail) || !is_numeric($detail[$index]) || intval($detail[$index]) < $max; |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | //------------------------------------------------ |
@@ -118,8 +118,8 @@ discard block |
||
118 | 118 | * @return bool con true si están todos llenos, false si al menos uno está vacío |
119 | 119 | */ |
120 | 120 | final public function all_full(array $array) : bool { |
121 | - foreach($array as $e) { |
|
122 | - if($this->emp($e) and $e != '0') { |
|
121 | + foreach ($array as $e) { |
|
122 | + if ($this->emp($e) and $e != '0') { |
|
123 | 123 | return false; |
124 | 124 | } |
125 | 125 | } |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | */ |
136 | 136 | final public function e() : bool { |
137 | 137 | for ($i = 0, $nargs = func_num_args(); $i < $nargs; $i++) { |
138 | - if(null === func_get_arg($i) || ($this->emp(func_get_arg($i)) && func_get_arg($i) != '0')) { |
|
138 | + if (null === func_get_arg($i) || ($this->emp(func_get_arg($i)) && func_get_arg($i) != '0')) { |
|
139 | 139 | return true; |
140 | 140 | } |
141 | 141 | } |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * @return string con la fecha en formato humano (y en español) |
154 | 154 | */ |
155 | 155 | final public function fecha(string $format, int $time = 0) : string { |
156 | - $date = date($format,$time == 0 ? time() : $time); |
|
156 | + $date = date($format, $time == 0 ? time() : $time); |
|
157 | 157 | $cambios = array( |
158 | 158 | 'Monday'=> 'Lunes', |
159 | 159 | 'Tuesday'=> 'Martes', |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | * @return string con el número del día |
227 | 227 | */ |
228 | 228 | final public function last_day_month(int $mes, int $anio) : string { |
229 | - return date('d', (mktime(0,0,0,$mes + 1, 1, $anio) - 1)); |
|
229 | + return date('d', (mktime(0, 0, 0, $mes + 1, 1, $anio) - 1)); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | //------------------------------------------------ |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | * @return string cifra con cero a la izquirda |
240 | 240 | */ |
241 | 241 | final public function cero_izq(int $num) : string { |
242 | - if($num < 10) { |
|
242 | + if ($num < 10) { |
|
243 | 243 | return '0' . $num; |
244 | 244 | } |
245 | 245 | |
@@ -257,24 +257,24 @@ discard block |
||
257 | 257 | * @return int|null con el timestamp |
258 | 258 | */ |
259 | 259 | final public function str_to_time($fecha, string $hora = '00:00:00') { |
260 | - if(null == $fecha) { |
|
260 | + if (null == $fecha) { |
|
261 | 261 | return null; |
262 | 262 | } |
263 | 263 | |
264 | - $detail = explode('/',$fecha); |
|
264 | + $detail = explode('/', $fecha); |
|
265 | 265 | |
266 | 266 | // Formato de día incorrecto |
267 | - if($this->check_str_to_time(0,$detail,1)) { |
|
267 | + if ($this->check_str_to_time(0, $detail, 1)) { |
|
268 | 268 | return null; |
269 | 269 | } |
270 | 270 | |
271 | 271 | // Formato de mes incorrecto |
272 | - if($this->check_str_to_time(1,$detail,1) || intval($detail[1]) > 12) { |
|
272 | + if ($this->check_str_to_time(1, $detail, 1) || intval($detail[1]) > 12) { |
|
273 | 273 | return null; |
274 | 274 | } |
275 | 275 | |
276 | 276 | // Formato del año |
277 | - if($this->check_str_to_time(2,$detail,1970)) { |
|
277 | + if ($this->check_str_to_time(2, $detail, 1970)) { |
|
278 | 278 | return null; |
279 | 279 | } |
280 | 280 | |
@@ -302,11 +302,11 @@ discard block |
||
302 | 302 | */ |
303 | 303 | final public function desde_date(int $desde) { |
304 | 304 | # Obtener esta fecha |
305 | - $hoy = date('d/m/Y/D',time()); |
|
306 | - $hoy = explode('/',$hoy); |
|
305 | + $hoy = date('d/m/Y/D', time()); |
|
306 | + $hoy = explode('/', $hoy); |
|
307 | 307 | |
308 | 308 | |
309 | - switch($desde) { |
|
309 | + switch ($desde) { |
|
310 | 310 | # Hoy |
311 | 311 | case 1: |
312 | 312 | return date('d/m/Y', time()); |
@@ -343,21 +343,21 @@ discard block |
||
343 | 343 | } |
344 | 344 | |
345 | 345 | # Mes anterior y posiblemente, año también. |
346 | - if($dia == 0) { |
|
346 | + if ($dia == 0) { |
|
347 | 347 | # Verificamos si estamos en enero |
348 | - if($hoy[1] == 1) { |
|
349 | - return $this->last_day_month($hoy[1],$hoy[2]) .'/'. $this->cero_izq($hoy[1] - 1) .'/' . ($hoy[2] - 1); |
|
348 | + if ($hoy[1] == 1) { |
|
349 | + return $this->last_day_month($hoy[1], $hoy[2]) . '/' . $this->cero_izq($hoy[1] - 1) . '/' . ($hoy[2] - 1); |
|
350 | 350 | } |
351 | 351 | |
352 | 352 | # Si no es enero, es el año actual |
353 | - return $this->last_day_month($hoy[1],$hoy[2]) .'/'. $this->cero_izq($hoy[1] - 1) .'/' . $hoy[2]; |
|
353 | + return $this->last_day_month($hoy[1], $hoy[2]) . '/' . $this->cero_izq($hoy[1] - 1) . '/' . $hoy[2]; |
|
354 | 354 | } |
355 | 355 | |
356 | - return $this->cero_izq($dia) .'/'. $this->cero_izq($hoy[1]) .'/' . $hoy[2]; |
|
356 | + return $this->cero_izq($dia) . '/' . $this->cero_izq($hoy[1]) . '/' . $hoy[2]; |
|
357 | 357 | |
358 | 358 | # Mes |
359 | 359 | case 4: |
360 | - return '01/'. $this->cero_izq($hoy[1]) .'/' . $hoy[2]; |
|
360 | + return '01/' . $this->cero_izq($hoy[1]) . '/' . $hoy[2]; |
|
361 | 361 | |
362 | 362 | # Año |
363 | 363 | case 5: |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @return int catidad de bytes escritos en el archivo |
49 | 49 | */ |
50 | 50 | final public static function write_file(string $dir, string $content) : int { |
51 | - $f = new \SplFileObject($dir,'w'); |
|
51 | + $f = new \SplFileObject($dir, 'w'); |
|
52 | 52 | return (int) $f->fwrite($content); |
53 | 53 | } |
54 | 54 | |
@@ -154,11 +154,11 @@ discard block |
||
154 | 154 | * @return bool con true si fue creado con éxito, false si el directorio ya existía o hubo algún error |
155 | 155 | */ |
156 | 156 | final public static function create_dir(string $dir, int $permisos = 0755) : bool { |
157 | - if(is_dir($dir)) { |
|
157 | + if (is_dir($dir)) { |
|
158 | 158 | return false; |
159 | 159 | } |
160 | 160 | |
161 | - return (bool) mkdir($dir,$permisos,true); |
|
161 | + return (bool) mkdir($dir, $permisos, true); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | //------------------------------------------------ |
@@ -230,16 +230,16 @@ discard block |
||
230 | 230 | |
231 | 231 | self::create_dir($new_dir); |
232 | 232 | |
233 | - foreach(glob($old_dir . ($only_images ? '{*.jpg,*.gif,*.png,*.gif,*.jpeg,*.JPG,*.GIF,*.PNG,*.JPEG}' : '*'),GLOB_BRACE) as $file) { |
|
234 | - if(file_exists($file)) { |
|
233 | + foreach (glob($old_dir . ($only_images ? '{*.jpg,*.gif,*.png,*.gif,*.jpeg,*.JPG,*.GIF,*.PNG,*.JPEG}' : '*'), GLOB_BRACE) as $file) { |
|
234 | + if (file_exists($file)) { |
|
235 | 235 | unlink($file); |
236 | 236 | } |
237 | 237 | |
238 | - $name = explode('/',$file); |
|
238 | + $name = explode('/', $file); |
|
239 | 239 | $name = end($name); |
240 | - copy($file,$new_dir . $name); |
|
240 | + copy($file, $new_dir . $name); |
|
241 | 241 | |
242 | - if($delete_old) { |
|
242 | + if ($delete_old) { |
|
243 | 243 | unlink($file); |
244 | 244 | } |
245 | 245 | } |
@@ -72,49 +72,49 @@ |
||
72 | 72 | try { |
73 | 73 | switch ($motor) { |
74 | 74 | case 'sqlite': |
75 | - parent::__construct('sqlite:'.$name); |
|
75 | + parent::__construct('sqlite:' . $name); |
|
76 | 76 | break; |
77 | 77 | case 'cubrid': |
78 | - parent::__construct('cubrid:host='.$config['database']['host'].';dbname='.$name.';port='.$config['database']['port'], |
|
78 | + parent::__construct('cubrid:host=' . $config['database']['host'] . ';dbname=' . $name . ';port=' . $config['database']['port'], |
|
79 | 79 | $config['database']['user'], |
80 | 80 | $config['database']['pass'], |
81 | 81 | $comun_config); |
82 | 82 | break; |
83 | 83 | case 'firebird': |
84 | - parent::__construct('firebird:dbname='.$config['database']['host'].':'.$name, |
|
84 | + parent::__construct('firebird:dbname=' . $config['database']['host'] . ':' . $name, |
|
85 | 85 | $config['database']['user'], |
86 | 86 | $config['database']['pass'], |
87 | 87 | $comun_config); |
88 | 88 | break; |
89 | 89 | case 'odbc'; |
90 | - parent::__construct('odbc:'.$name, |
|
90 | + parent::__construct('odbc:' . $name, |
|
91 | 91 | $config['database']['user'], |
92 | 92 | $config['database']['pass']); |
93 | 93 | break; |
94 | 94 | case 'oracle': |
95 | 95 | parent::__construct('oci:dbname=(DESCRIPTION = |
96 | 96 | (ADDRESS_LIST = |
97 | - (ADDRESS = (PROTOCOL = '.$config['database']['protocol'].')(HOST = '.$motor.')(PORT = '.$config['database']['port'].')) |
|
97 | + (ADDRESS = (PROTOCOL = '.$config['database']['protocol'] . ')(HOST = ' . $motor . ')(PORT = ' . $config['database']['port'] . ')) |
|
98 | 98 | ) |
99 | 99 | (CONNECT_DATA = |
100 | - (SERVICE_NAME = '.$name.') |
|
100 | + (SERVICE_NAME = '.$name . ') |
|
101 | 101 | ) |
102 | 102 | );charset=utf8', |
103 | 103 | $config['database']['user'], |
104 | 104 | $config['database']['pass'], |
105 | - array_merge(array(\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC),$comun_config)); |
|
105 | + array_merge(array(\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC), $comun_config)); |
|
106 | 106 | break; |
107 | 107 | case 'postgresql': |
108 | - parent::__construct('pgsql:host='.$config['database']['host'].';dbname='.$name.';charset=utf8', |
|
108 | + parent::__construct('pgsql:host=' . $config['database']['host'] . ';dbname=' . $name . ';charset=utf8', |
|
109 | 109 | $config['database']['user'], |
110 | 110 | $config['database']['pass'], |
111 | 111 | $comun_config); |
112 | 112 | break; |
113 | 113 | case 'mysql': |
114 | - parent::__construct('mysql:host='.$config['database']['host'].';dbname='.$name, |
|
114 | + parent::__construct('mysql:host=' . $config['database']['host'] . ';dbname=' . $name, |
|
115 | 115 | $config['database']['user'], |
116 | 116 | $config['database']['pass'], |
117 | - array_merge(array(\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'),$comun_config)); |
|
117 | + array_merge(array(\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'), $comun_config)); |
|
118 | 118 | break; |
119 | 119 | case 'mssql': |
120 | 120 | # Añadido por marc2684 |