Ticket #53: 0000053-balancetags-patch2.diff
File 0000053-balancetags-patch2.diff, 2.6 KB (added by , 19 years ago) |
---|
-
.php
old new 176 176 @license GPL v2.0 177 177 @notes 178 178 @changelog 179 --- Modified by Scott Reilly (coffee2code) 02 Aug 2004 179 180 1.2 ***TODO*** Make better - change loop condition to $text 180 181 1.1 Fixed handling of append/stack pop order of end text 181 182 Added Cleaning Hooks … … 195 196 $text = preg_replace('#<([0-9]{1})#', '<$1', $text); 196 197 197 198 while (preg_match("/<(\/?\w*)\s*([^>]*)>/",$text,$regex)) { 198 $newtext = $newtext .$tagqueue;199 $newtext .= $tagqueue; 199 200 200 201 $i = strpos($text,$regex[0]); 201 $l = strlen($ tagqueue) + strlen($regex[0]);202 $l = strlen($regex[0]); 202 203 203 204 // clear the shifter 204 205 $tagqueue = ''; … … 234 235 235 236 // Tag Cleaning 236 237 237 // Push if not img or br or hr 238 if($tag != 'br' && $tag != 'img' && $tag != 'hr') { 238 // If self-closing or '', don't do anything. 239 if((substr($regex[2],-1) == '/') || ($tag == '')) { 240 } 241 // ElseIf it's a known single-entity tag but it doesn't close itself, do so 242 elseif ($tag == 'br' || $tag == 'img' || $tag == 'hr' || $tag == 'input') { 243 $regex[2] .= '/'; 244 } else { // Push the tag onto the stack 245 // If the top of the stack is the same as the tag we want to push, close previous tag 246 if (($stacksize > 0) && ($tag != 'div') && ($tagstack[$stacksize - 1] == $tag)) { 247 $tagqueue = '</' . array_pop ($tagstack) . '>'; 248 $stacksize--; 249 } 239 250 $stacksize = array_push ($tagstack, $tag); 240 251 } 241 252 242 253 // Attributes 243 // $attributes = $regex[2];244 254 $attributes = $regex[2]; 245 255 if($attributes) { 246 256 $attributes = ' '.$attributes; 247 257 } 248 258 $tag = '<'.$tag.$attributes.'>'; 259 //If already queuing a close tag, then put this tag on, too 260 if ($tagqueue) { 261 $tagqueue .= $tag; 262 $tag = ''; 263 } 249 264 } 250 265 $newtext .= substr($text,0,$i) . $tag; 251 266 $text = substr($text,$i+$l); 252 267 } 253 268 254 269 // Clear Tag Queue 255 $newtext = $newtext .$tagqueue;270 $newtext .= $tagqueue; 256 271 257 272 // Add Remaining text 258 273 $newtext .= $text; 259 274 260 275 // Empty Stack 261 276 while($x = array_pop($tagstack)) { 262 $newtext = $newtext .'</' . $x . '>'; // Add remaining tags to close277 $newtext .= '</' . $x . '>'; // Add remaining tags to close 263 278 } 264 279 265 280 // WP fix for the bug with HTML comments