From 4a37c978c23c53329ab33c79347333f9e468cb5d Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 8 Oct 2022 09:36:35 +0000 Subject: [PATCH] Issue 11969: Simplified share --- mod/share.php | 29 +++++++++-------------------- src/Content/Text/BBCode.php | 17 +++++++++-------- src/Model/Item.php | 10 +++++++++- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/mod/share.php b/mod/share.php index 8f55781e52..b4c2bc50dd 100644 --- a/mod/share.php +++ b/mod/share.php @@ -21,13 +21,11 @@ use Friendica\App; use Friendica\Content\Text\BBCode; -use Friendica\Core\Protocol; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Item; use Friendica\Model\Post; -use Friendica\Util\Network; function share_init(App $a) { $post_id = ((DI::args()->getArgc() > 1) ? intval(DI::args()->getArgv()[1]) : 0); @@ -36,30 +34,21 @@ function share_init(App $a) { System::exit(); } - $fields = ['private', 'body', 'author-name', 'author-link', 'author-avatar', - 'guid', 'created', 'plink', 'uri', 'title', 'network']; + $fields = ['private', 'body', 'uri']; $item = Post::selectFirst($fields, ['id' => $post_id]); if (!DBA::isResult($item) || $item['private'] == Item::PRIVATE) { System::exit(); } - if (strpos($item['body'], "[/share]") !== false) { - $pos = strpos($item['body'], "[share"); - $o = substr($item['body'], $pos); - } elseif (Network::isValidHttpUrl($item['uri']) && in_array($item['network'], Protocol::FEDERATED)) { - $o = "[share]" . $item['uri'] . "[/share]"; + $shared = BBCode::fetchShareAttributes($item['body']); + if (!empty($shared['message_id']) || !empty($shared['link'])) { + $content = '[share]' . ($shared['message_id'] ?: $shared['link']) . '[/share]'; + } elseif (strpos($item['body'], '[/share]') !== false) { + $pos = strpos($item['body'], '[share'); + $content = substr($item['body'], $pos); } else { - $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"; - } - - $o .= $item['body']; - $o .= "[/share]"; + $content = '[share]' . $item['uri'] . '[/share]'; } - - echo $o; - System::exit(); + System::httpExit($content); } diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 2a3bced6af..43d4127ea9 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1009,14 +1009,15 @@ class BBCode /** * @param string $text A BBCode string * @return array Empty array if no share tag is present or the following array, missing attributes end up empty strings: - * - comment: Text before the opening share tag - * - shared : Text inside the share tags - * - author : (Optional) Display name of the shared author - * - profile: (Optional) Profile page URL of the shared author - * - avatar : (Optional) Profile picture URL of the shared author - * - link : (Optional) Canonical URL of the shared post - * - posted : (Optional) Date the shared post was initially posted ("Y-m-d H:i:s" in GMT) - * - guid : (Optional) Shared post GUID if any + * - comment : Text before the opening share tag + * - shared : Text inside the share tags + * - author : (Optional) Display name of the shared author + * - profile : (Optional) Profile page URL of the shared author + * - avatar : (Optional) Profile picture URL of the shared author + * - link : (Optional) Canonical URL of the shared post + * - posted : (Optional) Date the shared post was initially posted ("Y-m-d H:i:s" in GMT) + * - message_id: (Optional) Shared post URI if any + * - guid : (Optional) Shared post GUID if any */ public static function fetchShareAttributes(string $text): array { diff --git a/src/Model/Item.php b/src/Model/Item.php index f6c990bb44..aa683f3522 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -3671,7 +3671,15 @@ class Item return $item['body']; } - $id = self::fetchByLink($shared['link'] ?: $shared['message_id']); + $link = $shared['link'] ?: $shared['message_id']; + + if (!empty($item['uid'])) { + $id = self::searchByLink($link, $item['uid']); + } + + if (empty($id)) { + $id = self::fetchByLink($link); + } Logger::debug('Fetched shared post', ['uri-id' => $item['uri-id'], 'id' => $id, 'author' => $shared['profile'], 'url' => $shared['link'], 'guid' => $shared['guid'], 'uri' => $shared['message_id'], 'callstack' => System::callstack()]); if (!$id) { return $item['body']; -- 2.39.5