]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/kses.php
Wordpress 3.0.5
[autoinstalls/wordpress.git] / wp-includes / kses.php
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  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  or visit
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  * You can override this in a plugin.
35  *
36  * @since 1.2.0
37  */
38 if ( ! defined( 'CUSTOM_TAGS' ) )
39         define( 'CUSTOM_TAGS', false );
40
41 if ( ! CUSTOM_TAGS ) {
42         /**
43          * Kses global for default allowable HTML tags.
44          *
45          * Can be override by using CUSTOM_TAGS constant.
46          *
47          * @global array $allowedposttags
48          * @since 2.0.0
49          */
50         $allowedposttags = array(
51                 'address' => array(),
52                 'a' => array(
53                         'class' => array (),
54                         'href' => array (),
55                         'id' => array (),
56                         'title' => array (),
57                         'rel' => array (),
58                         'rev' => array (),
59                         'name' => array (),
60                         'target' => array()),
61                 'abbr' => array(
62                         'class' => array (),
63                         'title' => array ()),
64                 'acronym' => array(
65                         'title' => array ()),
66                 'article' => array(
67                         'align' => array (),
68                         'class' => array (),
69                         'dir' => array (),
70                         'lang' => array(),
71                         'style' => array (),
72                         'xml:lang' => array(),
73                 ),
74                 'aside' => array(
75                         'align' => array (),
76                         'class' => array (),
77                         'dir' => array (),
78                         'lang' => array(),
79                         'style' => array (),
80                         'xml:lang' => array(),
81                 ),
82                 'b' => array(),
83                 'big' => array(),
84                 'blockquote' => array(
85                         'id' => array (),
86                         'cite' => array (),
87                         'class' => array(),
88                         'lang' => array(),
89                         'xml:lang' => array()),
90                 'br' => array (
91                         'class' => array ()),
92                 'button' => array(
93                         'disabled' => array (),
94                         'name' => array (),
95                         'type' => array (),
96                         'value' => array ()),
97                 'caption' => array(
98                         'align' => array (),
99                         'class' => array ()),
100                 'cite' => array (
101                         'class' => array(),
102                         'dir' => array(),
103                         'lang' => array(),
104                         'title' => array ()),
105                 'code' => array (
106                         'style' => array()),
107                 'col' => array(
108                         'align' => array (),
109                         'char' => array (),
110                         'charoff' => array (),
111                         'span' => array (),
112                         'dir' => array(),
113                         'style' => array (),
114                         'valign' => array (),
115                         'width' => array ()),
116                 'del' => array(
117                         'datetime' => array ()),
118                 'dd' => array(),
119                 'details' => array(
120                         'align' => array (),
121                         'class' => array (),
122                         'dir' => array (),
123                         'lang' => array(),
124                         'open' => array (),
125                         'style' => array (),
126                         'xml:lang' => array(),
127                 ),
128                 'div' => array(
129                         'align' => array (),
130                         'class' => array (),
131                         'dir' => array (),
132                         'lang' => array(),
133                         'style' => array (),
134                         'xml:lang' => array()),
135                 'dl' => array(),
136                 'dt' => array(),
137                 'em' => array(),
138                 'fieldset' => array(),
139                 'figure' => array(
140                         'align' => array (),
141                         'class' => array (),
142                         'dir' => array (),
143                         'lang' => array(),
144                         'style' => array (),
145                         'xml:lang' => array(),
146                 ),
147                 'figcaption' => array(
148                         'align' => array (),
149                         'class' => array (),
150                         'dir' => array (),
151                         'lang' => array(),
152                         'style' => array (),
153                         'xml:lang' => array(),
154                 ),
155                 'font' => array(
156                         'color' => array (),
157                         'face' => array (),
158                         'size' => array ()),
159                 'footer' => array(
160                         'align' => array (),
161                         'class' => array (),
162                         'dir' => array (),
163                         'lang' => array(),
164                         'style' => array (),
165                         'xml:lang' => array(),
166                 ),
167                 'form' => array(
168                         'action' => array (),
169                         'accept' => array (),
170                         'accept-charset' => array (),
171                         'enctype' => array (),
172                         'method' => array (),
173                         'name' => array (),
174                         'target' => array ()),
175                 'h1' => array(
176                         'align' => array (),
177                         'class' => array (),
178                         'id'    => array (),
179                         'style' => array ()),
180                 'h2' => array (
181                         'align' => array (),
182                         'class' => array (),
183                         'id'    => array (),
184                         'style' => array ()),
185                 'h3' => array (
186                         'align' => array (),
187                         'class' => array (),
188                         'id'    => array (),
189                         'style' => array ()),
190                 'h4' => array (
191                         'align' => array (),
192                         'class' => array (),
193                         'id'    => array (),
194                         'style' => array ()),
195                 'h5' => array (
196                         'align' => array (),
197                         'class' => array (),
198                         'id'    => array (),
199                         'style' => array ()),
200                 'h6' => array (
201                         'align' => array (),
202                         'class' => array (),
203                         'id'    => array (),
204                         'style' => array ()),
205                 'header' => array(
206                         'align' => array (),
207                         'class' => array (),
208                         'dir' => array (),
209                         'lang' => array(),
210                         'style' => array (),
211                         'xml:lang' => array(),
212                 ),
213                 'hgroup' => array(
214                         'align' => array (),
215                         'class' => array (),
216                         'dir' => array (),
217                         'lang' => array(),
218                         'style' => array (),
219                         'xml:lang' => array(),
220                 ),
221                 'hr' => array (
222                         'align' => array (),
223                         'class' => array (),
224                         'noshade' => array (),
225                         'size' => array (),
226                         'width' => array ()),
227                 'i' => array(),
228                 'img' => array(
229                         'alt' => array (),
230                         'align' => array (),
231                         'border' => array (),
232                         'class' => array (),
233                         'height' => array (),
234                         'hspace' => array (),
235                         'longdesc' => array (),
236                         'vspace' => array (),
237                         'src' => array (),
238                         'style' => array (),
239                         'width' => array ()),
240                 'ins' => array(
241                         'datetime' => array (),
242                         'cite' => array ()),
243                 'kbd' => array(),
244                 'label' => array(
245                         'for' => array ()),
246                 'legend' => array(
247                         'align' => array ()),
248                 'li' => array (
249                         'align' => array (),
250                         'class' => array ()),
251                 'menu' => array (
252                         'class' => array (),
253                         'style' => array (),
254                         'type' => array ()),
255                 'nav' => array(
256                         'align' => array (),
257                         'class' => array (),
258                         'dir' => array (),
259                         'lang' => array(),
260                         'style' => array (),
261                         'xml:lang' => array(),
262                 ),
263                 'p' => array(
264                         'class' => array (),
265                         'align' => array (),
266                         'dir' => array(),
267                         'lang' => array(),
268                         'style' => array (),
269                         'xml:lang' => array()),
270                 'pre' => array(
271                         'style' => array(),
272                         'width' => array ()),
273                 'q' => array(
274                         'cite' => array ()),
275                 's' => array(),
276                 'span' => array (
277                         'class' => array (),
278                         'dir' => array (),
279                         'align' => array (),
280                         'lang' => array (),
281                         'style' => array (),
282                         'title' => array (),
283                         'xml:lang' => array()),
284                 'section' => array(
285                         'align' => array (),
286                         'class' => array (),
287                         'dir' => array (),
288                         'lang' => array(),
289                         'style' => array (),
290                         'xml:lang' => array(),
291                 ),
292                 'strike' => array(),
293                 'strong' => array(),
294                 'sub' => array(),
295                 'summary' => array(
296                         'align' => array (),
297                         'class' => array (),
298                         'dir' => array (),
299                         'lang' => array(),
300                         'style' => array (),
301                         'xml:lang' => array(),
302                 ),
303                 'sup' => array(),
304                 'table' => array(
305                         'align' => array (),
306                         'bgcolor' => array (),
307                         'border' => array (),
308                         'cellpadding' => array (),
309                         'cellspacing' => array (),
310                         'class' => array (),
311                         'dir' => array(),
312                         'id' => array(),
313                         'rules' => array (),
314                         'style' => array (),
315                         'summary' => array (),
316                         'width' => array ()),
317                 'tbody' => array(
318                         'align' => array (),
319                         'char' => array (),
320                         'charoff' => array (),
321                         'valign' => array ()),
322                 'td' => array(
323                         'abbr' => array (),
324                         'align' => array (),
325                         'axis' => array (),
326                         'bgcolor' => array (),
327                         'char' => array (),
328                         'charoff' => array (),
329                         'class' => array (),
330                         'colspan' => array (),
331                         'dir' => array(),
332                         'headers' => array (),
333                         'height' => array (),
334                         'nowrap' => array (),
335                         'rowspan' => array (),
336                         'scope' => array (),
337                         'style' => array (),
338                         'valign' => array (),
339                         'width' => array ()),
340                 'textarea' => array(
341                         'cols' => array (),
342                         'rows' => array (),
343                         'disabled' => array (),
344                         'name' => array (),
345                         'readonly' => array ()),
346                 'tfoot' => array(
347                         'align' => array (),
348                         'char' => array (),
349                         'class' => array (),
350                         'charoff' => array (),
351                         'valign' => array ()),
352                 'th' => array(
353                         'abbr' => array (),
354                         'align' => array (),
355                         'axis' => array (),
356                         'bgcolor' => array (),
357                         'char' => array (),
358                         'charoff' => array (),
359                         'class' => array (),
360                         'colspan' => array (),
361                         'headers' => array (),
362                         'height' => array (),
363                         'nowrap' => array (),
364                         'rowspan' => array (),
365                         'scope' => array (),
366                         'valign' => array (),
367                         'width' => array ()),
368                 'thead' => array(
369                         'align' => array (),
370                         'char' => array (),
371                         'charoff' => array (),
372                         'class' => array (),
373                         'valign' => array ()),
374                 'title' => array(),
375                 'tr' => array(
376                         'align' => array (),
377                         'bgcolor' => array (),
378                         'char' => array (),
379                         'charoff' => array (),
380                         'class' => array (),
381                         'style' => array (),
382                         'valign' => array ()),
383                 'tt' => array(),
384                 'u' => array(),
385                 'ul' => array (
386                         'class' => array (),
387                         'style' => array (),
388                         'type' => array ()),
389                 'ol' => array (
390                         'class' => array (),
391                         'start' => array (),
392                         'style' => array (),
393                         'type' => array ()),
394                 'var' => array ());
395
396         /**
397          * Kses allowed HTML elements.
398          *
399          * @global array $allowedtags
400          * @since 1.0.0
401          */
402         $allowedtags = array(
403                 'a' => array(
404                         'href' => array (),
405                         'title' => array ()),
406                 'abbr' => array(
407                         'title' => array ()),
408                 'acronym' => array(
409                         'title' => array ()),
410                 'b' => array(),
411                 'blockquote' => array(
412                         'cite' => array ()),
413                 //      'br' => array(),
414                 'cite' => array (),
415                 'code' => array(),
416                 'del' => array(
417                         'datetime' => array ()),
418                 //      'dd' => array(),
419                 //      'dl' => array(),
420                 //      'dt' => array(),
421                 'em' => array (), 'i' => array (),
422                 //      'ins' => array('datetime' => array(), 'cite' => array()),
423                 //      'li' => array(),
424                 //      'ol' => array(),
425                 //      'p' => array(),
426                 'q' => array(
427                         'cite' => array ()),
428                 'strike' => array(),
429                 'strong' => array(),
430                 //      'sub' => array(),
431                 //      'sup' => array(),
432                 //      'u' => array(),
433                 //      'ul' => array(),
434         );
435
436         $allowedentitynames = array(
437                 'nbsp',    'iexcl',  'cent',    'pound',  'curren', 'yen',
438                 'brvbar',  'sect',   'uml',     'copy',   'ordf',   'laquo',
439                 'not',     'shy',    'reg',     'macr',   'deg',    'plusmn',
440                 'acute',   'micro',  'para',    'middot', 'cedil',  'ordm',
441                 'raquo',   'iquest', 'Agrave',  'Aacute', 'Acirc',  'Atilde',
442                 'Auml',    'Aring',  'AElig',   'Ccedil', 'Egrave', 'Eacute',
443                 'Ecirc',   'Euml',   'Igrave',  'Iacute', 'Icirc',  'Iuml',
444                 'ETH',     'Ntilde', 'Ograve',  'Oacute', 'Ocirc',  'Otilde',
445                 'Ouml',    'times',  'Oslash',  'Ugrave', 'Uacute', 'Ucirc',
446                 'Uuml',    'Yacute', 'THORN',   'szlig',  'agrave', 'aacute',
447                 'acirc',   'atilde', 'auml',    'aring',  'aelig',  'ccedil',
448                 'egrave',  'eacute', 'ecirc',   'euml',   'igrave', 'iacute',
449                 'icirc',   'iuml',   'eth',     'ntilde', 'ograve', 'oacute',
450                 'ocirc',   'otilde', 'ouml',    'divide', 'oslash', 'ugrave',
451                 'uacute',  'ucirc',  'uuml',    'yacute', 'thorn',  'yuml',
452                 'quot',    'amp',    'lt',      'gt',     'apos',   'OElig',
453                 'oelig',   'Scaron', 'scaron',  'Yuml',   'circ',   'tilde',
454                 'ensp',    'emsp',   'thinsp',  'zwnj',   'zwj',    'lrm',
455                 'rlm',     'ndash',  'mdash',   'lsquo',  'rsquo',  'sbquo',
456                 'ldquo',   'rdquo',  'bdquo',   'dagger', 'Dagger', 'permil',
457                 'lsaquo',  'rsaquo', 'euro',    'fnof',   'Alpha',  'Beta',
458                 'Gamma',   'Delta',  'Epsilon', 'Zeta',   'Eta',    'Theta',
459                 'Iota',    'Kappa',  'Lambda',  'Mu',     'Nu',     'Xi',
460                 'Omicron', 'Pi',     'Rho',     'Sigma',  'Tau',    'Upsilon',
461                 'Phi',     'Chi',    'Psi',     'Omega',  'alpha',  'beta',
462                 'gamma',   'delta',  'epsilon', 'zeta',   'eta',    'theta',
463                 'iota',    'kappa',  'lambda',  'mu',     'nu',     'xi',
464                 'omicron', 'pi',     'rho',     'sigmaf', 'sigma',  'tau',
465                 'upsilon', 'phi',    'chi',     'psi',    'omega',  'thetasym',
466                 'upsih',   'piv',    'bull',    'hellip', 'prime',  'Prime',
467                 'oline',   'frasl',  'weierp',  'image',  'real',   'trade',
468                 'alefsym', 'larr',   'uarr',    'rarr',   'darr',   'harr',
469                 'crarr',   'lArr',   'uArr',    'rArr',   'dArr',   'hArr',
470                 'forall',  'part',   'exist',   'empty',  'nabla',  'isin',
471                 'notin',   'ni',     'prod',    'sum',    'minus',  'lowast',
472                 'radic',   'prop',   'infin',   'ang',    'and',    'or',
473                 'cap',     'cup',    'int',     'sim',    'cong',   'asymp',
474                 'ne',      'equiv',  'le',      'ge',     'sub',    'sup',
475                 'nsub',    'sube',   'supe',    'oplus',  'otimes', 'perp',
476                 'sdot',    'lceil',  'rceil',   'lfloor', 'rfloor', 'lang',
477                 'rang',    'loz',    'spades',  'clubs',  'hearts', 'diams',
478         );
479 }
480
481 /**
482  * Filters content and keeps only allowable HTML elements.
483  *
484  * This function makes sure that only the allowed HTML element names, attribute
485  * names and attribute values plus only sane HTML entities will occur in
486  * $string. You have to remove any slashes from PHP's magic quotes before you
487  * call this function.
488  *
489  * The default allowed protocols are 'http', 'https', 'ftp', 'mailto', 'news',
490  * 'irc', 'gopher', 'nntp', 'feed', 'telnet, 'mms', 'rtsp' and 'svn'. This
491  * covers all common link protocols, except for 'javascript' which should not
492  * be allowed for untrusted users.
493  *
494  * @since 1.0.0
495  *
496  * @param string $string Content to filter through kses
497  * @param array $allowed_html List of allowed HTML elements
498  * @param array $allowed_protocols Optional. Allowed protocol in links.
499  * @return string Filtered content with only allowed HTML elements
500  */
501 function wp_kses($string, $allowed_html, $allowed_protocols = array ()) {
502         $allowed_protocols = wp_parse_args( $allowed_protocols, apply_filters('kses_allowed_protocols', array ('http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn') ));
503         $string = wp_kses_no_null($string);
504         $string = wp_kses_js_entities($string);
505         $string = wp_kses_normalize_entities($string);
506         $allowed_html_fixed = wp_kses_array_lc($allowed_html);
507         $string = wp_kses_hook($string, $allowed_html_fixed, $allowed_protocols); // WP changed the order of these funcs and added args to wp_kses_hook
508         return wp_kses_split($string, $allowed_html_fixed, $allowed_protocols);
509 }
510
511 /**
512  * You add any kses hooks here.
513  *
514  * There is currently only one kses WordPress hook and it is called here. All
515  * parameters are passed to the hooks and expected to recieve a string.
516  *
517  * @since 1.0.0
518  *
519  * @param string $string Content to filter through kses
520  * @param array $allowed_html List of allowed HTML elements
521  * @param array $allowed_protocols Allowed protocol in links
522  * @return string Filtered content through 'pre_kses' hook
523  */
524 function wp_kses_hook($string, $allowed_html, $allowed_protocols) {
525         $string = apply_filters('pre_kses', $string, $allowed_html, $allowed_protocols);
526         return $string;
527 }
528
529 /**
530  * This function returns kses' version number.
531  *
532  * @since 1.0.0
533  *
534  * @return string KSES Version Number
535  */
536 function wp_kses_version() {
537         return '0.2.2';
538 }
539
540 /**
541  * Searches for HTML tags, no matter how malformed.
542  *
543  * It also matches stray ">" characters.
544  *
545  * @since 1.0.0
546  *
547  * @param string $string Content to filter
548  * @param array $allowed_html Allowed HTML elements
549  * @param array $allowed_protocols Allowed protocols to keep
550  * @return string Content with fixed HTML tags
551  */
552 function wp_kses_split($string, $allowed_html, $allowed_protocols) {
553         global $pass_allowed_html, $pass_allowed_protocols;
554         $pass_allowed_html = $allowed_html;
555         $pass_allowed_protocols = $allowed_protocols;
556         return preg_replace_callback('%((<!--.*?(-->|$))|(<[^>]*(>|$)|>))%',
557                 create_function('$match', 'global $pass_allowed_html, $pass_allowed_protocols; return wp_kses_split2($match[1], $pass_allowed_html, $pass_allowed_protocols);'), $string);
558 }
559
560 /**
561  * Callback for wp_kses_split for fixing malformed HTML tags.
562  *
563  * This function does a lot of work. It rejects some very malformed things like
564  * <:::>. It returns an empty string, if the element isn't allowed (look ma, no
565  * strip_tags()!). Otherwise it splits the tag into an element and an attribute
566  * list.
567  *
568  * After the tag is split into an element and an attribute list, it is run
569  * through another filter which will remove illegal attributes and once that is
570  * completed, will be returned.
571  *
572  * @access private
573  * @since 1.0.0
574  * @uses wp_kses_attr()
575  *
576  * @param string $string Content to filter
577  * @param array $allowed_html Allowed HTML elements
578  * @param array $allowed_protocols Allowed protocols to keep
579  * @return string Fixed HTML element
580  */
581 function wp_kses_split2($string, $allowed_html, $allowed_protocols) {
582         $string = wp_kses_stripslashes($string);
583
584         if (substr($string, 0, 1) != '<')
585                 return '&gt;';
586         # It matched a ">" character
587
588         if (preg_match('%^<!--(.*?)(-->)?$%', $string, $matches)) {
589                 $string = str_replace(array('<!--', '-->'), '', $matches[1]);
590                 while ( $string != $newstring = wp_kses($string, $allowed_html, $allowed_protocols) )
591                         $string = $newstring;
592                 if ( $string == '' )
593                         return '';
594                 // prevent multiple dashes in comments
595                 $string = preg_replace('/--+/', '-', $string);
596                 // prevent three dashes closing a comment
597                 $string = preg_replace('/-$/', '', $string);
598                 return "<!--{$string}-->";
599         }
600         # Allow HTML comments
601
602         if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9]+)([^>]*)>?$%', $string, $matches))
603                 return '';
604         # It's seriously malformed
605
606         $slash = trim($matches[1]);
607         $elem = $matches[2];
608         $attrlist = $matches[3];
609
610         if (!@isset($allowed_html[strtolower($elem)]))
611                 return '';
612         # They are using a not allowed HTML element
613
614         if ($slash != '')
615                 return "<$slash$elem>";
616         # No attributes are allowed for closing elements
617
618         return wp_kses_attr("$slash$elem", $attrlist, $allowed_html, $allowed_protocols);
619 }
620
621 /**
622  * Removes all attributes, if none are allowed for this element.
623  *
624  * If some are allowed it calls wp_kses_hair() to split them further, and then
625  * it builds up new HTML code from the data that kses_hair() returns. It also
626  * removes "<" and ">" characters, if there are any left. One more thing it does
627  * is to check if the tag has a closing XHTML slash, and if it does, it puts one
628  * in the returned code as well.
629  *
630  * @since 1.0.0
631  *
632  * @param string $element HTML element/tag
633  * @param string $attr HTML attributes from HTML element to closing HTML element tag
634  * @param array $allowed_html Allowed HTML elements
635  * @param array $allowed_protocols Allowed protocols to keep
636  * @return string Sanitized HTML element
637  */
638 function wp_kses_attr($element, $attr, $allowed_html, $allowed_protocols) {
639         # Is there a closing XHTML slash at the end of the attributes?
640
641         $xhtml_slash = '';
642         if (preg_match('%\s*/\s*$%', $attr))
643                 $xhtml_slash = ' /';
644
645         # Are any attributes allowed at all for this element?
646
647         if (@ count($allowed_html[strtolower($element)]) == 0)
648                 return "<$element$xhtml_slash>";
649
650         # Split it
651
652         $attrarr = wp_kses_hair($attr, $allowed_protocols);
653
654         # Go through $attrarr, and save the allowed attributes for this element
655         # in $attr2
656
657         $attr2 = '';
658
659         foreach ($attrarr as $arreach) {
660                 if (!@ isset ($allowed_html[strtolower($element)][strtolower($arreach['name'])]))
661                         continue; # the attribute is not allowed
662
663                 $current = $allowed_html[strtolower($element)][strtolower($arreach['name'])];
664                 if ($current == '')
665                         continue; # the attribute is not allowed
666
667                 if (!is_array($current))
668                         $attr2 .= ' '.$arreach['whole'];
669                 # there are no checks
670
671                 else {
672                         # there are some checks
673                         $ok = true;
674                         foreach ($current as $currkey => $currval)
675                                 if (!wp_kses_check_attr_val($arreach['value'], $arreach['vless'], $currkey, $currval)) {
676                                         $ok = false;
677                                         break;
678                                 }
679
680                         if ( strtolower($arreach['name']) == 'style' ) {
681                                 $orig_value = $arreach['value'];
682
683                                 $value = safecss_filter_attr($orig_value);
684
685                                 if ( empty($value) )
686                                         continue;
687
688                                 $arreach['value'] = $value;
689
690                                 $arreach['whole'] = str_replace($orig_value, $value, $arreach['whole']);
691                         }
692
693                         if ($ok)
694                                 $attr2 .= ' '.$arreach['whole']; # it passed them
695                 } # if !is_array($current)
696         } # foreach
697
698         # Remove any "<" or ">" characters
699
700         $attr2 = preg_replace('/[<>]/', '', $attr2);
701
702         return "<$element$attr2$xhtml_slash>";
703 }
704
705 /**
706  * Builds an attribute list from string containing attributes.
707  *
708  * This function does a lot of work. It parses an attribute list into an array
709  * with attribute data, and tries to do the right thing even if it gets weird
710  * input. It will add quotes around attribute values that don't have any quotes
711  * or apostrophes around them, to make it easier to produce HTML code that will
712  * conform to W3C's HTML specification. It will also remove bad URL protocols
713  * from attribute values.  It also reduces duplicate attributes by using the
714  * attribute defined first (foo='bar' foo='baz' will result in foo='bar').
715  *
716  * @since 1.0.0
717  *
718  * @param string $attr Attribute list from HTML element to closing HTML element tag
719  * @param array $allowed_protocols Allowed protocols to keep
720  * @return array List of attributes after parsing
721  */
722 function wp_kses_hair($attr, $allowed_protocols) {
723         $attrarr = array ();
724         $mode = 0;
725         $attrname = '';
726         $uris = array('xmlns', 'profile', 'href', 'src', 'cite', 'classid', 'codebase', 'data', 'usemap', 'longdesc', 'action');
727
728         # Loop through the whole attribute list
729
730         while (strlen($attr) != 0) {
731                 $working = 0; # Was the last operation successful?
732
733                 switch ($mode) {
734                         case 0 : # attribute name, href for instance
735
736                                 if (preg_match('/^([-a-zA-Z]+)/', $attr, $match)) {
737                                         $attrname = $match[1];
738                                         $working = $mode = 1;
739                                         $attr = preg_replace('/^[-a-zA-Z]+/', '', $attr);
740                                 }
741
742                                 break;
743
744                         case 1 : # equals sign or valueless ("selected")
745
746                                 if (preg_match('/^\s*=\s*/', $attr)) # equals sign
747                                         {
748                                         $working = 1;
749                                         $mode = 2;
750                                         $attr = preg_replace('/^\s*=\s*/', '', $attr);
751                                         break;
752                                 }
753
754                                 if (preg_match('/^\s+/', $attr)) # valueless
755                                         {
756                                         $working = 1;
757                                         $mode = 0;
758                                         if(FALSE === array_key_exists($attrname, $attrarr)) {
759                                                 $attrarr[$attrname] = array ('name' => $attrname, 'value' => '', 'whole' => $attrname, 'vless' => 'y');
760                                         }
761                                         $attr = preg_replace('/^\s+/', '', $attr);
762                                 }
763
764                                 break;
765
766                         case 2 : # attribute value, a URL after href= for instance
767
768                                 if (preg_match('%^"([^"]*)"(\s+|/?$)%', $attr, $match))
769                                         # "value"
770                                         {
771                                         $thisval = $match[1];
772                                         if ( in_array(strtolower($attrname), $uris) )
773                                                 $thisval = wp_kses_bad_protocol($thisval, $allowed_protocols);
774
775                                         if(FALSE === array_key_exists($attrname, $attrarr)) {
776                                                 $attrarr[$attrname] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname=\"$thisval\"", 'vless' => 'n');
777                                         }
778                                         $working = 1;
779                                         $mode = 0;
780                                         $attr = preg_replace('/^"[^"]*"(\s+|$)/', '', $attr);
781                                         break;
782                                 }
783
784                                 if (preg_match("%^'([^']*)'(\s+|/?$)%", $attr, $match))
785                                         # 'value'
786                                         {
787                                         $thisval = $match[1];
788                                         if ( in_array(strtolower($attrname), $uris) )
789                                                 $thisval = wp_kses_bad_protocol($thisval, $allowed_protocols);
790
791                                         if(FALSE === array_key_exists($attrname, $attrarr)) {
792                                                 $attrarr[$attrname] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname='$thisval'", 'vless' => 'n');
793                                         }
794                                         $working = 1;
795                                         $mode = 0;
796                                         $attr = preg_replace("/^'[^']*'(\s+|$)/", '', $attr);
797                                         break;
798                                 }
799
800                                 if (preg_match("%^([^\s\"']+)(\s+|/?$)%", $attr, $match))
801                                         # value
802                                         {
803                                         $thisval = $match[1];
804                                         if ( in_array(strtolower($attrname), $uris) )
805                                                 $thisval = wp_kses_bad_protocol($thisval, $allowed_protocols);
806
807                                         if(FALSE === array_key_exists($attrname, $attrarr)) {
808                                                 $attrarr[$attrname] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname=\"$thisval\"", 'vless' => 'n');
809                                         }
810                                         # We add quotes to conform to W3C's HTML spec.
811                                         $working = 1;
812                                         $mode = 0;
813                                         $attr = preg_replace("%^[^\s\"']+(\s+|$)%", '', $attr);
814                                 }
815
816                                 break;
817                 } # switch
818
819                 if ($working == 0) # not well formed, remove and try again
820                 {
821                         $attr = wp_kses_html_error($attr);
822                         $mode = 0;
823                 }
824         } # while
825
826         if ($mode == 1 && FALSE === array_key_exists($attrname, $attrarr))
827                 # special case, for when the attribute list ends with a valueless
828                 # attribute like "selected"
829                 $attrarr[$attrname] = array ('name' => $attrname, 'value' => '', 'whole' => $attrname, 'vless' => 'y');
830
831         return $attrarr;
832 }
833
834 /**
835  * Performs different checks for attribute values.
836  *
837  * The currently implemented checks are "maxlen", "minlen", "maxval", "minval"
838  * and "valueless" with even more checks to come soon.
839  *
840  * @since 1.0.0
841  *
842  * @param string $value Attribute value
843  * @param string $vless Whether the value is valueless. Use 'y' or 'n'
844  * @param string $checkname What $checkvalue is checking for.
845  * @param mixed $checkvalue What constraint the value should pass
846  * @return bool Whether check passes
847  */
848 function wp_kses_check_attr_val($value, $vless, $checkname, $checkvalue) {
849         $ok = true;
850
851         switch (strtolower($checkname)) {
852                 case 'maxlen' :
853                         # The maxlen check makes sure that the attribute value has a length not
854                         # greater than the given value. This can be used to avoid Buffer Overflows
855                         # in WWW clients and various Internet servers.
856
857                         if (strlen($value) > $checkvalue)
858                                 $ok = false;
859                         break;
860
861                 case 'minlen' :
862                         # The minlen check makes sure that the attribute value has a length not
863                         # smaller than the given value.
864
865                         if (strlen($value) < $checkvalue)
866                                 $ok = false;
867                         break;
868
869                 case 'maxval' :
870                         # The maxval check does two things: it checks that the attribute value is
871                         # an integer from 0 and up, without an excessive amount of zeroes or
872                         # whitespace (to avoid Buffer Overflows). It also checks that the attribute
873                         # value is not greater than the given value.
874                         # This check can be used to avoid Denial of Service attacks.
875
876                         if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value))
877                                 $ok = false;
878                         if ($value > $checkvalue)
879                                 $ok = false;
880                         break;
881
882                 case 'minval' :
883                         # The minval check checks that the attribute value is a positive integer,
884                         # and that it is not smaller than the given value.
885
886                         if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value))
887                                 $ok = false;
888                         if ($value < $checkvalue)
889                                 $ok = false;
890                         break;
891
892                 case 'valueless' :
893                         # The valueless check checks if the attribute has a value
894                         # (like <a href="blah">) or not (<option selected>). If the given value
895                         # is a "y" or a "Y", the attribute must not have a value.
896                         # If the given value is an "n" or an "N", the attribute must have one.
897
898                         if (strtolower($checkvalue) != $vless)
899                                 $ok = false;
900                         break;
901         } # switch
902
903         return $ok;
904 }
905
906 /**
907  * Sanitize string from bad protocols.
908  *
909  * This function removes all non-allowed protocols from the beginning of
910  * $string. It ignores whitespace and the case of the letters, and it does
911  * understand HTML entities. It does its work in a while loop, so it won't be
912  * fooled by a string like "javascript:javascript:alert(57)".
913  *
914  * @since 1.0.0
915  *
916  * @param string $string Content to filter bad protocols from
917  * @param array $allowed_protocols Allowed protocols to keep
918  * @return string Filtered content
919  */
920 function wp_kses_bad_protocol($string, $allowed_protocols) {
921         $string = wp_kses_no_null($string);
922         $string2 = $string.'a';
923
924         while ($string != $string2) {
925                 $string2 = $string;
926                 $string = wp_kses_bad_protocol_once($string, $allowed_protocols);
927         } # while
928
929         return $string;
930 }
931
932 /**
933  * Removes any NULL characters in $string.
934  *
935  * @since 1.0.0
936  *
937  * @param string $string
938  * @return string
939  */
940 function wp_kses_no_null($string) {
941         $string = preg_replace('/\0+/', '', $string);
942         $string = preg_replace('/(\\\\0)+/', '', $string);
943
944         return $string;
945 }
946
947 /**
948  * Strips slashes from in front of quotes.
949  *
950  * This function changes the character sequence  \"  to just  ". It leaves all
951  * other slashes alone. It's really weird, but the quoting from
952  * preg_replace(//e) seems to require this.
953  *
954  * @since 1.0.0
955  *
956  * @param string $string String to strip slashes
957  * @return string Fixed strings with quoted slashes
958  */
959 function wp_kses_stripslashes($string) {
960         return preg_replace('%\\\\"%', '"', $string);
961 }
962
963 /**
964  * Goes through an array and changes the keys to all lower case.
965  *
966  * @since 1.0.0
967  *
968  * @param array $inarray Unfiltered array
969  * @return array Fixed array with all lowercase keys
970  */
971 function wp_kses_array_lc($inarray) {
972         $outarray = array ();
973
974         foreach ( (array) $inarray as $inkey => $inval) {
975                 $outkey = strtolower($inkey);
976                 $outarray[$outkey] = array ();
977
978                 foreach ( (array) $inval as $inkey2 => $inval2) {
979                         $outkey2 = strtolower($inkey2);
980                         $outarray[$outkey][$outkey2] = $inval2;
981                 } # foreach $inval
982         } # foreach $inarray
983
984         return $outarray;
985 }
986
987 /**
988  * Removes the HTML JavaScript entities found in early versions of Netscape 4.
989  *
990  * @since 1.0.0
991  *
992  * @param string $string
993  * @return string
994  */
995 function wp_kses_js_entities($string) {
996         return preg_replace('%&\s*\{[^}]*(\}\s*;?|$)%', '', $string);
997 }
998
999 /**
1000  * Handles parsing errors in wp_kses_hair().
1001  *
1002  * The general plan is to remove everything to and including some whitespace,
1003  * but it deals with quotes and apostrophes as well.
1004  *
1005  * @since 1.0.0
1006  *
1007  * @param string $string
1008  * @return string
1009  */
1010 function wp_kses_html_error($string) {
1011         return preg_replace('/^("[^"]*("|$)|\'[^\']*(\'|$)|\S)*\s*/', '', $string);
1012 }
1013
1014 /**
1015  * Sanitizes content from bad protocols and other characters.
1016  *
1017  * This function searches for URL protocols at the beginning of $string, while
1018  * handling whitespace and HTML entities.
1019  *
1020  * @since 1.0.0
1021  *
1022  * @param string $string Content to check for bad protocols
1023  * @param string $allowed_protocols Allowed protocols
1024  * @return string Sanitized content
1025  */
1026 function wp_kses_bad_protocol_once($string, $allowed_protocols) {
1027         $string2 = preg_split( '/:|&#0*58;|&#x0*3a;/i', $string, 2 );
1028         if ( isset($string2[1]) && ! preg_match('%/\?%', $string2[0]) )
1029                 $string = wp_kses_bad_protocol_once2( $string2[0], $allowed_protocols ) . trim( $string2[1] );
1030
1031         return $string;
1032 }
1033
1034 /**
1035  * Callback for wp_kses_bad_protocol_once() regular expression.
1036  *
1037  * This function processes URL protocols, checks to see if they're in the
1038  * white-list or not, and returns different data depending on the answer.
1039  *
1040  * @access private
1041  * @since 1.0.0
1042  *
1043  * @param string $string URI scheme to check against the whitelist
1044  * @param string $allowed_protocols Allowed protocols
1045  * @return string Sanitized content
1046  */
1047 function wp_kses_bad_protocol_once2( $string, $allowed_protocols ) {
1048         $string2 = wp_kses_decode_entities($string);
1049         $string2 = preg_replace('/\s/', '', $string2);
1050         $string2 = wp_kses_no_null($string2);
1051         $string2 = strtolower($string2);
1052
1053         $allowed = false;
1054         foreach ( (array) $allowed_protocols as $one_protocol )
1055                 if ( strtolower($one_protocol) == $string2 ) {
1056                         $allowed = true;
1057                         break;
1058                 }
1059
1060         if ($allowed)
1061                 return "$string2:";
1062         else
1063                 return '';
1064 }
1065
1066 /**
1067  * Converts and fixes HTML entities.
1068  *
1069  * This function normalizes HTML entities. It will convert "AT&T" to the correct
1070  * "AT&amp;T", "&#00058;" to "&#58;", "&#XYZZY;" to "&amp;#XYZZY;" and so on.
1071  *
1072  * @since 1.0.0
1073  *
1074  * @param string $string Content to normalize entities
1075  * @return string Content with normalized entities
1076  */
1077 function wp_kses_normalize_entities($string) {
1078         # Disarm all entities by converting & to &amp;
1079
1080         $string = str_replace('&', '&amp;', $string);
1081
1082         # Change back the allowed entities in our entity whitelist
1083
1084         $string = preg_replace_callback('/&amp;([A-Za-z]{2,8});/', 'wp_kses_named_entities', $string);
1085         $string = preg_replace_callback('/&amp;#(0*[0-9]{1,7});/', 'wp_kses_normalize_entities2', $string);
1086         $string = preg_replace_callback('/&amp;#[Xx](0*[0-9A-Fa-f]{1,6});/', 'wp_kses_normalize_entities3', $string);
1087
1088         return $string;
1089 }
1090
1091 /**
1092  * Callback for wp_kses_normalize_entities() regular expression.
1093  *
1094  * This function only accepts valid named entity references, which are finite,
1095  * case-sensitive, and highly scrutinized by HTML and XML validators.
1096  *
1097  * @since 3.0.0
1098  *
1099  * @param array $matches preg_replace_callback() matches array
1100  * @return string Correctly encoded entity
1101  */
1102 function wp_kses_named_entities($matches) {
1103         global $allowedentitynames;
1104
1105         if ( empty($matches[1]) )
1106                 return '';
1107
1108         $i = $matches[1];
1109         return ( ( ! in_array($i, $allowedentitynames) ) ? "&amp;$i;" : "&$i;" );
1110 }
1111
1112 /**
1113  * Callback for wp_kses_normalize_entities() regular expression.
1114  *
1115  * This function helps wp_kses_normalize_entities() to only accept 16 bit values
1116  * and nothing more for &#number; entities.
1117  *
1118  * @access private
1119  * @since 1.0.0
1120  *
1121  * @param array $matches preg_replace_callback() matches array
1122  * @return string Correctly encoded entity
1123  */
1124 function wp_kses_normalize_entities2($matches) {
1125         if ( empty($matches[1]) )
1126                 return '';
1127
1128         $i = $matches[1];
1129         if (valid_unicode($i)) {
1130                 $i = str_pad(ltrim($i,'0'), 3, '0', STR_PAD_LEFT);
1131                 $i = "&#$i;";
1132         } else {
1133                 $i = "&amp;#$i;";
1134         }
1135
1136         return $i;
1137 }
1138
1139 /**
1140  * Callback for wp_kses_normalize_entities() for regular expression.
1141  *
1142  * This function helps wp_kses_normalize_entities() to only accept valid Unicode
1143  * numeric entities in hex form.
1144  *
1145  * @access private
1146  *
1147  * @param array $matches preg_replace_callback() matches array
1148  * @return string Correctly encoded entity
1149  */
1150 function wp_kses_normalize_entities3($matches) {
1151         if ( empty($matches[1]) )
1152                 return '';
1153
1154         $hexchars = $matches[1];
1155         return ( ( ! valid_unicode(hexdec($hexchars)) ) ? "&amp;#x$hexchars;" : '&#x'.ltrim($hexchars,'0').';' );
1156 }
1157
1158 /**
1159  * Helper function to determine if a Unicode value is valid.
1160  *
1161  * @param int $i Unicode value
1162  * @return bool true if the value was a valid Unicode number
1163  */
1164 function valid_unicode($i) {
1165         return ( $i == 0x9 || $i == 0xa || $i == 0xd ||
1166                         ($i >= 0x20 && $i <= 0xd7ff) ||
1167                         ($i >= 0xe000 && $i <= 0xfffd) ||
1168                         ($i >= 0x10000 && $i <= 0x10ffff) );
1169 }
1170
1171 /**
1172  * Convert all entities to their character counterparts.
1173  *
1174  * This function decodes numeric HTML entities (&#65; and &#x41;). It doesn't do
1175  * anything with other entities like &auml;, but we don't need them in the URL
1176  * protocol whitelisting system anyway.
1177  *
1178  * @since 1.0.0
1179  *
1180  * @param string $string Content to change entities
1181  * @return string Content after decoded entities
1182  */
1183 function wp_kses_decode_entities($string) {
1184         $string = preg_replace_callback('/&#([0-9]+);/', '_wp_kses_decode_entities_chr', $string);
1185         $string = preg_replace_callback('/&#[Xx]([0-9A-Fa-f]+);/', '_wp_kses_decode_entities_chr_hexdec', $string);
1186
1187         return $string;
1188 }
1189
1190 /**
1191  * Regex callback for wp_kses_decode_entities()
1192  *
1193  * @param array $match preg match
1194  * @return string
1195  */
1196 function _wp_kses_decode_entities_chr( $match ) {
1197         return chr( $match[1] );
1198 }
1199
1200 /**
1201  * Regex callback for wp_kses_decode_entities()
1202  *
1203  * @param array $match preg match
1204  * @return string
1205  */
1206 function _wp_kses_decode_entities_chr_hexdec( $match ) {
1207         return chr( hexdec( $match[1] ) );
1208 }
1209
1210 /**
1211  * Sanitize content with allowed HTML Kses rules.
1212  *
1213  * @since 1.0.0
1214  * @uses $allowedtags
1215  *
1216  * @param string $data Content to filter, expected to be escaped with slashes
1217  * @return string Filtered content
1218  */
1219 function wp_filter_kses($data) {
1220         global $allowedtags;
1221         return addslashes( wp_kses(stripslashes( $data ), $allowedtags) );
1222 }
1223
1224 /**
1225  * Sanitize content with allowed HTML Kses rules.
1226  *
1227  * @since 2.9.0
1228  * @uses $allowedtags
1229  *
1230  * @param string $data Content to filter, expected to not be escaped
1231  * @return string Filtered content
1232  */
1233 function wp_kses_data($data) {
1234         global $allowedtags;
1235         return wp_kses( $data , $allowedtags );
1236 }
1237
1238 /**
1239  * Sanitize content for allowed HTML tags for post content.
1240  *
1241  * Post content refers to the page contents of the 'post' type and not $_POST
1242  * data from forms.
1243  *
1244  * @since 2.0.0
1245  * @uses $allowedposttags
1246  *
1247  * @param string $data Post content to filter, expected to be escaped with slashes
1248  * @return string Filtered post content with allowed HTML tags and attributes intact.
1249  */
1250 function wp_filter_post_kses($data) {
1251         global $allowedposttags;
1252         return addslashes ( wp_kses(stripslashes( $data ), $allowedposttags) );
1253 }
1254
1255 /**
1256  * Sanitize content for allowed HTML tags for post content.
1257  *
1258  * Post content refers to the page contents of the 'post' type and not $_POST
1259  * data from forms.
1260  *
1261  * @since 2.9.0
1262  * @uses $allowedposttags
1263  *
1264  * @param string $data Post content to filter
1265  * @return string Filtered post content with allowed HTML tags and attributes intact.
1266  */
1267 function wp_kses_post($data) {
1268         global $allowedposttags;
1269         return wp_kses( $data , $allowedposttags );
1270 }
1271
1272 /**
1273  * Strips all of the HTML in the content.
1274  *
1275  * @since 2.1.0
1276  *
1277  * @param string $data Content to strip all HTML from
1278  * @return string Filtered content without any HTML
1279  */
1280 function wp_filter_nohtml_kses($data) {
1281         return addslashes ( wp_kses(stripslashes( $data ), array()) );
1282 }
1283
1284 /**
1285  * Adds all Kses input form content filters.
1286  *
1287  * All hooks have default priority. The wp_filter_kses() function is added to
1288  * the 'pre_comment_content' and 'title_save_pre' hooks.
1289  *
1290  * The wp_filter_post_kses() function is added to the 'content_save_pre',
1291  * 'excerpt_save_pre', and 'content_filtered_save_pre' hooks.
1292  *
1293  * @since 2.0.0
1294  * @uses add_filter() See description for what functions are added to what hooks.
1295  */
1296 function kses_init_filters() {
1297         // Normal filtering.
1298         add_filter('pre_comment_content', 'wp_filter_kses');
1299         add_filter('title_save_pre', 'wp_filter_kses');
1300
1301         // Post filtering
1302         add_filter('content_save_pre', 'wp_filter_post_kses');
1303         add_filter('excerpt_save_pre', 'wp_filter_post_kses');
1304         add_filter('content_filtered_save_pre', 'wp_filter_post_kses');
1305 }
1306
1307 /**
1308  * Removes all Kses input form content filters.
1309  *
1310  * A quick procedural method to removing all of the filters that kses uses for
1311  * content in WordPress Loop.
1312  *
1313  * Does not remove the kses_init() function from 'init' hook (priority is
1314  * default). Also does not remove kses_init() function from 'set_current_user'
1315  * hook (priority is also default).
1316  *
1317  * @since 2.0.6
1318  */
1319 function kses_remove_filters() {
1320         // Normal filtering.
1321         remove_filter('pre_comment_content', 'wp_filter_kses');
1322         remove_filter('title_save_pre', 'wp_filter_kses');
1323
1324         // Post filtering
1325         remove_filter('content_save_pre', 'wp_filter_post_kses');
1326         remove_filter('excerpt_save_pre', 'wp_filter_post_kses');
1327         remove_filter('content_filtered_save_pre', 'wp_filter_post_kses');
1328 }
1329
1330 /**
1331  * Sets up most of the Kses filters for input form content.
1332  *
1333  * If you remove the kses_init() function from 'init' hook and
1334  * 'set_current_user' (priority is default), then none of the Kses filter hooks
1335  * will be added.
1336  *
1337  * First removes all of the Kses filters in case the current user does not need
1338  * to have Kses filter the content. If the user does not have unfiltered html
1339  * capability, then Kses filters are added.
1340  *
1341  * @uses kses_remove_filters() Removes the Kses filters
1342  * @uses kses_init_filters() Adds the Kses filters back if the user
1343  *              does not have unfiltered HTML capability.
1344  * @since 2.0.0
1345  */
1346 function kses_init() {
1347         kses_remove_filters();
1348
1349         if (current_user_can('unfiltered_html') == false)
1350                 kses_init_filters();
1351 }
1352
1353 add_action('init', 'kses_init');
1354 add_action('set_current_user', 'kses_init');
1355
1356 /**
1357  * Inline CSS filter
1358  *
1359  * @since 2.8.1
1360  */
1361 function safecss_filter_attr( $css, $deprecated = '' ) {
1362         if ( !empty( $deprecated ) )
1363                 _deprecated_argument( __FUNCTION__, '2.8.1' ); // Never implemented
1364
1365         $css = wp_kses_no_null($css);
1366         $css = str_replace(array("\n","\r","\t"), '', $css);
1367
1368         if ( preg_match( '%[\\(&=}]|/\*%', $css ) ) // remove any inline css containing \ ( & } = or comments
1369                 return '';
1370
1371         $css_array = explode( ';', trim( $css ) );
1372         $allowed_attr = apply_filters( 'safe_style_css', array( 'text-align', 'margin', 'color', 'float',
1373         'border', 'background', 'background-color', 'border-bottom', 'border-bottom-color',
1374         'border-bottom-style', 'border-bottom-width', 'border-collapse', 'border-color', 'border-left',
1375         'border-left-color', 'border-left-style', 'border-left-width', 'border-right', 'border-right-color',
1376         'border-right-style', 'border-right-width', 'border-spacing', 'border-style', 'border-top',
1377         'border-top-color', 'border-top-style', 'border-top-width', 'border-width', 'caption-side',
1378         'clear', 'cursor', 'direction', 'font', 'font-family', 'font-size', 'font-style',
1379         'font-variant', 'font-weight', 'height', 'letter-spacing', 'line-height', 'margin-bottom',
1380         'margin-left', 'margin-right', 'margin-top', 'overflow', 'padding', 'padding-bottom',
1381         'padding-left', 'padding-right', 'padding-top', 'text-decoration', 'text-indent', 'vertical-align',
1382         'width' ) );
1383
1384         if ( empty($allowed_attr) )
1385                 return $css;
1386
1387         $css = '';
1388         foreach ( $css_array as $css_item ) {
1389                 if ( $css_item == '' )
1390                         continue;
1391                 $css_item = trim( $css_item );
1392                 $found = false;
1393                 if ( strpos( $css_item, ':' ) === false ) {
1394                         $found = true;
1395                 } else {
1396                         $parts = split( ':', $css_item );
1397                         if ( in_array( trim( $parts[0] ), $allowed_attr ) )
1398                                 $found = true;
1399                 }
1400                 if ( $found ) {
1401                         if( $css != '' )
1402                                 $css .= ';';
1403                         $css .= $css_item;
1404                 }
1405         }
1406
1407         return $css;
1408 }