X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=src%2FModel%2FUser.php;h=a1d3bc65f851faf8d0a8e2a1da878a46095dd05c;hb=f81192b4c3838480154301ac25cbbbed58593380;hp=d774a6454aa5480edfcfd2543173b0cf77083c45;hpb=104ce7c64f364146985283dd6e16ad5b3d995e36;p=friendica.git diff --git a/src/Model/User.php b/src/Model/User.php index d774a6454a..a1d3bc65f8 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -127,7 +127,6 @@ class User case 'community': return User::ACCOUNT_TYPE_COMMUNITY; - } return null; } @@ -364,7 +363,7 @@ class User 'deny_cid' => '', 'deny_gid' => '', 'blockwall' => true, - 'hidewall' => true, + 'blocktags' => true, ]; User::update($fields, $uid); @@ -425,7 +424,7 @@ class User * @return array user * @throws Exception */ - public static function getFirstAdmin(array $fields = []) : array + public static function getFirstAdmin(array $fields = []): array { if (!empty(DI::config()->get('config', 'admin_nickname'))) { return self::getByNickname(DI::config()->get('config', 'admin_nickname'), $fields); @@ -560,22 +559,88 @@ class User return $default_circle; } -/** - * Fetch the language code from the given user. If the code is invalid, return the system language - * - * @param integer $uid User-Id - * @return string - */ + /** + * Fetch the language code from the given user. If the code is invalid, return the system language + * + * @param integer $uid User-Id + * @return string + */ public static function getLanguageCode(int $uid): string { - $owner = self::getOwnerDataById($uid); - $languages = DI::l10n()->getAvailableLanguages(true); - if (in_array($owner['language'], array_keys($languages))) { - $language = $owner['language']; - } else { - $language = DI::config()->get('system', 'language'); + $owner = self::getOwnerDataById($uid); + $language = DI::l10n()->toISO6391($owner['language']); + if (in_array($language, array_keys(DI::l10n()->getLanguageCodes()))) { + return $language; } - return $language; + return DI::l10n()->toISO6391(DI::config()->get('system', 'language')); + } + + /** + * Fetch the wanted languages for a given user + * + * @param integer $uid + * @return array + */ + public static function getWantedLanguages(int $uid): array + { + return DI::pConfig()->get($uid, 'channel', 'languages', [User::getLanguageCode($uid)]) ?? []; + } + + /** + * Get a list of all languages that are used by the users + * + * @return array + */ + public static function getLanguages(): array + { + $cachekey = 'user:getLanguages'; + $languages = DI::cache()->get($cachekey); + if (!is_null($languages)) { + return $languages; + } + + $supported = array_keys(DI::l10n()->getLanguageCodes()); + $languages = []; + $uids = []; + + $condition = ["`verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired` AND `uid` > ?", 0]; + + $abandon_days = intval(DI::config()->get('system', 'account_abandon_days')); + if (!empty($abandon_days)) { + $condition = DBA::mergeConditions($condition, ["`last-activity` > ?", DateTimeFormat::utc('now - ' . $abandon_days . ' days')]); + } + + $users = DBA::select('user', ['uid', 'language'], $condition); + while ($user = DBA::fetch($users)) { + $uids[] = $user['uid']; + $code = DI::l10n()->toISO6391($user['language']); + if (!in_array($code, $supported)) { + continue; + } + $languages[$code] = $code; + } + DBA::close($users); + + $channels = DBA::select('pconfig', ['uid', 'v'], ["`cat` = ? AND `k` = ? AND `v` != ?", 'channel', 'languages', '']); + while ($channel = DBA::fetch($channels)) { + if (!in_array($channel['uid'], $uids)) { + continue; + } + $values = unserialize($channel['v']); + if (!empty($values) && is_array($values)) { + foreach ($values as $language) { + $language = DI::l10n()->toISO6391($language); + $languages[$language] = $language; + } + } + } + DBA::close($channels); + + ksort($languages); + $languages = array_keys($languages); + DI::cache()->set($cachekey, $languages); + + return $languages; } /** @@ -1160,7 +1225,7 @@ class User throw new Exception(DI::l10n()->tt('Username should be at most %s character.', 'Username should be at most %s characters.', $username_max_length)); } - // So now we are just looking for a space in the full name. + // So now we are just looking for a space in the display name. $loose_reg = DI::config()->get('system', 'no_regfullname'); if (!$loose_reg) { $username = mb_convert_case($username, MB_CASE_TITLE, 'UTF-8'); @@ -1480,7 +1545,7 @@ class User Photo::delete(['uid' => $register['uid']]); return DBA::delete('user', ['uid' => $register['uid']]) && - Register::deleteByHash($register['hash']); + Register::deleteByHash($register['hash']); } /** @@ -1530,10 +1595,9 @@ class User You may also wish to add some basic information to your default profile (on the "Profiles" page) so that other people can easily find you. - We recommend setting your full name, adding a profile photo, - adding some profile "keywords" (very useful in making new friends) - and - perhaps what country you live in; if you do not wish to be more specific - than that. + We recommend adding a profile photo, adding some profile "keywords" + (very useful in making new friends) - and perhaps what country you live in; + if you do not wish to be more specific than that. We fully respect your right to privacy, and none of these items are necessary. If you are new and do not know anybody here, they may help @@ -1634,10 +1698,9 @@ class User You may also wish to add some basic information to your default profile ' . "\x28" . 'on the "Profiles" page' . "\x29" . ' so that other people can easily find you. - We recommend setting your full name, adding a profile photo, - adding some profile "keywords" ' . "\x28" . 'very useful in making new friends' . "\x29" . ' - and - perhaps what country you live in; if you do not wish to be more specific - than that. + We recommend adding a profile photo, adding some profile "keywords" ' . "\x28" . 'very useful + in making new friends' . "\x29" . ' - and perhaps what country you live in; if you do not wish + to be more specific than that. We fully respect your right to privacy, and none of these items are necessary. If you are new and do not know anybody here, they may help