correctly parse and display nested shares

This commit is contained in:
Mario
2025-11-10 08:01:18 +00:00
parent 866d88de53
commit 0be74299ca
2 changed files with 15 additions and 22 deletions

View File

@@ -637,11 +637,11 @@ class Activity {
$ret['tag'] = $t;
}
// TODO: Do not replace the if the owner is a forum.
// Keep the share tag tag if the owner is a forum.
// Receivers will not be able to fetch the original in that case.
if (str_contains($i['body'], '[/share]') && !$i['owner']['xchan_pubforum']) {
preg_match_all('/\[share(.*?)\[\/share\]/ism', $i['body'], $all_shares, PREG_SET_ORDER);
// Match all occurences of share tag, disregard the nested ones
preg_match_all('/\[share(?>[^\[]|\[(?!\/share\]))*\[\/share\]/ism', $i['body'], $all_shares, PREG_SET_ORDER);
$quote_urls = [];
foreach ($all_shares as $share) {
@@ -674,7 +674,6 @@ class Activity {
$ret['tag'] = array_merge($ret['tag'], $obj_links);
}
}
}
if ($i['mimetype'] === 'text/bbcode') {

View File

@@ -118,26 +118,20 @@ class Share {
$photo_bb = $object['body'];
}
if (strpos($this->item['body'], "[/share]") !== false) {
$pos = strpos($this->item['body'], "[share");
$bb = substr($this->item['body'], $pos);
} else {
$bb = "[share author='".urlencode($this->item['author']['xchan_name']).
"' profile='" . $this->item['author']['xchan_url'] .
"' avatar='" . $this->item['author']['xchan_photo_s'] .
"' link='" . $this->item['plink'] .
"' auth='" . (($this->item['author']['xchan_network'] === 'zot6') ? 'true' : 'false') .
"' posted='" . $this->item['created'] .
"' message_id='" . $this->item['mid'] .
"']";
if($this->item['title'])
$bb .= '[h3][b]'.$this->item['title'].'[/b][/h3]'."\r\n";
$bb .= (($is_photo) ? $photo_bb . "\r\n" . $this->item['body'] : $this->item['body']);
$bb .= "[/share]";
}
$bb = "[share author='".urlencode($this->item['author']['xchan_name']).
"' profile='" . $this->item['author']['xchan_url'] .
"' avatar='" . $this->item['author']['xchan_photo_s'] .
"' link='" . $this->item['plink'] .
"' auth='" . (($this->item['author']['xchan_network'] === 'zot6') ? 'true' : 'false') .
"' posted='" . $this->item['created'] .
"' message_id='" . $this->item['mid'] .
"']";
if($this->item['title'])
$bb .= '[h3][b]'.$this->item['title'].'[/b][/h3]'."\r\n";
$bb .= (($is_photo) ? $photo_bb . "\r\n" . $this->item['body'] : $this->item['body']);
$bb .= "[/share]";
return $bb;
}
}