quick 'n dirty about section

This commit is contained in:
flash 2018-09-20 18:50:11 +02:00
parent 4300fc4a4f
commit 14340774b9
4 changed files with 72 additions and 2 deletions

View file

@ -1,7 +1,7 @@
.profile__about { .profile__about {
&__content { &__content {
max-height: 300px; max-height: 600px;
overflow: auto; overflow: auto;
} }
} }

View file

@ -12,6 +12,7 @@ $perms = [
'edit_profile' => perms_check($userPerms, MSZ_PERM_USER_EDIT_PROFILE), 'edit_profile' => perms_check($userPerms, MSZ_PERM_USER_EDIT_PROFILE),
'edit_avatar' => perms_check($userPerms, MSZ_PERM_USER_CHANGE_AVATAR), 'edit_avatar' => perms_check($userPerms, MSZ_PERM_USER_CHANGE_AVATAR),
'edit_background' => perms_check($userPerms, MSZ_PERM_USER_CHANGE_BACKGROUND), 'edit_background' => perms_check($userPerms, MSZ_PERM_USER_CHANGE_BACKGROUND),
'edit_about' => perms_check($userPerms, MSZ_PERM_USER_EDIT_ABOUT),
]; ];
if (!$app->hasActiveSession()) { if (!$app->hasActiveSession()) {
@ -109,6 +110,41 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
} }
} }
if (!empty($_POST['about']) && is_array($_POST['about'])) {
if (!$perms['edit_about']) {
$settingsErrors[] = "You're not allowed to edit your about page.";
} else {
$aboutParser = (int)($_POST['about']['parser'] ?? MSZ_FORUM_POST_PARSER_PLAIN);
$aboutText = $_POST['about']['text'] ?? '';
// TODO: this is disgusting (move this into a user_set_about function or some shit)
while (true) {
// TODO: take parser shit out of forum_post
if (!forum_post_is_valid_parser($aboutParser)) {
$settingsErrors[] = 'Invalid parser specified.';
break;
}
if (strlen($aboutText) > 0xFFFF) {
$settingsErrors[] = 'Please keep the length of your about page to at most ' . 0xFFFF . '.';
break;
}
$setAbout = Database::prepare('
UPDATE `msz_users`
SET `user_about_content` = :content,
`user_about_parser` = :parser
WHERE `user_id` = :user
');
$setAbout->bindValue('user', $app->getUserId());
$setAbout->bindValue('content', strlen($aboutText) < 1 ? null : $aboutText);
$setAbout->bindValue('parser', $aboutParser);
$setAbout->execute();
break;
}
}
}
if (!empty($_POST['avatar']) && is_array($_POST['avatar'])) { if (!empty($_POST['avatar']) && is_array($_POST['avatar'])) {
switch ($_POST['avatar']['mode'] ?? '') { switch ($_POST['avatar']['mode'] ?? '') {
case 'delete': case 'delete':
@ -348,7 +384,7 @@ tpl_vars([
]); ]);
switch ($settingsMode) { switch ($settingsMode) {
case 'account': case 'account': // TODO: FIX THIS GARBAGE HOLY HELL
$profileFields = user_profile_fields_get(); $profileFields = user_profile_fields_get();
$getUserFields = Database::prepare(' $getUserFields = Database::prepare('
SELECT ' . pdo_prepare_array($profileFields, true, '`user_%s`') . ' SELECT ' . pdo_prepare_array($profileFields, true, '`user_%s`') . '
@ -368,6 +404,14 @@ switch ($settingsMode) {
$userHasAvatar = is_file(build_path($app->getStoragePath(), 'avatars/original', $avatarFileName)); $userHasAvatar = is_file(build_path($app->getStoragePath(), 'avatars/original', $avatarFileName));
$userHasBackground = is_file(build_path($app->getStoragePath(), 'backgrounds/original', $avatarFileName)); $userHasBackground = is_file(build_path($app->getStoragePath(), 'backgrounds/original', $avatarFileName));
$getAboutInfo = Database::prepare('
SELECT `user_about_content`, `user_about_parser`
FROM `msz_users`
WHERE `user_id` = :user_id
');
$getAboutInfo->bindValue('user_id', $app->getUserId());
$aboutInfo = $getAboutInfo->execute() ? $getAboutInfo->fetch(PDO::FETCH_ASSOC) : [];
tpl_vars([ tpl_vars([
'avatar' => $avatarProps, 'avatar' => $avatarProps,
'background' => $backgroundProps, 'background' => $backgroundProps,
@ -377,6 +421,7 @@ switch ($settingsMode) {
'settings_profile_values' => $userFields, 'settings_profile_values' => $userFields,
'settings_disable_account_options' => $disableAccountOptions, 'settings_disable_account_options' => $disableAccountOptions,
'settings_email' => $currentEmail, 'settings_email' => $currentEmail,
'about_info' => $aboutInfo,
]); ]);
break; break;

View file

@ -6,6 +6,7 @@ use Misuzu\IO\File;
define('MSZ_PERM_USER_EDIT_PROFILE', 1); define('MSZ_PERM_USER_EDIT_PROFILE', 1);
define('MSZ_PERM_USER_CHANGE_AVATAR', 1 << 1); define('MSZ_PERM_USER_CHANGE_AVATAR', 1 << 1);
define('MSZ_PERM_USER_CHANGE_BACKGROUND', 1 << 2); define('MSZ_PERM_USER_CHANGE_BACKGROUND', 1 << 2);
define('MSZ_PERM_USER_EDIT_ABOUT', 1 << 3);
define('MSZ_PERM_USER_MANAGE_USERS', 1 << 20); define('MSZ_PERM_USER_MANAGE_USERS', 1 << 20);
define('MSZ_PERM_USER_MANAGE_ROLES', 1 << 21); define('MSZ_PERM_USER_MANAGE_ROLES', 1 << 21);

View file

@ -261,4 +261,28 @@
}); });
</script> </script>
{% endif %} {% endif %}
{% if settings_perms.edit_about %}
<div class="container">
<div class="container__title">
About you
</div>
<form method="post" action="" enctype="multipart/form-data">
<input type="hidden" name="csrf" value="{{ csrf_token() }}">
<textarea name="about[text]">{{ about_info.user_about_content }}</textarea>
<select name="about[parser]">
{# todo: foreach #}
<option value="0">Plain text</option>
<option value="1">BB Code</option>
<option value="2">Markdown</option>
</select>
<button class="input__button">Update</button>
<button class="input__button" type="reset">Reset</button>
</form>
</div>
{% endif %}
{% endblock %} {% endblock %}