From bcc8ed378c1920bc66d0f301f1060e7ebf894999 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 29 Jul 2019 05:09:11 +0000 Subject: [PATCH] ActivityPub: We now do support transmitting alternative image descriptions --- src/Protocol/ActivityPub/Transmitter.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 9f5d17c90e..b64e746e79 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -1034,7 +1034,7 @@ class Transmitter // Simplify image codes $body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $item['body']); - // Grab all pictures and create attachments out of them + // Grab all pictures without alternative descriptions and create attachments out of them if (preg_match_all("/\[img\]([^\[\]]*)\[\/img\]/Usi", $body, $pictures)) { foreach ($pictures[1] as $picture) { $imgdata = Image::getInfoFromURL($picture); @@ -1047,6 +1047,19 @@ class Transmitter } } + // Grab all pictures with alternative description and create attachments out of them + if (preg_match_all("/\[img=([^\[\]]*)\]([^\[\]]*)\[\/img\]/Usi", $body, $pictures, PREG_SET_ORDER)) { + foreach ($pictures as $picture) { + $imgdata = Image::getInfoFromURL($picture[1]); + if ($imgdata) { + $attachments[] = ['type' => 'Document', + 'mediaType' => $imgdata['mime'], + 'url' => $picture[1], + 'name' => $picture[2]]; + } + } + } + return $attachments; }