diff --git a/Web/Models/Entities/Traits/TRichText.php b/Web/Models/Entities/Traits/TRichText.php index 6bb7f304..faec0bca 100644 --- a/Web/Models/Entities/Traits/TRichText.php +++ b/Web/Models/Entities/Traits/TRichText.php @@ -26,6 +26,21 @@ trait TRichText return $text; } + + private function formatLinks(string &$text): string + { + return preg_replace_callback( + "%(([A-z]++):\/\/(\S*?\.\S*?))([\s)\[\]{},;\"\'<]|\.\s|$)%", + (function (array $matches): string { + $href = str_replace("#", "#", $matches[1]); + $link = str_replace("#", "#", $matches[3]); + $rel = $this->isAd() ? "sponsored" : "ugc"; + + return "$link" . htmlentities($matches[4]); + }), + $text + ); + } private function removeZalgo(string $text): string { @@ -39,11 +54,7 @@ trait TRichText if($html) { if($proc) { $rel = $this->isAd() ? "sponsored" : "ugc"; - $text = preg_replace( - "%((https?|ftp):\/\/(\S*?\.\S*?))([\s)\[\]{},;\"\':<]|\.\s|$)%", - "$3$4", - $text - ); + $text = $this->formatLinks($text); $text = preg_replace("%@(id|club)([0-9]++) \(([\p{L} 0-9]+)\)%Xu", "[$1$2|$3]", $text); $text = preg_replace("%@(id|club)([0-9]++)%Xu", "[$1$2|@$1$2]", $text); $text = preg_replace("%\[(id|club)([0-9]++)\|([\p{L} 0-9@]+)\]%Xu", "$3", $text);