X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FUser.php;h=92180a9fbc4d747b8809588cfdcd4040d4172d97;hb=749367e12f9742d7fd5ee028230fefa627599125;hp=27299e62e04f2db7fd0410da82fe8e2ef16f7aa5;hpb=d684a07fd93fe46c6195b0aeb56fcf01812ef60d;p=quix0rs-gnu-social.git diff --git a/classes/User.php b/classes/User.php index 27299e62e0..92180a9fbc 100644 --- a/classes/User.php +++ b/classes/User.php @@ -84,7 +84,8 @@ class User extends Memcached_DataObject function isSubscribed($other) { - return Subscription::exists($this->getProfile(), $other); + $profile = $this->getProfile(); + return $profile->isSubscribed($other); } // 'update' won't write key columns, so we have to do it ourselves. @@ -115,6 +116,16 @@ class User extends Memcached_DataObject return $result; } + /** + * Check whether the given nickname is potentially usable, or if it's + * excluded by any blacklists on this system. + * + * WARNING: INPUT IS NOT VALIDATED OR NORMALIZED. NON-NORMALIZED INPUT + * OR INVALID INPUT MAY LEAD TO FALSE RESULTS. + * + * @param string $nickname + * @return boolean true if clear, false if blacklisted + */ static function allowed_nickname($nickname) { // XXX: should already be validated for size, content, etc. @@ -418,8 +429,8 @@ class User extends Memcached_DataObject function mutuallySubscribed($other) { - return $this->isSubscribed($other) && - $other->isSubscribed($this); + $profile = $this->getProfile(); + return $profile->mutuallySubscribed($other); } function mutuallySubscribedUsers() @@ -482,17 +493,8 @@ class User extends Memcached_DataObject function blowFavesCache() { - $cache = common_memcache(); - if ($cache) { - // Faves don't happen chronologically, so we need to blow - // ;last cache, too - $cache->delete(common_cache_key('fave:ids_by_user:'.$this->id)); - $cache->delete(common_cache_key('fave:ids_by_user:'.$this->id.';last')); - $cache->delete(common_cache_key('fave:ids_by_user_own:'.$this->id)); - $cache->delete(common_cache_key('fave:ids_by_user_own:'.$this->id.';last')); - } $profile = $this->getProfile(); - $profile->blowFaveCount(); + $profile->blowFavesCache(); } function getSelfTags() @@ -884,4 +886,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.')); + } + } }