2023-01-18 08:20:12 +00:00
|
|
|
|
<?php
|
|
|
|
|
requirePHPLib('form');
|
|
|
|
|
requirePHPLib('data');
|
|
|
|
|
|
|
|
|
|
Auth::check() || redirectToLogin();
|
|
|
|
|
UOJProblem::userCanCreateProblem(Auth::user()) || UOJResponse::page403();
|
|
|
|
|
|
|
|
|
|
$new_remote_problem_form = new UOJForm('new_remote_problem');
|
|
|
|
|
$new_remote_problem_form->addSelect('remote_online_judge', [
|
|
|
|
|
'label' => '远程 OJ',
|
2023-01-20 13:23:22 +00:00
|
|
|
|
'options' => array_map(fn ($provider) => $provider['name'], UOJRemoteProblem::$providers),
|
2023-01-18 08:20:12 +00:00
|
|
|
|
]);
|
|
|
|
|
$new_remote_problem_form->addInput('remote_problem_id', [
|
|
|
|
|
'div_class' => 'mt-3',
|
|
|
|
|
'label' => '远程 OJ 上的题目 ID',
|
|
|
|
|
'validator_php' => function ($id, &$vdata) {
|
2023-01-20 13:23:22 +00:00
|
|
|
|
$remote_oj = $_POST['remote_online_judge'];
|
|
|
|
|
if ($remote_oj === 'codeforces') {
|
2023-01-18 08:20:12 +00:00
|
|
|
|
$id = trim(strtoupper($id));
|
|
|
|
|
|
|
|
|
|
if (!validateCodeforcesProblemId($id)) {
|
|
|
|
|
return '不合法的题目 ID';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$vdata['remote_problem_id'] = $id;
|
|
|
|
|
|
2023-01-20 13:23:22 +00:00
|
|
|
|
return '';
|
|
|
|
|
} else if ($remote_oj === 'atcoder') {
|
|
|
|
|
$id = trim(strtolower($id));
|
|
|
|
|
|
|
|
|
|
if (!validateString($id)) {
|
|
|
|
|
return '不合法的题目 ID';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$vdata['remote_problem_id'] = $id;
|
|
|
|
|
|
2023-01-22 09:00:12 +00:00
|
|
|
|
return '';
|
2023-01-24 03:51:21 +00:00
|
|
|
|
} else if ($remote_oj === 'uoj') {
|
|
|
|
|
if (!validateUInt($id)) {
|
|
|
|
|
return '不合法的题目 ID';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$vdata['remote_problem_id'] = $id;
|
|
|
|
|
|
|
|
|
|
return '';
|
|
|
|
|
} else if ($remote_oj === 'loj') {
|
2023-01-22 09:00:12 +00:00
|
|
|
|
if (!validateUInt($id)) {
|
|
|
|
|
return '不合法的题目 ID';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$vdata['remote_problem_id'] = $id;
|
|
|
|
|
|
2023-02-02 13:53:36 +00:00
|
|
|
|
return '';
|
|
|
|
|
} else if ($remote_oj === 'luogu') {
|
|
|
|
|
$id = trim(strtoupper($id));
|
|
|
|
|
|
|
|
|
|
if (!validateLuoguProblemId($id)) {
|
|
|
|
|
return '不合法的题目 ID';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$vdata['remote_problem_id'] = $id;
|
|
|
|
|
|
2023-01-18 08:20:12 +00:00
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return '不合法的远程 OJ 类型';
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
$new_remote_problem_form->handle = function (&$vdata) {
|
|
|
|
|
$remote_online_judge = $_POST['remote_online_judge'];
|
|
|
|
|
$remote_problem_id = $vdata['remote_problem_id'];
|
|
|
|
|
$remote_provider = UOJRemoteProblem::$providers[$remote_online_judge];
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$data = UOJRemoteProblem::getProblemBasicInfo($remote_online_judge, $remote_problem_id);
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
$data = null;
|
|
|
|
|
UOJLog::error($e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($data === null) {
|
|
|
|
|
UOJResponse::page500('题目抓取失败,可能是题目不存在或者没有题面!如果题目没有问题,请稍后再试。<a href="">返回</a>');
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-02 12:07:35 +00:00
|
|
|
|
$submission_requirement = UOJRemoteProblem::getSubmissionRequirements($remote_online_judge);
|
2023-01-18 08:20:12 +00:00
|
|
|
|
$enc_submission_requirement = json_encode($submission_requirement);
|
|
|
|
|
|
|
|
|
|
$extra_config = [
|
|
|
|
|
'remote_online_judge' => $remote_online_judge,
|
|
|
|
|
'remote_problem_id' => $remote_problem_id,
|
|
|
|
|
'time_limit' => $data['time_limit'],
|
|
|
|
|
'memory_limit' => $data['memory_limit'],
|
|
|
|
|
];
|
|
|
|
|
$enc_extra_config = json_encode($extra_config);
|
|
|
|
|
|
|
|
|
|
DB::insert([
|
|
|
|
|
"insert into problems",
|
2023-01-19 02:17:30 +00:00
|
|
|
|
"(title, uploader, is_hidden, submission_requirement, extra_config, difficulty, type)",
|
|
|
|
|
"values", DB::tuple([$data['title'], Auth::id(), 1, $enc_submission_requirement, $enc_extra_config, $data['difficulty'] ?: -1, "remote"])
|
2023-01-18 08:20:12 +00:00
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$id = DB::insert_id();
|
2023-01-30 12:27:53 +00:00
|
|
|
|
dataNewProblem($id);
|
|
|
|
|
|
|
|
|
|
if ($data['type'] == 'pdf') {
|
2023-01-30 23:59:24 +00:00
|
|
|
|
file_put_contents(UOJContext::storagePath(), "/problem_resources/$id/statement.pdf", $data['pdf_data']);
|
2023-01-30 12:27:53 +00:00
|
|
|
|
$data['statement'] = "<div data-pdf data-src=\"/problem/$id/resources/statement.pdf\"></div>\n" . $data['statement'];
|
|
|
|
|
}
|
2023-01-18 08:20:12 +00:00
|
|
|
|
|
|
|
|
|
DB::insert([
|
|
|
|
|
"insert into problems_contents",
|
|
|
|
|
"(id, remote_content, statement, statement_md)",
|
|
|
|
|
"values",
|
2023-01-20 13:23:22 +00:00
|
|
|
|
DB::tuple([$id, HTML::purifier(['a' => ['target' => 'Enum#_blank']])->purify($data['statement']), '', ''])
|
2023-01-18 08:20:12 +00:00
|
|
|
|
]);
|
|
|
|
|
|
2023-01-28 01:40:46 +00:00
|
|
|
|
DB::insert([
|
|
|
|
|
"insert into problems_tags",
|
|
|
|
|
"(problem_id, tag)",
|
|
|
|
|
"values",
|
|
|
|
|
DB::tuple([$id, $remote_provider['name']]),
|
|
|
|
|
]);
|
|
|
|
|
|
2023-01-30 23:59:24 +00:00
|
|
|
|
UOJRemoteProblem::downloadImagesInRemoteContent(strval($id));
|
|
|
|
|
|
2023-01-18 08:20:12 +00:00
|
|
|
|
redirectTo("/problem/{$id}");
|
|
|
|
|
die();
|
|
|
|
|
};
|
|
|
|
|
$new_remote_problem_form->runAtServer();
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
|
|
<?php echoUOJPageHeader('导入远程题库') ?>
|
|
|
|
|
|
|
|
|
|
<h1>导入远程题库</h1>
|
|
|
|
|
|
|
|
|
|
<div class="row">
|
|
|
|
|
<div class="col-md-9">
|
|
|
|
|
<div class="card">
|
|
|
|
|
<div class="card-body">
|
|
|
|
|
<div class="row">
|
|
|
|
|
<div class="col-md-6">
|
|
|
|
|
<?php $new_remote_problem_form->printHTML() ?>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="col-md-6 mt-3 mt-md-0">
|
|
|
|
|
<h4>使用帮助</h4>
|
2023-01-19 02:17:16 +00:00
|
|
|
|
<ul>
|
|
|
|
|
<li>
|
|
|
|
|
<p>目前支持导入以下题库的题目作为远端评测题:</p>
|
2023-01-19 03:05:16 +00:00
|
|
|
|
<ul class="mb-3">
|
2023-01-24 03:51:21 +00:00
|
|
|
|
<li><a href="https://codeforces.com/problemset">Codeforces</a></li>
|
|
|
|
|
<li><a href="https://codeforces.com/gyms">Codeforces::Gym</a>(题号前加 <code>GYM</code>)</li>
|
|
|
|
|
<li><a href="https://atcoder.jp/contests/archive">AtCoder</a></li>
|
|
|
|
|
<li><a href="https://uoj.ac/problems">UniversalOJ</a></li>
|
|
|
|
|
<li><a href="https://loj.ac/p">LibreOJ</a></li>
|
2023-02-04 03:30:03 +00:00
|
|
|
|
<li><a href="https://www.luogu.com.cn/problem/list">洛谷</a></li>
|
2023-01-19 02:17:16 +00:00
|
|
|
|
</ul>
|
|
|
|
|
</li>
|
|
|
|
|
<li>在导入题目前请先搜索题库中是否已经存在相应题目,避免重复添加。</li>
|
|
|
|
|
</ul>
|
2023-01-18 08:20:12 +00:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="col-md-3">
|
2023-01-19 08:13:03 +00:00
|
|
|
|
<?php uojIncludeView('sidebar') ?>
|
2023-01-18 08:20:12 +00:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<?php echoUOJPageFooter() ?>
|