@@ -3,8 +3,8 @@ |
||
3 | 3 | spl_autoload_register('__ocrend_autoload'); |
4 | 4 | |
5 | 5 | function __ocrend_autoload(string $class) { |
6 | - $class = API_INTERFACE . str_replace('\\','/',$class); |
|
7 | - if(is_readable($class . '.php')) { |
|
6 | + $class = API_INTERFACE . str_replace('\\', '/', $class); |
|
7 | + if (is_readable($class . '.php')) { |
|
8 | 8 | require_once $class . '.php'; |
9 | 9 | } |
10 | 10 | } |
11 | 11 | \ No newline at end of file |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | */ |
92 | 92 | final private function setCollectionRule(string $index, string $rule) { |
93 | 93 | # Verificar si la regla existe |
94 | - if(!in_array($rule,self::RULES)) { |
|
94 | + if (!in_array($rule, self::RULES)) { |
|
95 | 95 | throw new \RuntimeException('La regla ' . $rule . ' no existe.'); |
96 | 96 | } |
97 | 97 | # Definir la regla para la ruta |
@@ -103,14 +103,14 @@ discard block |
||
103 | 103 | */ |
104 | 104 | final private function checkRequests() { |
105 | 105 | # Verificar si existe peticiones |
106 | - if(null !== $this->requestUri) { |
|
107 | - $this->real_request = explode('/',$this->requestUri); |
|
106 | + if (null !== $this->requestUri) { |
|
107 | + $this->real_request = explode('/', $this->requestUri); |
|
108 | 108 | $this->routerCollection['/controller'] = $this->real_request[0]; |
109 | 109 | } |
110 | 110 | |
111 | 111 | # Setear las siguientes rutas |
112 | - $this->routerCollection['/method'] = array_key_exists(1,$this->real_request) ? $this->real_request[1] : null; |
|
113 | - $this->routerCollection['/id'] = array_key_exists(2,$this->real_request) ? $this->real_request[2] : null; |
|
112 | + $this->routerCollection['/method'] = array_key_exists(1, $this->real_request) ? $this->real_request[1] : null; |
|
113 | + $this->routerCollection['/id'] = array_key_exists(2, $this->real_request) ? $this->real_request[2] : null; |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | */ |
124 | 124 | final public function setRoute(string $index, string $rule = 'none') { |
125 | 125 | # Nombres de rutas no permitidos |
126 | - if(in_array($index,['/controller','/method','/id'])) { |
|
126 | + if (in_array($index, ['/controller', '/method', '/id'])) { |
|
127 | 127 | throw new \RuntimeException('No puede definirse ' . $index . ' como índice en la ruta.'); |
128 | 128 | } |
129 | 129 | |
@@ -135,8 +135,8 @@ discard block |
||
135 | 135 | |
136 | 136 | # Definir la ruta y regla |
137 | 137 | $lastRoute = sizeof($this->routerCollection); |
138 | - $this->routerCollection[$index] = array_key_exists($lastRoute,$this->real_request) ? $this->real_request[$lastRoute] : null; |
|
139 | - $this->setCollectionRule($index,$rule); |
|
138 | + $this->routerCollection[$index] = array_key_exists($lastRoute, $this->real_request) ? $this->real_request[$lastRoute] : null; |
|
139 | + $this->setCollectionRule($index, $rule); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | */ |
150 | 150 | final public function getRoute(string $index) { |
151 | 151 | # Verificar existencia de ruta |
152 | - if(!array_key_exists($index,$this->routerCollection)) { |
|
152 | + if (!array_key_exists($index, $this->routerCollection)) { |
|
153 | 153 | throw new \RuntimeException('La ruta ' . $index . ' no está definida en el controlador.'); |
154 | 154 | } |
155 | 155 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | $ruta = $this->routerCollection[$index]; |
158 | 158 | |
159 | 159 | # Retornar ruta con la regla definida aplicada |
160 | - switch($this->routerCollectionRules[$index]) { |
|
160 | + switch ($this->routerCollectionRules[$index]) { |
|
161 | 161 | case 'none': |
162 | 162 | return $ruta; |
163 | 163 | break; |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | */ |
220 | 220 | final public function getId(bool $with_rules = false) { |
221 | 221 | $id = $this->routerCollection['/id']; |
222 | - if($with_rules) { |
|
222 | + if ($with_rules) { |
|
223 | 223 | return (null !== $id && is_numeric($id) && $id > 0) ? (int) $id : null; |
224 | 224 | } |
225 | 225 | |
@@ -233,10 +233,10 @@ discard block |
||
233 | 233 | */ |
234 | 234 | final public function executeController() { |
235 | 235 | # Definir controlador |
236 | - if(null != ($controller = $this->getController())) { |
|
236 | + if (null != ($controller = $this->getController())) { |
|
237 | 237 | $controller = $controller . 'Controller'; |
238 | 238 | |
239 | - if(!is_readable('app/controllers/' . $controller . '.php')) { |
|
239 | + if (!is_readable('app/controllers/' . $controller . '.php')) { |
|
240 | 240 | $controller = 'errorController'; |
241 | 241 | } |
242 | 242 |
@@ -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 |
@@ -66,41 +66,41 @@ discard block |
||
66 | 66 | try { |
67 | 67 | switch ($motor) { |
68 | 68 | case 'sqlite': |
69 | - parent::__construct('sqlite:'.$name); |
|
69 | + parent::__construct('sqlite:' . $name); |
|
70 | 70 | break; |
71 | 71 | case 'cubrid': |
72 | - parent::__construct('cubrid:host='.$config['database']['host'].';dbname='.$name.';port='.$config['database']['port'],$config['database']['user'],$config['database']['pass'],array( |
|
72 | + parent::__construct('cubrid:host=' . $config['database']['host'] . ';dbname=' . $name . ';port=' . $config['database']['port'], $config['database']['user'], $config['database']['pass'], array( |
|
73 | 73 | \PDO::ATTR_EMULATE_PREPARES => false, |
74 | 74 | \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION)); |
75 | 75 | break; |
76 | 76 | case 'firebird': |
77 | - parent::__construct('firebird:dbname='.$config['database']['host'].':'.$name,$config['database']['user'],$config['database']['pass'],array( |
|
77 | + parent::__construct('firebird:dbname=' . $config['database']['host'] . ':' . $name, $config['database']['user'], $config['database']['pass'], array( |
|
78 | 78 | \PDO::ATTR_EMULATE_PREPARES => false, |
79 | 79 | \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION)); |
80 | 80 | break; |
81 | 81 | case 'odbc'; |
82 | - parent::__construct('odbc:'.$name,$config['database']['user'],$config['database']['pass']); |
|
82 | + parent::__construct('odbc:' . $name, $config['database']['user'], $config['database']['pass']); |
|
83 | 83 | break; |
84 | 84 | case 'oracle': |
85 | 85 | parent::__construct('oci:dbname=(DESCRIPTION = |
86 | 86 | (ADDRESS_LIST = |
87 | - (ADDRESS = (PROTOCOL = '.$config['database']['protocol'].')(HOST = '.$motor.')(PORT = '.$config['database']['port'].')) |
|
87 | + (ADDRESS = (PROTOCOL = '.$config['database']['protocol'] . ')(HOST = ' . $motor . ')(PORT = ' . $config['database']['port'] . ')) |
|
88 | 88 | ) |
89 | 89 | (CONNECT_DATA = |
90 | - (SERVICE_NAME = '.$name.') |
|
90 | + (SERVICE_NAME = '.$name . ') |
|
91 | 91 | ) |
92 | - );charset=utf8',$config['database']['user'],$config['database']['pass'], |
|
92 | + );charset=utf8',$config['database']['user'], $config['database']['pass'], |
|
93 | 93 | array(\PDO::ATTR_EMULATE_PREPARES => false, |
94 | 94 | \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, |
95 | 95 | \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC)); |
96 | 96 | break; |
97 | 97 | case 'postgresql': |
98 | - parent::__construct('pgsql:host='.$config['database']['host'].';dbname='.$name.';charset=utf8',$config['database']['user'],$config['database']['pass'],array( |
|
98 | + parent::__construct('pgsql:host=' . $config['database']['host'] . ';dbname=' . $name . ';charset=utf8', $config['database']['user'], $config['database']['pass'], array( |
|
99 | 99 | \PDO::ATTR_EMULATE_PREPARES => false, |
100 | 100 | \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION)); |
101 | 101 | break; |
102 | 102 | case 'mysql': |
103 | - parent::__construct('mysql:host='.$config['database']['host'].';dbname='.$name,$config['database']['user'],$config['database']['pass'],array( |
|
103 | + parent::__construct('mysql:host=' . $config['database']['host'] . ';dbname=' . $name, $config['database']['user'], $config['database']['pass'], array( |
|
104 | 104 | \PDO::ATTR_EMULATE_PREPARES => false, |
105 | 105 | \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, |
106 | 106 | \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | case 'mssql': |
109 | 109 | # Añadido por marc2684 |
110 | 110 | # DOC: https://github.com/prinick96/Ocrend-Framework/issues/7 |
111 | - parent::__construct('sqlsrv:Server='.$config['database']['host'].';Database='.$name.';ConnectionPooling=0', |
|
111 | + parent::__construct('sqlsrv:Server=' . $config['database']['host'] . ';Database=' . $name . ';ConnectionPooling=0', |
|
112 | 112 | $config['database']['user'], |
113 | 113 | $config['database']['pass'], |
114 | 114 | array(\PDO::ATTR_EMULATE_PREPARES => false, |
@@ -118,10 +118,10 @@ discard block |
||
118 | 118 | )); |
119 | 119 | break; |
120 | 120 | default: |
121 | - throw new \RuntimeException('Motor '. $motor .' de conexión no identificado.'); |
|
121 | + throw new \RuntimeException('Motor ' . $motor . ' de conexión no identificado.'); |
|
122 | 122 | break; |
123 | 123 | } |
124 | - } catch(\PDOException $e) { |
|
124 | + } catch (\PDOException $e) { |
|
125 | 125 | throw new \RuntimeException('Problema al conectar con la base de datos: ' . $e->getMessage()); |
126 | 126 | } |
127 | 127 | } |
@@ -156,18 +156,18 @@ discard block |
||
156 | 156 | * @return int/float/string sanados según sea el tipo de dato pasado por parámetro |
157 | 157 | */ |
158 | 158 | final public function scape($e) { |
159 | - if(null === $e) { |
|
159 | + if (null === $e) { |
|
160 | 160 | return ''; |
161 | 161 | } |
162 | 162 | |
163 | - if(is_numeric($e) and $e <= 2147483647) { |
|
164 | - if(explode('.',$e)[0] != $e) { |
|
163 | + if (is_numeric($e) and $e <= 2147483647) { |
|
164 | + if (explode('.', $e)[0] != $e) { |
|
165 | 165 | return (float) $e; |
166 | 166 | } |
167 | 167 | return (int) $e; |
168 | 168 | } |
169 | 169 | |
170 | - return (string) trim(str_replace(['\\',"\x00",'\n','\r',"'",'"',"\x1a"],['\\\\','\\0','\\n','\\r',"\'",'\"','\\Z'],$e)); |
|
170 | + return (string) trim(str_replace(['\\', "\x00", '\n', '\r', "'", '"', "\x1a"], ['\\\\', '\\0', '\\n', '\\r', "\'", '\"', '\\Z'], $e)); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | */ |
196 | 196 | final public function insert(string $table, array $e) : \PDOStatement { |
197 | 197 | if (sizeof($e) == 0) { |
198 | - throw new \RuntimeException('El arreglo pasado por $this->db->insert(\''.$table.'\',...) está vacío.'); |
|
198 | + throw new \RuntimeException('El arreglo pasado por $this->db->insert(\'' . $table . '\',...) está vacío.'); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | $query = "INSERT INTO $table ("; |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | */ |
226 | 226 | final public function update(string $table, array $e, string $where, string $limit = '') : \PDOStatement { |
227 | 227 | if (sizeof($e) == 0) { |
228 | - throw new \RuntimeException('El arreglo pasado por $this->db->update(\''.$table.'\'...) está vacío.'); |
|
228 | + throw new \RuntimeException('El arreglo pasado por $this->db->update(\'' . $table . '\'...) está vacío.'); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | $query = "UPDATE $table SET "; |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | $result = $sql->fetchAll(); |
263 | 263 | $sql->closeCursor(); |
264 | 264 | |
265 | - if(sizeof($result) > 0) { |
|
265 | + if (sizeof($result) > 0) { |
|
266 | 266 | return $result; |
267 | 267 | } |
268 | 268 |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | /** |
47 | 47 | * Lectura y escritura de caché para Twig |
48 | 48 | */ |
49 | -if(!is_writable(API_INTERFACE . 'app/templates/.cache/') || !is_readable(API_INTERFACE . 'app/templates/.cache/')) { |
|
49 | +if (!is_writable(API_INTERFACE . 'app/templates/.cache/') || !is_readable(API_INTERFACE . 'app/templates/.cache/')) { |
|
50 | 50 | throw new \RuntimeException('Debe conceder permisos de escritura y lectura a la ruta ' . API_INTERFACE . 'app/templates/.cache/ ó crearla si no existe.'); |
51 | 51 | } |
52 | 52 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | /** |
83 | 83 | * Estatus del DEBUG |
84 | 84 | */ |
85 | -if($config['framework']['debug']) { |
|
85 | +if ($config['framework']['debug']) { |
|
86 | 86 | Debug::enable(); |
87 | 87 | } |
88 | 88 |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | $this->template->addGlobal('is_logged', $this->is_logged); |
115 | 115 | |
116 | 116 | # Datos del usuario actual |
117 | - if($this->is_logged) { |
|
117 | + if ($this->is_logged) { |
|
118 | 118 | $this->user = (new Model\Users)->getOwnerUser(); |
119 | 119 | $this->template->addGlobal('owner_user', $this->user); |
120 | 120 | } |
@@ -145,17 +145,17 @@ discard block |
||
145 | 145 | $this->controllerConfig['users_not_logged'] = false; |
146 | 146 | |
147 | 147 | # Establecer las configuraciones pasadas |
148 | - if(null != $config) { |
|
148 | + if (null != $config) { |
|
149 | 149 | # Configura el autoreload del caché de twig |
150 | - if(array_key_exists('twig_cache_reload',$config)) { |
|
150 | + if (array_key_exists('twig_cache_reload', $config)) { |
|
151 | 151 | $this->controllerConfig['twig_cache_reload'] = (bool) $config['twig_cache_reload']; |
152 | 152 | } |
153 | 153 | # Configura el controlador para solo ser visto por usuarios logeados |
154 | - if(array_key_exists('users_logged',$config)) { |
|
154 | + if (array_key_exists('users_logged', $config)) { |
|
155 | 155 | $this->controllerConfig['users_logged'] = (bool) $config['users_logged']; |
156 | 156 | } |
157 | 157 | # Configura el controlador para solo ser visto por usuario no logeados |
158 | - if(array_key_exists('users_not_logged',$config)) { |
|
158 | + if (array_key_exists('users_not_logged', $config)) { |
|
159 | 159 | $this->controllerConfig['users_not_logged'] = (bool) $config['users_not_logged']; |
160 | 160 | } |
161 | 161 | } |
@@ -168,12 +168,12 @@ discard block |
||
168 | 168 | */ |
169 | 169 | private function knowVisitorPermissions() { |
170 | 170 | # Sólamente usuarios logeados |
171 | - if($this->controllerConfig['users_logged'] && !$this->is_logged) { |
|
171 | + if ($this->controllerConfig['users_logged'] && !$this->is_logged) { |
|
172 | 172 | $this->functions->redir(); |
173 | 173 | } |
174 | 174 | |
175 | 175 | # Sólamente usuarios no logeados |
176 | - if($this->controllerConfig['users_not_logged'] && $this->is_logged) { |
|
176 | + if ($this->controllerConfig['users_not_logged'] && $this->is_logged) { |
|
177 | 177 | $this->functions->redir(); |
178 | 178 | } |
179 | 179 | } |
@@ -43,32 +43,32 @@ 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 | |
55 | 55 | # Desnivel |
56 | - if(is_array($contenido)) { |
|
57 | - throw new \RuntimeException('El arreglo $b en la llave '.$llave.' es un arreglo y no puede operar.'); |
|
56 | + if (is_array($contenido)) { |
|
57 | + throw new \RuntimeException('El arreglo $b en la llave ' . $llave . ' es un arreglo y no puede operar.'); |
|
58 | 58 | break; |
59 | 59 | } |
60 | 60 | |
61 | 61 | # Existencia de la llave |
62 | - if(array_key_exists($llave,$a)) { |
|
62 | + if (array_key_exists($llave, $a)) { |
|
63 | 63 | # Excepciones de uso |
64 | - if(is_array($a[$llave])) { |
|
65 | - throw new \RuntimeException('El arreglo $a en la llave '.$llave.' es un arreglo y no puede operar.'); |
|
64 | + if (is_array($a[$llave])) { |
|
65 | + throw new \RuntimeException('El arreglo $a en la llave ' . $llave . ' es un arreglo y no puede operar.'); |
|
66 | 66 | break; |
67 | - } else if(!is_numeric($a[$llave]) && null !== $a[$llave]) { |
|
68 | - throw new \RuntimeException('El arreglo $a en la llave '.$llave.' no es un número y no puede operar.'); |
|
67 | + } else if (!is_numeric($a[$llave]) && null !== $a[$llave]) { |
|
68 | + throw new \RuntimeException('El arreglo $a en la llave ' . $llave . ' no es un número y no puede operar.'); |
|
69 | 69 | break; |
70 | - } else if(!is_numeric($b[$llave]) && null !== $b[$llave]) { |
|
71 | - throw new \RuntimeException('El arreglo $b en la llave '.$llave.' no es un número y no puede operar.'); |
|
70 | + } else if (!is_numeric($b[$llave]) && null !== $b[$llave]) { |
|
71 | + throw new \RuntimeException('El arreglo $b en la llave ' . $llave . ' no es un número y no puede operar.'); |
|
72 | 72 | break; |
73 | 73 | } |
74 | 74 | |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | final public static function get_key_by_index(string $index, array $a) : int { |
95 | 95 | $i = 0; |
96 | 96 | foreach ($a as $key => $val) { |
97 | - if($key == $index) { |
|
97 | + if ($key == $index) { |
|
98 | 98 | return (int) $i; |
99 | 99 | } |
100 | 100 | $i++; |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | * @return false si no lo es, true si lo es |
128 | 128 | */ |
129 | 129 | final public static function is_assoc(array $a) : bool { |
130 | - if(sizeof($a) === 0) { |
|
130 | + if (sizeof($a) === 0) { |
|
131 | 131 | return false; |
132 | 132 | } |
133 | 133 |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | } elseif ($diff->m == 1) { |
42 | 42 | $text = '1 mes'; |
43 | 43 | } elseif ($diff->d > 7) { |
44 | - $text = ceil($diff->d / 7) . ' semanas'; |
|
44 | + $text = ceil($diff->d/7) . ' semanas'; |
|
45 | 45 | } elseif ($diff->d == 7) { |
46 | 46 | $text = '1 semana'; |
47 | 47 | } elseif ($diff->d > 1) { |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @return string Hash, con la forma $2a$10$87b2b603324793cc37f8dOPFTnHRY0lviq5filK5cN4aMCQDJcC9G |
87 | 87 | */ |
88 | 88 | final public static function hash(string $p) : string { |
89 | - return crypt($p, '$2a$10$' . substr(sha1(mt_rand()),0,22)); |
|
89 | + return crypt($p, '$2a$10$' . substr(sha1(mt_rand()), 0, 22)); |
|
90 | 90 | } |
91 | 91 | //------------------------------------------------ |
92 | 92 | /** |
@@ -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 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 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 | /** |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * |
114 | 114 | */ |
115 | 115 | final public static function calculate_age(string $cumple) : int { |
116 | - $age = explode('.', (string) (self::date_difference($cumple,date('d-m-Y',time())) / 365)); |
|
116 | + $age = explode('.', (string) (self::date_difference($cumple, date('d-m-Y', time()))/365)); |
|
117 | 117 | return (int) $age[0]; |
118 | 118 | } |
119 | 119 | //------------------------------------------------ |
@@ -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, date('m',time()), date('Y',time())); |
|
127 | + return cal_days_in_month(CAL_GREGORIAN, date('m', time()), date('Y', time())); |
|
128 | 128 | } |
129 | 129 | //------------------------------------------------ |
130 | 130 | /** |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | * @return string del texto sin espacios |
147 | 147 | */ |
148 | 148 | final public static function remove_spaces(string $s) : string { |
149 | - return trim(str_replace(' ','',$s)); |
|
149 | + return trim(str_replace(' ', '', $s)); |
|
150 | 150 | } |
151 | 151 | //------------------------------------------------ |
152 | 152 | /** |
@@ -191,9 +191,9 @@ discard block |
||
191 | 191 | */ |
192 | 192 | final public static function url_amigable(string $url) : string { |
193 | 193 | $url = strtolower($url); |
194 | - $url = str_replace (['á', 'é', 'í', 'ó', 'ú', 'ñ'],['a', 'e', 'i', 'o', 'u', 'n'], $url); |
|
195 | - $url = str_replace([' ', '&', '\r\n', '\n', '+', '%'],'-',$url); |
|
196 | - return preg_replace (['/[^a-z0-9\-<>]/', '/[\-]+/', '/<[^>]*>/'],['', '-', ''], $url); |
|
194 | + $url = str_replace(['á', 'é', 'í', 'ó', 'ú', 'ñ'], ['a', 'e', 'i', 'o', 'u', 'n'], $url); |
|
195 | + $url = str_replace([' ', '&', '\r\n', '\n', '+', '%'], '-', $url); |
|
196 | + return preg_replace(['/[^a-z0-9\-<>]/', '/[\-]+/', '/<[^>]*>/'], ['', '-', ''], $url); |
|
197 | 197 | } |
198 | 198 | //------------------------------------------------ |
199 | 199 | /** |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | '<span style="font-size: $1px">$2</span>', |
247 | 247 | '<span style="font-family: $1">$2</span>' |
248 | 248 | ); |
249 | - return nl2br(preg_replace($BBcode,$HTML,$string)); |
|
249 | + return nl2br(preg_replace($BBcode, $HTML, $string)); |
|
250 | 250 | } |
251 | 251 | //------------------------------------------------ |
252 | 252 | /** |
@@ -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 str_word_count($s,0); |
|
297 | + return str_word_count($s, 0); |
|
298 | 298 | } |
299 | 299 | //------------------------------------------------ |
300 | 300 | /** |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | $mail->CharSet = "UTF-8"; |
36 | 36 | $mail->Encoding = "quoted-printable"; |
37 | 37 | |
38 | - if($is_smtp) { |
|
38 | + if ($is_smtp) { |
|
39 | 39 | $mail->isSMTP(); |
40 | 40 | $mail->SMTPAuth = true; |
41 | 41 | $mail->Host = $config['phpmailer']['host']; |
@@ -88,13 +88,13 @@ discard block |
||
88 | 88 | $mail->Subject = $titulo; |
89 | 89 | $mail->Body = $HTML; |
90 | 90 | |
91 | - if(sizeof($adj)) { |
|
91 | + if (sizeof($adj)) { |
|
92 | 92 | foreach ($adj as $ruta) { |
93 | 93 | $mail->AddAttachment($ruta); |
94 | 94 | } |
95 | 95 | } |
96 | 96 | |
97 | - if(!$mail->send()) { |
|
97 | + if (!$mail->send()) { |
|
98 | 98 | return $mail->ErrorInfo; |
99 | 99 | } |
100 | 100 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | </head> |
119 | 119 | <body style="font-family: Verdana;"> |
120 | 120 | <section> |
121 | - '.$content.' |
|
121 | + '.$content . ' |
|
122 | 122 | </section> |
123 | 123 | </body> |
124 | 124 | </html>'; |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @return 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 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * @return bool true si borró el fichero, false si no (porque no existía) |
63 | 63 | */ |
64 | 64 | final public static function delete_file(string $route) : bool { |
65 | - if(file_exists($route)) { |
|
65 | + if (file_exists($route)) { |
|
66 | 66 | unlink($route); |
67 | 67 | |
68 | 68 | return true; |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @return true si es una imagen, false si no lo es |
95 | 95 | */ |
96 | 96 | final public static function is_image(string $file_name) : bool { |
97 | - return (bool) in_array(self::get_file_ext($file_name),['jpg','png','jpeg','gif','JPG','PNG','JPEG','GIF']); |
|
97 | + return (bool) in_array(self::get_file_ext($file_name), ['jpg', 'png', 'jpeg', 'gif', 'JPG', 'PNG', 'JPEG', 'GIF']); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | //------------------------------------------------ |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | */ |
136 | 136 | final public static function get_files_in_dir(string $dir, string $types = '') : array { |
137 | 137 | $array = array(); |
138 | - if(is_dir($dir)) { |
|
138 | + if (is_dir($dir)) { |
|
139 | 139 | foreach (glob($dir . '*' . $types) as $file) { |
140 | 140 | $array[] = $file; |
141 | 141 | } |
@@ -154,11 +154,11 @@ discard block |
||
154 | 154 | * @return 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 = 0777) : 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 | //------------------------------------------------ |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | final public static function rm_dir(string $dir) { |
176 | 176 | |
177 | 177 | # Evitar una desgracia |
178 | - if(in_array($dir,[ |
|
178 | + if (in_array($dir, [ |
|
179 | 179 | 'Ocrend/', |
180 | 180 | 'Ocrend/Kernel/', |
181 | 181 | 'Ocrend/vendor/', |
@@ -188,10 +188,10 @@ discard block |
||
188 | 188 | throw new \RuntimeException('No puede eliminar la ruta ' . $dir . ' ya que es crítica.'); |
189 | 189 | } |
190 | 190 | |
191 | - foreach(glob($dir . "/*") as $archivos_carpeta) { |
|
192 | - if (is_dir($archivos_carpeta)) { |
|
191 | + foreach (glob($dir . "/*") as $archivos_carpeta) { |
|
192 | + if (is_dir($archivos_carpeta)) { |
|
193 | 193 | self::rm_dir($archivos_carpeta); |
194 | - } else { |
|
194 | + } else { |
|
195 | 195 | unlink($archivos_carpeta); |
196 | 196 | } |
197 | 197 | } |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | * @return int cantidad de imágenes |
211 | 211 | */ |
212 | 212 | final public static function images_in_dir(string $dir) : int { |
213 | - return sizeof(glob($dir . '{*.jpg,*.gif,*.png,*.gif,*.jpeg,*.JPG,*.GIF,*.PNG,*.JPEG}',GLOB_BRACE)); |
|
213 | + return sizeof(glob($dir . '{*.jpg,*.gif,*.png,*.gif,*.jpeg,*.JPG,*.GIF,*.PNG,*.JPEG}', GLOB_BRACE)); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | //------------------------------------------------ |
@@ -230,17 +230,17 @@ discard block |
||
230 | 230 | |
231 | 231 | self::create_dir($new_dir); |
232 | 232 | |
233 | - foreach(glob($new_dir . ($only_images ? '{*.jpg,*.gif,*.png,*.gif,*.jpeg,*.JPG,*.GIF,*.PNG,*.JPEG}' : '*'),GLOB_BRACE) as $file) { |
|
234 | - $name = explode('/',$file); |
|
233 | + foreach (glob($new_dir . ($only_images ? '{*.jpg,*.gif,*.png,*.gif,*.jpeg,*.JPG,*.GIF,*.PNG,*.JPEG}' : '*'), GLOB_BRACE) as $file) { |
|
234 | + $name = explode('/', $file); |
|
235 | 235 | $name = end($file); |
236 | 236 | |
237 | - if(file_exists($new_dir . $name)) { |
|
237 | + if (file_exists($new_dir . $name)) { |
|
238 | 238 | unlink($new_dir . $name); |
239 | 239 | } |
240 | 240 | |
241 | - copy($file,$new_dir . $name); |
|
241 | + copy($file, $new_dir . $name); |
|
242 | 242 | |
243 | - if($delete_old) { |
|
243 | + if ($delete_old) { |
|
244 | 244 | unlink($file); |
245 | 245 | } |
246 | 246 | } |