From 7cdb39267a71f4a4e66e627aa10b8b8d239e6442 Mon Sep 17 00:00:00 2001
From: Baoshuo
Date: Thu, 2 Feb 2023 20:07:35 +0800
Subject: [PATCH] feat(problem/remote): prepare for luogu
---
web/app/controllers/new_remote_problem.php | 9 +-
.../controllers/problem_statement_manage.php | 13 +-
web/app/libs/uoj-form-lib.php | 141 ++++++++++++++++--
web/app/libs/uoj-html-lib.php | 18 ++-
web/app/models/UOJForm.php | 1 +
web/app/models/UOJProblem.php | 2 +
web/app/models/UOJRemoteProblem.php | 28 ++++
web/app/models/UOJSubmission.php | 7 +-
web/app/models/UOJSubmissionLikeTrait.php | 18 +++
9 files changed, 201 insertions(+), 36 deletions(-)
diff --git a/web/app/controllers/new_remote_problem.php b/web/app/controllers/new_remote_problem.php
index 63cf369..e7af67d 100644
--- a/web/app/controllers/new_remote_problem.php
+++ b/web/app/controllers/new_remote_problem.php
@@ -73,14 +73,7 @@ $new_remote_problem_form->handle = function (&$vdata) {
UOJResponse::page500('题目抓取失败,可能是题目不存在或者没有题面!如果题目没有问题,请稍后再试。返回');
}
- $submission_requirement = [
- [
- "name" => "answer",
- "type" => "source code",
- "file_name" => "answer.code",
- "languages" => $remote_provider['languages'],
- ]
- ];
+ $submission_requirement = UOJRemoteProblem::getSubmissionRequirements($remote_online_judge);
$enc_submission_requirement = json_encode($submission_requirement);
$extra_config = [
diff --git a/web/app/controllers/problem_statement_manage.php b/web/app/controllers/problem_statement_manage.php
index 3ccc75b..3b3353a 100644
--- a/web/app/controllers/problem_statement_manage.php
+++ b/web/app/controllers/problem_statement_manage.php
@@ -118,7 +118,7 @@ if (UOJProblem::info('type') == 'remote') {
EOD);
$re_crawl_form->config['submit_button']['text'] = '重新爬取';
- $re_crawl_form->handle = function () use ($remote_online_judge, $remote_problem_id, $remote_provider) {
+ $re_crawl_form->handle = function () use ($remote_online_judge, $remote_problem_id) {
try {
$data = UOJRemoteProblem::getProblemBasicInfo($remote_online_judge, $remote_problem_id);
} catch (Exception $e) {
@@ -134,16 +134,9 @@ if (UOJProblem::info('type') == 'remote') {
$data['difficulty'] = UOJProblem::info('difficulty');
}
- $submission_requirement = [
- [
- "name" => "answer",
- "type" => "source code",
- "file_name" => "answer.code",
- "languages" => $remote_provider['languages'],
- ]
- ];
+ $submission_requirement = UOJRemoteProblem::getSubmissionRequirements($remote_online_judge);
$enc_submission_requirement = json_encode($submission_requirement);
-
+
$extra_config = [
'remote_online_judge' => $remote_online_judge,
'remote_problem_id' => $remote_problem_id,
diff --git a/web/app/libs/uoj-form-lib.php b/web/app/libs/uoj-form-lib.php
index aef5409..41a3efa 100644
--- a/web/app/libs/uoj-form-lib.php
+++ b/web/app/libs/uoj-form-lib.php
@@ -46,6 +46,7 @@ function newAddDelCmdForm($form_name, $validate, $handle, $final = null) {
function newSubmissionForm($form_name, $requirement, $zip_file_name_gen, $handle) {
$form = new UOJForm($form_name);
+
foreach ($requirement as $req) {
if ($req['type'] == "source code") {
$languages = UOJLang::getAvailableLanguages(isset($req['languages']) ? $req['languages'] : null);
@@ -57,6 +58,101 @@ function newSubmissionForm($form_name, $requirement, $zip_file_name_gen, $handle
$form->addTextFileInput("{$form_name}_{$req['name']}", [
'filename' => $req['file_name'],
]);
+ } else if ($req['type'] == "remote submission") {
+ if ($req['name'] == 'luogu') {
+ $form->appendHTML(HTML::tag_begin('div', ['class' => 'row']));
+ $form->appendHTML(HTML::tag(
+ 'div',
+ [
+ 'class' => 'col-sm-2',
+ ],
+ HTML::tag('label', [
+ 'class' => 'form-col-label',
+ ], '_uid')
+ ));
+ $form->addInput("{$form_name}_{$req['name']}_uid", [
+ 'div_class' => 'col-sm-4',
+ 'validator_php' => function ($x) {
+ if (!validateUInt($x)) {
+ return 'ID 不合法';
+ }
+
+ return '';
+ },
+ ]);
+ $form->appendHTML(HTML::tag(
+ 'div',
+ [
+ 'class' => 'col-sm-6',
+ ],
+ HTML::tag('div', [
+ 'class' => 'form-text',
+ ], '请在 Cookie 中找到 _uid
,然后填入框中。')
+ ));
+ $form->appendHTML(HTML::tag_end('div'));
+
+ $form->appendHTML(HTML::tag_begin('div', ['class' => 'row mt-3']));
+ $form->appendHTML(HTML::tag(
+ 'div',
+ [
+ 'class' => 'col-sm-2',
+ ],
+ HTML::tag('label', [
+ 'class' => 'form-col-label',
+ ], '__clientid')
+ ));
+ $form->addInput("{$form_name}_{$req['name']}_clientid", [
+ 'div_class' => 'col-sm-4',
+ 'validator_php' => function ($x) {
+ if (!validateString($x)) {
+ return 'ID 不合法';
+ }
+
+ return '';
+ },
+ ]);
+ $form->appendHTML(HTML::tag(
+ 'div',
+ [
+ 'class' => 'col-sm-6',
+ ],
+ HTML::tag('div', [
+ 'class' => 'form-text',
+ ], '请在 Cookie 中找到 __clientid
,然后填入框中。')
+ ));
+ $form->appendHTML(HTML::tag_end('div'));
+
+ $form->appendHTML(HTML::tag_begin('div', ['class' => 'row mt-3']));
+ $form->appendHTML(HTML::tag(
+ 'div',
+ [
+ 'class' => 'col-sm-2',
+ ],
+ HTML::tag('label', [
+ 'class' => 'form-col-label',
+ ], '提交记录 ID')
+ ));
+ $form->addInput("{$form_name}_{$req['name']}_submission_id", [
+ 'div_class' => 'col-sm-4',
+ 'validator_php' => function ($x) {
+ if (!validateUInt($x)) {
+ return 'ID 不合法';
+ }
+
+ return '';
+ },
+ ]);
+ $form->appendHTML(HTML::tag(
+ 'div',
+ [
+ 'class' => 'col-sm-6',
+ ],
+ HTML::tag('div', [
+ 'class' => 'form-text',
+ ], '请填入提交记录 ID(不带开头的字母 R
)。')
+ ));
+ $form->appendHTML(HTML::tag_end('div'));
+ }
}
}
@@ -74,35 +170,48 @@ function newSubmissionForm($form_name, $requirement, $zip_file_name_gen, $handle
$content = [];
$content['file_name'] = $zip_file_name;
$content['config'] = [];
+
foreach ($requirement as $req) {
if ($req['type'] == "source code") {
$content['config'][] = ["{$req['name']}_language", $_POST["{$form_name}_{$req['name']}_language"]];
+ } else if ($req['type'] == "remote submission") {
+ $content['no_rejudge'] = true;
+
+ if ($req['name'] == "luogu") {
+ $content['config'][] = ["{$req['name']}_uid", $_POST["{$form_name}_{$req['name']}_uid"]];
+ $content['config'][] = ["{$req['name']}_clientid", $_POST["{$form_name}_{$req['name']}_clientid"]];
+ $content['config'][] = ["{$req['name']}_submission_id", $_POST["{$form_name}_{$req['name']}_submission_id"]];
+ }
}
}
foreach ($requirement as $req) {
- if ($_POST["{$form_name}_{$req['name']}_upload_type"] == 'editor') {
- $zip_file->addFromString($req['file_name'], $_POST["{$form_name}_{$req['name']}_editor"]);
+ if ($req['type'] == "remote submission") {
+ $zip_file->addFromString($req['name'], '');
} else {
- $tmp_name = UOJForm::uploadedFileTmpName("{$form_name}_{$req['name']}_file");
- if ($tmp_name == null) {
- $zip_file->addFromString($req['file_name'], '');
+ if ($_POST["{$form_name}_{$req['name']}_upload_type"] == 'editor') {
+ $zip_file->addFromString($req['file_name'], $_POST["{$form_name}_{$req['name']}_editor"]);
} else {
- $zip_file->addFile($tmp_name, $req['file_name']);
+ $tmp_name = UOJForm::uploadedFileTmpName("{$form_name}_{$req['name']}_file");
+ if ($tmp_name == null) {
+ $zip_file->addFromString($req['file_name'], '');
+ } else {
+ $zip_file->addFile($tmp_name, $req['file_name']);
+ }
}
- }
- $stat = $zip_file->statName($req['file_name']);
+ $stat = $zip_file->statName($req['file_name']);
- if ($req['type'] == 'source code') {
- $max_size = isset($req['size']) ? (int)$req['size'] : 100;
- if ($stat['size'] > $max_size * 1024) {
- $zip_file->close();
- unlink(UOJContext::storagePath() . $zip_file_name);
- UOJResponse::message("源代码长度不能超过 {$max_size} kB。");
+ if ($req['type'] == 'source code') {
+ $max_size = isset($req['size']) ? (int)$req['size'] : 100;
+ if ($stat['size'] > $max_size * 1024) {
+ $zip_file->close();
+ unlink(UOJContext::storagePath() . $zip_file_name);
+ UOJResponse::message("源代码长度不能超过 {$max_size} kB。");
+ }
}
- }
- $tot_size += $stat['size'];
+ $tot_size += $stat['size'];
+ }
}
$zip_file->close();
diff --git a/web/app/libs/uoj-html-lib.php b/web/app/libs/uoj-html-lib.php
index 0fa2ddb..d6b5157 100644
--- a/web/app/libs/uoj-html-lib.php
+++ b/web/app/libs/uoj-html-lib.php
@@ -403,7 +403,7 @@ function echoSubmissionContent($submission, $requirement) {
echo '';
echo ' ';
echo '';
- } elseif ($req['type'] == "text") {
+ } else if ($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));
@@ -417,6 +417,22 @@ function echoSubmissionContent($submission, $requirement) {
echo '';
echo ' ';
echo '';
+ } else if ($req['type'] == "remote submission") {
+ $remote_provider = UOJRemoteProblem::$providers[$req['name']];
+ $content = '';
+
+ if ($req['name'] == 'luogu') {
+ $content .= '
远端评测 ID:' . + HTML::tag( + 'a', + [ + 'href' => $remote_provider['url'] . '/record/' . $config['luogu_submission_id'] + ], + 'R' . $config['luogu_submission_id'] + ) . '
'; + } + + HTML::echoPanel('', '远端评测记录', $content); } } diff --git a/web/app/models/UOJForm.php b/web/app/models/UOJForm.php index 55882e4..ad3a541 100644 --- a/web/app/models/UOJForm.php +++ b/web/app/models/UOJForm.php @@ -665,6 +665,7 @@ class UOJForm { EOD; } else { echo <<