Posts without text or only with emojis are now always accepted in the language check

This commit is contained in:
Michael 2023-08-28 15:37:20 +00:00
parent 5f832cb75a
commit 4dbb7dd3da
3 changed files with 21 additions and 6 deletions

View file

@ -285,4 +285,17 @@ class Smilies
return str_replace($matches[0], $t, $matches[0]); 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));
}
} }

View file

@ -1735,13 +1735,9 @@ class BBCode
$text = preg_replace("/\[event\-id\](.*?)\[\/event\-id\]/ism", '', $text); $text = preg_replace("/\[event\-id\](.*?)\[\/event\-id\]/ism", '', $text);
} }
if (!$for_plaintext && DI::config()->get('system', 'big_emojis') && ($simple_html != self::DIASPORA)) { if (!$for_plaintext && DI::config()->get('system', 'big_emojis') && ($simple_html != self::DIASPORA) && Smilies::isEmojiPost($text)) {
$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>'; $text = '<span style="font-size: xx-large; line-height: normal;">' . $text . '</span>';
} }
}
// Handle mentions and hashtag links // Handle mentions and hashtag links
if ($simple_html == self::DIASPORA) { if ($simple_html == self::DIASPORA) {

View file

@ -21,6 +21,7 @@
namespace Friendica\Protocol; namespace Friendica\Protocol;
use Friendica\Content\Smilies;
use Friendica\Content\Text\BBCode; use Friendica\Content\Text\BBCode;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
@ -157,6 +158,11 @@ class Relay
*/ */
public static function isWantedLanguage(string $body) public static function isWantedLanguage(string $body)
{ {
if (empty($body) || Smilies::isEmojiPost($body)) {
Logger::debug('Empty body or only emojis', ['body' => $body]);
return true;
}
$languages = []; $languages = [];
foreach (Item::getLanguageArray($body, 10) as $language => $reliability) { foreach (Item::getLanguageArray($body, 10) as $language => $reliability) {
if ($reliability > 0) { if ($reliability > 0) {