Merge pull request #9513 from MrPetovan/task/9508-mastodon-handled-mentions

[AP] Use contact.alias if it exists instead of contact.url for mention links
This commit is contained in:
Michael Vogel 2020-11-09 07:45:27 +01:00 committed by GitHub
commit 8a055902f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 25 deletions

View File

@ -1509,29 +1509,9 @@ class BBCode
$text = str_replace('[hr]', '<hr />', $text);
if (!$for_plaintext) {
$escaped = [];
// Escaping BBCodes susceptible to contain rogue URL we don'' want the autolinker to catch
$text = preg_replace_callback('#\[(url|img|audio|video|youtube|vimeo|share|attachment|iframe|bookmark).+?\[/\1\]#ism',
function ($matches) use (&$escaped) {
$return = '{escaped-' . count($escaped) . '}';
$escaped[] = $matches[0];
return $return;
},
$text
);
// Autolinker for isolated URLs
$text = preg_replace(Strings::autoLinkRegEx(), '[url]$1[/url]', $text);
// Restoring escaped blocks
$text = preg_replace_callback('/{escaped-([0-9]+)}/iU',
function ($matches) use ($escaped) {
return $escaped[intval($matches[1])] ?? $matches[0];
},
$text
);
$text = self::performWithEscapedTags($text, ['url', 'img', 'audio', 'video', 'youtube', 'vimeo', 'share', 'attachment', 'iframe', 'bookmark'], function ($text) {
return preg_replace(Strings::autoLinkRegEx(), '[url]$1[/url]', $text);
});
}
// This is actually executed in Item::prepareBody()

View File

@ -1253,12 +1253,12 @@ class Transmitter
return '';
}
$data = Contact::getByURL($match[1], false, ['url', 'nick']);
$data = Contact::getByURL($match[1], false, ['url', 'alias', 'nick']);
if (empty($data['nick'])) {
return $match[0];
}
return '[url=' . $data['url'] . ']@' . $data['nick'] . '[/url]';
return '[url=' . ($data['alias'] ?: $data['url']) . ']@' . $data['nick'] . '[/url]';
}
/**