inline image extractor (to add attachments for all inline images) was also extracting images from code blocks.

This commit is contained in:
Mike Macgirvin 2023-07-22 12:24:18 +10:00
parent dec3021ab8
commit 4c935b94cd

View file

@ -1152,10 +1152,20 @@ class Activity
}
}
$images = false;
// protect code blocks before searching for images
$item['body'] = preg_replace_callback('#(^|\n)([`~]{3,})(?: *\.?([a-zA-Z0-9\-.]+))?\n+([\s\S]+?)\n+\2(\n|$)#', function ($match) {
return $match[1] . $match[2] . "\n" . bb_code_protect($match[4]) . "\n" . $match[2] . (($match[5]) ?: "\n");
}, $item['body']);
$item['body'] = preg_replace_callback('/\[code(.*?)\[\/(code)\]/ism', '\red_escape_codeblock', $item['body']);
// find all inline images (outside protected code blocks) to add back as attachments
$has_images = preg_match_all('/\[[zi]mg(.*?)](.*?)\[/ism', $item['body'], $images, PREG_SET_ORDER);
$item['body'] = preg_replace_callback('/\[\$b64code(.*?)\[\/(code)\]/ism', '\red_unescape_codeblock', $item['body']);
$item['body'] = bb_code_unprotect($item['body']);
$activity['id'] = $item['mid'];
$activity['published'] = datetime_convert('UTC', 'UTC', $item['created'], ATOM_TIME);