+ /**
+ * Replace names in mentions with nicknames
+ *
+ * @param string $body
+ * @return string Body with replaced mentions
+ */
+ public static function setMentionsToNicknames(string $body):string
+ {
+ DI::profiler()->startRecording('rendering');
+ $regexp = "/([@!])\[url\=([^\[\]]*)\].*?\[\/url\]/ism";
+ $body = preg_replace_callback($regexp, ['self', 'mentionCallback'], $body);
+ DI::profiler()->stopRecording();
+ return $body;
+ }
+
+ /**
+ * Callback function to replace a Friendica style mention in a mention with the nickname
+ *
+ * @param array $match Matching values for the callback
+ * @return string Replaced mention
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ */
+ private static function mentionCallback($match)
+ {
+ if (empty($match[2])) {
+ return '';
+ }
+
+ $data = Contact::getByURL($match[2], false, ['url', 'nick']);
+ if (empty($data['nick'])) {
+ return $match[0];
+ }
+
+ return $match[1] . '[url=' . $data['url'] . ']' . $data['nick'] . '[/url]';
+ }
+
+ /**
+ * Converts a BBCode message for a given URI-ID to a HTML message
+ *
+ * BBcode 2 HTML was written by WAY2WEB.net
+ * extended to work with Mistpark/Friendica - Mike Macgirvin
+ *
+ * Simple HTML values meaning:
+ * - 0: Friendica display
+ * - 1: Unused
+ * - 2: Used for Windows Phone push, Friendica API
+ * - 3: Used before converting to Markdown in bb2diaspora.php
+ * - 4: Used for WordPress, Libertree (before Markdown), pump.io and tumblr
+ * - 5: Unused
+ * - 6: Unused
+ * - 7: Used for dfrn, OStatus
+ * - 8: Used for Twitter, WP backlink text setting
+ * - 9: ActivityPub
+ *
+ * @param int $uriid
+ * @param string $text
+ * @param int $simple_html
+ * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ */
+ public static function convertForUriId(int $uriid = null, string $text = null, int $simple_html = self::INTERNAL)
+ {
+ $try_oembed = ($simple_html == self::INTERNAL);
+
+ return self::convert($text ?? '', $try_oembed, $simple_html, false, $uriid ?? 0);
+ }
+