Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Help with BB Code!

    Hello Guys

    Im new here - and im not sure if this is the correct place to post? Well, please correct me if im wrong.

    I have an Online game - and im currently making changes to the BB Code so that users can embed YouTube videos into there profiles - but im not surehow?

    Here is a snippet of the code:

    PHP Code:
    /////////BB Codes////////////


    $txt str_replace("[quote]""<fieldset><legend>QUOTE:</legend><br>"$txt);

    $txt str_replace("[/quote]""</fieldset>"$txt);

    $txt str_replace("[center]""<center>"$txt);

    $txt str_replace("[/center]""</center>"$txt);

    $txt str_replace("[b]""<b>"$txt);

    $txt str_replace("[/b]""</b>"$txt);

    $txt str_replace("[i]""<i>"$txt);

    $txt str_replace("[/i]""</i>"$txt);

    $txt str_replace("[u]""<u>"$txt);

    $txt str_replace("[/u]""</u>"$txt);

    $txt str_replace("[move]""<marquee>"$txt);

    $txt str_replace("[/move]""</marquee>"$txt);

    $txt str_replace('[url=''<a href="'$txt);

    $txt str_replace('[/url]''</a>'$txt);



    $txt str_replace("[hr]""<hr>"$txt);


    $txt str_replace("[img]""<img border=0 src="$txt);

    $txt str_replace("[/img]"">"$txt);

    $txt str_replace("[IMG]""<img border=0 src="$txt);

    $txt str_replace("[/IMG]"">"$txt);

    $txt str_replace("[quote]""<div id=quote>quote:<br>"$txt);

    $txt str_replace("[/quote]""</div>"$txt);


    $txt str_replace("[font color=red]""<font color=red>"$txt);

    $txt str_replace("[/font]""</font>"$txt);


    $txt str_replace("[font color=blue]""<font color=blue>"$txt);

    $txt str_replace("[/font]""</font>"$txt);


    $txt str_replace("[font color=green]""<font color=green>"$txt);

    $txt str_replace("[/font]""</font>"$txt);

    $txt str_replace("[font color=orange]""<font color=orange>"$txt);

    $txt str_replace("[/font]""</font>"$txt);

    $txt str_replace("[font color=white]""<font color=white>"$txt);

    $txt str_replace("[/font]""</font>"$txt);

    $txt str_replace("[font color=black]""<font color=black>"$txt);

    $txt str_replace("[/font]""</font>"$txt);


    $txt str_replace("[bg=white]""<body bgcolor=white>"$txt);
    $txt str_replace("[/bg]""</body>"$txt);


    $txt str_replace("[code]""<div id=code>"$txt);

    $txt str_replace("[/code]""</div>"$txt);

    $txt str_replace(array("\r\n""\n""\r"), '<br>'$txt); 

    $txt str_replace("[b]""<b>"$txt);

    $txt str_replace("[h1]""<h1>"$txt);

    $txt str_replace("[h2]""<h2>"$txt);

    $txt str_replace("[h3]""<h3>"$txt);

    $txt str_replace("[h3]""<h3>"$txt);

    $txt str_replace("[h4]""<h4>"$txt);

    $txt str_replace("[h5]""<h5>"$txt);















    return 
    $txt;

    }



    function 
    rep2($txt) {

    $txt str_replace('&lt;','<',$txt);

    $txt str_replace('&gt;','>',$txt);

    $txt str_replace('&quot;','\"',$txt);


    $txt str_replace('&#amp;','&',$txt);

    return 
    $txt;

    }


    //EXTERNAL BB



    //EXTERNAL BB CODE END


    ?> 

  • #2
    Regular Coder
    Join Date
    Apr 2008
    Posts
    685
    Thanks
    15
    Thanked 105 Times in 104 Posts
    How do you want them to embed the video?Can't they just copy and paste the embed code from youtube it into their profile as it is.

  • Users who have thanked Scriptet for this post:

    Mafiadream (09-09-2009)

  • #3
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks for your reply,

    The code I beleived has protection from cross-site scripting? So its basically coded through where it must be BB Codes.

    Any thoughts?

  • #4
    Regular Coder funnymoney's Avatar
    Join Date
    Aug 2007
    Posts
    364
    Thanks
    17
    Thanked 24 Times in 24 Posts
    Quote Originally Posted by Mafiadream View Post
    Any thoughts?
    all you need to do is parse the embed link or embed html provided by the youtube or any other video sharing website, and then through simple input field add details to where details are needed

  • #5
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I understand what you mean, however I do not have enoguh experience to do this.

    Could someone help?

  • #6
    Regular Coder
    Join Date
    Apr 2008
    Posts
    685
    Thanks
    15
    Thanked 105 Times in 104 Posts
    Hmm you could add a YouTube button then, which asks for the video ID of the video and then parse it somehow..

    You need the code for where the buttons are created also.

    1. So basically whent the button is clicked, an alert can popup (javascript) and it can ask for a video id or src you decide..

    2. Then this can input something like
    [youtube]user input goes here[/youtube] into their text area

    3. Then using the code above you can use a regular expression or something to get the data between the two [youtube] tags and then replace it with the youtube embed code.

    4.But what would happen if somebody enters an incorrect video id or src? a blank video would show up, is this acceptable you decide. I can't think of anyway to check if a youtube video src/url is legit really other than maybe to connect to their api or something

  • Users who have thanked Scriptet for this post:

    Mafiadream (09-09-2009)

  • #7
    Regular Coder
    Join Date
    Apr 2008
    Posts
    685
    Thanks
    15
    Thanked 105 Times in 104 Posts
    Here try this:

    1. Add the following code below the line: $txt = str_replace("[h5]", "<h5>", $txt); in that code you pasted above.

    PHP Code:
    //Get String Between the 2 tags
    $pos_s strpos($txt,"[youtube]");
    $pos_e strpos($txt,"[/youtube]");
    for(
    $i=$pos_s+strlen("[youtube]");(($i<($pos_e))&& $i strlen($txt)); $i++){
        
    $id .= $txt[$i];
    }

    //Create the YT Embed Code
    $embedCode = <<<EMBED
    <object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/$id&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/$id&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>
    EMBED;

    //Now replace the yt tags with the embed code
    $strReplace "[youtube]".$id."[/youtube]";
    $txt str_replace($strReplace"$embedCode"$txt); 
    Then try adding something like
    [youtube]ZcZONRjxpSs[/youtube] in their profile.
    Then if this works all you need to do is sort out the button part.

  • Users who have thanked Scriptet for this post:

    Mafiadream (09-09-2009)

  • #8
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thank you very much mate this works perfectly!!


    Really glad you helped mate thankyou very much.

  • #9
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    ..Suppose they only put one tag. You need to use regex my friend, it'll make this script much more efficient.

    Like zis:

    PHP Code:
            $Arr = array(
            
    "/\[b\](.+?)\[\/b\]/si",
            
    "/\[i\](.+?)\[\/i\]/si",
            
    "/\[quote=(.+?)\](.+?)\[\/quote\]/si",
            
    "/\[quote\](.+?)\[\/quote\]/si",
            
    "/\[url=(.+?)\](.+?)\[\/url\]/si"
            
    );
            
            
    $Rep = array(
            
    "<b>$1</b>",
            
    "<i>$1></i>",
            
    "<blockquote>$1 <b>Said</b> <br /> $2</blockquote>",
            
    "<blockquote>$1</blockquote>",
            
    "<a href=\"$1\" target=\"_blank\">$2</a>"
            
    );
            
            
    $sText preg_replace ($Arr$Rep$sText); 
    PHP Code:
    $aString is_string((string)array()) ? true false// true :D 
    [/CENTER]


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •