]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/User.php
Merge pull request #10845 from MrPetovan/bug/10844-unfollow-errors
[friendica.git] / src / Model / User.php
index 78ef3085a6056f37efb6fc9bd60ba89f73d6cfc9..e27a950adb57f609039f93e7ad5b5ff85f16d446 100644 (file)
@@ -149,16 +149,24 @@ class User
                $system['page-flags'] = User::PAGE_FLAGS_SOAPBOX;
                $system['account-type'] = $system['contact-type'];
                $system['guid'] = '';
-               $system['nickname'] = $system['nick'];
-               $system['pubkey'] = $system['pubkey'];
+               $system['picdate'] = '';
+               $system['theme'] = '';
+               $system['publish'] = false;
+               $system['net-publish'] = false;
+               $system['hide-friends'] = true;
+               $system['prv_keywords'] = '';
+               $system['pub_keywords'] = '';
+               $system['address'] = '';
                $system['locality'] = '';
                $system['region'] = '';
+               $system['postal-code'] = '';
                $system['country-name'] = '';
-               $system['net-publish'] = false;
+               $system['homepage'] = DI::baseUrl()->get();
+               $system['dob'] = '0000-00-00';
 
                // Ensure that the user contains data
-               $user = DBA::selectFirst('user', ['prvkey'], ['uid' => 0]);
-               if (empty($user['prvkey'])) {
+               $user = DBA::selectFirst('user', ['prvkey', 'guid'], ['uid' => 0]);
+               if (empty($user['prvkey']) || empty($user['guid'])) {
                        $fields = [
                                'username' => $system['name'],
                                'nickname' => $system['nick'],
@@ -167,12 +175,17 @@ class User
                                'prvkey' => $system['prvkey'],
                                'spubkey' => $system['spubkey'],
                                'sprvkey' => $system['sprvkey'],
+                               'guid' => System::createUUID(),
                                'verified' => true,
                                'page-flags' => User::PAGE_FLAGS_SOAPBOX,
                                'account-type' => User::ACCOUNT_TYPE_RELAY,
                        ];
 
                        DBA::update('user', $fields, ['uid' => 0]);
+
+                       $system['guid'] = $fields['guid'];
+               } else {
+                       $system['guid'] = $user['guid'];
                }
 
                return $system;
@@ -221,7 +234,7 @@ class User
                $system['closeness'] = 0;
                $system['baseurl'] = DI::baseUrl();
                $system['gsid'] = GServer::getID($system['baseurl']);
-               DBA::insert('contact', $system);
+               Contact::insert($system);
        }
 
        /**
@@ -827,6 +840,52 @@ class User
                return false;
        }
 
+       /**
+        * Get avatar link for given user
+        *
+        * @param array  $user
+        * @param string $size One of the Proxy::SIZE_* constants
+        * @return string avatar link
+        * @throws Exception
+        */
+       public static function getAvatarUrl(array $user, string $size = ''):string
+       {
+               if (empty($user['nickname'])) {
+                       DI::logger()->warning('Missing user nickname key', ['trace' => System::callstack(20)]);
+               }
+
+               $url = DI::baseUrl() . '/photo/';
+
+               switch ($size) {
+                       case Proxy::SIZE_MICRO:
+                               $url .= 'micro/';
+                               $scale = 6;
+                               break;
+                       case Proxy::SIZE_THUMB:
+                               $url .= 'avatar/';
+                               $scale = 5;
+                               break;
+                       default:
+                               $url .= 'profile/';
+                               $scale = 4;
+                               break;
+               }
+
+               $updated =  '';
+               $imagetype = IMAGETYPE_JPEG;
+
+               $photo = Photo::selectFirst(['type', 'created', 'edited', 'updated'], ["scale" => $scale, 'uid' => $user['uid'], 'profile' => true]);
+               if (!empty($photo)) {
+                       $updated = max($photo['created'], $photo['edited'], $photo['updated']);
+
+                       if (in_array($photo['type'], ['image/png', 'image/gif'])) {
+                               $imagetype = IMAGETYPE_PNG;
+                       }
+               }
+
+               return $url . $user['nickname'] . image_type_to_extension($imagetype) . ($updated ? '?ts=' . strtotime($updated) : '');
+       }
+
        /**
         * Catch-all user creation function
         *
@@ -1041,8 +1100,8 @@ class User
                $insert_result = DBA::insert('profile', [
                        'uid' => $uid,
                        'name' => $username,
-                       'photo' => DI::baseUrl() . "/photo/profile/{$uid}.jpg",
-                       'thumb' => DI::baseUrl() . "/photo/avatar/{$uid}.jpg",
+                       'photo' => self::getAvatarUrl($user),
+                       'thumb' => self::getAvatarUrl($user, Proxy::SIZE_THUMB),
                        'publish' => $publish,
                        'net-publish' => $netpublish,
                ]);
@@ -1085,7 +1144,7 @@ class User
                        $photo_failure = false;
 
                        $filename = basename($photo);
-                       $curlResult = DI::httpRequest()->get($photo);
+                       $curlResult = DI::httpClient()->get($photo);
                        if ($curlResult->isSuccess()) {
                                $img_str = $curlResult->getBody();
                                $type = $curlResult->getContentType();
@@ -1572,8 +1631,8 @@ class User
        /**
         * Check if the given user id has delegations or is delegated
         *
-        * @param int $uid 
-        * @return bool 
+        * @param int $uid
+        * @return bool
         */
        public static function hasIdentities(int $uid):bool
        {
@@ -1594,7 +1653,7 @@ class User
                        return true;
                }
 
-               if (DBA::exists('manage', ['muid' => $uid])) {
+               if (DBA::exists('manage', ['uid' => $uid])) {
                        return true;
                }