From 81f4dfce19a246dbdcb59043f6e4bdd2257b449a Mon Sep 17 00:00:00 2001 From: flashwave Date: Tue, 25 Jul 2023 15:03:25 +0000 Subject: [PATCH] Fixed error 500 when trying to view a non-existent profile. --- public-legacy/profile.php | 18 +++++++++++++----- templates/profile/_layout/header.twig | 2 +- templates/profile/index.twig | 4 ++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/public-legacy/profile.php b/public-legacy/profile.php index b96e97e..f766fca 100644 --- a/public-legacy/profile.php +++ b/public-legacy/profile.php @@ -14,26 +14,33 @@ $userId = !empty($_GET['u']) && is_string($_GET['u']) ? trim($_GET['u']) : 0; $profileMode = !empty($_GET['m']) && is_string($_GET['m']) ? (string)$_GET['m'] : ''; $isEditing = !empty($_GET['edit']) && is_string($_GET['edit']) ? (bool)$_GET['edit'] : !empty($_POST) && is_array($_POST); +$currentUser = User::getCurrent(); +$viewingAsGuest = $currentUser === null; +$currentUserId = $viewingAsGuest ? 0 : $currentUser->getId(); + try { $profileUser = User::findForProfile($userId); } catch(RuntimeException $ex) { http_response_code(404); - Template::render('profile.index'); + Template::render('profile.index', [ + 'profile_is_guest' => $viewingAsGuest, + 'profile_is_deleted' => true, + ]); return; } if($profileUser->isDeleted()) { http_response_code(404); - Template::render('profile.index'); + Template::render('profile.index', [ + 'profile_is_guest' => $viewingAsGuest, + 'profile_is_deleted' => true, + ]); return; } $notices = []; $profileFields = new ProfileFields($db); -$currentUser = User::getCurrent(); -$viewingAsGuest = $currentUser === null; -$currentUserId = $viewingAsGuest ? 0 : $currentUser->getId(); $viewingOwnProfile = $currentUserId === $profileUser->getId(); $isBanned = $profileUser->hasActiveWarning(); $userPerms = perms_get_user($currentUserId)[MSZ_PERMS_USER]; @@ -443,5 +450,6 @@ if(!empty($template)) { 'profile_is_editing' => $isEditing, 'profile_is_banned' => $isBanned, 'profile_is_guest' => $viewingAsGuest, + 'profile_is_deleted' => false, ]); } diff --git a/templates/profile/_layout/header.twig b/templates/profile/_layout/header.twig index fd78c0a..33b13aa 100644 --- a/templates/profile/_layout/header.twig +++ b/templates/profile/_layout/header.twig @@ -1,7 +1,7 @@ {% from 'macros.twig' import avatar %} {% from '_layout/input.twig' import input_checkbox_raw %} -
+
diff --git a/templates/profile/index.twig b/templates/profile/index.twig index 2524a90..e3f3e6d 100644 --- a/templates/profile/index.twig +++ b/templates/profile/index.twig @@ -77,7 +77,7 @@ {% endif %}
- {% set show_profile_fields = not profile_is_guest and (profile_is_editing ? perms.edit_profile : profile_fields_display_values is not empty) %} + {% set show_profile_fields = not profile_is_guest and (profile_is_editing ? perms.edit_profile : profile_fields_display_values|default([]) is not empty) %} {% set show_background_settings = profile_is_editing and perms.edit_background %} {% set show_birthdate = profile_is_editing and perms.edit_birthdate %} {% set show_active_forum_info = not profile_is_editing and (profile_active_category_info.forum_id|default(0) > 0 or profile_active_topic_info.topic_id|default(0) > 0) %} @@ -102,7 +102,7 @@
{% endif %} - {% if current_user is not defined %} + {% if current_user is not defined and not profile_is_deleted %}
You must log in to view full profiles!