| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542 |
- <?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 . '">' . HTML::escape($rp['title']) . '</a>';
- }
- function getProblemLink($problem, $problem_title = '!title_only') {
- if ($problem_title == '!title_only') {
- $problem_title = HTML::escape($problem['title']);
- } elseif ($problem_title == '!id_and_title') {
- $problem_title = "#${problem['id']}. " . HTML::escape($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 = HTML::escape($problem['title']);
- } elseif ($problem_title == '!id_and_title') {
- $problem_title = "#{$problem['id']}. " . HTML::escape($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><th>题目</th></tr>', queryUserExtgroups($user), function($grp) {
- $qp = queryUser($grp);
- $link = getUserLink($qp['username']);
- $name = HTML::escape($qp['email']);
- echo <<<HTML
- <tr>
- <td>$link</td>
- <td>$name</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 = HTML::escape($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 = HTML::escape($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><th>管理</th></tr>', queryUserCtrlgroups($user), function($grp) {
- $qp = queryUser($grp);
- $link = getUserLink($qp['username']);
- $name = HTML::escape($qp['email']);
- echo <<<HTML
- <tr>
- <td>$link</td>
- <td>$name</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) {
- $token = HTML::hiddenToken();
- $col = explode('#', $certs)[0];
- $text = HTML::escape(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">
- {$token}
- <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, $options = array()) {
- static $uoj_submission_content_seq = 0;
- $collapsible = isset($options['collapsible']) && $options['collapsible'];
- $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">';
- if ($collapsible) {
- $uoj_submission_content_seq++;
- $fold_id = 'uoj-code-'.$submission['id'].'-'.$uoj_submission_content_seq;
- echo '<button type="button" class="btn btn-sm btn-outline-secondary uoj-code-toggle" id="', $fold_id, '_toggle" aria-haspopup="dialog">', '查看源代码', '</button>';
- echo '<div class="uoj-modal" id="', $fold_id, '_modal" hidden>';
- echo '<div class="uoj-modal-backdrop" data-uoj-modal-close></div>';
- echo '<div class="uoj-modal-window" role="dialog" aria-modal="true" aria-label="', '源代码', '">';
- echo '<button type="button" class="uoj-modal-close" data-uoj-modal-close aria-label="', '关闭', '">×</button>';
- echo '<div class="uoj-modal-body">';
- echo '<div class="text-muted uoj-code-meta">'.$footer_text.'</div>';
- echo '<pre><code class="'.$sh_class.'">'.$file_content."\n".'</code></pre>';
- echo '</div>';
- echo '</div>';
- echo '</div>';
- echoUOJModalHelper();
- echo '<script type="text/javascript">';
- echo '(function(){var b=document.getElementById(', json_encode($fold_id.'_toggle'), '),m=document.getElementById(', json_encode($fold_id.'_modal'), ');';
- echo 'if(!b||!m||!window.uojModalInit){return;}';
- echo 'var api=window.uojModalInit(m);';
- echo 'b.addEventListener("click",function(){api.open();});';
- echo '})();';
- echo '</script>';
- } else {
- 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();
- }
- // Shared vanilla-JS modal helper. Emitted at most once per request, and it is
- // also guarded in JS, so both the test-detail modal and the source-code modal
- // can use it independently (a page with only one of them still works).
- function echoUOJModalHelper() {
- static $emitted = false;
- if ($emitted) {
- return;
- }
- $emitted = true;
- echo <<<'UOJMODAL'
- <script type="text/javascript">
- if (typeof window.uojModalInit !== 'function') {
- window.uojModalInit = function (modal) {
- var win = modal.querySelector('.uoj-modal-window');
- var api = {
- lastFocus: null,
- body: modal.querySelector('.uoj-modal-body'),
- open: function () {
- if (!modal.hidden) {
- return;
- }
- if (window.uojModalCurrent && window.uojModalCurrent !== api) {
- window.uojModalCurrent.close();
- }
- api.lastFocus = document.activeElement;
- modal.hidden = false;
- document.body.classList.add('uoj-modal-open');
- window.uojModalCurrent = api;
- var btn = modal.querySelector('.uoj-modal-close');
- if (btn && btn.focus) {
- btn.focus();
- }
- },
- close: function () {
- if (modal.hidden) {
- return;
- }
- modal.hidden = true;
- if (window.uojModalCurrent === api) {
- window.uojModalCurrent = null;
- }
- if (!window.uojModalCurrent) {
- document.body.classList.remove('uoj-modal-open');
- }
- if (api.lastFocus && api.lastFocus.focus) {
- api.lastFocus.focus();
- }
- }
- };
- modal.addEventListener('click', function (e) {
- if (e.target === modal || (e.target.getAttribute && e.target.getAttribute('data-uoj-modal-close') !== null)) {
- api.close();
- }
- });
- document.addEventListener('keydown', function (e) {
- if ((e.key === 'Escape' || e.keyCode === 27) && !modal.hidden) {
- api.close();
- }
- });
- return api;
- };
- }
- </script>
- UOJMODAL;
- }
- class JudgementDetailsPrinter {
- private $name;
- private $styler;
- private $dom;
- private $subtask_num;
- private $prefix;
- private $blocks = array();
- private $pending_tests = array();
- private $bodies = array();
- private $body_seq = 0;
- private $rect_seq = 0;
- private $auto_select_id = null;
- private static $instance_seq = 0;
- 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 == '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, '>';
- }
- }
- private function getVerdictAbbr($info) {
- $info = trim($info);
- $map = array(
- 'Accepted' => 'AC',
- 'Extra Test Passed' => 'AC',
- 'Success' => 'AC',
- 'Acceptable Answer' => 'AC',
- 'Wrong Answer' => 'WA',
- 'Time Limit Exceeded' => 'TLE',
- 'Memory Limit Exceeded' => 'MLE',
- 'Runtime Error' => 'RE',
- 'Output Limit Exceeded' => 'OLE',
- 'Dangerous Syscalls' => 'DGS',
- 'Judgement Failed' => 'JGF',
- 'No Comment' => '?',
- );
- if ($info === '') {
- return '?';
- }
- if (isset($map[$info])) {
- return $map[$info];
- }
- $words = preg_split('/\s+/', $info, -1, PREG_SPLIT_NO_EMPTY);
- if (count($words) > 1) {
- $abbr = '';
- foreach ($words as $word) {
- $abbr .= strtoupper(substr($word, 0, 1));
- if (strlen($abbr) >= 4) {
- break;
- }
- }
- if ($abbr !== '') {
- return substr($abbr, 0, 4);
- }
- }
- if (function_exists('mb_substr')) {
- return strtoupper(mb_substr($info, 0, 4, 'UTF-8'));
- }
- return strtoupper(substr($info, 0, 4));
- }
- private function getVerdictClass($info) {
- $info = trim($info);
- if ($info == 'Accepted' || $info == 'Extra Test Passed' || $info == 'Success' || $info == 'Acceptable Answer') {
- return 'uoj-test-rect-ac';
- }
- if ($info == 'Wrong Answer') {
- return 'uoj-test-rect-wa';
- }
- return 'uoj-test-rect-other';
- }
- private function collectBlocks($node) {
- foreach ($node->childNodes as $child) {
- if ($child->nodeType != XML_ELEMENT_NODE) {
- continue;
- }
- if ($child->nodeName == 'subtask') {
- $this->flushPendingTests();
- $this->blocks[] = array('type' => 'subtask', 'node' => $child);
- } elseif ($child->nodeName == 'test' || $child->nodeName == 'custom-test') {
- $this->pending_tests[] = $child;
- } elseif ($child->nodeName == 'error') {
- $this->flushPendingTests();
- $this->blocks[] = array('type' => 'error', 'node' => $child);
- } else {
- $this->collectBlocks($child);
- }
- }
- }
- private function flushPendingTests() {
- if (count($this->pending_tests)) {
- $this->blocks[] = array('type' => 'tests', 'nodes' => $this->pending_tests);
- $this->pending_tests = array();
- }
- }
- private function collectRoot($node) {
- if ($node->nodeName == 'subtask') {
- $this->blocks[] = array('type' => 'subtask', 'node' => $node);
- } elseif ($node->nodeName == 'test' || $node->nodeName == 'custom-test') {
- $this->pending_tests[] = $node;
- } elseif ($node->nodeName == 'error') {
- $this->blocks[] = array('type' => 'error', 'node' => $node);
- } else {
- $this->collectBlocks($node);
- }
- }
- private function renderRect($node) {
- $info = trim($node->getAttribute('info'));
- $num = $node->getAttribute('num');
- $time = $node->getAttribute('time');
- $memory = $node->getAttribute('memory');
- $this->rect_seq++;
- if ($num !== '' && is_numeric($num)) {
- $num_text = ((int)$num > 0) ? ('#' . (int)$num) : 'Extra';
- } else {
- $num_text = '#' . $this->rect_seq;
- }
- // The verdict abbreviation is always the label. UOJ stores a per-test
- // point value in score="..." (e.g. 10 on every test of an ACM problem),
- // so it is NOT a partial-credit signal and must never replace the
- // verdict (see the subtask header for the per-subtask score instead).
- $label = $this->getVerdictAbbr($info);
- $meta = array();
- if ($time !== '' && is_numeric($time) && $time >= 0) {
- $meta[] = $time . 'ms';
- }
- if ($memory !== '' && is_numeric($memory) && $memory >= 0) {
- $meta[] = $memory . 'kb';
- }
- $class = $this->getVerdictClass($info);
- $title = (strlen($num_text) && $num_text[0] === '#') ? trim($num_text . ' ' . $info) : $info;
- if ($this->styler->shouldFadeDetails($info)) {
- echo '<div class="uoj-test-rect ', $class, ' is-disabled" title="', htmlspecialchars($title), '">';
- } else {
- $body_id = $this->prefix . '_body_' . (++$this->body_seq);
- $this->bodies[$body_id] = $node;
- $auto_attr = '';
- if ($this->styler->collapse_in && $this->auto_select_id === null) {
- $this->auto_select_id = $body_id;
- $auto_attr = ' data-auto="1"';
- }
- echo '<div class="uoj-test-rect ', $class, '" role="button" tabindex="0" data-target="', $body_id, '"', $auto_attr, ' title="', htmlspecialchars($title), '">';
- }
- echo '<span class="uoj-test-rect-index">', htmlspecialchars($num_text), '</span>';
- echo '<span class="uoj-test-rect-verdict">', htmlspecialchars($label), '</span>';
- foreach ($meta as $meta_part) {
- echo '<span class="uoj-test-rect-meta">', htmlspecialchars($meta_part), '</span>';
- }
- echo '</div>';
- }
- private function renderSubtask($node) {
- $num = $node->getAttribute('num');
- $score = $node->getAttribute('score');
- $tests = array();
- $sum = 0;
- $has_test_score = false;
- foreach ($node->childNodes as $child) {
- if ($child->nodeType != XML_ELEMENT_NODE) {
- continue;
- }
- if ($child->nodeName != 'test' && $child->nodeName != 'custom-test') {
- continue;
- }
- $tests[] = $child;
- $test_score = $child->getAttribute('score');
- if ($test_score !== '' && is_numeric($test_score)) {
- $sum += $test_score + 0;
- $has_test_score = true;
- }
- }
- echo '<div class="uoj-test-group uoj-test-group-subtask">';
- echo '<div class="uoj-test-subtask-head">Subtask #', htmlspecialchars($num);
- if ($this->styler->show_score) {
- if ($score !== '') {
- echo ' · ', htmlspecialchars($score);
- }
- if ($has_test_score) {
- echo ' / ', htmlspecialchars(rtrim(rtrim(sprintf('%.2f', $sum), '0'), '.'));
- }
- }
- echo '</div>';
- echo '<div class="uoj-test-rects">';
- foreach ($tests as $test) {
- $this->renderRect($test);
- }
- echo '</div>';
- echo '</div>';
- }
- private function renderGrid() {
- echo '<div class="uoj-details-wrap" id="', $this->prefix, '_wrap">';
- // Only once per page: a two-phase submission (pretest + final test) runs
- // this printer twice, and showing the same tip above both grids was
- // confusing. static so it spans every instance in this request.
- static $tip_shown = false;
- if (!$tip_shown && $this->styler->show_small_tip) {
- $tip_shown = true;
- echo '<div class="text-right text-muted uoj-details-tip">', '小提示:点击方块,在弹出的窗口中查看该测试点的详细信息', '</div>';
- } elseif (!$tip_shown && !empty($this->styler->ioi_contest_is_running)) {
- $tip_shown = true;
- echo '<div class="text-right text-muted uoj-details-tip">', 'IOI 赛制比赛中不支持显示详细信息', '</div>';
- }
- echo '<div class="uoj-test-grid">';
- foreach ($this->blocks as $block) {
- if ($block['type'] == 'error') {
- echo '<div class="uoj-details-error">';
- $this->_print($block['node']);
- echo '</div>';
- } elseif ($block['type'] == 'subtask') {
- $this->renderSubtask($block['node']);
- } else {
- echo '<div class="uoj-test-group">';
- foreach ($block['nodes'] as $test) {
- $this->renderRect($test);
- }
- echo '</div>';
- }
- }
- echo '</div>';
- if (count($this->bodies)) {
- echo '<div class="uoj-modal" id="', $this->prefix, '_modal" hidden>';
- echo '<div class="uoj-modal-backdrop" data-uoj-modal-close></div>';
- echo '<div class="uoj-modal-window" role="dialog" aria-modal="true" aria-label="', '测试点详细信息', '">';
- echo '<button type="button" class="uoj-modal-close" data-uoj-modal-close aria-label="', '关闭', '">×</button>';
- echo '<div class="uoj-modal-body" id="', $this->prefix, '_modal_body">';
- foreach ($this->bodies as $body_id => $test) {
- echo '<div class="uoj-test-body" id="', $body_id, '" hidden>';
- $this->_print_c($test);
- echo '</div>';
- }
- echo '</div>';
- echo '</div>';
- echo '</div>';
- }
- echo '</div>';
- }
- private function renderScript() {
- if (!count($this->bodies)) {
- return;
- }
- echoUOJModalHelper();
- $wrap = $this->prefix . '_wrap';
- $modal = $this->prefix . '_modal';
- echo '<script type="text/javascript">';
- echo '(function(){';
- echo 'var wrap=document.getElementById(', json_encode($wrap), ');';
- echo 'var modal=document.getElementById(', json_encode($modal), ');';
- echo 'if(!wrap||!modal||!window.uojModalInit){return;}';
- echo 'var api=window.uojModalInit(modal);';
- echo 'var body=api.body;';
- echo 'var rects=wrap.querySelectorAll(".uoj-test-rect[data-target]");';
- echo 'function show(rect){';
- echo 'var target=document.getElementById(rect.getAttribute("data-target"));';
- echo 'if(!target){return;}';
- echo 'var bodies=body.querySelectorAll(".uoj-test-body");';
- echo 'for(var i=0;i<bodies.length;i++){bodies[i].hidden=true;}';
- echo 'target.hidden=false;';
- echo 'for(var i=0;i<rects.length;i++){';
- echo 'if(rects[i]===rect){rects[i].classList.add("is-selected");}else{rects[i].classList.remove("is-selected");}';
- echo '}';
- echo '}';
- echo 'for(var i=0;i<rects.length;i++){(function(rect){';
- echo 'rect.addEventListener("click",function(){show(rect);api.open();});';
- echo 'rect.addEventListener("keydown",function(e){if(e.key==="Enter"||e.key===" "){e.preventDefault();show(rect);api.open();}});';
- echo '})(rects[i]);}';
- echo 'var auto=wrap.querySelector(".uoj-test-rect[data-auto=\"1\"]");';
- echo 'if(auto){show(auto);api.open();}';
- echo '})();';
- echo '</script>';
- }
- 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->prefix = $this->name . '_' . (++self::$instance_seq);
- $root = $this->dom->documentElement;
- if ($root->nodeName == 'error') {
- $this->_print($root);
- return;
- }
- $this->collectRoot($root);
- $this->flushPendingTests();
- $this->renderGrid();
- $this->renderScript();
- }
- }
- 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']);
- $userlink = getUserLink($blog['poster']);
- $posttime = $blog['post_time'];
- $usermotto = HTML::escape($poster['motto']);
- $zanblock = getClickZanBlock('B', $blog['id'], $blog['zan']);
- $avatar = "https://q.qlogo.cn/g?b=qq&nk=" . $poster['qq'] . "&s=100";
- return <<<EOF
- <div class="col-12 mb-3">
- <div class="card wyoj-blog-card border-0 shadow-sm">
- <div class="card-body p-3">
- <a href="$bloghref" class="text-decoration-none text-dark">
- <h5 class="mb-3 wyoj-blog-title">$blogtitle</h5>
- </a>
- <div class="d-flex align-items-center justify-content-between">
- <div class="d-flex align-items-center" style="min-width:0;">
- <img class="uoj-avatar rounded-circle flex-shrink-0 mr-2"
- style="width:28px;height:28px;object-fit:cover;"
- src="$avatar" alt="...">
- <span class="text-truncate">$userlink</span>
- <span class="text-muted ml-2 text-nowrap" style="font-size:0.85rem;">$posttime</span>
- <span class="ml-3 text-truncate" style="font-size:1rem;font-family:'SimSun','宋体','Songti SC','STSong',serif;">$usermotto</span>
- </div>
- <div class="flex-shrink-0 ml-2">$zanblock</div>
- </div>
- </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();
- $relcnt = 0;
- $print_row = function($user, $now_cnt) use (&$users, &$relcnt) {
- #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;
- $relcnt++;
-
- echo '<tr>';
- echo '<td>' . $user['rank'] . ' (' . $relcnt . ')</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 = 'inner join contests_registrants c on user_info.username = c.username inner join contests s on s.id = c.contest_id where datediff(now(), s.start_time) <= 180 group by c.username having cnt >= 3 order by rating desc, username asc';
- # $tail = 'order by rating desc, username asc';
- #
- $config['raw_sql'] = 'select u.username, u.email, u.rating, u.rating_rd, u.rating_vol, u.motto, u.qq, count(*) cnt from user_info u inner join contests_registrants c on u.username = c.username inner join contests s on s.id = c.contest_id where datediff(now(), s.start_time) <= 180 group by c.username having cnt >= 3 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);
- }
|