From 34437e368f24adbcd418bd82e6de41d839b1bc05 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 19 Jan 2022 09:49:56 -0500 Subject: [PATCH] [langfilter] Improve language detection by removing contiguous whitespace from the message - HTML-heavy posts had several superfluous whitespace character putting them over the minimum message length --- langfilter/langfilter.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/langfilter/langfilter.php b/langfilter/langfilter.php index c75a07b5..9d7b20a9 100644 --- a/langfilter/langfilter.php +++ b/langfilter/langfilter.php @@ -119,11 +119,13 @@ function langfilter_prepare_body_content_filter(App $a, &$hook_data) return; } - if (!empty($hook_data['item']['rendered-html'])) { - $naked_body = strip_tags($hook_data['item']['rendered-html']); - } else { - $naked_body = BBCode::toPlaintext($hook_data['item']['body'], false); - } + $naked_body = strip_tags( + $hook_data['item']['rendered-html'] + ??''?: // Equivalent of !empty() + BBCode::convert($hook_data['item']['body'], false, BBCode::INTERNAL, true) + ); + + $naked_body = preg_replace('#\s+#', ' ', trim($naked_body)); // Don't filter if body lenght is below minimum $minlen = DI::pConfig()->get(local_user(), 'langfilter', 'minlength', 32); -- 2.39.5