Do emojis render correctly on SMF 2.1?
I do believe they should, but don't take this as a promise.
All seems fine on both my sites.
What makes 2.1 capable of rendering them that 2.0 and 1.x don't necessarily have?
I believe they should work anywhere that utf-8 is accepted. The rest depends on the browser. Ex: 🌸
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.
1.1 will break them, 2.0 shouldn't, 2.1 really really shouldn't break them.
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?
You can look at what $smcFunc['htmlspecialchars'] does, but I don't know if SMF 1.1 uses its equivalent everywhere correctly,
Thank you everyone. I'll start by analyzing $smcFunc['htmlspecialchars'] then look for the smf 1.x equivalent then piece together what I need.
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
you know what the BETTER fix is? upgrade your SMF to a modern version that does not have known, unpatched security issues....
Quoteyou know what the BETTER fix is?
found it! https://www.simplemachines.org/community/index.php?topic=566029.msg4011519#msg4011519
This "fix" is more a hack than something else,
modern setup with postgres oder mysql with mb4 didn't use this any more.
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.
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.
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
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.
@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?
Because being around here isn't my day job and I was typing that on an iPad in between doing my actual job.
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.
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"