PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 1.21
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v1.21
2.1.0 2.0.15 2.0.12 2.0.10 2.0.4 2.0.1 2.0.0 1.95.3 1.95.2 1.95 1.91.6 trunk 1.11 1.12 1.13 1.20 1.21 1.22 1.23 1.30 1.31 1.32 1.35 1.40 1.41 All 42 releases
fluent-boards / vendor / wpfluent / framework / src / WPFluent / Support / Sanitizer.php

Sanitizer.php in FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration 1.21, at vendor/wpfluent/framework/src/WPFluent/Support/Sanitizer.php

301 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBoards\Framework\Support;
4
5 Class Sanitizer
6 {
7 public static function sanitizeEmail($arg)
8 {
9 return sanitize_email($arg);
10 }
11
12 public static function sanitizeFileName($arg)
13 {
14 return sanitize_file_name($arg);
15 }
16
17 public static function sanitizeHtmlClass($arg)
18 {
19 return sanitize_html_class($arg);
20 }
21
22 public static function sanitizeKey($arg)
23 {
24 return sanitize_key($arg);
25 }
26
27 public static function sanitizeMeta($arg)
28 {
29 return sanitize_meta($arg);
30 }
31
32 public static function sanitizeMimeType($arg)
33 {
34 return sanitize_mime_type($arg);
35 }
36
37 public static function sanitizeOption($arg)
38 {
39 return sanitize_option($arg);
40 }
41
42 public static function sanitizeSqlOrderby($arg)
43 {
44 return sanitize_sql_orderby($arg);
45 }
46
47 public static function sanitizeTextField($arg)
48 {
49 return sanitize_text_field($arg);
50 }
51
52 public static function sanitizeTitle($arg)
53 {
54 return sanitize_title($arg);
55 }
56
57 public static function sanitizeTitleForQuery($arg)
58 {
59 return sanitize_title_for_query($arg);
60 }
61
62 public static function sanitizeTitleWithDashes($arg)
63 {
64 return sanitize_title_with_dashes($arg);
65 }
66
67 public static function sanitizeUser($arg)
68 {
69 return sanitize_user($arg);
70 }
71
72 public static function wpFilterPostKses($arg)
73 {
74 return wp_filter_post_kses($arg);
75 }
76
77 public static function wpFilterNohtmlKses($arg)
78 {
79 return wp_filter_nohtml_kses($arg);
80 }
81
82 public static function escAttr($arg)
83 {
84 return esc_attr($arg);
85 }
86
87 public static function escHtml($arg)
88 {
89 return esc_html($arg);
90 }
91
92 public static function escJs($arg)
93 {
94 return esc_js($arg);
95 }
96
97 public static function escTextarea($arg)
98 {
99 return esc_textarea($arg);
100 }
101
102 public static function escUrl($arg)
103 {
104 return esc_url($arg);
105 }
106
107 public static function escUrlRaw($arg)
108 {
109 return esc_url_raw($arg);
110 }
111
112 public static function escXml($arg)
113 {
114 return esc_xml($arg);
115 }
116
117 public static function kses($arg)
118 {
119 return wp_kses($arg);
120 }
121
122 public static function ksesPost($arg)
123 {
124 return wp_kses_post($arg);
125 }
126
127 public static function ksesData($arg)
128 {
129 return wp_kses_data($arg);
130 }
131
132 public static function escHtml__($arg)
133 {
134 return esc_html__($arg);
135 }
136
137 public static function escAttr__($arg)
138 {
139 return esc_attr__($arg);
140 }
141
142 public static function escHtmlE($arg)
143 {
144 return esc_html_e($arg);
145 }
146
147 public static function escAttrE($arg)
148 {
149 return esc_attr_e($arg);
150 }
151
152 public static function escHtmlX($arg)
153 {
154 return esc_html_x($arg);
155 }
156
157 public static function escAttrX($arg)
158 {
159 return esc_attr_x($arg);
160 }
161
162 public static function sanitize(array $data = [], array $rules = [])
163 {
164 $array = $result = [];
165
166 foreach ($rules as $key => $callbacks) {
167
168 if (!$callbacks) continue;
169
170 $callbacks = is_array($callbacks) ? $callbacks : [$callbacks];
171
172 $array[$key] = $callbacks;
173
174 if (str_contains($key, '*')) {
175 $array = static::substituteWildcardKeys($array, $key, $data);
176 }
177
178 foreach ($array as $k => $callbacks) {
179
180 $callbacks = static::mayBeFixCallbacks($callbacks);
181
182 if (($value = Arr::get($data, $k)) !== null) {
183 $callbacks = is_callable($callbacks) ? [$callbacks] : $callbacks;
184
185 while ($callback = static::getCallback(array_shift($callbacks))) {
186 if (is_array($value)) {
187 $value = array_map($callback, $value);
188 } else {
189 $value = $callback($value);
190 }
191 }
192
193 Arr::set($result, $k, $value);
194 }
195 }
196 }
197
198 return $result;
199 }
200
201 /**
202 * Normalize wildcard rules to dotted rule, i.e:
203 * key_one.*.key_two.*.key_three becomes:
204 * key_one.0.key_two.0.key_three.0
205 * key_one.0.key_two.1.key_three.0
206 * depending on the data array.
207 *
208 * @param array $array
209 * @param string $field
210 * @return array
211 */
212 protected static function substituteWildcardKeys($array, $field, $data)
213 {
214 $callback = $array[$field];
215
216 $keys = array_map(function($v) {
217 return trim($v, '.');
218 }, explode('*', $field));
219
220 $key = array_shift($keys);
221
222 if ($key && ($val = Arr::get($data, $key)) && is_array($val)) {
223
224 $dotted = array_keys(Arr::dot($val, $key . '.'));
225
226 foreach ($dotted as $dottedField) {
227
228 $r = preg_replace('/[0-9]+/', '*', $dottedField);
229
230 if (preg_match("/{$field}/", $r)) {
231
232 $array[$dottedField] = $callback;
233
234 if (isset($array[$field])) {
235 unset($array[$field]);
236 }
237 }
238 }
239 }
240
241 return $array;
242 }
243
244 /**
245 * Check and fix if callbacks are given
246 * as: callback1|callback2\callback3.
247 *
248 * @param array|string $callbacks
249 * @return array
250 */
251 protected static function mayBeFixCallbacks($callbacks)
252 {
253 $nonFunctionCallables = $functionCallables = [];
254
255 foreach ($callbacks as $cb) {
256 if (is_callable($cb)) {
257 $nonFunctionCallables[] = $cb;
258 } elseif (is_string($cb)) {
259 $functionCallables[] = explode('|', $cb);
260 } elseif (is_array($cb) && !str_contains($cb[0], '::')) {
261 $functionCallables[] = $cb[0];
262 } elseif (is_array($cb) && str_contains($cb[0], '::')) {
263 $nonFunctionCallables[] = explode('::', $cb[0]);
264 }
265 }
266
267 $callbacks = array_merge(
268 Arr::flatten($functionCallables), $nonFunctionCallables
269 );
270
271 return $callbacks;
272 }
273
274 protected static function getCallback($callback)
275 {
276 if ($callback) {
277
278 if ($cb = static::methodExists($callback)) {
279 $callback = $cb;
280 }
281 }
282
283 return $callback;
284 }
285
286 protected static function methodExists($method)
287 {
288 $suffix = '';
289
290 if (Str::endsWith($method, '__')) {
291 $suffix = '__';
292 }
293
294 $method = Str::camel($method) . $suffix;
295
296 if (method_exists(static::class, $method)) {
297 return [static::class, $method];
298 }
299 }
300 }
301