]> git.mxchange.org Git - friendica-addons.git/commitdiff
[langfilter] Improve language detection by removing contiguous whitespace from the...
authorHypolite Petovan <hypolite@mrpetovan.com>
Wed, 19 Jan 2022 14:49:56 +0000 (09:49 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Thu, 20 Jan 2022 00:52:04 +0000 (19:52 -0500)
- HTML-heavy posts had several superfluous whitespace character putting them over the minimum message length

langfilter/langfilter.php

index c75a07b507a6da337b71060acfd6c36ff9342b01..9d7b20a92c7ba9569517531f6dc08b3f382b539b 100644 (file)
@@ -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);