From cdeb4682ef6fc0ed6d5f6264564ffd29c1ac735c Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 19 Oct 2018 05:27:54 +0000 Subject: [PATCH] Use nickname based mentions for AP --- src/Protocol/ActivityPub/Transmitter.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 7f22e8386b..2a930fcc6f 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -743,6 +743,26 @@ class Transmitter return $attachments; } + /** + * @brief Callback function to replace a Friendica style mention in a mention that is used on AP + * + * @param array $match Matching values for the callback + * @return string Replaced mention + */ + private static function MentionCallback($match) + { + if (empty($match[1])) { + return; + } + + $data = Contact::getDetailsByURL($match[1]); + if (empty($data) || empty($data['nick'])) { + return; + } + + return '@[url=' . $data['url'] . ']' . $data['nick'] . '[/url]'; + } + /** * Remove image elements and replaces them with links to the image * @@ -851,6 +871,9 @@ class Transmitter $body = self::removePictures($body); } + $regexp = "/[@!]\[url\=([^\[\]]*)\].*?\[\/url\]/ism"; + $body = preg_replace_callback($regexp, ['self', 'MentionCallback'], $body); + $data['content'] = BBCode::convert($body, false, 7); $data['source'] = ['content' => $item['body'], 'mediaType' => "text/bbcode"]; -- 2.39.5