|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* sysPass |
|
4
|
|
|
* |
|
5
|
|
|
* @author nuxsmin |
|
6
|
|
|
* @link https://syspass.org |
|
7
|
|
|
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org |
|
8
|
|
|
* |
|
9
|
|
|
* This file is part of sysPass. |
|
10
|
|
|
* |
|
11
|
|
|
* sysPass is free software: you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU General Public License as published by |
|
13
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
14
|
|
|
* (at your option) any later version. |
|
15
|
|
|
* |
|
16
|
|
|
* sysPass is distributed in the hope that it will be useful, |
|
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19
|
|
|
* GNU General Public License for more details. |
|
20
|
|
|
* |
|
21
|
|
|
* You should have received a copy of the GNU General Public License |
|
22
|
|
|
* along with sysPass. If not, see <http://www.gnu.org/licenses/>. |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
namespace SP\Util; |
|
26
|
|
|
|
|
27
|
|
|
defined('APP_ROOT') || die(); |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Class Filter para el filtrado de datos |
|
31
|
|
|
* |
|
32
|
|
|
* @package SP\Util |
|
33
|
|
|
*/ |
|
34
|
|
|
final class Filter |
|
35
|
|
|
{ |
|
36
|
|
|
/** |
|
37
|
|
|
* Limpiar una cadena de búsqueda de carácteres utilizados en expresiones regulares |
|
38
|
|
|
* |
|
39
|
|
|
* @param $string |
|
40
|
|
|
* |
|
41
|
|
|
* @return mixed |
|
42
|
|
|
*/ |
|
43
|
|
|
public static function safeSearchString($string) |
|
44
|
|
|
{ |
|
45
|
|
|
return str_replace(['/', '[', '\\', ']', '%', '{', '}', '*', '$'], '', (string)$string); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param $value |
|
50
|
|
|
* |
|
51
|
|
|
* @return string |
|
52
|
|
|
*/ |
|
53
|
|
|
public static function getEmail($value): string |
|
54
|
|
|
{ |
|
55
|
|
|
return filter_var(trim($value), FILTER_SANITIZE_EMAIL); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param array $array |
|
60
|
|
|
* |
|
61
|
|
|
* @return array |
|
62
|
|
|
*/ |
|
63
|
|
|
public static function getArray(array $array): array |
|
64
|
|
|
{ |
|
65
|
|
|
return array_map(function ($value) { |
|
66
|
|
|
if ($value !== null) { |
|
67
|
|
|
if (is_numeric($value)) { |
|
68
|
|
|
return Filter::getInt($value); |
|
69
|
|
|
} else { |
|
70
|
|
|
return Filter::getString($value); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return null; |
|
75
|
|
|
}, $array); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param $value |
|
80
|
|
|
* |
|
81
|
|
|
* @return int |
|
82
|
|
|
*/ |
|
83
|
|
|
public static function getInt($value): int |
|
84
|
|
|
{ |
|
85
|
|
|
return (int)filter_var($value, FILTER_SANITIZE_NUMBER_INT); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param $value |
|
90
|
|
|
* |
|
91
|
|
|
* @return string |
|
92
|
|
|
*/ |
|
93
|
|
|
public static function getString($value): string |
|
94
|
|
|
{ |
|
95
|
|
|
return filter_var(trim($value), FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @param $value |
|
100
|
|
|
* |
|
101
|
|
|
* @return string |
|
102
|
|
|
*/ |
|
103
|
|
|
public static function getRaw($value): string |
|
104
|
|
|
{ |
|
105
|
|
|
return filter_var(trim($value), FILTER_UNSAFE_RAW); |
|
106
|
|
|
} |
|
107
|
|
|
} |