Firefox PHP

Howto avoid smiley interpretation in code, url etc.?

Posted by covex 
Howto avoid smiley interpretation in code, url etc.?
December 02, 2007 12:30PM
Is there a way how to avoid smiley to be replaced inside code and in urls? This causes some problems e.g. when users wants to paste MAC address or log outputs.
Re: Howto avoid smiley interpretation in code, url etc.?
December 02, 2007 03:53PM
In phorum 5.2 you can make use of that feature. It is added to the smileys and the bbcode module.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: Howto avoid smiley interpretation in code, url etc.?
July 20, 2011 03:31PM
Quote
Maurice Makaay
In phorum 5.2 you can make use of that feature. It is added to the smileys and the bbcode module.
No, you can only disable smileys in the message. The problem described above is that smiley codes are also being parsed within bbcode tags.

Here is an example:
[img=someurl/somefile(tu).jpg]

In the smiley module a smiley exists by default represented exactly by this code: (tu)
It's now being parsed within the html code for displaying the image which makes trouble of course.

To solve this problem I had to do some changes in the mods/smileys/smileys.php

Search for the following comment included in the source code:
// Do body replacements.

Now replace all the code beginning from this line until the end of that function (including the function close tag) with this code:

        // Do body replacements.
        if (isset($replace['body']) && isset($message['body'])) {
            // parse smileys only outside bbcode!
            $orig = $message['body'];
            $newmsg = '';
            $find = $replace['body'][0];
            $repl = $replace['body'][1];
            $len = strlen( $orig );
            $freepos = 0;
            $lock = 0;
            for( $aa = 0; $aa < $len; $aa ++ ) {
                if( !$lock ) {
                    switch( substr($orig, $aa, 6) ) {
                        case '<a hre':
                            $lock = 1;
                            $newmsg .= str_replace( $find, $repl, substr($orig, $freepos, $aa-$freepos) );
                            $freepos = $aa;
                            break;
                        case '<span ':
                            $lock = 2;
                            $newmsg .= str_replace( $find, $repl, substr($orig, $freepos, $aa-$freepos) );
                            $freepos = $aa;
                            break;
                        case '<img s':
                            $lock = 3;
                            $newmsg .= str_replace( $find, $repl, substr($orig, $freepos, $aa-$freepos) );
                            $freepos = $aa;
                            break;
                    }
                }
                elseif( $aa > 6 ) {
                    switch( $lock ) {
                        case 1:
                            if( substr($orig, $aa - 4, 4) == '</a>' ) {
                                $lock = 0;
                                $newmsg .= substr( $orig, $freepos, $aa-$freepos );
                                $freepos = $aa;
                            }
                            break;
                        case 2:
                            if( substr($orig, $aa - 7, 7) == '</span>' ) {
                                $lock = 0;
                                $newmsg .= substr( $orig, $freepos, $aa-$freepos );
                                $freepos = $aa;
                            }
                            break;
                        case 3:
                            if( substr($orig, $aa - 2, 2) == '/>' ) {
                                $lock = 0;
                                $newmsg .= substr( $orig, $freepos, $aa-$freepos );
                                $freepos = $aa;
                            }
                            break;
                    }
                }
            }
            if( $lock ) {
                $newmsg .= substr( $orig, $freepos, $aa-$freepos );
            }
            else {
                $newmsg .= str_replace( $find, $repl, substr($orig, $freepos, $aa-$freepos) );
            }

            $data[$key]['body'] = $newmsg;
        }
    }

    return $data;
}
I hope I could help somebody out there. Sorry for my bad english! Feel free to use the code in one of the next phorum versions. The code could be written more clearly but it's trimmed for getting the best performance.
Re: Howto avoid smiley interpretation in code, url etc.?
November 04, 2011 02:44PM
I see that somebody also has this problem. Nice to see some patch to work around it.
Re: Howto avoid smiley interpretation in code, url etc.?
November 08, 2011 05:20AM
One of our users extended this patch the way it also prevents smiles to be interpreted in <pre> element. Here is the extended version for anybody interested.
$ diff smileys.php.withoutFix smileys.php.withFix 
78,79c78,153
<         if (isset($replace["body"]) && isset($message["body"])) {
<             $data[$key]['body'] = str_replace ($replace["body"][0] , $replace["body"][1], $message['body'] );
---
>         // Do body replacements.
>         if (isset($replace['body']) && isset($message['body'])) {
>             // parse smileys only outside bbcode!
>             $orig = $message['body'];
>             $newmsg = '';
>             $find = $replace['body'][0];
>             $repl = $replace['body'][1];
>             $len = strlen( $orig );
>             $freepos = 0;
>             $lock = 0;
>             for( $aa = 0; $aa < $len; $aa ++ ) {
>                 if( !$lock ) {
>                     switch( substr($orig, $aa, 6) ) {
>                         case '<a hre':
>                             $lock = 1;
>                             $newmsg .= str_replace( $find, $repl, substr($orig, $freepos, $aa-$freepos) );
>                             $freepos = $aa;
>                             break;
>                         case '<span ':
>                             $lock = 2;
>                             $newmsg .= str_replace( $find, $repl, substr($orig, $freepos, $aa-$freepos) );
>                             $freepos = $aa;
>                             break;
>                         case '<img s':
>                             $lock = 3;
>                             $newmsg .= str_replace( $find, $repl, substr($orig, $freepos, $aa-$freepos) );
>                             $freepos = $aa;
>                             break;
>                         case '<pre c':
>                             $lock = 4;
>                             $newmsg .= str_replace( $find, $repl, substr($orig, $freepos, $aa-$freepos) );
>                             $freepos = $aa;
>                             break;
>                     }
>                 }
>                 elseif( $aa > 6 ) {
>                     switch( $lock ) {
>                         case 1:
>                             if( substr($orig, $aa - 4, 4) == '</a>' ) {
>                                 $lock = 0;
>                                 $newmsg .= substr( $orig, $freepos, $aa-$freepos );
>                                 $freepos = $aa;
>                             }
>                             break;
>                         case 2:
>                             if( substr($orig, $aa - 7, 7) == '</span>' ) {
>                                 $lock = 0;
>                                 $newmsg .= substr( $orig, $freepos, $aa-$freepos );
>                                 $freepos = $aa;
>                             }
>                             break;
>                         case 3:
>                             if( substr($orig, $aa - 2, 2) == '/>' ) {
>                                 $lock = 0;
>                                 $newmsg .= substr( $orig, $freepos, $aa-$freepos );
>                                 $freepos = $aa;
>                             }
>                             break;
>                         case 4:
>                             if( substr($orig, $aa - 6, 6) == '</pre>' ) {
>                                 $lock = 0;
>                                 $newmsg .= substr( $orig, $freepos, $aa-$freepos );
>                                 $freepos = $aa;
>                             }
>                             break;
>                     }
>                 }
>             }
>             if( $lock ) {
>                 $newmsg .= substr( $orig, $freepos, $aa-$freepos );
>             }
>             else {
>                 $newmsg .= str_replace( $find, $repl, substr($orig, $freepos, $aa-$freepos) );
>             }
> 
>             $data[$key]['body'] = $newmsg;
Sorry, only registered users may post in this forum.

Click here to login