• Login
  • Register
  • Zoek
This Thread
  • Everywhere
  • This Thread
  • This Forum
  • Articles
  • Pages
  • Forum
  • Filebase Entry
  • More Options

ICTscripters

Dé plek voor IT

Dé plek voor IT

Login

Geavanceerde opties
  1. Home
  2. Forum
    1. Alle berichten
    2. Recente activiteiten
  3. ICT Nieuws
  4. Blog
  5. Marktplaats
    1. Werk
    2. Advertenties
    3. Domeinnamen
    4. Websites
    5. Design & lay-outs
    6. Scripts
    7. Overige
  6. Design
  7. Leden
    1. Actieve bezoekers
    2. Team
    3. Leden zoeken
  8. Downloads
  9. Goedkope domeinnamen
  1. Home
  2. Forum
    1. Alle berichten
    2. Recente activiteiten
  3. ICT Nieuws
  4. Blog
  5. Marktplaats
    1. Werk
    2. Advertenties
    3. Domeinnamen
    4. Websites
    5. Design & lay-outs
    6. Scripts
    7. Overige
  6. Design
  7. Leden
    1. Actieve bezoekers
    2. Team
    3. Leden zoeken
  8. Downloads
  9. Goedkope domeinnamen
  1. Home
  2. Forum
    1. Alle berichten
    2. Recente activiteiten
  3. ICT Nieuws
  4. Blog
  5. Marktplaats
    1. Werk
    2. Advertenties
    3. Domeinnamen
    4. Websites
    5. Design & lay-outs
    6. Scripts
    7. Overige
  6. Design
  7. Leden
    1. Actieve bezoekers
    2. Team
    3. Leden zoeken
  8. Downloads
  9. Goedkope domeinnamen
  1. Dé plek voor IT - ICTscripters
  2. Forum
  3. Scripting & programmeren
  4. PHP + SQL

Forum

  • Op zoek naar de legends

    Syntax 5 januari 2026 om 13:50
  • Na 15 jaar terug van weggeweest: iCriminals.nl is terug (BETA)!

    Syntax 4 januari 2026 om 10:58
  • Developer Gezocht

    K.Rens 30 december 2025 om 12:32
  • [FREE] WeFact Hosting module

    Jeroen.G 13 oktober 2025 om 14:09
  • Help testers nodig voor android app Urgent

    urgentotservices 26 september 2025 om 10:21
  • Versio vervanger

    Jeroen.G 25 augustus 2025 om 15:56
  • Afspraken systeem met planbeperking

    Lijno 1 augustus 2025 om 23:04
  • Partner Gezocht om meerdere NFT Collecties op Open Sea te Plaatsen

    NFT Art Designer 1 maart 2025 om 14:08

Marktplaats

  • 321 Nieuwe Domeinnamen December 2025

    shiga 1 januari 2026 om 10:26
  • Meerdere mafia game template te koop

    Syntax 28 december 2025 om 21:20
  • Van een pixelige afbeelding naar een strakke, moderne website

    Syntax 21 december 2025 om 17:05

ubb parser haalt enters weg

  • Luc
  • 21 juni 2010 om 11:45
  • Luc
    Software Engineer
    Ontvangen Reacties
    44
    Berichten
    1.986
    • 21 juni 2010 om 11:45
    • #1

    Beste leden van criminalspoint, op dit moment ben ik druk bezig aan één nieuwe website. Maar daarvoor heb ik een stack based ubb script voor nodig. Nu ik er eindelijk een heb gevonden die werkt, zit ik met één groter probleem.

    Wanneer je 2 enters typt zet hij er maar één neer, terwijl er 2 nodig zijn. Wanneer ik er dan echter nl2br overheen gooi, wordt het script zo ongeveer per enter 2 enters neergezet. Ook niet echt de bedoeling.

    Nu hoop ik dat iemand me hiermee kan helpen. Voor live voorbeeld PM me.

    PHP
    <?php
    /*
    *   Auteur: Grayen Myrith
    */
    class ubb
    {
        private $aPieces = array();
        
        private $aTree = array();
        
        private $bParse = true;
        
        private $bParagraphise = true;
        
        private $aAlias = array
        (
            '*' => 'li',
            'list' => 'ul',
            'ulist' => 'ul',
            'olist' => 'ol',
            'url' => 'a',
            'quote' => 'blockquote',
            'google' => 'search'
        );
        
        /*
        
        allowed: alle tags die in de gedefineerde tag mogen staan.
        child: de verplichte childs die een tag moet hebben.
        parent: de verplichte parent die en tag moet hebben.
        inline: is het inline element? of niet?
        solid: is het een block element waarbij eerst alle tags moeten worden gesloten? Voorbeelden hiervan: table, ul, ol dat moet je uiteraard niet aan tags als td gaan geven, want dan krijg je bijvoorbeeld het volgende: <table><tr></tr></table><td>tekst</td> (en dat willen we natuurljik niet :P)
        single: de tag heeft geen bij behorende sluitende tag.
        master: door deze item toe te voegen negeert de tag alle regels (Pas op! bij deze tags kun je niet meer gebruik maken van $this->parse('tag') functionaliteit)
        
        */
        
        public $aFilters = array
        (
            'basic' => array
            (
                'b' => array
                (
                    'allowed' => 'all',
                    'solid' => false,
                    'inline' => true
                ),
                'i' => array
                (
                    'allowed' => 'all',
                    'solid' => false,
                    'inline' => true
                ),
                'u' => array
                (
                    'allowed' => 'all',
                    'solid' => false,
                    'inline' => true
                ),
                's' => array
                (
                    'allowed' => 'all',
                    'solid' => false,
                    'inline' => true
                ),
                'sub' => array
                (
                    'allowed' => 'all',
                    'solid' => false,
                    'inline' => true
                ),
                'sup' => array
                (
                    'allowed' => 'all',
                    'solid' => false,
                    'inline' => true
                )
            ),
            'extended' => array
            (
                'code' => array
                (
                    'allowed' => 'all',
                    'solid' => true,
                    'inline' => false
                ),
                'h2' => array
                (
                    'allowed' => 'all',
                    'solid' => true,
                    'inline' => false
                ),
                'h3' => array
                (
                    'allowed' => 'all',
                    'solid' => true,
                    'inline' => false
                ),
                'h4' => array
                (
                    'allowed' => 'all',
                    'solid' => true,
                    'inline' => false
                ),
                'h5' => array
                (
                    'allowed' => 'all',
                    'solid' => true,
                    'inline' => false
                ),
                'h6' => array
                (
                    'allowed' => 'all',
                    'solid' => true,
                    'inline' => false
                ),
                'blockquote' => array
                (
                    'allowed' => 'all',
                    'solid' => true,
                    'inline' => false,
                    'master' => true
                ),
                'hr' => array
                (
                    'allowed' => 'all',
                    'solid' => true,
                    'inline' => false,
                    'single' => true
                )
            ),
            'links' => array
            (
                'a' => array
                (
                    'allowed' => 'all',
                    'solid' => false,
                    'inline' => true
                ),
                'search' => array
                (
                    'allowed' => 'all',
                    'solid' => false,
                    'inline' => true
                )
            ),
            'images' => array
            (
                'img' => array
                (
                    'allowed' => 'none',
                    'solid' => true,
                    'inline' => false,
                    'single' => true
                )
            ),
            'tables' => array
            (
                'table' => array
                (
                    'allowed' => 'all',
                    'child' => array('tr'),
                    'solid' => true,
                    'inline' => false
                ),
                'tr' => array
                (
                    'allowed' => 'all',
                    'parent' => array('table'),
                    'child' => array('td', 'th'),
                    'solid' => false,
                    'inline' => false
                ),
                'th' => array
                (
                    'allowed' => 'all',
                    'parent' => array('tr'),
                    'solid' => false,
                    'inline' => false
                ),
                'td' => array
                (
                    'allowed' => 'all',
                    'parent' => array('tr'),
                    'solid' => false,
                    'inline' => false
                )
            ),
            'lists' => array
            (
                'ol' => array
                (
                    'allowed' => 'all',
                    'child' => array('li'),
                    'solid' => true,
                    'inline' => false
                ),
                'ul' => array
                (
                    'allowed' => 'all',
                    'child' => array('li'),
                    'solid' => true,
                    'inline' => false
                ),
                'li' => array
                (
                    'allowed' => 'all',
                    'parent' => array('ul', 'ol'),
                    'solid' => false,
                    'inline' => false
                )  
            )
        );
        
        private $aFilter = array('basic', 'extended', 'links', 'images', 'lists', 'tables');
        
        private $aTags = array();
        
        public $sText = '';
        
        public $aText = array();
        
        public function __construct($sText)
        { 
            $this->sText = trim($sText);
            
            foreach($this->aFilters as $sName => $aTags)
            {
                if(in_array($sName, $this->aFilter) === true)
                {
                    $this->aTags = array_merge($this->aTags, $aTags);
                }
            }
        }
        
        private function cleanWhiteSpace()
        {
            $this->sText = preg_replace(array("/\\n{3,}/", "/\\n *\\n/"), "\\n\\n", str_replace(array("\\r\\n", "\\n\\r"), "\\n", $this->sText));
        }
        
        private function realEmpty($sString)
        {
            return !(empty($sString) === false &amp;&amp; substr_count($sString, "\\n") != strlen($sString));
        }
        
        private function getPieces()
        {
            # De tekst die in delen moet worden gehakt.
            $sText = $this->sText;
            
            # De counter voor de key waarden voor elk stukje.
            $i = 0;
            
            # De tekst dat zich nog voor de tag bevindt.
            $sOther = '';
            
            while(strlen($sText) > 0)
            {
                $iOpen = strpos($sText, '[');
                $iClose = strpos($sText, ']');
                
                # Er is geen tag gevonden, het is dus tekst.
                if($iClose === false || $iOpen === false)
                {
                    $this->aPieces['t'.$i] = $sText;
                    $i++;
                    
                    return true;
                }
                else
                {
                    # Is het echt wel een tag, zoals [tag] en niet zomaar twee haakjes als ][.
                    while($iOpen > $iClose)
                    {
                        $iClose = strpos($sText, ']', $iClose + 1);
                        
                        # Het was geen echte tag, dus het is tekst.
                        if($iClose === false)
                        {
                            $this->aPieces['t'.$i] = $sText;
                            $i++;
                            
                            return true;
                        }
                    }
                    
                    # Zit er niet nog een [ voor de tag.
                    $iTemp = strpos($sText, '[', $iOpen + 1);
                    while($iOpen < $iTemp &amp;&amp; $iTemp < $iClose)
                    {
                        $iOpen = $iTemp;
                        $iTemp = strpos($sText, '[', $iOpen + 1);
                    }
                    
                    # Er is een tag gevonden.
                    if($iOpen < $iClose)
                    {
                        $sTag = substr($sText, $iOpen, $iClose - $iOpen + 1);
                        
                        # Heeft de tag wel een waarde en is het niet gewoon [].
                        $sTagValue = substr($sTag, 1, -1);
                        if(empty($sTagValue) === true)
                        {
                            $iOpen = $iClose + 1;
                        }
                        
                        # De tekst voor de tag ophalen.
                        $sTemp = substr($sText, 0, $iOpen);
                        if(empty($sTemp) === false)
                        {
                            $sOther .= $sTemp;
                        }
                        
                        # Is de tag niet leeg?
                        if(empty($sTagValue) === false)
                        {
                            # Stond er nog tekst voor de tag?
                            if(empty($sOther) === false)
                            {
                                $this->aPieces['t'.$i] = $sOther;
                                $i++;
                                
                                $sOther = '';
                            }
                            
                            # Stop de tag in de array.
                            $this->aPieces[($sTag{1} == '/' ? 'c' : 'o').$i] = $sTag;
                            $i++;
                        }
                        
                        # Hakt het al geparsde deel van de tekst af.
                        $sText = substr($sText, $iClose + 1);
                    }
                }
            }
        }
        
        private function createTree()
        {
            foreach($this->aPieces as $sKey => $sPiece)
            {
                switch($sKey{0})
                {
                    case 't':
                        $this->append($this->createText($sPiece));
                    break;
                    
                    case 'o':
                        $this->append($this->createOpenTag($sPiece));
                    break;
                    
                    case 'c':
                        $this->append($this->createCloseTag($sPiece));
                    break;
                }
            }
        }
        
        private function append($aData)
        {
            $this->aTree[] = $aData;
        }
        
        private function createOpenTag($sTag)
        {
            # Zet alle gegevens over de tag in een array.
            $aNode = array();
            
            $aNode['type'] = 'open';
            $aNode['text'] = $sTag;
            
            # De tag zonder haakjes.
            $sTag = substr($sTag, 1, -1);
            
            if(strpos($sTag, ' ') == true || strpos($sTag, '=') == true)
            {
                $aNode['tag'] = strtok($sTag, " =");
            }
            else
            {
                $aNode['tag'] = $sTag;
            }
            
            $aNode['attributes'] = array();
            
            $iSpace = strpos($aNode['text'], ' ');
            $iIsSign = strpos($aNode['text'], '=');
            
            if($iSpace !== false || $iIsSign !== false)
            {
                while(preg_match('#([a-zA-Z0-9]+?)=\\'(.*?)\\'(\\s|$)#si', $sTag, $aMatches) == true || preg_match('#([a-zA-Z0-9]+?)=(.*?)(\\s|$)#si', $sTag, $aMatches) == true)
                {
                    $sValue = trim($aMatches[2]);
                    if(empty($sValue) === false)
                    {
                        $aNode['attributes'][isset($this->aAlias[trim($aMatches[1])]) === true ? $this->aAlias[trim($aMatches[1])] : trim($aMatches[1])] = str_replace(array('"', "'"), '', $sValue);
                    }
                    $sTag = str_replace($aMatches[0], '', $sTag);
                }
            }
            
            # Vervangt de waarde naar de alias.
            if(isset($this->aAlias[$aNode['tag']]) === true)
            {
                $aNode['tag'] = $this->aAlias[$aNode['tag']];
                
                if($iSpace === false &amp;&amp; $iIsSign === false)
                {
                    $aNode['text'] = '['.$aNode['tag'].']';
                }
                else
                {
                    if($iSpace > $iIsSign || $iIsSign !== false &amp;&amp; $iSpace === false)
                    {
                        $aNode['text'] = '['.$aNode['tag'].substr($aNode['text'], $iIsSign).']';
                    }
                    else if($iIsSign > $iSpace || $iSpace === false &amp;&amp; $iIsSign !== false)
                    {
                        $aNode['text'] = '['.$aNode['tag'].substr($aNode['text'], $iSpace).']';
                    }
                }
            }
            
            return $aNode;
        }
        
        private function createCloseTag($sTag)
        {
            $aNode = array();
            
            $aNode['type'] = 'close';
            $aNode['text'] = $sTag;
            
            $aNode['tag'] = substr($sTag, 2, -1);
            
            # Kijken of er een alias voor bestaat.
            $aNode['tag'] = isset($this->aAlias[$aNode['tag']]) === true ? $this->aAlias[$aNode['tag']] : $aNode['tag'];
            
            return $aNode;
        }
        
        private function createText($sText)
        {
            $aNode = array();
            
            $aNode['type'] = 'text';
            $aNode['text'] = $sText;
            
            return $aNode;
        }
        
        private function validateTree()
        {
            # Is er een child toegevoegd (en is dus nog niet gesloten)?
            $sOpened = '';
            
            # Welk block element geopend is als laatst geopend?
            $bSolidOpened = false;
            
            $aNewTree = array();
            $aOpenTags = array();
            
            $aNode = array_shift($this->aTree);
            
            while(empty($aNode) === false)
            {
                $aPrevNode = end($aNewTree);
                
                switch($aNode['type'])
                {
                    case 'text':
                        # Heeft de parent tag nog een bepaalde child nodig?
                        if($this->realEmpty($aNode['text']) === false &amp;&amp; empty($aOpenTags) === false &amp;&amp; ($vChild = $this->childNeeded(end($aOpenTags), 'text')) !== false &amp;&amp; is_bool($vChild) === false)
                        {
                            array_unshift($this->aTree, $this->createCloseTag('[/'.$vChild['tag'].']'));
                            array_unshift($this->aTree, $aNode);
                            array_unshift($this->aTree, $vChild);
                        }
                        else
                        {
                            # Als het vorige fragment ook tekst is, voeg deze dan samen.
                            if($aPrevNode['type'] === 'text')
                            {
                                $aNode['text'] = $aPrevNode['text'].$aNode['text'];
                                array_pop($aNewTree);
                            }
                            
                            # Als er een paragraaf in de tekst zit, sluit dan eerst alle open tags.
                            if(empty($aOpenTags) === false &amp;&amp; isset($this->aTags[end($aOpenTags)]) === true &amp;&amp; strpos($aNode['text'], "\\n\\n") !== false)
                            {
                                # Verwijder spaties links en recht van de tekst indien de tekst in een element staat.
                                $aNode['text'] = trim($aNode['text']);
                                
                                if($this->aTags[end($aOpenTags)]['inline'] === true)
                                {
                                    $aParagraphs = explode("\\n\\n", $aNode['text']);
                                    
                                    $aNode['text'] = array_shift($aParagraphs);
                                    $aNewTree[] = $aNode;
                                    
                                    while(end($aOpenTags) &amp;&amp; (isset($this->aTags[end($aOpenTags)]['single']) === false || $this->aTags[end($aOpenTags)]['single'] !== true))
                                    {
                                        $aNewTree[] = $this->createCloseTag('[/'.end($aOpenTags).']');
                                        array_pop($aOpenTags);
                                    }
                                    
                                    $aNode['text'] = "\\n\\n".implode("\\n\\n", $aParagraphs);
                                    $aNewTree[] = $aNode;
                                }
                                else
                                {
                                    $aNode['text'] = $aNode['text'];
                                    $aNewTree[] = $aNode;
                                }
                            }
                            else
                            {
                                $aNewTree[] = $aNode;
                            }
                        }
                    break;
                    
                    case 'open':
                        $bSkip = false;
                        
                        if(isset($this->aTags[$aNode['tag']]) === false)
                        {
                            $aNode['type'] = 'text';
                            if($aNode['type'] == 'text')
                            {
                                $aNode['text'] = $aPrevNode['text'].$aNode['text'];
                                array_pop($aNewTree);
                            }
                            $aNewTree[] = $aNode;
                        }
                        else
                        {
                            # Is de tag wel toegestaan binnen zijn parent?
                            if(empty($aOpenTags) === true || $this->isAllowed(end($aOpenTags), $aNode['tag']) === true)
                            {
                                # Voorkomt dat een inline element om een block element komt te staan.
                                if(isset($this->aTags[end($aOpenTags)]) === true &amp;&amp; $this->aTags[end($aOpenTags)]['inline'] === true &amp;&amp; $this->aTags[$aNode['tag']]['inline'] === false)
                                {
                                    array_pop($aNewTree);
                                    array_pop($aOpenTags);
                                    
                                    continue;
                                }
                                
                                # Zorgt ervoor dat alle tags worden gesloten bij een nieuw block element.
                                if(isset($this->aTags[$aNode['tag']]['solid']) === true &amp;&amp; $this->aTags[$aNode['tag']]['solid'] === true)
                                {
                                    $bSolidOpened = true;
                                    
                                    while(end($aOpenTags) &amp;&amp; (isset($this->aTags[end($aOpenTags)]['single']) === false || $this->aTags[end($aOpenTags)]['single'] !== true) &amp;&amp; isset($this->aTags[end($aOpenTags)]['master']) === false)
                                    {
                                        $aNewTree[] = $this->createCloseTag('[/'.end($aOpenTags).']');
                                        array_pop($aOpenTags);
                                    }
                                }
                               
                                $vParent = $this->parentNeeded(end($aOpenTags), $aNode['tag']);
                                $vChild = $this->childNeeded(end($aOpenTags), $aNode['tag']);
                                
                                # Omdat we het gebruik van parent willen verkomen moeten we kijken of de vorige node niet al de juiste parent heeft aangemaakt.
                                if(is_bool($vParent) === false)
                                {
                                    if($aNode['tag'] == end($aOpenTags))
                                    {
                                        $aNewTree[] = $this->createCloseTag('[/'.$aNode['tag'].']');
                                        array_pop($aOpenTags);
                                    }
                                    else
                                    {
                                        array_unshift($this->aTree, $aNode);
                                        array_unshift($this->aTree, $vParent);
                                        
                                        $bSkip = true;
                                    }
                                }
                                
                                # Is een child noodzakelijk?
                                if(is_bool($vChild) === false)
                                {
                                    array_unshift($this->aTree, $aNode);
                                    array_unshift($this->aTree, $vChild);
                                    
                                    $bSkip = true;
                                }
                                
                                if($bSkip === false)
                                {
                                    # Voeg de tag toe aan de nieuwe tree.
                                    $aNewTree[] = $aNode;
                                    $aOpenTags[] = $aNode['tag'];
                                }
                            }
                        }
                    break;
                    
                    case 'close':
                        # Als er niks tussen de tags staat, haal ze dan weg.
                        if($aPrevNode['type'] == 'open' &amp;&amp; $aPrevNode['tag'] == $aNode['tag'])
                        {
                            array_pop($aNewTree);
                            array_pop($aOpenTags);
                        }
                        else
                        {
                            # Is de sluitende tag wel gelijk aan de geopende?
                            if(empty($aOpenTags) === false &amp;&amp; ($aNode['tag'] == end($aOpenTags)))
                            {
                                if(in_array($aNode['tag'], $aOpenTags) === true)
                                {
                                    $aNewTree[] = $aNode;
                                    array_pop($aOpenTags);
                                }
                            }
                            else if(isset($this->aTags[$aNode['tag']]) === false)
                            {
                                $aNode['type'] = 'text';
                                if($aNode['type'] == 'text')
                                {
                                    $aNode['text'] = $aPrevNode['text'].$aNode['text'];
                                    array_pop($aNewTree);
                                }
                                $aNewTree[] = $aNode;
                            }
                        }
                    break;
                }
                $aNode = array_shift($this->aTree);
            }
            # Sluit alle nog open tags.
            while(end($aOpenTags) &amp;&amp; (isset($this->aTags[end($aOpenTags)]['single']) === false || $this->aTags[end($aOpenTags)]['single'] !== true))
            {
                $aNewTree[] = $this->createCloseTag('[/'.end($aOpenTags).']');
                array_pop($aOpenTags);
            }
            
            # Update de oude tree.
            $this->aTree = $aNewTree;
        }
        
        private function childNeeded($sParent, $sChild)
        {
            # Er zijn geen verplichte childs.
            if(isset($this->aTags[$sParent]['child']) === false)
            {
                return false;
            }
            
            # De nieuwe child is al in orde.
            if(in_array($sChild, $this->aTags[$sParent]['child']) === true)
            {
                return false;
            }
            
            # Een child is nodig, dus moet er een worden toegevoegd.
            return $this->createOpenTag('['.$this->aTags[$sParent]['child'][0].']');
        }
        
        private function parentNeeded($sParent, $sChild)
        {
            # Er zijn geen verplichte parents.
            if(isset($this->aTags[$sChild]['parent']) === false)
            {
                return false;
            }
            
            # De parent is al in orde.
            if(in_array($sParent, $this->aTags[$sChild]['parent']) === true)
            {
                return false;
            }
            
            # Een andere parent is nodig, dus moet er een worden toegevoegd.
            return $this->createOpenTag('['.$this->aTags[$sChild]['parent'][0].']');
        }
        
        private function isAllowed($sParent, $sChild)
        {
            # Alle tags zijn toegestaan.
            if($this->aTags[$sParent]['allowed'] == 'all')
            {
                return true;
            }
            # Geen enkele tag is binnen deze tag toegestaan.
            if($this->aTags[$sParent]['allowed'] == 'none')
            {
                return false;
            }
            
            # Leest de argumenten uit.
            $aArguments = explode('^', $this->aTags[$sChild]['allowed']);
            $aTags = explode(',', $aArguments[1]);
            
            # Kijkt of de child aan de eisen voldoet.
            if($aArguments[0] == 'none' &amp;&amp; in_array($sChild, $aTags) === true)
            {
                return true;
            }
            if($aArguments[0] == 'all' &amp;&amp; in_array($sChild, $aTags) === true)
            {
                return false;
            }
            
            return false;
        }
        
        # Zodat de parser weet of hij zich in het eerste level bevindt of niet.
        private $iLevel = 0;
        
        # Zorgt ervoor dat de parse functie ook werkt binnen ubb methodes die je zelf aan heb gemaakt.
        private $bChangeSolid = false;
        
        private function parse($sStopTag = '')
        {
            # Als er niks is om te parsen.
            if(empty($this->aTree) === true)
            {
                return '';
            }
            
            # De tag van het block type dat open is.
            $aOpen = array();
            
            # De hoeveelheid tags er van het type block en hetzelfde zijn die open zijn.
            $iOpen = 0;
            
            # Wat het vorige type was.
            $bSolid = false;
            
            # Het type van het huidige element.
            $bNodeInline = false;
            
            # De counter voor de keys van de text array.
            $i = 0;
            
            $iLevel = $this->iLevel;
            
            $this->iLevel++;
            
            $sText = '';
            
            while($aNode = array_shift($this->aTree))
            {
                if($this->bParagraphise === true &amp;&amp; $iLevel == 0)
                {
                    # Is het een tag?
                    if(isset($aNode['tag']) === true &amp;&amp; isset($this->aTags[$aNode['tag']]) === true)
                    {
                        # Is geen tag open van het type block?
                        if(empty($aOpen) === true)
                        {
                            $bNodeInline = $this->aTags[$aNode['tag']]['solid'];
                        }
                    }
                    else if($aNode['type'] == 'text' &amp;&amp; empty($aOpen) === true &amp;&amp; empty($aNode['text']) === false)
                    {
                        $bNodeInline = false;
                    }
                    
                    # Stopt de tekst als een item in de tekst array.
                    if($bSolid !== $bNodeInline &amp;&amp; $this->realEmpty($sText) === false)
                    {
                        $this->aText[($bSolid === false ? 'i' : 'b').$i] = trim($sText);
                        $sText = '';
                        $i++;
                    }
                    
                    # Update het vorige type naar het huidige.
                    $bSolid = $bNodeInline;
                }
                
                if(isset($aNode['tag']) === true &amp;&amp; isset($this->aTags[$aNode['tag']]) === true)
                {
                    if($aNode['tag'] == $sStopTag)
                    {
                        $this->bChangeSolid = true;
                        return $sText;
                    }
                    else
                    {
                        if(method_exists($this, $aNode['tag']) === true)
                        {
                            if($this->bParse === true)
                            {
                                $sText .= $this->$aNode['tag']($aNode);
                            }
                            else
                            {
                                $sText .= $aNode['text'];
                            }
                        }
                    }
                }
                else
                {
                    $sText .= $aNode['text'];
                }
                
                # Zet de tekst in array formaat als dit aan staat.
                if($this->bParagraphise === true &amp;&amp; $iLevel == 0)
                {
                    # Is het een tag?
                    if(isset($aNode['tag']) === true &amp;&amp; isset($this->aTags[$aNode['tag']]) === true)
                    {
                        if(isset($this->aTags[$aNode['tag']]['master']) === true)
                        {
                            $this->aText['b'.$i] = trim($sText);
                            $sText = '';
                            $i++;
                            $aOpen = array();
                            $iOpen = 0;
                        }
                        else
                        {
                            # Er is een tag geopend van het type block.
                            if($aNode['type'] == 'open' &amp;&amp; $this->aTags[$aNode['tag']]['solid'] === true)
                            {
                                if(empty($aOpen) === true)
                                {
                                    $aOpen = $aNode;
                                }
                                
                                # Is het dezelfde tag als de geen die al open is?
                                if($aNode['tag'] == $aOpen['tag'])
                                {
                                    $iOpen++;
                                }
                            }
                            
                            # Er is een tag gesloten van het type block.
                            if(($aNode['type'] == 'close' &amp;&amp; $this->aTags[$aNode['tag']]['solid'] === true &amp;&amp; empty($aOpen) === false &amp;&amp; $aNode['tag'] == $aOpen['tag']) || $this->bChangeSolid === true)
                            {
                                $this->bChangeSolid = false;
                                
                                $iOpen--;
                                
                                if($iOpen == 0 &amp;&amp; $this->realEmpty($sText) === false)
                                {
                                    $this->aText[($bSolid === false ? 'i' : 'b').$i] = trim($sText);
                                    $sText = '';
                                    $i++;
                                    $aOpen = array();
                                }
                            }
                        }
                    }
                }
            }
            
            # Als paragrafen aanmaken aanstaat, maak dan paragrafen om de teksten.
            if($this->bParagraphise === true &amp;&amp; $iLevel == 0)
            {
                # Het overgebleven geparsde tekst toevoegen aan de tekst array.
                if($this->realEmpty($sText) === false)
                {
                    $this->aText[($bSolid === false ? 'i' : 'b').$i] = $sText;
                }
                
                # Zorg ervoor dat er paragrafen komen.
                $this->sText = '';
                foreach($this->aText as $sKey => $sText)
                {
                    if($sKey{0} == 'i')
                    {
                        $this->sText .= $this->paragraphise($sText);
                    }
                    else
                    {
                        $this->sText .= $sText;
                    }
                }
            }
            else
            {
                $this->sText = $sText;
            }
        }
        
        private function paragraphise($sText)
        {
            $aParagraphs = explode("\\n\\n", $sText);
            $sText = '';
            foreach($aParagraphs as $sParagraph)
            {
                $sText .= '<p>'.str_replace("\\n", '<br />', trim($sParagraph)).'</p>';
            }
            return $sText; 
        }
        
        private function basic($aNode, $sTag)
        {
            if($aNode['type'] == 'open')
            {
                return '<'.$sTag.'>';
            }
            else
            {
                return '</'.$sTag.'>';
            }
        }
        
        private function b($aNode)
        {
            return $this->basic($aNode, 'strong');
        }
        
        private function i($aNode)
        {
            return $this->basic($aNode, 'em');
        }
        
        private function u($aNode)
        {
            return $this->basic($aNode, 'ins');
        }
        
        private function s($aNode)
        {
            return $this->basic($aNode, 'del');
        }
        
        private function sub($aNode)
        {
            return $this->basic($aNode, 'sub');
        }
        
        private function sup($aNode)
        {
            return $this->basic($aNode, 'sup');
        }
        
        private function a($aNode)
        {
            if($aNode['type'] == 'open')
            {
                if(isset($aNode['attributes'][$aNode['tag']]) === true)
                {
                    $sHref = $aNode['attributes'][$aNode['tag']];
                    
                    if(strpos($sHref, 'http://') === false)
                    {
                        $sHref = 'http://'.$sHref;
                    }
                }
                else
                {
                    $sHref = '#';
                }
                
                return '<a href="'.$sHref.'">';
            }
            else
            {
                return '</a>';
            }
        }
        
        private function search($aNode)
        {
            $sSearch = $this->parse('search');
            return 'Google zoekopdracht: <a href="http://www.google.nl/search?q='.$sSearch.'">'.$sSearch.'</a>';
        }
        
        private function h2($aNode)
        {
            return $this->basic($aNode, 'h2');
        }
        
        private function h3($aNode)
        {
            return $this->basic($aNode, 'h3');
        }
        
        private function h4($aNode)
        {
            return $this->basic($aNode, 'h4');
        }
        
        private function h5($aNode)
        {
            return $this->basic($aNode, 'h5');
        }
        
        private function h6($aNode)
        {
            return $this->basic($aNode, 'h6');
        }
        
        private function ol($aNode)
        {
            return $this->basic($aNode, 'ol');
        }
        
        private function ul($aNode)
        {
            return $this->basic($aNode, 'ul');
        }
        
        private function li($aNode)
        {
            return $this->basic($aNode, 'li');
        }
        
        private function table($aNode)
        {
            return $this->basic($aNode, 'table');
        }
        
        private function tr($aNode)
        {
            return $this->basic($aNode, 'tr');
        }
        
        private function th($aNode)
        {
            return $this->basic($aNode, 'th');
        }
        
        private function td($aNode)
        {
            return $this->basic($aNode, 'td');
        }
        
        private function img($aNode)
        {
          	$this->bParse = false;
            
            $sIMG = $this->parse('img');
            
            $this->bParse = true;
    
    
            return '<img src="'.stripslashes($sIMG).'" alt="Kon niet weergegeven worden" />';
        }
        
        private function hr($aNode)
        {
            if($aNode['type'] == 'open')
            {
                return '<hr />';
            }
        }
        
        private function blockquote($aNode)
        {
            return $this->basic($aNode, 'blockquote');
        }
        
        private function code($aNode)
        {
            $this->bParse = false;
            
            $sCode = $this->parse('code');
            
            $this->bParse = true;
    
    
    	$sCode = str_replace("<br>", "", $sCode);  
            $sCode = str_replace("<br />", "", $sCode);  
            $sCode = str_replace("&amp;gt;", ">", $sCode);  
            $sCode = str_replace("&amp;lt;", "<", $sCode);  
    	$sCode = str_replace("&amp;quot;", "\\"", $sCode);  
    
    
            $sCode = str_replace("&amp;amp;", "&amp;", $sCode);  
            $sCode = str_replace('$', '\\$', $sCode);  
            $sCode = str_replace('\\n', '\\\\\\\\n', $sCode);  
            $sCode = str_replace('\\r', '\\\\\\\\r', $sCode);  
            $sCode = str_replace('\\t', '\\\\\\\\t', $sCode);
    	$sCode = str_replace(':)', ':)', $sCode);
    
    
    	
    
    
    	$lines = explode(PHP_EOL, trim($sCode));
    
    
    	$i=1;
    
    
      $code = '<div class="Code">
    		<div class="Code_Titel">PHP code</div>
    		<div class="Left">';
    			foreach ($lines as $line)
    			{
    				$code .= $i.'<br />';
    
    
    				$i++;
    			}	
      $code .= '</div>
    		<div class="Right">
    				'.highlight_string(stripslashes(trim($sCode)), true).'
    		</div>
    	</div>';
    
    
        return $code;  
            
        }
        
          static public function execute($sText)
        {
            $oParser = new ubb($sText);
            $oParser->cleanWhiteSpace();
            $oParser->getPieces();
            $oParser->createTree();
            $oParser->validateTree();
            $oParser->parse();
            echo $oParser->sText;
            return noXSS($oParser->sText);        
        }
    }
    
    
    function noXSS($sString)
    {
        return stripslashes(preg_replace('#(href|src)=(\\'|\\")(.+?)(\\'|\\")( |>)#ise', "'\\\\1=\\\\2'.removeJavascript('\\\\3').'\\\\4\\\\5'", $sString));
    }
    function removeJavascript($sString)
    {
        $sReturn = '#';
        
        $sCheck = str_replace(array("\\n", ' '), '', stripslashes(strip_tags(html_entity_decode(trim(strtolower($sString))))));
        
        $bEvil = false;
        $aEvil = array('javascript:', 'onfocus=', 'onblur=', 'onclick=', 'ondblclick=', 'onmousedown=', 'onmouseup=', 'onmouseover=', 'onmousemove=', 'onmouseout=', 'onkeypress=', 'onkeydown=', 'onkeyup=');
        foreach($aEvil as $sEvil)
        {
            if(strpos($sCheck, $sEvil) !== false)
            {
                $bEvil = true;
                break;
            }
        }
        
        if($bEvil === false)
        {
            $sReturn = $sString;
        }
        
        return $sReturn;
    }
    ?>
    Toon Meer

    Website: https://devimo.nl
    Skype: https://join.skype.com/invite/dJyYILTt7Eqh

  • Guest, wil je besparen op je domeinnamen? (ad)
  • Stefan.J
    Master
    Ontvangen Reacties
    9
    Berichten
    2.358
    • 21 juni 2010 om 12:28
    • #2

    Ik zit een beetje door je code heen te scannen, en toen zag ik de methode cleanWhiteSpaces() staan. Vervolgens scrolde ik naar beneden om deze reactie te schrijven, en werd ik nogmaals geholpen:

    PHP
    static public function execute($sText)
        {
            $oParser = new ubb($sText);
            $oParser->cleanWhiteSpace();
            $oParser->getPieces();
            $oParser->createTree();
            $oParser->validateTree();
            $oParser->parse();
            echo $oParser->sText;
            return noXSS($oParser->sText);        
        }
    Toon Meer

    Ik heb niet nagezocht of dit ook werkelijk het probleem oplost. Echter, de kans lijkt me erg groot!

    Succes.

    [offtopic]Vrij goed stukje code moet ik zeggen... Waar komt het vandaan?[/offtopic]

  • Luc
    Software Engineer
    Ontvangen Reacties
    44
    Berichten
    1.986
    • 21 juni 2010 om 14:18
    • #3

    het komt hier vandaan:

    http://www.sitemasters.be/scripts/1/17/1…ased_UBB_parser

    Ik ga even kijken of ik in de clean wat kan veranderen.

    EDIT
    Ik heb het nu weggehaald, en het werkt nu al wat beter, maar als ik bijvoorbeeld bij mijn [ code] block wat heb staan en vervolgens wat enters, worden die enters alsnog weggehaad, geldt ook voor de eerste regel tekst na het code block;)

    Website: https://devimo.nl
    Skype: https://join.skype.com/invite/dJyYILTt7Eqh

Participate now!

Heb je nog geen account? Registreer je nu en word deel van onze community!

Maak een account aan Login

ICT Nieuws

  • Fijne feestdagen

    tcbhome 28 december 2025 om 13:55
  • Kritieke update voor Really Simple Security-plug-in

    K.Rens 16 november 2024 om 16:12
  • ING Nederland streeft naar ondersteuning van Google Pay tegen eind februari

    K.Rens 2 november 2024 om 16:09

Blogs

  • Functioneel ontwerp

    Dees 28 december 2014 om 12:38
  • Access Control List implementatie in PHP/MySQL - deel 1/2

    FangorN 28 december 2018 om 12:35
  • Access Control List implementatie in PHP/MySQL - deel 2/2

    FangorN 29 december 2018 om 12:37
  1. Marktplaats
  2. Design
  3. Voorwaarden
  4. Ons team
  5. Leden
  6. Geschiedenis
  7. Regels
  8. Links
  9. Privacy Policy
ICTscripters ©2005 - 2026 , goedkope hosting door DiMoWeb.com, BE0558.915.582
Sponsors: Beste kattenhotel provincie Antwerpen | Beste Zetes eid kaartlezer webshop
Style: Nexus by cls-design
Stylename
Nexus
Manufacturer
cls-design
Licence
Commercial styles
Help
Supportforum
Visit cls-design