diff --git a/web/app/controllers/subdomain/blog/blog.php b/web/app/controllers/subdomain/blog/blog.php index 5150047..9399add 100644 --- a/web/app/controllers/subdomain/blog/blog.php +++ b/web/app/controllers/subdomain/blog/blog.php @@ -201,7 +201,9 @@ $comments_pag = new Paginator([ "order by id" ]); foreach ($replies as $idx => $reply) { - $replies[$idx]['poster_realname'] = UOJUser::query($reply['poster'])['realname']; + $reply_user = UOJUser::query($reply['poster']); + $replies[$idx]['poster_realname'] = $reply_user['realname']; + $replies[$idx]['poster_username_color'] = UOJUser::getUserColor($reply_user); $replies[$idx]['content'] = getCommentContentToDisplay($reply); } $replies_json = json_encode($replies); diff --git a/web/app/libs/uoj-contest-lib.php b/web/app/libs/uoj-contest-lib.php index 1b53904..f360bf0 100644 --- a/web/app/libs/uoj-contest-lib.php +++ b/web/app/libs/uoj-contest-lib.php @@ -87,14 +87,23 @@ function queryContestData($contest, $config = []) { $people = []; if ($contest['extra_config']['individual_or_team'] == 'individual') { - $people = DB::selectAll([ - "select contests_registrants.username, user_info.realname from contests_registrants", + $res = DB::selectAll([ + "select contests_registrants.username, user_info.realname, user_info.extra, user_info.usergroup from contests_registrants", "inner join user_info on contests_registrants.username = user_info.username", "where", [ "contest_id" => $contest['id'], "has_participated" => 1 ] ], DB::NUM); + foreach ($res as $row) { + $extra = json_decode($row[2], true); + $people[] = [ + $row[0], + trim(HTML::escape($row[1])), + null, + UOJUser::getUserColor2($row[3], $extra['username_color']), + ]; + } } elseif ($contest['extra_config']['individual_or_team'] == 'team') { $res = DB::selectAll([ "select user_info.username, null, user_info.extra from contests_registrants, user_info", @@ -106,11 +115,15 @@ function queryContestData($contest, $config = []) { ], DB::NUM); foreach ($res as $row) { $extra = json_decode($row[2], true); - $row[2] = [ - 'team_name' => $extra['acm']['team_name'], - 'members' => $extra['acm']['members'] + $people[] = [ + $row[0], + null, + [ + 'team_name' => $extra['acm']['team_name'], + 'members' => $extra['acm']['members'], + ], + null, ]; - $people[] = $row; } } @@ -373,7 +386,7 @@ function calcStandings($contest, $contest_data, &$score, &$standings, $cfg = []) } } - // standings: rank => score, penalty, [username, realname], virtual_rank, ?review + // standings: rank => score, penalty, [username, realname, null|array, null|color], virtual_rank, ?review $standings = []; foreach ($contest_data['people'] as $person) { $cur = array(0, 0, $person); diff --git a/web/app/models/UOJUser.php b/web/app/models/UOJUser.php index 508305d..388b724 100644 --- a/web/app/models/UOJUser.php +++ b/web/app/models/UOJUser.php @@ -210,6 +210,33 @@ class UOJUser { } } + public static function getUserColor($user) { + $extra = UOJUser::getExtra($user); + + return UOJUser::getUserColor2($user['usergroup'], $extra['username_color']); + } + + public static function getUserColor2($usergroup, $custom_color = null) { + if ($usergroup == 'B') { + return '#996600'; + } + + if ($usergroup == 'T') { + return '#707070'; + } + + if ($usergroup == 'S') { + return $custom_color ?: '#9d3dcf'; + } + + // 前管理员设置颜色为紫色、红色的,颜色改为蓝色 + if ($custom_color == '#9d3dcf' || $custom_color == '#fe4c61') { + return '#0d6efd'; + } + + return $custom_color ?: '#0d6efd'; + } + public static function getLink($user) { if (is_string($user)) { $info = UOJUser::query($user); @@ -221,36 +248,21 @@ class UOJUser { } } - $extra = UOJUser::getExtra($user); $realname = $user['realname']; - $color = '#0d6efd'; - - if ($user['usergroup'] === 'B') { - $color = '#996600'; - } else if (isTmpUser($user)) { - $color = '#707070'; - } else { - if (isSuperUser($user)) { - $color = '#9d3dcf'; - } - - $color = $extra['username_color']; - - // 前管理员设置颜色为紫色、红色的,颜色改为蓝色 - if (($color === '#9d3dcf' || $color === '#fe4c61') && !isSuperUser($user)) { - $color = '#0d6efd'; - } - } if ($user['usertype'] == 'teacher') { $realname .= '老师'; } + if (!Auth::check()) { + $realname = ''; + } + return HTML::tag('span', [ 'class' => 'uoj-username', + 'data-color' => UOJUser::getUserColor($user), // 未登录不可查看真实姓名 - 'data-realname' => Auth::check() ? trim(HTML::escape($realname)) : '', - 'data-color' => $color, + 'data-realname' => trim(HTML::escape($realname)), ], $user['username']); } diff --git a/web/app/views/contest-standings.php b/web/app/views/contest-standings.php index 35ee895..b5240f8 100644 --- a/web/app/views/contest-standings.php +++ b/web/app/views/contest-standings.php @@ -35,7 +35,7 @@ function(row) { var col_tr = '