The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Allow x nested quotes
how can I modify this function to allow x amount of nested quotes?
Code:
// ###################### Start strip_quotes ####################### function strip_quotes($text) { $lowertext = strtolower($text); // find all [quote tags $start_pos = array(); $curpos = 0; do { $pos = strpos($lowertext, '[quote', $curpos); if ($pos !== false) { $start_pos["$pos"] = 'start'; $curpos = $pos + 6; } } while ($pos !== false); if (sizeof($start_pos) == 0) { return $text; } // find all [/quote] tags $end_pos = array(); $curpos = 0; do { $pos = strpos($lowertext, '[/quote]', $curpos); if ($pos !== false) { $end_pos["$pos"] = 'end'; $curpos = $pos + 8; } } while ($pos !== false); if (sizeof($end_pos) == 0) { return $text; } // merge them together and sort based on position in string $pos_list = $start_pos + $end_pos; ksort($pos_list); do { // build a stack that represents when a quote tag is opened // and add non-quote text to the new string $stack = array(); $newtext = ''; $substr_pos = 0; foreach ($pos_list AS $pos => $type) { $stacksize = sizeof($stack); if ($type == 'start') { // empty stack, so add from the last close tag or the beginning of the string if ($stacksize == 0) { $newtext .= substr($text, $substr_pos, $pos - $substr_pos); } array_push($stack, $pos); } else { // pop off the latest opened tag if ($stacksize) { array_pop($stack); $substr_pos = $pos + 8; } } } // add any trailing text $newtext .= substr($text, $substr_pos); // check to see if there's a stack remaining, remove those points // as key points, and repeat. Allows emulation of a non-greedy-type // recursion. if ($stack) { foreach ($stack AS $pos) { unset($pos_list["$pos"]); } } } while ($stack); return $newtext; } Code:
// ###################### Start strip_quotes ####################### function strip_quotes($text) { $nestlevel = 3; $lowertext = strtolower($text); // find all [quote tags $start_pos = array(); $curpos = 0; $nestcount = 0; do { $pos = strpos($lowertext, '[quote', $curpos); if ($pos !== false) { $start_pos["$pos"] = 'start'; $curpos = $pos + 6; $nestcount++; } } while (($pos !== false) && ($nestcount < $nestlevel)); if (sizeof($start_pos) == 0) { return $text; } // find all [/quote] tags $end_pos = array(); $curpos = 0; $nestcount = 0; do { $pos = strpos($lowertext, '[/quote]', $curpos); if ($pos !== false) { $end_pos["$pos"] = 'end'; $curpos = $pos + 8; $nestcount++; } } while (($pos !== false) && ($nestcount < $nestlevel)); if (sizeof($end_pos) == 0) { return $text; } // merge them together and sort based on position in string $pos_list = $start_pos + $end_pos; ksort($pos_list); do { // build a stack that represents when a quote tag is opened // and add non-quote text to the new string $stack = array(); $newtext = ''; $substr_pos = 0; foreach ($pos_list AS $pos => $type) { $stacksize = sizeof($stack); if ($type == 'start') { // empty stack, so add from the last close tag or the beginning of the string if ($stacksize == 0) { $newtext .= substr($text, $substr_pos, $pos - $substr_pos); } array_push($stack, $pos); } else { // pop off the latest opened tag if ($stacksize) { array_pop($stack); $substr_pos = $pos + 8; } } } // add any trailing text $newtext .= substr($text, $substr_pos); // check to see if there's a stack remaining, remove those points // as key points, and repeat. Allows emulation of a non-greedy-type // recursion. if ($stack) { foreach ($stack AS $pos) { unset($pos_list["$pos"]); } } } while ($stack); return $newtext; } |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|