1
0
mirror of https://github.com/renbaoshuo/UOJ-Luogu-RemoteJudge.git synced 2024-11-23 19:18:43 +00:00

feat: fetch problem from luogu

This commit is contained in:
Baoshuo Ren 2023-03-20 15:03:25 +08:00
parent b3a8b003f7
commit b8e84f43f1
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
9 changed files with 730 additions and 5 deletions

View File

@ -1,3 +1,9 @@
# 安装
## 前期准备
请先在服务器上安装 Node.js 18 LTS 和 `php-curl`
## 修改源码
_TODO_

View File

@ -0,0 +1,279 @@
<?php
requirePHPLib('form');
requirePHPLib('judger');
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
become404Page();
}
$problem_content = queryProblemContent($problem['id']);
$contest = validateUInt($_GET['contest_id']) ? queryContest($_GET['contest_id']) : null;
if ($contest != null) {
genMoreContestInfo($contest);
$problem_rank = queryContestProblemRank($contest, $problem);
if ($problem_rank == null) {
become404Page();
} else {
$problem_letter = chr(ord('A') + $problem_rank - 1);
}
}
$is_in_contest = false;
$ban_in_contest = false;
if ($contest != null) {
if (!hasContestPermission($myUser, $contest)) {
if ($contest['cur_progress'] == CONTEST_NOT_STARTED) {
become404Page();
} elseif ($contest['cur_progress'] == CONTEST_IN_PROGRESS) {
if ($myUser == null || !hasRegistered($myUser, $contest)) {
becomeMsgPage("<h1>比赛正在进行中</h1><p>很遗憾,您尚未报名。比赛结束后再来看吧~</p>");
} else {
$is_in_contest = true;
DB::update("update contests_registrants set has_participated = 1 where username = '{$myUser['username']}' and contest_id = {$contest['id']}");
}
} else {
$ban_in_contest = !isProblemVisibleToUser($problem, $myUser);
}
}
} else {
if (!isProblemVisibleToUser($problem, $myUser)) {
become404Page();
}
}
$submission_requirement = json_decode($problem['submission_requirement'], true);
$problem_extra_config = getProblemExtraConfig($problem);
$custom_test_requirement = getProblemCustomTestRequirement($problem);
if ($custom_test_requirement && Auth::check()) {
$custom_test_submission = DB::selectFirst("select * from custom_test_submissions where submitter = '".Auth::id()."' and problem_id = {$problem['id']} order by id desc limit 1");
$custom_test_submission_result = json_decode($custom_test_submission['result'], true);
}
if ($custom_test_requirement && $_GET['get'] == 'custom-test-status-details' && Auth::check()) {
if ($custom_test_submission == null) {
echo json_encode(null);
} elseif ($custom_test_submission['status'] != 'Judged') {
echo json_encode(array(
'judged' => false,
'html' => getSubmissionStatusDetails($custom_test_submission)
));
} else {
ob_start();
$styler = new CustomTestSubmissionDetailsStyler();
if (!hasViewPermission($problem_extra_config['view_details_type'], $myUser, $problem, $submission)) {
$styler->fade_all_details = true;
}
echoJudgementDetails($custom_test_submission_result['details'], $styler, 'custom_test_details');
$result = ob_get_contents();
ob_end_clean();
echo json_encode(array(
'judged' => true,
'html' => getSubmissionStatusDetails($custom_test_submission),
'result' => $result
));
}
die();
}
$can_use_zip_upload = true;
foreach ($submission_requirement as $req) {
if ($req['type'] == 'source code') {
$can_use_zip_upload = false;
}
}
function handleUpload($zip_file_name, $content, $tot_size) {
global $problem, $contest, $myUser, $is_in_contest;
$content['config'][] = array('problem_id', $problem['id']);
if ($is_in_contest && $contest['extra_config']["contest_type"]!='IOI' && !isset($contest['extra_config']["problem_{$problem['id']}"])) {
$content['final_test_config'] = $content['config'];
$content['config'][] = array('test_sample_only', 'on');
}
$esc_content = DB::escape(json_encode($content));
$language = '/';
foreach ($content['config'] as $row) {
if (strEndWith($row[0], '_language')) {
$language = $row[1];
break;
}
}
if ($language != '/') {
Cookie::set('uoj_preferred_language', $language, time() + 60 * 60 * 24 * 365, '/');
}
$esc_language = DB::escape($language);
$result = array();
$result['status'] = "Waiting";
$result_json = json_encode($result);
if ($is_in_contest) {
DB::query("insert into submissions (problem_id, contest_id, submit_time, submitter, content, language, tot_size, status, result, is_hidden) values (${problem['id']}, ${contest['id']}, now(), '${myUser['username']}', '$esc_content', '$esc_language', $tot_size, '${result['status']}', '$result_json', 0)");
} else {
DB::query("insert into submissions (problem_id, submit_time, submitter, content, language, tot_size, status, result, is_hidden) values (${problem['id']}, now(), '${myUser['username']}', '$esc_content', '$esc_language', $tot_size, '${result['status']}', '$result_json', {$problem['is_hidden']})");
}
}
function handleCustomTestUpload($zip_file_name, $content, $tot_size) {
global $problem, $contest, $myUser;
$content['config'][] = array('problem_id', $problem['id']);
$content['config'][] = array('custom_test', 'on');
$esc_content = DB::escape(json_encode($content));
$language = '/';
foreach ($content['config'] as $row) {
if (strEndWith($row[0], '_language')) {
$language = $row[1];
break;
}
}
if ($language != '/') {
Cookie::set('uoj_preferred_language', $language, time() + 60 * 60 * 24 * 365, '/');
}
$esc_language = DB::escape($language);
$result = array();
$result['status'] = "Waiting";
$result_json = json_encode($result);
DB::insert("insert into custom_test_submissions (problem_id, submit_time, submitter, content, status, result) values ({$problem['id']}, now(), '{$myUser['username']}', '$esc_content', '{$result['status']}', '$result_json')");
}
if ($can_use_zip_upload) {
$zip_answer_form = newZipSubmissionForm('zip_answer',
$submission_requirement,
'uojRandAvaiableSubmissionFileName',
'handleUpload');
$zip_answer_form->extra_validator = function() {
global $ban_in_contest;
if ($ban_in_contest) {
return '请耐心等待比赛结束后题目对所有人可见了再提交';
}
return '';
};
$zip_answer_form->succ_href = $is_in_contest ? "/contest/{$contest['id']}/submissions" : '/submissions';
$zip_answer_form->runAtServer();
}
$answer_form = newSubmissionForm('answer',
$submission_requirement,
'uojRandAvaiableSubmissionFileName',
'handleUpload');
$answer_form->extra_validator = function() {
global $ban_in_contest;
if ($ban_in_contest) {
return '请耐心等待比赛结束后题目对所有人可见了再提交';
}
return '';
};
$answer_form->succ_href = $is_in_contest ? "/contest/{$contest['id']}/submissions" : '/submissions';
$answer_form->runAtServer();
if ($custom_test_requirement) {
$custom_test_form = newSubmissionForm('custom_test',
$custom_test_requirement,
function() {
return uojRandAvaiableFileName('/tmp/');
},
'handleCustomTestUpload');
$custom_test_form->appendHTML(<<<EOD
<div id="div-custom_test_result"></div>
EOD
);
$custom_test_form->succ_href = 'none';
$custom_test_form->extra_validator = function() {
global $ban_in_contest, $custom_test_submission;
if ($ban_in_contest) {
return '请耐心等待比赛结束后题目对所有人可见了再提交';
}
if ($custom_test_submission && $custom_test_submission['status'] != 'Judged') {
return '上一个测评尚未结束';
}
return '';
};
$custom_test_form->ctrl_enter_submit = true;
$custom_test_form->setAjaxSubmit(<<<EOD
function(response_text) {custom_test_onsubmit(response_text, $('#div-custom_test_result')[0], '{$_SERVER['REQUEST_URI']}?get=custom-test-status-details')}
EOD
);
$custom_test_form->submit_button_config['text'] = UOJLocale::get('problems::run');
$custom_test_form->runAtServer();
}
?>
<?php
$REQUIRE_LIB['mathjax'] = '';
$REQUIRE_LIB['shjs'] = '';
?>
<?php echoUOJPageHeader(HTML::stripTags($problem['title']) . ' - ' . UOJLocale::get('problems::problem')) ?>
<?php
if ($problem['type'] == 'luogu') {
$time_limit = $problem_extra_config['time_limit'];
$memory_limit = $problem_extra_config['memory_limit'];
} else {
$limit = getUOJConf("/var/uoj_data/{$problem['id']}/problem.conf");
$time_limit = $limit['time_limit'];
$memory_limit = $limit['memory_limit'];
}
?>
<div class="row d-flex justify-content-center">
<span class="badge badge-secondary mr-1">时间限制:<?=$time_limit!=null?"$time_limit s":"N/A"?></span>
<span class="badge badge-secondary mr-1">空间限制:<?=$memory_limit!=null?"$memory_limit MB":"N/A"?></span>
</div>
<div class="float-right">
<?= getClickZanBlock('P', $problem['id'], $problem['zan']) ?>
</div>
<?php if ($contest): ?>
<div class="page-header row">
<h1 class="col-md-3 text-left"><small><?= $contest['name'] ?></small></h1>
<h1 class="col-md-7 text-center"><?= $problem_letter ?>. <?= $problem['title'] ?></h1>
<div class="col-md-2 text-right" id="contest-countdown"></div>
</div>
<a role="button" class="btn btn-info float-right" href="/contest/<?= $contest['id'] ?>/problem/<?= $problem['id'] ?>/statistics"><span class="glyphicon glyphicon-stats"></span> <?= UOJLocale::get('problems::statistics') ?></a>
<?php if ($contest['cur_progress'] <= CONTEST_IN_PROGRESS): ?>
<script type="text/javascript">
checkContestNotice(<?= $contest['id'] ?>, '<?= UOJTime::$time_now_str ?>');
$('#contest-countdown').countdown(<?= $contest['end_time']->getTimestamp() - UOJTime::$time_now->getTimestamp() ?>);
</script>
<?php endif ?>
<?php else: ?>
<h1 class="page-header text-center">#<?= $problem['id']?>. <?= $problem['title'] ?></h1>
<a role="button" class="btn btn-info float-right" href="/problem/<?= $problem['id'] ?>/statistics"><span class="glyphicon glyphicon-stats"></span> <?= UOJLocale::get('problems::statistics') ?></a>
<?php endif ?>
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item"><a class="nav-link active" href="#tab-statement" role="tab" data-toggle="tab"><span class="glyphicon glyphicon-book"></span> <?= UOJLocale::get('problems::statement') ?></a></li>
<li class="nav-item"><a class="nav-link" href="#tab-submit-answer" role="tab" data-toggle="tab"><span class="glyphicon glyphicon-upload"></span> <?= UOJLocale::get('problems::submit') ?></a></li>
<?php if ($custom_test_requirement): ?>
<li class="nav-item"><a class="nav-link" href="#tab-custom-test" role="tab" data-toggle="tab"><span class="glyphicon glyphicon-console"></span> <?= UOJLocale::get('problems::custom test') ?></a></li>
<?php endif ?>
<?php if (hasProblemPermission($myUser, $problem)): ?>
<li class="nav-item"><a class="nav-link" href="/problem/<?= $problem['id'] ?>/manage/statement" role="tab"><?= UOJLocale::get('problems::manage') ?></a></li>
<?php endif ?>
<?php if ($contest): ?>
<li class="nav-item"><a class="nav-link" href="/contest/<?= $contest['id'] ?>" role="tab"><?= UOJLocale::get('contests::back to the contest') ?></a></li>
<?php endif ?>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab-statement">
<article class="top-buffer-md"><?= $problem_content['statement'] ?></article>
</div>
<div class="tab-pane" id="tab-submit-answer">
<div class="top-buffer-sm"></div>
<?php if ($can_use_zip_upload): ?>
<?php $zip_answer_form->printHTML(); ?>
<hr />
<strong><?= UOJLocale::get('problems::or upload files one by one') ?><br /></strong>
<?php endif ?>
<?php $answer_form->printHTML(); ?>
</div>
<?php if ($custom_test_requirement): ?>
<div class="tab-pane" id="tab-custom-test">
<div class="top-buffer-sm"></div>
<?php $custom_test_form->printHTML(); ?>
</div>
<?php endif ?>
</div>
<?php echoUOJPageFooter() ?>

View File

@ -0,0 +1,17 @@
--- UOJ-System/web/app/controllers/problem.php 2022-12-30 09:54:05.452022649 +0800
+++ UOJ-Luogu-RemoteJudge/web/app/controllers/problem.php 2023-03-20 15:01:32.363789172 +0800
@@ -208,9 +208,14 @@
?>
<?php echoUOJPageHeader(HTML::stripTags($problem['title']) . ' - ' . UOJLocale::get('problems::problem')) ?>
<?php
+if ($problem['type'] == 'luogu') {
+ $time_limit = $problem_extra_config['time_limit'];
+ $memory_limit = $problem_extra_config['memory_limit'];
+} else {
$limit = getUOJConf("/var/uoj_data/{$problem['id']}/problem.conf");
$time_limit = $limit['time_limit'];
$memory_limit = $limit['memory_limit'];
+}
?>
<div class="row d-flex justify-content-center">
<span class="badge badge-secondary mr-1">时间限制:<?=$time_limit!=null?"$time_limit s":"N/A"?></span>

View File

@ -0,0 +1,224 @@
<?php
requirePHPLib('form');
requirePHPLib('judger');
requirePHPLib('data');
requirePHPLib('luogu');
if (isSuperUser($myUser)) {
$new_problem_form = new UOJForm('new_problem');
$new_problem_form->handle = function() {
DB::query("insert into problems (title, is_hidden, submission_requirement) values ('New Problem', 1, '{}')");
$id = DB::insert_id();
DB::query("insert into problems_contents (id, statement, statement_md) values ($id, '', '')");
dataNewProblem($id);
};
$new_problem_form->submit_button_config['align'] = 'right';
$new_problem_form->submit_button_config['class_str'] = 'btn btn-primary';
$new_problem_form->submit_button_config['text'] = UOJLocale::get('problems::add new');
$new_problem_form->submit_button_config['smart_confirm'] = '';
$new_problem_form->runAtServer();
$new_luogu_problem_form = new UOJForm('new_luogu_problem');
$new_luogu_problem_form->addVInput('luogu_pid', 'text', '洛谷题号', '', function($id) {
if (!validateLuoguProblemId($id)) {
return '题目 ID 不合法';
}
return '';
}, null);
$new_luogu_problem_form->handle = function() {
try {
newLuoguRemoteProblem($_POST['luogu_pid']);
} catch (Exception $e) {
becomeMsgPage('<h2>添加失败</h2><pre>' . $e->getMessage() . '</pre>');
}
};
// $new_luogu_problem_form->submit_button_config['align'] = 'right';
$new_luogu_problem_form->submit_button_config['class_str'] = 'btn btn-primary';
$new_luogu_problem_form->submit_button_config['text'] = UOJLocale::get('problems::add new');
$new_luogu_problem_form->submit_button_config['confirm'] = '新增来自洛谷的题目';
$new_luogu_problem_form->runAtServer();
}
function echoProblem($problem) {
global $myUser;
if (isProblemVisibleToUser($problem, $myUser)) {
echo '<tr class="text-center">';
if ($problem['submission_id']) {
echo '<td class="success">';
} else {
echo '<td>';
}
echo '#', $problem['id'], '</td>';
echo '<td class="text-left">';
if ($problem['is_hidden']) {
echo ' <span class="text-danger">[隐藏]</span> ';
}
echo '<a href="/problem/', $problem['id'], '">', $problem['title'], '</a>';
if (isset($_COOKIE['show_tags_mode'])) {
foreach (queryProblemTags($problem['id']) as $tag) {
echo '<a class="uoj-problem-tag">', '<span class="badge badge-pill badge-secondary">', HTML::escape($tag), '</span>', '</a>';
}
}
echo '</td>';
if (isset($_COOKIE['show_submit_mode'])) {
$perc = $problem['submit_num'] > 0 ? round(100 * $problem['ac_num'] / $problem['submit_num']) : 0;
echo <<<EOD
<td><a href="/submissions?problem_id={$problem['id']}&min_score=100&max_score=100">&times;{$problem['ac_num']}</a></td>
<td><a href="/submissions?problem_id={$problem['id']}">&times;{$problem['submit_num']}</a></td>
<td>
<div class="progress bot-buffer-no">
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="$perc" aria-valuemin="0" aria-valuemax="100" style="width: $perc%; min-width: 20px;">{$perc}%</div>
</div>
</td>
EOD;
}
echo '<td class="text-left">', getClickZanBlock('P', $problem['id'], $problem['zan']), '</td>';
echo '</tr>';
}
}
$cond = array();
$search_tag = null;
$cur_tab = isset($_GET['tab']) ? $_GET['tab'] : 'all';
if ($cur_tab == 'template') {
$search_tag = "模板题";
}
if (isset($_GET['tag'])) {
$search_tag = $_GET['tag'];
}
if ($search_tag) {
$cond[] = "'".DB::escape($search_tag)."' in (select tag from problems_tags where problems_tags.problem_id = problems.id)";
}
if (isset($_GET["search"])) {
$cond[]="title like '%".DB::escape($_GET["search"])."%' or id like '%".DB::escape($_GET["search"])."%'";
}
if ($cond) {
$cond = join($cond, ' and ');
} else {
$cond = '1';
}
$header = '<tr>';
$header .= '<th class="text-center" style="width:5em;">ID</th>';
$header .= '<th>'.UOJLocale::get('problems::problem').'</th>';
if (isset($_COOKIE['show_submit_mode'])) {
$header .= '<th class="text-center" style="width:5em;">'.UOJLocale::get('problems::ac').'</th>';
$header .= '<th class="text-center" style="width:5em;">'.UOJLocale::get('problems::submit').'</th>';
$header .= '<th class="text-center" style="width:150px;">'.UOJLocale::get('problems::ac ratio').'</th>';
}
$header .= '<th class="text-center" style="width:180px;">'.UOJLocale::get('appraisal').'</th>';
$header .= '</tr>';
$tabs_info = array(
'all' => array(
'name' => UOJLocale::get('problems::all problems'),
'url' => "/problems"
),
'template' => array(
'name' => UOJLocale::get('problems::template problems'),
'url' => "/problems/template"
)
);
/*
<?php
echoLongTable(array('*'),
"problems left join best_ac_submissions on best_ac_submissions.submitter = '{$myUser['username']}' and problems.id = best_ac_submissions.problem_id", $cond, 'order by id asc',
$header,
'echoProblem',
array('page_len' => 3,
'table_classes' => array('table', 'table-bordered', 'table-hover', 'table-striped'),
'print_after_table' => function() {
global $myUser;
if (isSuperUser($myUser)) {
global $new_problem_form;
$new_problem_form->printHTML();
}
},
'head_pagination' => true
)
);
?>*/
$pag_config = array('page_len' => 100);
$pag_config['col_names'] = array('*');
$pag_config['table_name'] = "problems left join best_ac_submissions on best_ac_submissions.submitter = '{$myUser['username']}' and problems.id = best_ac_submissions.problem_id";
$pag_config['cond'] = $cond;
$pag_config['tail'] = "order by id asc";
$pag = new Paginator($pag_config);
$div_classes = array('table-responsive');
$table_classes = array('table', 'table-bordered', 'table-hover', 'table-striped');
?>
<?php echoUOJPageHeader(UOJLocale::get('problems')) ?>
<div class="row">
<div class="col-sm-4">
<?= HTML::tablist($tabs_info, $cur_tab, 'nav-pills') ?>
</div>
<div class="col-sm-4 order-sm-9 checkbox text-right">
<label class="checkbox-inline" for="input-show_tags_mode"><input type="checkbox" id="input-show_tags_mode" <?= isset($_COOKIE['show_tags_mode']) ? 'checked="checked" ': ''?>/> <?= UOJLocale::get('problems::show tags') ?></label>
<label class="checkbox-inline" for="input-show_submit_mode"><input type="checkbox" id="input-show_submit_mode" <?= isset($_COOKIE['show_submit_mode']) ? 'checked="checked" ': ''?>/> <?= UOJLocale::get('problems::show statistics') ?></label>
</div>
<div class="col-sm-4 order-sm-5">
<?php echo $pag->pagination(); ?>
</div>
</div>
<div class="top-buffer-sm"></div>
<script type="text/javascript">
$('#input-show_tags_mode').click(function() {
if (this.checked) {
$.cookie('show_tags_mode', '', {path: '/problems'});
} else {
$.removeCookie('show_tags_mode', {path: '/problems'});
}
location.reload();
});
$('#input-show_submit_mode').click(function() {
if (this.checked) {
$.cookie('show_submit_mode', '', {path: '/problems'});
} else {
$.removeCookie('show_submit_mode', {path: '/problems'});
}
location.reload();
});
</script>
<?php
echo '<div class="', join($div_classes, ' '), '">';
echo '<table class="', join($table_classes, ' '), '">';
echo '<thead>';
echo $header;
echo '</thead>';
echo '<tbody>';
foreach ($pag->get() as $idx => $row) {
echoProblem($row);
echo "\n";
}
if ($pag->isEmpty()) {
echo '<tr><td class="text-center" colspan="233">'.UOJLocale::get('none').'</td></tr>';
}
echo '</tbody>';
echo '</table>';
echo '</div>';
if (isSuperUser($myUser)) {
echo '<div class="top-buffer-sm"></div>';
$new_problem_form->printHTML();
echo '<div class="top-buffer-sm"></div>';
echo '<div class="card" style="max-width: 300px">';
echo '<div class="card-body">';
$new_luogu_problem_form->printHTML();
echo '</div>';
echo '</div>';
echo '</div>';
}
echo $pag->pagination();
?>
<?php echoUOJPageFooter() ?>

View File

@ -0,0 +1,57 @@
--- UOJ-System/web/app/controllers/problem_set.php 2023-03-19 21:20:30.679254485 +0800
+++ UOJ-Luogu-RemoteJudge/web/app/controllers/problem_set.php 2023-03-20 14:43:44.884987235 +0800
@@ -2,6 +2,7 @@
requirePHPLib('form');
requirePHPLib('judger');
requirePHPLib('data');
+ requirePHPLib('luogu');
if (isSuperUser($myUser)) {
$new_problem_form = new UOJForm('new_problem');
@@ -15,8 +16,28 @@
$new_problem_form->submit_button_config['class_str'] = 'btn btn-primary';
$new_problem_form->submit_button_config['text'] = UOJLocale::get('problems::add new');
$new_problem_form->submit_button_config['smart_confirm'] = '';
-
$new_problem_form->runAtServer();
+
+ $new_luogu_problem_form = new UOJForm('new_luogu_problem');
+ $new_luogu_problem_form->addVInput('luogu_pid', 'text', '洛谷题号', '', function($id) {
+ if (!validateLuoguProblemId($id)) {
+ return '题目 ID 不合法';
+ }
+
+ return '';
+ }, null);
+ $new_luogu_problem_form->handle = function() {
+ try {
+ newLuoguRemoteProblem($_POST['luogu_pid']);
+ } catch (Exception $e) {
+ becomeMsgPage('<h2>添加失败</h2><pre>' . $e->getMessage() . '</pre>');
+ }
+ };
+ // $new_luogu_problem_form->submit_button_config['align'] = 'right';
+ $new_luogu_problem_form->submit_button_config['class_str'] = 'btn btn-primary';
+ $new_luogu_problem_form->submit_button_config['text'] = UOJLocale::get('problems::add new');
+ $new_luogu_problem_form->submit_button_config['confirm'] = '新增来自洛谷的题目';
+ $new_luogu_problem_form->runAtServer();
}
function echoProblem($problem) {
@@ -186,7 +207,16 @@
echo '</div>';
if (isSuperUser($myUser)) {
+ echo '<div class="top-buffer-sm"></div>';
$new_problem_form->printHTML();
+
+ echo '<div class="top-buffer-sm"></div>';
+ echo '<div class="card" style="max-width: 300px">';
+ echo '<div class="card-body">';
+ $new_luogu_problem_form->printHTML();
+ echo '</div>';
+ echo '</div>';
+ echo '</div>';
}
echo $pag->pagination();

View File

@ -0,0 +1,78 @@
<?php
requirePHPLib('form');
requirePHPLib('data');
requirePHPLib('luogu');
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
become404Page();
}
if (!hasProblemPermission($myUser, $problem)) {
become403Page();
}
$problem_content = queryProblemContent($problem['id']);
$problem_tags = queryProblemTags($problem['id']);
$problem_editor = new UOJBlogEditor();
$problem_editor->name = 'problem';
$problem_editor->blog_url = "/problem/{$problem['id']}";
$problem_editor->cur_data = array(
'title' => $problem['title'],
'content_md' => $problem_content['statement_md'],
'content' => $problem_content['statement'],
'tags' => $problem_tags,
'is_hidden' => $problem['is_hidden']
);
$problem_editor->label_text = array_merge($problem_editor->label_text, array(
'view blog' => '查看题目',
'blog visibility' => '题目可见性'
));
$problem_editor->save = function($data) {
global $problem, $problem_tags;
DB::update("update problems set title = '".DB::escape($data['title'])."' where id = {$problem['id']}");
DB::update("update problems_contents set statement = '".DB::escape($data['content'])."', statement_md = '".DB::escape($data['content_md'])."' where id = {$problem['id']}");
if ($data['tags'] !== $problem_tags) {
DB::delete("delete from problems_tags where problem_id = {$problem['id']}");
foreach ($data['tags'] as $tag) {
DB::insert("insert into problems_tags (problem_id, tag) values ({$problem['id']}, '".DB::escape($tag)."')");
}
}
if ($data['is_hidden'] != $problem['is_hidden'] ) {
DB::update("update problems set is_hidden = {$data['is_hidden']} where id = {$problem['id']}");
DB::update("update submissions set is_hidden = {$data['is_hidden']} where problem_id = {$problem['id']}");
DB::update("update hacks set is_hidden = {$data['is_hidden']} where problem_id = {$problem['id']}");
}
};
$problem_editor->runAtServer();
if ($problem['type'] == 'luogu') {
$refetch_problem_form = new UOJForm('refetch_luogu');
$refetch_problem_form->submit_button_config['align'] = 'left';
$refetch_problem_form->submit_button_config['class_str'] = 'btn btn-danger';
$refetch_problem_form->submit_button_config['text'] = '重新拉取题目';
$refetch_problem_form->handle = function() use ($problem) {
try {
refetchLuoguProblemInfo($problem['id']);
} catch (Exception $e) {
becomeMsgPage('<h2>拉取失败</h2><pre>' . $e->getMessage() . '</pre>');
}
};
$refetch_problem_form->runAtServer();
}
?>
<?php echoUOJPageHeader(HTML::stripTags($problem['title']) . ' - 编辑 - 题目管理') ?>
<h1 class="page-header" align="center">#<?=$problem['id']?> : <?=$problem['title']?> 管理</h1>
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item"><a class="nav-link active" href="/problem/<?= $problem['id'] ?>/manage/statement" role="tab">编辑</a></li>
<li class="nav-item"><a class="nav-link" href="/problem/<?= $problem['id'] ?>/manage/managers" role="tab">管理者</a></li>
<li class="nav-item"><a class="nav-link" href="/problem/<?= $problem['id'] ?>/manage/data" role="tab">数据</a></li>
<li class="nav-item"><a class="nav-link" href="/problem/<?=$problem['id']?>" role="tab">返回</a></li>
</ul>
<?php $problem_editor->printHTML() ?>
<?php if (isset($refetch_problem_form)): ?>
<?php $refetch_problem_form->printHTML() ?>
<?php endif ?>
<?php echoUOJPageFooter() ?>

View File

@ -0,0 +1,40 @@
--- UOJ-System/web/app/controllers/problem_statement_manage.php 2023-03-19 21:20:30.679254485 +0800
+++ UOJ-Luogu-RemoteJudge/web/app/controllers/problem_statement_manage.php 2023-03-20 15:02:04.084987421 +0800
@@ -1,5 +1,7 @@
<?php
requirePHPLib('form');
+ requirePHPLib('data');
+ requirePHPLib('luogu');
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
become404Page();
@@ -45,6 +47,21 @@
};
$problem_editor->runAtServer();
+
+ if ($problem['type'] == 'luogu') {
+ $refetch_problem_form = new UOJForm('refetch_luogu');
+ $refetch_problem_form->submit_button_config['align'] = 'left';
+ $refetch_problem_form->submit_button_config['class_str'] = 'btn btn-danger';
+ $refetch_problem_form->submit_button_config['text'] = '重新拉取题目';
+ $refetch_problem_form->handle = function() use ($problem) {
+ try {
+ refetchLuoguProblemInfo($problem['id']);
+ } catch (Exception $e) {
+ becomeMsgPage('<h2>拉取失败</h2><pre>' . $e->getMessage() . '</pre>');
+ }
+ };
+ $refetch_problem_form->runAtServer();
+ }
?>
<?php echoUOJPageHeader(HTML::stripTags($problem['title']) . ' - 编辑 - 题目管理') ?>
<h1 class="page-header" align="center">#<?=$problem['id']?> : <?=$problem['title']?> 管理</h1>
@@ -55,4 +72,7 @@
<li class="nav-item"><a class="nav-link" href="/problem/<?=$problem['id']?>" role="tab">返回</a></li>
</ul>
<?php $problem_editor->printHTML() ?>
+<?php if (isset($refetch_problem_form)): ?>
+ <?php $refetch_problem_form->printHTML() ?>
+<?php endif ?>
<?php echoUOJPageFooter() ?>

View File

@ -62,7 +62,6 @@ function fetchLuoguProblemBasicInfo($pid) {
$curl->set('CURLOPT_HTTPHEADER', [
'User-Agent: ' . LUOGU_USER_AGENT,
'Content-Type: application/json',
'Accept: application/json',
]);
@ -92,17 +91,44 @@ function newLuoguRemoteProblem($pid) {
));
$esc_extra_config = json_encode(array(
"luogu_pid" => $pid,
"time_limit" => $problem['time_limit'],
"memory_limit" => $problem['memory_limit'],
"view_content_type" => "ALL",
"view_details_type" => "ALL",
));
DB::query("insert into problems (title, is_hidden, submission_requirement, extra_config, hackable, type) values ('" . DB::escape($problem['title']) . "', 1, '" . DB::escape($esc_submission_requirements) . "', '" . DB::escape($esc_extra_config) . "', 0, 'luogu')");
DB::insert("insert into problems (title, is_hidden, submission_requirement, extra_config, hackable, type) values ('" . DB::escape($problem['title']) . "', 1, '" . DB::escape($esc_submission_requirements) . "', '" . DB::escape($esc_extra_config) . "', 0, 'luogu')");
$id = DB::insert_id();
DB::query("insert into problems_contents (id, statement, statement_md) values ($id, '" . DB::escape($problem['statement']) . "', '" . DB::escape($problem['statement_md']) . "')");
DB::insert("insert into problems_contents (id, statement, statement_md) values ($id, '" . DB::escape($problem['statement']) . "', '" . DB::escape($problem['statement_md']) . "')");
dataNewProblem($id);
return $id;
}
function refetchLuoguProblemInfo($id) {
$problem = queryProblemBrief($id);
$problem_extra_config = getProblemExtraConfig($problem);
$pid = $problem_extra_config['luogu_pid'];
$luogu_problem = fetchLuoguProblemBasicInfo($pid);
$esc_submission_requirements = json_encode(array(
array(
"name" => "answer",
"type" => "source code",
"file_name" => "answer.code",
"languages" => LUOGU_SUPPORTED_LANGUAGES,
),
));
mergeConfig($problem_extra_config, array(
"time_limit" => $luogu_problem['time_limit'],
"memory_limit" => $luogu_problem['memory_limit'],
));
$esc_extra_config = json_encode($problem_extra_config);
DB::update("update problems set title = '" . DB::escape($luogu_problem['title']) . "', submission_requirement = '" . DB::escape($esc_submission_requirements) . "', extra_config = '" . DB::escape($esc_extra_config) . "' where id = {$problem['id']}");
DB::update("update problems_contents set statement = '" . DB::escape($luogu_problem['statement']) . "', statement_md = '" . DB::escape($luogu_problem['statement_md']) . "' where id = {$problem['id']}");
}

View File

@ -3,8 +3,6 @@
// from https://github.com/wenpeng/curl
// requires php-curl module
use Exception;
class Curl {
private $post;
private $retry = 0;