SimpleBB..now in OOP!

Results 1 to 3 of 3
  1. #1
    Account Upgraded | Title Enabled! xSilv3rbullet is offline
    MemberRank
    Apr 2009 Join Date
    1,226Posts

    SimpleBB..now in OOP!

    Well, my old site got wiped.
    ...and no, I don't have a "recent enough" copy of it.

    So, I'm going to take this opportunity to recode SimpleBB!

    Progress will be posted here, as well as parts of files.

    Improvements:
    Spoiler:

    -New, more efficient OOP design
    -MySQL and MySQLi compatible
    -Database, Functions are now grouped into classes, and they can be called from their variables in Globals.php


    To-do:
    Spoiler:

    -Module system
    -Advanced theming system.


    Dev team:
    Spoiler:

    -Me


    Expect a preview/release in 3-5 weeks.

    Bits & Pieces:

    Spoiler:

    BBCode Parser
    Spoiler:

    ...monstrous 300 line parser.
    Note that this is a sample page, the real parser is contained within a class.

    A lot of the "debugging" variables are still there, so expect a massive code cleanup soon. :)
    PHP Code:
    <?php
    //Parser power!

    if(!isset($_REQUEST['bbsubmit']))
    {
        echo 
    "
        <html>
            <head>
                <title>SimpleBB\Tests\BBCode</title>
            </head>
            <body style=\"font-family:Tahoma; background-color: grey; color:white;\">
                <div style=\"text-align: center;\">
                <p onclick=\"window.location='#DOCS'\">SimpleBB BBCode Parser ALPHA  Scroll down or click for some documentation!</p><br />
                <br />
                    <form method=\"post\" action=\"\">
                        <textarea cols=\"50\" rows=\"10\" style=\"margin-left:auto; margin-right:auto;\" name=\"bbcode\">sample[b]hello[i]recursive[b]test[/b][/i][/b][long]test[/long][i]hello[/b]
                        </textarea>
                        <br />
                        <input type=\"submit\" name=\"bbsubmit\" value=\"Parse It! (ALT+P)\" accesskey=\"p\"/>
                    </form>
                    <br />
                    <br />
                    <br />
                    <br />
                    <br />
                    <br /><br />
                    <br />
                    <br /><br />
                    <br />
                    <br /><br />
                    <br />
                    <br /><br />
                    <br />
                    <br /><br />
                    <br />
                    <br /><br />
                    <br />
                    <br /><br />
                    <br />
                    <br /><br />
                    <br />
                    <br />
                    <strong>ParserDOC</strong><br />
                    <br />
                    <a name=\"DOCS\"></a>
                    8.28.10 - Started on parser.  Parser can detect unfinished <strong>first-level</strong> bbcode.  Recursive checking is not done yet.<br />
                    8.29.10 - Recursive parsing just about done.  There may still be bugs though...next up: Tag fixing.<br />
                    8.31.10 - Parser is pretty much done.  (Most) Bugs have been fixed.
                </div>
            </body>
        </html>
        "
    ;
    }
    else
    {
        
    $codes = array(
            
    'b' => array(
                
    'handler' => 'simplebb_parse_bold'
            
    ),
            
    'i' => array(
                
    'handler' => 'simplebb_parse_italics'
            
    ),
            
    'u' => array(
                
    'handler' => 'simplebb_parse_underline'
            
    )
        );
        
        
    $text $_REQUEST['bbcode'];
        
    $text nl2br($texttrue);

        echo 
    "<pre>";
        echo 
    "<p onclick=\"window.location='bbcode.php';\" style=\"color:blue;\">Click here to go back.</p>";
        echo 
    "<br />";

        echo 
    "The text " $text "generated...<br /><br />";

        function 
    test($text$isrecursive=false)
        {        
            
    //We want to "globalize" our code array
            
    global $codes;
            
            
    $pos 0;
        
            
    //Syntax tree--initialize it to an empty array
            
    $tree = array();
            
            
    //What offset are we at?
            
    $offset 0;
            
    $id 1;
            
            
    $error 0;
            
            
    $textstart 0;
            
            
    $prevbegin 0;
            
    $prevend = -1;
            
            
    //Loop...
            
    while(1)
            {
                
    //Initialize our found variable to false
                
    $found false;
                
                
    //Search for a tag!
                
    $begin stripos($text"["$offset);
                
    $end stripos($text"]"$begin);
                
                
    //Didn't find anything?
                
    if($begin === false || $end === false)
                {
                    
    //Since there's no bbcode, exit the loop.
                    
    break;
                }
                
                
    //In that case, let's set our offset as the closing bracket
                
    $offset $end;
                
                
    //What tag are we dealing with?
                
    $bbtag substr($text$begin+1$end-$begin-1);
                
                foreach(
    $codes as $key => $value)
                {
                    
    //Does this tag even exist?
                    
    if(strcmp($bbtag$key) == 0)
                    {
                        
    //Ok, good, I was starting to get worried. :P
                        
    $found true;
                    }
                }
                
                
    //Now look for the end tag.
                
                //Was it a valid tag?
                
    if(!$found)
                {
                    
    //It wasn't a tag?
                    
    continue;
                }
                else 
                {
                    
    //Add the text to the array...
                    //$tree["text".$id] = substr($text, $offset-$begin-2, $begin);
                    //$id++;
                    
                    //Open and end brackets for the closing tag
                    
    $begin_ stripos($text"[/".$bbtag$offset);
                    
    $end_ stripos($text"]"$begin_);
                    
                    
    //Not found?
                    
    if(!$begin_ || !$end_)
                    {
                        
    //We have an error!
                        
    $error++;
                        
                        continue;
                    }
                    
                    
    $length $begin-$prevend-1;
                    
    $textbefore substr($text$textstart$length);
                    
                    if(empty(
    $textbefore))
                    {}
                    
    //Push any text before the bbcode onto the array...
                    
    else
                        
    array_push($tree, array(""$textbefore, array()));
                    
                    
    $textstart $end_+1;
                    
                    
    $offset $end_;
                    
                    
    $endbbtag substr($text$begin_+1$end_-$begin_-1);//We want to skip the [
                    
                    //Are they the same?
                    
    if($endbbtag == "/" $bbtag)
                    {
                        
    //Yes!  Now we can process the text inside!
                        
    $intags substr($text$end+1$begin_-$end-1);
                        
    $original $intags;
                        
                        
    $multiple false;
                        
                        
    //Search for repeating tags
                        /*while(1)
                        {
                            $multipletags = stripos($intags, "[".$bbtag."]");
                            
                            if($multipletags === false)
                                break;
                            else 
                            {
                                $multiple = $multipletags;
                                
                                for($i = strlen($bbtag)+1; $i >= 0; $i--)
                                {
                                    $intags[$multipletags+$i] = "";
                                }
                            }
                        }*/
                        
                        //Children trees...
                        
    $children = array();
                        
                        
    //Recursive--find any tags with in children, and find any tags within those, and within those, and within...
                        
    $children test($intagstrue);
                            
                        
    //Push the whole thing on...
                        
    array_push($tree, array($bbtag$intags$children));
                        
                    }
                    else
                    { }
                    
                    
    $prevbegin $begin;
                    
    $prevend $end_;
                }
            }
            
            
    //Anymore text?
            
    $lasttext substr($text$textstart);
            
            if(
    $isrecursive)
            {}
            else
            {
                if(empty(
    $lasttext))
                { }
                else
                {
                    
    array_push($tree, array(""$lasttext, array()));
                }
            }
            
    //if($error)
                //return $error;

            //Check for empt
            
            //EVRY'THING MUST GOETH!
            
    return $tree;
        }
        
        function 
    simplebb_parse_bold($text)
        {
            return 
    "<span style=\"font-weight:bold;\">".$text."</span>";    
        }
            
        function 
    simplebb_parse_italics($text)
        {
            return 
    "<span style=\"font-style:italic;\">".$text."</span>";
        }
        
        function 
    simplebb_parse_underline($text)
        {
            return 
    "<span style=\"text-decoration:underline;\">".$text."</span>";
        }

        
    //NOTE: This assumes that the tag exists!!!
        
    function GenerateText($textarray)
        {
            global 
    $codes;
            
            if(!
    is_array($textarray))
                return 
    "";
                
            
    $output = array();
            
            
    $tag $textarray[0];
            
    $wrapped $textarray[1];
            
    $children $textarray[2];

            
    //It's plain text
            
    if($tag == "")
            {
                return 
    $wrapped;
            }    
            
            
    $recursive = array();
            
            if(
    count($children) > 0)
            {
                
    //This needs to be fixed...
                
    foreach($children AS $child)
                {
                    
    $recursive_ GenerateText($child);
                    
                    
    array_push($recursive$recursive_);
                }
            }
            
            foreach(
    $recursive AS $rec)
            {
                if(!empty(
    $rec[0]))
                {
                    
    $toreplace "[".$rec[0]."]".$rec[1]."[/".$rec[0]."]";
                    
                    
    $wrapped str_ireplace($toreplace$rec[2], $wrapped);
                }
            }
            
            
    $handler $codes[$tag]["handler"];
            
            
    $output[0] = $tag;
            
    $output[1] = $wrapped;
            
    $output[2] = call_user_func($handler$wrapped, array(), array());
            
            return 
    $output;
        }
        
        function 
    GenerateFromTree($tree)
        {
            if(!
    is_array($tree))
                return 
    "";
            
            
    //This is it!
            
    $output "";
            
            foreach(
    $tree AS $part)
            {
                if(!
    is_array($part))
                    return 
    "";
                
                
    $output_ GenerateText($part);
                
                
    //Some weird bug happens here...probably just a code problem :P
                
    if(isset($output_[2]))
                {
                    if(
    is_array($output_))
                        
    $output .= $output_[2];
                    else 
                        
    $output .= $output_;
                }
            }

            return 
    $output;
        }
        
        
    $bbcodetree test($text);
        
        
    print_r($bbcodetree);
        
        
    $out GenerateFromTree($bbcodetree);
        echo 
    $out;
        echo 
    "</pre>";
        
        echo 
    "<p onclick=\"window.location='bbcode.php';\" style=\"color:blue;\">Click here to go back.</p>";
    }
    ?>



    Challenging...David's AdvancedBB (http://forum.ragezone.com/f86/advanc...7/#post5874923)
    Last edited by xSilv3rbullet; 03-09-10 at 03:32 AM.


  2. #2
    Account Upgraded | Title Enabled! xSilv3rbullet is offline
    MemberRank
    Apr 2009 Join Date
    1,226Posts

    Re: SimpleBB..now in OOP!

    --Reserved for Updates--

    9.2.10 - Added sample BBCode Parser to the main post.

  3. #3
    C:\ WizCoder is offline
    MemberRank
    Aug 2010 Join Date
    JapanLocation
    703Posts

    Re: SimpleBB..now in OOP!

    nice release



Advertisement