X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FUser.php;h=7345dc7f94ad68aa31277d4a9a21ad4d0a21d00e;hb=fbd8052d05fda7a967d8440574d2b5013d4e7be1;hp=e784fd9e9a7278ec8c49955bcdeb5ad94588facc;hpb=3ed726bbcc2b60799f8af9475ebd456ad6738c2b;p=quix0rs-gnu-social.git diff --git a/classes/User.php b/classes/User.php index e784fd9e9a..7345dc7f94 100644 --- a/classes/User.php +++ b/classes/User.php @@ -875,4 +875,45 @@ 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')) { + + $user = null; + + $nickname = common_config('singleuser', 'nickname'); + + if (!empty($nickname)) { + $user = User::staticGet('nickname', $nickname); + } + + // if there was no nickname or no user by that nickname, + // try the site owner. + + if (empty($user)) { + $user = User::siteOwner(); + } + + if (!empty($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.')); + } + } }