]> git.mxchange.org Git - friendica.git/commitdiff
Simplyfied code
authorMichael <heluecht@pirati.ca>
Thu, 21 Dec 2023 05:01:24 +0000 (05:01 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 21 Dec 2023 05:01:24 +0000 (05:01 +0000)
src/Protocol/ActivityPub/Processor.php

index 2a70e40289fb3f841c81479cf3c72e0c83158369..efd1e00cedf8eb36d9482d36a430f9edec54f776 100644 (file)
@@ -1324,23 +1324,21 @@ class Processor
        public static function storeReceivers(int $uriid, array $receivers)
        {
                foreach (['as:to' => Tag::TO, 'as:cc' => Tag::CC, 'as:bto' => Tag::BTO, 'as:bcc' => Tag::BCC, 'as:audience' => Tag::AUDIENCE, 'as:attributedTo' => Tag::ATTRIBUTED] as $element => $type) {
-                       if (!empty($receivers[$element])) {
-                               foreach ($receivers[$element] as $receiver) {
-                                       if ($receiver == ActivityPub::PUBLIC_COLLECTION) {
-                                               $name = Receiver::PUBLIC_COLLECTION;
-                                       } elseif ($path = parse_url($receiver, PHP_URL_PATH)) {
-                                               $name = trim($path, '/');
-                                       } elseif ($host = parse_url($receiver, PHP_URL_HOST)) {
-                                               $name = $host;
-                                       } else {
-                                               Logger::warning('Unable to coerce name from receiver', ['element' => $element, 'type' => $type, 'receiver' => $receiver]);
-                                               $name = '';
-                                       }
-
-                                       $target = Tag::getTargetType($receiver);
-                                       Logger::debug('Got target type', ['type' => $target, 'url' => $receiver]);
-                                       Tag::store($uriid, $type, $name, $receiver, $target);
+                       foreach ($receivers[$element] ?? [] as $receiver) {
+                               if ($receiver == ActivityPub::PUBLIC_COLLECTION) {
+                                       $name = Receiver::PUBLIC_COLLECTION;
+                               } elseif ($path = parse_url($receiver, PHP_URL_PATH)) {
+                                       $name = trim($path, '/');
+                               } elseif ($host = parse_url($receiver, PHP_URL_HOST)) {
+                                       $name = $host;
+                               } else {
+                                       Logger::warning('Unable to coerce name from receiver', ['element' => $element, 'type' => $type, 'receiver' => $receiver]);
+                                       $name = '';
                                }
+
+                               $target = Tag::getTargetType($receiver);
+                               Logger::debug('Got target type', ['type' => $target, 'url' => $receiver]);
+                               Tag::store($uriid, $type, $name, $receiver, $target);
                        }
                }
        }
@@ -1348,22 +1346,20 @@ class Processor
        private static function storeCapabilities(int $uriid, array $capabilities)
        {
                foreach (['pixelfed:canAnnounce' => Tag::CAN_ANNOUNCE, 'pixelfed:canLike' => Tag::CAN_LIKE, 'pixelfed:canReply' => Tag::CAN_REPLY] as $element => $type) {
-                       if (!empty($capabilities[$element])) {
-                               foreach ($capabilities[$element] as $capability) {
-                                       if ($capability == ActivityPub::PUBLIC_COLLECTION) {
-                                               $name = Receiver::PUBLIC_COLLECTION;
-                                       } elseif (empty($capability) || ($capability == '[]')) {
-                                               continue;
-                                       } elseif ($path = parse_url($capability, PHP_URL_PATH)) {
-                                               $name = trim($path, '/');
-                                       } elseif ($host = parse_url($capability, PHP_URL_HOST)) {
-                                               $name = $host;
-                                       } else {
-                                               Logger::warning('Unable to coerce name from capability', ['element' => $element, 'type' => $type, 'capability' => $capability]);
-                                               $name = '';
-                                       }
-                                       Tag::store($uriid, $type, $name, $capability);
+                       foreach ($capabilities[$element] ?? [] as $capability) {
+                               if ($capability == ActivityPub::PUBLIC_COLLECTION) {
+                                       $name = Receiver::PUBLIC_COLLECTION;
+                               } elseif (empty($capability) || ($capability == '[]')) {
+                                       continue;
+                               } elseif ($path = parse_url($capability, PHP_URL_PATH)) {
+                                       $name = trim($path, '/');
+                               } elseif ($host = parse_url($capability, PHP_URL_HOST)) {
+                                       $name = $host;
+                               } else {
+                                       Logger::warning('Unable to coerce name from capability', ['element' => $element, 'type' => $type, 'capability' => $capability]);
+                                       $name = '';
                                }
+                               Tag::store($uriid, $type, $name, $capability);
                        }
                }
        }