]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #12364 from MrPetovan/bug/warnings
authorMichael Vogel <icarus@dabo.de>
Sat, 10 Dec 2022 17:10:24 +0000 (18:10 +0100)
committerGitHub <noreply@github.com>
Sat, 10 Dec 2022 17:10:24 +0000 (18:10 +0100)
Address several warning messages

12 files changed:
src/App.php
src/Contact/Avatar.php
src/Model/APContact.php
src/Model/Contact.php
src/Model/Item.php
src/Model/Mail.php
src/Module/NoScrape.php
src/Module/Tos.php
src/Network/Probe.php
src/Protocol/ActivityPub/Processor.php
src/Protocol/ActivityPub/Receiver.php
src/Protocol/Feed.php

index 25770dd782e072e2add1532e68bb23667c7cf504..0d4e8880dd9d8373db64f8b0a60df3cd7325da83 100644 (file)
@@ -631,10 +631,10 @@ class App
 
                        // ZRL
                        if (!empty($_GET['zrl']) && $this->mode->isNormal() && !$this->mode->isBackend() && !$this->session->getLocalUserId()) {
-                               // Only continue when the given profile link seems valid
+                               // Only continue when the given profile link seems valid.
                                // Valid profile links contain a path with "/profile/" and no query parameters
                                if ((parse_url($_GET['zrl'], PHP_URL_QUERY) == '') &&
-                                       strstr(parse_url($_GET['zrl'], PHP_URL_PATH), '/profile/')) {
+                                       strpos(parse_url($_GET['zrl'], PHP_URL_PATH) ?? '', '/profile/') !== false) {
                                        if ($this->session->get('visitor_home') != $_GET['zrl']) {
                                                $this->session->set('my_url', $_GET['zrl']);
                                                $this->session->set('authenticated', 0);
index 0cfc8df3458275478b84340d9245440c595af10c..711a8549f26a96c7f6b85ec9de93a001210ae2b2 100644 (file)
@@ -125,7 +125,7 @@ class Avatar
 
        private static function getFilename(string $url): string
        {
-               $guid = Item::guidFromUri($url, parse_url($url, PHP_URL_HOST));
+               $guid = Item::guidFromUri($url);
 
                return substr($guid, 0, 2) . '/' . substr($guid, 3, 2) . '/' . substr($guid, 5, 3) . '/' .
                        substr($guid, 9, 2) .'/' . substr($guid, 11, 2) . '/' . substr($guid, 13, 4). '/' . substr($guid, 18) . '-';
index 67ce2b66bf73d9c689ef5f778404edc42c1fb358..fd748f1cd4e92419b77513f5cad205a3cec60fcb 100644 (file)
@@ -291,14 +291,11 @@ class APContact
                        return $fetched_contact;
                }
 
-               $parts = parse_url($apcontact['url']);
-               unset($parts['scheme']);
-               unset($parts['path']);
-
                if (empty($apcontact['addr'])) {
-                       if (!empty($apcontact['nick']) && is_array($parts)) {
-                               $apcontact['addr'] = $apcontact['nick'] . '@' . str_replace('//', '', Network::unparseURL($parts));
-                       } else {
+                       try {
+                               $apcontact['addr'] = $apcontact['nick'] . '@' . (new Uri($apcontact['url']))->getAuthority();
+                       } catch (\Throwable $e) {
+                               Logger::warning('Unable to coerce APContact URL into a UriInterface object', ['url' => $apcontact['url'], 'error' => $e->getMessage()]);
                                $apcontact['addr'] = '';
                        }
                }
index d3ff4a2ef11086e6f2e5317951ee53cafc2beddf..c20435278f9d8973e5ccd53be9b425cb3ae38b72 100644 (file)
@@ -2107,7 +2107,7 @@ class Contact
                if ($static) {
                        $query_params['static'] = true;
                }
-               
+
                return $url . ($guid ?: $cid) . (!empty($query_params) ? '?' . http_build_query($query_params) : '');
        }
 
@@ -2691,7 +2691,7 @@ class Contact
                }
 
                $update = false;
-               $guid = ($ret['guid'] ?? '') ?: Item::guidFromUri($ret['url'], parse_url($ret['url'], PHP_URL_HOST));
+               $guid = ($ret['guid'] ?? '') ?: Item::guidFromUri($ret['url']);
 
                // make sure to not overwrite existing values with blank entries except some technical fields
                $keep = ['batch', 'notify', 'poll', 'request', 'confirm', 'poco', 'baseurl'];
index ff4791a7cca866f23d49b733dae2286c969fa646..8b9909f8bf06699ed71f0ff8a1b8bdbf52d54027 100644 (file)
@@ -2034,9 +2034,10 @@ class Item
         * Posts that are created on this system are using System::createUUID.
         * Received ActivityPub posts are using Processor::getGUIDByURL.
         *
-        * @param string      $uri uri of an item entry
+        * @param string      $uri  uri of an item entry
         * @param string|null $host hostname for the GUID prefix
         * @return string Unique guid
+        * @throws \Exception
         */
        public static function guidFromUri(string $uri, string $host = null): string
        {
@@ -2047,11 +2048,16 @@ class Item
                // Remove the scheme to make sure that "https" and "http" doesn't make a difference
                unset($parsed['scheme']);
 
+               $hostPart = $host ?? $parsed['host'] ?? '';
+               if (!$hostPart) {
+                       Logger::warning('Empty host GUID part', ['uri' => $uri, 'host' => $host, 'parsed' => $parsed, 'callstack' => System::callstack(10)]);
+               }
+
                // Glue it together to be able to make a hash from it
                $host_id = implode('/', $parsed);
 
                // Use a mixture of several hashes to provide some GUID like experience
-               return hash('crc32', $host) . '-'. hash('joaat', $host_id) . '-'. hash('fnv164', $host_id);
+               return hash('crc32', $hostPart) . '-' . hash('joaat', $host_id) . '-' . hash('fnv164', $host_id);
        }
 
        /**
index 6ccce24ba7d93d7a6ff4e428da273385216efb87..9469483d9a9749e39d131db34eef27aedb9c9873 100644 (file)
@@ -59,8 +59,7 @@ class Mail
                }
 
                if (empty($msg['guid'])) {
-                       $host = parse_url($msg['from-url'], PHP_URL_HOST);
-                       $msg['guid'] = Item::guidFromUri($msg['uri'], $host);
+                       $msg['guid'] = Item::guidFromUri($msg['uri'], parse_url($msg['from-url'], PHP_URL_HOST));
                }
 
                $msg['created'] = (!empty($msg['created']) ? DateTimeFormat::utc($msg['created']) : DateTimeFormat::utcNow());
index 8e5850ac0b4ad30efbfef9a67378054121eeffad..56f31f2dcfeef2d98926d0118710b430aef8d36d 100644 (file)
@@ -94,7 +94,7 @@ class NoScrape extends BaseModule
 
                // We display the last activity (post or login), reduced to year and week number
                $last_active = strtotime($owner['last-item']);
-               if ($last_active < strtotime($owner['last-activity'])) {
+               if ($owner['last-activity'] && $last_active < strtotime($owner['last-activity'])) {
                        $last_active = strtotime($owner['last-activity']);
                }
                $json_info['last-activity'] = date('o-W', $last_active);
index 822aa8813b8d18af371c23f31bd98b6c5547c324..11cecac44da3d8a1510b4116016986015f6e455d 100644 (file)
@@ -77,7 +77,7 @@ class Tos extends BaseModule
         */
        protected function content(array $request = []): string
        {
-               if (strlen($this->config->get('system', 'singleuser'))) {
+               if ($this->config->get('system', 'singleuser')) {
                        $this->baseUrl->redirect('profile/' . $this->config->get('system', 'singleuser'));
                }
 
index e74b4373454b4403ef0d275a6c047ce9b6de169f..5a8f75e2d8cc30820cf63b3b40073c40c6692787 100644 (file)
@@ -38,6 +38,7 @@ use Friendica\Network\HTTPClient\Client\HttpClientAccept;
 use Friendica\Network\HTTPClient\Client\HttpClientOptions;
 use Friendica\Protocol\ActivityNamespace;
 use Friendica\Protocol\ActivityPub;
+use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\Email;
 use Friendica\Protocol\Feed;
 use Friendica\Protocol\Salmon;
@@ -358,7 +359,9 @@ class Probe
                        if (empty($data) || (!empty($ap_profile) && empty($network) && (($data['network'] ?? '') != Protocol::DFRN))) {
                                $networks = $data['networks'] ?? [];
                                unset($data['networks']);
-                               $networks[$data['network']] = $data;
+                               if (!empty($data['network'])) {
+                                       $networks[$data['network']] = $data;
+                               }
                                $data = $ap_profile;
                                $data['networks'] = $networks;
                        } elseif (!empty($ap_profile)) {
@@ -684,7 +687,7 @@ class Probe
                }
 
                $parts = parse_url($uri);
-               if (empty($parts['scheme']) && empty($parts['host']) && !strstr($parts['path'], '@')) {
+               if (empty($parts['scheme']) && empty($parts['host']) && (empty($parts['path']) || strpos($parts['path'], '@') === false)) {
                        Logger::info('URI was not detectable', ['uri' => $uri]);
                        return [];
                }
@@ -2207,6 +2210,8 @@ class Probe
                        $owner     = User::getOwnerDataById($uid);
                        $approfile = ActivityPub\Transmitter::getProfile($uid);
 
+                       $split_name = Diaspora::splitName($owner['name']);
+       
                        if (empty($owner['gsid'])) {
                                $owner['gsid'] = GServer::getID($approfile['generator']['url']);
                        }
@@ -2226,7 +2231,28 @@ class Probe
                                'inbox'            => $approfile['inbox'], 'outbox' => $approfile['outbox'],
                                'sharedinbox'      => $approfile['endpoints']['sharedInbox'], 'network' => Protocol::DFRN,
                                'pubkey'           => $owner['upubkey'], 'baseurl' => $approfile['generator']['url'], 'gsid' => $owner['gsid'],
-                               'manually-approve' => in_array($owner['page-flags'], [User::PAGE_FLAGS_NORMAL, User::PAGE_FLAGS_PRVGROUP])
+                               'manually-approve' => in_array($owner['page-flags'], [User::PAGE_FLAGS_NORMAL, User::PAGE_FLAGS_PRVGROUP]),
+                               'networks' => [
+                                       Protocol::DIASPORA => [
+                                               'name'         => $owner['name'],
+                                               'given_name'   => $split_name['first'],
+                                               'family_name'  => $split_name['last'],
+                                               'nick'         => $owner['nick'],
+                                               'guid'         => $approfile['diaspora:guid'],
+                                               'url'          => $owner['url'],
+                                               'addr'         => $owner['addr'],
+                                               'alias'        => $owner['alias'],
+                                               'photo'        => $owner['photo'],
+                                               'photo_medium' => $owner['thumb'],
+                                               'photo_small'  => $owner['micro'],
+                                               'batch'        => $approfile['generator']['url'] . '/receive/public',
+                                               'notify'       => $owner['notify'],
+                                               'poll'         => $owner['poll'],
+                                               'poco'         => $owner['poco'],                                               
+                                               'network'      => Protocol::DIASPORA,
+                                               'pubkey'       => $owner['upubkey'],
+                                       ]
+                               ]
                        ];
                } catch (Exception $e) {
                        // Default values for non existing targets
index 8e21a664469bc7a7e274dcb4bbc01f9e67c84f60..d098ddb691343f957f9ea1f525807158995099cf 100644 (file)
@@ -804,7 +804,7 @@ class Processor
        private static function processContent(array $activity, array $item)
        {
                if (!empty($activity['mediatype']) && ($activity['mediatype'] == 'text/markdown')) {
-                       $item['title'] = strip_tags($activity['name']);
+                       $item['title'] = strip_tags($activity['name'] ?? '');
                        $content = Markdown::toBBCode($activity['content']);
                } elseif (!empty($activity['mediatype']) && ($activity['mediatype'] == 'text/bbcode')) {
                        $item['title'] = $activity['name'];
@@ -1273,8 +1273,11 @@ class Processor
                                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, '/');
                                        } else {
-                                               $name = trim(parse_url($receiver, PHP_URL_PATH), '/');
+                                               Logger::warning('Unable to coerce name from receiver', ['receiver' => $receiver]);
+                                               $name = '';
                                        }
 
                                        $target = Tag::getTargetType($receiver);
index 4e2bcceafbc0efc8bf3cfa6b1e6a59066ff8149b..89398227422a411f7de6b25e452360cdab9c3238 100644 (file)
@@ -209,7 +209,7 @@ class Receiver
                                Logger::notice('No object data found', ['type' => $type, 'object_type' => $object_type, 'object_id' => $object_id, 'actor' => $actor, 'activity' => $activity]);
                                return;
                        }
-       
+
                        if (self::routeActivities($object_data, $type, true)) {
                                Logger::debug('Handled activity', ['type' => $type, 'object_type' => $object_type, 'object_id' => $object_id, 'actor' => $actor]);
                        } else {
@@ -1472,7 +1472,7 @@ class Receiver
                                continue;
                        }
 
-                       $element = ['type' => str_replace('as:', '', JsonLD::fetchElement($tag, '@type')),
+                       $element = ['type' => str_replace('as:', '', JsonLD::fetchElement($tag, '@type') ?? ''),
                                'href' => JsonLD::fetchElement($tag, 'as:href', '@id'),
                                'name' => JsonLD::fetchElement($tag, 'as:name', '@value')];
 
index 29b192331609890b03606ee639b48a943c9808eb..dec463820d89507b33891087f711be5bbbcd7f8f 100644 (file)
@@ -625,8 +625,8 @@ class Feed
 
                        $notify = Item::isRemoteSelf($contact, $item);
 
-                       // Distributed items should have a well formatted URI.
-                       // Additionally we have to avoid conflicts with identical URI between imported feeds and these items.
+                       // Distributed items should have a well-formatted URI.
+                       // Additionally, we have to avoid conflicts with identical URI between imported feeds and these items.
                        if ($notify) {
                                $item['guid'] = Item::guidFromUri($orig_plink, DI::baseUrl()->getHostname());
                                $item['uri'] = Item::newURI($item['guid']);