]> 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 55bbb8b84136dbf52182e0d5ebd7575b989c95ec..e27a950adb57f609039f93e7ad5b5ff85f16d446 100644 (file)
@@ -149,12 +149,20 @@ 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', 'guid'], ['uid' => 0]);
@@ -226,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);
        }
 
        /**
@@ -832,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
         *
@@ -1046,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,
                ]);
@@ -1090,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();
@@ -1577,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
        {