-
+ AD0707F4063782A4AD2492D7B6E85AF27FBD9AC946B7F18071F0B88A490A0A33FE2E67BCFD774D39B7A79B93B044A4D005AE063BE1558BA2F3DA3A97C96C1218mp-wp/wp-includes/kses.php(0 . 0)(1 . 1128)
133414 <?php
133415 /**
133416 * HTML/XHTML filter that only allows some elements and attributes
133417 *
133418 * Added wp_ prefix to avoid conflicts with existing kses users
133419 *
133420 * @version 0.2.2
133421 * @copyright (C) 2002, 2003, 2005
133422 * @author Ulf Harnhammar <metaur@users.sourceforge.net>
133423 *
133424 * @package External
133425 * @subpackage KSES
133426 *
133427 * @internal
133428 * *** CONTACT INFORMATION ***
133429 * E-mail: metaur at users dot sourceforge dot net
133430 * Web page: http://sourceforge.net/projects/kses
133431 * Paper mail: Ulf Harnhammar
133432 * Ymergatan 17 C
133433 * 753 25 Uppsala
133434 * SWEDEN
133435 *
133436 * [kses strips evil scripts!]
133437 */
133438
133439 /**
133440 * You can override this in your my-hacks.php file You can also override this
133441 * in a plugin file. The my-hacks.php is deprecated in its usage.
133442 *
133443 * @since 1.2.0
133444 */
133445 if (!defined('CUSTOM_TAGS'))
133446 define('CUSTOM_TAGS', false);
133447
133448 if (!CUSTOM_TAGS) {
133449 /**
133450 * Kses global for default allowable HTML tags.
133451 *
133452 * Can be override by using CUSTOM_TAGS constant.
133453 *
133454 * @global array $allowedposttags
133455 * @since 2.0.0
133456 */
133457 $allowedposttags = array(
133458 'address' => array(),
133459 'a' => array(
133460 'class' => array (),
133461 'href' => array (),
133462 'id' => array (),
133463 'title' => array (),
133464 'rel' => array (),
133465 'rev' => array (),
133466 'name' => array (),
133467 'target' => array()),
133468 'abbr' => array(
133469 'class' => array (),
133470 'title' => array ()),
133471 'acronym' => array(
133472 'title' => array ()),
133473 'b' => array(),
133474 'big' => array(),
133475 'blockquote' => array(
133476 'id' => array (),
133477 'cite' => array (),
133478 'class' => array(),
133479 'lang' => array(),
133480 'xml:lang' => array()),
133481 'br' => array (
133482 'class' => array ()),
133483 'button' => array(
133484 'disabled' => array (),
133485 'name' => array (),
133486 'type' => array (),
133487 'value' => array ()),
133488 'caption' => array(
133489 'align' => array (),
133490 'class' => array ()),
133491 'cite' => array (
133492 'class' => array(),
133493 'dir' => array(),
133494 'lang' => array(),
133495 'title' => array ()),
133496 'code' => array (
133497 'style' => array()),
133498 'col' => array(
133499 'align' => array (),
133500 'char' => array (),
133501 'charoff' => array (),
133502 'span' => array (),
133503 'dir' => array(),
133504 'style' => array (),
133505 'valign' => array (),
133506 'width' => array ()),
133507 'del' => array(
133508 'datetime' => array ()),
133509 'dd' => array(),
133510 'div' => array(
133511 'align' => array (),
133512 'class' => array (),
133513 'dir' => array (),
133514 'lang' => array(),
133515 'style' => array (),
133516 'xml:lang' => array()),
133517 'dl' => array(),
133518 'dt' => array(),
133519 'em' => array(),
133520 'fieldset' => array(),
133521 'font' => array(
133522 'color' => array (),
133523 'face' => array (),
133524 'size' => array ()),
133525 'form' => array(
133526 'action' => array (),
133527 'accept' => array (),
133528 'accept-charset' => array (),
133529 'enctype' => array (),
133530 'method' => array (),
133531 'name' => array (),
133532 'target' => array ()),
133533 'h1' => array(
133534 'align' => array (),
133535 'class' => array ()),
133536 'h2' => array(
133537 'align' => array (),
133538 'class' => array ()),
133539 'h3' => array(
133540 'align' => array (),
133541 'class' => array ()),
133542 'h4' => array(
133543 'align' => array (),
133544 'class' => array ()),
133545 'h5' => array(
133546 'align' => array (),
133547 'class' => array ()),
133548 'h6' => array(
133549 'align' => array (),
133550 'class' => array ()),
133551 'hr' => array(
133552 'align' => array (),
133553 'class' => array (),
133554 'noshade' => array (),
133555 'size' => array (),
133556 'width' => array ()),
133557 'i' => array(),
133558 'img' => array(
133559 'alt' => array (),
133560 'align' => array (),
133561 'border' => array (),
133562 'class' => array (),
133563 'height' => array (),
133564 'hspace' => array (),
133565 'longdesc' => array (),
133566 'vspace' => array (),
133567 'src' => array (),
133568 'style' => array (),
133569 'width' => array ()),
133570 'ins' => array(
133571 'datetime' => array (),
133572 'cite' => array ()),
133573 'kbd' => array(),
133574 'label' => array(
133575 'for' => array ()),
133576 'legend' => array(
133577 'align' => array ()),
133578 'li' => array (
133579 'align' => array (),
133580 'class' => array ()),
133581 'p' => array(
133582 'class' => array (),
133583 'align' => array (),
133584 'dir' => array(),
133585 'lang' => array(),
133586 'style' => array (),
133587 'xml:lang' => array()),
133588 'pre' => array(
133589 'style' => array(),
133590 'width' => array ()),
133591 'q' => array(
133592 'cite' => array ()),
133593 's' => array(),
133594 'span' => array (
133595 'class' => array (),
133596 'dir' => array (),
133597 'align' => array (),
133598 'lang' => array (),
133599 'style' => array (),
133600 'title' => array (),
133601 'xml:lang' => array()),
133602 'strike' => array(),
133603 'strong' => array(),
133604 'sub' => array(),
133605 'sup' => array(),
133606 'table' => array(
133607 'align' => array (),
133608 'bgcolor' => array (),
133609 'border' => array (),
133610 'cellpadding' => array (),
133611 'cellspacing' => array (),
133612 'class' => array (),
133613 'dir' => array(),
133614 'id' => array(),
133615 'rules' => array (),
133616 'style' => array (),
133617 'summary' => array (),
133618 'width' => array ()),
133619 'tbody' => array(
133620 'align' => array (),
133621 'char' => array (),
133622 'charoff' => array (),
133623 'valign' => array ()),
133624 'td' => array(
133625 'abbr' => array (),
133626 'align' => array (),
133627 'axis' => array (),
133628 'bgcolor' => array (),
133629 'char' => array (),
133630 'charoff' => array (),
133631 'class' => array (),
133632 'colspan' => array (),
133633 'dir' => array(),
133634 'headers' => array (),
133635 'height' => array (),
133636 'nowrap' => array (),
133637 'rowspan' => array (),
133638 'scope' => array (),
133639 'style' => array (),
133640 'valign' => array (),
133641 'width' => array ()),
133642 'textarea' => array(
133643 'cols' => array (),
133644 'rows' => array (),
133645 'disabled' => array (),
133646 'name' => array (),
133647 'readonly' => array ()),
133648 'tfoot' => array(
133649 'align' => array (),
133650 'char' => array (),
133651 'class' => array (),
133652 'charoff' => array (),
133653 'valign' => array ()),
133654 'th' => array(
133655 'abbr' => array (),
133656 'align' => array (),
133657 'axis' => array (),
133658 'bgcolor' => array (),
133659 'char' => array (),
133660 'charoff' => array (),
133661 'class' => array (),
133662 'colspan' => array (),
133663 'headers' => array (),
133664 'height' => array (),
133665 'nowrap' => array (),
133666 'rowspan' => array (),
133667 'scope' => array (),
133668 'valign' => array (),
133669 'width' => array ()),
133670 'thead' => array(
133671 'align' => array (),
133672 'char' => array (),
133673 'charoff' => array (),
133674 'class' => array (),
133675 'valign' => array ()),
133676 'title' => array(),
133677 'tr' => array(
133678 'align' => array (),
133679 'bgcolor' => array (),
133680 'char' => array (),
133681 'charoff' => array (),
133682 'class' => array (),
133683 'style' => array (),
133684 'valign' => array ()),
133685 'tt' => array(),
133686 'u' => array(),
133687 'ul' => array (
133688 'class' => array (),
133689 'style' => array (),
133690 'type' => array ()),
133691 'ol' => array (
133692 'class' => array (),
133693 'start' => array (),
133694 'style' => array (),
133695 'type' => array ()),
133696 'var' => array ());
133697
133698 /**
133699 * Kses allowed HTML elements.
133700 *
133701 * @global array $allowedtags
133702 * @since 1.0.0
133703 */
133704 $allowedtags = array(
133705 'a' => array(
133706 'href' => array (),
133707 'title' => array ()),
133708 'abbr' => array(
133709 'title' => array ()),
133710 'acronym' => array(
133711 'title' => array ()),
133712 'b' => array(),
133713 'blockquote' => array(
133714 'cite' => array ()),
133715 // 'br' => array(),
133716 'cite' => array (),
133717 'code' => array(),
133718 'del' => array(
133719 'datetime' => array ()),
133720 // 'dd' => array(),
133721 // 'dl' => array(),
133722 // 'dt' => array(),
133723 'em' => array (), 'i' => array (),
133724 // 'ins' => array('datetime' => array(), 'cite' => array()),
133725 // 'li' => array(),
133726 // 'ol' => array(),
133727 // 'p' => array(),
133728 'q' => array(
133729 'cite' => array ()),
133730 'strike' => array(),
133731 'strong' => array(),
133732 // 'sub' => array(),
133733 // 'sup' => array(),
133734 // 'u' => array(),
133735 // 'ul' => array(),
133736 );
133737 }
133738
133739 /**
133740 * Filters content and keeps only allowable HTML elements.
133741 *
133742 * This function makes sure that only the allowed HTML element names, attribute
133743 * names and attribute values plus only sane HTML entities will occur in
133744 * $string. You have to remove any slashes from PHP's magic quotes before you
133745 * call this function.
133746 *
133747 * The default allowed protocols are 'http', 'https', 'ftp', 'mailto', 'news',
133748 * 'irc', 'gopher', 'nntp', 'feed', and finally 'telnet. This covers all common
133749 * link protocols, except for 'javascript' which should not be allowed for
133750 * untrusted users.
133751 *
133752 * @since 1.0.0
133753 *
133754 * @param string $string Content to filter through kses
133755 * @param array $allowed_html List of allowed HTML elements
133756 * @param array $allowed_protocols Optional. Allowed protocol in links.
133757 * @return string Filtered content with only allowed HTML elements
133758 */
133759 function wp_kses($string, $allowed_html, $allowed_protocols = array ('http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet')) {
133760 $string = wp_kses_no_null($string);
133761 $string = wp_kses_js_entities($string);
133762 $string = wp_kses_normalize_entities($string);
133763 $allowed_html_fixed = wp_kses_array_lc($allowed_html);
133764 $string = wp_kses_hook($string, $allowed_html_fixed, $allowed_protocols); // WP changed the order of these funcs and added args to wp_kses_hook
133765 return wp_kses_split($string, $allowed_html_fixed, $allowed_protocols);
133766 }
133767
133768 /**
133769 * You add any kses hooks here.
133770 *
133771 * There is currently only one kses WordPress hook and it is called here. All
133772 * parameters are passed to the hooks and expected to recieve a string.
133773 *
133774 * @since 1.0.0
133775 *
133776 * @param string $string Content to filter through kses
133777 * @param array $allowed_html List of allowed HTML elements
133778 * @param array $allowed_protocols Allowed protocol in links
133779 * @return string Filtered content through 'pre_kses' hook
133780 */
133781 function wp_kses_hook($string, $allowed_html, $allowed_protocols) {
133782 $string = apply_filters('pre_kses', $string, $allowed_html, $allowed_protocols);
133783 return $string;
133784 }
133785
133786 /**
133787 * This function returns kses' version number.
133788 *
133789 * @since 1.0.0
133790 *
133791 * @return string KSES Version Number
133792 */
133793 function wp_kses_version() {
133794 return '0.2.2';
133795 }
133796
133797 /**
133798 * Searches for HTML tags, no matter how malformed.
133799 *
133800 * It also matches stray ">" characters.
133801 *
133802 * @since 1.0.0
133803 *
133804 * @param string $string Content to filter
133805 * @param array $allowed_html Allowed HTML elements
133806 * @param array $allowed_protocols Allowed protocols to keep
133807 * @return string Content with fixed HTML tags
133808 */
133809 function wp_kses_split($string, $allowed_html, $allowed_protocols) {
133810 return preg_replace_callback('%((<!--.*?(-->|$))|(<[^>]*(>|$)|>))%',
133811 function($match) {
133812 return wp_kses_split2($match[1], $allowed_html, $allowed_protocols);
133813 }, $string);
133814 }
133815
133816 /**
133817 * Callback for wp_kses_split for fixing malformed HTML tags.
133818 *
133819 * This function does a lot of work. It rejects some very malformed things like
133820 * <:::>. It returns an empty string, if the element isn't allowed (look ma, no
133821 * strip_tags()!). Otherwise it splits the tag into an element and an attribute
133822 * list.
133823 *
133824 * After the tag is split into an element and an attribute list, it is run
133825 * through another filter which will remove illegal attributes and once that is
133826 * completed, will be returned.
133827 *
133828 * @access private
133829 * @since 1.0.0
133830 * @uses wp_kses_attr()
133831 *
133832 * @param string $string Content to filter
133833 * @param array $allowed_html Allowed HTML elements
133834 * @param array $allowed_protocols Allowed protocols to keep
133835 * @return string Fixed HTML element
133836 */
133837 function wp_kses_split2($string, $allowed_html, $allowed_protocols) {
133838 $string = wp_kses_stripslashes($string);
133839
133840 if (substr($string, 0, 1) != '<')
133841 return '>';
133842 # It matched a ">" character
133843
133844 if (preg_match('%^<!--(.*?)(-->)?$%', $string, $matches)) {
133845 $string = str_replace(array('<!--', '-->'), '', $matches[1]);
133846 while ( $string != $newstring = wp_kses($string, $allowed_html, $allowed_protocols) )
133847 $string = $newstring;
133848 if ( $string == '' )
133849 return '';
133850 // prevent multiple dashes in comments
133851 $string = preg_replace('/--+/', '-', $string);
133852 // prevent three dashes closing a comment
133853 $string = preg_replace('/-$/', '', $string);
133854 return "<!--{$string}-->";
133855 }
133856 # Allow HTML comments
133857
133858 if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9]+)([^>]*)>?$%', $string, $matches))
133859 return '';
133860 # It's seriously malformed
133861
133862 $slash = trim($matches[1]);
133863 $elem = $matches[2];
133864 $attrlist = $matches[3];
133865
133866 if (!@isset($allowed_html[strtolower($elem)]))
133867 return '';
133868 # They are using a not allowed HTML element
133869
133870 if ($slash != '')
133871 return "<$slash$elem>";
133872 # No attributes are allowed for closing elements
133873
133874 return wp_kses_attr("$slash$elem", $attrlist, $allowed_html, $allowed_protocols);
133875 }
133876
133877 /**
133878 * Removes all attributes, if none are allowed for this element.
133879 *
133880 * If some are allowed it calls wp_kses_hair() to split them further, and then
133881 * it builds up new HTML code from the data that kses_hair() returns. It also
133882 * removes "<" and ">" characters, if there are any left. One more thing it does
133883 * is to check if the tag has a closing XHTML slash, and if it does, it puts one
133884 * in the returned code as well.
133885 *
133886 * @since 1.0.0
133887 *
133888 * @param string $element HTML element/tag
133889 * @param string $attr HTML attributes from HTML element to closing HTML element tag
133890 * @param array $allowed_html Allowed HTML elements
133891 * @param array $allowed_protocols Allowed protocols to keep
133892 * @return string Sanitized HTML element
133893 */
133894 function wp_kses_attr($element, $attr, $allowed_html, $allowed_protocols) {
133895 # Is there a closing XHTML slash at the end of the attributes?
133896
133897 $xhtml_slash = '';
133898 if (preg_match('%\s/\s*$%', $attr))
133899 $xhtml_slash = ' /';
133900
133901 # Are any attributes allowed at all for this element?
133902
133903 if (@ count($allowed_html[strtolower($element)]) == 0)
133904 return "<$element$xhtml_slash>";
133905
133906 # Split it
133907
133908 $attrarr = wp_kses_hair($attr, $allowed_protocols);
133909
133910 # Go through $attrarr, and save the allowed attributes for this element
133911 # in $attr2
133912
133913 $attr2 = '';
133914
133915 foreach ($attrarr as $arreach) {
133916 if (!@ isset ($allowed_html[strtolower($element)][strtolower($arreach['name'])]))
133917 continue; # the attribute is not allowed
133918
133919 $current = $allowed_html[strtolower($element)][strtolower($arreach['name'])];
133920 if ($current == '')
133921 continue; # the attribute is not allowed
133922
133923 if (!is_array($current))
133924 $attr2 .= ' '.$arreach['whole'];
133925 # there are no checks
133926
133927 else {
133928 # there are some checks
133929 $ok = true;
133930 foreach ($current as $currkey => $currval)
133931 if (!wp_kses_check_attr_val($arreach['value'], $arreach['vless'], $currkey, $currval)) {
133932 $ok = false;
133933 break;
133934 }
133935
133936 if ($ok)
133937 $attr2 .= ' '.$arreach['whole']; # it passed them
133938 } # if !is_array($current)
133939 } # foreach
133940
133941 # Remove any "<" or ">" characters
133942
133943 $attr2 = preg_replace('/[<>]/', '', $attr2);
133944
133945 return "<$element$attr2$xhtml_slash>";
133946 }
133947
133948 /**
133949 * Builds an attribute list from string containing attributes.
133950 *
133951 * This function does a lot of work. It parses an attribute list into an array
133952 * with attribute data, and tries to do the right thing even if it gets weird
133953 * input. It will add quotes around attribute values that don't have any quotes
133954 * or apostrophes around them, to make it easier to produce HTML code that will
133955 * conform to W3C's HTML specification. It will also remove bad URL protocols
133956 * from attribute values. It also reduces duplicate attributes by using the
133957 * attribute defined first (foo='bar' foo='baz' will result in foo='bar').
133958 *
133959 * @since 1.0.0
133960 *
133961 * @param string $attr Attribute list from HTML element to closing HTML element tag
133962 * @param array $allowed_protocols Allowed protocols to keep
133963 * @return array List of attributes after parsing
133964 */
133965 function wp_kses_hair($attr, $allowed_protocols) {
133966 $attrarr = array ();
133967 $mode = 0;
133968 $attrname = '';
133969 $uris = array('xmlns', 'profile', 'href', 'src', 'cite', 'classid', 'codebase', 'data', 'usemap', 'longdesc', 'action');
133970
133971 # Loop through the whole attribute list
133972
133973 while (strlen($attr) != 0) {
133974 $working = 0; # Was the last operation successful?
133975
133976 switch ($mode) {
133977 case 0 : # attribute name, href for instance
133978
133979 if (preg_match('/^([-a-zA-Z]+)/', $attr, $match)) {
133980 $attrname = $match[1];
133981 $working = $mode = 1;
133982 $attr = preg_replace('/^[-a-zA-Z]+/', '', $attr);
133983 }
133984
133985 break;
133986
133987 case 1 : # equals sign or valueless ("selected")
133988
133989 if (preg_match('/^\s*=\s*/', $attr)) # equals sign
133990 {
133991 $working = 1;
133992 $mode = 2;
133993 $attr = preg_replace('/^\s*=\s*/', '', $attr);
133994 break;
133995 }
133996
133997 if (preg_match('/^\s+/', $attr)) # valueless
133998 {
133999 $working = 1;
134000 $mode = 0;
134001 if(FALSE === array_key_exists($attrname, $attrarr)) {
134002 $attrarr[$attrname] = array ('name' => $attrname, 'value' => '', 'whole' => $attrname, 'vless' => 'y');
134003 }
134004 $attr = preg_replace('/^\s+/', '', $attr);
134005 }
134006
134007 break;
134008
134009 case 2 : # attribute value, a URL after href= for instance
134010
134011 if (preg_match('/^"([^"]*)"(\s+|$)/', $attr, $match))
134012 # "value"
134013 {
134014 $thisval = $match[1];
134015 if ( in_array($attrname, $uris) )
134016 $thisval = wp_kses_bad_protocol($thisval, $allowed_protocols);
134017
134018 if(FALSE === array_key_exists($attrname, $attrarr)) {
134019 $attrarr[$attrname] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname=\"$thisval\"", 'vless' => 'n');
134020 }
134021 $working = 1;
134022 $mode = 0;
134023 $attr = preg_replace('/^"[^"]*"(\s+|$)/', '', $attr);
134024 break;
134025 }
134026
134027 if (preg_match("/^'([^']*)'(\s+|$)/", $attr, $match))
134028 # 'value'
134029 {
134030 $thisval = $match[1];
134031 if ( in_array($attrname, $uris) )
134032 $thisval = wp_kses_bad_protocol($thisval, $allowed_protocols);
134033
134034 if(FALSE === array_key_exists($attrname, $attrarr)) {
134035 $attrarr[$attrname] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname='$thisval'", 'vless' => 'n');
134036 }
134037 $working = 1;
134038 $mode = 0;
134039 $attr = preg_replace("/^'[^']*'(\s+|$)/", '', $attr);
134040 break;
134041 }
134042
134043 if (preg_match("%^([^\s\"']+)(\s+|$)%", $attr, $match))
134044 # value
134045 {
134046 $thisval = $match[1];
134047 if ( in_array($attrname, $uris) )
134048 $thisval = wp_kses_bad_protocol($thisval, $allowed_protocols);
134049
134050 if(FALSE === array_key_exists($attrname, $attrarr)) {
134051 $attrarr[$attrname] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname=\"$thisval\"", 'vless' => 'n');
134052 }
134053 # We add quotes to conform to W3C's HTML spec.
134054 $working = 1;
134055 $mode = 0;
134056 $attr = preg_replace("%^[^\s\"']+(\s+|$)%", '', $attr);
134057 }
134058
134059 break;
134060 } # switch
134061
134062 if ($working == 0) # not well formed, remove and try again
134063 {
134064 $attr = wp_kses_html_error($attr);
134065 $mode = 0;
134066 }
134067 } # while
134068
134069 if ($mode == 1 && FALSE === array_key_exists($attrname, $attrarr))
134070 # special case, for when the attribute list ends with a valueless
134071 # attribute like "selected"
134072 $attrarr[$attrname] = array ('name' => $attrname, 'value' => '', 'whole' => $attrname, 'vless' => 'y');
134073
134074 return $attrarr;
134075 }
134076
134077 /**
134078 * Performs different checks for attribute values.
134079 *
134080 * The currently implemented checks are "maxlen", "minlen", "maxval", "minval"
134081 * and "valueless" with even more checks to come soon.
134082 *
134083 * @since 1.0.0
134084 *
134085 * @param string $value Attribute value
134086 * @param string $vless Whether the value is valueless or not. Use 'y' or 'n'
134087 * @param string $checkname What $checkvalue is checking for.
134088 * @param mixed $checkvalue What constraint the value should pass
134089 * @return bool Whether check passes (true) or not (false)
134090 */
134091 function wp_kses_check_attr_val($value, $vless, $checkname, $checkvalue) {
134092 $ok = true;
134093
134094 switch (strtolower($checkname)) {
134095 case 'maxlen' :
134096 # The maxlen check makes sure that the attribute value has a length not
134097 # greater than the given value. This can be used to avoid Buffer Overflows
134098 # in WWW clients and various Internet servers.
134099
134100 if (strlen($value) > $checkvalue)
134101 $ok = false;
134102 break;
134103
134104 case 'minlen' :
134105 # The minlen check makes sure that the attribute value has a length not
134106 # smaller than the given value.
134107
134108 if (strlen($value) < $checkvalue)
134109 $ok = false;
134110 break;
134111
134112 case 'maxval' :
134113 # The maxval check does two things: it checks that the attribute value is
134114 # an integer from 0 and up, without an excessive amount of zeroes or
134115 # whitespace (to avoid Buffer Overflows). It also checks that the attribute
134116 # value is not greater than the given value.
134117 # This check can be used to avoid Denial of Service attacks.
134118
134119 if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value))
134120 $ok = false;
134121 if ($value > $checkvalue)
134122 $ok = false;
134123 break;
134124
134125 case 'minval' :
134126 # The minval check checks that the attribute value is a positive integer,
134127 # and that it is not smaller than the given value.
134128
134129 if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value))
134130 $ok = false;
134131 if ($value < $checkvalue)
134132 $ok = false;
134133 break;
134134
134135 case 'valueless' :
134136 # The valueless check checks if the attribute has a value
134137 # (like <a href="blah">) or not (<option selected>). If the given value
134138 # is a "y" or a "Y", the attribute must not have a value.
134139 # If the given value is an "n" or an "N", the attribute must have one.
134140
134141 if (strtolower($checkvalue) != $vless)
134142 $ok = false;
134143 break;
134144 } # switch
134145
134146 return $ok;
134147 }
134148
134149 /**
134150 * Sanitize string from bad protocols.
134151 *
134152 * This function removes all non-allowed protocols from the beginning of
134153 * $string. It ignores whitespace and the case of the letters, and it does
134154 * understand HTML entities. It does its work in a while loop, so it won't be
134155 * fooled by a string like "javascript:javascript:alert(57)".
134156 *
134157 * @since 1.0.0
134158 *
134159 * @param string $string Content to filter bad protocols from
134160 * @param array $allowed_protocols Allowed protocols to keep
134161 * @return string Filtered content
134162 */
134163 function wp_kses_bad_protocol($string, $allowed_protocols) {
134164 $string = wp_kses_no_null($string);
134165 $string = preg_replace('/\xad+/', '', $string); # deals with Opera "feature"
134166 $string2 = $string.'a';
134167
134168 while ($string != $string2) {
134169 $string2 = $string;
134170 $string = wp_kses_bad_protocol_once($string, $allowed_protocols);
134171 } # while
134172
134173 return $string;
134174 }
134175
134176 /**
134177 * Removes any NULL characters in $string.
134178 *
134179 * @since 1.0.0
134180 *
134181 * @param string $string
134182 * @return string
134183 */
134184 function wp_kses_no_null($string) {
134185 $string = preg_replace('/\0+/', '', $string);
134186 $string = preg_replace('/(\\\\0)+/', '', $string);
134187
134188 return $string;
134189 }
134190
134191 /**
134192 * Strips slashes from in front of quotes.
134193 *
134194 * This function changes the character sequence \" to just ". It leaves all
134195 * other slashes alone. It's really weird, but the quoting from
134196 * preg_replace(//e) seems to require this.
134197 *
134198 * @since 1.0.0
134199 *
134200 * @param string $string String to strip slashes
134201 * @return string Fixed strings with quoted slashes
134202 */
134203 function wp_kses_stripslashes($string) {
134204 return preg_replace('%\\\\"%', '"', $string);
134205 }
134206
134207 /**
134208 * Goes through an array and changes the keys to all lower case.
134209 *
134210 * @since 1.0.0
134211 *
134212 * @param array $inarray Unfiltered array
134213 * @return array Fixed array with all lowercase keys
134214 */
134215 function wp_kses_array_lc($inarray) {
134216 $outarray = array ();
134217
134218 foreach ( (array) $inarray as $inkey => $inval) {
134219 $outkey = strtolower($inkey);
134220 $outarray[$outkey] = array ();
134221
134222 foreach ( (array) $inval as $inkey2 => $inval2) {
134223 $outkey2 = strtolower($inkey2);
134224 $outarray[$outkey][$outkey2] = $inval2;
134225 } # foreach $inval
134226 } # foreach $inarray
134227
134228 return $outarray;
134229 }
134230
134231 /**
134232 * Removes the HTML JavaScript entities found in early versions of Netscape 4.
134233 *
134234 * @since 1.0.0
134235 *
134236 * @param string $string
134237 * @return string
134238 */
134239 function wp_kses_js_entities($string) {
134240 return preg_replace('%&\s*\{[^}]*(\}\s*;?|$)%', '', $string);
134241 }
134242
134243 /**
134244 * Handles parsing errors in wp_kses_hair().
134245 *
134246 * The general plan is to remove everything to and including some whitespace,
134247 * but it deals with quotes and apostrophes as well.
134248 *
134249 * @since 1.0.0
134250 *
134251 * @param string $string
134252 * @return string
134253 */
134254 function wp_kses_html_error($string) {
134255 return preg_replace('/^("[^"]*("|$)|\'[^\']*(\'|$)|\S)*\s*/', '', $string);
134256 }
134257
134258 /**
134259 * Sanitizes content from bad protocols and other characters.
134260 *
134261 * This function searches for URL protocols at the beginning of $string, while
134262 * handling whitespace and HTML entities.
134263 *
134264 * @since 1.0.0
134265 *
134266 * @param string $string Content to check for bad protocols
134267 * @param string $allowed_protocols Allowed protocols
134268 * @return string Sanitized content
134269 */
134270 function wp_kses_bad_protocol_once($string, $allowed_protocols) {
134271 global $_kses_allowed_protocols;
134272 $_kses_allowed_protocols = $allowed_protocols;
134273
134274 $string2 = preg_split('/:|:|:/i', $string, 2);
134275 if ( isset($string2[1]) && !preg_match('%/\?%', $string2[0]) )
134276 $string = wp_kses_bad_protocol_once2($string2[0]) . trim($string2[1]);
134277 else
134278 $string = preg_replace_callback('/^((&[^;]*;|[\sA-Za-z0-9])*)'.'(:|:|[Xx]3[Aa];)\s*/', 'wp_kses_bad_protocol_once2', $string);
134279
134280 return $string;
134281 }
134282
134283 /**
134284 * Callback for wp_kses_bad_protocol_once() regular expression.
134285 *
134286 * This function processes URL protocols, checks to see if they're in the
134287 * white-list or not, and returns different data depending on the answer.
134288 *
134289 * @access private
134290 * @since 1.0.0
134291 *
134292 * @param mixed $matches string or preg_replace_callback() matches array to check for bad protocols
134293 * @return string Sanitized content
134294 */
134295 function wp_kses_bad_protocol_once2($matches) {
134296 global $_kses_allowed_protocols;
134297
134298 if ( is_array($matches) ) {
134299 if ( ! isset($matches[1]) || empty($matches[1]) )
134300 return '';
134301
134302 $string = $matches[1];
134303 } else {
134304 $string = $matches;
134305 }
134306
134307 $string2 = wp_kses_decode_entities($string);
134308 $string2 = preg_replace('/\s/', '', $string2);
134309 $string2 = wp_kses_no_null($string2);
134310 $string2 = preg_replace('/\xad+/', '', $string2);
134311 # deals with Opera "feature"
134312 $string2 = strtolower($string2);
134313
134314 $allowed = false;
134315 foreach ( (array) $_kses_allowed_protocols as $one_protocol)
134316 if (strtolower($one_protocol) == $string2) {
134317 $allowed = true;
134318 break;
134319 }
134320
134321 if ($allowed)
134322 return "$string2:";
134323 else
134324 return '';
134325 }
134326
134327 /**
134328 * Converts and fixes HTML entities.
134329 *
134330 * This function normalizes HTML entities. It will convert "AT&T" to the correct
134331 * "AT&T", ":" to ":", "YZZY;" to "&#XYZZY;" and so on.
134332 *
134333 * @since 1.0.0
134334 *
134335 * @param string $string Content to normalize entities
134336 * @return string Content with normalized entities
134337 */
134338 function wp_kses_normalize_entities($string) {
134339 # Disarm all entities by converting & to &
134340
134341 $string = str_replace('&', '&', $string);
134342
134343 # Change back the allowed entities in our entity whitelist
134344
134345 $string = preg_replace('/&([A-Za-z][A-Za-z0-9]{0,19});/', '&\\1;', $string);
134346 $string = preg_replace_callback('/�*([0-9]{1,5});/', 'wp_kses_normalize_entities2', $string);
134347 $string = preg_replace_callback('/&#([Xx])0*(([0-9A-Fa-f]{2}){1,2});/', 'wp_kses_normalize_entities3', $string);
134348
134349 return $string;
134350 }
134351
134352 /**
134353 * Callback for wp_kses_normalize_entities() regular expression.
134354 *
134355 * This function helps wp_kses_normalize_entities() to only accept 16 bit values
134356 * and nothing more for number; entities.
134357 *
134358 * @access private
134359 * @since 1.0.0
134360 *
134361 * @param array $matches preg_replace_callback() matches array
134362 * @return string Correctly encoded entity
134363 */
134364 function wp_kses_normalize_entities2($matches) {
134365 if ( ! isset($matches[1]) || empty($matches[1]) )
134366 return '';
134367
134368 $i = $matches[1];
134369 return ( ( ! valid_unicode($i) ) || ($i > 65535) ? "&#$i;" : "$i;" );
134370 }
134371
134372 /**
134373 * Callback for wp_kses_normalize_entities() for regular expression.
134374 *
134375 * This function helps wp_kses_normalize_entities() to only accept valid Unicode
134376 * numeric entities in hex form.
134377 *
134378 * @access private
134379 *
134380 * @param array $matches preg_replace_callback() matches array
134381 * @return string Correctly encoded entity
134382 */
134383 function wp_kses_normalize_entities3($matches) {
134384 if ( ! isset($matches[2]) || empty($matches[2]) )
134385 return '';
134386
134387 $hexchars = $matches[2];
134388 return ( ( ! valid_unicode(hexdec($hexchars)) ) ? "&#x$hexchars;" : "$hexchars;" );
134389 }
134390
134391 /**
134392 * Helper function to determine if a Unicode value is valid.
134393 *
134394 * @param int $i Unicode value
134395 * @return bool true if the value was a valid Unicode number
134396 */
134397 function valid_unicode($i) {
134398 return ( $i == 0x9 || $i == 0xa || $i == 0xd ||
134399 ($i >= 0x20 && $i <= 0xd7ff) ||
134400 ($i >= 0xe000 && $i <= 0xfffd) ||
134401 ($i >= 0x10000 && $i <= 0x10ffff) );
134402 }
134403
134404 /**
134405 * Convert all entities to their character counterparts.
134406 *
134407 * This function decodes numeric HTML entities (A and A). It doesn't do
134408 * anything with other entities like ä, but we don't need them in the URL
134409 * protocol whitelisting system anyway.
134410 *
134411 * @since 1.0.0
134412 *
134413 * @param string $string Content to change entities
134414 * @return string Content after decoded entities
134415 */
134416 function wp_kses_decode_entities($string) {
134417 $string = preg_replace_callback('/([0-9]+);/', function($match) {
134418 return chr($match[1]);
134419 }, $string);
134420 $string = preg_replace_callback('/[Xx]([0-9A-Fa-f]+);/', function($match) {
134421 return chr(hexdec($match[1]));
134422 }, $string);
134423
134424 return $string;
134425 }
134426
134427 /**
134428 * Sanitize content with allowed HTML Kses rules.
134429 *
134430 * @since 1.0.0
134431 * @uses $allowedtags
134432 *
134433 * @param string $data Content to filter
134434 * @return string Filtered content
134435 */
134436 function wp_filter_kses($data) {
134437 global $allowedtags;
134438 return addslashes( wp_kses(stripslashes( $data ), $allowedtags) );
134439 }
134440
134441 /**
134442 * Sanitize content for allowed HTML tags for post content.
134443 *
134444 * Post content refers to the page contents of the 'post' type and not $_POST
134445 * data from forms.
134446 *
134447 * @since 2.0.0
134448 * @uses $allowedposttags
134449 *
134450 * @param string $data Post content to filter
134451 * @return string Filtered post content with allowed HTML tags and attributes intact.
134452 */
134453 function wp_filter_post_kses($data) {
134454 global $allowedposttags;
134455 return addslashes ( wp_kses(stripslashes( $data ), $allowedposttags) );
134456 }
134457
134458 /**
134459 * Strips all of the HTML in the content.
134460 *
134461 * @since 2.1.0
134462 *
134463 * @param string $data Content to strip all HTML from
134464 * @return string Filtered content without any HTML
134465 */
134466 function wp_filter_nohtml_kses($data) {
134467 return addslashes ( wp_kses(stripslashes( $data ), array()) );
134468 }
134469
134470 /**
134471 * Adds all Kses input form content filters.
134472 *
134473 * All hooks have default priority. The wp_filter_kses() function is added to
134474 * the 'pre_comment_content' and 'title_save_pre' hooks.
134475 *
134476 * The wp_filter_post_kses() function is added to the 'content_save_pre',
134477 * 'excerpt_save_pre', and 'content_filtered_save_pre' hooks.
134478 *
134479 * @since 2.0.0
134480 * @uses add_filter() See description for what functions are added to what hooks.
134481 */
134482 function kses_init_filters() {
134483 // Normal filtering.
134484 add_filter('pre_comment_content', 'wp_filter_kses');
134485 add_filter('title_save_pre', 'wp_filter_kses');
134486
134487 // Post filtering
134488 add_filter('content_save_pre', 'wp_filter_post_kses');
134489 add_filter('excerpt_save_pre', 'wp_filter_post_kses');
134490 add_filter('content_filtered_save_pre', 'wp_filter_post_kses');
134491 }
134492
134493 /**
134494 * Removes all Kses input form content filters.
134495 *
134496 * A quick procedural method to removing all of the filters that kses uses for
134497 * content in WordPress Loop.
134498 *
134499 * Does not remove the kses_init() function from 'init' hook (priority is
134500 * default). Also does not remove kses_init() function from 'set_current_user'
134501 * hook (priority is also default).
134502 *
134503 * @since 2.0.6
134504 */
134505 function kses_remove_filters() {
134506 // Normal filtering.
134507 remove_filter('pre_comment_content', 'wp_filter_kses');
134508 remove_filter('title_save_pre', 'wp_filter_kses');
134509
134510 // Post filtering
134511 remove_filter('content_save_pre', 'wp_filter_post_kses');
134512 remove_filter('excerpt_save_pre', 'wp_filter_post_kses');
134513 remove_filter('content_filtered_save_pre', 'wp_filter_post_kses');
134514 }
134515
134516 /**
134517 * Sets up most of the Kses filters for input form content.
134518 *
134519 * If you remove the kses_init() function from 'init' hook and
134520 * 'set_current_user' (priority is default), then none of the Kses filter hooks
134521 * will be added.
134522 *
134523 * First removes all of the Kses filters in case the current user does not need
134524 * to have Kses filter the content. If the user does not have unfiltered html
134525 * capability, then Kses filters are added.
134526 *
134527 * @uses kses_remove_filters() Removes the Kses filters
134528 * @uses kses_init_filters() Adds the Kses filters back if the user
134529 * does not have unfiltered HTML capability.
134530 * @since 2.0.0
134531 */
134532 function kses_init() {
134533 kses_remove_filters();
134534
134535 if (current_user_can('unfiltered_html') == false)
134536 kses_init_filters();
134537 }
134538
134539 add_action('init', 'kses_init');
134540 add_action('set_current_user', 'kses_init');
134541 ?>