]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/User.php
Merge pull request #10969 from MrPetovan/task/remove-private-contacts
[friendica.git] / src / Model / User.php
index f3f837eb2e6854a592587059c44d2fd5f027fdc7..736612b0d158eb45e35059d5574ea372587c839b 100644 (file)
@@ -481,13 +481,12 @@ class User
        /**
         * Returns the default group for a given user and network
         *
-        * @param int    $uid     User id
-        * @param string $network network name
+        * @param int $uid User id
         *
         * @return int group id
         * @throws Exception
         */
-       public static function getDefaultGroup($uid, $network = '')
+       public static function getDefaultGroup($uid)
        {
                $user = DBA::selectFirst('user', ['def_gid'], ['uid' => $uid]);
                if (DBA::isResult($user)) {
@@ -499,26 +498,6 @@ class User
                return $default_group;
        }
 
-
-       /**
-        * Authenticate a user with a clear text password
-        *
-        * @param mixed  $user_info
-        * @param string $password
-        * @param bool   $third_party
-        * @return int|boolean
-        * @deprecated since version 3.6
-        * @see        User::getIdFromPasswordAuthentication()
-        */
-       public static function authenticate($user_info, $password, $third_party = false)
-       {
-               try {
-                       return self::getIdFromPasswordAuthentication($user_info, $password, $third_party);
-               } catch (Exception $ex) {
-                       return false;
-               }
-       }
-
        /**
         * Authenticate a user with a clear text password
         *
@@ -706,7 +685,7 @@ class User
        {
                $cache = new CacheItemPool();
                $cache->changeConfig([
-                       'cacheDirectory' => get_temppath() . '/password-exposed-cache/',
+                       'cacheDirectory' => System::getTempPath() . '/password-exposed-cache/',
                ]);
 
                try {
@@ -841,14 +820,19 @@ class User
        }
 
        /**
-        * Get avatar link for given user id
+        * Get avatar link for given user
         *
-        * @param integer $uid     user id
-        * @param string  $size    One of the ProxyUtils::SIZE_* constants
+        * @param array  $user
+        * @param string $size One of the Proxy::SIZE_* constants
         * @return string avatar link
+        * @throws Exception
         */
-       public static function getAvatarUrlForId(int $uid, string $size = ''):string
+       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) {
@@ -869,26 +853,16 @@ class User
                $updated =  '';
                $imagetype = IMAGETYPE_JPEG;
 
-               $photo = Photo::selectFirst(['type', 'created', 'edited', 'updated'], ["scale" => $scale, 'uid' => $uid, 'profile' => true]);
+               $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']);
 
-                       switch ($photo['type']) {
-                               case 'image/png':
-                                       $imagetype = IMAGETYPE_PNG;
-                                       break;
-
-                               case 'image/gif':
-                                       $imagetype = IMAGETYPE_PNG;
-                                       break;
-
-                               default:
-                                       $imagetype = IMAGETYPE_JPEG;
-                                       break;
+                       if (in_array($photo['type'], ['image/png', 'image/gif'])) {
+                               $imagetype = IMAGETYPE_PNG;
                        }
                }
 
-               return $url . $uid . image_type_to_extension($imagetype) . ($updated ? '?ts=' . strtotime($updated) : '');
+               return $url . $user['nickname'] . image_type_to_extension($imagetype) . ($updated ? '?ts=' . strtotime($updated) : '');
        }
 
        /**
@@ -916,18 +890,18 @@ class User
 
                $using_invites = DI::config()->get('system', 'invitation_only');
 
-               $invite_id  = !empty($data['invite_id'])  ? Strings::escapeTags(trim($data['invite_id']))  : '';
-               $username   = !empty($data['username'])   ? Strings::escapeTags(trim($data['username']))   : '';
-               $nickname   = !empty($data['nickname'])   ? Strings::escapeTags(trim($data['nickname']))   : '';
-               $email      = !empty($data['email'])      ? Strings::escapeTags(trim($data['email']))      : '';
-               $openid_url = !empty($data['openid_url']) ? Strings::escapeTags(trim($data['openid_url'])) : '';
-               $photo      = !empty($data['photo'])      ? Strings::escapeTags(trim($data['photo']))      : '';
-               $password   = !empty($data['password'])   ? trim($data['password'])           : '';
-               $password1  = !empty($data['password1'])  ? trim($data['password1'])          : '';
-               $confirm    = !empty($data['confirm'])    ? trim($data['confirm'])            : '';
+               $invite_id  = !empty($data['invite_id'])  ? trim($data['invite_id'])  : '';
+               $username   = !empty($data['username'])   ? trim($data['username'])   : '';
+               $nickname   = !empty($data['nickname'])   ? trim($data['nickname'])   : '';
+               $email      = !empty($data['email'])      ? trim($data['email'])      : '';
+               $openid_url = !empty($data['openid_url']) ? trim($data['openid_url']) : '';
+               $photo      = !empty($data['photo'])      ? trim($data['photo'])      : '';
+               $password   = !empty($data['password'])   ? trim($data['password'])   : '';
+               $password1  = !empty($data['password1'])  ? trim($data['password1'])  : '';
+               $confirm    = !empty($data['confirm'])    ? trim($data['confirm'])    : '';
                $blocked    = !empty($data['blocked']);
                $verified   = !empty($data['verified']);
-               $language   = !empty($data['language'])   ? Strings::escapeTags(trim($data['language']))   : 'en';
+               $language   = !empty($data['language'])   ? trim($data['language'])   : 'en';
 
                $netpublish = $publish = !empty($data['profile_publish_reg']);
 
@@ -984,7 +958,7 @@ class User
                $username_max_length = max(1, min(64, intval(DI::config()->get('system', 'username_max_length', 48))));
 
                if ($username_min_length > $username_max_length) {
-                       Logger::log(DI::l10n()->t('system.username_min_length (%s) and system.username_max_length (%s) are excluding each other, swapping values.', $username_min_length, $username_max_length), Logger::WARNING);
+                       Logger::error(DI::l10n()->t('system.username_min_length (%s) and system.username_max_length (%s) are excluding each other, swapping values.', $username_min_length, $username_max_length));
                        $tmp = $username_min_length;
                        $username_min_length = $username_max_length;
                        $username_max_length = $tmp;
@@ -1105,8 +1079,8 @@ class User
                $insert_result = DBA::insert('profile', [
                        'uid' => $uid,
                        'name' => $username,
-                       'photo' => self::getAvatarUrlForId($uid),
-                       'thumb' => self::getAvatarUrlForId($uid, Proxy::SIZE_THUMB),
+                       'photo' => self::getAvatarUrl($user),
+                       'thumb' => self::getAvatarUrl($user, Proxy::SIZE_THUMB),
                        'publish' => $publish,
                        'net-publish' => $netpublish,
                ]);
@@ -1166,7 +1140,10 @@ class User
 
                                $resource_id = Photo::newResource();
 
-                               $r = Photo::store($Image, $uid, 0, $resource_id, $filename, DI::l10n()->t('Profile Photos'), 4);
+                               // Not using Photo::PROFILE_PHOTOS here, so that it is discovered as translateble string
+                               $profile_album = DI::l10n()->t('Profile Photos');
+
+                               $r = Photo::store($Image, $uid, 0, $resource_id, $filename, $profile_album, 4);
 
                                if ($r === false) {
                                        $photo_failure = true;
@@ -1174,7 +1151,7 @@ class User
 
                                $Image->scaleDown(80);
 
-                               $r = Photo::store($Image, $uid, 0, $resource_id, $filename, DI::l10n()->t('Profile Photos'), 5);
+                               $r = Photo::store($Image, $uid, 0, $resource_id, $filename, $profile_album, 5);
 
                                if ($r === false) {
                                        $photo_failure = true;
@@ -1182,14 +1159,14 @@ class User
 
                                $Image->scaleDown(48);
 
-                               $r = Photo::store($Image, $uid, 0, $resource_id, $filename, DI::l10n()->t('Profile Photos'), 6);
+                               $r = Photo::store($Image, $uid, 0, $resource_id, $filename, $profile_album, 6);
 
                                if ($r === false) {
                                        $photo_failure = true;
                                }
 
                                if (!$photo_failure) {
-                                       Photo::update(['profile' => 1], ['resource-id' => $resource_id]);
+                                       Photo::update(['profile' => true, 'photo-type' => Photo::USER_AVATAR], ['resource-id' => $resource_id]);
                                }
                        }
 
@@ -1519,7 +1496,7 @@ class User
                        return false;
                }
 
-               Logger::log('Removing user: ' . $uid);
+               Logger::notice('Removing user', ['user' => $uid]);
 
                $user = DBA::selectFirst('user', [], ['uid' => $uid]);