]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Contact.php
Merge pull request #5109 from rabuzarus/20180522_-_frio_nav_about_instance
[friendica.git] / src / Model / Contact.php
index 60dec8b2891f9b9a532892ecb790355b138ce59c..03f5a36db1b4a4cab2d3fedefd21e15df69c8e4c 100644 (file)
@@ -206,6 +206,16 @@ class Contact extends BaseObject
                $fields['forum'] = $user['page-flags'] == PAGE_COMMUNITY;
                $fields['prv'] = $user['page-flags'] == PAGE_PRVGROUP;
 
+               // it seems as if ported accounts can have wrong values, so we make sure that now everything is fine.
+               $fields['url'] = System::baseUrl() . '/profile/' . $user['nickname'];
+               $fields['nurl'] = normalise_link($fields['url']);
+               $fields['addr'] = $user['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3);
+               $fields['request'] = System::baseUrl() . '/dfrn_request/' . $user['nickname'];
+               $fields['notify'] = System::baseUrl() . '/dfrn_notify/'  . $user['nickname'];
+               $fields['poll'] = System::baseUrl() . '/dfrn_poll/'    . $user['nickname'];
+               $fields['confirm'] = System::baseUrl() . '/dfrn_confirm/' . $user['nickname'];
+               $fields['poco'] = System::baseUrl() . '/poco/'         . $user['nickname'];
+
                $update = false;
 
                foreach ($fields as $field => $content) {
@@ -220,6 +230,11 @@ class Contact extends BaseObject
 
                        // Update the public contact as well
                        dba::update('contact', $fields, ['uid' => 0, 'nurl' => $self['nurl']]);
+
+                       // Update the profile
+                       $fields = ['photo' => System::baseUrl() . '/photo/profile/' .$uid . '.jpg',
+                               'thumb' => System::baseUrl() . '/photo/avatar/' . $uid .'.jpg'];
+                       dba::update('profile', $fields, ['uid' => $uid, 'is-default' => true]);
                }
        }
 
@@ -306,7 +321,9 @@ class Contact extends BaseObject
                         */
 
                        /// @todo Check for contact vitality via probing
-                       $expiry = $contact['term-date'] . ' + 32 days ';
+                       $archival_days = Config::get('system', 'archival_days', 32);
+
+                       $expiry = $contact['term-date'] . ' + ' . $archival_days . ' days ';
                        if (DateTimeFormat::utcNow() > DateTimeFormat::utc($expiry)) {
                                /* Relationship is really truly dead. archive them rather than
                                 * delete, though if the owner tries to unarchive them we'll start
@@ -343,9 +360,14 @@ class Contact extends BaseObject
                $fields = ['term-date' => NULL_DATE, 'archive' => false];
                dba::update('contact', $fields, ['id' => $contact['id']]);
 
-               if ($contact['url'] != '') {
+               if (!empty($contact['url'])) {
                        dba::update('contact', $fields, ['nurl' => normalise_link($contact['url'])]);
                }
+
+               if (!empty($contact['batch'])) {
+                       $condition = ['batch' => $contact['batch'], 'contact-type' => ACCOUNT_TYPE_RELAY];
+                       dba::update('contact', $fields, $condition);
+               }
        }
 
        /**
@@ -411,7 +433,7 @@ class Contact extends BaseObject
                // Fetch the data from the gcontact table
                if (!DBM::is_result($r)) {
                        $s = dba::p("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`, `gender`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, `community` AS `forum`, 0 AS `prv`, `community`, `contact-type`, `birthday`, 0 AS `self`
+                       `keywords`, `gender`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, 0 AS `forum`, 0 AS `prv`, `community`, `contact-type`, `birthday`, 0 AS `self`
                        FROM `gcontact` WHERE `nurl` = ?", normalise_link($url));
                        $r = dba::inArray($s);
                }
@@ -740,10 +762,11 @@ class Contact extends BaseObject
         * @param string  $url       Contact URL
         * @param integer $uid       The user id for the contact (0 = public contact)
         * @param boolean $no_update Don't update the contact
+        * @param array   $default   Default value for creating the contact when every else fails
         *
         * @return integer Contact ID
         */
-       public static function getIdForURL($url, $uid = 0, $no_update = false)
+       public static function getIdForURL($url, $uid = 0, $no_update = false, $default = [])
        {
                logger("Get contact data for url " . $url . " and user " . $uid . " - " . System::callstack(), LOGGER_DEBUG);
 
@@ -792,18 +815,48 @@ class Contact extends BaseObject
                $data = Probe::uri($url, "", $uid);
 
                // Last try in gcontact for unsupported networks
-               if (!in_array($data["network"], [NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA, NETWORK_PUMPIO, NETWORK_MAIL])) {
+               if (!in_array($data["network"], [NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA, NETWORK_PUMPIO, NETWORK_MAIL, NETWORK_FEED])) {
                        if ($uid != 0) {
                                return 0;
                        }
 
                        // Get data from the gcontact table
-                       $gcontact = dba::selectFirst('gcontact', ['name', 'nick', 'url', 'photo', 'addr', 'alias', 'network'], ['nurl' => normalise_link($url)]);
-                       if (!DBM::is_result($gcontact)) {
-                               return 0;
+                       $fields = ['name', 'nick', 'url', 'photo', 'addr', 'alias', 'network'];
+                       $contact = dba::selectFirst('gcontact', $fields, ['nurl' => normalise_link($url)]);
+                       if (!DBM::is_result($contact)) {
+                               $contact = dba::selectFirst('contact', $fields, ['nurl' => normalise_link($url)]);
+                       }
+
+                       if (!DBM::is_result($contact)) {
+                               $fields = ['url', 'addr', 'alias', 'notify', 'poll', 'name', 'nick',
+                                       'photo', 'keywords', 'location', 'about', 'network',
+                                       'priority', 'batch', 'request', 'confirm', 'poco'];
+                               $contact = dba::selectFirst('contact', $fields, ['addr' => $url]);
+                       }
+
+                       if (!DBM::is_result($contact)) {
+                               // The link could be provided as http although we stored it as https
+                               $ssl_url = str_replace('http://', 'https://', $url);
+                               $condition = ['alias' => [$url, normalise_link($url), $ssl_url]];
+                               $contact = dba::selectFirst('contact', $fields, $condition);
                        }
 
-                       $data = array_merge($data, $gcontact);
+                       if (!DBM::is_result($contact)) {
+                               $fields = ['url', 'addr', 'alias', 'notify', 'poll', 'name', 'nick',
+                                       'photo', 'network', 'priority', 'batch', 'request', 'confirm'];
+                               $condition = ['url' => [$url, normalise_link($url), $ssl_url]];
+                               $contact = dba::selectFirst('fcontact', $fields, $condition);
+                       }
+
+                       if (!empty($default)) {
+                               $contact = $default;
+                       }
+
+                       if (!DBM::is_result($contact)) {
+                               return 0;
+                       } else {
+                               $data = array_merge($data, $contact);
+                       }
                }
 
                if (!$contact_id && ($data["alias"] != '') && ($data["alias"] != $url)) {
@@ -1251,7 +1304,7 @@ class Contact extends BaseObject
 
                if (($network != '') && ($ret['network'] != $network)) {
                        logger('Expected network ' . $network . ' does not match actual network ' . $ret['network']);
-                       return result;
+                       return $result;
                }
 
                // check if we already have a contact
@@ -1470,6 +1523,11 @@ class Contact extends BaseObject
                        }
                        // send email notification to owner?
                } else {
+                       if (dba::exists('contact', ['nurl' => normalise_link($url), 'uid' => $importer['uid'], 'pending' => true])) {
+                               logger('ignoring duplicated connection request from pending contact ' . $url);
+                               return;
+                       }
+
                        // create contact record
                        q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `name`, `nick`, `photo`, `network`, `rel`,
                                `blocked`, `readonly`, `pending`, `writable`)