From 23cdc9cec85c6ed6db11ba93add4b8936b3a0306 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 7 Dec 2019 21:05:14 +0000 Subject: [PATCH] Fixes issue 7914: Reshares got crumbled --- mod/item.php | 6 +++--- src/Content/Text/BBCode.php | 5 ++--- src/Model/Item.php | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/mod/item.php b/mod/item.php index 999e7a25c6..93da70e40e 100644 --- a/mod/item.php +++ b/mod/item.php @@ -652,6 +652,9 @@ function item_post(App $a) { if ($orig_post) { $datarray['edit'] = true; } else { + // If this was a share, add missing data here + $datarray = Item::addShareDataFromOriginal($datarray); + $datarray['edit'] = false; } @@ -730,9 +733,6 @@ function item_post(App $a) { } } - // If this was a share, add missing data here - $datarray = Item::addShareDataFromOriginal($datarray); - $post_id = Item::insert($datarray); if (!$post_id) { diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 0291c729e8..29b4f47eb7 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -953,12 +953,11 @@ class BBCode extends BaseObject public static function convertShare($text, callable $callback) { $return = preg_replace_callback( - "/(.*?)\[share(.*?)\](.*?)\[\/share\]/ism", + "/(.*?)\[share(.*?)\](.*)\[\/share\]/ism", function ($match) use ($callback) { $attribute_string = $match[2]; - $attributes = []; - foreach(['author', 'profile', 'avatar', 'link', 'posted'] as $field) { + foreach (['author', 'profile', 'avatar', 'link', 'posted'] as $field) { preg_match("/$field=(['\"])(.+?)\\1/ism", $attribute_string, $matches); $attributes[$field] = html_entity_decode($matches[2] ?? '', ENT_QUOTES, 'UTF-8'); } diff --git a/src/Model/Item.php b/src/Model/Item.php index 0f008518b0..1e3b16002a 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -3833,7 +3833,7 @@ class Item extends BaseObject $body = $shared_item['body']; } - $item['body'] = preg_replace("/(.*?\[share.*?\]\s?).*?(\s?\[\/share\]\s?)/ism", '$1' . $body . '$2', $item['body']); + $item['body'] = preg_replace("/\[share ([^\[\]]*)\].*\[\/share\]/ism", '[share $1]' . $body . '[/share]', $item['body']); unset($shared_item['body']); return array_merge($item, $shared_item);