]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/ActivityPub/Transmitter.php
Merge pull request #10463 from annando/proxy-security
[friendica.git] / src / Protocol / ActivityPub / Transmitter.php
index 27658c84fa6f4c7f8dae39692ab6b070f226ead3..9ff3957c1e8eaedc93ca3c5f812d4b205ec4915b 100644 (file)
@@ -143,7 +143,7 @@ class Transmitter
 
                return $success;
        }
-       
+
        /**
         * Collects a list of contacts of the given owner
         *
@@ -325,7 +325,7 @@ class Transmitter
                                return [];
                        }
 
-                       $fields = ['locality', 'region', 'country-name'];
+                       $fields = ['locality', 'region', 'country-name', 'net-publish'];
                        $profile = DBA::selectFirst('profile', $fields, ['uid' => $uid]);
                        if (!DBA::isResult($profile)) {
                                return [];
@@ -340,7 +340,7 @@ class Transmitter
                        $contact = User::getSystemAccount();
                        $user = ['guid' => '', 'nickname' => $contact['nick'], 'pubkey' => $contact['pubkey'],
                                'account-type' => $contact['contact-type'], 'page-flags' => User::PAGE_FLAGS_NORMAL];
-                       $profile = ['locality' => '', 'region' => '', 'country-name' => ''];
+                       $profile = ['locality' => '', 'region' => '', 'country-name' => '', 'net-publish' => false];
                }
 
                $data = ['@context' => ActivityPub::CONTEXT];
@@ -351,7 +351,7 @@ class Transmitter
                }
 
                $data['type'] = ActivityPub::ACCOUNT_TYPES[$user['account-type']];
-               
+
                if ($uid != 0) {
                        $data['following'] = DI::baseUrl() . '/following/' . $user['nickname'];
                        $data['followers'] = DI::baseUrl() . '/followers/' . $user['nickname'];
@@ -375,6 +375,7 @@ class Transmitter
 
                $data['url'] = $contact['url'];
                $data['manuallyApprovesFollowers'] = in_array($user['page-flags'], [User::PAGE_FLAGS_NORMAL, User::PAGE_FLAGS_PRVGROUP]);
+               $data['discoverable'] = $profile['net-publish'];
                $data['publicKey'] = ['id' => $contact['url'] . '#main-key',
                        'owner' => $contact['url'],
                        'publicKeyPem' => $user['pubkey']];
@@ -719,10 +720,10 @@ class Transmitter
        /**
         * Check if a given contact should be delivered via AP
         *
-        * @param array $contact 
-        * @param array $networks 
-        * @return bool 
-        * @throws Exception 
+        * @param array $contact
+        * @param array $networks
+        * @return bool
+        * @throws Exception
         */
        private static function isAPContact(array $contact, array $networks)
        {
@@ -1078,7 +1079,7 @@ class Transmitter
                                if (!empty($self['uid'])) {
                                        $forum_item = Post::selectFirst(Item::DELIVER_FIELDLIST, ['uri-id' => $item['uri-id'], 'uid' => $self['uid']]);
                                        if (DBA::isResult($forum_item)) {
-                                               $item = $forum_item; 
+                                               $item = $forum_item;
                                        }
                                }
                        }
@@ -1297,10 +1298,24 @@ class Transmitter
                                }
                                $urls[] = $attachment['url'];
 
-                               $attachments[] = ['type' => 'Document',
+                               $attach = ['type' => 'Document',
                                        'mediaType' => $attachment['mimetype'],
                                        'url' => $attachment['url'],
                                        'name' => $attachment['description']];
+                               
+                               if (!empty($attachment['height'])) {
+                                       $attach['height'] = $attachment['height'];
+                               }
+
+                               if (!empty($attachment['width'])) {
+                                       $attach['width'] = $attachment['width'];
+                               }
+       
+                               if (!empty($attachment['preview'])) {
+                                       $attach['image'] = $attachment['preview'];
+                               }
+
+                               $attachments[] = $attach;
                        }
                }
 
@@ -1315,10 +1330,24 @@ class Transmitter
                                }
                                $urls[] = $attachment['url'];
 
-                               $attachments[] = ['type' => 'Document',
+                               $attach = ['type' => 'Document',
                                        'mediaType' => $attachment['mimetype'],
                                        'url' => $attachment['url'],
                                        'name' => $attachment['description']];
+                               
+                               if (!empty($attachment['height'])) {
+                                       $attach['height'] = $attachment['height'];
+                               }
+
+                               if (!empty($attachment['width'])) {
+                                       $attach['width'] = $attachment['width'];
+                               }
+
+                               if (!empty($attachment['preview'])) {
+                                       $attach['image'] = $attachment['preview'];
+                               }
+
+                               $attachments[] = $attach;       
                        }
                        // Currently deactivated, since it creates side effects on Mastodon and Pleroma.
                        // It will be activated, once this cleared.
@@ -1549,7 +1578,7 @@ class Transmitter
                 * This part is currently deactivated. The automated summary seems to be more
                 * confusing than helping. But possibly we will find a better way.
                 * So the code is left here for now as a reminder
-                * 
+                *
                 * } elseif (($type == 'Article') && empty($data['summary'])) {
                 *              $regexp = "/[@!]\[url\=([^\[\]]*)\].*?\[\/url\]/ism";
                 *              $summary = preg_replace_callback($regexp, ['self', 'mentionAddrCallback'], $body);