Support simultaneous id & username inputs for browsing profiles (#1166)

This commit is contained in:
Cønstantine Kovalensky 2023-11-24 12:01:11 +04:00 committed by GitHub
commit 82251ece8c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View file

@ -980,7 +980,7 @@ function clean_username($username)
* @param bool $allow_guest * @param bool $allow_guest
* @return mixed * @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)) { if (empty($u)) {
return false; 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)) . "'"; $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 : ''; $exclude_anon_sql = (!$allow_guest) ? "AND user_id != " . GUEST_UID : '';
$sql = "SELECT * FROM " . BB_USERS . " $where_sql $exclude_anon_sql LIMIT 1"; $sql = "SELECT * FROM " . BB_USERS . " $where_sql $exclude_anon_sql LIMIT 1";

View file

@ -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']); bb_die($lang['NO_USER_ID_SPECIFIED']);
} }