Moved profile about sections into their own table.

This commit is contained in:
flash 2025-02-08 23:20:53 +00:00
parent 8bb2400d3f
commit 372797c564
11 changed files with 218 additions and 108 deletions
public-legacy

View file

@ -7,8 +7,8 @@ use RuntimeException;
use Index\ByteFormat;
use Misuzu\Forum\ForumSignaturesData;
use Misuzu\Parsers\TextFormat;
use Misuzu\Profile\ProfileBackgroundAttach;
use Misuzu\Users\{User,UsersContext};
use Misuzu\Profile\{ProfileAboutData,ProfileBackgroundAttach};
use Misuzu\Users\{User,UserBirthdatesData};
use Misuzu\Users\Assets\UserAvatarAsset;
use Misuzu\Users\Assets\UserBackgroundAsset;
@ -80,6 +80,7 @@ $avatarAsset = new UserAvatarAsset($userInfo);
$backgroundInfo = $msz->profileCtx->backgrounds->getProfileBackground($userInfo);
$backgroundAsset = new UserBackgroundAsset($userInfo, $backgroundInfo);
$aboutInfo = $msz->profileCtx->about->getProfileAbout($userInfo);
$sigInfo = $msz->forumCtx->signatures->getSignature($userInfo);
if($isEditing) {
@ -140,24 +141,28 @@ if($isEditing) {
}
}
if(!empty($_POST['about']) && is_array($_POST['about'])) {
if(filter_has_var(INPUT_POST, 'about_body')) {
if(!$perms->edit_about) {
$notices[] = 'You\'re not allowed to edit your about page.';
$notices[] = "You're not allowed to edit your about page.";
} else {
$aboutText = (string)($_POST['about']['text'] ?? '');
$aboutParse = TextFormat::tryFrom((string)($_POST['about']['parser'] ?? '')) ?? TextFormat::Plain;
$aboutValid = $msz->usersCtx->users->validateProfileAbout($aboutParse, $aboutText);
if($aboutValid === '')
$msz->usersCtx->users->updateUser($userInfo, aboutBody: $aboutText, aboutBodyFormat: $aboutParse);
else
$notices[] = $msz->usersCtx->users->validateProfileAboutText($aboutValid);
$aboutBody = (string)filter_input(INPUT_POST, 'about_body');
if(trim($aboutBody) === '') {
$msz->profileCtx->about->deleteProfileAbout($userInfo);
$aboutInfo = null;
} else {
$aboutFormat = TextFormat::tryFrom(filter_input(INPUT_POST, 'about_format'));
$aboutValid = ProfileAboutData::validateProfileAbout($aboutFormat, $aboutBody);
if($aboutValid === '')
$aboutInfo = $msz->profileCtx->about->updateProfileAbout($userInfo, $aboutBody, $aboutFormat);
else
$notices[] = ProfileAboutData::validateProfileAboutText($aboutValid);
}
}
}
if(filter_has_var(INPUT_POST, 'sig_body')) {
if(!$perms->edit_signature) {
$notices[] = 'You\'re not allowed to edit your forum signature.';
$notices[] = "You're not allowed to edit your forum signature.";
} else {
$sigBody = (string)filter_input(INPUT_POST, 'sig_body');
if(trim($sigBody) === '') {
@ -181,7 +186,7 @@ if($isEditing) {
$birthYear = (int)($_POST['birthdate']['year'] ?? 0);
$birthMonth = (int)($_POST['birthdate']['month'] ?? 0);
$birthDay = (int)($_POST['birthdate']['day'] ?? 0);
$birthValid = UsersContext::validateBirthdate($birthYear, $birthMonth, $birthDay);
$birthValid = UserBirthdatesData::validateBirthdate($birthYear, $birthMonth, $birthDay);
if($birthValid === '') {
if($birthMonth === 0 && $birthDay === 0)
@ -189,7 +194,7 @@ if($isEditing) {
else
$msz->usersCtx->birthdates->updateUserBirthdate($userInfo, $birthYear === 0 ? null : $birthYear, $birthMonth, $birthDay);
} else
$notices[] = $msz->usersCtx->users->validateBirthdateText($birthValid);
$notices[] = UserBirthdatesData::validateBirthdateText($birthValid);
}
}
@ -402,5 +407,6 @@ Template::render('profile.index', [
'profile_background_asset' => $backgroundAsset,
'profile_can_send_messages' => $viewerPermsGlobal->check(Perm::G_MESSAGES_SEND),
'profile_age' => $msz->usersCtx->birthdates->getUserAge($userInfo),
'profile_about_info' => $aboutInfo,
'profile_forum_signature_info' => $sigInfo,
]);

View file

@ -147,10 +147,11 @@ if(isset($_POST['action']) && is_string($_POST['action'])) {
$tmpFiles[] = db_to_zip($archive, $userInfo, 'oauth2_refresh', ['ref_id:s', 'app_id:s', 'user_id:s:n', 'acc_id:s:n', 'ref_token:n', 'ref_scope:s', 'ref_created:t', 'ref_expires:t']);
$tmpFiles[] = db_to_zip($archive, $userInfo, 'perms', ['user_id:s:n', 'role_id:s:n', 'forum_id:s:n', 'perms_category:s', 'perms_allow:i', 'perms_deny:i']);
$tmpFiles[] = db_to_zip($archive, $userInfo, 'perms_calculated', ['user_id:s:n', 'forum_id:s:n', 'perms_category:s', 'perms_calculated:i']);
$tmpFiles[] = db_to_zip($archive, $userInfo, 'profile_about', ['user_id:s', 'about_body:s', 'about_body_format:s', 'about_created:t']);
$tmpFiles[] = db_to_zip($archive, $userInfo, 'profile_backgrounds', ['user_id:s', 'bg_attach:s', 'bg_blend:i', 'bg_slide:i']);
$tmpFiles[] = db_to_zip($archive, $userInfo, 'profile_fields_values', ['field_id:s', 'user_id:s', 'format_id:s', 'field_value:s']);
$tmpFiles[] = db_to_zip($archive, $userInfo, 'sessions', ['session_id:s', 'user_id:s', 'session_key:n', 'session_remote_addr_first:a', 'session_remote_addr_last:a:n', 'session_user_agent:s', 'session_country:s', 'session_expires:t', 'session_expires_bump:b', 'session_created:t', 'session_active:t:n']);
$tmpFiles[] = db_to_zip($archive, $userInfo, 'users', ['user_id:s', 'user_name:s', 'user_password:n', 'user_email:s', 'user_remote_addr_first:a', 'user_remote_addr_last:a', 'user_super:b', 'user_country:s', 'user_colour:i:n', 'user_created:t', 'user_active:t:n', 'user_deleted:t:n', 'user_display_role_id:s:n', 'user_about_content:s:n', 'user_about_content_format:s', 'user_title:s:n']);
$tmpFiles[] = db_to_zip($archive, $userInfo, 'users', ['user_id:s', 'user_name:s', 'user_password:n', 'user_email:s', 'user_remote_addr_first:a', 'user_remote_addr_last:a', 'user_super:b', 'user_country:s', 'user_colour:i:n', 'user_created:t', 'user_active:t:n', 'user_deleted:t:n', 'user_display_role_id:s:n', 'user_title:s:n']);
$tmpFiles[] = db_to_zip($archive, $userInfo, 'users_bans', ['ban_id:s', 'user_id:s', 'mod_id:n', 'ban_severity:i', 'ban_reason_public:s', 'ban_reason_private:s', 'ban_created:t', 'ban_expires:t:n']);
$tmpFiles[] = db_to_zip($archive, $userInfo, 'users_birthdates', ['user_id:s', 'birth_year:i:n', 'birth_month:i', 'birth_day:i']);
$tmpFiles[] = db_to_zip($archive, $userInfo, 'users_password_resets', ['reset_id:s', 'user_id:s', 'reset_remote_addr:a', 'reset_requested:t', 'reset_code:n']);