MyBB Community Forums

Full Version: Smilies problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys,
i have a problem with the smilies.
I have converted from phpbb and all the smilies are inserted in mybb just fine.
The names and "text to replace" in most of the smilies is similar (i.e. :emot1 , :emot2, :emot12 etc).
When i click on the smiley :emot12 for example then in the message it shows the smiley :emot1 and after that the number '2'.
It's like it doesn't recognize the whole name of the emoticon and when it finds something to replace it does it and prints the rest of the text.
In phpbb it worked fine.

Do you have any ideas?
Thanks
There are problems if you have similar emoticon codes that overlap such as:

:emot1
:emot12

Those may not work together*. You should choose new codes for your emoticons that overlap with other codes:

:emot01
:emot12



* Why I say "may not" is that under certain circumstances when the :emot12 emoticon was inserted into the database earlier than :emot1, the smileys would work as expected as :emot12 is replaced earlier than :emot1, but if :emot1 is replaced earlier than :emot12, then the :emot1 part of :emot12 will be replaced with the :emot1 pic.
so there is no way to change something in the sql queries?

hmmmm

ok! thanks
ok...done!
solved
Dennis, couldn't we prevent that problem by looking for exact matches with a space after them?
It's possible, but then it would be necessary to have a space after each emoticon, and if you have an emoticon at the end of a message, there wouldn't be a space after it, or if you stuck an emoBig Grinicon in somewhere...Toungue... Or maybe I have misinterpreted your post entirely Wink
I'm guessing you use preg_replace to put the emotes in place of the code? (posifty uses something like that for [ url] tags). If so you could use \b before and after the emote. \b is a word doundary and I don't think " is called as part of a word. Not sure though. Just an idea.
Here's the current smilies code:

function dosmilies($message, $url="")
{
	global $db, $smiliecache, $cache;

	if($url != "")
	{
		if(substr($url, strlen($url) -1) != "/")
		{
			$url = $url."/";
		}
	}
	
	$smiliecache = $cache->read("smilies");
	if(is_array($smiliecache))
	{
		reset($smiliecache);
		foreach($smiliecache as $sid => $smilie)
		{
			$message = str_replace($smilie['find'], "<img src=\"".$url.$smilie['image']."\" align=\"middle\" border=\"0\" alt=\"".$smilie['name']."\" />", $message);
		}
	}
	return $message;
}
I have this problem too. Isn't it possible to order the smilies on the length of 'Text to replace' and check for the longest one first?
nobody?