]> git.mxchange.org Git - friendica.git/commitdiff
Use "IntlChar" for the emoji detection
authorMichael <heluecht@pirati.ca>
Thu, 12 Oct 2023 21:23:08 +0000 (21:23 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 12 Oct 2023 21:23:08 +0000 (21:23 +0000)
src/Content/Smilies.php

index 8744e19995aec9cfcf93ce88e53119fce6131c70..7d3e4073f480b8130c3c3d3bd321b0b031922121 100644 (file)
@@ -296,7 +296,22 @@ class Smilies
        {
                // Strips all whitespace
                $conv = preg_replace('#\s#u', '', html_entity_decode($body));
-               // @FIXME Emojis are almost always 4 byte Unicode characters, except when they include the zero-width joiner character, encoded on 3 bytes
-               return (!empty($conv) && (strlen($conv) / mb_strlen($conv) == 4));
+               if (empty($conv)) {
+                       return false;
+               }
+
+               if (!class_exists('IntlChar')) {
+                       // Most Emojis are 4 byte Unicode characters, so this is a good workaround, when IntlChar does not exist on the system
+                       return strlen($conv) / mb_strlen($conv) == 4;
+               }
+
+               for ($i = 0; $i < mb_strlen($conv); $i++) {
+                       $character = mb_substr($conv, $i, 1);
+
+                       if (\IntlChar::isalnum($character)) {
+                               return false;
+                       }
+               }
+               return true;
        }
 }