if ($orig_post) {
$datarray['edit'] = true;
} else {
+ // If this was a share, add missing data here
+ $datarray = Item::addShareDataFromOriginal($datarray);
+
$datarray['edit'] = false;
}
}
}
- // If this was a share, add missing data here
- $datarray = Item::addShareDataFromOriginal($datarray);
-
$post_id = Item::insert($datarray);
if (!$post_id) {
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');
}
$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);