<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[17730] trunk/wp-includes/kses.php: kses optimizations.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/17730">17730</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2011-04-27 21:50:39 +0000 (Wed, 27 Apr 2011)</dd>
</dl>

<h3>Log Message</h3>
<pre>kses optimizations. Props duck_. fixes <a href="http://trac.wordpress.org/ticket/17045">#17045</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesksesphp">trunk/wp-includes/kses.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesksesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/kses.php (17729 => 17730)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/kses.php        2011-04-27 21:44:09 UTC (rev 17729)
+++ trunk/wp-includes/kses.php        2011-04-27 21:50:39 UTC (rev 17730)
</span><span class="lines">@@ -554,7 +554,7 @@
</span><span class="cx">         global $pass_allowed_html, $pass_allowed_protocols;
</span><span class="cx">         $pass_allowed_html = $allowed_html;
</span><span class="cx">         $pass_allowed_protocols = $allowed_protocols;
</span><del>-        return preg_replace_callback( '%((&lt;!--.*?(--&gt;|$))|(&lt;[^&gt;]*(&gt;|$)|&gt;))%', '_wp_kses_split_callback', $string );
</del><ins>+        return preg_replace_callback( '%(&lt;!--.*?(--&gt;|$))|(&lt;[^&gt;]*(&gt;|$)|&gt;)%', '_wp_kses_split_callback', $string );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -565,7 +565,7 @@
</span><span class="cx">  */
</span><span class="cx"> function _wp_kses_split_callback( $match ) {
</span><span class="cx">         global $pass_allowed_html, $pass_allowed_protocols;
</span><del>-        return wp_kses_split2( $match[1], $pass_allowed_html, $pass_allowed_protocols );
</del><ins>+        return wp_kses_split2( $match[0], $pass_allowed_html, $pass_allowed_protocols );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -596,9 +596,9 @@
</span><span class="cx">                 return '&amp;gt;';
</span><span class="cx">         # It matched a &quot;&gt;&quot; character
</span><span class="cx"> 
</span><del>-        if (preg_match('%^&lt;!--(.*?)(--&gt;)?$%', $string, $matches)) {
-                $string = str_replace(array('&lt;!--', '--&gt;'), '', $matches[1]);
-                while ( $string != $newstring = wp_kses($string, $allowed_html, $allowed_protocols) )
</del><ins>+        if ( '&lt;!--' == substr( $string, 0, 4 ) ) {
+                $string = str_replace( array('&lt;!--', '--&gt;'), '', $string );
+                while ( $string != ($newstring = wp_kses($string, $allowed_html, $allowed_protocols)) )
</ins><span class="cx">                         $string = $newstring;
</span><span class="cx">                 if ( $string == '' )
</span><span class="cx">                         return '';
</span><span class="lines">@@ -618,15 +618,15 @@
</span><span class="cx">         $elem = $matches[2];
</span><span class="cx">         $attrlist = $matches[3];
</span><span class="cx"> 
</span><del>-        if (!@isset($allowed_html[strtolower($elem)]))
</del><ins>+        if ( ! isset($allowed_html[strtolower($elem)]) )
</ins><span class="cx">                 return '';
</span><span class="cx">         # They are using a not allowed HTML element
</span><span class="cx"> 
</span><span class="cx">         if ($slash != '')
</span><del>-                return &quot;&lt;$slash$elem&gt;&quot;;
</del><ins>+                return &quot;&lt;/$elem&gt;&quot;;
</ins><span class="cx">         # No attributes are allowed for closing elements
</span><span class="cx"> 
</span><del>-        return wp_kses_attr(&quot;$slash$elem&quot;, $attrlist, $allowed_html, $allowed_protocols);
</del><ins>+        return wp_kses_attr( $elem, $attrlist, $allowed_html, $allowed_protocols );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -654,50 +654,47 @@
</span><span class="cx">                 $xhtml_slash = ' /';
</span><span class="cx"> 
</span><span class="cx">         # Are any attributes allowed at all for this element?
</span><del>-
-        if (@ count($allowed_html[strtolower($element)]) == 0)
</del><ins>+        if ( ! isset($allowed_html[strtolower($element)]) || count($allowed_html[strtolower($element)]) == 0 )
</ins><span class="cx">                 return &quot;&lt;$element$xhtml_slash&gt;&quot;;
</span><span class="cx"> 
</span><span class="cx">         # Split it
</span><del>-
</del><span class="cx">         $attrarr = wp_kses_hair($attr, $allowed_protocols);
</span><span class="cx"> 
</span><span class="cx">         # Go through $attrarr, and save the allowed attributes for this element
</span><span class="cx">         # in $attr2
</span><del>-
</del><span class="cx">         $attr2 = '';
</span><span class="cx"> 
</span><ins>+        $allowed_attr = $allowed_html[strtolower($element)];
</ins><span class="cx">         foreach ($attrarr as $arreach) {
</span><del>-                if (!@ isset ($allowed_html[strtolower($element)][strtolower($arreach['name'])]))
</del><ins>+                if ( ! isset( $allowed_attr[strtolower($arreach['name'])] ) )
</ins><span class="cx">                         continue; # the attribute is not allowed
</span><span class="cx"> 
</span><del>-                $current = $allowed_html[strtolower($element)][strtolower($arreach['name'])];
-                if ($current == '')
</del><ins>+                $current = $allowed_attr[strtolower($arreach['name'])];
+                if ( $current == '' )
</ins><span class="cx">                         continue; # the attribute is not allowed
</span><span class="cx"> 
</span><del>-                if (!is_array($current))
</del><ins>+                if ( ! is_array($current) ) {
</ins><span class="cx">                         $attr2 .= ' '.$arreach['whole'];
</span><span class="cx">                 # there are no checks
</span><span class="cx"> 
</span><del>-                else {
</del><ins>+                } else {
</ins><span class="cx">                         # there are some checks
</span><span class="cx">                         $ok = true;
</span><del>-                        foreach ($current as $currkey =&gt; $currval)
-                                if (!wp_kses_check_attr_val($arreach['value'], $arreach['vless'], $currkey, $currval)) {
</del><ins>+                        foreach ($current as $currkey =&gt; $currval) {
+                                if ( ! wp_kses_check_attr_val($arreach['value'], $arreach['vless'], $currkey, $currval) ) {
</ins><span class="cx">                                         $ok = false;
</span><span class="cx">                                         break;
</span><span class="cx">                                 }
</span><ins>+                        }
</ins><span class="cx"> 
</span><span class="cx">                         if ( strtolower($arreach['name']) == 'style' ) {
</span><span class="cx">                                 $orig_value = $arreach['value'];
</span><del>-
</del><span class="cx">                                 $value = safecss_filter_attr($orig_value);
</span><span class="cx"> 
</span><span class="cx">                                 if ( empty($value) )
</span><span class="cx">                                         continue;
</span><span class="cx"> 
</span><span class="cx">                                 $arreach['value'] = $value;
</span><del>-
</del><span class="cx">                                 $arreach['whole'] = str_replace($orig_value, $value, $arreach['whole']);
</span><span class="cx">                         }
</span><span class="cx"> 
</span><span class="lines">@@ -707,7 +704,6 @@
</span><span class="cx">         } # foreach
</span><span class="cx"> 
</span><span class="cx">         # Remove any &quot;&lt;&quot; or &quot;&gt;&quot; characters
</span><del>-
</del><span class="cx">         $attr2 = preg_replace('/[&lt;&gt;]/', '', $attr2);
</span><span class="cx"> 
</span><span class="cx">         return &quot;&lt;$element$attr2$xhtml_slash&gt;&quot;;
</span></span></pre>
</div>
</div>

</body>
</html>