]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/User.php
Merge branch '0.9.x' into 1.0.x
[quix0rs-gnu-social.git] / classes / User.php
index 259df7e2c3eb4b74b120df4a1a4413a5d9fdbd66..9188938b18e90da331380125559b4bc9dd60fdfa 100644 (file)
@@ -870,4 +870,35 @@ class User extends Memcached_DataObject
 
         return $owner;
     }
+
+    /**
+     * Pull the primary site account to use in single-user mode.
+     * If a valid user nickname is listed in 'singleuser':'nickname'
+     * in the config, this will be used; otherwise the site owner
+     * account is taken by default.
+     *
+     * @return User
+     * @throws ServerException if no valid single user account is present
+     * @throws ServerException if called when not in single-user mode
+     */
+    static function singleUser()
+    {
+        if (common_config('singleuser', 'enabled')) {
+            $nickname = common_config('singleuser', 'nickname');
+            if ($nickname) {
+                $user = User::staticGet('nickname', $nickname);
+            } else {
+                $user = User::siteOwner();
+            }
+            if ($user) {
+                return $user;
+            } else {
+                // TRANS: Server exception.
+                throw new ServerException(_('No single user defined for single-user mode.'));
+            }
+        } else {
+            // TRANS: Server exception.
+            throw new ServerException(_('Single-user mode code called when not enabled.'));
+        }
+    }
 }