mirror of
https://git.friendi.ca/friendica/friendica.git
synced 2025-06-07 19:24:28 +02:00
Merge pull request #14892 from annando/reshare-profile
Use alias for profile link in reshare
This commit is contained in:
commit
8e0a3d00bb
4 changed files with 83 additions and 23 deletions
|
@ -913,13 +913,18 @@ class BBCode
|
||||||
default:
|
default:
|
||||||
$text = ($is_quote_share ? "\n" : '');
|
$text = ($is_quote_share ? "\n" : '');
|
||||||
|
|
||||||
$contact = Contact::getByURL($attributes['profile'], false, ['network']);
|
$contact = Contact::getByURL($attributes['profile'], false, ['network', 'url', 'alias']);
|
||||||
$network = $contact['network'] ?? Protocol::PHANTOM;
|
$network = $contact['network'] ?? Protocol::PHANTOM;
|
||||||
|
if (!empty($contact)) {
|
||||||
|
$profile = Contact::getProfileLink($contact);
|
||||||
|
} else {
|
||||||
|
$profile = $attributes['profile'];
|
||||||
|
}
|
||||||
|
|
||||||
$gsid = ContactSelector::getServerIdForProfile($attributes['profile']);
|
$gsid = ContactSelector::getServerIdForProfile($attributes['profile']);
|
||||||
$tpl = Renderer::getMarkupTemplate('shared_content.tpl');
|
$tpl = Renderer::getMarkupTemplate('shared_content.tpl');
|
||||||
$text .= self::SHARED_ANCHOR . Renderer::replaceMacros($tpl, [
|
$text .= self::SHARED_ANCHOR . Renderer::replaceMacros($tpl, [
|
||||||
'$profile' => $attributes['profile'],
|
'$profile' => $profile,
|
||||||
'$avatar' => $attributes['avatar'],
|
'$avatar' => $attributes['avatar'],
|
||||||
'$author' => $attributes['author'],
|
'$author' => $attributes['author'],
|
||||||
'$link' => $attributes['link'],
|
'$link' => $attributes['link'],
|
||||||
|
@ -1984,12 +1989,25 @@ class BBCode
|
||||||
'<a href="$2" class="mention hashtag" rel="tag">$1<span>$3</span></a>',
|
'<a href="$2" class="mention hashtag" rel="tag">$1<span>$3</span></a>',
|
||||||
$text
|
$text
|
||||||
);
|
);
|
||||||
} elseif (in_array($simple_html, [self::INTERNAL, self::EXTERNAL, self::TWITTER_API])) {
|
} elseif (in_array($simple_html, [self::EXTERNAL, self::TWITTER_API])) {
|
||||||
$text = preg_replace(
|
$text = preg_replace(
|
||||||
"/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
|
"/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
|
||||||
'<bdi>$1<a href="$2" class="userinfo mention" title="$3">$3</a></bdi>',
|
'<bdi>$1<a href="$2" class="userinfo mention" title="$3">$3</a></bdi>',
|
||||||
$text
|
$text
|
||||||
);
|
);
|
||||||
|
} elseif ($simple_html == self::INTERNAL) {
|
||||||
|
if (preg_match_all("/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism", $text, $matches, PREG_SET_ORDER)) {
|
||||||
|
foreach ($matches as $match) {
|
||||||
|
$contact = Contact::getByURL($match[2], false, ['network', 'url', 'alias']);
|
||||||
|
if (!empty($contact)) {
|
||||||
|
$url = Contact::getProfileLink($contact);
|
||||||
|
} else {
|
||||||
|
$url = $match[2];
|
||||||
|
}
|
||||||
|
$text = str_replace($match[0], '<bdi>' . $match[1] . '<a href="' . $url . '" class="userinfo mention" title="' . $match[3] . '">' . $match[3] . '</a></bdi>', $text);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
} elseif ($simple_html == self::MASTODON_API) {
|
} elseif ($simple_html == self::MASTODON_API) {
|
||||||
$text = preg_replace(
|
$text = preg_replace(
|
||||||
"/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
|
"/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
|
||||||
|
|
|
@ -506,13 +506,10 @@ class Processor
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'app.bsky.richtext.facet#mention':
|
case 'app.bsky.richtext.facet#mention':
|
||||||
$contact = Contact::getByURL($feature->did, null, ['id']);
|
$url = $feature->did;
|
||||||
if (!empty($contact['id'])) {
|
if (substr($linktext, 0, 1) == '@') {
|
||||||
$url = $this->baseURL . '/contact/' . $contact['id'];
|
$prefix .= '@';
|
||||||
if (substr($linktext, 0, 1) == '@') {
|
$linktext = substr($linktext, 1);
|
||||||
$prefix .= '@';
|
|
||||||
$linktext = substr($linktext, 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -13,11 +13,11 @@ use Friendica\Model\Notification;
|
||||||
return [
|
return [
|
||||||
'gserver' => [
|
'gserver' => [
|
||||||
[
|
[
|
||||||
'url' => 'https://friendica.local',
|
'url' => 'https://friendica.local',
|
||||||
'nurl' => 'http://friendica.local',
|
'nurl' => 'http://friendica.local',
|
||||||
'register_policy' => 0,
|
'register_policy' => 0,
|
||||||
'registered-users' => 0,
|
'registered-users' => 0,
|
||||||
'network' => 'unkn',
|
'network' => 'unkn',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
// Base test config to avoid notice messages
|
// Base test config to avoid notice messages
|
||||||
|
@ -88,6 +88,11 @@ return [
|
||||||
'uri' => 'https://friendica.local/profile/mutualcontact',
|
'uri' => 'https://friendica.local/profile/mutualcontact',
|
||||||
'guid' => '46',
|
'guid' => '46',
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'id' => 49,
|
||||||
|
'uri' => 'https://domain.tld/profile/remotecontact',
|
||||||
|
'guid' => '49',
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'id' => 100,
|
'id' => 100,
|
||||||
'uri' => 'https://friendica.local/posts/100',
|
'uri' => 'https://friendica.local/posts/100',
|
||||||
|
@ -214,6 +219,23 @@ return [
|
||||||
'network' => Protocol::DFRN,
|
'network' => Protocol::DFRN,
|
||||||
'location' => 'DFRN',
|
'location' => 'DFRN',
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'id' => 49,
|
||||||
|
'uid' => 0,
|
||||||
|
'uri-id' => 43,
|
||||||
|
'name' => 'Remote user',
|
||||||
|
'nick' => 'remotecontact',
|
||||||
|
'self' => 0,
|
||||||
|
'nurl' => 'http://domain.tld/profile/remotecontact',
|
||||||
|
'url' => 'https://domain.tld/profile/remotecontact',
|
||||||
|
'alias' => 'https://domain.tld/~remotecontact',
|
||||||
|
'about' => 'User used in tests',
|
||||||
|
'pending' => 0,
|
||||||
|
'blocked' => 0,
|
||||||
|
'rel' => Contact::FOLLOWER,
|
||||||
|
'network' => Protocol::ACTIVITYPUB,
|
||||||
|
'location' => 'AP',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'apcontact' => [
|
'apcontact' => [
|
||||||
[
|
[
|
||||||
|
@ -343,7 +365,7 @@ return [
|
||||||
'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
|
'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
|
||||||
'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
|
'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
|
||||||
'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
|
'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
|
||||||
'plink' => 'https://friendica.local/display/6',
|
'plink' => 'https://friendica.local/display/6',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'uri-id' => 100,
|
'uri-id' => 100,
|
||||||
|
@ -912,8 +934,8 @@ return [
|
||||||
],
|
],
|
||||||
'profile' => [
|
'profile' => [
|
||||||
[
|
[
|
||||||
'id' => 1,
|
'id' => 1,
|
||||||
'uid' => 42,
|
'uid' => 42,
|
||||||
'locality' => 'DFRN',
|
'locality' => 'DFRN',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
@ -933,18 +955,18 @@ return [
|
||||||
],
|
],
|
||||||
'group_member' => [
|
'group_member' => [
|
||||||
[
|
[
|
||||||
'id' => 1,
|
'id' => 1,
|
||||||
'gid' => 1,
|
'gid' => 1,
|
||||||
'contact-id' => 43,
|
'contact-id' => 43,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'id' => 2,
|
'id' => 2,
|
||||||
'gid' => 1,
|
'gid' => 1,
|
||||||
'contact-id' => 43,
|
'contact-id' => 43,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'id' => 3,
|
'id' => 3,
|
||||||
'gid' => 2,
|
'gid' => 2,
|
||||||
'contact-id' => 43,
|
'contact-id' => 43,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
|
@ -615,4 +615,27 @@ Lucas: For the right price, yes.[/share]',
|
||||||
|
|
||||||
self::assertEquals($expected, $actual);
|
self::assertEquals($expected, $actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function dataProfileLink(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'mention' => [
|
||||||
|
'expected' => 'Test 1: <bdi>@<a href="https://domain.tld/~remotecontact" class="userinfo mention" title="Remote contact">Remote contact</a></bdi>',
|
||||||
|
'text' => 'Test 1: @[url=https://domain.tld/profile/remotecontact]Remote contact[/url]',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider dataProfileLink
|
||||||
|
*
|
||||||
|
* @param string $expected Expected BBCode output
|
||||||
|
* @param string $text Input text
|
||||||
|
*/
|
||||||
|
public function testProfileLink(string $expected, string $text)
|
||||||
|
{
|
||||||
|
$actual = BBCode::convertForUriId(0, $text);
|
||||||
|
|
||||||
|
self::assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue