Make WordPress Core

Changeset 2057


Ignore:
Timestamp:
01/06/2005 10:24:11 AM (22 years ago)
Author:
saxmatt
Message:

Patch for balanceTags from Scott Reilly: http://mosquito.wordpress.org/view.php?id=53

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions-formatting.php

    r2056 r2057  
    316316 @notes           
    317317 @changelog       
     318 ---  Modified by Scott Reilly (coffee2code) 02 Aug 2004
    318319             1.2  ***TODO*** Make better - change loop condition to $text
    319320             1.1  Fixed handling of append/stack pop order of end text
     
    335336
    336337        while (preg_match("/<(\/?\w*)\s*([^>]*)>/",$text,$regex)) {
    337                 $newtext = $newtext . $tagqueue;
     338                $newtext .= $tagqueue;
    338339
    339340                $i = strpos($text,$regex[0]);
    340                 $l = strlen($tagqueue) + strlen($regex[0]);
     341                $l = strlen($regex[0]);
    341342
    342343                // clear the shifter
     
    374375                        // Tag Cleaning
    375376
    376                         // Push if not img or br or hr
    377                         if($tag != 'br' && $tag != 'img' && $tag != 'hr') {
     377                        // If self-closing or '', don't do anything.
     378                        if((substr($regex[2],-1) == '/') || ($tag == '')) {
     379                        }
     380                        // ElseIf it's a known single-entity tag but it doesn't close itself, do so
     381                        elseif ($tag == 'br' || $tag == 'img' || $tag == 'hr' || $tag == 'input') {
     382                                $regex[2] .= '/';
     383                        } else {        // Push the tag onto the stack
     384                                // If the top of the stack is the same as the tag we want to push, close previous tag
     385                                if (($stacksize > 0) && ($tag != 'div') && ($tagstack[$stacksize - 1] == $tag)) {
     386                                        $tagqueue = '</' . array_pop ($tagstack) . '>';
     387                                        $stacksize--;
     388                                }
    378389                                $stacksize = array_push ($tagstack, $tag);
    379390                        }
    380391
    381392                        // Attributes
    382                         // $attributes = $regex[2];
    383393                        $attributes = $regex[2];
    384394                        if($attributes) {
     
    386396                        }
    387397                        $tag = '<'.$tag.$attributes.'>';
     398                        //If already queuing a close tag, then put this tag on, too
     399                        if ($tagqueue) {
     400                                $tagqueue .= $tag;
     401                                $tag = '';
     402                        }
    388403                }
    389404                $newtext .= substr($text,0,$i) . $tag;
     
    392407
    393408        // Clear Tag Queue
    394         $newtext = $newtext . $tagqueue;
     409        $newtext .= $tagqueue;
    395410
    396411        // Add Remaining text
     
    399414        // Empty Stack
    400415        while($x = array_pop($tagstack)) {
    401                 $newtext = $newtext . '</' . $x . '>'; // Add remaining tags to close     
     416                $newtext .= '</' . $x . '>'; // Add remaining tags to close
    402417        }
    403418
Note: See TracChangeset for help on using the changeset viewer.