From 912ff069c06ae7697431bd104cd4c50677f0e033 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 21 Jun 2020 09:42:37 -0400 Subject: [PATCH 1/4] Update getShareOpeningTag::getShareOpeningTag method signature - Optional parameter $guid is now at the end - Always provided parameter $posted is now mandatory --- include/api.php | 2 +- mod/share.php | 2 +- src/Content/Text/BBCode.php | 28 +++++++++++------------- src/Protocol/ActivityPub/Transmitter.php | 2 +- src/Protocol/Diaspora.php | 6 ++--- 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/include/api.php b/include/api.php index d314988ed..d55183fbf 100644 --- a/include/api.php +++ b/include/api.php @@ -2043,7 +2043,7 @@ function api_statuses_repeat($type) $pos = strpos($item['body'], "[share"); $post = substr($item['body'], $pos); } else { - $post = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'], $item['guid'], $item['created'], $item['plink']); + $post = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'], $item['plink'], $item['created'], $item['guid']); if (!empty($item['title'])) { $post .= '[h3]' . $item['title'] . "[/h3]\n"; diff --git a/mod/share.php b/mod/share.php index fe4b7bfe7..a8ac3bd8b 100644 --- a/mod/share.php +++ b/mod/share.php @@ -43,7 +43,7 @@ function share_init(App $a) { $pos = strpos($item['body'], "[share"); $o = substr($item['body'], $pos); } else { - $o = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'], $item['guid'], $item['created'], $item['plink']); + $o = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'], $item['plink'], $item['created'], $item['guid']); if ($item['title']) { $o .= '[h3]'.$item['title'].'[/h3]'."\n"; diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 1cd8e438c..266182b3b 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -2225,30 +2225,28 @@ class BBCode } /** - * @param $author - * @param $profile - * @param $avatar - * @param $guid - * @param $posted - * @param $link + * @param string $author Author display name + * @param string $profile Author profile URL + * @param string $avatar Author profile picture URL + * @param string $link Post source URL + * @param string $posted Post created date + * @param string|null $guid Post guid (if any) * @return string * @TODO Rewrite to handle over whole record array */ - public static function getShareOpeningTag($author, $profile, $avatar, $guid, $posted, $link) + public static function getShareOpeningTag(string $author, string $profile, string $avatar, string $link, string $posted, string $guid = null) { - $header = "[share author='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $author). - "' profile='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $profile). - "' avatar='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $avatar); + $header = "[share author='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $author) . + "' profile='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $profile) . + "' avatar='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $avatar) . + "' link='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $link) . + "' posted='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $posted); if ($guid) { $header .= "' guid='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $guid); } - if ($posted) { - $header .= "' posted='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $posted); - } - - $header .= "' link='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $link)."']"; + $header .= "']"; return $header; } diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index dfe7c77df..e7a16f052 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -864,7 +864,7 @@ class Transmitter // Disguise forum posts as reshares. Will later be converted to a real announce $item['body'] = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'], - $item['guid'], $item['created'], $item['plink']) . $item['body'] . '[/share]'; + $item['plink'], $item['created'], $item['guid']) . $item['body'] . '[/share]'; } } diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 3833aae23..7f4690879 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -2799,9 +2799,9 @@ class Diaspora $original_item["author-name"], $original_item["author-link"], $original_item["author-avatar"], - $original_item["guid"], + $orig_url, $original_item["created"], - $orig_url + $original_item["guid"] ); if (!empty($original_item['title'])) { @@ -3677,7 +3677,7 @@ class Diaspora if ($item['author-link'] != $item['owner-link']) { require_once 'mod/share.php'; $body = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'], - "", $item['created'], $item['plink']) . $body . '[/share]'; + $item['plink'], $item['created']) . $body . '[/share]'; } // convert to markdown From d2aa68106b89a193c00133291a0c9b4cfc63f388 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 21 Jun 2020 09:45:00 -0400 Subject: [PATCH 2/4] Make guid attribute available to convertShare callback --- src/Content/Text/BBCode.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 266182b3b..7354e0645 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -978,7 +978,7 @@ class BBCode function ($match) use ($callback) { $attribute_string = $match[2]; $attributes = []; - foreach (['author', 'profile', 'avatar', 'link', 'posted'] as $field) { + foreach (['author', 'profile', 'avatar', 'link', 'posted', 'guid'] as $field) { preg_match("/$field=(['\"])(.+?)\\1/ism", $attribute_string, $matches); $attributes[$field] = html_entity_decode($matches[2] ?? '', ENT_QUOTES, 'UTF-8'); } @@ -1088,6 +1088,7 @@ class BBCode '$link' => $attributes['link'], '$link_title' => DI::l10n()->t('link to source'), '$posted' => $attributes['posted'], + '$guid' => $attributes['guid'], '$network_name' => ContactSelector::networkToName($contact['network'], $attributes['profile']), '$network_icon' => ContactSelector::networkToIcon($contact['network'], $attributes['profile']), '$content' => self::setMentions(trim($content), 0, $contact['network']), From b77896ed455c0eef443b646c49f635be5682140c Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 21 Jun 2020 09:45:36 -0400 Subject: [PATCH 3/4] [frio] Add local post link to share block when guid attribute is present --- view/theme/frio/templates/shared_content.tpl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/view/theme/frio/templates/shared_content.tpl b/view/theme/frio/templates/shared_content.tpl index a4f47e618..f7b210bb8 100644 --- a/view/theme/frio/templates/shared_content.tpl +++ b/view/theme/frio/templates/shared_content.tpl @@ -18,7 +18,15 @@ {{/if}} -
{{$posted}}
+
+ {{if $guid}} + + {{/if}} + {{$posted}} + {{if $guid}} + + {{/if}} +
{{$content nofilter}}
From 2b83ec6784efe7345107ffd047bb11164896c17b Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 22 Jun 2020 17:49:20 -0400 Subject: [PATCH 4/4] Add more expected data to test fixtures --- tests/datasets/api.fixture.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/datasets/api.fixture.php b/tests/datasets/api.fixture.php index 8bdb86892..0ff9a4a21 100644 --- a/tests/datasets/api.fixture.php +++ b/tests/datasets/api.fixture.php @@ -192,6 +192,8 @@ return [ 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '', + 'guid' => '1', + 'plink' => 'http://localhost/display/1', ], [ 'id' => 2, @@ -209,6 +211,8 @@ return [ 'wall' => 1, 'starred' => 0, 'origin' => 1, + 'guid' => '2', + 'plink' => 'http://localhost/display/2', ], [ @@ -227,6 +231,8 @@ return [ 'wall' => 1, 'starred' => 0, 'origin' => 1, + 'guid' => '3', + 'plink' => 'http://localhost/display/3', ], [ 'id' => 4, @@ -244,6 +250,8 @@ return [ 'wall' => 1, 'starred' => 0, 'origin' => 1, + 'guid' => '4', + 'plink' => 'http://localhost/display/4', ], [ @@ -266,6 +274,8 @@ return [ 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '', + 'guid' => '5', + 'plink' => 'http://localhost/display/5', ], [ 'id' => 6, @@ -283,6 +293,8 @@ return [ 'wall' => 1, 'starred' => 0, 'origin' => 1, + 'guid' => '6', + 'plink' => 'http://localhost/display/6', ], ], 'notify' => [