vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Modification Requests/Questions (Unpaid) (https://vborg.vbsupport.ru/forumdisplay.php?f=112)
-   -   Allow x nested quotes (https://vborg.vbsupport.ru/showthread.php?t=74820)

Boots 01-21-2005 03:26 PM

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;
}

would this work?

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;
}



All times are GMT. The time now is 11:12 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01069 seconds
  • Memory Usage 1,742KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (1)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete