return '[url=' . $data['url'] . ']@' . $data['nick'] . '[/url]';
}
+ /**
+ * Callback function to replace a Friendica style mention in a mention for a summary
+ *
+ * @param array $match Matching values for the callback
+ * @return string Replaced mention
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ */
+ private static function mentionAddrCallback($match)
+ {
+ if (empty($match[1])) {
+ return '';
+ }
+
+ $data = Contact::getByURL($match[1], false, ['addr', 'nick']);
+ if (empty($data['addr'])) {
+ return $match[0];
+ }
+
+ return '@' . $data['addr'];
+ }
+
/**
* Remove image elements since they are added as attachment
*
if ($type == 'Note') {
$body = $item['raw-body'] ?? self::removePictures($body);
} elseif (($type == 'Article') && empty($data['summary'])) {
- $data['summary'] = BBCode::toPlaintext(Plaintext::shorten(self::removePictures($body), 1000));
+ $regexp = "/[@!]\[url\=([^\[\]]*)\].*?\[\/url\]/ism";
+ $summary = preg_replace_callback($regexp, ['\Friendica\Protocol\ActivityPub\Transmitter', 'mentionAddrCallback'], $body);
+ $data['summary'] = BBCode::toPlaintext(Plaintext::shorten(self::removePictures($summary), 1000));
}
if (empty($item['uid']) || !Feature::isEnabled($item['uid'], 'explicit_mentions')) {