From cd74fb8609003f88e04f2d0560abe573cfb09231 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 18 Jun 2020 08:53:30 -0400 Subject: [PATCH 1/3] Add new Content\BBCode::getShareOpeningTag --- src/Content/Text/BBCode.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 09d0310686..1cd8e438cd 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -2223,4 +2223,33 @@ class BBCode return $body; } + + /** + * @param $author + * @param $profile + * @param $avatar + * @param $guid + * @param $posted + * @param $link + * @return string + * @TODO Rewrite to handle over whole record array + */ + public static function getShareOpeningTag($author, $profile, $avatar, $guid, $posted, $link) + { + $header = "[share author='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $author). + "' profile='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $profile). + "' avatar='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $avatar); + + if ($guid) { + $header .= "' guid='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $guid); + } + + if ($posted) { + $header .= "' posted='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $posted); + } + + $header .= "' link='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $link)."']"; + + return $header; + } } From 1f20111c80481711c3e7fd41090b15b88075db4a Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 18 Jun 2020 08:53:57 -0400 Subject: [PATCH 2/3] Replace share_header calls with BBCode::getShareOpeningTag --- include/api.php | 2 +- mod/share.php | 3 ++- src/Protocol/ActivityPub/Transmitter.php | 2 +- src/Protocol/Diaspora.php | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/api.php b/include/api.php index 808e34065b..d314988ed8 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 = share_header($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['guid'], $item['created'], $item['plink']); if (!empty($item['title'])) { $post .= '[h3]' . $item['title'] . "[/h3]\n"; diff --git a/mod/share.php b/mod/share.php index 3e9b6aee6f..90f2b52488 100644 --- a/mod/share.php +++ b/mod/share.php @@ -20,6 +20,7 @@ */ use Friendica\App; +use Friendica\Content\Text\BBCode; use Friendica\Database\DBA; use Friendica\Model\Item; @@ -42,7 +43,7 @@ function share_init(App $a) { $pos = strpos($item['body'], "[share"); $o = substr($item['body'], $pos); } else { - $o = share_header($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['guid'], $item['created'], $item['plink']); if ($item['title']) { $o .= '[h3]'.$item['title'].'[/h3]'."\n"; diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 9cb5efca41..dfe7c77df7 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -863,7 +863,7 @@ class Transmitter $type = 'Announce'; // Disguise forum posts as reshares. Will later be converted to a real announce - $item['body'] = share_header($item['author-name'], $item['author-link'], $item['author-avatar'], + $item['body'] = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'], $item['guid'], $item['created'], $item['plink']) . $item['body'] . '[/share]'; } } diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index c4e7d9fb87..3833aae23c 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -2795,7 +2795,7 @@ class Diaspora /// @todo Copy tag data from original post - $prefix = share_header( + $prefix = BBCode::getShareOpeningTag( $original_item["author-name"], $original_item["author-link"], $original_item["author-avatar"], @@ -3676,7 +3676,7 @@ class Diaspora if ($item['author-link'] != $item['owner-link']) { require_once 'mod/share.php'; - $body = share_header($item['author-name'], $item['author-link'], $item['author-avatar'], + $body = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'], "", $item['created'], $item['plink']) . $body . '[/share]'; } From b9117ceddce749422d00a8a47611d6fd8fdbd13a Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 18 Jun 2020 11:23:57 -0400 Subject: [PATCH 3/3] Remove share_header() function from mod/share --- mod/share.php | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/mod/share.php b/mod/share.php index 90f2b52488..fe4b7bfe7f 100644 --- a/mod/share.php +++ b/mod/share.php @@ -56,22 +56,3 @@ function share_init(App $a) { echo $o; exit(); } - -/// @TODO Rewrite to handle over whole record array -function share_header($author, $profile, $avatar, $guid, $posted, $link) { - $header = "[share author='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $author). - "' profile='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $profile). - "' avatar='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $avatar); - - if ($guid) { - $header .= "' guid='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $guid); - } - - if ($posted) { - $header .= "' posted='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $posted); - } - - $header .= "' link='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $link)."']"; - - return $header; -}