Howto avoid smiley interpretation in code, url etc.?
Posted by covex
Howto avoid smiley interpretation in code, url etc.? December 02, 2007 12:30PM |
Registered: 17 years ago Posts: 11 |
Re: Howto avoid smiley interpretation in code, url etc.? December 02, 2007 03:53PM |
Admin Registered: 19 years ago Posts: 8,532 |
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
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 |
Registered: 12 years ago Posts: 1 |
No, you can only disable smileys in the message. The problem described above is that smiley codes are also being parsed within bbcode tags.Quote
Maurice Makaay
In phorum 5.2 you can make use of that feature. It is added to the smileys and the bbcode module.
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 |
Registered: 17 years ago Posts: 11 |
Re: Howto avoid smiley interpretation in code, url etc.? November 08, 2011 05:20AM |
Registered: 17 years ago Posts: 11 |
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.