X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=src%2FContent%2FText%2FBBCode.php;h=32cd818cac690c29364802f70bc7df59dc9008d7;hb=1cc341033f28f35b66400a394d1031c2e885a302;hp=af423a676a6d698ee81120828aa349c9f1a1469c;hpb=d9bfd78bd450bf5f829904fe67456b41db59d621;p=friendica.git diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index af423a676a..32cd818cac 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -2115,6 +2115,32 @@ class BBCode return array_unique($ret); } + /** + * Expand tags to URLs + * + * @param string $body + * @return string body with expanded tags + */ + public static function expandTags(string $body) + { + return preg_replace_callback("/([!#@])([^\^ \x0D\x0A,;:?\']*[^\^ \x0D\x0A,;:?!\'.])/", + function ($match) { + switch ($match[1]) { + case '!': + case '@': + $contact = Contact::getByURL($match[2]); + if (!empty($contact)) { + return $match[1] . '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]'; + } else { + return $match[1] . $match[2]; + } + break; + case '#': + return $match[1] . '[url=' . 'https://' . DI::baseUrl() . '/search?tag=' . $match[2] . ']' . $match[2] . '[/url]'; + } + }, $body); + } + /** * Perform a custom function on a text after having escaped blocks enclosed in the provided tag list. *