| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330 |
- <?php
- function uojHandleAtSign($str, $uri) {
- $referrers = array();
- $res = preg_replace_callback('/@(@|[a-zA-Z0-9_]{1,20})/', function($matches) use (&$referrers) {
- if ($matches[1] === '@') {
- return '@';
- } else {
- $user = queryUser($matches[1]);
- if ($user == null) {
- return $matches[0];
- } else {
- $referrers[$user['username']] = '';
- return '<span class="uoj-username" data-rating="'.$user['rating'].'">@'.$user['username'].'</span>';
- }
- }
- }, $str);
-
- $referrers_list = array();
- foreach ($referrers as $referrer => $val) {
- $referrers_list[] = $referrer;
- }
-
- return array($res, $referrers_list);
- }
- function uojFilePreview($file_name, $output_limit, $file_type = 'text') {
- switch ($file_type) {
- case 'text':
- return strOmit(file_get_contents($file_name, false, null, 0, $output_limit + 4), $output_limit);
- default:
- return strOmit(shell_exec('xxd -g 4 -l 5000 ' . escapeshellarg($file_name) . ' | head -c ' . ($output_limit + 4)), $output_limit);
- }
- }
- function uojIncludeView($name, $view_params = array()) {
- extract($view_params);
- include $_SERVER['DOCUMENT_ROOT'].'/app/views/'.$name.'.php';
- }
- function redirectTo($url) {
- header('Location: '.$url);
- die();
- }
- function permanentlyRedirectTo($url) {
- header("HTTP/1.1 301 Moved Permanently");
- header('Location: '.$url);
- die();
- }
- function redirectToLogin() {
- if (UOJContext::isAjax()) {
- die('please <a href="'.HTML::url('/login').'">login</a>');
- } else {
- header('Location: '.HTML::url('/login'));
- die();
- }
- }
- function becomeMsgPage($msg, $title = '消息') {
- if (UOJContext::isAjax()) {
- die($msg);
- } else {
- echoUOJPageHeader($title);
- echo $msg;
- echoUOJPageFooter();
- die();
- }
- }
- function become404Page() {
- header($_SERVER['SERVER_PROTOCOL'] . " 404 Not Found", true, 404);
- becomeMsgPage('<div class="text-center"><div style="font-size:233px">404</div><p>唔……未找到该页面……你是从哪里点进来的……>_<……</p></div>', '404');
- }
- function become403Page() {
- header($_SERVER['SERVER_PROTOCOL'] . " 403 Forbidden", true, 403);
- becomeMsgPage('<div class="text-center"><div style="font-size:233px">403</div><p>禁止入内! T_T</p></div>', '403');
- }
- function getUserLink($username, $rating = null, $certs = null) {
- if (validateUsername($username) && ($user = queryUser($username))) {
- if ($rating == null) {
- $rating = $user['rating'];
- }
- if ($cert == null) {
- $certs = $user['certs'];
- }
- return '<span class="uoj-username" data-rating="'.$rating.'" data-certs="'.$certs.'">'.$username.'</span>';
- } else {
- $esc_username = HTML::escape($username);
- return '<span>'.$esc_username.'</span>';
- }
- }
- function getRemoteProblemLink($rpid) {
- $rp = queryRemoteProblemBrief($rpid);
- return '<a href="/rp/' . $rpid . '">' . $rp['title'] . '</a>';
- }
- function getProblemLink($problem, $problem_title = '!title_only') {
- if ($problem_title == '!title_only') {
- $problem_title = $problem['title'];
- } elseif ($problem_title == '!id_and_title') {
- $problem_title = "#${problem['id']}. ${problem['title']}";
- }
- return '<a href="/problem/'.$problem['id'].'">'.$problem_title.'</a>';
- }
- function getContestProblemLink($problem, $contest_id, $problem_title = '!title_only') {
- if ($problem_title == '!title_only') {
- $problem_title = $problem['title'];
- } elseif ($problem_title == '!id_and_title') {
- $problem_title = "#{$problem['id']}. {$problem['title']}";
- }
- return '<a href="/contest/'.$contest_id.'/problem/'.$problem['id'].'">'.$problem_title.'</a>';
- }
- function getBlogLink($id) {
- if (validateUInt($id) && $blog = queryBlog($id)) {
- return '<a href="/blogs/'.$id.'">'.$blog['title'].'</a>';
- }
- }
- function getClickZanBlock($type, $id, $cnt, $val = null) {
- if ($val == null) {
- $val = queryZanVal($id, $type, Auth::user());
- }
- return '<div class="uoj-click-zan-block" data-id="'.$id.'" data-type="'.$type.'" data-val="'.$val.'" data-cnt="'.$cnt.'"></div>';
- }
- function getLongTablePageRawUri($page) {
- $path = strtok(UOJContext::requestURI(), '?');
- $query_string = strtok('?');
- parse_str($query_string, $param);
-
- $param['page'] = $page;
- if ($page == 1) {
- unset($param['page']);
- }
-
- if ($param) {
- return $path . '?' . http_build_query($param);
- } else {
- return $path;
- }
- }
- function getLongTablePageUri($page) {
- return HTML::escape(getLongTablePageRawUri($page));
- }
- function echoLongTable($col_names, $table_name, $cond, $tail, $header_row, $print_row, $config) {
- $pag_config = $config;
- $pag_config['col_names'] = $col_names;
- $pag_config['table_name'] = $table_name;
- $pag_config['cond'] = $cond;
- $pag_config['tail'] = $tail;
- $pag = new Paginator($pag_config);
- $div_classes = isset($config['div_classes']) ? $config['div_classes'] : array('table-responsive', 'shadow', 'my-4');
- $table_classes = isset($config['table_classes']) ? $config['table_classes'] : array('table', 'table-bordered', 'table-hover', 'table-striped', 'table-text-center');
-
- echo '<div class="', join($div_classes, ' '), '">';
- echo '<table class="', join($table_classes, ' '), '">';
- echo '<thead>';
- echo $header_row;
- echo '</thead>';
- echo '<tbody>';
- foreach ($pag->get() as $idx => $row) {
- if (isset($config['get_row_index'])) {
- $print_row($row, $idx);
- } else {
- $print_row($row);
- }
- }
- if ($pag->isEmpty()) {
- echo '<tr><td colspan="233">'.UOJLocale::get('none').'</td></tr>';
- }
- echo '</tbody>';
- echo '</table>';
- echo '</div>';
-
- if (isset($config['print_after_table'])) {
- $fun = $config['print_after_table'];
- $fun();
- }
-
- echo $pag->pagination();
- }
- function getSubmissionStatusDetails($submission) {
- $html = '<td colspan="233" style="vertical-align: middle">';
-
- $out_status = explode(', ', $submission['status'])[0];
-
- $fly = '<img src="/images/utility/qpx_n/b37.gif" alt="小熊像超人一样飞" class="img-rounded" />';
- $think = '<img src="/images/utility/qpx_n/b29.gif" alt="小熊像在思考" class="img-rounded" />';
-
- if ($out_status == 'Judged') {
- $status_text = '<strong>Judged!</strong>';
- $status_img = $fly;
- } else {
- if ($submission['status_details'] !== '') {
- $status_img = $fly;
- $status_text = HTML::escape($submission['status_details']);
- } else {
- $status_img = $think;
- $status_text = $out_status;
- }
- }
- $html .= '<div class="uoj-status-details-img-div">' . $status_img . '</div>';
- $html .= '<div class="uoj-status-details-text-div">' . $status_text . '</div>';
- $html .= '</td>';
- return $html;
- }
- function echoSubmission($submission, $config, $user) {
- $problem = queryProblemBrief($submission['problem_id']);
- $submitterLink = getUserLink($submission['submitter']);
-
- if ($submission['score'] == null) {
- $used_time_str = "/";
- $used_memory_str = "/";
- } else {
- $used_time_str = $submission['used_time'] . 'ms';
- $used_memory_str = $submission['used_memory'] . 'kb';
- }
-
- $status = explode(', ', $submission['status'])[0];
-
- $show_status_details = Auth::check() && ($submission['submitter'] === Auth::id() || isSuperUser(queryUser(Auth::id()))) && $status !== 'Judged';
-
- if (!$show_status_details) {
- echo '<tr>';
- } else {
- echo '<tr class="warning">';
- }
- if (!isset($config['id_hidden'])) {
- echo '<td><a href="/submission/', $submission['id'], '">#', $submission['id'], '</a></td>';
- }
- if (!isset($config['problem_hidden'])) {
- if ($submission['contest_id']) {
- echo '<td>', getContestProblemLink($problem, $submission['contest_id'], '!id_and_title'), '</td>';
- } else if ($submission['problem_id'] != 260328) {
- echo '<td>', getProblemLink($problem, '!id_and_title'), '</td>';
- } else {
- foreach (json_decode($submission['content'], true)['config'] as $row)
- if ($row[0] == 'rpid') {
- $rpid = $row[1];
- break;
- }
- echo '<td>' . getRemoteProblemLink($rpid) . '</td>';
- }
- }
- if (!isset($config['submitter_hidden'])) {
- echo '<td>', $submitterLink, '</td>';
- }
- if (!isset($config['result_hidden'])) {
- echo '<td>';
- if ($status == 'Judged') {
- if ($submission['score'] == null) {
- echo '<a href="/submission/', $submission['id'], '" class="small">', $submission['result_error'], '</a>';
- } else {
- echo '<a href="/submission/', $submission['id'], '" class="uoj-score">', $submission['score'], '</a>';
- }
- } else {
- echo '<a href="/submission/', $submission['id'], '" class="small">', $status, '</a>';
- }
- echo '</td>';
- }
- if (!isset($config['used_time_hidden'])) {
- echo '<td>', $used_time_str, '</td>';
- }
- if (!isset($config['used_memory_hidden'])) {
- echo '<td>', $used_memory_str, '</td>';
- }
- echo '<td>', '<a href="/submission/', $submission['id'], '">', $submission['language'], '</a>', '</td>';
- if ($submission['tot_size'] < 1024) {
- $size_str = $submission['tot_size'] . 'b';
- } else {
- $size_str = sprintf("%.1f", $submission['tot_size'] / 1024) . 'kb';
- }
- echo '<td>', $size_str, '</td>';
- if (!isset($config['submit_time_hidden'])) {
- echo '<td><small>', $submission['submit_time'], '</small></td>';
- }
- if (!isset($config['judge_time_hidden'])) {
- echo '<td><small>', $submission['judge_time'], '</small></td>';
- }
- echo '</tr>';
- if ($show_status_details) {
- echo '<tr id="', "status_details_{$submission['id']}", '" class="info">';
- echo getSubmissionStatusDetails($submission);
- echo '</tr>';
- echo '<script type="text/javascript">update_judgement_status_details('.$submission['id'].')</script>';
- }
- }
- function echoSubmissionsListOnlyOne($submission, $config, $user) {
- echo '<div class="table-responsive shadow my-4">';
- echo '<table class="table table-bordered table-text-center">';
- echo '<thead>';
- echo '<tr>';
- if (!isset($config['id_hidden'])) {
- echo '<th>ID</th>';
- }
- if (!isset($config['problem_hidden'])) {
- echo '<th>'.UOJLocale::get('problems::problem').'</th>';
- }
- if (!isset($config['submitter_hidden'])) {
- echo '<th>'.UOJLocale::get('problems::submitter').'</th>';
- }
- if (!isset($config['result_hidden'])) {
- echo '<th>'.UOJLocale::get('problems::result').'</th>';
- }
- if (!isset($config['used_time_hidden'])) {
- echo '<th>'.UOJLocale::get('problems::used time').'</th>';
- }
- if (!isset($config['used_memory_hidden'])) {
- echo '<th>'.UOJLocale::get('problems::used memory').'</th>';
- }
- echo '<th>'.UOJLocale::get('problems::language').'</th>';
- echo '<th>'.UOJLocale::get('problems::file size').'</th>';
- if (!isset($config['submit_time_hidden'])) {
- echo '<th>'.UOJLocale::get('problems::submit time').'</th>';
- }
- if (!isset($config['judge_time_hidden'])) {
- echo '<th>'.UOJLocale::get('problems::judge time').'</th>';
- }
- echo '</tr>';
- echo '</thead>';
- echo '<tbody>';
- echoSubmission($submission, $config, $user);
- echo '</tbody>';
- echo '</table>';
- echo '</div>';
- }
- function echoSubmissionsList($cond, $tail, $config, $user) {
- $header_row = '<tr>';
- $col_names = array();
- $col_names[] = 'submissions.status_details';
- $col_names[] = 'submissions.status';
- $col_names[] = 'submissions.result_error';
- $col_names[] = 'submissions.score';
- $col_names[] = 'submissions.content';
-
- if (!isset($config['id_hidden'])) {
- $header_row .= '<th>ID</th>';
- $col_names[] = 'submissions.id';
- }
- if (!isset($config['problem_hidden'])) {
- $header_row .= '<th>'.UOJLocale::get('problems::problem').'</th>';
- $col_names[] = 'submissions.problem_id';
- $col_names[] = 'submissions.contest_id';
- }
- if (!isset($config['submitter_hidden'])) {
- $header_row .= '<th>'.UOJLocale::get('problems::submitter').'</th>';
- $col_names[] = 'submissions.submitter';
- }
- if (!isset($config['result_hidden'])) {
- $header_row .= '<th>'.UOJLocale::get('problems::result').'</th>';
- }
- if (!isset($config['used_time_hidden'])) {
- $header_row .= '<th>'.UOJLocale::get('problems::used time').'</th>';
- $col_names[] = 'submissions.used_time';
- }
- if (!isset($config['used_memory_hidden'])) {
- $header_row .= '<th>'.UOJLocale::get('problems::used memory').'</th>';
- $col_names[] = 'submissions.used_memory';
- }
- $header_row .= '<th>'.UOJLocale::get('problems::language').'</th>';
- $col_names[] = 'submissions.language';
- $header_row .= '<th>'.UOJLocale::get('problems::file size').'</th>';
- $col_names[] = 'submissions.tot_size';
- if (!isset($config['submit_time_hidden'])) {
- $header_row .= '<th>'.UOJLocale::get('problems::submit time').'</th>';
- $col_names[] = 'submissions.submit_time';
- }
- if (!isset($config['judge_time_hidden'])) {
- $header_row .= '<th>'.UOJLocale::get('problems::judge time').'</th>';
- $col_names[] = 'submissions.judge_time';
- }
- $header_row .= '</tr>';
-
- $table_name = isset($config['table_name']) ? $config['table_name'] : 'submissions';
-
- if (!isSuperUser($user)) {
- if ($user != null) {
- $permission_cond = "submissions.is_hidden = false or (submissions.is_hidden = true and submissions.problem_id in (select problem_id from problems_permissions where username = '{$user['username']}')) or (submissions.is_hidden = 1 and (select max(find_in_set(submissions.problem_id, privs)) as nr from user_info where username like 'group_%' and find_in_set(username, '{$user['extgroups']}')))";
- } else {
- $permission_cond = "submissions.is_hidden = false";
- }
- if ($cond !== '1') {
- $cond = "($cond) and ($permission_cond)";
- } else {
- $cond = $permission_cond;
- }
- }
-
- $table_config = isset($config['table_config']) ? $config['table_config'] : null;
-
- echoLongTable($col_names, $table_name, $cond, $tail, $header_row,
- function($submission) use ($config, $user) {
- echoSubmission($submission, $config, $user);
- }, $table_config);
- }
- function echoShortList($header, $rows, $print_row) {
- echo '<div class="table-responsive"><table class="table table-bordered table-hover table-striped table-text-center">';
- echo '<thead>';
- echo $header;
- echo '</thead>';
- echo '<tbody>';
- foreach ($rows as $idx => $row)
- $print_row($row);
- if (empty($rows))
- echo '<tr><td colspan="233">'.UOJLocale::get('none').'</td></tr>';
- echo '</tbody>';
- echo '</table>';
- echo '</div>';
- }
- function echoBelongGroupList($user) {
- echoShortList('<tr><th>组名</th><th>题目</th></tr>', queryUserExtgroups($user), function($grp) {
- $link = getUserLink(queryUser($grp)['username']);
- echo <<<HTML
- <tr>
- <td>$link</td>
- <td><a href="/problems/group/{$grp}">题目</a></td>
- </tr>
- HTML;
- });
- }
- function echoGroupMemberList($grp) {
- echoShortList('<tr><th>用户名</th><th>管理</th></tr>', queryGroupMembers($grp),
- function($usern) use ($grp) {
- $username = $usern['username'];
- $user = queryUser($username);
- $link = getUserLink($username);
- if (hasGroupCtrlPermission($user, $grp)) $adminp = '<b>是</b>';
- else $adminp = '否';
- echo <<<HTML
- <tr>
- <td>$link</td>
- <td>$adminp</td>
- </tr>
- HTML;
- });
- }
- function echoGroupProblemList($grp) {
- echoShortList('<tr><th>题号</th><th>题名</th><th>控制</th><th>压缩包大小</th></tr>', queryGroupProblems($grp),
- function($pid) use ($grp) {
- $problem = queryProblemBrief($pid);
- $pid = $pid;
- $title = $problem['title'];
- if ($problem['ctrl'] && $problem['ctrl'] == $grp['username']) $adminp = '<b>是</b>';
- else $adminp = '否';
- $size = printSize(queryProblemSize($pid));
- echo <<<HTML
- <tr><td>$pid</td>
- <td><a href="/problem/{$pid}">$title</a></td>
- <td>$adminp</td>
- <td>$size</td></tr>
- HTML;
- });
- }
- function echoGroupProblemSizeList($grp) {
- echoShortList('<tr><th>题号</th><th>题名</th><th>压缩包大小</th></tr>', queryGroupCtrlProblems($grp),
- function($pid) {
- $problem = queryProblemBrief($pid);
- $pid = $pid;
- $title = $problem['title'];
- $size = printSize(queryProblemSize($pid));
- echo <<<HTML
- <tr><td>$pid</td>
- <td><a href="/problem/{$pid}">$title</a></td>
- <td>$size</td></tr>
- HTML;
- });
- }
- function echoControlGroupList($user) {
- echoShortList('<tr><th>组名</th><th>管理</th></tr>', queryUserCtrlgroups($user), function($grp) {
- $link = getUserLink(queryUser($grp)['username']);
- echo <<<HTML
- <tr>
- <td>$link</td>
- <td><a href="/group-manage/{$grp}">管理</a></td>
- </tr>
- HTML;
- });
- }
- function echoGroupsList() {
- $header_row = '<tr>';
- $col_names = ['username', 'privs'];
- $header_row .= '<th>组名</th>';
- $header_row .= '<th>组权限</th>';
- $header_row .= '</tr>';
- $table_name = 'user_info';
- echoLongTable($col_names, $table_name, "username like 'group_%'", '', $header_row,
- function ($group) {
- $link = getUserLink($group['username']);
- $privs = $group['privs'];
- echo <<<HTML
- <tr>
- <td>
- {$link}
- </td>
- <td>
- {$privs_pretty}
- </td>
- </tr>
- HTML;
- }, []);
- }
- function echoCertsList($user) {
- echoShortList('<tr><th>勋章</th><th>展示</th></tr>', explode(',', $user['certslist']), function($certs) {
- $col = explode('#', $certs)[0];
- $text = explode('#', $certs)[1];
- $cert = '<span class="uoj-certs uoj-certs-' . $col . '">' . $text . '</span>';
- echo <<<HTML
- <tr>
- <td>$cert</td>
- <td>
- <form action="/certs-manage" method="post">
- <input type="hidden" name="certs" value="$certs">
- <button type="submit" class="btn btn-primary">展示这个</button>
- </form>
- </td>
- </tr>
- HTML;
- });
- }
- function echoPastesList() {
- $header_row = '<tr>';
- $col_names = ['`index`','creator','created_at'];
- $header_row .= '<th>ID</th>';
- $header_row .= '<th>'.UOJLocale::get("problems::submitter").'</th>';
- $header_row .= '<th>'.UOJLocale::get('problems::submit time').'</th>';
- $header_row .= '<th> 操作 </th>';
- $header_row .= '</tr>';
- $table_name = 'pastes';
- echoLongTable($col_names, $table_name, "1", 'order by created_at desc', $header_row,
- function($paste) {
- $user = getUserLink($paste['creator']);
- $token = HTML::hiddenToken();
- echo <<<HTML
- <tr>
- <td>
- <a href="/pastes/{$paste['index']}">{$paste['index']}</a>
- </td>
- <td>
- {$user}
- </td>
- <td>
- {$paste['created_at']}
- </td>
- <td>
- <form action="/super-manage/paste" method="post" class="form-horizontal">
- {$token}
- <input type="text" class="form-control" name="paste_deleter_name" id="input-paste_deleter_name" value="{$paste['index']}" style="display: none;">
- <button type="submit" name="submit-paste_deleter" value="paste_deleter" class="btn btn-sm btn-danger" style="margin: 0">删除</button>
- </form>
- </td>
- </tr>
- HTML;
- }, []);
- }
- function echoPasteContent($paste) {
- $zip_file = new ZipArchive();
- $submission_content = json_decode($paste['content'], true);
- $zip_file->open(UOJContext::storagePath().$submission_content['file_name']);
- $config = array();
- foreach ($submission_content['config'] as $config_key => $config_val) {
- $config[$config_val[0]] = $config_val[1];
- }
- $file_content = $zip_file->getFromName("paste.code");
- $file_content = uojTextEncode($file_content, array('allow_CR' => true, 'html_escape' => true));
- $file_language = htmlspecialchars($config["paste_language"]);
- $footer_text = UOJLocale::get('problems::source code').', '.UOJLocale::get('problems::language').': '.$file_language;
- $footer_text .= ", ".UOJLocale::get("problems::submitter") . <<<HTML
- : <a href="/user/profile/${paste['creator']}">${paste['creator']}</a>
- HTML;
- $footer_text .= ", ".UOJLocale::get("problems::submit time").": ".$paste['created_at'];
- switch ($file_language) {
- case 'C++14':
- case 'C++17':
- case 'C++17ubsan':
- $sh_class = 'sh_cpp';
- break;
- case 'Python2':
- case 'Python3':
- $sh_class = 'sh_python';
- break;
- case 'Java8':
- case 'Java11':
- $sh_class = 'sh_java';
- break;
- case 'C':
- $sh_class = 'sh_c';
- break;
- case 'Pascal':
- $sh_class = 'sh_pascal';
- break;
- default:
- $sh_class = '';
- break;
- }
- echo '<div class="card border-info mb-3">';
- echo '<div class="card-header bg-info">';
- echo '<h4 class="card-title">Paste!</h4>';
- echo '</div>';
- echo '<div class="card-body">';
- echo '<pre><code class="'.$sh_class.'">'.$file_content."\n".'</code></pre>';
- echo '</div>';
- echo '<div class="card-footer">'.$footer_text.'</div>';
- echo '</div>';
- $zip_file->close();
- }
- function echoSubmissionContent($submission, $requirement) {
- $zip_file = new ZipArchive();
- $submission_content = json_decode($submission['content'], true);
- $zip_file->open(UOJContext::storagePath().$submission_content['file_name']);
-
- $config = array();
- foreach ($submission_content['config'] as $config_key => $config_val) {
- $config[$config_val[0]] = $config_val[1];
- }
-
- foreach ($requirement as $req) {
- if ($req['type'] == "source code") {
- $file_content = $zip_file->getFromName("{$req['name']}.code");
- $file_content = uojTextEncode($file_content, array('allow_CR' => true, 'html_escape' => true));
- $file_language = htmlspecialchars($config["{$req['name']}_language"]);
- $footer_text = UOJLocale::get('problems::source code').', '.UOJLocale::get('problems::language').': '.$file_language;
- switch ($file_language) {
- case 'C++14':
- case 'C++17':
- case 'C++17ubsan':
- $sh_class = 'sh_cpp';
- break;
- case 'Python2':
- case 'Python3':
- $sh_class = 'sh_python';
- break;
- case 'Java8':
- case 'Java11':
- $sh_class = 'sh_java';
- break;
- case 'C':
- $sh_class = 'sh_c';
- break;
- case 'Pascal':
- $sh_class = 'sh_pascal';
- break;
- default:
- $sh_class = '';
- break;
- }
- echo '<div class="card border-info mb-3">';
- echo '<div class="card-header bg-info">';
- echo '<h4 class="card-title">'.$req['name'].'</h4>';
- echo '</div>';
- echo '<div class="card-body">';
- echo '<pre><code class="'.$sh_class.'">'.$file_content."\n".'</code></pre>';
- echo '</div>';
- echo '<div class="card-footer">'.$footer_text.'</div>';
- echo '</div>';
- } elseif ($req['type'] == "text") {
- $file_content = $zip_file->getFromName("{$req['file_name']}", 504);
- $file_content = strOmit($file_content, 500);
- $file_content = uojTextEncode($file_content, array('allow_CR' => true, 'html_escape' => true));
- $footer_text = UOJLocale::get('problems::text file');
- echo '<div class="card border-info mb-3">';
- echo '<div class="card-header bg-info">';
- echo '<h4 class="card-title">'.$req['file_name'].'</h4>';
- echo '</div>';
- echo '<div class="card-body">';
- echo '<pre>'."\n".$file_content."\n".'</pre>';
- echo '</div>';
- echo '<div class="card-footer">'.$footer_text.'</div>';
- echo '</div>';
- }
- }
- $zip_file->close();
- }
- class JudgementDetailsPrinter {
- private $name;
- private $styler;
- private $dom;
-
- private $subtask_num;
- private function _print_c($node) {
- foreach ($node->childNodes as $child) {
- if ($child->nodeName == '#text') {
- echo htmlspecialchars($child->nodeValue);
- } else {
- $this->_print($child);
- }
- }
- }
- private function _print($node) {
- if ($node->nodeName == 'error') {
- echo "<pre>\n";
- $this->_print_c($node);
- echo "\n</pre>";
- } elseif ($node->nodeName == 'tests') {
- echo '<div id="', $this->name, '_details_accordion">';
- if ($this->styler->show_small_tip) {
- echo '<div class="text-right text-muted">', '小提示:点击横条可展开更详细的信息', '</div>';
- } elseif ($this->styler->ioi_contest_is_running) {
- echo '<div class="text-right text-muted">', 'IOI 赛制比赛中不支持显示详细信息', '</div>';
- }
- $this->_print_c($node);
- echo '</div>';
- } elseif ($node->nodeName == 'subtask') {
- $subtask_num = $node->getAttribute('num');
- $subtask_score = $node->getAttribute('score');
- $subtask_info = $node->getAttribute('info');
-
- echo '<div class="card ', $this->styler->getTestInfoClass($subtask_info), ' mb-3">';
-
- $accordion_parent = "{$this->name}_details_accordion";
- $accordion_collapse = "{$accordion_parent}_collapse_subtask_{$subtask_num}";
- $accordion_collapse_accordion = "{$accordion_collapse}_accordion";
- echo '<div class="card-header" data-toggle="collapse" data-parent="#', $accordion_parent, '" data-target="#', $accordion_collapse, '">';
-
- echo '<div class="row">';
- echo '<div class="col-sm-4">';
- echo '<h3 class="card-title">', 'Subtask #', $subtask_num, ': ', '</h3>';
- echo '</div>';
-
- if ($this->styler->show_score) {
- echo '<div class="col-sm-4">';
- echo '得分:', $subtask_score;
- echo '</div>';
- echo '<div class="col-sm-4">';
- echo htmlspecialchars($subtask_info);
- echo '</div>';
- } else {
- echo '<div class="col-sm-8">';
- echo htmlspecialchars($subtask_info);
- echo '</div>';
- }
- echo '</div>';
- echo '</div>';
-
- echo '<div id="', $accordion_collapse, '" class="card-collapse collapse">';
- echo '<div class="card-body">';
- echo '<div id="', $accordion_collapse_accordion, '">';
- $this->subtask_num = $subtask_num;
- $this->_print_c($node);
- $this->subtask_num = null;
- echo '</div>';
- echo '</div>';
- echo '</div>';
- echo '</div>';
- } elseif ($node->nodeName == 'test') {
- $test_info = $node->getAttribute('info');
- $test_num = $node->getAttribute('num');
- $test_score = $node->getAttribute('score');
- $test_time = $node->getAttribute('time');
- $test_memory = $node->getAttribute('memory');
- echo '<div class="card ', $this->styler->getTestInfoClass($test_info), ' mb-3">';
-
- $accordion_parent = "{$this->name}_details_accordion";
- if ($this->subtask_num != null) {
- $accordion_parent .= "_collapse_subtask_{$this->subtask_num}_accordion";
- }
- $accordion_collapse = "{$accordion_parent}_collapse_test_{$test_num}";
- if (!$this->styler->shouldFadeDetails($test_info)) {
- echo '<div class="card-header" data-toggle="collapse" data-parent="#', $accordion_parent, '" data-target="#', $accordion_collapse, '">';
- } else {
- echo '<div class="card-header">';
- }
- echo '<div class="row">';
- echo '<div class="col-sm-4">';
- if ($test_num > 0) {
- echo '<h4 class="card-title">', 'Test #', $test_num, ': ', '</h4>';
- } else {
- echo '<h4 class="card-title">', 'Extra Test:', '</h4>';
- }
- echo '</div>';
-
- if ($this->styler->show_score) {
- echo '<div class="col-sm-4">';
- echo '得分:', $test_score;
- echo '</div>';
- echo '<div class="col-sm-4">';
- echo htmlspecialchars($test_info);
- echo '</div>';
- } else {
- echo '<div class="col-sm-8">';
- echo htmlspecialchars($test_info);
- echo '</div>';
- }
-
- echo '<div class="col-sm-4">';
- if ($test_time >= 0) {
- echo '时间:', $test_time, 'ms';
- }
- echo '</div>';
- echo '<div class="col-sm-4">';
- if ($test_memory >= 0) {
- echo '内存:', $test_memory, 'kb';
- }
- echo '</div>';
- echo '</div>';
- echo '</div>';
- if (!$this->styler->shouldFadeDetails($test_info)) {
- $accordion_collapse_class = 'card-collapse collapse';
- if ($this->styler->collapse_in) {
- $accordion_collapse_class .= ' in';
- }
- echo '<div id="', $accordion_collapse, '" class="', $accordion_collapse_class, '">';
- echo '<div class="card-body">';
- $this->_print_c($node);
- echo '</div>';
- echo '</div>';
- }
- echo '</div>';
- } elseif ($node->nodeName == 'custom-test') {
- $test_info = $node->getAttribute('info');
- $test_time = $node->getAttribute('time');
- $test_memory = $node->getAttribute('memory');
- echo '<div class="card ', $this->styler->getTestInfoClass($test_info), ' mb-3">';
-
- $accordion_parent = "{$this->name}_details_accordion";
- $accordion_collapse = "{$accordion_parent}_collapse_custom_test";
- if (!$this->styler->shouldFadeDetails($test_info)) {
- echo '<div class="card-header" data-toggle="collapse" data-parent="#', $accordion_parent, '" data-target="#', $accordion_collapse, '">';
- } else {
- echo '<div class="card-header">';
- }
- echo '<div class="row">';
- echo '<div class="col-sm-2">';
- echo '<h4 class="card-title">', '自定义测试:', '</h4>';
- echo '</div>';
-
- echo '<div class="col-sm-4">';
- echo htmlspecialchars($test_info);
- echo '</div>';
-
- echo '<div class="col-sm-3">';
- if ($test_time >= 0) {
- echo '时间:', $test_time, 'ms';
- }
- echo '</div>';
- echo '<div class="col-sm-3">';
- if ($test_memory >= 0) {
- echo '空间:', $test_memory, 'kb';
- }
- echo '</div>';
- echo '</div>';
- echo '</div>';
- if (!$this->styler->shouldFadeDetails($test_info)) {
- $accordion_collapse_class = 'card-collapse collapse';
- if ($this->styler->collapse_in) {
- $accordion_collapse_class .= ' in';
- }
- echo '<div id="', $accordion_collapse, '" class="', $accordion_collapse_class, '">';
- echo '<div class="card-body">';
- $this->_print_c($node);
- echo '</div>';
- echo '</div>';
- echo '</div>';
- }
- } elseif ($node->nodeName == 'in') {
- echo "<h4>标准输入:</h4><pre>\n";
- $this->_print_c($node);
- echo "\n</pre>";
- } elseif ($node->nodeName == 'out') {
- echo "<h4>标准输出:</h4><pre>\n";
- $this->_print_c($node);
- echo "\n</pre>";
- } elseif ($node->nodeName == 'res') {
- echo "<h4>检验结果:</h4><pre>\n";
- $this->_print_c($node);
- echo "\n</pre>";
- } else {
- echo '<', $node->nodeName;
- foreach ($node->attributes as $attr) {
- echo ' ', $attr->name, '="', htmlspecialchars($attr->value), '"';
- }
- echo '>';
- $this->_print_c($node);
- echo '</', $node->nodeName, '>';
- }
- }
- public function __construct($details, $styler, $name) {
- $this->name = $name;
- $this->styler = $styler;
- $this->details = $details;
- $this->dom = new DOMDocument();
- if (!$this->dom->loadXML($this->details)) {
- throw new Exception("XML syntax error");
- }
- $this->details = '';
- }
- public function printHTML() {
- $this->subtask_num = null;
- $this->_print($this->dom->documentElement);
- }
- }
- function echoJudgementDetails($raw_details, $styler, $name) {
- try {
- $printer = new JudgementDetailsPrinter($raw_details, $styler, $name);
- $printer->printHTML();
- } catch (Exception $e) {
- echo 'Failed to show details';
- }
- }
- class SubmissionDetailsStyler {
- public $show_score = true;
- public $show_small_tip = true;
- public $collapse_in = false;
- public $fade_all_details = false;
- public function getTestInfoClass($info) {
- if ($info == 'Accepted' || $info == 'Extra Test Passed') {
- return 'card-uoj-accepted';
- } elseif ($info == 'Time Limit Exceeded') {
- return 'card-uoj-tle';
- } elseif ($info == 'Acceptable Answer') {
- return 'card-uoj-acceptable-answer';
- } else {
- return 'card-uoj-wrong';
- }
- }
- public function shouldFadeDetails($info) {
- return $this->fade_all_details || $info == 'Extra Test Passed';
- }
- }
- class CustomTestSubmissionDetailsStyler {
- public $show_score = true;
- public $show_small_tip = false;
- public $collapse_in = true;
- public $fade_all_details = false;
- public $ioi_contest_is_running = false;
- public function getTestInfoClass($info) {
- if ($info == 'Success') {
- return 'card-uoj-accepted';
- } elseif ($info == 'Time Limit Exceeded') {
- return 'card-uoj-tle';
- } elseif ($info == 'Acceptable Answer') {
- return 'card-uoj-acceptable-answer';
- } else {
- return 'card-uoj-wrong';
- }
- }
- public function shouldFadeDetails($info) {
- return $this->fade_all_details;
- }
- }
- class HackDetailsStyler {
- public $show_score = false;
- public $show_small_tip = false;
- public $collapse_in = true;
- public $fade_all_details = false;
- public function getTestInfoClass($info) {
- if ($info == 'Accepted' || $info == 'Extra Test Passed') {
- return 'card-uoj-accepted';
- } elseif ($info == 'Time Limit Exceeded') {
- return 'card-uoj-tle';
- } elseif ($info == 'Acceptable Answer') {
- return 'card-uoj-acceptable-answer';
- } else {
- return 'card-uoj-wrong';
- }
- }
- public function shouldFadeDetails($info) {
- return $this->fade_all_details;
- }
- }
- function echoSubmissionDetails($submission_details, $name) {
- echoJudgementDetails($submission_details, new SubmissionDetailsStyler(), $name);
- }
- function echoCustomTestSubmissionDetails($submission_details, $name) {
- echoJudgementDetails($submission_details, new CustomTestSubmissionDetailsStyler(), $name);
- }
- function echoHackDetails($hack_details, $name) {
- echoJudgementDetails($hack_details, new HackDetailsStyler(), $name);
- }
- function echoHack($hack, $config, $user) {
- $problem = queryProblemBrief($hack['problem_id']);
- echo '<tr>';
- if (!isset($config['id_hidden'])) {
- echo '<td><a href="/hack/', $hack['id'], '">#', $hack['id'], '</a></td>';
- }
- if (!isset($config['submission_hidden'])) {
- echo '<td><a href="/submission/', $hack['submission_id'], '">#', $hack['submission_id'], '</a></td>';
- }
- if (!isset($config['problem_hidden'])) {
- if ($hack['contest_id']) {
- echo '<td>', getContestProblemLink($problem, $hack['contest_id'], '!id_and_title'), '</td>';
- } else {
- echo '<td>', getProblemLink($problem, '!id_and_title'), '</td>';
- }
- }
- if (!isset($config['hacker_hidden'])) {
- echo '<td>', getUserLink($hack['hacker']), '</td>';
- }
- if (!isset($config['owner_hidden'])) {
- echo '<td>', getUserLink($hack['owner']), '</td>';
- }
- if (!isset($config['result_hidden'])) {
- if ($hack['judge_time'] == null) {
- echo '<td><a href="/hack/', $hack['id'], '">Waiting</a></td>';
- } elseif ($hack['success'] == null) {
- echo '<td><a href="/hack/', $hack['id'], '">Judging</a></td>';
- } elseif ($hack['success']) {
- echo '<td><a href="/hack/', $hack['id'], '" class="uoj-status" data-success="1"><strong>Success!</strong></a></td>';
- } else {
- echo '<td><a href="/hack/', $hack['id'], '" class="uoj-status" data-success="0"><strong>Failed.</strong></a></td>';
- }
- } else {
- echo '<td>Hidden</td>';
- }
- if (!isset($config['submit_time_hidden'])) {
- echo '<td>', $hack['submit_time'], '</td>';
- }
- if (!isset($config['judge_time_hidden'])) {
- echo '<td>', $hack['judge_time'], '</td>';
- }
- echo '</tr>';
- }
- function echoHackListOnlyOne($hack, $config, $user) {
- echo '<div class="table-responsive shadow my-4">';
- echo '<table class="table table-bordered table-text-center">';
- echo '<thead>';
- echo '<tr>';
- if (!isset($config['id_hidden'])) {
- echo '<th>ID</th>';
- }
- if (!isset($config['submission_id_hidden'])) {
- echo '<th>'.UOJLocale::get('problems::submission id').'</th>';
- }
- if (!isset($config['problem_hidden'])) {
- echo '<th>'.UOJLocale::get('problems::problem').'</th>';
- }
- if (!isset($config['hacker_hidden'])) {
- echo '<th>'.UOJLocale::get('problems::hacker').'</th>';
- }
- if (!isset($config['owner_hidden'])) {
- echo '<th>'.UOJLocale::get('problems::owner').'</th>';
- }
- if (!isset($config['result_hidden'])) {
- echo '<th>'.UOJLocale::get('problems::result').'</th>';
- }
- if (!isset($config['submit_time_hidden'])) {
- echo '<th>'.UOJLocale::get('problems::submit time').'</th>';
- }
- if (!isset($config['judge_time_hidden'])) {
- echo '<th>'.UOJLocale::get('problems::judge time').'</th>';
- }
- echo '</tr>';
- echo '</thead>';
- echo '<tbody>';
- echoHack($hack, $config, $user);
- echo '</tbody>';
- echo '</table>';
- echo '</div>';
- }
- function echoHacksList($cond, $tail, $config, $user) {
- $header_row = '<tr>';
- $col_names = array();
-
- $col_names[] = 'id';
- $col_names[] = 'success';
- $col_names[] = 'judge_time';
-
- if (!isset($config['id_hidden'])) {
- $header_row .= '<th>ID</th>';
- }
- if (!isset($config['submission_id_hidden'])) {
- $header_row .= '<th>'.UOJLocale::get('problems::submission id').'</th>';
- $col_names[] = 'submission_id';
- }
- if (!isset($config['problem_hidden'])) {
- $header_row .= '<th>'.UOJLocale::get('problems::problem').'</th>';
- $col_names[] = 'problem_id';
- }
- if (!isset($config['hacker_hidden'])) {
- $header_row .= '<th>'.UOJLocale::get('problems::hacker').'</th>';
- $col_names[] = 'hacker';
- }
- if (!isset($config['owner_hidden'])) {
- $header_row .= '<th>'.UOJLocale::get('problems::owner').'</th>';
- $col_names[] = 'owner';
- }
- if (!isset($config['result_hidden'])) {
- $header_row .= '<th>'.UOJLocale::get('problems::result').'</th>';
- }
- if (!isset($config['submit_time_hidden'])) {
- $header_row .= '<th>'.UOJLocale::get('problems::submit time').'</th>';
- $col_names[] = 'submit_time';
- }
- if (!isset($config['judge_time_hidden'])) {
- $header_row .= '<th>'.UOJLocale::get('problems::judge time').'</th>';
- }
- $header_row .= '</tr>';
- if (!isSuperUser($user)) {
- if ($user != null) {
- $permission_cond = "is_hidden = false or (is_hidden = true and problem_id in (select problem_id from problems_permissions where username = '{$user['username']}'))";
- } else {
- $permission_cond = "is_hidden = false";
- }
- if ($cond !== '1') {
- $cond = "($cond) and ($permission_cond)";
- } else {
- $cond = $permission_cond;
- }
- }
- echoLongTable($col_names, 'hacks', $cond, $tail, $header_row,
- function($hacks) use ($config, $user) {
- echoHack($hacks, $config, $user);
- }, null);
- }
- function echoDatum($datum) {
- $pid = $datum['pid'];
- $title = queryProblemBrief($pid)['title'];
- echo '<tr>';
- echo '<td>' . $datum['id'] . '</td>';
- echo '<td>', getProblemLink(queryProblemBrief($pid), '!id_and_title'), '</td>';
- if ($datum['status'] == 'Done')
- echo '<td><a href="/datum/' . $datum['id'] . '" class="uoj-status" data-success="1"><strong>Done</strong></a></td>';
- else if ($datum['status'] == 'Failed')
- echo '<td><a href="/datum/' . $datum['id'] . '" class="uoj-status" data-success="0"><strong>Failed</strong></a></td>';
- else echo '<td><a href="/datum/' . $datum['id'] . '">' . $datum['status'] . '</a></td>';
-
- echo '<td>' . $datum['request_time'] . '</td>';
- echo '<td>' . $datum['finish_time'] . '</td>';
- echo '<td>' . $datum['timelimit'] . ' s</td>';
- echo '<td>' . $datum['memlimit'] . ' MB</td>';
- echo '</tr>';
- }
- function echoDatumlistOnlyOne($datum) {
- $header_row = '<tr><th>ID</th><th>题目</th><th>状态</th><th>请求时间</th><th>完成时间</th><th>时间限制</th><th>空间限制</th></tr>';
- echo '<div class="table-responsive shadow my-4">';
- echo '<table class="table table-bordered table-text-center">';
- echo '<thead>';
- echo $header_row;
- echo '</thead>';
- echo '<tbody>';
- echoDatum($datum);
- echo '</tbody>';
- echo '</table></div>';
- }
- function echoDatumList() {
- $col_names = array('id', 'pid', 'request_time', 'status', 'finish_time', 'timelimit', 'memlimit');
- $header_row = '<tr><th>ID</th><th>题目</th><th>状态</th><th>请求时间</th><th>完成时间</th><th>时间限制</th><th>空间限制</th></tr>';
- echoLongTable($col_names, 'datum_requests', '1', '', $header_row,
- function($datum) { echoDatum($datum); }, null);
- }
- function getBlogPreview($str) {
- return '';
- }
- function echoBlogCard($blog) {
- if ($blog == null)
- return;
- $bloghref = "/blogs/" . $blog['id'];
- $blogtitle = $blog['title'];
- $poster = queryUser($blog['poster']);
- $blogpreview = getBlogPreview($blog['content']);
- $userlink = getUserLink($blog['poster']);
- $posttime = $blog['post_time'];
- $usermotto = $poster['motto'];
- $zanblock = getClickZanBlock('B', $blog['id'], $blog['zan']);
- return <<<EOF
- <div class="col-12 mb-4">
- <div class="card d-flex p-3 shadow mx-4">
- <div class="align-items-start">
- <a href="$bloghref"><h5>$blogtitle</h5></a>
- <p>$blogpreview</p>
- </div>
- <div class="d-flex align-items-end justify-content-between">
- <div>
- <span class="mb-2">$userlink</span>
- <span class="text-muted">$posttime</span>
- <span class="ml-4">$usermotto</span>
- </div>
- $zanblock
- </div>
- </div>
- </div>
- EOF;
- }
- function echoRecommendProblem($pid, $link, $name, $descr) {
- return <<<EOF
- <div class="col-md-3 mb-4">
- <div class="card h-100 p-3 text-center">
- <a class="mb-2" href="$link"><h4>$pid</h4></a>
- <h4 class="mb-2">$name</h4>
- <span class="text-bottom">$descr</span>
- </div>
- </div>
- EOF;
- }
- function echoBlog($blog, $config = array()) {
- $default_config = array(
- 'blog' => $blog,
- 'show_title_only' => false,
- 'show_content_only' => false,
- 'is_preview' => false,
- 'outside_blog_domain' => false,
- );
- foreach ($default_config as $key => $val) {
- if (!isset($config[$key])) {
- $config[$key] = $val;
- }
- }
- uojIncludeView('blog-preview', $config);
- }
- function echoBlogTag($tag) {
- echo '<a class="uoj-blog-tag"><span class="badge badge-pill badge-secondary">', HTML::escape($tag), '</span></a>';
- }
- function echoUOJPageHeader($page_title, $extra_config = array()) {
- global $REQUIRE_LIB;
- $config = UOJContext::pageConfig();
- $config['REQUIRE_LIB'] = $REQUIRE_LIB;
- $config['PageTitle'] = $page_title;
- $config = array_merge($config, $extra_config);
- uojIncludeView('page-header', $config);
- }
- function echoUOJPageFooter($config = array()) {
- uojIncludeView('page-footer', $config);
- }
- function getAvatar($user) {
- return '<img class="media-object img-rounded" height="50" width="50" src="' . HTML::avatar_addr($user, 50) . '">';
- }
- function echoRanklist($config = array()) {
- $header_row = '';
- $header_row .= '<tr>';
- $header_row .= '<th style="width: 5em;">#</th>';
- $header_row .= '<th style="width: 14em";>'.'头像'.'</th>';
- $header_row .= '<th style="width: 14em;">'.UOJLocale::get('username').'</th>';
- $header_row .= '<th style="width: 50em;">'.UOJLocale::get('motto').'</th>';
- $header_row .= '<th style="width: 5em;">'.UOJLocale::get('rating').'</th>';
- $header_row .= '</tr>';
-
- $users = array();
- $print_row = function($user, $now_cnt) use (&$users) {
- if (!$users) {
- $rank = DB::selectCount("select count(*) from user_info where rating > {$user['rating']}") + 1;
- } elseif ($user['rating'] == $users[count($users) - 1]['rating']) {
- $rank = $users[count($users) - 1]['rank'];
- } else {
- $rank = $now_cnt;
- }
-
- $user['rank'] = $rank;
-
- echo '<tr>';
- echo '<td>' . $user['rank'] . '</td>';
- echo '<td>' . getAvatar($user) . '</td>';
- echo '<td>' . getUserLink($user['username']) . '</td>';
- echo '<td>' . HTML::escape($user['motto']) . '</td>';
- echo '<td>' . $user['rating'] . '</td>';
- echo '</tr>';
-
- $users[] = $user;
- };
- $col_names = array('username', 'email', 'qq', 'rating', 'motto');
- $tail = 'order by rating desc, username asc';
-
- if (isset($config['top10'])) {
- $tail .= ' limit 10';
- }
-
- $config['get_row_index'] = '';
- echoLongTable($col_names, 'user_info', '1', $tail, $header_row, $print_row, $config);
- }
|