Simple Machines Community Forum

SMF Support => SMF 2.1.x Support => Topic started by: Biology Forums on March 15, 2019, 12:18:21 PM

Title: Do emojis render correctly on SMF 2.1?
Post by: Biology Forums on March 15, 2019, 12:18:21 PM
Do emojis render correctly on SMF 2.1?
Title: Re: Do emojis render correctly on SMF 2.1?
Post by: Aleksi "Lex" Kilpinen on March 15, 2019, 12:25:06 PM
I do believe they should, but don't take this as a promise.
Title: Re: Do emojis render correctly on SMF 2.1?
Post by: Bigguy on March 15, 2019, 12:35:16 PM
All seems fine on both my sites.
Title: Re: Do emojis render correctly on SMF 2.1?
Post by: Biology Forums on March 15, 2019, 02:13:57 PM
What makes 2.1 capable of rendering them that 2.0 and 1.x don't necessarily have?
Title: Re: Do emojis render correctly on SMF 2.1?
Post by: Gwenwyfar on March 15, 2019, 02:14:19 PM
I believe they should work anywhere that utf-8 is accepted. The rest depends on the browser. Ex: 🌸
Title: Re: Do emojis render correctly on SMF 2.1?
Post by: Aleksi "Lex" Kilpinen on March 15, 2019, 02:16:29 PM
Quote from: Study Force on March 15, 2019, 02:13:57 PM
What makes 2.1 capable of rendering them that 2.0 and 1.x don't necessarily have?
If I understood right, 1.1 and 2.0 may break them in how they are saved to the DB.
Title: Re: Do emojis render correctly on SMF 2.1?
Post by: Arantor on March 15, 2019, 02:26:30 PM
1.1 will break them, 2.0 shouldn't, 2.1 really really shouldn't break them.
Title: Re: Do emojis render correctly on SMF 2.1?
Post by: Biology Forums on March 15, 2019, 02:27:38 PM
I just checked on SMF 2.0.15, emojis do render correctly.

What should I look at to possibly make them work on 1.x? Which function, for example, should I start my focus?
Title: Re: Do emojis render correctly on SMF 2.1?
Post by: Arantor on March 15, 2019, 02:29:15 PM
You can look at what $smcFunc['htmlspecialchars'] does, but I don't know if SMF 1.1 uses its equivalent everywhere correctly,
Title: Re: Do emojis render correctly on SMF 2.1?
Post by: Biology Forums on March 15, 2019, 02:38:49 PM
Thank you everyone. I'll start by analyzing $smcFunc['htmlspecialchars'] then look for the smf 1.x equivalent then piece together what I need.
Title: Re: Do emojis render correctly on SMF 2.1?
Post by: Biology Forums on March 15, 2019, 02:55:07 PM
So here's the fix.

Find in Load.php (1.x)

'htmlspecialchars' => create_function('$string, $quote_style = ENT_COMPAT, $charset = \'ISO-8859-1\'', '
global $func;
return ' . strtr($ent_check[0], array('&' => '&'))  . 'htmlspecialchars($string, $quote_style, ' . ($utf8 ? '\'UTF-8\'' : '$charset') . ')' . $ent_check[1] . ';'),


Replace with:

'htmlspecialchars' => create_function('$string, $quote_style = ENT_COMPAT, $charset = \'ISO-8859-1\'', '
global $func;
return ' . ($utf8 ? '$func[\'fix_utf8mb4\'](' : '') . strtr($ent_check[0], array('&' => '&')) . 'htmlspecialchars($string, $quote_style, ' . ($utf8 ? '\'UTF-8\'' : '$charset') . ')' . $ent_check[1] . ($utf8 ? ')' : '') . ';'),


'fix_utf8mb4' => create_function('$string', '
$i = 0;
$len = strlen($string);
$new_string = \'\';
while ($i < $len)
{
$ord = ord($string[$i]);
if ($ord < 128)
{
$new_string .= $string[$i];
$i++;
}
elseif ($ord < 224)
{
$new_string .= $string[$i] . $string[$i+1];
$i += 2;
}
elseif ($ord < 240)
{
$new_string .= $string[$i] . $string[$i+1] . $string[$i+2];
$i += 3;
}
elseif ($ord < 248)
{
// Magic happens.
$val = (ord($string[$i]) & 0x07) << 18;
$val += (ord($string[$i+1]) & 0x3F) << 12;
$val += (ord($string[$i+2]) & 0x3F) << 6;
$val += (ord($string[$i+3]) & 0x3F);
$new_string .= \'&#\' . $val . \';\';
$i += 4;
}
}
return $new_string;'),


Thank you, Arantor
Title: Re: Do emojis render correctly on SMF 2.1?
Post by: Kindred on March 15, 2019, 07:03:50 PM
you know what the BETTER fix is?  upgrade your SMF to a modern version that does not have known, unpatched security issues....
Title: Re: Do emojis render correctly on SMF 2.1?
Post by: Biology Forums on March 16, 2019, 12:42:45 AM
Quoteyou know what the BETTER fix is?

found it! https://www.simplemachines.org/community/index.php?topic=566029.msg4011519#msg4011519
Title: Re: Do emojis render correctly on SMF 2.1?
Post by: albertlast on March 16, 2019, 03:37:34 AM
This "fix" is more a hack than something else,
modern setup with postgres oder mysql with mb4 didn't use this any more.
Title: Re: Do emojis render correctly on SMF 2.1?
Post by: Arantor on March 16, 2019, 04:31:07 AM
The best solution is to native to something that actually support ps it properly rather than using a workaround.

@albertlast, when I wrote that "hack" mb4 support was not especially widespread in hosting communities that SMF users actually use, but it's good to know that you think so highly of my work. I guess we should stop supporting everyone except those who can run bleeding edge versions of things.
Title: Re: Do emojis render correctly on SMF 2.1?
Post by: albertlast on March 16, 2019, 04:57:37 AM
To be ownest i was thinking on study and not at you and
i only want to describe how 2.1 works internaly since we are here in 2.1 part.
Title: Re: Do emojis render correctly on SMF 2.1?
Post by: Biology Forums on March 16, 2019, 12:42:51 PM
Quote from: albertlast on March 16, 2019, 03:37:34 AM
This "fix" is more a hack than something else,
modern setup with postgres oder mysql with mb4 didn't use this any more.

So 2.0.x used a hack to make emojis supportable? That's interesting.

I'm in the process of learning the 2.x system, I'm currently educating myself about 2.x. Hopefully by the time I'm comfortable, 2.1 will be officially released and I can make the switcharoo
Title: Re: Do emojis render correctly on SMF 2.1?
Post by: Arantor on March 16, 2019, 01:49:19 PM
Yes, it used a hack I came up with (which you've found) because the issue is that emojis require 4-byte UTF-8 storage and this is what utf8mb4 is, while SMF 2.0 doesn't technically support it at all, and when I put the hack together, MySQL on a lot of shared hosts didn't support it either... so I came up with a way to safely encode emoji into entities so they could at least be stored and displayed.
Title: Re: Do emojis render correctly on SMF 2.1?
Post by: Biology Forums on March 16, 2019, 02:49:58 PM
@Arantor -- Curious though, why you didn't tell me right from the get-go? In other words, why did you make me look for it? Is it because you weren't confident with your own solution?
Title: Re: Do emojis render correctly on SMF 2.1?
Post by: Arantor on March 16, 2019, 03:14:38 PM
Because being around here isn't my day job and I was typing that on an iPad in between doing my actual job.
Title: Re: Do emojis render correctly on SMF 2.1?
Post by: Doug Heffernan on March 16, 2019, 03:23:33 PM
Quote from: Study Force on March 16, 2019, 02:49:58 PM
@Arantor -- Curious though, why you didn't tell me right from the get-go? In other words, why did you make me look for it? Is it because you weren't confident with your own solution?

I have to say, I find this a rather strange question. It comes off as complaining to me. That you had to look for something, that you wanted/needed to know for yourself.

You should have looked/searched for it yourself in the first place, before asking the question imo.

Title: Re: Do emojis render correctly on SMF 2.1?
Post by: Biology Forums on March 16, 2019, 04:45:03 PM
It's a fair question b/c he designed the hack. If I designed a hack, I wouldn't dance around the solution. Not saying that's what Arantor did, but given the logistics I do understand why he wasn't entirely explicit. It was transparent enough to know how to move forward.

To quote Forrest Gump, "and that's all I have to say about"