Fix tag order when closing open tags with TextHelper::truncate()

This commit is contained in:
Kyle Robinson Young 2011-12-25 09:10:50 -08:00
parent 4e7e06fa9f
commit acca796d10
2 changed files with 10 additions and 4 deletions

View file

@ -287,9 +287,15 @@ class TextHelper extends AppHelper {
$bits = mb_substr($truncate, $spacepos);
preg_match_all('/<\/([a-z]+)>/', $bits, $droppedTags, PREG_SET_ORDER);
if (!empty($droppedTags)) {
foreach ($droppedTags as $closingTag) {
if (!in_array($closingTag[1], $openTags)) {
array_unshift($openTags, $closingTag[1]);
if (!empty($openTags)) {
foreach ($droppedTags as $closingTag) {
if (!in_array($closingTag[1], $openTags)) {
array_unshift($openTags, $closingTag[1]);
}
}
} else {
foreach ($droppedTags as $closingTag) {
array_push($openTags, $closingTag[1]);
}
}
}