author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 17:39:30 +0200 | |
changeset 7 | cf61fcea0001 |
parent 5 | 5e2f62d02dcd |
child 9 | 177826044cd9 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* kses 0.2.2 - HTML/XHTML filter that only allows some elements and attributes |
|
4 |
* Copyright (C) 2002, 2003, 2005 Ulf Harnhammar |
|
5 |
* |
|
6 |
* This program is free software and open source software; you can redistribute |
|
7 |
* it and/or modify it under the terms of the GNU General Public License as |
|
8 |
* published by the Free Software Foundation; either version 2 of the License, |
|
9 |
* or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|
14 |
* more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License along |
|
17 |
* with this program; if not, write to the Free Software Foundation, Inc., |
|
18 |
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
|
19 |
* http://www.gnu.org/licenses/gpl.html |
|
20 |
* |
|
21 |
* [kses strips evil scripts!] |
|
22 |
* |
|
23 |
* Added wp_ prefix to avoid conflicts with existing kses users |
|
24 |
* |
|
25 |
* @version 0.2.2 |
|
26 |
* @copyright (C) 2002, 2003, 2005 |
|
27 |
* @author Ulf Harnhammar <http://advogato.org/person/metaur/> |
|
28 |
* |
|
29 |
* @package External |
|
30 |
* @subpackage KSES |
|
31 |
* |
|
32 |
*/ |
|
33 |
||
34 |
/** |
|
35 |
* You can override this in a plugin. |
|
36 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
* The {@see 'wp_kses_allowed_html'} filter is more powerful and supplies context. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
38 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
* `CUSTOM_TAGS` is not recommended and should be considered deprecated. |
0 | 40 |
* |
41 |
* @see wp_kses_allowed_html() |
|
42 |
* |
|
43 |
* @since 1.2.0 |
|
44 |
*/ |
|
45 |
if ( ! defined( 'CUSTOM_TAGS' ) ) |
|
46 |
define( 'CUSTOM_TAGS', false ); |
|
47 |
||
5 | 48 |
// Ensure that these variables are added to the global namespace |
49 |
// (e.g. if using namespaces / autoload in the current PHP environment). |
|
50 |
global $allowedposttags, $allowedtags, $allowedentitynames; |
|
51 |
||
0 | 52 |
if ( ! CUSTOM_TAGS ) { |
53 |
/** |
|
54 |
* Kses global for default allowable HTML tags. |
|
55 |
* |
|
56 |
* Can be override by using CUSTOM_TAGS constant. |
|
57 |
* |
|
58 |
* @global array $allowedposttags |
|
59 |
* @since 2.0.0 |
|
60 |
*/ |
|
61 |
$allowedposttags = array( |
|
62 |
'address' => array(), |
|
63 |
'a' => array( |
|
64 |
'href' => true, |
|
65 |
'rel' => true, |
|
66 |
'rev' => true, |
|
67 |
'name' => true, |
|
68 |
'target' => true, |
|
69 |
), |
|
70 |
'abbr' => array(), |
|
71 |
'acronym' => array(), |
|
72 |
'area' => array( |
|
73 |
'alt' => true, |
|
74 |
'coords' => true, |
|
75 |
'href' => true, |
|
76 |
'nohref' => true, |
|
77 |
'shape' => true, |
|
78 |
'target' => true, |
|
79 |
), |
|
80 |
'article' => array( |
|
81 |
'align' => true, |
|
82 |
'dir' => true, |
|
83 |
'lang' => true, |
|
84 |
'xml:lang' => true, |
|
85 |
), |
|
86 |
'aside' => array( |
|
87 |
'align' => true, |
|
88 |
'dir' => true, |
|
89 |
'lang' => true, |
|
90 |
'xml:lang' => true, |
|
91 |
), |
|
5 | 92 |
'audio' => array( |
93 |
'autoplay' => true, |
|
94 |
'controls' => true, |
|
95 |
'loop' => true, |
|
96 |
'muted' => true, |
|
97 |
'preload' => true, |
|
98 |
'src' => true, |
|
99 |
), |
|
0 | 100 |
'b' => array(), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
101 |
'bdo' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
102 |
'dir' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
103 |
), |
0 | 104 |
'big' => array(), |
105 |
'blockquote' => array( |
|
106 |
'cite' => true, |
|
107 |
'lang' => true, |
|
108 |
'xml:lang' => true, |
|
109 |
), |
|
110 |
'br' => array(), |
|
111 |
'button' => array( |
|
112 |
'disabled' => true, |
|
113 |
'name' => true, |
|
114 |
'type' => true, |
|
115 |
'value' => true, |
|
116 |
), |
|
117 |
'caption' => array( |
|
118 |
'align' => true, |
|
119 |
), |
|
120 |
'cite' => array( |
|
121 |
'dir' => true, |
|
122 |
'lang' => true, |
|
123 |
), |
|
124 |
'code' => array(), |
|
125 |
'col' => array( |
|
126 |
'align' => true, |
|
127 |
'char' => true, |
|
128 |
'charoff' => true, |
|
129 |
'span' => true, |
|
130 |
'dir' => true, |
|
131 |
'valign' => true, |
|
132 |
'width' => true, |
|
133 |
), |
|
5 | 134 |
'colgroup' => array( |
135 |
'align' => true, |
|
136 |
'char' => true, |
|
137 |
'charoff' => true, |
|
138 |
'span' => true, |
|
139 |
'valign' => true, |
|
140 |
'width' => true, |
|
141 |
), |
|
0 | 142 |
'del' => array( |
143 |
'datetime' => true, |
|
144 |
), |
|
145 |
'dd' => array(), |
|
5 | 146 |
'dfn' => array(), |
0 | 147 |
'details' => array( |
148 |
'align' => true, |
|
149 |
'dir' => true, |
|
150 |
'lang' => true, |
|
151 |
'open' => true, |
|
152 |
'xml:lang' => true, |
|
153 |
), |
|
154 |
'div' => array( |
|
155 |
'align' => true, |
|
156 |
'dir' => true, |
|
157 |
'lang' => true, |
|
158 |
'xml:lang' => true, |
|
159 |
), |
|
160 |
'dl' => array(), |
|
161 |
'dt' => array(), |
|
162 |
'em' => array(), |
|
163 |
'fieldset' => array(), |
|
164 |
'figure' => array( |
|
165 |
'align' => true, |
|
166 |
'dir' => true, |
|
167 |
'lang' => true, |
|
168 |
'xml:lang' => true, |
|
169 |
), |
|
170 |
'figcaption' => array( |
|
171 |
'align' => true, |
|
172 |
'dir' => true, |
|
173 |
'lang' => true, |
|
174 |
'xml:lang' => true, |
|
175 |
), |
|
176 |
'font' => array( |
|
177 |
'color' => true, |
|
178 |
'face' => true, |
|
179 |
'size' => true, |
|
180 |
), |
|
181 |
'footer' => array( |
|
182 |
'align' => true, |
|
183 |
'dir' => true, |
|
184 |
'lang' => true, |
|
185 |
'xml:lang' => true, |
|
186 |
), |
|
187 |
'form' => array( |
|
188 |
'action' => true, |
|
189 |
'accept' => true, |
|
190 |
'accept-charset' => true, |
|
191 |
'enctype' => true, |
|
192 |
'method' => true, |
|
193 |
'name' => true, |
|
194 |
'target' => true, |
|
195 |
), |
|
196 |
'h1' => array( |
|
197 |
'align' => true, |
|
198 |
), |
|
199 |
'h2' => array( |
|
200 |
'align' => true, |
|
201 |
), |
|
202 |
'h3' => array( |
|
203 |
'align' => true, |
|
204 |
), |
|
205 |
'h4' => array( |
|
206 |
'align' => true, |
|
207 |
), |
|
208 |
'h5' => array( |
|
209 |
'align' => true, |
|
210 |
), |
|
211 |
'h6' => array( |
|
212 |
'align' => true, |
|
213 |
), |
|
214 |
'header' => array( |
|
215 |
'align' => true, |
|
216 |
'dir' => true, |
|
217 |
'lang' => true, |
|
218 |
'xml:lang' => true, |
|
219 |
), |
|
220 |
'hgroup' => array( |
|
221 |
'align' => true, |
|
222 |
'dir' => true, |
|
223 |
'lang' => true, |
|
224 |
'xml:lang' => true, |
|
225 |
), |
|
226 |
'hr' => array( |
|
227 |
'align' => true, |
|
228 |
'noshade' => true, |
|
229 |
'size' => true, |
|
230 |
'width' => true, |
|
231 |
), |
|
232 |
'i' => array(), |
|
233 |
'img' => array( |
|
234 |
'alt' => true, |
|
235 |
'align' => true, |
|
236 |
'border' => true, |
|
237 |
'height' => true, |
|
238 |
'hspace' => true, |
|
239 |
'longdesc' => true, |
|
240 |
'vspace' => true, |
|
241 |
'src' => true, |
|
242 |
'usemap' => true, |
|
243 |
'width' => true, |
|
244 |
), |
|
245 |
'ins' => array( |
|
246 |
'datetime' => true, |
|
247 |
'cite' => true, |
|
248 |
), |
|
249 |
'kbd' => array(), |
|
250 |
'label' => array( |
|
251 |
'for' => true, |
|
252 |
), |
|
253 |
'legend' => array( |
|
254 |
'align' => true, |
|
255 |
), |
|
256 |
'li' => array( |
|
257 |
'align' => true, |
|
258 |
'value' => true, |
|
259 |
), |
|
260 |
'map' => array( |
|
261 |
'name' => true, |
|
262 |
), |
|
5 | 263 |
'mark' => array(), |
0 | 264 |
'menu' => array( |
265 |
'type' => true, |
|
266 |
), |
|
267 |
'nav' => array( |
|
268 |
'align' => true, |
|
269 |
'dir' => true, |
|
270 |
'lang' => true, |
|
271 |
'xml:lang' => true, |
|
272 |
), |
|
273 |
'p' => array( |
|
274 |
'align' => true, |
|
275 |
'dir' => true, |
|
276 |
'lang' => true, |
|
277 |
'xml:lang' => true, |
|
278 |
), |
|
279 |
'pre' => array( |
|
280 |
'width' => true, |
|
281 |
), |
|
282 |
'q' => array( |
|
283 |
'cite' => true, |
|
284 |
), |
|
285 |
's' => array(), |
|
5 | 286 |
'samp' => array(), |
0 | 287 |
'span' => array( |
288 |
'dir' => true, |
|
289 |
'align' => true, |
|
290 |
'lang' => true, |
|
291 |
'xml:lang' => true, |
|
292 |
), |
|
293 |
'section' => array( |
|
294 |
'align' => true, |
|
295 |
'dir' => true, |
|
296 |
'lang' => true, |
|
297 |
'xml:lang' => true, |
|
298 |
), |
|
299 |
'small' => array(), |
|
300 |
'strike' => array(), |
|
301 |
'strong' => array(), |
|
302 |
'sub' => array(), |
|
303 |
'summary' => array( |
|
304 |
'align' => true, |
|
305 |
'dir' => true, |
|
306 |
'lang' => true, |
|
307 |
'xml:lang' => true, |
|
308 |
), |
|
309 |
'sup' => array(), |
|
310 |
'table' => array( |
|
311 |
'align' => true, |
|
312 |
'bgcolor' => true, |
|
313 |
'border' => true, |
|
314 |
'cellpadding' => true, |
|
315 |
'cellspacing' => true, |
|
316 |
'dir' => true, |
|
317 |
'rules' => true, |
|
318 |
'summary' => true, |
|
319 |
'width' => true, |
|
320 |
), |
|
321 |
'tbody' => array( |
|
322 |
'align' => true, |
|
323 |
'char' => true, |
|
324 |
'charoff' => true, |
|
325 |
'valign' => true, |
|
326 |
), |
|
327 |
'td' => array( |
|
328 |
'abbr' => true, |
|
329 |
'align' => true, |
|
330 |
'axis' => true, |
|
331 |
'bgcolor' => true, |
|
332 |
'char' => true, |
|
333 |
'charoff' => true, |
|
334 |
'colspan' => true, |
|
335 |
'dir' => true, |
|
336 |
'headers' => true, |
|
337 |
'height' => true, |
|
338 |
'nowrap' => true, |
|
339 |
'rowspan' => true, |
|
340 |
'scope' => true, |
|
341 |
'valign' => true, |
|
342 |
'width' => true, |
|
343 |
), |
|
344 |
'textarea' => array( |
|
345 |
'cols' => true, |
|
346 |
'rows' => true, |
|
347 |
'disabled' => true, |
|
348 |
'name' => true, |
|
349 |
'readonly' => true, |
|
350 |
), |
|
351 |
'tfoot' => array( |
|
352 |
'align' => true, |
|
353 |
'char' => true, |
|
354 |
'charoff' => true, |
|
355 |
'valign' => true, |
|
356 |
), |
|
357 |
'th' => array( |
|
358 |
'abbr' => true, |
|
359 |
'align' => true, |
|
360 |
'axis' => true, |
|
361 |
'bgcolor' => true, |
|
362 |
'char' => true, |
|
363 |
'charoff' => true, |
|
364 |
'colspan' => true, |
|
365 |
'headers' => true, |
|
366 |
'height' => true, |
|
367 |
'nowrap' => true, |
|
368 |
'rowspan' => true, |
|
369 |
'scope' => true, |
|
370 |
'valign' => true, |
|
371 |
'width' => true, |
|
372 |
), |
|
373 |
'thead' => array( |
|
374 |
'align' => true, |
|
375 |
'char' => true, |
|
376 |
'charoff' => true, |
|
377 |
'valign' => true, |
|
378 |
), |
|
379 |
'title' => array(), |
|
380 |
'tr' => array( |
|
381 |
'align' => true, |
|
382 |
'bgcolor' => true, |
|
383 |
'char' => true, |
|
384 |
'charoff' => true, |
|
385 |
'valign' => true, |
|
386 |
), |
|
5 | 387 |
'track' => array( |
388 |
'default' => true, |
|
389 |
'kind' => true, |
|
390 |
'label' => true, |
|
391 |
'src' => true, |
|
392 |
'srclang' => true, |
|
393 |
), |
|
0 | 394 |
'tt' => array(), |
395 |
'u' => array(), |
|
396 |
'ul' => array( |
|
397 |
'type' => true, |
|
398 |
), |
|
399 |
'ol' => array( |
|
400 |
'start' => true, |
|
401 |
'type' => true, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
402 |
'reversed' => true, |
0 | 403 |
), |
404 |
'var' => array(), |
|
5 | 405 |
'video' => array( |
406 |
'autoplay' => true, |
|
407 |
'controls' => true, |
|
408 |
'height' => true, |
|
409 |
'loop' => true, |
|
410 |
'muted' => true, |
|
411 |
'poster' => true, |
|
412 |
'preload' => true, |
|
413 |
'src' => true, |
|
414 |
'width' => true, |
|
415 |
), |
|
0 | 416 |
); |
417 |
||
418 |
/** |
|
419 |
* Kses allowed HTML elements. |
|
420 |
* |
|
421 |
* @global array $allowedtags |
|
422 |
* @since 1.0.0 |
|
423 |
*/ |
|
424 |
$allowedtags = array( |
|
425 |
'a' => array( |
|
426 |
'href' => true, |
|
427 |
'title' => true, |
|
428 |
), |
|
429 |
'abbr' => array( |
|
430 |
'title' => true, |
|
431 |
), |
|
432 |
'acronym' => array( |
|
433 |
'title' => true, |
|
434 |
), |
|
435 |
'b' => array(), |
|
436 |
'blockquote' => array( |
|
437 |
'cite' => true, |
|
438 |
), |
|
439 |
'cite' => array(), |
|
440 |
'code' => array(), |
|
441 |
'del' => array( |
|
442 |
'datetime' => true, |
|
443 |
), |
|
444 |
'em' => array(), |
|
445 |
'i' => array(), |
|
446 |
'q' => array( |
|
447 |
'cite' => true, |
|
448 |
), |
|
5 | 449 |
's' => array(), |
0 | 450 |
'strike' => array(), |
451 |
'strong' => array(), |
|
452 |
); |
|
453 |
||
454 |
$allowedentitynames = array( |
|
455 |
'nbsp', 'iexcl', 'cent', 'pound', 'curren', 'yen', |
|
456 |
'brvbar', 'sect', 'uml', 'copy', 'ordf', 'laquo', |
|
457 |
'not', 'shy', 'reg', 'macr', 'deg', 'plusmn', |
|
458 |
'acute', 'micro', 'para', 'middot', 'cedil', 'ordm', |
|
459 |
'raquo', 'iquest', 'Agrave', 'Aacute', 'Acirc', 'Atilde', |
|
460 |
'Auml', 'Aring', 'AElig', 'Ccedil', 'Egrave', 'Eacute', |
|
461 |
'Ecirc', 'Euml', 'Igrave', 'Iacute', 'Icirc', 'Iuml', |
|
462 |
'ETH', 'Ntilde', 'Ograve', 'Oacute', 'Ocirc', 'Otilde', |
|
463 |
'Ouml', 'times', 'Oslash', 'Ugrave', 'Uacute', 'Ucirc', |
|
464 |
'Uuml', 'Yacute', 'THORN', 'szlig', 'agrave', 'aacute', |
|
465 |
'acirc', 'atilde', 'auml', 'aring', 'aelig', 'ccedil', |
|
466 |
'egrave', 'eacute', 'ecirc', 'euml', 'igrave', 'iacute', |
|
467 |
'icirc', 'iuml', 'eth', 'ntilde', 'ograve', 'oacute', |
|
468 |
'ocirc', 'otilde', 'ouml', 'divide', 'oslash', 'ugrave', |
|
469 |
'uacute', 'ucirc', 'uuml', 'yacute', 'thorn', 'yuml', |
|
470 |
'quot', 'amp', 'lt', 'gt', 'apos', 'OElig', |
|
471 |
'oelig', 'Scaron', 'scaron', 'Yuml', 'circ', 'tilde', |
|
472 |
'ensp', 'emsp', 'thinsp', 'zwnj', 'zwj', 'lrm', |
|
473 |
'rlm', 'ndash', 'mdash', 'lsquo', 'rsquo', 'sbquo', |
|
474 |
'ldquo', 'rdquo', 'bdquo', 'dagger', 'Dagger', 'permil', |
|
475 |
'lsaquo', 'rsaquo', 'euro', 'fnof', 'Alpha', 'Beta', |
|
476 |
'Gamma', 'Delta', 'Epsilon', 'Zeta', 'Eta', 'Theta', |
|
477 |
'Iota', 'Kappa', 'Lambda', 'Mu', 'Nu', 'Xi', |
|
478 |
'Omicron', 'Pi', 'Rho', 'Sigma', 'Tau', 'Upsilon', |
|
479 |
'Phi', 'Chi', 'Psi', 'Omega', 'alpha', 'beta', |
|
480 |
'gamma', 'delta', 'epsilon', 'zeta', 'eta', 'theta', |
|
481 |
'iota', 'kappa', 'lambda', 'mu', 'nu', 'xi', |
|
482 |
'omicron', 'pi', 'rho', 'sigmaf', 'sigma', 'tau', |
|
483 |
'upsilon', 'phi', 'chi', 'psi', 'omega', 'thetasym', |
|
484 |
'upsih', 'piv', 'bull', 'hellip', 'prime', 'Prime', |
|
485 |
'oline', 'frasl', 'weierp', 'image', 'real', 'trade', |
|
486 |
'alefsym', 'larr', 'uarr', 'rarr', 'darr', 'harr', |
|
487 |
'crarr', 'lArr', 'uArr', 'rArr', 'dArr', 'hArr', |
|
488 |
'forall', 'part', 'exist', 'empty', 'nabla', 'isin', |
|
489 |
'notin', 'ni', 'prod', 'sum', 'minus', 'lowast', |
|
490 |
'radic', 'prop', 'infin', 'ang', 'and', 'or', |
|
491 |
'cap', 'cup', 'int', 'sim', 'cong', 'asymp', |
|
492 |
'ne', 'equiv', 'le', 'ge', 'sub', 'sup', |
|
493 |
'nsub', 'sube', 'supe', 'oplus', 'otimes', 'perp', |
|
494 |
'sdot', 'lceil', 'rceil', 'lfloor', 'rfloor', 'lang', |
|
495 |
'rang', 'loz', 'spades', 'clubs', 'hearts', 'diams', |
|
5 | 496 |
'sup1', 'sup2', 'sup3', 'frac14', 'frac12', 'frac34', |
497 |
'there4', |
|
0 | 498 |
); |
499 |
||
500 |
$allowedposttags = array_map( '_wp_add_global_attributes', $allowedposttags ); |
|
501 |
} else { |
|
502 |
$allowedtags = wp_kses_array_lc( $allowedtags ); |
|
503 |
$allowedposttags = wp_kses_array_lc( $allowedposttags ); |
|
504 |
} |
|
505 |
||
506 |
/** |
|
507 |
* Filters content and keeps only allowable HTML elements. |
|
508 |
* |
|
509 |
* This function makes sure that only the allowed HTML element names, attribute |
|
510 |
* names and attribute values plus only sane HTML entities will occur in |
|
511 |
* $string. You have to remove any slashes from PHP's magic quotes before you |
|
512 |
* call this function. |
|
513 |
* |
|
514 |
* The default allowed protocols are 'http', 'https', 'ftp', 'mailto', 'news', |
|
515 |
* 'irc', 'gopher', 'nntp', 'feed', 'telnet, 'mms', 'rtsp' and 'svn'. This |
|
516 |
* covers all common link protocols, except for 'javascript' which should not |
|
517 |
* be allowed for untrusted users. |
|
518 |
* |
|
519 |
* @since 1.0.0 |
|
520 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
521 |
* @param string $string Content to filter through kses |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
522 |
* @param array $allowed_html List of allowed HTML elements |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
523 |
* @param array $allowed_protocols Optional. Allowed protocol in links. |
0 | 524 |
* @return string Filtered content with only allowed HTML elements |
525 |
*/ |
|
526 |
function wp_kses( $string, $allowed_html, $allowed_protocols = array() ) { |
|
527 |
if ( empty( $allowed_protocols ) ) |
|
528 |
$allowed_protocols = wp_allowed_protocols(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
529 |
$string = wp_kses_no_null( $string, array( 'slash_zero' => 'keep' ) ); |
0 | 530 |
$string = wp_kses_normalize_entities($string); |
531 |
$string = wp_kses_hook($string, $allowed_html, $allowed_protocols); // WP changed the order of these funcs and added args to wp_kses_hook |
|
532 |
return wp_kses_split($string, $allowed_html, $allowed_protocols); |
|
533 |
} |
|
534 |
||
535 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
536 |
* Filters one attribute only and ensures its value is allowed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
537 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
538 |
* This function has the advantage of being more secure than esc_attr() and can |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
539 |
* escape data in some situations where wp_kses() must strip the whole attribute. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
540 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
541 |
* @since 4.2.3 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
542 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
543 |
* @param string $string The 'whole' attribute, including name and value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
544 |
* @param string $element The element name to which the attribute belongs. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
545 |
* @return string Filtered attribute. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
546 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
547 |
function wp_kses_one_attr( $string, $element ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
548 |
$uris = array('xmlns', 'profile', 'href', 'src', 'cite', 'classid', 'codebase', 'data', 'usemap', 'longdesc', 'action'); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
549 |
$allowed_html = wp_kses_allowed_html( 'post' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
550 |
$allowed_protocols = wp_allowed_protocols(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
551 |
$string = wp_kses_no_null( $string, array( 'slash_zero' => 'keep' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
552 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
553 |
// Preserve leading and trailing whitespace. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
554 |
$matches = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
555 |
preg_match('/^\s*/', $string, $matches); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
556 |
$lead = $matches[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
557 |
preg_match('/\s*$/', $string, $matches); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
558 |
$trail = $matches[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
559 |
if ( empty( $trail ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
560 |
$string = substr( $string, strlen( $lead ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
561 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
562 |
$string = substr( $string, strlen( $lead ), -strlen( $trail ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
563 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
564 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
565 |
// Parse attribute name and value from input. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
566 |
$split = preg_split( '/\s*=\s*/', $string, 2 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
567 |
$name = $split[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
568 |
if ( count( $split ) == 2 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
569 |
$value = $split[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
570 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
571 |
// Remove quotes surrounding $value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
572 |
// Also guarantee correct quoting in $string for this one attribute. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
573 |
if ( '' == $value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
574 |
$quote = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
575 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
576 |
$quote = $value[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
577 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
578 |
if ( '"' == $quote || "'" == $quote ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
579 |
if ( substr( $value, -1 ) != $quote ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
580 |
return ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
581 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
582 |
$value = substr( $value, 1, -1 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
583 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
584 |
$quote = '"'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
585 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
586 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
587 |
// Sanitize quotes, angle braces, and entities. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
588 |
$value = esc_attr( $value ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
589 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
590 |
// Sanitize URI values. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
591 |
if ( in_array( strtolower( $name ), $uris ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
592 |
$value = wp_kses_bad_protocol( $value, $allowed_protocols ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
593 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
594 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
595 |
$string = "$name=$quote$value$quote"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
596 |
$vless = 'n'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
597 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
598 |
$value = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
599 |
$vless = 'y'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
600 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
601 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
602 |
// Sanitize attribute by name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
603 |
wp_kses_attr_check( $name, $value, $string, $vless, $element, $allowed_html ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
604 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
605 |
// Restore whitespace. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
606 |
return $lead . $string . $trail; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
607 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
608 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
609 |
/** |
0 | 610 |
* Return a list of allowed tags and attributes for a given context. |
611 |
* |
|
612 |
* @since 3.5.0 |
|
613 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
614 |
* @global array $allowedposttags |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
615 |
* @global array $allowedtags |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
616 |
* @global array $allowedentitynames |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
617 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
618 |
* @param string|array $context The context for which to retrieve tags. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
619 |
* Allowed values are post, strip, data, entities, or |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
620 |
* the name of a field filter such as pre_user_description. |
0 | 621 |
* @return array List of allowed tags and their allowed attributes. |
622 |
*/ |
|
623 |
function wp_kses_allowed_html( $context = '' ) { |
|
624 |
global $allowedposttags, $allowedtags, $allowedentitynames; |
|
625 |
||
5 | 626 |
if ( is_array( $context ) ) { |
627 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
628 |
* Filters HTML elements allowed for a given context. |
5 | 629 |
* |
630 |
* @since 3.5.0 |
|
631 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
632 |
* @param array $context Context to judge allowed tags by. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
633 |
* @param string $context_type Context type (explicit). |
5 | 634 |
*/ |
0 | 635 |
return apply_filters( 'wp_kses_allowed_html', $context, 'explicit' ); |
5 | 636 |
} |
0 | 637 |
|
638 |
switch ( $context ) { |
|
639 |
case 'post': |
|
5 | 640 |
/** This filter is documented in wp-includes/kses.php */ |
0 | 641 |
return apply_filters( 'wp_kses_allowed_html', $allowedposttags, $context ); |
5 | 642 |
|
0 | 643 |
case 'user_description': |
644 |
case 'pre_user_description': |
|
645 |
$tags = $allowedtags; |
|
646 |
$tags['a']['rel'] = true; |
|
5 | 647 |
/** This filter is documented in wp-includes/kses.php */ |
0 | 648 |
return apply_filters( 'wp_kses_allowed_html', $tags, $context ); |
5 | 649 |
|
0 | 650 |
case 'strip': |
5 | 651 |
/** This filter is documented in wp-includes/kses.php */ |
0 | 652 |
return apply_filters( 'wp_kses_allowed_html', array(), $context ); |
5 | 653 |
|
0 | 654 |
case 'entities': |
5 | 655 |
/** This filter is documented in wp-includes/kses.php */ |
0 | 656 |
return apply_filters( 'wp_kses_allowed_html', $allowedentitynames, $context); |
5 | 657 |
|
0 | 658 |
case 'data': |
659 |
default: |
|
5 | 660 |
/** This filter is documented in wp-includes/kses.php */ |
0 | 661 |
return apply_filters( 'wp_kses_allowed_html', $allowedtags, $context ); |
662 |
} |
|
663 |
} |
|
664 |
||
665 |
/** |
|
666 |
* You add any kses hooks here. |
|
667 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
668 |
* There is currently only one kses WordPress hook, {@see 'pre_kses'}, and it is called here. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
669 |
* All parameters are passed to the hooks and expected to receive a string. |
0 | 670 |
* |
671 |
* @since 1.0.0 |
|
672 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
673 |
* @param string $string Content to filter through kses |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
674 |
* @param array $allowed_html List of allowed HTML elements |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
675 |
* @param array $allowed_protocols Allowed protocol in links |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
676 |
* @return string Filtered content through {@see 'pre_kses'} hook. |
0 | 677 |
*/ |
678 |
function wp_kses_hook( $string, $allowed_html, $allowed_protocols ) { |
|
5 | 679 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
680 |
* Filters content to be run through kses. |
5 | 681 |
* |
682 |
* @since 2.3.0 |
|
683 |
* |
|
684 |
* @param string $string Content to run through kses. |
|
685 |
* @param array $allowed_html Allowed HTML elements. |
|
686 |
* @param array $allowed_protocols Allowed protocol in links. |
|
687 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
688 |
return apply_filters( 'pre_kses', $string, $allowed_html, $allowed_protocols ); |
0 | 689 |
} |
690 |
||
691 |
/** |
|
692 |
* This function returns kses' version number. |
|
693 |
* |
|
694 |
* @since 1.0.0 |
|
695 |
* |
|
696 |
* @return string KSES Version Number |
|
697 |
*/ |
|
698 |
function wp_kses_version() { |
|
699 |
return '0.2.2'; |
|
700 |
} |
|
701 |
||
702 |
/** |
|
703 |
* Searches for HTML tags, no matter how malformed. |
|
704 |
* |
|
705 |
* It also matches stray ">" characters. |
|
706 |
* |
|
707 |
* @since 1.0.0 |
|
708 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
709 |
* @global array $pass_allowed_html |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
710 |
* @global array $pass_allowed_protocols |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
711 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
712 |
* @param string $string Content to filter |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
713 |
* @param array $allowed_html Allowed HTML elements |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
714 |
* @param array $allowed_protocols Allowed protocols to keep |
0 | 715 |
* @return string Content with fixed HTML tags |
716 |
*/ |
|
717 |
function wp_kses_split( $string, $allowed_html, $allowed_protocols ) { |
|
718 |
global $pass_allowed_html, $pass_allowed_protocols; |
|
719 |
$pass_allowed_html = $allowed_html; |
|
720 |
$pass_allowed_protocols = $allowed_protocols; |
|
721 |
return preg_replace_callback( '%(<!--.*?(-->|$))|(<[^>]*(>|$)|>)%', '_wp_kses_split_callback', $string ); |
|
722 |
} |
|
723 |
||
724 |
/** |
|
725 |
* Callback for wp_kses_split. |
|
726 |
* |
|
727 |
* @since 3.1.0 |
|
728 |
* @access private |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
729 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
730 |
* @global array $pass_allowed_html |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
731 |
* @global array $pass_allowed_protocols |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
732 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
733 |
* @return string |
0 | 734 |
*/ |
735 |
function _wp_kses_split_callback( $match ) { |
|
736 |
global $pass_allowed_html, $pass_allowed_protocols; |
|
737 |
return wp_kses_split2( $match[0], $pass_allowed_html, $pass_allowed_protocols ); |
|
738 |
} |
|
739 |
||
740 |
/** |
|
741 |
* Callback for wp_kses_split for fixing malformed HTML tags. |
|
742 |
* |
|
743 |
* This function does a lot of work. It rejects some very malformed things like |
|
744 |
* <:::>. It returns an empty string, if the element isn't allowed (look ma, no |
|
745 |
* strip_tags()!). Otherwise it splits the tag into an element and an attribute |
|
746 |
* list. |
|
747 |
* |
|
748 |
* After the tag is split into an element and an attribute list, it is run |
|
749 |
* through another filter which will remove illegal attributes and once that is |
|
750 |
* completed, will be returned. |
|
751 |
* |
|
752 |
* @access private |
|
753 |
* @since 1.0.0 |
|
754 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
755 |
* @param string $string Content to filter |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
756 |
* @param array $allowed_html Allowed HTML elements |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
757 |
* @param array $allowed_protocols Allowed protocols to keep |
0 | 758 |
* @return string Fixed HTML element |
759 |
*/ |
|
760 |
function wp_kses_split2($string, $allowed_html, $allowed_protocols) { |
|
761 |
$string = wp_kses_stripslashes($string); |
|
762 |
||
763 |
if (substr($string, 0, 1) != '<') |
|
764 |
return '>'; |
|
5 | 765 |
// It matched a ">" character |
0 | 766 |
|
767 |
if ( '<!--' == substr( $string, 0, 4 ) ) { |
|
768 |
$string = str_replace( array('<!--', '-->'), '', $string ); |
|
769 |
while ( $string != ($newstring = wp_kses($string, $allowed_html, $allowed_protocols)) ) |
|
770 |
$string = $newstring; |
|
771 |
if ( $string == '' ) |
|
772 |
return ''; |
|
773 |
// prevent multiple dashes in comments |
|
774 |
$string = preg_replace('/--+/', '-', $string); |
|
775 |
// prevent three dashes closing a comment |
|
776 |
$string = preg_replace('/-$/', '', $string); |
|
777 |
return "<!--{$string}-->"; |
|
778 |
} |
|
5 | 779 |
// Allow HTML comments |
0 | 780 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
781 |
if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9-]+)([^>]*)>?$%', $string, $matches)) |
0 | 782 |
return ''; |
5 | 783 |
// It's seriously malformed |
0 | 784 |
|
785 |
$slash = trim($matches[1]); |
|
786 |
$elem = $matches[2]; |
|
787 |
$attrlist = $matches[3]; |
|
788 |
||
789 |
if ( ! is_array( $allowed_html ) ) |
|
790 |
$allowed_html = wp_kses_allowed_html( $allowed_html ); |
|
791 |
||
792 |
if ( ! isset($allowed_html[strtolower($elem)]) ) |
|
793 |
return ''; |
|
5 | 794 |
// They are using a not allowed HTML element |
0 | 795 |
|
796 |
if ($slash != '') |
|
797 |
return "</$elem>"; |
|
5 | 798 |
// No attributes are allowed for closing elements |
0 | 799 |
|
800 |
return wp_kses_attr( $elem, $attrlist, $allowed_html, $allowed_protocols ); |
|
801 |
} |
|
802 |
||
803 |
/** |
|
804 |
* Removes all attributes, if none are allowed for this element. |
|
805 |
* |
|
806 |
* If some are allowed it calls wp_kses_hair() to split them further, and then |
|
807 |
* it builds up new HTML code from the data that kses_hair() returns. It also |
|
808 |
* removes "<" and ">" characters, if there are any left. One more thing it does |
|
809 |
* is to check if the tag has a closing XHTML slash, and if it does, it puts one |
|
810 |
* in the returned code as well. |
|
811 |
* |
|
812 |
* @since 1.0.0 |
|
813 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
814 |
* @param string $element HTML element/tag |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
815 |
* @param string $attr HTML attributes from HTML element to closing HTML element tag |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
816 |
* @param array $allowed_html Allowed HTML elements |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
817 |
* @param array $allowed_protocols Allowed protocols to keep |
0 | 818 |
* @return string Sanitized HTML element |
819 |
*/ |
|
820 |
function wp_kses_attr($element, $attr, $allowed_html, $allowed_protocols) { |
|
821 |
if ( ! is_array( $allowed_html ) ) |
|
822 |
$allowed_html = wp_kses_allowed_html( $allowed_html ); |
|
823 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
824 |
// Is there a closing XHTML slash at the end of the attributes? |
0 | 825 |
$xhtml_slash = ''; |
826 |
if (preg_match('%\s*/\s*$%', $attr)) |
|
827 |
$xhtml_slash = ' /'; |
|
828 |
||
5 | 829 |
// Are any attributes allowed at all for this element? |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
830 |
$element_low = strtolower( $element ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
831 |
if ( empty( $allowed_html[ $element_low ] ) || true === $allowed_html[ $element_low ] ) { |
0 | 832 |
return "<$element$xhtml_slash>"; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
833 |
} |
0 | 834 |
|
5 | 835 |
// Split it |
0 | 836 |
$attrarr = wp_kses_hair($attr, $allowed_protocols); |
837 |
||
5 | 838 |
// Go through $attrarr, and save the allowed attributes for this element |
839 |
// in $attr2 |
|
0 | 840 |
$attr2 = ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
841 |
foreach ( $attrarr as $arreach ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
842 |
if ( wp_kses_attr_check( $arreach['name'], $arreach['value'], $arreach['whole'], $arreach['vless'], $element, $allowed_html ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
843 |
$attr2 .= ' '.$arreach['whole']; |
0 | 844 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
845 |
} |
0 | 846 |
|
5 | 847 |
// Remove any "<" or ">" characters |
0 | 848 |
$attr2 = preg_replace('/[<>]/', '', $attr2); |
849 |
||
850 |
return "<$element$attr2$xhtml_slash>"; |
|
851 |
} |
|
852 |
||
853 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
854 |
* Determine whether an attribute is allowed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
855 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
856 |
* @since 4.2.3 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
857 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
858 |
* @param string $name The attribute name. Returns empty string when not allowed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
859 |
* @param string $value The attribute value. Returns a filtered value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
860 |
* @param string $whole The name=value input. Returns filtered input. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
861 |
* @param string $vless 'y' when attribute like "enabled", otherwise 'n'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
862 |
* @param string $element The name of the element to which this attribute belongs. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
863 |
* @param array $allowed_html The full list of allowed elements and attributes. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
864 |
* @return bool Is the attribute allowed? |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
865 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
866 |
function wp_kses_attr_check( &$name, &$value, &$whole, $vless, $element, $allowed_html ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
867 |
$allowed_attr = $allowed_html[strtolower( $element )]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
868 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
869 |
$name_low = strtolower( $name ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
870 |
if ( ! isset( $allowed_attr[$name_low] ) || '' == $allowed_attr[$name_low] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
871 |
$name = $value = $whole = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
872 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
873 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
874 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
875 |
if ( 'style' == $name_low ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
876 |
$new_value = safecss_filter_attr( $value ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
877 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
878 |
if ( empty( $new_value ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
879 |
$name = $value = $whole = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
880 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
881 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
882 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
883 |
$whole = str_replace( $value, $new_value, $whole ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
884 |
$value = $new_value; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
885 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
886 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
887 |
if ( is_array( $allowed_attr[$name_low] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
888 |
// there are some checks |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
889 |
foreach ( $allowed_attr[$name_low] as $currkey => $currval ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
890 |
if ( ! wp_kses_check_attr_val( $value, $vless, $currkey, $currval ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
891 |
$name = $value = $whole = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
892 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
893 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
894 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
895 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
896 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
897 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
898 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
899 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
900 |
/** |
0 | 901 |
* Builds an attribute list from string containing attributes. |
902 |
* |
|
903 |
* This function does a lot of work. It parses an attribute list into an array |
|
904 |
* with attribute data, and tries to do the right thing even if it gets weird |
|
905 |
* input. It will add quotes around attribute values that don't have any quotes |
|
906 |
* or apostrophes around them, to make it easier to produce HTML code that will |
|
907 |
* conform to W3C's HTML specification. It will also remove bad URL protocols |
|
908 |
* from attribute values. It also reduces duplicate attributes by using the |
|
909 |
* attribute defined first (foo='bar' foo='baz' will result in foo='bar'). |
|
910 |
* |
|
911 |
* @since 1.0.0 |
|
912 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
913 |
* @param string $attr Attribute list from HTML element to closing HTML element tag |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
914 |
* @param array $allowed_protocols Allowed protocols to keep |
0 | 915 |
* @return array List of attributes after parsing |
916 |
*/ |
|
917 |
function wp_kses_hair($attr, $allowed_protocols) { |
|
918 |
$attrarr = array(); |
|
919 |
$mode = 0; |
|
920 |
$attrname = ''; |
|
921 |
$uris = array('xmlns', 'profile', 'href', 'src', 'cite', 'classid', 'codebase', 'data', 'usemap', 'longdesc', 'action'); |
|
922 |
||
5 | 923 |
// Loop through the whole attribute list |
0 | 924 |
|
925 |
while (strlen($attr) != 0) { |
|
5 | 926 |
$working = 0; // Was the last operation successful? |
0 | 927 |
|
928 |
switch ($mode) { |
|
5 | 929 |
case 0 : // attribute name, href for instance |
0 | 930 |
|
5 | 931 |
if ( preg_match('/^([-a-zA-Z:]+)/', $attr, $match ) ) { |
0 | 932 |
$attrname = $match[1]; |
933 |
$working = $mode = 1; |
|
5 | 934 |
$attr = preg_replace( '/^[-a-zA-Z:]+/', '', $attr ); |
0 | 935 |
} |
936 |
||
937 |
break; |
|
938 |
||
5 | 939 |
case 1 : // equals sign or valueless ("selected") |
0 | 940 |
|
5 | 941 |
if (preg_match('/^\s*=\s*/', $attr)) // equals sign |
0 | 942 |
{ |
943 |
$working = 1; |
|
944 |
$mode = 2; |
|
945 |
$attr = preg_replace('/^\s*=\s*/', '', $attr); |
|
946 |
break; |
|
947 |
} |
|
948 |
||
5 | 949 |
if (preg_match('/^\s+/', $attr)) // valueless |
0 | 950 |
{ |
951 |
$working = 1; |
|
952 |
$mode = 0; |
|
953 |
if(false === array_key_exists($attrname, $attrarr)) { |
|
954 |
$attrarr[$attrname] = array ('name' => $attrname, 'value' => '', 'whole' => $attrname, 'vless' => 'y'); |
|
955 |
} |
|
956 |
$attr = preg_replace('/^\s+/', '', $attr); |
|
957 |
} |
|
958 |
||
959 |
break; |
|
960 |
||
5 | 961 |
case 2 : // attribute value, a URL after href= for instance |
0 | 962 |
|
963 |
if (preg_match('%^"([^"]*)"(\s+|/?$)%', $attr, $match)) |
|
5 | 964 |
// "value" |
0 | 965 |
{ |
966 |
$thisval = $match[1]; |
|
967 |
if ( in_array(strtolower($attrname), $uris) ) |
|
968 |
$thisval = wp_kses_bad_protocol($thisval, $allowed_protocols); |
|
969 |
||
970 |
if(false === array_key_exists($attrname, $attrarr)) { |
|
971 |
$attrarr[$attrname] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname=\"$thisval\"", 'vless' => 'n'); |
|
972 |
} |
|
973 |
$working = 1; |
|
974 |
$mode = 0; |
|
975 |
$attr = preg_replace('/^"[^"]*"(\s+|$)/', '', $attr); |
|
976 |
break; |
|
977 |
} |
|
978 |
||
979 |
if (preg_match("%^'([^']*)'(\s+|/?$)%", $attr, $match)) |
|
5 | 980 |
// 'value' |
0 | 981 |
{ |
982 |
$thisval = $match[1]; |
|
983 |
if ( in_array(strtolower($attrname), $uris) ) |
|
984 |
$thisval = wp_kses_bad_protocol($thisval, $allowed_protocols); |
|
985 |
||
986 |
if(false === array_key_exists($attrname, $attrarr)) { |
|
987 |
$attrarr[$attrname] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname='$thisval'", 'vless' => 'n'); |
|
988 |
} |
|
989 |
$working = 1; |
|
990 |
$mode = 0; |
|
991 |
$attr = preg_replace("/^'[^']*'(\s+|$)/", '', $attr); |
|
992 |
break; |
|
993 |
} |
|
994 |
||
995 |
if (preg_match("%^([^\s\"']+)(\s+|/?$)%", $attr, $match)) |
|
5 | 996 |
// value |
0 | 997 |
{ |
998 |
$thisval = $match[1]; |
|
999 |
if ( in_array(strtolower($attrname), $uris) ) |
|
1000 |
$thisval = wp_kses_bad_protocol($thisval, $allowed_protocols); |
|
1001 |
||
1002 |
if(false === array_key_exists($attrname, $attrarr)) { |
|
1003 |
$attrarr[$attrname] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname=\"$thisval\"", 'vless' => 'n'); |
|
1004 |
} |
|
5 | 1005 |
// We add quotes to conform to W3C's HTML spec. |
0 | 1006 |
$working = 1; |
1007 |
$mode = 0; |
|
1008 |
$attr = preg_replace("%^[^\s\"']+(\s+|$)%", '', $attr); |
|
1009 |
} |
|
1010 |
||
1011 |
break; |
|
5 | 1012 |
} // switch |
0 | 1013 |
|
5 | 1014 |
if ($working == 0) // not well formed, remove and try again |
0 | 1015 |
{ |
1016 |
$attr = wp_kses_html_error($attr); |
|
1017 |
$mode = 0; |
|
1018 |
} |
|
5 | 1019 |
} // while |
0 | 1020 |
|
1021 |
if ($mode == 1 && false === array_key_exists($attrname, $attrarr)) |
|
5 | 1022 |
// special case, for when the attribute list ends with a valueless |
1023 |
// attribute like "selected" |
|
0 | 1024 |
$attrarr[$attrname] = array ('name' => $attrname, 'value' => '', 'whole' => $attrname, 'vless' => 'y'); |
1025 |
||
1026 |
return $attrarr; |
|
1027 |
} |
|
1028 |
||
1029 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1030 |
* Finds all attributes of an HTML element. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1031 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1032 |
* Does not modify input. May return "evil" output. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1033 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1034 |
* Based on wp_kses_split2() and wp_kses_attr() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1035 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1036 |
* @since 4.2.3 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1037 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1038 |
* @param string $element HTML element/tag |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1039 |
* @return array|bool List of attributes found in $element. Returns false on failure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1040 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1041 |
function wp_kses_attr_parse( $element ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1042 |
$valid = preg_match('%^(<\s*)(/\s*)?([a-zA-Z0-9]+\s*)([^>]*)(>?)$%', $element, $matches); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1043 |
if ( 1 !== $valid ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1044 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1045 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1046 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1047 |
$begin = $matches[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1048 |
$slash = $matches[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1049 |
$elname = $matches[3]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1050 |
$attr = $matches[4]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1051 |
$end = $matches[5]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1052 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1053 |
if ( '' !== $slash ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1054 |
// Closing elements do not get parsed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1055 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1056 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1057 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1058 |
// Is there a closing XHTML slash at the end of the attributes? |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1059 |
if ( 1 === preg_match( '%\s*/\s*$%', $attr, $matches ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1060 |
$xhtml_slash = $matches[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1061 |
$attr = substr( $attr, 0, -strlen( $xhtml_slash ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1062 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1063 |
$xhtml_slash = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1064 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1065 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1066 |
// Split it |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1067 |
$attrarr = wp_kses_hair_parse( $attr ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1068 |
if ( false === $attrarr ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1069 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1070 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1071 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1072 |
// Make sure all input is returned by adding front and back matter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1073 |
array_unshift( $attrarr, $begin . $slash . $elname ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1074 |
array_push( $attrarr, $xhtml_slash . $end ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1075 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1076 |
return $attrarr; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1077 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1078 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1079 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1080 |
* Builds an attribute list from string containing attributes. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1081 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1082 |
* Does not modify input. May return "evil" output. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1083 |
* In case of unexpected input, returns false instead of stripping things. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1084 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1085 |
* Based on wp_kses_hair() but does not return a multi-dimensional array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1086 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1087 |
* @since 4.2.3 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1088 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1089 |
* @param string $attr Attribute list from HTML element to closing HTML element tag |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1090 |
* @return array|bool List of attributes found in $attr. Returns false on failure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1091 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1092 |
function wp_kses_hair_parse( $attr ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1093 |
if ( '' === $attr ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1094 |
return array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1095 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1096 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1097 |
$regex = |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1098 |
'(?:' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1099 |
. '[-a-zA-Z:]+' // Attribute name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1100 |
. '|' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1101 |
. '\[\[?[^\[\]]+\]\]?' // Shortcode in the name position implies unfiltered_html. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1102 |
. ')' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1103 |
. '(?:' // Attribute value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1104 |
. '\s*=\s*' // All values begin with '=' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1105 |
. '(?:' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1106 |
. '"[^"]*"' // Double-quoted |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1107 |
. '|' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1108 |
. "'[^']*'" // Single-quoted |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1109 |
. '|' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1110 |
. '[^\s"\']+' // Non-quoted |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1111 |
. '(?:\s|$)' // Must have a space |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1112 |
. ')' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1113 |
. '|' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1114 |
. '(?:\s|$)' // If attribute has no value, space is required. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1115 |
. ')' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1116 |
. '\s*'; // Trailing space is optional except as mentioned above. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1117 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1118 |
// Although it is possible to reduce this procedure to a single regexp, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1119 |
// we must run that regexp twice to get exactly the expected result. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1120 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1121 |
$validation = "%^($regex)+$%"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1122 |
$extraction = "%$regex%"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1123 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1124 |
if ( 1 === preg_match( $validation, $attr ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1125 |
preg_match_all( $extraction, $attr, $attrarr ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1126 |
return $attrarr[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1127 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1128 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1129 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1130 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1131 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1132 |
/** |
0 | 1133 |
* Performs different checks for attribute values. |
1134 |
* |
|
1135 |
* The currently implemented checks are "maxlen", "minlen", "maxval", "minval" |
|
1136 |
* and "valueless". |
|
1137 |
* |
|
1138 |
* @since 1.0.0 |
|
1139 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1140 |
* @param string $value Attribute value |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1141 |
* @param string $vless Whether the value is valueless. Use 'y' or 'n' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1142 |
* @param string $checkname What $checkvalue is checking for. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1143 |
* @param mixed $checkvalue What constraint the value should pass |
0 | 1144 |
* @return bool Whether check passes |
1145 |
*/ |
|
1146 |
function wp_kses_check_attr_val($value, $vless, $checkname, $checkvalue) { |
|
1147 |
$ok = true; |
|
1148 |
||
1149 |
switch (strtolower($checkname)) { |
|
1150 |
case 'maxlen' : |
|
5 | 1151 |
// The maxlen check makes sure that the attribute value has a length not |
1152 |
// greater than the given value. This can be used to avoid Buffer Overflows |
|
1153 |
// in WWW clients and various Internet servers. |
|
0 | 1154 |
|
1155 |
if (strlen($value) > $checkvalue) |
|
1156 |
$ok = false; |
|
1157 |
break; |
|
1158 |
||
1159 |
case 'minlen' : |
|
5 | 1160 |
// The minlen check makes sure that the attribute value has a length not |
1161 |
// smaller than the given value. |
|
0 | 1162 |
|
1163 |
if (strlen($value) < $checkvalue) |
|
1164 |
$ok = false; |
|
1165 |
break; |
|
1166 |
||
1167 |
case 'maxval' : |
|
5 | 1168 |
// The maxval check does two things: it checks that the attribute value is |
1169 |
// an integer from 0 and up, without an excessive amount of zeroes or |
|
1170 |
// whitespace (to avoid Buffer Overflows). It also checks that the attribute |
|
1171 |
// value is not greater than the given value. |
|
1172 |
// This check can be used to avoid Denial of Service attacks. |
|
0 | 1173 |
|
1174 |
if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value)) |
|
1175 |
$ok = false; |
|
1176 |
if ($value > $checkvalue) |
|
1177 |
$ok = false; |
|
1178 |
break; |
|
1179 |
||
1180 |
case 'minval' : |
|
5 | 1181 |
// The minval check makes sure that the attribute value is a positive integer, |
1182 |
// and that it is not smaller than the given value. |
|
0 | 1183 |
|
1184 |
if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value)) |
|
1185 |
$ok = false; |
|
1186 |
if ($value < $checkvalue) |
|
1187 |
$ok = false; |
|
1188 |
break; |
|
1189 |
||
1190 |
case 'valueless' : |
|
5 | 1191 |
// The valueless check makes sure if the attribute has a value |
1192 |
// (like <a href="blah">) or not (<option selected>). If the given value |
|
1193 |
// is a "y" or a "Y", the attribute must not have a value. |
|
1194 |
// If the given value is an "n" or an "N", the attribute must have one. |
|
0 | 1195 |
|
1196 |
if (strtolower($checkvalue) != $vless) |
|
1197 |
$ok = false; |
|
1198 |
break; |
|
5 | 1199 |
} // switch |
0 | 1200 |
|
1201 |
return $ok; |
|
1202 |
} |
|
1203 |
||
1204 |
/** |
|
1205 |
* Sanitize string from bad protocols. |
|
1206 |
* |
|
1207 |
* This function removes all non-allowed protocols from the beginning of |
|
1208 |
* $string. It ignores whitespace and the case of the letters, and it does |
|
1209 |
* understand HTML entities. It does its work in a while loop, so it won't be |
|
1210 |
* fooled by a string like "javascript:javascript:alert(57)". |
|
1211 |
* |
|
1212 |
* @since 1.0.0 |
|
1213 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1214 |
* @param string $string Content to filter bad protocols from |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1215 |
* @param array $allowed_protocols Allowed protocols to keep |
0 | 1216 |
* @return string Filtered content |
1217 |
*/ |
|
1218 |
function wp_kses_bad_protocol($string, $allowed_protocols) { |
|
1219 |
$string = wp_kses_no_null($string); |
|
1220 |
$iterations = 0; |
|
1221 |
||
1222 |
do { |
|
1223 |
$original_string = $string; |
|
1224 |
$string = wp_kses_bad_protocol_once($string, $allowed_protocols); |
|
1225 |
} while ( $original_string != $string && ++$iterations < 6 ); |
|
1226 |
||
1227 |
if ( $original_string != $string ) |
|
1228 |
return ''; |
|
1229 |
||
1230 |
return $string; |
|
1231 |
} |
|
1232 |
||
1233 |
/** |
|
5 | 1234 |
* Removes any invalid control characters in $string. |
1235 |
* |
|
1236 |
* Also removes any instance of the '\0' string. |
|
0 | 1237 |
* |
1238 |
* @since 1.0.0 |
|
1239 |
* |
|
1240 |
* @param string $string |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1241 |
* @param array $options Set 'slash_zero' => 'keep' when '\0' is allowed. Default is 'remove'. |
0 | 1242 |
* @return string |
1243 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1244 |
function wp_kses_no_null( $string, $options = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1245 |
if ( ! isset( $options['slash_zero'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1246 |
$options = array( 'slash_zero' => 'remove' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1247 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1248 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1249 |
$string = preg_replace( '/[\x00-\x08\x0B\x0C\x0E-\x1F]/', '', $string ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1250 |
if ( 'remove' == $options['slash_zero'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1251 |
$string = preg_replace( '/\\\\+0+/', '', $string ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1252 |
} |
0 | 1253 |
|
1254 |
return $string; |
|
1255 |
} |
|
1256 |
||
1257 |
/** |
|
1258 |
* Strips slashes from in front of quotes. |
|
1259 |
* |
|
1260 |
* This function changes the character sequence \" to just ". It leaves all |
|
1261 |
* other slashes alone. It's really weird, but the quoting from |
|
1262 |
* preg_replace(//e) seems to require this. |
|
1263 |
* |
|
1264 |
* @since 1.0.0 |
|
1265 |
* |
|
1266 |
* @param string $string String to strip slashes |
|
1267 |
* @return string Fixed string with quoted slashes |
|
1268 |
*/ |
|
1269 |
function wp_kses_stripslashes($string) { |
|
1270 |
return preg_replace('%\\\\"%', '"', $string); |
|
1271 |
} |
|
1272 |
||
1273 |
/** |
|
1274 |
* Goes through an array and changes the keys to all lower case. |
|
1275 |
* |
|
1276 |
* @since 1.0.0 |
|
1277 |
* |
|
1278 |
* @param array $inarray Unfiltered array |
|
1279 |
* @return array Fixed array with all lowercase keys |
|
1280 |
*/ |
|
1281 |
function wp_kses_array_lc($inarray) { |
|
1282 |
$outarray = array (); |
|
1283 |
||
1284 |
foreach ( (array) $inarray as $inkey => $inval) { |
|
1285 |
$outkey = strtolower($inkey); |
|
1286 |
$outarray[$outkey] = array (); |
|
1287 |
||
1288 |
foreach ( (array) $inval as $inkey2 => $inval2) { |
|
1289 |
$outkey2 = strtolower($inkey2); |
|
1290 |
$outarray[$outkey][$outkey2] = $inval2; |
|
5 | 1291 |
} // foreach $inval |
1292 |
} // foreach $inarray |
|
0 | 1293 |
|
1294 |
return $outarray; |
|
1295 |
} |
|
1296 |
||
1297 |
/** |
|
1298 |
* Handles parsing errors in wp_kses_hair(). |
|
1299 |
* |
|
1300 |
* The general plan is to remove everything to and including some whitespace, |
|
1301 |
* but it deals with quotes and apostrophes as well. |
|
1302 |
* |
|
1303 |
* @since 1.0.0 |
|
1304 |
* |
|
1305 |
* @param string $string |
|
1306 |
* @return string |
|
1307 |
*/ |
|
1308 |
function wp_kses_html_error($string) { |
|
1309 |
return preg_replace('/^("[^"]*("|$)|\'[^\']*(\'|$)|\S)*\s*/', '', $string); |
|
1310 |
} |
|
1311 |
||
1312 |
/** |
|
1313 |
* Sanitizes content from bad protocols and other characters. |
|
1314 |
* |
|
1315 |
* This function searches for URL protocols at the beginning of $string, while |
|
1316 |
* handling whitespace and HTML entities. |
|
1317 |
* |
|
1318 |
* @since 1.0.0 |
|
1319 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1320 |
* @param string $string Content to check for bad protocols |
0 | 1321 |
* @param string $allowed_protocols Allowed protocols |
1322 |
* @return string Sanitized content |
|
1323 |
*/ |
|
1324 |
function wp_kses_bad_protocol_once($string, $allowed_protocols, $count = 1 ) { |
|
1325 |
$string2 = preg_split( '/:|�*58;|�*3a;/i', $string, 2 ); |
|
1326 |
if ( isset($string2[1]) && ! preg_match('%/\?%', $string2[0]) ) { |
|
1327 |
$string = trim( $string2[1] ); |
|
1328 |
$protocol = wp_kses_bad_protocol_once2( $string2[0], $allowed_protocols ); |
|
1329 |
if ( 'feed:' == $protocol ) { |
|
1330 |
if ( $count > 2 ) |
|
1331 |
return ''; |
|
1332 |
$string = wp_kses_bad_protocol_once( $string, $allowed_protocols, ++$count ); |
|
1333 |
if ( empty( $string ) ) |
|
1334 |
return $string; |
|
1335 |
} |
|
1336 |
$string = $protocol . $string; |
|
1337 |
} |
|
1338 |
||
1339 |
return $string; |
|
1340 |
} |
|
1341 |
||
1342 |
/** |
|
1343 |
* Callback for wp_kses_bad_protocol_once() regular expression. |
|
1344 |
* |
|
1345 |
* This function processes URL protocols, checks to see if they're in the |
|
1346 |
* whitelist or not, and returns different data depending on the answer. |
|
1347 |
* |
|
1348 |
* @access private |
|
1349 |
* @since 1.0.0 |
|
1350 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1351 |
* @param string $string URI scheme to check against the whitelist |
0 | 1352 |
* @param string $allowed_protocols Allowed protocols |
1353 |
* @return string Sanitized content |
|
1354 |
*/ |
|
1355 |
function wp_kses_bad_protocol_once2( $string, $allowed_protocols ) { |
|
1356 |
$string2 = wp_kses_decode_entities($string); |
|
1357 |
$string2 = preg_replace('/\s/', '', $string2); |
|
1358 |
$string2 = wp_kses_no_null($string2); |
|
1359 |
$string2 = strtolower($string2); |
|
1360 |
||
1361 |
$allowed = false; |
|
1362 |
foreach ( (array) $allowed_protocols as $one_protocol ) |
|
1363 |
if ( strtolower($one_protocol) == $string2 ) { |
|
1364 |
$allowed = true; |
|
1365 |
break; |
|
1366 |
} |
|
1367 |
||
1368 |
if ($allowed) |
|
1369 |
return "$string2:"; |
|
1370 |
else |
|
1371 |
return ''; |
|
1372 |
} |
|
1373 |
||
1374 |
/** |
|
1375 |
* Converts and fixes HTML entities. |
|
1376 |
* |
|
5 | 1377 |
* This function normalizes HTML entities. It will convert `AT&T` to the correct |
1378 |
* `AT&T`, `:` to `:`, `&#XYZZY;` to `&#XYZZY;` and so on. |
|
0 | 1379 |
* |
1380 |
* @since 1.0.0 |
|
1381 |
* |
|
1382 |
* @param string $string Content to normalize entities |
|
1383 |
* @return string Content with normalized entities |
|
1384 |
*/ |
|
1385 |
function wp_kses_normalize_entities($string) { |
|
5 | 1386 |
// Disarm all entities by converting & to & |
0 | 1387 |
$string = str_replace('&', '&', $string); |
1388 |
||
5 | 1389 |
// Change back the allowed entities in our entity whitelist |
1390 |
$string = preg_replace_callback('/&([A-Za-z]{2,8}[0-9]{0,2});/', 'wp_kses_named_entities', $string); |
|
0 | 1391 |
$string = preg_replace_callback('/&#(0*[0-9]{1,7});/', 'wp_kses_normalize_entities2', $string); |
1392 |
$string = preg_replace_callback('/&#[Xx](0*[0-9A-Fa-f]{1,6});/', 'wp_kses_normalize_entities3', $string); |
|
1393 |
||
1394 |
return $string; |
|
1395 |
} |
|
1396 |
||
1397 |
/** |
|
1398 |
* Callback for wp_kses_normalize_entities() regular expression. |
|
1399 |
* |
|
1400 |
* This function only accepts valid named entity references, which are finite, |
|
1401 |
* case-sensitive, and highly scrutinized by HTML and XML validators. |
|
1402 |
* |
|
1403 |
* @since 3.0.0 |
|
1404 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1405 |
* @global array $allowedentitynames |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1406 |
* |
0 | 1407 |
* @param array $matches preg_replace_callback() matches array |
1408 |
* @return string Correctly encoded entity |
|
1409 |
*/ |
|
1410 |
function wp_kses_named_entities($matches) { |
|
1411 |
global $allowedentitynames; |
|
1412 |
||
1413 |
if ( empty($matches[1]) ) |
|
1414 |
return ''; |
|
1415 |
||
1416 |
$i = $matches[1]; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1417 |
return ( ! in_array( $i, $allowedentitynames ) ) ? "&$i;" : "&$i;"; |
0 | 1418 |
} |
1419 |
||
1420 |
/** |
|
1421 |
* Callback for wp_kses_normalize_entities() regular expression. |
|
1422 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1423 |
* This function helps wp_kses_normalize_entities() to only accept 16-bit |
5 | 1424 |
* values and nothing more for `&#number;` entities. |
0 | 1425 |
* |
1426 |
* @access private |
|
1427 |
* @since 1.0.0 |
|
1428 |
* |
|
1429 |
* @param array $matches preg_replace_callback() matches array |
|
1430 |
* @return string Correctly encoded entity |
|
1431 |
*/ |
|
1432 |
function wp_kses_normalize_entities2($matches) { |
|
1433 |
if ( empty($matches[1]) ) |
|
1434 |
return ''; |
|
1435 |
||
1436 |
$i = $matches[1]; |
|
1437 |
if (valid_unicode($i)) { |
|
1438 |
$i = str_pad(ltrim($i,'0'), 3, '0', STR_PAD_LEFT); |
|
1439 |
$i = "&#$i;"; |
|
1440 |
} else { |
|
1441 |
$i = "&#$i;"; |
|
1442 |
} |
|
1443 |
||
1444 |
return $i; |
|
1445 |
} |
|
1446 |
||
1447 |
/** |
|
1448 |
* Callback for wp_kses_normalize_entities() for regular expression. |
|
1449 |
* |
|
1450 |
* This function helps wp_kses_normalize_entities() to only accept valid Unicode |
|
1451 |
* numeric entities in hex form. |
|
1452 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1453 |
* @since 2.7.0 |
0 | 1454 |
* @access private |
1455 |
* |
|
1456 |
* @param array $matches preg_replace_callback() matches array |
|
1457 |
* @return string Correctly encoded entity |
|
1458 |
*/ |
|
1459 |
function wp_kses_normalize_entities3($matches) { |
|
1460 |
if ( empty($matches[1]) ) |
|
1461 |
return ''; |
|
1462 |
||
1463 |
$hexchars = $matches[1]; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1464 |
return ( ! valid_unicode( hexdec( $hexchars ) ) ) ? "&#x$hexchars;" : '&#x'.ltrim($hexchars,'0').';'; |
0 | 1465 |
} |
1466 |
||
1467 |
/** |
|
1468 |
* Helper function to determine if a Unicode value is valid. |
|
1469 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1470 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1471 |
* |
0 | 1472 |
* @param int $i Unicode value |
1473 |
* @return bool True if the value was a valid Unicode number |
|
1474 |
*/ |
|
1475 |
function valid_unicode($i) { |
|
1476 |
return ( $i == 0x9 || $i == 0xa || $i == 0xd || |
|
1477 |
($i >= 0x20 && $i <= 0xd7ff) || |
|
1478 |
($i >= 0xe000 && $i <= 0xfffd) || |
|
1479 |
($i >= 0x10000 && $i <= 0x10ffff) ); |
|
1480 |
} |
|
1481 |
||
1482 |
/** |
|
1483 |
* Convert all entities to their character counterparts. |
|
1484 |
* |
|
5 | 1485 |
* This function decodes numeric HTML entities (`A` and `A`). |
1486 |
* It doesn't do anything with other entities like ä, but we don't |
|
1487 |
* need them in the URL protocol whitelisting system anyway. |
|
0 | 1488 |
* |
1489 |
* @since 1.0.0 |
|
1490 |
* |
|
1491 |
* @param string $string Content to change entities |
|
1492 |
* @return string Content after decoded entities |
|
1493 |
*/ |
|
1494 |
function wp_kses_decode_entities($string) { |
|
1495 |
$string = preg_replace_callback('/&#([0-9]+);/', '_wp_kses_decode_entities_chr', $string); |
|
1496 |
$string = preg_replace_callback('/&#[Xx]([0-9A-Fa-f]+);/', '_wp_kses_decode_entities_chr_hexdec', $string); |
|
1497 |
||
1498 |
return $string; |
|
1499 |
} |
|
1500 |
||
1501 |
/** |
|
1502 |
* Regex callback for wp_kses_decode_entities() |
|
1503 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1504 |
* @since 2.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1505 |
* |
0 | 1506 |
* @param array $match preg match |
1507 |
* @return string |
|
1508 |
*/ |
|
1509 |
function _wp_kses_decode_entities_chr( $match ) { |
|
1510 |
return chr( $match[1] ); |
|
1511 |
} |
|
1512 |
||
1513 |
/** |
|
1514 |
* Regex callback for wp_kses_decode_entities() |
|
1515 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1516 |
* @since 2.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1517 |
* |
0 | 1518 |
* @param array $match preg match |
1519 |
* @return string |
|
1520 |
*/ |
|
1521 |
function _wp_kses_decode_entities_chr_hexdec( $match ) { |
|
1522 |
return chr( hexdec( $match[1] ) ); |
|
1523 |
} |
|
1524 |
||
1525 |
/** |
|
1526 |
* Sanitize content with allowed HTML Kses rules. |
|
1527 |
* |
|
1528 |
* @since 1.0.0 |
|
1529 |
* |
|
1530 |
* @param string $data Content to filter, expected to be escaped with slashes |
|
1531 |
* @return string Filtered content |
|
1532 |
*/ |
|
1533 |
function wp_filter_kses( $data ) { |
|
1534 |
return addslashes( wp_kses( stripslashes( $data ), current_filter() ) ); |
|
1535 |
} |
|
1536 |
||
1537 |
/** |
|
1538 |
* Sanitize content with allowed HTML Kses rules. |
|
1539 |
* |
|
1540 |
* @since 2.9.0 |
|
1541 |
* |
|
1542 |
* @param string $data Content to filter, expected to not be escaped |
|
1543 |
* @return string Filtered content |
|
1544 |
*/ |
|
1545 |
function wp_kses_data( $data ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1546 |
return wp_kses( $data, current_filter() ); |
0 | 1547 |
} |
1548 |
||
1549 |
/** |
|
1550 |
* Sanitize content for allowed HTML tags for post content. |
|
1551 |
* |
|
1552 |
* Post content refers to the page contents of the 'post' type and not $_POST |
|
1553 |
* data from forms. |
|
1554 |
* |
|
1555 |
* @since 2.0.0 |
|
1556 |
* |
|
1557 |
* @param string $data Post content to filter, expected to be escaped with slashes |
|
1558 |
* @return string Filtered post content with allowed HTML tags and attributes intact. |
|
1559 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1560 |
function wp_filter_post_kses( $data ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1561 |
return addslashes( wp_kses( stripslashes( $data ), 'post' ) ); |
0 | 1562 |
} |
1563 |
||
1564 |
/** |
|
1565 |
* Sanitize content for allowed HTML tags for post content. |
|
1566 |
* |
|
1567 |
* Post content refers to the page contents of the 'post' type and not $_POST |
|
1568 |
* data from forms. |
|
1569 |
* |
|
1570 |
* @since 2.9.0 |
|
1571 |
* |
|
1572 |
* @param string $data Post content to filter |
|
1573 |
* @return string Filtered post content with allowed HTML tags and attributes intact. |
|
1574 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1575 |
function wp_kses_post( $data ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1576 |
return wp_kses( $data, 'post' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1577 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1578 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1579 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1580 |
* Navigates through an array, object, or scalar, and sanitizes content for |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1581 |
* allowed HTML tags for post content. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1582 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1583 |
* @since 4.4.2 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1584 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1585 |
* @see map_deep() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1586 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1587 |
* @param mixed $data The array, object, or scalar value to inspect. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1588 |
* @return mixed The filtered content. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1589 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1590 |
function wp_kses_post_deep( $data ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1591 |
return map_deep( $data, 'wp_kses_post' ); |
0 | 1592 |
} |
1593 |
||
1594 |
/** |
|
1595 |
* Strips all of the HTML in the content. |
|
1596 |
* |
|
1597 |
* @since 2.1.0 |
|
1598 |
* |
|
1599 |
* @param string $data Content to strip all HTML from |
|
1600 |
* @return string Filtered content without any HTML |
|
1601 |
*/ |
|
1602 |
function wp_filter_nohtml_kses( $data ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1603 |
return addslashes( wp_kses( stripslashes( $data ), 'strip' ) ); |
0 | 1604 |
} |
1605 |
||
1606 |
/** |
|
1607 |
* Adds all Kses input form content filters. |
|
1608 |
* |
|
1609 |
* All hooks have default priority. The wp_filter_kses() function is added to |
|
1610 |
* the 'pre_comment_content' and 'title_save_pre' hooks. |
|
1611 |
* |
|
1612 |
* The wp_filter_post_kses() function is added to the 'content_save_pre', |
|
1613 |
* 'excerpt_save_pre', and 'content_filtered_save_pre' hooks. |
|
1614 |
* |
|
1615 |
* @since 2.0.0 |
|
1616 |
*/ |
|
1617 |
function kses_init_filters() { |
|
1618 |
// Normal filtering |
|
1619 |
add_filter('title_save_pre', 'wp_filter_kses'); |
|
1620 |
||
1621 |
// Comment filtering |
|
1622 |
if ( current_user_can( 'unfiltered_html' ) ) |
|
1623 |
add_filter( 'pre_comment_content', 'wp_filter_post_kses' ); |
|
1624 |
else |
|
1625 |
add_filter( 'pre_comment_content', 'wp_filter_kses' ); |
|
1626 |
||
1627 |
// Post filtering |
|
1628 |
add_filter('content_save_pre', 'wp_filter_post_kses'); |
|
1629 |
add_filter('excerpt_save_pre', 'wp_filter_post_kses'); |
|
1630 |
add_filter('content_filtered_save_pre', 'wp_filter_post_kses'); |
|
1631 |
} |
|
1632 |
||
1633 |
/** |
|
1634 |
* Removes all Kses input form content filters. |
|
1635 |
* |
|
1636 |
* A quick procedural method to removing all of the filters that kses uses for |
|
1637 |
* content in WordPress Loop. |
|
1638 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1639 |
* Does not remove the kses_init() function from {@see 'init'} hook (priority is |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1640 |
* default). Also does not remove kses_init() function from {@see 'set_current_user'} |
0 | 1641 |
* hook (priority is also default). |
1642 |
* |
|
1643 |
* @since 2.0.6 |
|
1644 |
*/ |
|
1645 |
function kses_remove_filters() { |
|
1646 |
// Normal filtering |
|
1647 |
remove_filter('title_save_pre', 'wp_filter_kses'); |
|
1648 |
||
1649 |
// Comment filtering |
|
1650 |
remove_filter( 'pre_comment_content', 'wp_filter_post_kses' ); |
|
1651 |
remove_filter( 'pre_comment_content', 'wp_filter_kses' ); |
|
1652 |
||
1653 |
// Post filtering |
|
1654 |
remove_filter('content_save_pre', 'wp_filter_post_kses'); |
|
1655 |
remove_filter('excerpt_save_pre', 'wp_filter_post_kses'); |
|
1656 |
remove_filter('content_filtered_save_pre', 'wp_filter_post_kses'); |
|
1657 |
} |
|
1658 |
||
1659 |
/** |
|
1660 |
* Sets up most of the Kses filters for input form content. |
|
1661 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1662 |
* If you remove the kses_init() function from {@see 'init'} hook and |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1663 |
* {@see 'set_current_user'} (priority is default), then none of the Kses filter hooks |
0 | 1664 |
* will be added. |
1665 |
* |
|
1666 |
* First removes all of the Kses filters in case the current user does not need |
|
1667 |
* to have Kses filter the content. If the user does not have unfiltered_html |
|
1668 |
* capability, then Kses filters are added. |
|
1669 |
* |
|
1670 |
* @since 2.0.0 |
|
1671 |
*/ |
|
1672 |
function kses_init() { |
|
1673 |
kses_remove_filters(); |
|
1674 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1675 |
if ( ! current_user_can( 'unfiltered_html' ) ) { |
0 | 1676 |
kses_init_filters(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1677 |
} |
0 | 1678 |
} |
1679 |
||
1680 |
/** |
|
1681 |
* Inline CSS filter |
|
1682 |
* |
|
1683 |
* @since 2.8.1 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1684 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1685 |
* @param string $css A string of CSS rules. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1686 |
* @param string $deprecated Not used. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1687 |
* @return string Filtered string of CSS rules. |
0 | 1688 |
*/ |
1689 |
function safecss_filter_attr( $css, $deprecated = '' ) { |
|
1690 |
if ( !empty( $deprecated ) ) |
|
1691 |
_deprecated_argument( __FUNCTION__, '2.8.1' ); // Never implemented |
|
1692 |
||
1693 |
$css = wp_kses_no_null($css); |
|
1694 |
$css = str_replace(array("\n","\r","\t"), '', $css); |
|
1695 |
||
5 | 1696 |
if ( preg_match( '%[\\\\(&=}]|/\*%', $css ) ) // remove any inline css containing \ ( & } = or comments |
0 | 1697 |
return ''; |
1698 |
||
1699 |
$css_array = explode( ';', trim( $css ) ); |
|
5 | 1700 |
|
1701 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1702 |
* Filters list of allowed CSS attributes. |
5 | 1703 |
* |
1704 |
* @since 2.8.1 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1705 |
* @since 4.4.0 Added support for `min-height`, `max-height`, `min-width`, and `max-width`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1706 |
* @since 4.6.0 Added support for `list-style-type`. |
5 | 1707 |
* |
1708 |
* @param array $attr List of allowed CSS attributes. |
|
1709 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1710 |
$allowed_attr = apply_filters( 'safe_style_css', array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1711 |
'background', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1712 |
'background-color', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1713 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1714 |
'border', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1715 |
'border-width', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1716 |
'border-color', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1717 |
'border-style', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1718 |
'border-right', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1719 |
'border-right-color', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1720 |
'border-right-style', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1721 |
'border-right-width', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1722 |
'border-bottom', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1723 |
'border-bottom-color', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1724 |
'border-bottom-style', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1725 |
'border-bottom-width', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1726 |
'border-left', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1727 |
'border-left-color', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1728 |
'border-left-style', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1729 |
'border-left-width', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1730 |
'border-top', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1731 |
'border-top-color', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1732 |
'border-top-style', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1733 |
'border-top-width', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1734 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1735 |
'border-spacing', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1736 |
'border-collapse', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1737 |
'caption-side', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1738 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1739 |
'color', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1740 |
'font', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1741 |
'font-family', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1742 |
'font-size', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1743 |
'font-style', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1744 |
'font-variant', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1745 |
'font-weight', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1746 |
'letter-spacing', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1747 |
'line-height', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1748 |
'text-decoration', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1749 |
'text-indent', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1750 |
'text-align', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1751 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1752 |
'height', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1753 |
'min-height', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1754 |
'max-height', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1755 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1756 |
'width', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1757 |
'min-width', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1758 |
'max-width', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1759 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1760 |
'margin', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1761 |
'margin-right', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1762 |
'margin-bottom', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1763 |
'margin-left', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1764 |
'margin-top', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1765 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1766 |
'padding', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1767 |
'padding-right', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1768 |
'padding-bottom', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1769 |
'padding-left', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1770 |
'padding-top', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1771 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1772 |
'clear', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1773 |
'cursor', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1774 |
'direction', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1775 |
'float', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1776 |
'overflow', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1777 |
'vertical-align', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1778 |
'list-style-type', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1779 |
) ); |
0 | 1780 |
|
1781 |
if ( empty($allowed_attr) ) |
|
1782 |
return $css; |
|
1783 |
||
1784 |
$css = ''; |
|
1785 |
foreach ( $css_array as $css_item ) { |
|
1786 |
if ( $css_item == '' ) |
|
1787 |
continue; |
|
1788 |
$css_item = trim( $css_item ); |
|
1789 |
$found = false; |
|
1790 |
if ( strpos( $css_item, ':' ) === false ) { |
|
1791 |
$found = true; |
|
1792 |
} else { |
|
1793 |
$parts = explode( ':', $css_item ); |
|
1794 |
if ( in_array( trim( $parts[0] ), $allowed_attr ) ) |
|
1795 |
$found = true; |
|
1796 |
} |
|
1797 |
if ( $found ) { |
|
1798 |
if( $css != '' ) |
|
1799 |
$css .= ';'; |
|
1800 |
$css .= $css_item; |
|
1801 |
} |
|
1802 |
} |
|
1803 |
||
1804 |
return $css; |
|
1805 |
} |
|
1806 |
||
1807 |
/** |
|
1808 |
* Helper function to add global attributes to a tag in the allowed html list. |
|
1809 |
* |
|
1810 |
* @since 3.5.0 |
|
1811 |
* @access private |
|
1812 |
* |
|
1813 |
* @param array $value An array of attributes. |
|
1814 |
* @return array The array of attributes with global attributes added. |
|
1815 |
*/ |
|
1816 |
function _wp_add_global_attributes( $value ) { |
|
1817 |
$global_attributes = array( |
|
1818 |
'class' => true, |
|
1819 |
'id' => true, |
|
1820 |
'style' => true, |
|
1821 |
'title' => true, |
|
5 | 1822 |
'role' => true, |
0 | 1823 |
); |
1824 |
||
1825 |
if ( true === $value ) |
|
1826 |
$value = array(); |
|
1827 |
||
1828 |
if ( is_array( $value ) ) |
|
1829 |
return array_merge( $value, $global_attributes ); |
|
1830 |
||
1831 |
return $value; |
|
1832 |
} |