Jump to content

Help on disabling if they type quoted message


Monkuar

Recommended Posts

Okay, on my forum if my users try to quote a youtube video, it shows the youtube video, while being quoted... (and if alot of people quote that video in a topic/thread) it becomes slow and bloated because abunch of people quoted the youtube videos and they're RE-Quotes.

 

My solution is, is if the tags are INSIDE the

[quote]

tag's it just shows the youtube URL and doesn't embed!.

 

My Problem is, I don't know how to do it, lol

 

Here is my parser to convert the quotes:

 

$txt = preg_replace( "#(\[quote(.+?)?\].*\[/quote\])#ies" , "\$this->regex_parse_quotes('\\1')"  , $txt );

 

Regex_Parse_quotes function is:

 

 function regex_parse_quotes($the_txt="") {

        if ($the_txt == "") return;

        $txt = $the_txt;

        // Too many embedded code/quote/html/sql tags can crash Opera and Moz

        /*if (preg_match( "/\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\]/is", $txt) ) {
            $this->quote_error++;
            return $txt;
        }*/

        $this->quote_html = $this->wrap_style( array( 'STYLE' => 'QUOTE' ) );


        $txt = preg_replace( "#\[quote\]#ie"                        , "\$this->regex_simple_quote_tag()"    , $txt );
        $txt = preg_replace( "#\[quote=([^\]]+?),([^\]]+?)\]#ie"    , "\$this->regex_quote_tag('\\1', '\\2')"  , $txt );
        $txt = preg_replace( "#\[quote=([^\]]+?)\]#ie"              , "\$this->regex_quote_tag('\\1', '')"  , $txt );
        $txt = preg_replace( "#\[/quote\]#ie"                       , "\$this->regex_close_quote()"          , $txt );



        $txt = preg_replace( "/\n/", "<br>", $txt );

        if ( ($this->quote_open == $this->quote_closed) and ($this->quote_error == 0) )
        {
            $txt = preg_replace( "#(<!--QuoteEBegin-->.+?<!--QuoteEnd-->)#es", "\$this->regex_preserve_spacing('\\1')", trim($txt) );

            return $txt;
        }
        else
        {
            return $the_txt;
        }

    }

 

Here is my youtube parser:

 

$txt = preg_replace( "`\[youtube\]http\://(.*?)youtube\.com/watch\?v\=(.*?)\[/youtube\]`ie"     , "\$this->convert_youtube('\\1','\\2')", $txt );

 

Convert_Youtube function:

 

function convert_youtube($code,$code1) {
global $ibforums;
     

        $this->youtube_count++;

        return '<embed src="http://'.$code.'youtube.com/v/'.$code1.'" type="application/x-shockwave-flash" wmode="transparent" width="512" height="313" allowfullscreen="true" />';
    }

 

Thanks if you can help! I'll be tracking this topic like a hawk!

Link to comment
Share on other sites

Maybe change

$txt = preg_replace( "`(?<!\[quote\])\[youtube\]http://(.*?)youtube\.com/watch\?v=(.*?)\[/youtube\](?!\[/quote\])`ie"     , "\$this->convert_youtube('\\1','\\2')", $txt );

to

$txt = preg_replace( "`\[youtube\]http\://(.*?)youtube\.com/watch\?v\=(.*?)\[/youtube\]`ie"     , "\$this->convert_youtube('\\1','\\2')", $txt );

 

I think that will work

Link to comment
Share on other sites

Oh got it.. i read it again

 

So

Link

becomes

<embedded>youtube</embedded>

 

But you want

Link

Link

to become

LINK

 

Right ?

 

HAHA Yeah if they try to post the tags inside a

[quote]

then it just doesn't embed the youtube video, it just shows the link to it instead (or text)

 

it's frustrating when im viewing topics on my site and people quoting other people and the youtube video pops up with that quote, alot better if when they quote somone it just shows the youtube url instead

 

 

i just saw your reply let me get a few minutes to study and check it ty

Link to comment
Share on other sites

Maybe change

$txt = preg_replace( "`(?<!\[quote\])\[youtube\]http://(.*?)youtube\.com/watch\?v=(.*?)\[/youtube\](?!\[/quote\])`ie"     , "\$this->convert_youtube('\\1','\\2')", $txt );

to

$txt = preg_replace( "`\[youtube\]http\://(.*?)youtube\.com/watch\?v\=(.*?)\[/youtube\]`ie"     , "\$this->convert_youtube('\\1','\\2')", $txt );

 

I think that will work

 

The code works, because no errors, but it still embeds the youtube hmmm.. haha

Link to comment
Share on other sites

Okay

Here is a test file :P

 

Note that your need to remove the function convert_youtube($code,$code1) at the bottom and change

$txt = str_replace($match[0], convert_youtube($match[2],$match[3]), $txt,1);

to

$txt = str_replace($match[0], $this->convert_youtube($match[2],$match[3]), $txt,1);

if you choose to apply this code,

 

have a test and see if it suites :)

 

<?php
$txt = '[quote][youtube]http://youtube.com/watch?v=ABCD[/youtube][/quote]
  [youtube]http://youtube.com/watch?v=ABCD[/youtube]
  [quote][youtube]http://youtube.com/watch?v=ABCD[/youtube][/quote]
  [youtube]http://youtube.com/watch?v=ABCD[/youtube]
  [quote][youtube]http://youtube.com/watch?v=ABCD[/youtube][/quote]
  [youtube]http://youtube.com/watch?v=ABCD[/youtube]
  ';

$RegEx = '%(\[quote\].*?)?\[youtube\]http\://(.*?)youtube\.com/watch\?v\=(.*?)\[/youtube\](.*?\[/quote\])?%ie';
if(preg_match_all($RegEx, $txt, $matches,PREG_SET_ORDER)){
  foreach($matches as $match){
    if(!empty($match[0]) && empty($match[1]) && empty($match[4])){
      $txt = str_replace($match[0], convert_youtube($match[2],$match[3]), $txt,1);
    }else{
      $txt = str_replace($match[0], sprintf('%s<a href="http://%syoutube.com/watch?v=%s">LINK</a>%s',$match[1],$match[2],$match[3],$match[4]), $txt,1);
    }
  }
}
echo $txt;
function convert_youtube($code,$code1){
  return '<embed src="http://'.$code.'youtube.com/v/'.$code1.'" type="application/x-shockwave-flash" wmode="transparent" width="512" height="313" allowfullscreen="true" />';
}

Link to comment
Share on other sites

You may want to remove the 4th parameter from the str_replaces (the ",1" )

 

Brain is fried.. as its 3am here in the UK!

 

Lol, some odd reason, that code gives me a white screen of death, must be something to do with the $txt,

 

my $txt stuff is already in 1 big function also, but yeah ima look over it through the night picking pieces at it

 

blah i removed the ,1 and it's not screen of death, let me test ty

Link to comment
Share on other sites

mad Techie, the code again works when I take out the ,1 with no white screen of death.

 

but

 

 $txt = preg_replace( "#(\[quote(.+?)?\].*\[/quote\])#ies" , "\$this->regex_parse_quotes('\\1')"  , $txt );

 

I think is what making it not working

 

 

 

I have

 



$txt = str_replace($match[0], $this->convert_youtube($match[2],$match[3]), $txt);

$RegEx = '%(\[quote\].*?)?\[youtube\]http\://(.*?)youtube\.com/watch\?v\=(.*?)\[/youtube\](.*?\[/quote\])?%ie';
if(preg_match_all($RegEx, $txt, $matches,PREG_SET_ORDER)){
  foreach($matches as $match){
    if(!empty($match[0]) && empty($match[1]) && empty($match[4])){
      $txt = str_replace($match[0], $this->convert_youtube($match[2],$match[3]), $txt);
    }else{
      $txt = str_replace($match[0], sprintf('%s<a href="http://%syoutube.com/watch?v=%s">LINK</a>%s',$match[1],$match[2],$match[3],$match[4]), $txt);
    }
  }
}

 

 

if I take out that

 $txt = preg_replace( "#(\[quote(.+?)?\].*\[/quote\])#ies" , "\$this->regex_parse_quotes('\\1')"  , $txt );

my quotes don't work but the yt stuff does and it shows "LINK"  :rtfm:

 

EDIT: I think you might need to do the code to work with the quote function instead of the yt one? :P

Link to comment
Share on other sites

Ahh yes it will only handle [ quote ] not [ quote=hfdhsdkfk ] etc

update the RegEx to

$RegEx = '%(\[quote(?:=[^\]]*)\].*?)?\[youtube\]http\://(.*?)youtube\.com/watch\?v\=(.*?)\[/youtube\](.*?\[/quote\])?%ie';

and it should keep them as they were.

 

it does show "LINK"

but you could update

$txt = str_replace($match[0], sprintf('%s<a href="http://%syoutube.com/watch?v=%s">LINK</a>%s',$match[1],$match[2],$match[3],$match[4]), $txt);

to

      $url = sprintf('http://%syoutube.com/watch?v=%s',$match[2],$match[3]);
      $txt = str_replace($match[0], sprintf('%s<a href="$s">%s</a>%s',$match[1],$url,$url,$match[4]), $txt);

to display the link with the hyper-link  :shrug:

Link to comment
Share on other sites

Doh!

 

My bad

 $txt = str_replace($match[0], sprintf('%s<a href="$s">%s</a>%s',$match[1],$url,$url,$match[4]), $txt);

should be

 $txt = str_replace($match[0], sprintf('%s<a href="%s">%s</a>%s',$match[1],$url,$url,$match[4]), $txt);

 

but it was 3:45am when i wrote it :P!!

HAHA that is the same line of code!!!  :shrug:

Link to comment
Share on other sites

Haven't read through the entire thread but I could offer an alternative way of thinking for this...

 

-Run through the post and replace all quotes (from opening tag to it's closing tag) with a unique identifier and storing the quote in an array. E.g. '[|||QUOTE]##' for unique identifier, where ## represents which quote this is in terms of array position, so the first is 0.

-Run through the post and replace all the youtube tags that are present with function A which turns them into embedded videos.

-Run a for loop to put all the quotes back in in there original positions from the array we stored them in.

-Run through the post and replace all the remaining youtube tags with function B which turns them into links. (The only remaining one's will have only just appeared if they were in quotes)

-Now do all other replacements you might have.

 

Hope that helps you,

Joe

Link to comment
Share on other sites

No its not!

OLD:  $txt = str_replace($match[0], sprintf('%s<a href="$s">%s</a>%s',$match[1],$url,$url,$match[4]), $txt);

NEW: $txt = str_replace($match[0], sprintf('%s<a href="%s">%s</a>%s',$match[1],$url,$url,$match[4]), $txt);

 

HAH POOP ON ME!

 

let me try lol

 

Maybe I am the problem here  :shrug: :shrug:

Link to comment
Share on other sites

I'm going to need the code you have so far and some sample text,

 

as nothing in the code i have written will create the \" 's

Also you do have the line

$url = sprintf('http://%syoutube.com/watch?v=%s',$match[2],$match[3]);

above it, right ?

 

Hey I went to school, sorry for the response

 

I guess I forgot to add the $url to it, I did and it now shows

 

<a href="\"http://www.youtube.com/watch?v=xN0FFK8JSYE\"">http://www.youtube.com/watch?v=xN0FFK8JSYE</a>[code]

It has a extra  \ somewhere that's making it not do weird things, lol but damn bro it working for the most part, but when they click on it it goes to 
http://localhost/%22http://www.youtube.com/watch?v=xN0FFK8JSYE\%22

hence the above sentences

dude you're amazing, i would have never had figured this out man

now I will prob do the same to my vimeo bbcode tag's and Worldstarhiphop video tags aswel with your code.

you're wonderful 

Link to comment
Share on other sites

LOL, I hoped you forgot that line or i was totally lost!

 

however

I'm going to need the code you have so far and some sample text,

 

as nothing in the code i have written will create the \" 's

 

I would assume that the $txt has something done to it after my little process!

Link to comment
Share on other sites

Okay :)

 

Well this is below all your code, because this goes to my quote function to get my quotes working

 

$txt = preg_replace( "#(\[quote(.+?)?\].*\[/quote\])#ies" , "\$this->regex_parse_quotes('\\1')"  , $txt );

 

regex_parse_quotes function is:

 

function regex_parse_quotes($the_txt="") {
        if ($the_txt == "") return;

        $txt = $the_txt;

        // Too many embedded code/quote/html/sql tags can crash Opera and Moz

        /*if (preg_match( "/\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\]/is", $txt) ) {
            $this->quote_error++;
            return $txt;
        }*/

        $this->quote_html = $this->wrap_style( array( 'STYLE' => 'QUOTE' ) );


        $txt = preg_replace( "#\[quote\]#ie"                        , "\$this->regex_simple_quote_tag()"    , $txt );
        $txt = preg_replace( "#\[quote=([^\]]+?),([^\]]+?)\]#ie"    , "\$this->regex_quote_tag('\\1', '\\2')"  , $txt );
        $txt = preg_replace( "#\[quote=([^\]]+?)\]#ie"              , "\$this->regex_quote_tag('\\1', '')"  , $txt );
        $txt = preg_replace( "#\[/quote\]#ie"                       , "\$this->regex_close_quote()"          , $txt );



        $txt = preg_replace( "/\n/", "<br>", $txt );

        if ( ($this->quote_open == $this->quote_closed) and ($this->quote_error == 0) )
        {
            $txt = preg_replace( "#(<!--QuoteEBegin-->.+?<!--QuoteEnd-->)#es", "\$this->regex_preserve_spacing('\\1')", trim($txt) );

            return $txt;
        }
        else
        {
            return $the_txt;
        }

    }

 

Out of all those 4

  $txt = preg_replace( "#\[quote\]#ie"                        , "\$this->regex_simple_quote_tag()"    , $txt );
        $txt = preg_replace( "#\[quote=([^\]]+?),([^\]]+?)\]#ie"    , "\$this->regex_quote_tag('\\1', '\\2')"  , $txt );
        $txt = preg_replace( "#\[quote=([^\]]+?)\]#ie"              , "\$this->regex_quote_tag('\\1', '')"  , $txt );
        $txt = preg_replace( "#\[/quote\]#ie"                       , "\$this->regex_close_quote()"          , $txt );

 

I think the 

$txt = preg_replace( "#\[quote=([^\]]+?)\]#ie"              , "\$this->regex_quote_tag('\\1', '')"  , $txt );

 

one is the that is going to be used because it does the

 [quote === XXXXXXXXX] 

?? right?

 

If so, regex_quote_tag function is:

 

 

 

 

 

function regex_quote_tag($name="", $date="")
    {
        global $ibforums;

        if ( $date != "" )
        {
            $default = "\[quote=$name,$date\]";
        }
        else
        {
            $default = "\[quote=$name\]";
        }

        if ( strstr( $name, '<!--c1-->' ) or strstr( $date, '<!--c1-->' ) )
        {
            // Code tag detected...

            $this->quote_error++;
             return $default;
        }

        $name = str_replace( "+", "&#043;", $name );
        $name = str_replace( "-", "&#045;", $name );
        $name = str_replace( '[', "&#091;", $name );
        $name = str_replace( ']', "&#093;", $name );

        $this->quote_open++;

        if ($date == "")
        {
            $html = $this->wrap_style( array( 'STYLE' => 'QUOTE', 'EXTRA' => "($name)" ) );
        }
        else
        {
            $html = $this->wrap_style( array( 'STYLE' => 'QUOTE', 'EXTRA' => "($name &#064; $date)" ) );
        }

        $extra = "-".$name.'+'.$date;

        return "<!--QuoteBegin".$extra."-->{$html['START']}<!--QuoteEBegin-->";

    }

 

Hope this helps

Link to comment
Share on other sites

I don't see anything,

 

is their a function that deals with HTML or JS injection ?

 

Maybe see what happens with single quotes

change

$txt = str_replace($match[0], sprintf('%s<a href="%s">%s</a>%s',$match[1],$url,$url,$match[4]), $txt);

to

$txt = str_replace($match[0], sprintf('%s<a href='%s'>%s</a>%s',$match[1],$url,$url,$match[4]), $txt);

 

href="%s"
to
href='%s'
Link to comment
Share on other sites

I don't see anything,

 

is their a function that deals with HTML or JS injection ?

 

Maybe see what happens with single quotes

change

$txt = str_replace($match[0], sprintf('%s<a href="%s">%s</a>%s',$match[1],$url,$url,$match[4]), $txt);

to

$txt = str_replace($match[0], sprintf('%s<a href='%s'>%s</a>%s',$match[1],$url,$url,$match[4]), $txt);

 

href="%s"
to
href='%s'

 

$txt = str_replace($match[0], sprintf('%s<a href=\'%s\'>%s</a>%s',$match[1],$url,$url,$match[4]), $txt);

 

WE HAVE A WINNER!

 

THANKS YOU dude!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.