diff --git a/src/Content/Smilies.php b/src/Content/Smilies.php index d231797b81..6d07de575c 100644 --- a/src/Content/Smilies.php +++ b/src/Content/Smilies.php @@ -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)); + } } diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index ab7300da18..239e6dfa09 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -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 = '' . $text . ''; - } + if (!$for_plaintext && DI::config()->get('system', 'big_emojis') && ($simple_html != self::DIASPORA) && Smilies::isEmojiPost($text)) { + $text = '' . $text . ''; } // Handle mentions and hashtag links diff --git a/src/Protocol/Relay.php b/src/Protocol/Relay.php index 2002aa9bb8..8bcced7567 100644 --- a/src/Protocol/Relay.php +++ b/src/Protocol/Relay.php @@ -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) {