Make WordPress Core

Changeset 13914


Ignore:
Timestamp:
04/01/2010 01:18:34 PM (16 years ago)
Author:
dd32
Message:

Whitespace and coding standards cleanup for balanceTags(). See #11968

File:
1 edited

Legend:

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

    r13913 r13914  
    10291029 */
    10301030function force_balance_tags( $text ) {
    1031     $tagstack = array(); $stacksize = 0; $tagqueue = ''; $newtext = '';
    1032     $single_tags = array('br', 'hr', 'img', 'input'); //Known single-entity/self-closing tags
    1033     $nestable_tags = array('blockquote', 'div', 'span'); //Tags that can be immediately nested within themselves
    1034 
    1035     # WP bug fix for comments - in case you REALLY meant to type '< !--'
     1031    $tagstack = array();
     1032    $stacksize = 0;
     1033    $tagqueue = '';
     1034    $newtext = '';
     1035    $single_tags = array('br', 'hr', 'img', 'input'); // Known single-entity/self-closing tags
     1036    $nestable_tags = array('blockquote', 'div', 'span'); // Tags that can be immediately nested within themselves
     1037
     1038    // WP bug fix for comments - in case you REALLY meant to type '< !--'
    10361039    $text = str_replace('< !--', '<    !--', $text);
    1037     # WP bug fix for LOVE <3 (and other situations with '<' before a number)
     1040    // WP bug fix for LOVE <3 (and other situations with '<' before a number)
    10381041    $text = preg_replace('#<([0-9]{1})#', '&lt;$1', $text);
    10391042
    1040     while (preg_match("/<(\/?[\w:]*)\s*([^>]*)>/",$text,$regex)) {
     1043    while ( preg_match("/<(\/?[\w:]*)\s*([^>]*)>/", $text, $regex) ) {
    10411044        $newtext .= $tagqueue;
    10421045
    1043         $i = strpos($text,$regex[0]);
     1046        $i = strpos($text, $regex[0]);
    10441047        $l = strlen($regex[0]);
    10451048
     
    10501053            $tag = strtolower(substr($regex[1],1));
    10511054            // if too many closing tags
    1052             if($stacksize <= 0) {
     1055            if( $stacksize <= 0 ) {
    10531056                $tag = '';
    1054                 //or close to be safe $tag = '/' . $tag;
     1057                // or close to be safe $tag = '/' . $tag;
    10551058            }
    10561059            // if stacktop value = tag close value then pop
    1057             else if ($tagstack[$stacksize - 1] == $tag) { // found closing tag
     1060            else if ( $tagstack[$stacksize - 1] == $tag ) { // found closing tag
    10581061                $tag = '</' . $tag . '>'; // Close Tag
    10591062                // Pop
    1060                 array_pop ($tagstack);
     1063                array_pop( $tagstack );
    10611064                $stacksize--;
    10621065            } else { // closing tag not at top, search for it
    1063                 for ($j=$stacksize-1;$j>=0;$j--) {
    1064                     if ($tagstack[$j] == $tag) {
     1066                for ( $j = $stacksize-1; $j >= 0; $j-- ) {
     1067                    if ( $tagstack[$j] == $tag ) {
    10651068                    // add tag to tagqueue
    1066                         for ($k=$stacksize-1;$k>=$j;$k--){
    1067                             $tagqueue .= '</' . array_pop ($tagstack) . '>';
     1069                        for ( $k = $stacksize-1; $k >= $j; $k--) {
     1070                            $tagqueue .= '</' . array_pop( $tagstack ) . '>';
    10681071                            $stacksize--;
    10691072                        }
     
    10791082
    10801083            // If self-closing or '', don't do anything.
    1081             if((substr($regex[2],-1) == '/') || ($tag == '')) {
     1084            if ( substr($regex[2],-1) == '/' || $tag == '' ) {
     1085                // do nothing
    10821086            }
    10831087            // ElseIf it's a known single-entity tag but it doesn't close itself, do so
     
    10861090            } else {    // Push the tag onto the stack
    10871091                // If the top of the stack is the same as the tag we want to push, close previous tag
    1088                 if (($stacksize > 0) && !in_array($tag, $nestable_tags) && ($tagstack[$stacksize - 1] == $tag)) {
     1092                if ( $stacksize > 0 && !in_array($tag, $nestable_tags) && $tagstack[$stacksize - 1] == $tag ) {
    10891093                    $tagqueue = '</' . array_pop ($tagstack) . '>';
    10901094                    $stacksize--;
     
    10951099            // Attributes
    10961100            $attributes = $regex[2];
    1097             if($attributes) {
     1101            if( !empty($attributes) )
    10981102                $attributes = ' '.$attributes;
    1099             }
    1100             $tag = '<'.$tag.$attributes.'>';
     1103
     1104            $tag = '<' . $tag . $attributes . '>';
    11011105            //If already queuing a close tag, then put this tag on, too
    1102             if ($tagqueue) {
     1106            if ( !empty($tagqueue) ) {
    11031107                $tagqueue .= $tag;
    11041108                $tag = '';
    11051109            }
    11061110        }
    1107         $newtext .= substr($text,0,$i) . $tag;
    1108         $text = substr($text,$i+$l);
     1111        $newtext .= substr($text, 0, $i) . $tag;
     1112        $text = substr($text, $i + $l);
    11091113    }
    11101114
     
    11161120
    11171121    // Empty Stack
    1118     while($x = array_pop($tagstack)) {
     1122    while( $x = array_pop($tagstack) )
    11191123        $newtext .= '</' . $x . '>'; // Add remaining tags to close
    1120     }
    11211124
    11221125    // WP fix for the bug with HTML comments
Note: See TracChangeset for help on using the changeset viewer.