@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | */ |
| 93 | 93 | final private function setCollectionRule(string $index, string $rule) { |
| 94 | 94 | # Verificar si la regla existe |
| 95 | - if(!in_array($rule,self::RULES)) { |
|
| 95 | + if (!in_array($rule, self::RULES)) { |
|
| 96 | 96 | throw new \RuntimeException('La regla ' . $rule . ' no existe.'); |
| 97 | 97 | } |
| 98 | 98 | # Definir la regla para la ruta |
@@ -104,14 +104,14 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | final private function checkRequests() { |
| 106 | 106 | # Verificar si existe peticiones |
| 107 | - if(null !== $this->requestUri) { |
|
| 108 | - $this->real_request = explode('/',$this->requestUri); |
|
| 107 | + if (null !== $this->requestUri) { |
|
| 108 | + $this->real_request = explode('/', $this->requestUri); |
|
| 109 | 109 | $this->routerCollection['/controller'] = $this->real_request[0]; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | # Setear las siguientes rutas |
| 113 | - $this->routerCollection['/method'] = array_key_exists(1,$this->real_request) ? $this->real_request[1] : null; |
|
| 114 | - $this->routerCollection['/id'] = array_key_exists(2,$this->real_request) ? $this->real_request[2] : null; |
|
| 113 | + $this->routerCollection['/method'] = array_key_exists(1, $this->real_request) ? $this->real_request[1] : null; |
|
| 114 | + $this->routerCollection['/id'] = array_key_exists(2, $this->real_request) ? $this->real_request[2] : null; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | */ |
| 125 | 125 | final public function setRoute(string $index, string $rule = 'none') { |
| 126 | 126 | # Nombres de rutas no permitidos |
| 127 | - if(in_array($index,['/controller','/method','/id'])) { |
|
| 127 | + if (in_array($index, ['/controller', '/method', '/id'])) { |
|
| 128 | 128 | throw new \RuntimeException('No puede definirse ' . $index . ' como índice en la ruta.'); |
| 129 | 129 | } |
| 130 | 130 | |
@@ -136,8 +136,8 @@ discard block |
||
| 136 | 136 | |
| 137 | 137 | # Definir la ruta y regla |
| 138 | 138 | $lastRoute = sizeof($this->routerCollection); |
| 139 | - $this->routerCollection[$index] = array_key_exists($lastRoute,$this->real_request) ? $this->real_request[$lastRoute] : null; |
|
| 140 | - $this->setCollectionRule($index,$rule); |
|
| 139 | + $this->routerCollection[$index] = array_key_exists($lastRoute, $this->real_request) ? $this->real_request[$lastRoute] : null; |
|
| 140 | + $this->setCollectionRule($index, $rule); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | */ |
| 151 | 151 | final public function getRoute(string $index) { |
| 152 | 152 | # Verificar existencia de ruta |
| 153 | - if(!array_key_exists($index,$this->routerCollection)) { |
|
| 153 | + if (!array_key_exists($index, $this->routerCollection)) { |
|
| 154 | 154 | throw new \RuntimeException('La ruta ' . $index . ' no está definida en el controlador.'); |
| 155 | 155 | } |
| 156 | 156 | |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | $rules = new Rules; |
| 160 | 160 | |
| 161 | 161 | # Retornar ruta con la regla definida aplicada |
| 162 | - if(method_exists($rules, $this->routerCollectionRules[$index])) { |
|
| 162 | + if (method_exists($rules, $this->routerCollectionRules[$index])) { |
|
| 163 | 163 | return $rules->{$this->routerCollectionRules[$index]}($ruta); |
| 164 | 164 | } |
| 165 | 165 | |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | */ |
| 199 | 199 | final public function getId(bool $with_rules = false) { |
| 200 | 200 | $id = $this->routerCollection['/id']; |
| 201 | - if($with_rules && (!is_numeric($id) || $id <= 0)) { |
|
| 201 | + if ($with_rules && (!is_numeric($id) || $id <= 0)) { |
|
| 202 | 202 | return null; |
| 203 | 203 | } |
| 204 | 204 | |
@@ -212,10 +212,10 @@ discard block |
||
| 212 | 212 | */ |
| 213 | 213 | final public function executeController() { |
| 214 | 214 | # Definir controlador |
| 215 | - if(null != ($controller = $this->getController())) { |
|
| 215 | + if (null != ($controller = $this->getController())) { |
|
| 216 | 216 | $controller = $controller . 'Controller'; |
| 217 | 217 | |
| 218 | - if(!is_readable('app/controllers/' . $controller . '.php')) { |
|
| 218 | + if (!is_readable('app/controllers/' . $controller . '.php')) { |
|
| 219 | 219 | $controller = 'errorController'; |
| 220 | 220 | } |
| 221 | 221 | |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | final public static function Start($name = null, $motor = null, bool $new_instance = false) : Database { |
| 40 | 40 | global $config; |
| 41 | 41 | |
| 42 | - if(!self::$inst instanceof self or $new_instance) { |
|
| 42 | + if (!self::$inst instanceof self or $new_instance) { |
|
| 43 | 43 | self::$inst = new self( |
| 44 | 44 | null === $name ? $config['database']['name'] : $name, |
| 45 | 45 | null === $motor ? $config['database']['motor'] : $motor |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | * @param array $params: Lista de parámetros de configuración |
| 56 | 56 | */ |
| 57 | 57 | final private function motor_mysql(array $params) { |
| 58 | - parent::__construct('mysql:host='.$params['host'].';dbname='.$params['name'], |
|
| 58 | + parent::__construct('mysql:host=' . $params['host'] . ';dbname=' . $params['name'], |
|
| 59 | 59 | $params['user'], |
| 60 | 60 | $params['pass'], |
| 61 | 61 | array(\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | * @param array $params: Lista de parámetros de configuración |
| 71 | 71 | */ |
| 72 | 72 | final private function motor_sqlite(array $params) { |
| 73 | - parent::__construct('sqlite:'.$params['name']); |
|
| 73 | + parent::__construct('sqlite:' . $params['name']); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | * @param array $params: Lista de parámetros de configuración |
| 80 | 80 | */ |
| 81 | 81 | final private function motor_cubrid(array $params) { |
| 82 | - parent::__construct('cubrid:host='.$params['host'].';dbname='.$params['name'].';port='.$params['port'], |
|
| 82 | + parent::__construct('cubrid:host=' . $params['host'] . ';dbname=' . $params['name'] . ';port=' . $params['port'], |
|
| 83 | 83 | $params['user'], |
| 84 | - $params['pass'],array( |
|
| 84 | + $params['pass'], array( |
|
| 85 | 85 | \PDO::ATTR_EMULATE_PREPARES => false, |
| 86 | 86 | \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION |
| 87 | 87 | )); |
@@ -93,9 +93,9 @@ discard block |
||
| 93 | 93 | * @param array $params: Lista de parámetros de configuración |
| 94 | 94 | */ |
| 95 | 95 | final private function motor_firebird(array $params) { |
| 96 | - parent::__construct('firebird:dbname='.$params['host'].':'.$params['name'], |
|
| 96 | + parent::__construct('firebird:dbname=' . $params['host'] . ':' . $params['name'], |
|
| 97 | 97 | $params['user'], |
| 98 | - $params['pass'],array( |
|
| 98 | + $params['pass'], array( |
|
| 99 | 99 | \PDO::ATTR_EMULATE_PREPARES => false, |
| 100 | 100 | \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION |
| 101 | 101 | )); |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | * @param array $params: Lista de parámetros de configuración |
| 108 | 108 | */ |
| 109 | 109 | final private function motor_odbc(array $params) { |
| 110 | - parent::__construct('odbc:'.$params['name'], |
|
| 110 | + parent::__construct('odbc:' . $params['name'], |
|
| 111 | 111 | $params['user'], |
| 112 | 112 | $params['pass'] |
| 113 | 113 | ); |
@@ -121,12 +121,12 @@ discard block |
||
| 121 | 121 | final private function motor_oracle(array $params) { |
| 122 | 122 | parent::__construct('oci:dbname=(DESCRIPTION = |
| 123 | 123 | (ADDRESS_LIST = |
| 124 | - (ADDRESS = (PROTOCOL = '.$params['protocol'].')(HOST = '.$params['host'].')(PORT = '.$params['port'].')) |
|
| 124 | + (ADDRESS = (PROTOCOL = '.$params['protocol'] . ')(HOST = ' . $params['host'] . ')(PORT = ' . $params['port'] . ')) |
|
| 125 | 125 | ) |
| 126 | 126 | (CONNECT_DATA = |
| 127 | - (SERVICE_NAME = '.$params['name'].') |
|
| 127 | + (SERVICE_NAME = '.$params['name'] . ') |
|
| 128 | 128 | ) |
| 129 | - );charset=utf8',$params['database']['user'],$params['database']['pass'], |
|
| 129 | + );charset=utf8',$params['database']['user'], $params['database']['pass'], |
|
| 130 | 130 | array(\PDO::ATTR_EMULATE_PREPARES => false, |
| 131 | 131 | \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, |
| 132 | 132 | \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC |
@@ -139,9 +139,9 @@ discard block |
||
| 139 | 139 | * @param array $params: Lista de parámetros de configuración |
| 140 | 140 | */ |
| 141 | 141 | final private function motor_postgresql(array $params) { |
| 142 | - parent::__construct('pgsql:host='.$params['host'].';dbname='.$params['name'].';charset=utf8', |
|
| 142 | + parent::__construct('pgsql:host=' . $params['host'] . ';dbname=' . $params['name'] . ';charset=utf8', |
|
| 143 | 143 | $params['user'], |
| 144 | - $params['pass'],array( |
|
| 144 | + $params['pass'], array( |
|
| 145 | 145 | \PDO::ATTR_EMULATE_PREPARES => false, |
| 146 | 146 | \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION |
| 147 | 147 | )); |
@@ -154,9 +154,9 @@ discard block |
||
| 154 | 154 | * @param array $params: Lista de parámetros de configuración |
| 155 | 155 | */ |
| 156 | 156 | final private function motor_mssql(array $params) { |
| 157 | - parent::__construct('sqlsrv:Server='.$params['host'].';Database='.$params['name'].';ConnectionPooling=0', |
|
| 157 | + parent::__construct('sqlsrv:Server=' . $params['host'] . ';Database=' . $params['name'] . ';ConnectionPooling=0', |
|
| 158 | 158 | $params['user'], |
| 159 | - $params['pass'],array(\PDO::ATTR_EMULATE_PREPARES => false, |
|
| 159 | + $params['pass'], array(\PDO::ATTR_EMULATE_PREPARES => false, |
|
| 160 | 160 | \PDO::SQLSRV_ENCODING_UTF8, |
| 161 | 161 | \PDO::ATTR_ERRMODE => |
| 162 | 162 | \PDO::ERRMODE_EXCEPTION |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | |
| 180 | 180 | try { |
| 181 | 181 | # Verificar existencia del motor |
| 182 | - if(method_exists($this,'motor_' . $motor)) { |
|
| 182 | + if (method_exists($this, 'motor_' . $motor)) { |
|
| 183 | 183 | $this->{'motor_' . $motor}(array( |
| 184 | 184 | 'host' => $config['database']['host'], |
| 185 | 185 | 'name' => $name, |
@@ -189,9 +189,9 @@ discard block |
||
| 189 | 189 | 'protocol' => $config['database']['protocol'] |
| 190 | 190 | )); |
| 191 | 191 | } else { |
| 192 | - throw new \RuntimeException('Motor '. $motor .' de conexión no identificado.'); |
|
| 192 | + throw new \RuntimeException('Motor ' . $motor . ' de conexión no identificado.'); |
|
| 193 | 193 | } |
| 194 | - } catch(\PDOException $e) { |
|
| 194 | + } catch (\PDOException $e) { |
|
| 195 | 195 | throw new \RuntimeException('Problema al conectar con la base de datos: ' . $e->getMessage()); |
| 196 | 196 | } |
| 197 | 197 | } |
@@ -226,18 +226,18 @@ discard block |
||
| 226 | 226 | * @return mixed elemento sano |
| 227 | 227 | */ |
| 228 | 228 | final public function scape($e) { |
| 229 | - if(null === $e) { |
|
| 229 | + if (null === $e) { |
|
| 230 | 230 | return ''; |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | - if(is_numeric($e) and $e <= 2147483647) { |
|
| 234 | - if(explode('.',$e)[0] != $e) { |
|
| 233 | + if (is_numeric($e) and $e <= 2147483647) { |
|
| 234 | + if (explode('.', $e)[0] != $e) { |
|
| 235 | 235 | return (float) $e; |
| 236 | 236 | } |
| 237 | 237 | return (int) $e; |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - return (string) trim(str_replace(['\\',"\x00",'\n','\r',"'",'"',"\x1a"],['\\\\','\\0','\\n','\\r',"\'",'\"','\\Z'],$e)); |
|
| 240 | + return (string) trim(str_replace(['\\', "\x00", '\n', '\r', "'", '"', "\x1a"], ['\\\\', '\\0', '\\n', '\\r', "\'", '\"', '\\Z'], $e)); |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | /** |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | */ |
| 266 | 266 | final public function insert(string $table, array $e) : \PDOStatement { |
| 267 | 267 | if (sizeof($e) == 0) { |
| 268 | - throw new \RuntimeException('El arreglo pasado por $this->db->insert(\''.$table.'\',...) está vacío.'); |
|
| 268 | + throw new \RuntimeException('El arreglo pasado por $this->db->insert(\'' . $table . '\',...) está vacío.'); |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | $query = "INSERT INTO $table ("; |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | */ |
| 296 | 296 | final public function update(string $table, array $e, string $where, string $limit = '') : \PDOStatement { |
| 297 | 297 | if (sizeof($e) == 0) { |
| 298 | - throw new \RuntimeException('El arreglo pasado por $this->db->update(\''.$table.'\'...) está vacío.'); |
|
| 298 | + throw new \RuntimeException('El arreglo pasado por $this->db->update(\'' . $table . '\'...) está vacío.'); |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | $query = "UPDATE $table SET "; |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | $result = $sql->fetchAll(); |
| 333 | 333 | $sql->closeCursor(); |
| 334 | 334 | |
| 335 | - if(sizeof($result) > 0) { |
|
| 335 | + if (sizeof($result) > 0) { |
|
| 336 | 336 | return $result; |
| 337 | 337 | } |
| 338 | 338 | |
@@ -43,19 +43,19 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | final public static function arrays_sum(array $a, array $b) : array { |
| 45 | 45 | # Si alguno está vacío |
| 46 | - if(sizeof($a) == 0) { |
|
| 46 | + if (sizeof($a) == 0) { |
|
| 47 | 47 | return $b; |
| 48 | - } else if(sizeof($b) == 0) { |
|
| 48 | + } else if (sizeof($b) == 0) { |
|
| 49 | 49 | return $a; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | # Recorrer el segundo arreglo |
| 53 | - foreach($b as $llave => $contenido) { |
|
| 53 | + foreach ($b as $llave => $contenido) { |
|
| 54 | 54 | # Verificar que no hay desnivel |
| 55 | - if(!is_array($a[$llave]) && !is_array($b[$llave])) { |
|
| 55 | + if (!is_array($a[$llave]) && !is_array($b[$llave])) { |
|
| 56 | 56 | $a[$llave] += $b[$llave]; |
| 57 | 57 | } else { |
| 58 | - throw new \RuntimeException('Existe un problema para operar en la llave '.$llave.'.'); |
|
| 58 | + throw new \RuntimeException('Existe un problema para operar en la llave ' . $llave . '.'); |
|
| 59 | 59 | break; |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | final public static function get_key_by_index(string $index, array $a) : int { |
| 77 | 77 | $i = 0; |
| 78 | 78 | foreach ($a as $key => $val) { |
| 79 | - if($key == $index) { |
|
| 79 | + if ($key == $index) { |
|
| 80 | 80 | return (int) $i; |
| 81 | 81 | } |
| 82 | 82 | $i++; |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | * @return bool false si no lo es, true si lo es |
| 110 | 110 | */ |
| 111 | 111 | final public static function is_assoc(array $a) : bool { |
| 112 | - if(sizeof($a) === 0) { |
|
| 112 | + if (sizeof($a) === 0) { |
|
| 113 | 113 | return false; |
| 114 | 114 | } |
| 115 | 115 | |
@@ -29,14 +29,14 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | final public static function amigable_time(int $from, int $to = 0) : string { |
| 31 | 31 | $intervalos = array("segundo", "minuto", "hora", "día", "semana", "mes", "año"); |
| 32 | - $duraciones = array("60","60","24","7","4.35","12"); |
|
| 32 | + $duraciones = array("60", "60", "24", "7", "4.35", "12"); |
|
| 33 | 33 | $to = $to === 0 ? time() : $to; |
| 34 | 34 | |
| 35 | - if(empty($from)) { |
|
| 35 | + if (empty($from)) { |
|
| 36 | 36 | return "Fecha incorracta"; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - if($to > $from) { |
|
| 39 | + if ($to > $from) { |
|
| 40 | 40 | $diferencia = $to - $from; |
| 41 | 41 | $tiempo = "Hace"; |
| 42 | 42 | } else { |
@@ -44,15 +44,15 @@ discard block |
||
| 44 | 44 | $tiempo = "Dentro de"; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - for($j = 0; $diferencia >= $duraciones[$j] && $j < count($duraciones)-1; $j++) { |
|
| 47 | + for ($j = 0; $diferencia >= $duraciones[$j] && $j < count($duraciones) - 1; $j++) { |
|
| 48 | 48 | $diferencia /= $duraciones[$j]; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | $diferencia = round($diferencia); |
| 52 | 52 | |
| 53 | - if($diferencia != 1) { |
|
| 54 | - $intervalos[5].="e"; //MESES |
|
| 55 | - $intervalos[$j].= "s"; |
|
| 53 | + if ($diferencia != 1) { |
|
| 54 | + $intervalos[5] .= "e"; //MESES |
|
| 55 | + $intervalos[$j] .= "s"; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | return "$tiempo $diferencia $intervalos[$j]"; |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | * @return string Hash, con la forma $2a$10$87b2b603324793cc37f8dOPFTnHRY0lviq5filK5cN4aMCQDJcC9G |
| 81 | 81 | */ |
| 82 | 82 | final public static function hash(string $p) : string { |
| 83 | - return crypt($p, '$2a$10$' . substr(sha1(mt_rand()),0,22)); |
|
| 83 | + return crypt($p, '$2a$10$' . substr(sha1(mt_rand()), 0, 22)); |
|
| 84 | 84 | } |
| 85 | 85 | //------------------------------------------------ |
| 86 | 86 | /** |
@@ -93,9 +93,9 @@ discard block |
||
| 93 | 93 | * |
| 94 | 94 | */ |
| 95 | 95 | final public static function date_difference(string $ini, string $fin) : int { |
| 96 | - $ini_i = explode('-',str_replace('/','-',$ini)); |
|
| 97 | - $fin_i = explode('-',str_replace('/','-',$fin)); |
|
| 98 | - 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); |
|
| 96 | + $ini_i = explode('-', str_replace('/', '-', $ini)); |
|
| 97 | + $fin_i = explode('-', str_replace('/', '-', $fin)); |
|
| 98 | + 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); |
|
| 99 | 99 | } |
| 100 | 100 | //------------------------------------------------ |
| 101 | 101 | /** |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | * |
| 108 | 108 | */ |
| 109 | 109 | final public static function calculate_age(string $cumple) : int { |
| 110 | - $age = explode('.', (string) (self::date_difference($cumple,date('d-m-Y',time())) / 365)); |
|
| 110 | + $age = explode('.', (string) (self::date_difference($cumple, date('d-m-Y', time()))/365)); |
|
| 111 | 111 | return (int) $age[0]; |
| 112 | 112 | } |
| 113 | 113 | //------------------------------------------------ |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | * |
| 119 | 119 | */ |
| 120 | 120 | final public static function days_of_month() : int { |
| 121 | - return cal_days_in_month(CAL_GREGORIAN, (int) date('m',time()), (int) date('Y',time())); |
|
| 121 | + return cal_days_in_month(CAL_GREGORIAN, (int) date('m', time()), (int) date('Y', time())); |
|
| 122 | 122 | } |
| 123 | 123 | //------------------------------------------------ |
| 124 | 124 | /** |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | * @return string del texto sin espacios |
| 141 | 141 | */ |
| 142 | 142 | final public static function remove_spaces(string $s) : string { |
| 143 | - return trim(str_replace(' ','',$s)); |
|
| 143 | + return trim(str_replace(' ', '', $s)); |
|
| 144 | 144 | } |
| 145 | 145 | //------------------------------------------------ |
| 146 | 146 | /** |
@@ -185,9 +185,9 @@ discard block |
||
| 185 | 185 | */ |
| 186 | 186 | final public static function url_amigable(string $url) : string { |
| 187 | 187 | $url = strtolower($url); |
| 188 | - $url = str_replace (['á', 'é', 'í', 'ó', 'ú', 'ñ'],['a', 'e', 'i', 'o', 'u', 'n'], $url); |
|
| 189 | - $url = str_replace([' ', '&', '\r\n', '\n', '+', '%'],'-',$url); |
|
| 190 | - return preg_replace (['/[^a-z0-9\-<>]/', '/[\-]+/', '/<[^>]*>/'],['', '-', ''], $url); |
|
| 188 | + $url = str_replace(['á', 'é', 'í', 'ó', 'ú', 'ñ'], ['a', 'e', 'i', 'o', 'u', 'n'], $url); |
|
| 189 | + $url = str_replace([' ', '&', '\r\n', '\n', '+', '%'], '-', $url); |
|
| 190 | + return preg_replace(['/[^a-z0-9\-<>]/', '/[\-]+/', '/<[^>]*>/'], ['', '-', ''], $url); |
|
| 191 | 191 | } |
| 192 | 192 | //------------------------------------------------ |
| 193 | 193 | /** |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | '<span style="font-size: $1px">$2</span>', |
| 241 | 241 | '<span style="font-family: $1">$2</span>' |
| 242 | 242 | ); |
| 243 | - return nl2br(preg_replace($BBcode,$HTML,$string)); |
|
| 243 | + return nl2br(preg_replace($BBcode, $HTML, $string)); |
|
| 244 | 244 | } |
| 245 | 245 | //------------------------------------------------ |
| 246 | 246 | /** |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | * @return int Cantidad de palabras |
| 289 | 289 | */ |
| 290 | 290 | final public static function count_words(string $s) : int { |
| 291 | - return (int) str_word_count($s,0); |
|
| 291 | + return (int) str_word_count($s, 0); |
|
| 292 | 292 | } |
| 293 | 293 | //------------------------------------------------ |
| 294 | 294 | /** |
@@ -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 | //------------------------------------------------ |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | final public function redir($url = null) { |
| 46 | 46 | global $config; |
| 47 | 47 | |
| 48 | - if(null == $url) { |
|
| 48 | + if (null == $url) { |
|
| 49 | 49 | $url = $config['site']['url']; |
| 50 | 50 | } |
| 51 | 51 | |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * @return float con el porcentaje correspondiente |
| 65 | 65 | */ |
| 66 | 66 | final public function percent(float $por, float $n) : float { |
| 67 | - return $n * ($por / 100); |
|
| 67 | + return $n*($por/100); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | //------------------------------------------------ |
@@ -77,8 +77,8 @@ discard block |
||
| 77 | 77 | * @return string del tamaño $size convertido a la unidad más adecuada |
| 78 | 78 | */ |
| 79 | 79 | final public function convert(int $size) : string { |
| 80 | - $unit = array('bytes','kb','mb','gb','tb','pb'); |
|
| 81 | - return round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i]; |
|
| 80 | + $unit = array('bytes', 'kb', 'mb', 'gb', 'tb', 'pb'); |
|
| 81 | + return round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . ' ' . $unit[$i]; |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | //------------------------------------------------ |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * @return bool con true si está vacío, false si no, un espacio en blanco cuenta como vacío |
| 105 | 105 | */ |
| 106 | 106 | final public function emp($var) : bool { |
| 107 | - return (null === $var || empty(trim(str_replace(' ','',$var)))); |
|
| 107 | + return (null === $var || empty(trim(str_replace(' ', '', $var)))); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | //------------------------------------------------ |
@@ -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($this->emp(func_get_arg($i)) && func_get_arg($i) != '0') { |
|
| 138 | + if ($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', |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | 'Apr'=> 'Abr', |
| 187 | 187 | 'Dec'=> 'Dic' |
| 188 | 188 | ); |
| 189 | - return str_replace(array_keys($cambios),array_values($cambios),$date); |
|
| 189 | + return str_replace(array_keys($cambios), array_values($cambios), $date); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | //------------------------------------------------ |
@@ -206,13 +206,13 @@ discard block |
||
| 206 | 206 | # Revisar protocolo |
| 207 | 207 | $base = $config['site']['router']['protocol'] . '://'; |
| 208 | 208 | |
| 209 | - if(strtolower($www) == 'www') { |
|
| 209 | + if (strtolower($www) == 'www') { |
|
| 210 | 210 | $base .= 'www.' . $config['site']['router']['path']; |
| 211 | 211 | } else { |
| 212 | 212 | $base .= $config['site']['router']['path']; |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - return '<base href="'.$base.'" />'; |
|
| 215 | + return '<base href="' . $base . '" />'; |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | //------------------------------------------------ |
@@ -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,17 +257,17 @@ 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, mes y año incorrectos |
| 267 | - if ($this->check_str_to_time(0,$detail,1) |
|
| 268 | - || $this->check_str_to_time(1,$detail,1) |
|
| 267 | + if ($this->check_str_to_time(0, $detail, 1) |
|
| 268 | + || $this->check_str_to_time(1, $detail, 1) |
|
| 269 | 269 | || intval($detail[1]) > 12 |
| 270 | - || $this->check_str_to_time(2,$detail,1970)) { |
|
| 270 | + || $this->check_str_to_time(2, $detail, 1970)) { |
|
| 271 | 271 | return null; |
| 272 | 272 | } |
| 273 | 273 | |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | $year = intval($detail[2]); |
| 278 | 278 | |
| 279 | 279 | // Veriricar dia según mes |
| 280 | - if($day > $this->last_day_month($month,$year)) { |
|
| 280 | + if ($day > $this->last_day_month($month, $year)) { |
|
| 281 | 281 | return null; |
| 282 | 282 | } |
| 283 | 283 | |
@@ -295,8 +295,8 @@ discard block |
||
| 295 | 295 | */ |
| 296 | 296 | final public function desde_date(int $desde) { |
| 297 | 297 | # Obtener esta fecha |
| 298 | - $hoy = date('d/m/Y/D',time()); |
|
| 299 | - $hoy = explode('/',$hoy); |
|
| 298 | + $hoy = date('d/m/Y/D', time()); |
|
| 299 | + $hoy = explode('/', $hoy); |
|
| 300 | 300 | |
| 301 | 301 | # Arreglo de condiciones y subcondiciones |
| 302 | 302 | $fecha = array( |
@@ -311,21 +311,21 @@ discard block |
||
| 311 | 311 | 'Sat' => intval($hoy[0]) - 5, |
| 312 | 312 | 'Sun' => intval($hoy[0]) - 6 |
| 313 | 313 | ), |
| 314 | - 4 => '01/'. $this->cero_izq($hoy[1]) .'/' . $hoy[2], |
|
| 314 | + 4 => '01/' . $this->cero_izq($hoy[1]) . '/' . $hoy[2], |
|
| 315 | 315 | 5 => '01/01/' . $hoy[2] |
| 316 | 316 | ); |
| 317 | 317 | |
| 318 | - if($desde == 3) { |
|
| 318 | + if ($desde == 3) { |
|
| 319 | 319 | # Dia actual |
| 320 | 320 | $dia = $fecha[3][$hoy[3]]; |
| 321 | 321 | |
| 322 | 322 | # Mes anterior y posiblemente, año también. |
| 323 | - if($dia == 0) { |
|
| 323 | + if ($dia == 0) { |
|
| 324 | 324 | # Restante de la fecha |
| 325 | - $real_fecha = $this->last_day_month($hoy[1],$hoy[2]) .'/'. $this->cero_izq($hoy[1] - 1) .'/'; |
|
| 325 | + $real_fecha = $this->last_day_month($hoy[1], $hoy[2]) . '/' . $this->cero_izq($hoy[1] - 1) . '/'; |
|
| 326 | 326 | |
| 327 | 327 | # Verificamos si estamos en enero |
| 328 | - if($hoy[1] == 1) { |
|
| 328 | + if ($hoy[1] == 1) { |
|
| 329 | 329 | return $real_fecha . ($hoy[2] - 1); |
| 330 | 330 | } |
| 331 | 331 | |
@@ -333,8 +333,8 @@ discard block |
||
| 333 | 333 | return $real_fecha . $hoy[2]; |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | - return $this->cero_izq($dia) .'/'. $this->cero_izq($hoy[1]) .'/' . $hoy[2]; |
|
| 337 | - } else if(array_key_exists($desde,$fecha)) { |
|
| 336 | + return $this->cero_izq($dia) . '/' . $this->cero_izq($hoy[1]) . '/' . $hoy[2]; |
|
| 337 | + } else if (array_key_exists($desde, $fecha)) { |
|
| 338 | 338 | return $fecha[$desde]; |
| 339 | 339 | } |
| 340 | 340 | |
@@ -368,13 +368,13 @@ discard block |
||
| 368 | 368 | new \Twig_Function('e_dynamic', array($this, 'e')), |
| 369 | 369 | new \Twig_Function('all_full', array($this, 'all_full')), |
| 370 | 370 | new \Twig_Function('fecha', array($this, 'fecha')), |
| 371 | - new \Twig_Function('base_assets',array($this, 'base_assets')), |
|
| 372 | - new \Twig_Function('timestamp',array($this, 'timestamp')), |
|
| 373 | - new \Twig_Function('desde_date',array($this, 'desde_date')), |
|
| 374 | - new \Twig_Function('cero_izq',array($this, 'cero_izq')), |
|
| 375 | - new \Twig_Function('last_day_month',array($this, 'last_day_month')), |
|
| 376 | - new \Twig_Function('str_to_time',array($this, 'str_to_time')), |
|
| 377 | - new \Twig_Function('desde_date',array($this, 'desde_date')) |
|
| 371 | + new \Twig_Function('base_assets', array($this, 'base_assets')), |
|
| 372 | + new \Twig_Function('timestamp', array($this, 'timestamp')), |
|
| 373 | + new \Twig_Function('desde_date', array($this, 'desde_date')), |
|
| 374 | + new \Twig_Function('cero_izq', array($this, 'cero_izq')), |
|
| 375 | + new \Twig_Function('last_day_month', array($this, 'last_day_month')), |
|
| 376 | + new \Twig_Function('str_to_time', array($this, 'str_to_time')), |
|
| 377 | + new \Twig_Function('desde_date', array($this, 'desde_date')) |
|
| 378 | 378 | ); |
| 379 | 379 | } |
| 380 | 380 | |