Merge pull request #13266 from annando/quoted

Improve display of quoted posts
This commit is contained in:
Hypolite Petovan
2023-07-09 15:59:13 -04:00
committed by GitHub
4 changed files with 181 additions and 168 deletions
+5 -4
View File
@@ -669,14 +669,15 @@ class Item
* Add a share block for the given item array
*
* @param array $item
* @param bool $add_media
* @param bool $add_media true = Media is added to the body
* @param bool $for_display true = The share block is used for display purposes, false = used for connectors, transport to other systems, ...
* @return string
*/
public function createSharedBlockByArray(array $item, bool $add_media = false): string
public function createSharedBlockByArray(array $item, bool $add_media = false, bool $for_display = false): string
{
if ($item['network'] == Protocol::FEED) {
return PageInfo::getFooterFromUrl($item['plink']);
} elseif (!in_array($item['network'] ?? '', Protocol::FEDERATED)) {
} elseif (!in_array($item['network'] ?? '', Protocol::FEDERATED) && !$for_display) {
$item['guid'] = '';
$item['uri'] = '';
}
@@ -695,7 +696,7 @@ class Item
// If it is a reshared post then reformat it to avoid display problems with two share elements
if (!empty($shared)) {
if (!empty($shared['guid']) && ($encapsulated_share = $this->createSharedPostByGuid($shared['guid'], true))) {
if (($item['network'] != Protocol::BLUESKY) && !empty($shared['guid']) && ($encapsulated_share = $this->createSharedPostByGuid($shared['guid'], true))) {
if (!empty(BBCode::fetchShareAttributes($item['body']))) {
$item['body'] = preg_replace("/\[share.*?\](.*)\[\/share\]/ism", $encapsulated_share, $item['body']);
} else {
+3 -2
View File
@@ -64,7 +64,8 @@ class BBCode
const ACTIVITYPUB = 9;
const BLUESKY = 10;
const TOP_ANCHOR = '<br class="top-anchor">';
const SHARED_ANCHOR = '<hr class="shared-anchor">';
const TOP_ANCHOR = '<br class="top-anchor">';
const BOTTOM_ANCHOR = '<br class="button-anchor">';
const PREVIEW_NONE = 0;
@@ -930,7 +931,7 @@ class BBCode
$network = $contact['network'] ?? Protocol::PHANTOM;
$tpl = Renderer::getMarkupTemplate('shared_content.tpl');
$text .= Renderer::replaceMacros($tpl, [
$text .= BBCode::SHARED_ANCHOR . Renderer::replaceMacros($tpl, [
'$profile' => $attributes['profile'],
'$avatar' => $attributes['avatar'],
'$author' => $attributes['author'],
+11 -1
View File
@@ -3138,7 +3138,7 @@ class Item
if (!empty($quote_uri_id)) {
if (isset($shared_item['plink'])) {
$item['body'] .= "\n" . DI::contentItem()->createSharedBlockByArray($shared_item);
$item['body'] .= "\n" . DI::contentItem()->createSharedBlockByArray($shared_item, false, true);
} else {
DI::logger()->warning('Missing plink in shared item', ['item' => $item, 'shared' => $shared, 'quote_uri_id' => $quote_uri_id, 'shared_item' => $shared_item]);
}
@@ -3217,6 +3217,12 @@ class Item
$body = BBCode::removeSharedData($body);
}
$pos = strpos($s, BBCode::SHARED_ANCHOR);
if ($pos) {
$shared_html = substr($s, $pos + strlen(BBCode::SHARED_ANCHOR));
$s = substr($s, 0, $pos);
}
$s = self::addGallery($s, $attachments, $item['uri-id']);
$s = self::addVisualAttachments($attachments, $item, $s, false);
$s = self::addLinkAttachment($item['uri-id'], $attachments, $body, $s, false, $shared_links);
@@ -3237,6 +3243,10 @@ class Item
$s = preg_replace('|(<img[^>]+src="[^"]+/photo/[0-9a-f]+)-[0-9]|', "$1-" . $ps, $s);
}
if (!empty($shared_html)) {
$s .= $shared_html;
}
$s = HTML::applyContentFilter($s, $filter_reasons);
$hook_data = ['item' => $item, 'html' => $s];