Revert "Fixed null $u_data if user not found (#781)"

This reverts commit 1d1f9fa4aa.
This commit is contained in:
Roman Kelesidis 2023-06-06 14:46:54 +07:00
commit 9202ecbc91

View file

@ -958,7 +958,7 @@ function clean_username($username)
}
// Get Userdata, $u can be username or user_id. If $force_name is true, the username will be forced.
function get_userdata($u, bool $force_name = false, bool $allow_guest = false)
function get_userdata($u, $force_name = false, $allow_guest = false)
{
if (!$u) {
return false;
@ -970,9 +970,12 @@ function get_userdata($u, bool $force_name = false, bool $allow_guest = false)
}
}
$u_data = array();
$name_search = false;
$exclude_anon_sql = (!$allow_guest) ? "AND user_id != " . GUEST_UID : '';
if ($force_name || !is_int($u)) {
if ($force_name || !is_numeric($u)) {
$name_search = true;
$where_sql = "WHERE username = '" . DB()->escape(clean_username($u)) . "'";
} else {
$where_sql = "WHERE user_id = " . (int)$u;
@ -981,7 +984,11 @@ function get_userdata($u, bool $force_name = false, bool $allow_guest = false)
$sql = "SELECT * FROM " . BB_USERS . " $where_sql $exclude_anon_sql LIMIT 1";
if (!$u_data = DB()->fetch_row($sql)) {
return false;
if (!is_int($u) && !$name_search) {
$where_sql = "WHERE username = '" . DB()->escape(clean_username($u)) . "'";
$sql = "SELECT * FROM " . BB_USERS . " $where_sql $exclude_anon_sql LIMIT 1";
$u_data = DB()->fetch_row($sql);
}
}
if ($u_data['user_id'] == GUEST_UID) {