]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Contact.php
Merge branch 'develop' into task/mod_hostxrd
[friendica.git] / src / Model / Contact.php
index ecbf7411c323b6931c0413ea2f35a29fcec93879..85d1bfe9adf0634ba313e9d02022f43ed1a8a9dd 100644 (file)
@@ -22,6 +22,7 @@ use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\OStatus;
 use Friendica\Protocol\PortableContact;
 use Friendica\Protocol\Salmon;
+use Friendica\Util\BaseURL;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use Friendica\Util\Strings;
@@ -1241,11 +1242,11 @@ class Contact extends BaseObject
 
                /// @todo Verify if we can't use Contact::getDetailsByUrl instead of the following
                // We first try the nurl (http://server.tld/nick), most common case
-               $contact = DBA::selectFirst('contact', ['id', 'avatar', 'updated'], ['nurl' => Strings::normaliseLink($url), 'uid' => $uid, 'deleted' => false]);
+               $contact = DBA::selectFirst('contact', ['id', 'avatar', 'updated', 'network'], ['nurl' => Strings::normaliseLink($url), 'uid' => $uid, 'deleted' => false]);
 
                // Then the addr (nick@server.tld)
                if (!DBA::isResult($contact)) {
-                       $contact = DBA::selectFirst('contact', ['id', 'avatar', 'updated'], ['addr' => $url, 'uid' => $uid, 'deleted' => false]);
+                       $contact = DBA::selectFirst('contact', ['id', 'avatar', 'updated', 'network'], ['addr' => $url, 'uid' => $uid, 'deleted' => false]);
                }
 
                // Then the alias (which could be anything)
@@ -1253,7 +1254,7 @@ class Contact extends BaseObject
                        // The link could be provided as http although we stored it as https
                        $ssl_url = str_replace('http://', 'https://', $url);
                        $condition = ['`alias` IN (?, ?, ?) AND `uid` = ? AND NOT `deleted`', $url, Strings::normaliseLink($url), $ssl_url, $uid];
-                       $contact = DBA::selectFirst('contact', ['id', 'avatar', 'updated'], $condition);
+                       $contact = DBA::selectFirst('contact', ['id', 'avatar', 'updated', 'network'], $condition);
                }
 
                if (DBA::isResult($contact)) {
@@ -1268,7 +1269,7 @@ class Contact extends BaseObject
                        }
 
                        // Update the contact in the background if needed but it is called by the frontend
-                       if ($update_contact && $no_update) {
+                       if ($update_contact && $no_update && in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
                                Worker::add(PRIORITY_LOW, "UpdateContact", $contact_id);
                        }
 
@@ -1316,7 +1317,7 @@ class Contact extends BaseObject
                        return 0;
                }
 
-               if (!$contact_id && ($data["alias"] != '') && ($data["alias"] != $url) && !$in_loop) {
+               if (!$contact_id && !empty($data['alias']) && ($data['alias'] != $url) && !$in_loop) {
                        $contact_id = self::getIdForURL($data["alias"], $uid, true, $default, true);
                }
 
@@ -1324,26 +1325,26 @@ class Contact extends BaseObject
                        $fields = [
                                'uid'       => $uid,
                                'created'   => DateTimeFormat::utcNow(),
-                               'url'       => $data["url"],
-                               'nurl'      => Strings::normaliseLink($data["url"]),
-                               'addr'      => $data["addr"],
-                               'alias'     => $data["alias"],
-                               'notify'    => $data["notify"],
-                               'poll'      => $data["poll"],
-                               'name'      => $data["name"],
-                               'nick'      => $data["nick"],
-                               'photo'     => $data["photo"],
-                               'keywords'  => $data["keywords"],
-                               'location'  => $data["location"],
-                               'about'     => $data["about"],
-                               'network'   => $data["network"],
-                               'pubkey'    => $data["pubkey"],
+                               'url'       => $data['url'],
+                               'nurl'      => Strings::normaliseLink($data['url']),
+                               'addr'      => defaults($data, 'addr', ''),
+                               'alias'     => defaults($data, 'alias', ''),
+                               'notify'    => defaults($data, 'notify', ''),
+                               'poll'      => defaults($data, 'poll', ''),
+                               'name'      => defaults($data, 'name', ''),
+                               'nick'      => defaults($data, 'nick', ''),
+                               'photo'     => defaults($data, 'photo', ''),
+                               'keywords'  => defaults($data, 'keywords', ''),
+                               'location'  => defaults($data, 'location', ''),
+                               'about'     => defaults($data, 'about', ''),
+                               'network'   => $data['network'],
+                               'pubkey'    => defaults($data, 'pubkey', ''),
                                'rel'       => self::SHARING,
-                               'priority'  => $data["priority"],
-                               'batch'     => $data["batch"],
-                               'request'   => $data["request"],
-                               'confirm'   => $data["confirm"],
-                               'poco'      => $data["poco"],
+                               'priority'  => defaults($data, 'priority', 0),
+                               'batch'     => defaults($data, 'batch', ''),
+                               'request'   => defaults($data, 'request', ''),
+                               'confirm'   => defaults($data, 'confirm', ''),
+                               'poco'      => defaults($data, 'poco', ''),
                                'name-date' => DateTimeFormat::utcNow(),
                                'uri-date'  => DateTimeFormat::utcNow(),
                                'avatar-date' => DateTimeFormat::utcNow(),
@@ -1373,13 +1374,13 @@ class Contact extends BaseObject
                        $gcontact = DBA::selectFirst('gcontact', ['location', 'about', 'keywords', 'gender'], ['nurl' => Strings::normaliseLink($data["url"])]);
                        if (DBA::isResult($gcontact)) {
                                // Only use the information when the probing hadn't fetched these values
-                               if ($data['keywords'] != '') {
+                               if (!empty($data['keywords'])) {
                                        unset($gcontact['keywords']);
                                }
-                               if ($data['location'] != '') {
+                               if (!empty($data['location'])) {
                                        unset($gcontact['location']);
                                }
-                               if ($data['about'] != '') {
+                               if (!empty($data['about'])) {
                                        unset($gcontact['about']);
                                }
                                DBA::update('contact', $gcontact, ['id' => $contact_id]);
@@ -1393,7 +1394,9 @@ class Contact extends BaseObject
                        }
                }
 
-               self::updateAvatar($data["photo"], $uid, $contact_id);
+               if (!empty($data['photo'])) {
+                       self::updateAvatar($data['photo'], $uid, $contact_id);
+               }
 
                $fields = ['url', 'nurl', 'addr', 'alias', 'name', 'nick', 'keywords', 'location', 'about', 'avatar-date', 'pubkey'];
                $contact = DBA::selectFirst('contact', $fields, ['id' => $contact_id]);
@@ -1404,36 +1407,36 @@ class Contact extends BaseObject
                }
 
                $updated = ['addr' => $data['addr'],
-                       'alias' => $data['alias'],
+                       'alias' => defaults($data, 'alias', ''),
                        'url' => $data['url'],
                        'nurl' => Strings::normaliseLink($data['url']),
                        'name' => $data['name'],
                        'nick' => $data['nick']];
 
-               if ($data['keywords'] != '') {
+               if (!empty($data['keywords'])) {
                        $updated['keywords'] = $data['keywords'];
                }
-               if ($data['location'] != '') {
+               if (!empty($data['location'])) {
                        $updated['location'] = $data['location'];
                }
 
                // Update the technical stuff as well - if filled
-               if ($data['notify'] != '') {
+               if (!empty($data['notify'])) {
                        $updated['notify'] = $data['notify'];
                }
-               if ($data['poll'] != '') {
+               if (!empty($data['poll'])) {
                        $updated['poll'] = $data['poll'];
                }
-               if ($data['batch'] != '') {
+               if (!empty($data['batch'])) {
                        $updated['batch'] = $data['batch'];
                }
-               if ($data['request'] != '') {
+               if (!empty($data['request'])) {
                        $updated['request'] = $data['request'];
                }
-               if ($data['confirm'] != '') {
+               if (!empty($data['confirm'])) {
                        $updated['confirm'] = $data['confirm'];
                }
-               if ($data['poco'] != '') {
+               if (!empty($data['poco'])) {
                        $updated['poco'] = $data['poco'];
                }
 
@@ -1442,7 +1445,7 @@ class Contact extends BaseObject
                        $updated['pubkey'] = $data['pubkey'];
                }
 
-               if (($data["addr"] != $contact["addr"]) || ($data["alias"] != $contact["alias"])) {
+               if (($data['addr'] != $contact['addr']) || (!empty($data['alias']) && ($data['alias'] != $contact['alias']))) {
                        $updated['uri-date'] = DateTimeFormat::utcNow();
                }
                if (($data["name"] != $contact["name"]) || ($data["nick"] != $contact["nick"])) {
@@ -1726,7 +1729,11 @@ class Contact extends BaseObject
                $ret = Probe::uri($contact['url'], $network, $uid, !$force);
 
                // If Probe::uri fails the network code will be different (mostly "feed" or "unkn")
-               if ((in_array($ret['network'], [Protocol::FEED, Protocol::PHANTOM])) && ($ret['network'] != $contact['network'])) {
+               if (in_array($ret['network'], [Protocol::FEED, Protocol::PHANTOM]) && ($ret['network'] != $contact['network'])) {
+                       return false;
+               }
+
+               if (!in_array($ret['network'], Protocol::NATIVE_SUPPORT)) {
                        return false;
                }
 
@@ -2003,7 +2010,7 @@ class Contact extends BaseObject
        public static function updateSslPolicy(array $contact, $new_policy)
        {
                $ssl_changed = false;
-               if ((intval($new_policy) == SSL_POLICY_SELFSIGN || $new_policy === 'self') && strstr($contact['url'], 'https:')) {
+               if ((intval($new_policy) == BaseURL::SSL_POLICY_SELFSIGN || $new_policy === 'self') && strstr($contact['url'], 'https:')) {
                        $ssl_changed = true;
                        $contact['url']     =   str_replace('https:', 'http:', $contact['url']);
                        $contact['request'] =   str_replace('https:', 'http:', $contact['request']);
@@ -2013,7 +2020,7 @@ class Contact extends BaseObject
                        $contact['poco']    =   str_replace('https:', 'http:', $contact['poco']);
                }
 
-               if ((intval($new_policy) == SSL_POLICY_FULL || $new_policy === 'full') && strstr($contact['url'], 'http:')) {
+               if ((intval($new_policy) == BaseURL::SSL_POLICY_FULL || $new_policy === 'full') && strstr($contact['url'], 'http:')) {
                        $ssl_changed = true;
                        $contact['url']     =   str_replace('http:', 'https:', $contact['url']);
                        $contact['request'] =   str_replace('http:', 'https:', $contact['request']);