]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/ActivityPub/Transmitter.php
Merge pull request #7570 from nupplaphil/bug/friendica-7298
[friendica.git] / src / Protocol / ActivityPub / Transmitter.php
index 1d5192d93be6bb2286738b6ae6ead3a3d202d01c..e44ae1cf66c2dfa4ff9413cc2b457d10fbb39279 100644 (file)
@@ -386,7 +386,7 @@ class Transmitter
                                }
                        }
                } else {
-                       $receiver_list = Item::enumeratePermissions($item);
+                       $receiver_list = Item::enumeratePermissions($item, true);
 
                        foreach ($terms as $term) {
                                $cid = Contact::getIdForURL($term['url'], $item['uid']);
@@ -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;
        }
 
@@ -1287,6 +1300,7 @@ class Transmitter
         */
        private static function createAnnounce($item, $data)
        {
+               $orig_body = $item['body'];
                $announce = api_share_as_retweet($item);
                if (empty($announce['plink'])) {
                        $data['type'] = 'Create';
@@ -1299,12 +1313,29 @@ class Transmitter
                if (!empty($activity)) {
                        $ldactivity = JsonLD::compact($activity);
                        $id = JsonLD::fetchElement($ldactivity, '@id');
+                       $type = str_replace('as:', '', JsonLD::fetchElement($ldactivity, '@type'));
                        if (!empty($id)) {
-                               $data['object'] = $id;
+                               if (empty($announce['share-pre-body'])) {
+                                       // Pure announce, without a quote
+                                       $data['type'] = 'Announce';
+                                       $data['object'] = $id;
+                                       return $data;
+                               }
+
+                               // Quote
+                               $data['type'] = 'Create';
+                               $item['body'] = trim($announce['share-pre-body']) . "\n" . $id;
+                               $data['object'] = self::createNote($item);
+
+                               /// @todo Finally descide how to implement this in AP. This is a possible way:
+                               $data['object']['attachment'][] = ['type' => $type, 'id' => $id];
+
+                               $data['object']['source']['content'] = $orig_body;
                                return $data;
                        }
                }
 
+               $item['body'] = $orig_body;
                $data['type'] = 'Create';
                $data['object'] = self::createNote($item);
                return $data;