1 | <?php |
||
11 | class Sanitise |
||
12 | { |
||
13 | |||
14 | private $is_valid = null; |
||
15 | private $_sanitised = null; |
||
16 | private $filters; |
||
17 | private $input; |
||
18 | private $output; |
||
19 | private $strings; |
||
20 | private $urlService; |
||
21 | |||
22 | function __construct() |
||
28 | |||
29 | /** |
||
30 | * |
||
31 | * Removes URLs from strings |
||
32 | * |
||
33 | * @param array|string $data |
||
34 | * @return array|string|string[]|null |
||
35 | */ |
||
36 | public function removeUrl($data) |
||
37 | { |
||
38 | $this->_sanitised = null; |
||
39 | |||
40 | if (is_array($data)) { |
||
41 | foreach ($data as $key => $value) { |
||
42 | $data[$key] = $this->removeUrl($value); |
||
43 | } |
||
44 | return $data; |
||
45 | } |
||
46 | |||
47 | $this->input = $data = trim($data); |
||
48 | $data = $this->urlService->remove($data); |
||
49 | $data = trim($data); |
||
50 | |||
51 | if ($this->input != $data) { |
||
52 | $this->_sanitised = true; |
||
53 | } |
||
54 | $this->is_valid = true; |
||
55 | |||
56 | $this->output = $data; |
||
57 | return $data; |
||
58 | |||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @param $data |
||
63 | * @param string $toEncoding |
||
64 | * @param string $fromEncoding |
||
65 | * @return array|false|string|string[]|null |
||
66 | */ |
||
67 | public function cleanse($data, $toEncoding = 'utf-8', $fromEncoding = 'auto') |
||
68 | { |
||
69 | |||
70 | if (is_array($data)) { |
||
71 | foreach ($data as $key => $value) { |
||
72 | $data[$key] = $this->cleanse($value, $toEncoding, $fromEncoding); |
||
73 | } |
||
74 | return $data; |
||
75 | } |
||
76 | |||
77 | $this->input = $data = trim($data); |
||
78 | $data = $this->strings->clean($data); |
||
79 | $data = mb_convert_encoding($data, $toEncoding, $fromEncoding); |
||
80 | $data = htmlspecialchars_decode($data); |
||
81 | $data = $this->strings->clean($data); |
||
82 | if ($this->input != $data) { |
||
83 | $this->_sanitised = true; |
||
84 | } |
||
85 | $this->output = $data; |
||
86 | return $data; |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * @param $string |
||
91 | * @param string $delimiter |
||
92 | * @return string |
||
93 | */ |
||
94 | public function cleanseCsv($string, $delimiter = "|") |
||
98 | |||
99 | /** |
||
100 | * @param $data |
||
101 | * @param string $type |
||
102 | * @param int $stringLength |
||
103 | * @return mixed|string |
||
104 | */ |
||
105 | 4 | public function disinfect($data, $type = 'special_chars', $stringLength = -1) |
|
167 | |||
168 | |||
169 | /** |
||
170 | * @param $str |
||
171 | * @return mixed|string |
||
172 | */ |
||
173 | public function decodeHtmlEntity($str) |
||
207 | |||
208 | |||
209 | /** |
||
210 | * @return null |
||
211 | */ |
||
212 | public function isSanitised() |
||
216 | |||
217 | /** |
||
218 | * Returns true if the data is valid |
||
219 | * @return null |
||
220 | */ |
||
221 | public function isValid() |
||
225 | |||
226 | 4 | function result() |
|
234 | |||
235 | } |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.