]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/User.php
Replace reference to post plink by author base URL
[friendica.git] / src / Model / User.php
index d6a72fbfe9256b11e9ed027a2f6f16e7b4277eb4..af7a81a15dccc4a2ad22879d68beae7cb5eea192 100644 (file)
@@ -37,6 +37,7 @@ use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Module;
 use Friendica\Network\HTTPClient\Client\HttpClientAccept;
+use Friendica\Network\HTTPException\InternalServerErrorException;
 use Friendica\Security\TwoFactor\Model\AppSpecificPassword;
 use Friendica\Network\HTTPException;
 use Friendica\Object\Image;
@@ -132,6 +133,17 @@ class User
                return null;
        }
 
+       /**
+        * Get the Uri-Id of the system account
+        *
+        * @return integer
+        */
+       public static function getSystemUriId(): int
+       {
+               $system = self::getSystemAccount();
+               return $system['uri-id'] ?? 0;
+       }
+
        /**
         * Fetch the system account
         *
@@ -483,7 +495,7 @@ class User
        }
 
        /**
-        * Returns the default circle for a given user and network
+        * Returns the default circle for a given user
         *
         * @param int $uid User id
         *
@@ -502,6 +514,24 @@ class User
                return $default_circle;
        }
 
+       /**
+        * Returns the default circle for groups for a given user
+        *
+        * @param int $uid User id
+        *
+        * @return int circle id
+        * @throws Exception
+        */
+       public static function getDefaultGroupCircle(int $uid): int
+       {
+               $default_circle = DI::pConfig()->get($uid, 'system', 'default-group-gid');
+               if (empty($default_circle)) {
+                       $default_circle = self::getDefaultCircle($uid);
+               }
+
+               return $default_circle;
+       }
+
        /**
         * Authenticate a user with a clear text password
         *
@@ -851,6 +881,20 @@ class User
                ]);
        }
 
+       /**
+        * Returns if the given uid is valid and a moderator
+        *
+        * @param int $uid
+        *
+        * @return bool
+        * @throws Exception
+        */
+       public static function isModerator(int $uid): bool
+       {
+               // @todo Replace with a moderator check in the future
+               return self::isSiteAdmin($uid);
+       }
+
        /**
         * Checks if a nickname is in the list of the forbidden nicknames
         *
@@ -1208,6 +1252,11 @@ class User
 
                DBA::update('user', $fields, ['uid' => $uid]);
 
+               $def_gid_groups = Circle::create($uid, DI::l10n()->t('Groups'));
+               if ($def_gid_groups) {
+                       DI::pConfig()->set($uid, 'system', 'default-group-gid', $def_gid_groups);
+               }
+
                // if we have no OpenID photo try to look up an avatar
                if (!strlen($photo)) {
                        $photo = Network::lookupAvatarByEmail($email);
@@ -1280,33 +1329,18 @@ class User
        /**
         * Update a user entry and distribute the changes if needed
         *
-        * @param array $fields
+        * @param array   $fields
         * @param integer $uid
         * @return boolean
+        * @throws Exception
         */
        public static function update(array $fields, int $uid): bool
        {
-               $old_owner = self::getOwnerDataById($uid);
-               if (empty($old_owner)) {
-                       return false;
-               }
-
                if (!DBA::update('user', $fields, ['uid' => $uid])) {
                        return false;
                }
 
-               $update = Contact::updateSelfFromUserID($uid);
-
-               $owner = self::getOwnerDataById($uid);
-               if (empty($owner)) {
-                       return false;
-               }
-
-               if ($old_owner['name'] != $owner['name']) {
-                       Profile::update(['name' => $owner['name']], $uid);
-               }
-
-               if ($update) {
+               if (Contact::updateSelfFromUserID($uid)) {
                        Profile::publishUpdate($uid);
                }