]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/APContact.php
Changed double-quotes to single
[friendica.git] / src / Model / APContact.php
index a93484861226754eea85073035c09e9290005d6f..baa364e940636a4e1d39ea7e40cadd5fed0e7bdb 100644 (file)
@@ -48,7 +48,7 @@ class APContact
         * @param string $addr Address
         * @return array webfinger data
         */
-       private static function fetchWebfingerData(string $addr)
+       private static function fetchWebfingerData(string $addr): array
        {
                $addr_parts = explode('@', $addr);
                if (count($addr_parts) != 2) {
@@ -116,15 +116,16 @@ class APContact
         * @return array profile array
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
+        * @todo Rewrite parameter $update to avoid true|false|null (boolean is binary, null adds a third case)
         */
-       public static function getByURL(string $url, $update = null)
+       public static function getByURL(string $url, $update = null): array
        {
                if (empty($url) || Network::isUrlBlocked($url)) {
                        Logger::info('Domain is blocked', ['url' => $url]);
                        return [];
                }
 
-               $fetched_contact = false;
+               $fetched_contact = [];
 
                if (empty($update)) {
                        if (is_null($update)) {
@@ -164,6 +165,8 @@ class APContact
                                return $fetched_contact;
                        }
                        $url = $apcontact['url'];
+               } elseif (empty(parse_url($url, PHP_URL_PATH))) {
+                       $apcontact['baseurl'] = $url;
                }
 
                // Detect multiple fast repeating request to the same address
@@ -220,14 +223,14 @@ class APContact
                $apcontact['type'] = str_replace('as:', '', JsonLD::fetchElement($compacted, '@type'));
                $apcontact['following'] = JsonLD::fetchElement($compacted, 'as:following', '@id');
                $apcontact['followers'] = JsonLD::fetchElement($compacted, 'as:followers', '@id');
-               $apcontact['inbox'] = JsonLD::fetchElement($compacted, 'ldp:inbox', '@id');
+               $apcontact['inbox'] = (JsonLD::fetchElement($compacted, 'ldp:inbox', '@id') ?? '');
                self::unarchiveInbox($apcontact['inbox'], false);
 
                $apcontact['outbox'] = JsonLD::fetchElement($compacted, 'as:outbox', '@id');
 
                $apcontact['sharedinbox'] = '';
                if (!empty($compacted['as:endpoints'])) {
-                       $apcontact['sharedinbox'] = JsonLD::fetchElement($compacted['as:endpoints'], 'as:sharedInbox', '@id');
+                       $apcontact['sharedinbox'] = (JsonLD::fetchElement($compacted['as:endpoints'], 'as:sharedInbox', '@id') ?? '');
                        self::unarchiveInbox($apcontact['sharedinbox'], true);
                }
 
@@ -465,7 +468,7 @@ class APContact
                }
 
                // Limit the length on incoming fields
-               $apcontact = DBStructure::getFieldsForTable('apcontact', $apcontact);
+               $apcontact = DI::dbaDefinition()->truncateFieldsForTable('apcontact', $apcontact);
 
                if (DBA::exists('apcontact', ['url' => $apcontact['url']])) {
                        DBA::update('apcontact', $apcontact, ['url' => $apcontact['url']]);
@@ -526,8 +529,9 @@ class APContact
         *
         * @param string  $url    inbox url
         * @param boolean $shared Shared Inbox
+        * @return void
         */
-       private static function unarchiveInbox($url, $shared)
+       private static function unarchiveInbox(string $url, bool $shared)
        {
                if (empty($url)) {
                        return;