]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/User.php
Merge pull request #10116 from mexon/mat/addon-console-command
[friendica.git] / src / Model / User.php
index ca2878746207efd3248ac8080f2f938fd0aba0ec..7204fd0ac8675600abf8d42293882074eade241d 100644 (file)
@@ -34,13 +34,14 @@ use Friendica\Core\System;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\DI;
-use Friendica\Model\TwoFactor\AppSpecificPassword;
+use Friendica\Security\TwoFactor\Model\AppSpecificPassword;
 use Friendica\Network\HTTPException;
 use Friendica\Object\Image;
 use Friendica\Util\Crypto;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Images;
 use Friendica\Util\Network;
+use Friendica\Util\Proxy;
 use Friendica\Util\Strings;
 use Friendica\Worker\Delivery;
 use ImagickException;
@@ -96,6 +97,7 @@ class User
        const ACCOUNT_TYPE_NEWS =         2;
        const ACCOUNT_TYPE_COMMUNITY =    3;
        const ACCOUNT_TYPE_RELAY =        4;
+       const ACCOUNT_TYPE_DELETED =    127;
        /**
         * @}
         */
@@ -192,11 +194,12 @@ class User
                $system['name'] = 'System Account';
                $system['addr'] = $system_actor_name . '@' . DI::baseUrl()->getHostname();
                $system['nick'] = $system_actor_name;
-               $system['avatar'] = DI::baseUrl() . Contact::DEFAULT_AVATAR_PHOTO;
-               $system['photo'] = DI::baseUrl() . Contact::DEFAULT_AVATAR_PHOTO;
-               $system['thumb'] = DI::baseUrl() . Contact::DEFAULT_AVATAR_THUMB;
-               $system['micro'] = DI::baseUrl() . Contact::DEFAULT_AVATAR_MICRO;
                $system['url'] = DI::baseUrl() . '/friendica';
+
+               $system['avatar'] = $system['photo'] = Contact::getDefaultAvatar($system, Proxy::SIZE_SMALL);
+               $system['thumb'] = Contact::getDefaultAvatar($system, Proxy::SIZE_THUMB);
+               $system['micro'] = Contact::getDefaultAvatar($system, Proxy::SIZE_MICRO);
+
                $system['nurl'] = Strings::normaliseLink($system['url']);
                $system['pubkey'] = $keys['pubkey'];
                $system['prvkey'] = $keys['prvkey'];
@@ -264,7 +267,7 @@ class User
         */
        public static function getById($uid, array $fields = [])
        {
-               return DBA::selectFirst('user', $fields, ['uid' => $uid]);
+               return !empty($uid) ? DBA::selectFirst('user', $fields, ['uid' => $uid]) : [];
        }
 
        /**
@@ -368,12 +371,12 @@ class User
        /**
         * Get owner data by user id
         *
-        * @param int $uid
-        * @param boolean $check_valid Test if data is invalid and correct it
+        * @param int     $uid
+        * @param boolean $repairMissing Repair the owner data if it's missing
         * @return boolean|array
         * @throws Exception
         */
-       public static function getOwnerDataById(int $uid, bool $check_valid = true)
+       public static function getOwnerDataById(int $uid, bool $repairMissing = true)
        {
                if ($uid == 0) {
                        return self::getSystemAccount();
@@ -385,7 +388,7 @@ class User
 
                $owner = DBA::selectFirst('owner-view', [], ['uid' => $uid]);
                if (!DBA::isResult($owner)) {
-                       if (!DBA::exists('user', ['uid' => $uid]) || !$check_valid) {
+                       if (!DBA::exists('user', ['uid' => $uid]) || !$repairMissing) {
                                return false;
                        }
                        Contact::createSelfFromUserId($uid);
@@ -396,7 +399,7 @@ class User
                        return false;
                }
 
-               if (!$check_valid) {
+               if (!$repairMissing) {
                        return $owner;
                }
 
@@ -1156,6 +1159,9 @@ class User
                        return false;
                }
 
+               // Delete the avatar
+               Photo::delete(['uid' => $register['uid']]);
+
                return DBA::delete('user', ['uid' => $register['uid']]) &&
                       Register::deleteByHash($register['hash']);
        }
@@ -1347,7 +1353,7 @@ class User
         */
        public static function remove(int $uid)
        {
-               if (!$uid) {
+               if (empty($uid)) {
                        return false;
                }