Issue 13828: Use the alias as profile link if present

This commit is contained in:
Michael 2024-01-14 07:47:47 +00:00
parent 5dc49352e8
commit 5184aa990c
4 changed files with 22 additions and 9 deletions

View File

@ -383,7 +383,7 @@ class Item
'url' => $item['author-link'],
'alias' => $item['author-alias'],
];
$profile_link = Contact::magicLinkByContact($author, $item['author-link']);
$profile_link = Contact::magicLinkByContact($author, Contact::getProfileLink($author));
if (strpos($profile_link, 'contact/redir/') === 0) {
$status_link = $profile_link . '?' . http_build_query(['url' => $item['author-link'] . '/status']);
$photos_link = $profile_link . '?' . http_build_query(['url' => $item['author-link'] . '/photos']);

View File

@ -45,19 +45,21 @@ class Hovercard
$actions = [];
}
$contact_url = Contact::getProfileLink($contact);
// Move the contact data to the profile array so we can deliver it to
$tpl = Renderer::getMarkupTemplate('hovercard.tpl');
return Renderer::replaceMacros($tpl, [
'$profile' => [
'name' => $contact['name'],
'nick' => $contact['nick'],
'addr' => $contact['addr'] ?: $contact['url'],
'addr' => $contact['addr'] ?: $contact_url,
'thumb' => Contact::getThumb($contact),
'url' => Contact::magicLinkByContact($contact),
'nurl' => $contact['nurl'],
'location' => $contact['location'],
'about' => $contact['about'],
'network_link' => Strings::formatNetworkName($contact['network'], $contact['url']),
'network_link' => Strings::formatNetworkName($contact['network'], $contact_url),
'tags' => $contact['keywords'],
'bd' => $contact['bd'] <= DBA::NULL_DATE ? '' : $contact['bd'],
'account_type' => Contact::getAccountType($contact['contact-type']),

View File

@ -50,11 +50,7 @@ class VCard
Logger::warning('Incomplete contact', ['contact' => $contact ?? []]);
}
if (!Network::isValidHttpUrl($contact['url']) && Network::isValidHttpUrl($contact['alias'])) {
$contact_url = $contact['alias'];
} else {
$contact_url = $contact['url'];
}
$contact_url = Contact::getProfileLink($contact);
if ($contact['network'] != '') {
$network_link = Strings::formatNetworkName($contact['network'], $contact_url);

View File

@ -3490,6 +3490,21 @@ class Contact
return array_column($contacts, 'id');
}
/**
* Return the link to the profile
*
* @param array $contact
* @return string
*/
public static function getProfileLink(array $contact): string
{
if (!empty($contact['alias']) && Network::isValidHttpUrl($contact['alias']) && (($contact['network'] ?? '') != Protocol::DFRN)) {
return $contact['alias'];
} else {
return $contact['url'];
}
}
/**
* Returns a magic link to authenticate remote visitors
*
@ -3548,7 +3563,7 @@ class Contact
*/
public static function magicLinkByContact(array $contact, string $url = ''): string
{
$destination = $url ?: (!Network::isValidHttpUrl($contact['url']) && !empty($contact['alias']) && Network::isValidHttpUrl($contact['alias']) ? $contact['alias'] : $contact['url']);
$destination = $url ?: self::getProfileLink($contact);
if (!DI::userSession()->isAuthenticated()) {
return $destination;