From 14340774b9c6176e400e7b64eff23e952ee95df3 Mon Sep 17 00:00:00 2001 From: flashwave Date: Thu, 20 Sep 2018 18:50:11 +0200 Subject: [PATCH] quick 'n dirty about section --- assets/less/mio/classes/profile/about.less | 2 +- public/settings.php | 47 +++++++++++++++++++++- src/Users/user.php | 1 + templates/settings/account.twig | 24 +++++++++++ 4 files changed, 72 insertions(+), 2 deletions(-) diff --git a/assets/less/mio/classes/profile/about.less b/assets/less/mio/classes/profile/about.less index c5d5e10a..f61241dc 100644 --- a/assets/less/mio/classes/profile/about.less +++ b/assets/less/mio/classes/profile/about.less @@ -1,7 +1,7 @@ .profile__about { &__content { - max-height: 300px; + max-height: 600px; overflow: auto; } } diff --git a/public/settings.php b/public/settings.php index dbfc4535..ed195a73 100644 --- a/public/settings.php +++ b/public/settings.php @@ -12,6 +12,7 @@ $perms = [ 'edit_profile' => perms_check($userPerms, MSZ_PERM_USER_EDIT_PROFILE), 'edit_avatar' => perms_check($userPerms, MSZ_PERM_USER_CHANGE_AVATAR), 'edit_background' => perms_check($userPerms, MSZ_PERM_USER_CHANGE_BACKGROUND), + 'edit_about' => perms_check($userPerms, MSZ_PERM_USER_EDIT_ABOUT), ]; 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'])) { switch ($_POST['avatar']['mode'] ?? '') { case 'delete': @@ -348,7 +384,7 @@ tpl_vars([ ]); switch ($settingsMode) { - case 'account': + case 'account': // TODO: FIX THIS GARBAGE HOLY HELL $profileFields = user_profile_fields_get(); $getUserFields = Database::prepare(' SELECT ' . pdo_prepare_array($profileFields, true, '`user_%s`') . ' @@ -368,6 +404,14 @@ switch ($settingsMode) { $userHasAvatar = is_file(build_path($app->getStoragePath(), 'avatars/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([ 'avatar' => $avatarProps, 'background' => $backgroundProps, @@ -377,6 +421,7 @@ switch ($settingsMode) { 'settings_profile_values' => $userFields, 'settings_disable_account_options' => $disableAccountOptions, 'settings_email' => $currentEmail, + 'about_info' => $aboutInfo, ]); break; diff --git a/src/Users/user.php b/src/Users/user.php index d455f4eb..7b840d11 100644 --- a/src/Users/user.php +++ b/src/Users/user.php @@ -6,6 +6,7 @@ use Misuzu\IO\File; define('MSZ_PERM_USER_EDIT_PROFILE', 1); define('MSZ_PERM_USER_CHANGE_AVATAR', 1 << 1); 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_ROLES', 1 << 21); diff --git a/templates/settings/account.twig b/templates/settings/account.twig index ce7a0d11..e81fef0f 100644 --- a/templates/settings/account.twig +++ b/templates/settings/account.twig @@ -261,4 +261,28 @@ }); {% endif %} + + {% if settings_perms.edit_about %} +
+
+ About you +
+ +
+ + + + + + + + +
+
+ {% endif %} {% endblock %}