From 82251ece8c21e02498693719028570a413a6fc8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B8nstantine=20Kovalensky?= <45331093+kovalensky@users.noreply.github.com> Date: Fri, 24 Nov 2023 12:01:11 +0400 Subject: [PATCH] Support simultaneous id & username inputs for browsing profiles (#1166) --- library/includes/functions.php | 6 +++++- library/includes/ucp/viewprofile.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/library/includes/functions.php b/library/includes/functions.php index ac4f9bf22..92be75480 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -980,7 +980,7 @@ function clean_username($username) * @param bool $allow_guest * @return mixed */ -function get_userdata($u, bool $is_name = false, bool $allow_guest = false) +function get_userdata($u, bool $is_name = false, bool $allow_guest = false, bool $profile_view = false) { if (empty($u)) { return false; @@ -998,6 +998,10 @@ function get_userdata($u, bool $is_name = false, bool $allow_guest = false) $where_sql = "WHERE username = '" . DB()->escape(clean_username($u)) . "'"; } + if ($profile_view) { + $where_sql = "WHERE user_id = " . (int)$u . " OR username = '" . DB()->escape(clean_username($u)) . "'"; + } + $exclude_anon_sql = (!$allow_guest) ? "AND user_id != " . GUEST_UID : ''; $sql = "SELECT * FROM " . BB_USERS . " $where_sql $exclude_anon_sql LIMIT 1"; diff --git a/library/includes/ucp/viewprofile.php b/library/includes/ucp/viewprofile.php index 25e824b94..9ecb21c7c 100644 --- a/library/includes/ucp/viewprofile.php +++ b/library/includes/ucp/viewprofile.php @@ -26,7 +26,7 @@ if (!$userdata['session_logged_in']) { } } -if (!$profiledata = get_userdata($_GET[POST_USERS_URL], !is_numeric($_GET[POST_USERS_URL]))) { +if (!$profiledata = get_userdata($_GET[POST_USERS_URL], profile_view: true)) { bb_die($lang['NO_USER_ID_SPECIFIED']); }