]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/ActivityPub/Transmitter.php
Merge pull request #7092 from MrPetovan/task/7047-theme-error-page
[friendica.git] / src / Protocol / ActivityPub / Transmitter.php
index 8f9687a804f35258031f0a03d2855fa1584d8632..a06fbdcf19b532a0cad73877deddc8e05fd4672f 100644 (file)
@@ -187,6 +187,18 @@ class Transmitter
                return $data;
        }
 
+       /**
+        * Return the service array containing information the used software and it's url
+        *
+        * @return array with service data
+        */
+       private static function getService()
+       {
+               return ['type' => 'Service',
+                       'name' =>  FRIENDICA_PLATFORM . " '" . FRIENDICA_CODENAME . "' " . FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
+                       'url' => BaseObject::getApp()->getBaseURL()];
+       }
+
        /**
         * Return the ActivityPub profile of the given user
         *
@@ -243,10 +255,29 @@ class Transmitter
                $data['icon'] = ['type' => 'Image',
                        'url' => $contact['avatar']];
 
+               $data['generator'] = self::getService();
+
                // tags: https://kitty.town/@inmysocks/100656097926961126.json
                return $data;
        }
 
+       /**
+        * @param string $username
+        * @return array
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        */
+       public static function getDeletedUser($username)
+       {
+               return [
+                       '@context' => ActivityPub::CONTEXT,
+                       'id' => System::baseUrl() . '/profile/' . $username,
+                       'type' => 'Tombstone',
+                       'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
+                       'updated' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
+                       'deleted' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
+               ];
+       }
+
        /**
         * Returns an array with permissions of a given item array
         *
@@ -465,6 +496,18 @@ class Transmitter
                return $receivers;
        }
 
+       /**
+        * Check if an inbox is archived
+        *
+        * @param string $url Inbox url
+        *
+        * @return boolean "true" if inbox is archived
+        */
+       private static function archivedInbox($url)
+       {
+               return DBA::exists('inbox-status', ['url' => $url, 'archive' => true]);
+       }
+
        /**
         * Fetches a list of inboxes of followers of a given user
         *
@@ -506,7 +549,9 @@ class Transmitter
                                } else {
                                        $target = $profile['sharedinbox'];
                                }
-                               $inboxes[$target] = $target;
+                               if (!self::archivedInbox($target)) {
+                                       $inboxes[$target] = $target;
+                               }
                        }
                }
                DBA::close($contacts);
@@ -563,7 +608,9 @@ class Transmitter
                                                } else {
                                                        $target = $profile['sharedinbox'];
                                                }
-                                               $inboxes[$target] = $target;
+                                               if (!self::archivedInbox($target)) {
+                                                       $inboxes[$target] = $target;
+                                               }
                                        }
                                }
                        }
@@ -676,7 +723,7 @@ class Transmitter
                        $condition = ['item-uri' => $item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB];
                        $conversation = DBA::selectFirst('conversation', ['source'], $condition);
                        if (DBA::isResult($conversation)) {
-                               $data = json_decode($conversation['source']);
+                               $data = json_decode($conversation['source'], true);
                                if (!empty($data)) {
                                        return $data;
                                }
@@ -708,7 +755,7 @@ class Transmitter
 
                $data['published'] = DateTimeFormat::utc($item['created'] . '+00:00', DateTimeFormat::ATOM);
 
-               $data['instrument'] = ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()];
+               $data['instrument'] = self::getService();
 
                $data = array_merge($data, self::createPermissionBlockForItem($item, false));
 
@@ -1021,7 +1068,7 @@ class Transmitter
                        return $data;
                }
 
-               $data['summary'] = BBCode::convert(BBCode::getAbstract($item['body'], Protocol::ACTIVITYPUB), false, 7);
+               $data['summary'] = BBCode::toPlaintext(BBCode::getAbstract($item['body'], Protocol::ACTIVITYPUB));
 
                if ($item['uri'] != $item['thr-parent']) {
                        $data['inReplyTo'] = $item['thr-parent'];
@@ -1056,7 +1103,7 @@ class Transmitter
                if ($type == 'Note') {
                        $body = self::removePictures($body);
                } elseif (($type == 'Article') && empty($data['summary'])) {
-                       $data['summary'] = BBCode::convert(Plaintext::shorten(self::removePictures($body), 1000), false, 7);
+                       $data['summary'] = BBCode::toPlaintext(Plaintext::shorten(self::removePictures($body), 1000));
                }
 
                if ($type == 'Event') {
@@ -1166,7 +1213,7 @@ class Transmitter
                        'actor' => $owner['url'],
                        'object' => $suggestion['url'],
                        'content' => $suggestion['note'],
-                       'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
+                       'instrument' => self::getService(),
                        'to' => [ActivityPub::PUBLIC_COLLECTION],
                        'cc' => []];
 
@@ -1195,7 +1242,7 @@ class Transmitter
                        'actor' => $owner['url'],
                        'object' => $owner['url'],
                        'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
-                       'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
+                       'instrument' => self::getService(),
                        'to' => [ActivityPub::PUBLIC_COLLECTION],
                        'cc' => []];
 
@@ -1234,7 +1281,7 @@ class Transmitter
                        'actor' => $owner['url'],
                        'object' => $owner['url'],
                        'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
-                       'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
+                       'instrument' => self::getService(),
                        'to' => [ActivityPub::PUBLIC_COLLECTION],
                        'cc' => []];
 
@@ -1265,7 +1312,7 @@ class Transmitter
                        'actor' => $owner['url'],
                        'object' => self::getProfile($uid),
                        'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
-                       'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
+                       'instrument' => self::getService(),
                        'to' => [$profile['followers']],
                        'cc' => []];
 
@@ -1301,7 +1348,7 @@ class Transmitter
                        'type' => $activity,
                        'actor' => $owner['url'],
                        'object' => $profile['url'],
-                       'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
+                       'instrument' => self::getService(),
                        'to' => [$profile['url']]];
 
                Logger::log('Sending activity ' . $activity . ' to ' . $target . ' for user ' . $uid, Logger::DEBUG);
@@ -1350,7 +1397,7 @@ class Transmitter
                        'type' => 'Follow',
                        'actor' => $owner['url'],
                        'object' => $object,
-                       'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
+                       'instrument' => self::getService(),
                        'to' => [$profile['url']]];
 
                Logger::log('Sending follow ' . $object . ' to ' . $target . ' for user ' . $uid, Logger::DEBUG);
@@ -1380,7 +1427,7 @@ class Transmitter
                        'object' => ['id' => $id, 'type' => 'Follow',
                                'actor' => $profile['url'],
                                'object' => $owner['url']],
-                       'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
+                       'instrument' => self::getService(),
                        'to' => [$profile['url']]];
 
                Logger::log('Sending accept to ' . $target . ' for user ' . $uid . ' with id ' . $id, Logger::DEBUG);
@@ -1410,7 +1457,7 @@ class Transmitter
                        'object' => ['id' => $id, 'type' => 'Follow',
                                'actor' => $profile['url'],
                                'object' => $owner['url']],
-                       'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
+                       'instrument' => self::getService(),
                        'to' => [$profile['url']]];
 
                Logger::log('Sending reject to ' . $target . ' for user ' . $uid . ' with id ' . $id, Logger::DEBUG);
@@ -1447,7 +1494,7 @@ class Transmitter
                        'object' => ['id' => $object_id, 'type' => 'Follow',
                                'actor' => $owner['url'],
                                'object' => $profile['url']],
-                       'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
+                       'instrument' => self::getService(),
                        'to' => [$profile['url']]];
 
                Logger::log('Sending undo to ' . $target . ' for user ' . $uid . ' with id ' . $id, Logger::DEBUG);