diff --git a/Code/Lib/Activity.php b/Code/Lib/Activity.php index 743c51558..64fb291c9 100644 --- a/Code/Lib/Activity.php +++ b/Code/Lib/Activity.php @@ -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);