Changeset 13914
- Timestamp:
- 04/01/2010 01:18:34 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/wp-includes/formatting.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/formatting.php
r13913 r13914 1029 1029 */ 1030 1030 function 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 '< !--' 1036 1039 $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) 1038 1041 $text = preg_replace('#<([0-9]{1})#', '<$1', $text); 1039 1042 1040 while ( preg_match("/<(\/?[\w:]*)\s*([^>]*)>/",$text,$regex)) {1043 while ( preg_match("/<(\/?[\w:]*)\s*([^>]*)>/", $text, $regex) ) { 1041 1044 $newtext .= $tagqueue; 1042 1045 1043 $i = strpos($text, $regex[0]);1046 $i = strpos($text, $regex[0]); 1044 1047 $l = strlen($regex[0]); 1045 1048 … … 1050 1053 $tag = strtolower(substr($regex[1],1)); 1051 1054 // if too many closing tags 1052 if( $stacksize <= 0) {1055 if( $stacksize <= 0 ) { 1053 1056 $tag = ''; 1054 // or close to be safe $tag = '/' . $tag;1057 // or close to be safe $tag = '/' . $tag; 1055 1058 } 1056 1059 // if stacktop value = tag close value then pop 1057 else if ( $tagstack[$stacksize - 1] == $tag) { // found closing tag1060 else if ( $tagstack[$stacksize - 1] == $tag ) { // found closing tag 1058 1061 $tag = '</' . $tag . '>'; // Close Tag 1059 1062 // Pop 1060 array_pop ($tagstack);1063 array_pop( $tagstack ); 1061 1064 $stacksize--; 1062 1065 } 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 ) { 1065 1068 // 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 ) . '>'; 1068 1071 $stacksize--; 1069 1072 } … … 1079 1082 1080 1083 // 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 1082 1086 } 1083 1087 // ElseIf it's a known single-entity tag but it doesn't close itself, do so … … 1086 1090 } else { // Push the tag onto the stack 1087 1091 // 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 ) { 1089 1093 $tagqueue = '</' . array_pop ($tagstack) . '>'; 1090 1094 $stacksize--; … … 1095 1099 // Attributes 1096 1100 $attributes = $regex[2]; 1097 if( $attributes) {1101 if( !empty($attributes) ) 1098 1102 $attributes = ' '.$attributes; 1099 } 1100 $tag = '<' .$tag.$attributes.'>';1103 1104 $tag = '<' . $tag . $attributes . '>'; 1101 1105 //If already queuing a close tag, then put this tag on, too 1102 if ( $tagqueue) {1106 if ( !empty($tagqueue) ) { 1103 1107 $tagqueue .= $tag; 1104 1108 $tag = ''; 1105 1109 } 1106 1110 } 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); 1109 1113 } 1110 1114 … … 1116 1120 1117 1121 // Empty Stack 1118 while( $x = array_pop($tagstack)) {1122 while( $x = array_pop($tagstack) ) 1119 1123 $newtext .= '</' . $x . '>'; // Add remaining tags to close 1120 }1121 1124 1122 1125 // WP fix for the bug with HTML comments
Note: See TracChangeset
for help on using the changeset viewer.