]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Contact.php
Merge pull request #4516 from annando/item-ordering
[friendica.git] / src / Model / Contact.php
index 1d31c6cb5b38f5a50a547f2d54b1e2fcb4aeb341..8a2be5e9ad2ef6ff3d07c9c83e7182c3e51286a6 100644 (file)
@@ -1032,7 +1032,7 @@ class Contact extends BaseObject
 
                                // Update the public contact (contact id = 0)
                                if ($uid != 0) {
-                                       $pcontact = dba::selectFirst('contact', ['id'], ['nurl' => $contact['nurl']]);
+                                       $pcontact = dba::selectFirst('contact', ['id'], ['nurl' => $contact['nurl'], 'uid' => 0]);
                                        if (DBM::is_result($pcontact)) {
                                                self::updateAvatar($avatar, 0, $pcontact['id'], $force);
                                        }
@@ -1365,6 +1365,7 @@ class Contact extends BaseObject
                $url = notags(trim($datarray['author-link']));
                $name = notags(trim($datarray['author-name']));
                $photo = notags(trim($datarray['author-avatar']));
+               $nick = '';
 
                if (is_object($item)) {
                        $rawtag = $item->get_item_tags(NAMESPACE_ACTIVITY,'actor');
@@ -1398,20 +1399,16 @@ class Contact extends BaseObject
                                intval(CONTACT_IS_FOLLOWER)
                        );
 
-                       $r = q("SELECT `id`, `network` FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `pending` = 1 LIMIT 1",
-                                       intval($importer['uid']),
-                                       dbesc($url)
-                       );
-                       if (DBM::is_result($r)) {
-                               $contact_record = $r[0];
-                               Contact::updateAvatar($photo, $importer["uid"], $contact_record["id"], true);
-                       }
+                       $contact_record = [
+                               'id' => dba::lastInsertId(),
+                               'network' => NETWORK_OSTATUS
+                       ];
+                       Contact::updateAvatar($photo, $importer["uid"], $contact_record["id"], true);
 
                        /// @TODO Encapsulate this into a function/method
-                       $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
-                               intval($importer['uid'])
-                       );
-                       if (DBM::is_result($r) && !in_array($r[0]['page-flags'], [PAGE_SOAPBOX, PAGE_FREELOVE, PAGE_COMMUNITY])) {
+                       $fields = ['uid', 'username', 'email', 'page-flags', 'notify-flags', 'language'];
+                       $user = dba::selectFirst('user', $fields, ['uid' => $importer['uid']]);
+                       if (DBM::is_result($user) && !in_array($user['page-flags'], [PAGE_SOAPBOX, PAGE_FREELOVE, PAGE_COMMUNITY])) {
                                // create notification
                                $hash = random_string();
 
@@ -1423,16 +1420,16 @@ class Contact extends BaseObject
 
                                Group::addMember(User::getDefaultGroup($importer['uid'], $contact_record["network"]), $contact_record['id']);
 
-                               if (($r[0]['notify-flags'] & NOTIFY_INTRO) &&
-                                       in_array($r[0]['page-flags'], [PAGE_NORMAL])) {
+                               if (($user['notify-flags'] & NOTIFY_INTRO) &&
+                                       in_array($user['page-flags'], [PAGE_NORMAL])) {
 
                                        notification([
                                                'type'         => NOTIFY_INTRO,
-                                               'notify_flags' => $r[0]['notify-flags'],
-                                               'language'     => $r[0]['language'],
-                                               'to_name'      => $r[0]['username'],
-                                               'to_email'     => $r[0]['email'],
-                                               'uid'          => $r[0]['uid'],
+                                               'notify_flags' => $user['notify-flags'],
+                                               'language'     => $user['language'],
+                                               'to_name'      => $user['username'],
+                                               'to_email'     => $user['email'],
+                                               'uid'          => $user['uid'],
                                                'link'             => System::baseUrl() . '/notifications/intro',
                                                'source_name'  => ((strlen(stripslashes($contact_record['name']))) ? stripslashes($contact_record['name']) : L10n::t('[Name Withheld]')),
                                                'source_link'  => $contact_record['url'],
@@ -1442,13 +1439,12 @@ class Contact extends BaseObject
                                        ]);
 
                                }
-                       } elseif (DBM::is_result($r) && in_array($r[0]['page-flags'], [PAGE_SOAPBOX, PAGE_FREELOVE, PAGE_COMMUNITY])) {
+                       } elseif (DBM::is_result($user) && in_array($user['page-flags'], [PAGE_SOAPBOX, PAGE_FREELOVE, PAGE_COMMUNITY])) {
                                q("UPDATE `contact` SET `pending` = 0 WHERE `uid` = %d AND `url` = '%s' AND `pending` LIMIT 1",
                                                intval($importer['uid']),
                                                dbesc($url)
                                );
                        }
-
                }
        }