From 10eba95e069e3dc04283abe59e872404a32a5df9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Tue, 18 May 2021 22:07:49 +0200 Subject: [PATCH] add tag parse on messages --- app/Lib/Utils.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Lib/Utils.php b/app/Lib/Utils.php index 10c11b6..457dc2e 100644 --- a/app/Lib/Utils.php +++ b/app/Lib/Utils.php @@ -9,11 +9,16 @@ class Utils $text = e($text); // url replace and email replace $text = preg_replace_callback( - '/([^\s@]+@([^\s@.,]+\.)+[^\s@.,]{2,})|(?:http[s]?:\/\/.)?(?:www\.)?[-a-zA-Z0-9@%._\+~#=]{2,256}\.[a-z]{2,6}\b(?:[-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)/', + '/(?P[^\s@]+@([^\s@.,]+\.)+[^\s@.,]{2,})|(?P@\w*)|(?P(?:http[s]?:\/\/.)?(?:www\.)?[-a-zA-Z0-9@%._\+~#=]{2,256}\.[a-z]{2,6}\b(?:[-a-zA-Z0-9@:%_\+.~#?&\/\/=]*))/', function ($matches) { $match = collect($matches)->first() ?? ''; if (filter_var($match, FILTER_VALIDATE_EMAIL)) { return strlen($match) ? "$match" : $match; + } elseif (isset($matches['user']) and strlen($matches['user'])) { + return sprintf( + '%s', + $matches['user'] + ); } else { $url = $match; if (\strpos($url, 'http') === false and \strpos($url, 'https') === false) {