Merge pull request #13987 from annando/api-issues

Fixes API-Issues #13985 and #13986
This commit is contained in:
Hypolite Petovan 2024-03-12 19:33:42 +00:00 committed by GitHub
commit 7446048d5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 44 additions and 4 deletions

View file

@ -1245,6 +1245,42 @@ class BBCode
return $match[1] . '[url=' . $data['url'] . ']' . $data['nick'] . '[/url]';
}
/**
* Replace mention links
*
* @param string $body HTML/BBCode
* @return string Body with replaced mentions
*/
public static function setMentionsToAddr(string $body): string
{
DI::profiler()->startRecording('rendering');
$regexp = "/([@!])\[url\=([^\[\]]*)\].*?\[\/url\]/ism";
$body = preg_replace_callback($regexp, [self::class, 'mentionToAddrCallback'], $body);
DI::profiler()->stopRecording();
return $body;
}
/**
* Callback function to replace a Friendica style mention in a mention with the addr
*
* @param array $match Matching values for the callback
* @return string Replaced mention or empty string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function mentionToAddrCallback(array $match): string
{
if (empty($match[2])) {
return '';
}
$data = Contact::getByURL($match[2], false, ['url', 'nick', 'addr']);
if (empty($data['nick'])) {
return $match[0];
}
return $match[1] . ($data['addr'] ?: $data['nick']);
}
/**
* Normalize links to Youtube and Vimeo to a unified format.
*