]> git.mxchange.org Git - friendica.git/commitdiff
Fix all errors in Protocol namespace
authorArt4 <art4@wlabs.de>
Sun, 17 Nov 2024 18:39:17 +0000 (18:39 +0000)
committerArt4 <art4@wlabs.de>
Sun, 17 Nov 2024 18:39:17 +0000 (18:39 +0000)
src/Protocol/ActivityPub/ClientToServer.php
src/Protocol/ActivityPub/Delivery.php
src/Protocol/ActivityPub/Processor.php
src/Protocol/ActivityPub/Queue.php
src/Protocol/ActivityPub/Receiver.php
src/Protocol/ActivityPub/Transmitter.php
src/Protocol/Delivery.php
src/Protocol/Diaspora.php
src/Protocol/Feed.php
src/Util/JsonLD.php

index e668b77e36ba280a66d57a36e66d23df6bf94329..d812dacd48eb0019868cf8d5cd0124d22af39418 100644 (file)
@@ -323,7 +323,7 @@ class ClientToServer
                        $requester_id = Contact::getIdForURL($requester, $owner['uid']);
                        if (!empty($requester_id)) {
                                $permissionSets = DI::permissionSet()->selectByContactId($requester_id, $owner['uid']);
-                               if (!empty($permissionSets)) {
+                               if ($permissionSets->getTotalCount() > 0) {
                                        $condition = ['psid' => array_merge($permissionSets->column('id'),
                                                [DI::permissionSet()->selectPublicForUser($owner['uid'])])];
                                }
index 7a7d484b8d03505186435b58b6a5a1df20e057f5..fe7b0a76edc9096120d230a44d9cb2c9cf65899e 100644 (file)
@@ -42,6 +42,8 @@ class Delivery
                                continue;
                        }
 
+                       $result = [];
+
                        if (!$serverfail) {
                                $result = self::deliverToInbox($post['command'], 0, $inbox, $owner, $post['receivers'], $post['uri-id']);
 
@@ -121,11 +123,12 @@ class Delivery
                                        $serverfail = $response->isTimeout();
                                } catch (\Throwable $th) {
                                        Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+                                       $response   = null;
                                        $success    = false;
                                        $serverfail = true;
                                }
                                $runtime = microtime(true) - $timestamp;
-                               if (!$success) {
+                               if ($success === false) {
                                        // 5xx errors are problems on the server. We don't need to continue delivery then.
                                        if (!$serverfail && ($response->getReturnCode() >= 500) && ($response->getReturnCode() <= 599)) {
                                                $serverfail = true;
index 21be0f6379cd03a04cf99724f034851c60880733..b5aaaa5d33ddfc3d5409d9054c7a8efe80df0880 100644 (file)
@@ -520,7 +520,7 @@ class Processor
                if (!DI::config()->get('system', 'decoupled_receiver')) {
                        return;
                }
-               
+
                $replies = [$item['thr-parent']];
                if (!empty($item['parent-uri'])) {
                        $replies[] = $item['parent-uri'];
@@ -561,7 +561,7 @@ class Processor
                if (in_array($activity['reply-to-id'], $activity['children'] ?? [])) {
                        Logger::notice('reply-to-id is already in the list of children', ['id' => $activity['reply-to-id'], 'children' => $activity['children'], 'depth' => count($activity['children'])]);
                        return '';
-               } 
+               }
 
                self::addActivityId($activity['reply-to-id']);
 
@@ -1361,6 +1361,7 @@ class Processor
                        }
 
                        $hash = substr($tag['name'], 0, 1);
+                       $type = 0;
 
                        if ($tag['type'] == 'Mention') {
                                if (in_array($hash, [Tag::TAG_CHARACTER[Tag::MENTION],
@@ -1616,7 +1617,7 @@ class Processor
                        return [];
                }
 
-               if (!self::isValidObject($object, $url)) {
+               if (!self::isValidObject($object)) {
                        return [];
                }
 
@@ -1657,10 +1658,6 @@ class Processor
                        return '';
                }
 
-               if (empty($curlResult)) {
-                       return '';
-               }
-
                $body = $curlResult->getBodyString();
                if (!$curlResult->isSuccess() || empty($body)) {
                        if (in_array($curlResult->getReturnCode(), [403, 404, 406, 410])) {
@@ -1680,7 +1677,7 @@ class Processor
                        return null;
                }
 
-               if (!self::isValidObject($object, $url)) {
+               if (!self::isValidObject($object)) {
                        return null;
                }
 
@@ -1747,7 +1744,7 @@ class Processor
                $ldactivity['children']        = $child['children'] ?? [];
                $ldactivity['callstack']       = $child['callstack'] ?? [];
                // This check is mostly superfluous, since there are similar checks before. This covers the case, when the fetched id doesn't match the url
-               if (in_array($activity['id'], $ldactivity['children'])) {                       
+               if (in_array($activity['id'], $ldactivity['children'])) {
                        Logger::notice('Fetched id is already in the list of children. It will not be processed.', ['id' => $activity['id'], 'children' => $ldactivity['children'], 'depth' => count($ldactivity['children'])]);
                        return null;
                }
@@ -1829,6 +1826,8 @@ class Processor
                Logger::notice('Fetch replies - start', ['replies' => $url, 'callstack' => $child['callstack'], 'system' => $callstack]);
                $fetched = 0;
                foreach ($replies as $reply) {
+                       $id = '';
+
                        if (is_array($reply)) {
                                $ldobject = JsonLD::compact($reply);
                                $id = JsonLD::fetchElement($ldobject, '@id');
@@ -2120,9 +2119,8 @@ class Processor
                        self::transmitPendingEvents($cid, $owner['uid']);
                }
 
-               if (empty($contact)) {
-                       Contact::update(['hub-verify' => $activity['id'], 'protocol' => Protocol::ACTIVITYPUB], ['id' => $cid]);
-               }
+               Contact::update(['hub-verify' => $activity['id'], 'protocol' => Protocol::ACTIVITYPUB], ['id' => $cid]);
+
                Logger::notice('Follow user ' . $uid . ' from contact ' . $cid . ' with id ' . $activity['id']);
                Queue::remove($activity);
        }
@@ -2334,6 +2332,8 @@ class Processor
         */
        public static function acceptFollowUser(array $activity)
        {
+               $check_id = false;
+
                if (!empty($activity['object_actor'])) {
                        $uid      = User::getIdForURL($activity['object_actor']);
                        $check_id = false;
index 54bdee9dc00e8cdb91cf139e2cd2fec43dfa7052..84d49adbf1f86c39ec02eb44197354c30a4db91c 100644 (file)
@@ -414,7 +414,7 @@ class Queue
        {
                $entries = DBA::select('inbox-entry', ['id'], ["NOT `trust` AND `wid` IS NULL"], ['order' => ['id' => true]]);
                while ($entry = DBA::fetch($entries)) {
-                       $data = self::reprepareActivityById($entry['id'], false);
+                       $data = self::reprepareActivityById($entry['id']);
                        if ($data['trust']) {
                                DBA::update('inbox-entry', ['trust' => true], ['id' => $entry['id']]);
                        }
index 7512e6179c3d009f941544fe054910228140638c..41847a79a805d107c80ce24e89878620a7f90448 100644 (file)
@@ -304,9 +304,10 @@ class Receiver
         */
        public static function prepareObjectData(array $activity, int $uid, bool $push, bool &$trust_source, string $original_actor = ''): array
        {
-               $id        = JsonLD::fetchElement($activity, '@id');
-               $type      = JsonLD::fetchElement($activity, '@type');
-               $object_id = JsonLD::fetchElement($activity, 'as:object', '@id');
+               $id          = JsonLD::fetchElement($activity, '@id');
+               $type        = JsonLD::fetchElement($activity, '@type');
+               $object_id   = JsonLD::fetchElement($activity, 'as:object', '@id');
+               $object_type = '';
 
                if (!empty($object_id) && in_array($type, ['as:Create', 'as:Update'])) {
                        $fetch_id = $object_id;
@@ -630,7 +631,7 @@ class Receiver
                        $id            = JsonLD::fetchElement($activity, '@id');
                        $object_id     = JsonLD::fetchElement($activity, 'as:object', '@id');
 
-                       if (!empty($published) && !empty($object_id) && in_array($type, ['as:Create', 'as:Update']) && in_array($object_type, self::CONTENT_TYPES)
+                       if (!empty($published) && $object_id !== null && in_array($type, ['as:Create', 'as:Update']) && in_array($object_type, self::CONTENT_TYPES)
                                && ($push || ($completion != self::COMPLETION_MANUAL)) && DI::contentItem()->isTooOld($published) && !Post::exists(['uri' => $object_id])) {
                                Logger::debug('Activity is too old. It will not be processed', ['push' => $push, 'completion' => $completion, 'type' =>  $type,  'object-type' => $object_type, 'published' => $published, 'id' => $id, 'object-id' => $object_id]);
                                return true;
@@ -641,7 +642,7 @@ class Receiver
 
                // Test the provided signatures against the actor and "attributedTo"
                if ($trust_source) {
-                       if (!empty($attributed_to) && !empty($actor)) {
+                       if (!empty($attributed_to) && $actor !== null) {
                                $trust_source = (in_array($actor, $signer) && in_array($attributed_to, $signer));
                        } else {
                                $trust_source = in_array($actor, $signer);
@@ -1185,6 +1186,8 @@ class Receiver
                }
 
                $parent_followers = '';
+               $parent_profile   = [];
+
                $parent = Post::selectFirstPost(['parent-author-link'], ['uri' => $reply]);
                if (!empty($parent['parent-author-link'])) {
                        $parent_profile = APContact::getByURL($parent['parent-author-link']);
index 883a97c10acffe3dd6c5eaa5b0adcd939ff60972..0aeccc3867c55215b0dbd0d5b2eec9409a58dccb 100644 (file)
@@ -573,11 +573,12 @@ class Transmitter
                $exclusive  = false;
                $mention    = false;
                $audience   = [];
+               $owner      = false;
 
                // Check if we should always deliver our stuff via BCC
                if (!empty($item['uid'])) {
                        $owner = User::getOwnerDataById($item['uid']);
-                       if (!empty($owner)) {
+                       if (is_array($owner)) {
                                $always_bcc = $owner['hide-friends'];
                                $is_group   = ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY);
 
@@ -1399,7 +1400,7 @@ class Transmitter
                $type = self::getTypeOfItem($item);
 
                if (!$object_mode) {
-                       $data = ['@context' => $context ?? ActivityPub::CONTEXT];
+                       $data = ['@context' => ActivityPub::CONTEXT];
 
                        if ($item['deleted'] && ($item['gravity'] == Item::GRAVITY_ACTIVITY)) {
                                $type = 'Undo';
@@ -1750,6 +1751,7 @@ class Transmitter
 
                $title   = $item['title'];
                $summary = $item['content-warning'] ?: BBCode::toPlaintext(BBCode::getAbstract($item['body'], Protocol::ACTIVITYPUB));
+               $type    = '';
 
                if ($item['event-type'] == 'event') {
                        $type = 'Event';
index 9f875367752c44469d60cdd4daf356ca787d3692..c18de6264cee32be0dbfeff203691bd4717bd473 100644 (file)
@@ -12,7 +12,6 @@ use Friendica\Contact\FriendSuggest\Exception\FriendSuggestNotFoundException;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
 use Friendica\Core\Worker;
-use Friendica\Database\Database;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Contact;
@@ -48,6 +47,8 @@ class Delivery
                $top_level      = false;
                $followup       = false;
                $public_message = false;
+               $parent         = false;
+               $thr_parent     = false;
 
                $items = [];
                if ($cmd == self::MAIL) {
index 74963025e997b474e99154ff0383db164af35190..2e5b7bfdd0582a8dcbb94bac1ff23f2a56a13ef0 100644 (file)
@@ -623,22 +623,21 @@ class Diaspora
         */
        private static function validPosting(array $msg)
        {
-               $data = XML::parseString($msg['message']);
+               $element = XML::parseString($msg['message']);
 
-               if (!is_object($data)) {
+               if (!is_object($element)) {
                        Logger::info('No valid XML', ['message' => $msg['message']]);
                        return false;
                }
 
+               $oldXML = false;
+
                // Is this the new or the old version?
-               if ($data->getName() == 'XML') {
+               if ($element->getName() === 'XML') {
                        $oldXML = true;
-                       foreach ($data->post->children() as $child) {
+                       foreach ($element->post->children() as $child) {
                                $element = $child;
                        }
-               } else {
-                       $oldXML = false;
-                       $element = $data;
                }
 
                $type = $element->getName();
@@ -1460,7 +1459,7 @@ class Diaspora
                 */
 
                foreach ($matches as $match) {
-                       if (empty($match)) {
+                       if ($match === '') {
                                continue;
                        }
 
@@ -3030,7 +3029,7 @@ class Diaspora
                        // The "addr" field should always be filled.
                        // If this isn't the case, it will raise a notice some lines later.
                        // And in the log we will see where it came from, and we can handle it there.
-                       Logger::notice('Empty addr', ['contact' => $contact ?? []]);
+                       Logger::notice('Empty addr', ['contact' => $contact]);
                }
 
                $envelope = self::buildMessage($msg, $owner, $contact, $owner['uprvkey'], $pubkey ?? '', $public_batch);
@@ -3655,6 +3654,8 @@ class Diaspora
         */
        public static function sendFollowup(array $item, array $owner, array $contact, bool $public_batch = false): int
        {
+               $type = '';
+
                if (in_array($item['verb'], [Activity::ATTEND, Activity::ATTENDNO, Activity::ATTENDMAYBE])) {
                        $message = self::constructAttend($item, $owner);
                        $type = 'event_participation';
index 999f88febca373ae24229af1fd7bc35afe989b6f..1da524ed235d8055d802a5c4a70179f1b1fcc6e7 100644 (file)
@@ -556,7 +556,7 @@ class Feed
                                Logger::info('Feed is too old', ['created' => $item['created'], 'uid' => $item['uid'], 'uri' => $item['uri']]);
                                continue;
                        }
-                       
+
                        if (!empty($item['plink'])) {
                                $fetch_further_information = $contact['fetch_further_information'] ?? LocalRelationship::FFI_NONE;
                        } else {
@@ -736,7 +736,7 @@ class Feed
                                $publish_at = date(DateTimeFormat::MYSQL, $publish_time);
 
                                if (Post\Delayed::add($posting['item']['uri'], $posting['item'], $posting['notify'], Post\Delayed::PREPARED, $publish_at, $posting['taglist'], $posting['attachments'])) {
-                                       DI::pConfig()->set($item['uid'], 'system', 'last_publish', $publish_time);
+                                       DI::pConfig()->set($posting['item']['uid'], 'system', 'last_publish', $publish_time);
                                }
                        }
                }
@@ -1407,7 +1407,7 @@ class Feed
 
                                $contact = Contact::getByURL($item['author-link']) ?: $owner;
                                $contact['nickname'] = $contact['nickname'] ?? $contact['nick'];
-                               $author = self::addAuthor($doc, $contact, false);
+                               $author = self::addAuthor($doc, $contact);
                                $entry->appendChild($author);
                        }
                } else {
index 1ee5c0920e0e27cb9b9d508c6aac75d85eb9595f..39c368818c4420cb2370702d567d28fbbc58d4d4 100644 (file)
@@ -286,7 +286,7 @@ class JsonLD
         * @param $type
         * @param $type_value
         *
-        * @return string fetched element
+        * @return string|null fetched element
         */
        public static function fetchElement($array, $element, $key = '@id', $type = null, $type_value = null)
        {