]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Contact.php
Add probe_detect hook
[friendica.git] / src / Model / Contact.php
index f60a362c57689ce22b3f14e88f6f98101db23736..e881398df8b9ce893de96f520646934b6117a73c 100644 (file)
@@ -847,7 +847,7 @@ class Contact
                        $item['body'] = '';
                        $item['title'] = '';
                        $item['guid'] = '';
-                       $item['tag'] = '';
+                       $item['uri-id'] = 0;
                        $item['attach'] = '';
                        $slap = OStatus::salmon($item, $user);
 
@@ -1142,7 +1142,7 @@ class Contact
 
                // Fetch contact data from the contact table for the given user
                $r = q("SELECT `id`, `id` AS `cid`, 0 AS `gid`, 0 AS `zid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`,
-                       `keywords`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, `self`, `rel`, `pending`
+                       `keywords`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, `self`, `rel`, `pending`,`baseurl`
                        FROM `contact` WHERE `addr` = '%s' AND `uid` = %d AND NOT `deleted`",
                        DBA::escape($addr),
                        intval($uid)
@@ -1150,7 +1150,7 @@ class Contact
                // Fetch the data from the contact table with "uid=0" (which is filled automatically)
                if (!DBA::isResult($r)) {
                        $r = q("SELECT `id`, 0 AS `cid`, `id` AS `zid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`,
-                               `keywords`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, 0 AS `self`, `rel`, `pending`
+                               `keywords`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, 0 AS `self`, `rel`, `pending`, `baseurl`
                                FROM `contact` WHERE `addr` = '%s' AND `uid` = 0 AND NOT `deleted`",
                                DBA::escape($addr)
                        );
@@ -1159,7 +1159,7 @@ class Contact
                // Fetch the data from the gcontact table
                if (!DBA::isResult($r)) {
                        $r = q("SELECT 0 AS `id`, 0 AS `cid`, `id` AS `gid`, 0 AS `zid`, 0 AS `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, '' AS `xmpp`,
-                               `keywords`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, `community` AS `forum`, 0 AS `prv`, `community`, `contact-type`, `birthday`, 0 AS `self`, 2 AS `rel`, 0 AS `pending`
+                               `keywords`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, `community` AS `forum`, 0 AS `prv`, `community`, `contact-type`, `birthday`, 0 AS `self`, 2 AS `rel`, 0 AS `pending`, `server_url` AS `baseurl`
                                FROM `gcontact` WHERE `addr` = '%s'",
                                DBA::escape($addr)
                        );
@@ -1235,7 +1235,7 @@ class Contact
                }
 
                if (($contact['network'] == Protocol::DFRN) && !$contact['self'] && empty($contact['pending'])) {
-                       $poke_link = DI::baseUrl() . '/poke/?c=' . $contact['id'];
+                       $poke_link = 'contact/' . $contact['id'] . '/poke';
                }
 
                $contact_url = DI::baseUrl() . '/contact/' . $contact['id'];
@@ -1530,10 +1530,6 @@ class Contact
 
                if (empty($data)) {
                        $data = Probe::uri($url, "", $uid);
-                       // Ensure that there is a gserver entry
-                       if (!empty($data['baseurl']) && ($data['network'] != Protocol::PHANTOM)) {
-                               GServer::check($data['baseurl']);
-                       }
                }
 
                // Take the default values when probing failed
@@ -1546,6 +1542,14 @@ class Contact
                        return 0;
                }
 
+               if (!empty($data['baseurl'])) {
+                       $data['baseurl'] = GServer::cleanURL($data['baseurl']);
+               }
+
+               if (!empty($data['baseurl']) && empty($data['gsid'])) {
+                       $data['gsid'] = GServer::getID($data['baseurl']);
+               }
+
                if (!$contact_id && !empty($data['alias']) && ($data['alias'] != $url) && !$in_loop) {
                        $contact_id = self::getIdForURL($data["alias"], $uid, true, $default, true);
                }
@@ -1575,6 +1579,7 @@ class Contact
                                'confirm'   => $data['confirm'] ?? '',
                                'poco'      => $data['poco'] ?? '',
                                'baseurl'   => $data['baseurl'] ?? '',
+                               'gsid'      => $data['gsid'] ?? null,
                                'name-date' => DateTimeFormat::utcNow(),
                                'uri-date'  => DateTimeFormat::utcNow(),
                                'avatar-date' => DateTimeFormat::utcNow(),
@@ -1621,10 +1626,13 @@ class Contact
                                // Update the gcontact entry
                                if ($uid == 0) {
                                        GContact::updateFromPublicContactID($contact_id);
+                                       if (($data['network'] == Protocol::ACTIVITYPUB) && in_array(DI::config()->get('system', 'gcontact_discovery'), [GContact::DISCOVERY_DIRECT, GContact::DISCOVERY_RECURSIVE])) {
+                                               GContact::discoverFollowers($data['url']);
+                                       }
                                }
                        }
                } else {
-                       $fields = ['url', 'nurl', 'addr', 'alias', 'name', 'nick', 'keywords', 'location', 'about', 'avatar-date', 'baseurl'];
+                       $fields = ['url', 'nurl', 'addr', 'alias', 'name', 'nick', 'keywords', 'location', 'about', 'avatar-date', 'baseurl', 'gsid'];
                        $contact = DBA::selectFirst('contact', $fields, ['id' => $contact_id]);
 
                        // This condition should always be true
@@ -1638,7 +1646,7 @@ class Contact
                                'updated' => DateTimeFormat::utcNow()
                        ];
 
-                       $fields = ['addr', 'alias', 'name', 'nick', 'keywords', 'location', 'about', 'baseurl'];
+                       $fields = ['addr', 'alias', 'name', 'nick', 'keywords', 'location', 'about', 'baseurl', 'gsid'];
 
                        foreach ($fields as $field) {
                                $updated[$field] = ($data[$field] ?? '') ?: $contact[$field];
@@ -1911,7 +1919,7 @@ class Contact
         * @param int    $cid    Contact id
         * @param bool   $force  force picture update
         *
-        * @return array Returns array of the different avatar sizes
+        * @return void
         * @throws HTTPException\InternalServerErrorException
         * @throws HTTPException\NotFoundException
         * @throws \ImagickException
@@ -1920,8 +1928,7 @@ class Contact
        {
                $contact = DBA::selectFirst('contact', ['avatar', 'photo', 'thumb', 'micro', 'nurl'], ['id' => $cid, 'self' => false]);
                if (!DBA::isResult($contact)) {
-                       Logger::error('Contact not found', ['cid' => $cid]);
-                       throw new HTTPException\NotFoundException('Contact not found');
+                       return;
                }
 
                $data = [
@@ -1952,12 +1959,8 @@ class Contact
                                                DBA::update('contact', $fields, ['id' => $pcontact['id']]);
                                        }
                                }
-
-                               return $photos;
                        }
                }
-
-               return $data;
        }
 
        /**
@@ -2059,6 +2062,7 @@ class Contact
 
                        Worker::add(PRIORITY_HIGH, 'MergeContact', $first, $duplicate['id'], $uid);
                }
+               DBA::close($duplicates);
                Logger::info('Duplicates handled', ['uid' => $uid, 'nurl' => $nurl]);
                return true;
        }
@@ -2081,9 +2085,9 @@ class Contact
                // These fields aren't updated by this routine:
                // 'xmpp', 'sensitive'
 
-               $fields = ['uid', 'avatar', 'name', 'nick', 'location', 'keywords', 'about',
+               $fields = ['uid', 'avatar', 'name', 'nick', 'location', 'keywords', 'about', 'subscribe',
                        'unsearchable', 'url', 'addr', 'batch', 'notify', 'poll', 'request', 'confirm', 'poco',
-                       'network', 'alias', 'baseurl', 'forum', 'prv', 'contact-type', 'pubkey'];
+                       'network', 'alias', 'baseurl', 'gsid', 'forum', 'prv', 'contact-type', 'pubkey'];
                $contact = DBA::selectFirst('contact', $fields, ['id' => $id]);
                if (!DBA::isResult($contact)) {
                        return false;
@@ -2416,6 +2420,7 @@ class Contact
                                'nick'    => $ret['nick'],
                                'network' => $ret['network'],
                                'baseurl' => $ret['baseurl'],
+                               'gsid'    => $ret['gsid'] ?? null,
                                'protocol' => $protocol,
                                'pubkey'  => $ret['pubkey'],
                                'rel'     => $new_relation,
@@ -2458,7 +2463,7 @@ class Contact
                                $item['body'] = '';
                                $item['title'] = '';
                                $item['guid'] = '';
-                               $item['tag'] = '';
+                               $item['uri-id'] = 0;
                                $item['attach'] = '';
 
                                $slap = OStatus::salmon($item, $owner);
@@ -2734,6 +2739,7 @@ class Contact
                                );
                        }
                }
+               DBA::close($contacts);
        }
 
        /**