mirror of
https://github.com/friendica/friendica
synced 2025-04-22 19:10:12 +00:00
New function to replace mentions with nicknames
This commit is contained in:
parent
bb5f738619
commit
71f53c946f
3 changed files with 36 additions and 26 deletions
|
@ -1263,6 +1263,39 @@ class BBCode
|
|||
return $bbcode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace names in mentions with nicknames
|
||||
*
|
||||
* @param string $body
|
||||
* @return string Body with replaced mentions
|
||||
*/
|
||||
public static function setMentionsToNicknames(string $body):string
|
||||
{
|
||||
$regexp = "/([@!])\[url\=([^\[\]]*)\].*?\[\/url\]/ism";
|
||||
return preg_replace_callback($regexp, ['self', 'mentionCallback'], $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
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue