]> git.mxchange.org Git - friendica.git/commitdiff
Posts without text or only with emojis are now always accepted in the language check
authorMichael <heluecht@pirati.ca>
Mon, 28 Aug 2023 15:37:20 +0000 (15:37 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 28 Aug 2023 15:37:20 +0000 (15:37 +0000)
src/Content/Smilies.php
src/Content/Text/BBCode.php
src/Protocol/Relay.php

index d231797b8110718fddb6c41ed88a8f7bdbd94ad3..6d07de575c3973d7421d817d5aab0ef12837867a 100644 (file)
@@ -285,4 +285,17 @@ class Smilies
 
                return str_replace($matches[0], $t, $matches[0]);
        }
+
+       /**
+        * Checks if the body only contains 4 byte unicode characters.
+        *
+        * @param string $body
+        * @return boolean
+        */
+       public static function isEmojiPost(string $body): bool
+       {
+               $conv = html_entity_decode(str_replace([' ', "\n", "\r"], '', $body));
+               // Emojis are always 4 byte Unicode characters
+               return (!empty($conv) && (strlen($conv) / mb_strlen($conv) == 4));
+       }
 }
index ab7300da18b5c3e4f35b4bed9745374aee45bde5..239e6dfa092c6217bf6ed4ca5c643706eb285726 100644 (file)
@@ -1735,12 +1735,8 @@ class BBCode
                                        $text = preg_replace("/\[event\-id\](.*?)\[\/event\-id\]/ism", '', $text);
                                }
 
-                               if (!$for_plaintext && DI::config()->get('system', 'big_emojis') && ($simple_html != self::DIASPORA)) {
-                                       $conv = html_entity_decode(str_replace([' ', "\n", "\r"], '', $text));
-                                       // Emojis are always 4 byte Unicode characters
-                                       if (!empty($conv) && (strlen($conv) / mb_strlen($conv) == 4)) {
-                                               $text = '<span style="font-size: xx-large; line-height: normal;">' . $text . '</span>';
-                                       }
+                               if (!$for_plaintext && DI::config()->get('system', 'big_emojis') && ($simple_html != self::DIASPORA) && Smilies::isEmojiPost($text)) {
+                                       $text = '<span style="font-size: xx-large; line-height: normal;">' . $text . '</span>';
                                }
 
                                // Handle mentions and hashtag links
index 2002aa9bb8cb3426fdc51e5b642a20d05eeed749..8bcced7567cc163a0acde3238654ef6853703248 100644 (file)
@@ -21,6 +21,7 @@
 
 namespace Friendica\Protocol;
 
+use Friendica\Content\Smilies;
 use Friendica\Content\Text\BBCode;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
@@ -157,6 +158,11 @@ class Relay
         */
        public static function isWantedLanguage(string $body)
        {
+               if (empty($body) || Smilies::isEmojiPost($body)) {
+                       Logger::debug('Empty body or only emojis', ['body' => $body]);
+                       return true;
+               }
+
                $languages = [];
                foreach (Item::getLanguageArray($body, 10) as $language => $reliability) {
                        if ($reliability > 0) {