diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 5b22746ce..594cd9a6c 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1220,6 +1220,17 @@ class BBCode return $return; } + public static function removeLinks(string $bbcode) + { + $bbcode = preg_replace("/\[img\=(.*?)\](.*?)\[\/img\]/ism", ' $1 ', $bbcode); + $bbcode = preg_replace("/\[img.*?\[\/img\]/ism", ' ', $bbcode); + + $bbcode = preg_replace('/[@!#]\[url\=.*?\].*?\[\/url\]/ism', '', $bbcode); + $bbcode = preg_replace("/\[url=[^\[\]]*\](.*)\[\/url\]/Usi", ' $1 ', $bbcode); + $bbcode = preg_replace('/[@!#]?\[url.*?\[\/url\]/ism', '', $bbcode); + return $bbcode; + } + /** * Converts a BBCode message to HTML message * diff --git a/src/Model/Item.php b/src/Model/Item.php index 609535974..84033bc9d 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -2482,7 +2482,17 @@ class Item return ''; } - $naked_body = BBCode::toPlaintext($item['body'], false); + // Convert attachments to links + $naked_body = BBCode::removeAttachment($item['body']); + + // Remove links and pictures + $naked_body = BBCode::removeLinks($naked_body); + + // Convert the title and the body to plain text + $naked_body = trim($item['title'] . "\n" . BBCode::toPlaintext($naked_body)); + + // Remove possibly remaining links + $naked_body = preg_replace(Strings::autoLinkRegEx(), '', $naked_body); $ld = new Language(); $languages = $ld->detect($naked_body)->limit(0, 3)->close();