Fix code style

This commit is contained in:
Art4 2025-01-13 13:31:54 +00:00
parent d4697a17a3
commit 0e59dba914
102 changed files with 3038 additions and 2764 deletions

View file

@ -84,12 +84,12 @@ class User
* This will only be assigned to contacts, not to user accounts
* @{
*/
const ACCOUNT_TYPE_PERSON = 0;
const ACCOUNT_TYPE_PERSON = 0;
const ACCOUNT_TYPE_ORGANISATION = 1;
const ACCOUNT_TYPE_NEWS = 2;
const ACCOUNT_TYPE_COMMUNITY = 3;
const ACCOUNT_TYPE_RELAY = 4;
const ACCOUNT_TYPE_DELETED = 127;
const ACCOUNT_TYPE_NEWS = 2;
const ACCOUNT_TYPE_COMMUNITY = 3;
const ACCOUNT_TYPE_RELAY = 4;
const ACCOUNT_TYPE_DELETED = 127;
/**
* @}
*/
@ -150,42 +150,42 @@ class User
}
}
$system['name'] = App::PLATFORM . " '" . App::CODENAME . "' " . App::VERSION . '-' . DB_UPDATE_VERSION;
$system['uprvkey'] = $system['prvkey'];
$system['upubkey'] = $system['pubkey'];
$system['nickname'] = $system['nick'];
$system['page-flags'] = self::PAGE_FLAGS_SOAPBOX;
$system['name'] = App::PLATFORM . " '" . App::CODENAME . "' " . App::VERSION . '-' . DB_UPDATE_VERSION;
$system['uprvkey'] = $system['prvkey'];
$system['upubkey'] = $system['pubkey'];
$system['nickname'] = $system['nick'];
$system['page-flags'] = self::PAGE_FLAGS_SOAPBOX;
$system['account-type'] = $system['contact-type'];
$system['guid'] = '';
$system['picdate'] = '';
$system['theme'] = '';
$system['publish'] = false;
$system['net-publish'] = false;
$system['guid'] = '';
$system['picdate'] = '';
$system['theme'] = '';
$system['publish'] = false;
$system['net-publish'] = false;
$system['hide-friends'] = true;
$system['hidewall'] = true;
$system['hidewall'] = true;
$system['prv_keywords'] = '';
$system['pub_keywords'] = '';
$system['address'] = '';
$system['locality'] = '';
$system['region'] = '';
$system['postal-code'] = '';
$system['address'] = '';
$system['locality'] = '';
$system['region'] = '';
$system['postal-code'] = '';
$system['country-name'] = '';
$system['homepage'] = (string)DI::baseUrl();
$system['dob'] = '0000-00-00';
$system['homepage'] = (string)DI::baseUrl();
$system['dob'] = '0000-00-00';
// Ensure that the user contains data
$user = DBA::selectFirst('user', ['prvkey', 'guid', 'language'], ['uid' => 0]);
if (empty($user['prvkey']) || empty($user['guid'])) {
$fields = [
'username' => $system['name'],
'nickname' => $system['nick'],
'username' => $system['name'],
'nickname' => $system['nick'],
'register_date' => $system['created'],
'pubkey' => $system['pubkey'],
'prvkey' => $system['prvkey'],
'guid' => System::createUUID(),
'verified' => true,
'page-flags' => self::PAGE_FLAGS_SOAPBOX,
'account-type' => self::ACCOUNT_TYPE_RELAY,
'pubkey' => $system['pubkey'],
'prvkey' => $system['prvkey'],
'guid' => System::createUUID(),
'verified' => true,
'page-flags' => self::PAGE_FLAGS_SOAPBOX,
'account-type' => self::ACCOUNT_TYPE_RELAY,
];
DBA::update('user', $fields, ['uid' => 0]);
@ -349,12 +349,12 @@ class User
DI::pConfig()->set($uid, 'system', 'unlisted', true);
$fields = [
'allow_cid' => '',
'allow_gid' => $user['page-flags'] == self::PAGE_FLAGS_PRVGROUP ? '<' . Circle::FOLLOWERS . '>' : '',
'deny_cid' => '',
'deny_gid' => '',
'blockwall' => true,
'blocktags' => true,
'allow_cid' => '',
'allow_gid' => $user['page-flags'] == self::PAGE_FLAGS_PRVGROUP ? '<' . Circle::FOLLOWERS . '>' : '',
'deny_cid' => '',
'deny_gid' => '',
'blockwall' => true,
'blocktags' => true,
];
self::update($fields, $uid);
@ -490,12 +490,12 @@ class User
// Check if the returned data is valid, otherwise fix it. See issue #6122
// Check for correct url and normalised nurl
$url = DI::baseUrl() . '/profile/' . $owner['nickname'];
$url = DI::baseUrl() . '/profile/' . $owner['nickname'];
$repair = empty($owner['baseurl']) || empty($owner['network']) || ($owner['url'] != $url) || ($owner['nurl'] != Strings::normaliseLink($owner['url']));
if (!$repair) {
// Check if "addr" is present and correct
$addr = $owner['nickname'] . '@' . substr(DI::baseUrl(), strpos(DI::baseUrl(), '://') + 3);
$addr = $owner['nickname'] . '@' . substr(DI::baseUrl(), strpos(DI::baseUrl(), '://') + 3);
$repair = ($addr != $owner['addr']) || empty($owner['prvkey']) || empty($owner['pubkey']);
}
@ -628,7 +628,7 @@ class User
$users = DBA::select('user', ['uid', 'language'], $condition);
while ($user = DBA::fetch($users)) {
$uids[] = $user['uid'];
$code = DI::l10n()->toISO6391($user['language']);
$code = DI::l10n()->toISO6391($user['language']);
if (!in_array($code, $supported)) {
continue;
}
@ -644,7 +644,7 @@ class User
$values = unserialize($channel['v']);
if (!empty($values) && is_array($values)) {
foreach ($values as $language) {
$language = DI::l10n()->toISO6391($language);
$language = DI::l10n()->toISO6391($language);
$languages[$language] = $language;
}
}
@ -807,11 +807,11 @@ class User
} elseif (is_int($user_info) || is_string($user_info)) {
$fields = ['uid', 'nickname', 'password', 'legacy_password'];
if (is_int($user_info)) {
$condition = [
'uid' => $user_info,
$condition = [
'uid' => $user_info,
'account_expired' => false,
'account_removed' => false,
'verified' => true
'verified' => true
];
if (!$with_blocked) {
$condition = DBA::mergeConditions($condition, ['blocked' => false]);
@ -898,9 +898,9 @@ class User
return $passwordExposedChecker->passwordExposed($password) === PasswordExposed\Enums\PasswordStatus::EXPOSED;
} catch (Exception $e) {
DI::logger()->error('Password Exposed Exception: ' . $e->getMessage(), [
'code' => $e->getCode(),
'file' => $e->getFile(),
'line' => $e->getLine(),
'code' => $e->getCode(),
'file' => $e->getFile(),
'line' => $e->getLine(),
'trace' => $e->getTraceAsString()
]);
@ -1001,9 +1001,9 @@ class User
private static function updatePasswordHashed(int $uid, string $password_hashed): bool
{
$fields = [
'password' => $password_hashed,
'pwdreset' => null,
'pwdreset_time' => null,
'password' => $password_hashed,
'pwdreset' => null,
'pwdreset_time' => null,
'legacy_password' => false
];
return DBA::update('user', $fields, ['uid' => $uid]);
@ -1109,7 +1109,7 @@ class User
break;
}
$updated = '';
$updated = '';
$mimetype = '';
$photo = Photo::selectFirst(['type', 'created', 'edited', 'updated'], ["scale" => $scale, 'uid' => $user['uid'], 'profile' => true]);
@ -1214,14 +1214,14 @@ class User
throw new Exception(DI::l10n()->t('Invalid OpenID url'));
}
$_SESSION['register'] = 1;
$_SESSION['openid'] = $openid_url;
$_SESSION['openid'] = $openid_url;
$openid = new LightOpenID(DI::baseUrl()->getHost());
/** @phpstan-ignore-next-line $openid->identity is private, but will be set via magic setter */
$openid->identity = $openid_url;
$openid->identity = $openid_url;
$openid->returnUrl = DI::baseUrl() . '/openid';
$openid->required = ['namePerson/friendly', 'contact/email', 'namePerson'];
$openid->optional = ['namePerson/first', 'media/image/aspect11', 'media/image/default'];
$openid->required = ['namePerson/friendly', 'contact/email', 'namePerson'];
$openid->optional = ['namePerson/first', 'media/image/aspect11', 'media/image/default'];
try {
$authurl = $openid->authUrl();
} catch (Exception $e) {
@ -1246,7 +1246,7 @@ class User
if ($username_min_length > $username_max_length) {
DI::logger()->error(DI::l10n()->t('system.username_min_length (%s) and system.username_max_length (%s) are excluding each other, swapping values.', $username_min_length, $username_max_length));
$tmp = $username_min_length;
$tmp = $username_min_length;
$username_min_length = $username_max_length;
$username_max_length = $tmp;
}
@ -1303,7 +1303,7 @@ class User
throw new Exception(DI::l10n()->t('Nickname is already registered. Please choose another.'));
}
$new_password = strlen($password) ? $password : self::generateNewPassword();
$new_password = strlen($password) ? $password : self::generateNewPassword();
$new_password_encoded = self::hashPassword($new_password);
$return['password'] = $new_password;
@ -1317,24 +1317,24 @@ class User
$pubkey = $keys['pubkey'];
$insert_result = DBA::insert('user', [
'guid' => System::createUUID(),
'username' => $username,
'password' => $new_password_encoded,
'email' => $email,
'openid' => $openid_url,
'nickname' => $nickname,
'pubkey' => $pubkey,
'prvkey' => $prvkey,
'verified' => $verified,
'blocked' => $blocked,
'language' => $language,
'timezone' => 'UTC',
'register_date' => DateTimeFormat::utcNow(),
'guid' => System::createUUID(),
'username' => $username,
'password' => $new_password_encoded,
'email' => $email,
'openid' => $openid_url,
'nickname' => $nickname,
'pubkey' => $pubkey,
'prvkey' => $prvkey,
'verified' => $verified,
'blocked' => $blocked,
'language' => $language,
'timezone' => 'UTC',
'register_date' => DateTimeFormat::utcNow(),
'default-location' => ''
]);
if ($insert_result) {
$uid = DBA::lastInsertId();
$uid = DBA::lastInsertId();
$user = DBA::selectFirst('user', [], ['uid' => $uid]);
} else {
throw new Exception(DI::l10n()->t('An error occurred during registration. Please try again.'));
@ -1354,11 +1354,11 @@ class User
}
$insert_result = DBA::insert('profile', [
'uid' => $uid,
'name' => $username,
'photo' => self::getAvatarUrl($user),
'thumb' => self::getAvatarUrl($user, Proxy::SIZE_THUMB),
'publish' => $publish,
'uid' => $uid,
'name' => $username,
'photo' => self::getAvatarUrl($user),
'thumb' => self::getAvatarUrl($user, Proxy::SIZE_THUMB),
'publish' => $publish,
'net-publish' => $netpublish,
]);
if (!$insert_result) {
@ -1410,15 +1410,15 @@ class User
if ($curlResult->isSuccess()) {
DI::logger()->debug('Got picture', ['Content-Type' => $curlResult->getHeader('Content-Type'), 'url' => $photo]);
$img_str = $curlResult->getBodyString();
$type = $curlResult->getContentType();
$type = $curlResult->getContentType();
} else {
$img_str = '';
$type = '';
$type = '';
}
} catch (\Throwable $th) {
DI::logger()->notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
$img_str = '';
$type = '';
$type = '';
}
$image = new Image($img_str, $type, $photo);
@ -1496,7 +1496,7 @@ class User
* @param bool $block Block state (default is true)
*
* @return bool True, if successfully blocked
*
* @throws Exception
*/
public static function block(int $uid, bool $block = true): bool
@ -1601,21 +1601,21 @@ class User
public static function createMinimal(string $name, string $email, string $nick, string $lang = L10n::DEFAULT, string $avatar = ''): bool
{
if (empty($name) ||
empty($email) ||
empty($nick)) {
empty($email) ||
empty($nick)) {
throw new HTTPException\InternalServerErrorException('Invalid arguments.');
}
$result = self::create([
'username' => $name,
'email' => $email,
'email' => $email,
'nickname' => $nick,
'verified' => 1,
'language' => $lang,
'photo' => $avatar
'photo' => $avatar
]);
$user = $result['user'];
$user = $result['user'];
$preamble = Strings::deindent(DI::l10n()->t('
Dear %1$s,
the administrator of %2$s has set up an account for you.'));
@ -1647,7 +1647,7 @@ class User
Thank you and welcome to %4$s.'));
$preamble = sprintf($preamble, $user['username'], DI::config()->get('config', 'sitename'));
$body = sprintf($body, DI::baseUrl(), $user['nickname'], $result['password'], DI::config()->get('config', 'sitename'));
$body = sprintf($body, DI::baseUrl(), $user['nickname'], $result['password'], DI::config()->get('config', 'sitename'));
$email = DI::emailer()
->newSystemMail()
@ -1848,7 +1848,7 @@ class User
if (!$user['parent-uid']) {
// First add our own entry
$identities = [[
'uid' => $user['uid'],
'uid' => $user['uid'],
'username' => $user['username'],
'nickname' => $user['nickname']
]];
@ -1946,17 +1946,20 @@ class User
'active_users_weekly' => 0,
];
$userStmt = DBA::select('owner-view', ['uid', 'last-activity', 'last-item'],
$userStmt = DBA::select(
'owner-view',
['uid', 'last-activity', 'last-item'],
["`verified` AND `last-activity` > ? AND NOT `blocked`
AND NOT `account_removed` AND NOT `account_expired`",
DBA::NULL_DATETIME]);
DBA::NULL_DATETIME]
);
if (!DBA::isResult($userStmt)) {
return $statistics;
}
$halfyear = time() - (180 * 24 * 60 * 60);
$month = time() - (30 * 24 * 60 * 60);
$week = time() - (7 * 24 * 60 * 60);
$month = time() - (30 * 24 * 60 * 60);
$week = time() - (7 * 24 * 60 * 60);
while ($user = DBA::fetch($userStmt)) {
$statistics['total_users']++;
@ -1994,18 +1997,18 @@ class User
*/
public static function getList(int $start = 0, int $count = Pager::ITEMS_PER_PAGE, string $type = 'all', string $order = 'name', bool $descending = false)
{
$param = ['limit' => [$start, $count], 'order' => [$order => $descending]];
$param = ['limit' => [$start, $count], 'order' => [$order => $descending]];
$condition = [];
switch ($type) {
case 'active':
$condition['account_removed'] = false;
$condition['blocked'] = false;
$condition['blocked'] = false;
break;
case 'blocked':
$condition['account_removed'] = false;
$condition['blocked'] = true;
$condition['verified'] = true;
$condition['blocked'] = true;
$condition['verified'] = true;
break;
case 'removed':