]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/kses.php
Wordpress 3.0.6-scripts
[autoinstalls/wordpress.git] / wp-includes / kses.php
index 8eb046df6a1b9673a1907ec715cddf2f1366a8f6..7ca692f51a8b36b77438d6b50dc96d6bd75fdb17 100644 (file)
@@ -1,26 +1,33 @@
 <?php
 /**
- * HTML/XHTML filter that only allows some elements and attributes
+ * kses 0.2.2 - HTML/XHTML filter that only allows some elements and attributes
+ * Copyright (C) 2002, 2003, 2005  Ulf Harnhammar
+ *
+ * This program is free software and open source software; you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the License,
+ * or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  or visit
+ * http://www.gnu.org/licenses/gpl.html
+ * 
+ * [kses strips evil scripts!]
  *
  * Added wp_ prefix to avoid conflicts with existing kses users
  *
  * @version 0.2.2
  * @copyright (C) 2002, 2003, 2005
- * @author Ulf Harnhammar <metaur@users.sourceforge.net>
+ * @author Ulf Harnhammar <http://advogato.org/person/metaur/>
  *
  * @package External
  * @subpackage KSES
- *
- * @internal
- * *** CONTACT INFORMATION ***
- * E-mail:      metaur at users dot sourceforge dot net
- * Web page:    http://sourceforge.net/projects/kses
- * Paper mail:  Ulf Harnhammar
- *              Ymergatan 17 C
- *              753 25  Uppsala
- *              SWEDEN
- *
- * [kses strips evil scripts!]
  */
 
 /**
@@ -670,7 +677,7 @@ function wp_kses_attr($element, $attr, $allowed_html, $allowed_protocols) {
                                        break;
                                }
 
-                       if ( $arreach['name'] == 'style' ) {
+                       if ( strtolower($arreach['name']) == 'style' ) {
                                $orig_value = $arreach['value'];
 
                                $value = safecss_filter_attr($orig_value);
@@ -762,7 +769,7 @@ function wp_kses_hair($attr, $allowed_protocols) {
                                        # "value"
                                        {
                                        $thisval = $match[1];
-                                       if ( in_array($attrname, $uris) )
+                                       if ( in_array(strtolower($attrname), $uris) )
                                                $thisval = wp_kses_bad_protocol($thisval, $allowed_protocols);
 
                                        if(FALSE === array_key_exists($attrname, $attrarr)) {
@@ -778,7 +785,7 @@ function wp_kses_hair($attr, $allowed_protocols) {
                                        # 'value'
                                        {
                                        $thisval = $match[1];
-                                       if ( in_array($attrname, $uris) )
+                                       if ( in_array(strtolower($attrname), $uris) )
                                                $thisval = wp_kses_bad_protocol($thisval, $allowed_protocols);
 
                                        if(FALSE === array_key_exists($attrname, $attrarr)) {
@@ -794,7 +801,7 @@ function wp_kses_hair($attr, $allowed_protocols) {
                                        # value
                                        {
                                        $thisval = $match[1];
-                                       if ( in_array($attrname, $uris) )
+                                       if ( in_array(strtolower($attrname), $uris) )
                                                $thisval = wp_kses_bad_protocol($thisval, $allowed_protocols);
 
                                        if(FALSE === array_key_exists($attrname, $attrarr)) {
@@ -1017,14 +1024,9 @@ function wp_kses_html_error($string) {
  * @return string Sanitized content
  */
 function wp_kses_bad_protocol_once($string, $allowed_protocols) {
-       global $_kses_allowed_protocols;
-       $_kses_allowed_protocols = $allowed_protocols;
-
-       $string2 = preg_split('/:|&#58;|&#x3a;/i', $string, 2);
-       if ( isset($string2[1]) && !preg_match('%/\?%', $string2[0]) )
-               $string = wp_kses_bad_protocol_once2($string2[0]) . trim($string2[1]);
-       else
-               $string = preg_replace_callback('/^((&[^;]*;|[\sA-Za-z0-9])*)'.'(:|&#58;|&#[Xx]3[Aa];)\s*/', 'wp_kses_bad_protocol_once2', $string);
+       $string2 = preg_split( '/:|&#0*58;|&#x0*3a;/i', $string, 2 );
+       if ( isset($string2[1]) && ! preg_match('%/\?%', $string2[0]) )
+               $string = wp_kses_bad_protocol_once2( $string2[0], $allowed_protocols ) . trim( $string2[1] );
 
        return $string;
 }
@@ -1038,29 +1040,19 @@ function wp_kses_bad_protocol_once($string, $allowed_protocols) {
  * @access private
  * @since 1.0.0
  *
- * @param mixed $matches string or preg_replace_callback() matches array to check for bad protocols
+ * @param string $string URI scheme to check against the whitelist
+ * @param string $allowed_protocols Allowed protocols
  * @return string Sanitized content
  */
-function wp_kses_bad_protocol_once2($matches) {
-       global $_kses_allowed_protocols;
-
-       if ( is_array($matches) ) {
-               if ( empty($matches[1]) )
-                       return '';
-
-               $string = $matches[1];
-       } else {
-               $string = $matches;
-       }
-
+function wp_kses_bad_protocol_once2( $string, $allowed_protocols ) {
        $string2 = wp_kses_decode_entities($string);
        $string2 = preg_replace('/\s/', '', $string2);
        $string2 = wp_kses_no_null($string2);
        $string2 = strtolower($string2);
 
        $allowed = false;
-       foreach ( (array) $_kses_allowed_protocols as $one_protocol)
-               if (strtolower($one_protocol) == $string2) {
+       foreach ( (array) $allowed_protocols as $one_protocol )
+               if ( strtolower($one_protocol) == $string2 ) {
                        $allowed = true;
                        break;
                }
@@ -1373,10 +1365,10 @@ function safecss_filter_attr( $css, $deprecated = '' ) {
        $css = wp_kses_no_null($css);
        $css = str_replace(array("\n","\r","\t"), '', $css);
 
-       if ( preg_match( '%[\\(&]|/\*%', $css ) ) // remove any inline css containing \ ( & or comments
+       if ( preg_match( '%[\\(&=}]|/\*%', $css ) ) // remove any inline css containing \ ( & } = or comments
                return '';
 
-       $css_array = split( ';', trim( $css ) );
+       $css_array = explode( ';', trim( $css ) );
        $allowed_attr = apply_filters( 'safe_style_css', array( 'text-align', 'margin', 'color', 'float',
        'border', 'background', 'background-color', 'border-bottom', 'border-bottom-color',
        'border-bottom-style', 'border-bottom-width', 'border-collapse', 'border-color', 'border-left',