MyBB Community Forums

Full Version: Any good reason for replacing smilies this way?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I just noticed that if you have two smilies with the following code:
:-? and :-?? ... and when :-?? is used, it gets converted in the following fashion: (assume ":-?" = thinking.gif, and ":-??" = whaaat.gif)

<img src="http://url.com/images/smilies/whaaat.gif" style="vertical-align: middle;" border="0" alt="<img src="http://url.com/images/smilies/thinking.gif" style="vertical-align: middle;" border="0" alt=":-?" title=":-?" />?" title="<img src="http://url.com/images/smilies/thinking.gif" style="vertical-align: middle;" border="0" alt=":-?" title=":-?" />?" />

So it seems to be replacing again when it finds ":-?" in title attribute. I know it's my fault (or the MyBB Merge converters fault for using the code as the name), but it still tells something.

I don't like the idea of using str_replace at all, as many of the time it produces unexpected results. Maybe using a space before, or after the smilie is a good idea. Something like this: (just a rough example, not tested, but delivers my idea)

$var = preg_replace("#(^|\s){$smilie_code_cleaned}(\s|$)#", '\\1{$replacement}\\2", $var);

I think MyBB promotes the idea of more well-formed smilie codes and differentiation between codes and names, but give me a break, no one can keep guessing what will break the functionality.
I think this has been discussed before, and I believe the proper solution is to use well formed smilie data. Meaning you can have a replacement of say for instance, 'b' then it would replace every -b- letter with the smilie. The same applies to that.
I thought we fixed the problem with :-? and :-?? because now the smileys are sorted so that they the longest smiley replace codes are executed first, ie. :-?? is replaced before :-?

However, I think one of the problems that still persist is that if the smiley code is also present in another previously parsed smiley's HTML, then that would break.