From 07f7782ae4ce3dcc20d30943facf3585884d9143 Mon Sep 17 00:00:00 2001 From: Leo Lu Date: Thu, 6 Aug 2020 00:24:34 +0800 Subject: [PATCH] Added pastes --- install/db/app_uoj233.sql | 17 +++++++++ web/.gitignore | 3 +- web/app/controllers/paste_post.php | 37 +++++++++++++++++++ web/app/controllers/paste_view.php | 10 ++++++ web/app/controllers/super_manage.php | 25 +++++++++++++ web/app/libs/uoj-html-lib.php | 53 ++++++++++++++++++++++++++++ web/app/libs/uoj-rand-lib.php | 4 +++ web/app/route.php | 3 ++ web/app/storage/paste/.gitkeep | 0 9 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 web/app/controllers/paste_post.php create mode 100644 web/app/controllers/paste_view.php create mode 100644 web/app/storage/paste/.gitkeep diff --git a/install/db/app_uoj233.sql b/install/db/app_uoj233.sql index db51e85..0ec3098 100644 --- a/install/db/app_uoj233.sql +++ b/install/db/app_uoj233.sql @@ -697,6 +697,23 @@ LOCK TABLES `user_system_msg` WRITE; /*!40000 ALTER TABLE `user_system_msg` DISABLE KEYS */; /*!40000 ALTER TABLE `user_system_msg` ENABLE KEYS */; UNLOCK TABLES; + +create table pastes +( + `index` varchar(20) null, + creator varchar(20) null, + content text null +); + +create unique index pastes_index_uindex + on pastes (`index`); + +alter table pastes + add constraint pastes_pk + primary key (`index`); + + + /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; diff --git a/web/.gitignore b/web/.gitignore index 0cba4c5..6bebc64 100644 --- a/web/.gitignore +++ b/web/.gitignore @@ -3,6 +3,7 @@ app/.config.php app/storage/tmp/* app/storage/submission/* +app/storage/paste/* !app/storage/tmp/.gitkeep !app/storage/submission/.gitkeep - +!app/storage/paste/.gitkeep diff --git a/web/app/controllers/paste_post.php b/web/app/controllers/paste_post.php new file mode 100644 index 0000000..52c7cb3 --- /dev/null +++ b/web/app/controllers/paste_post.php @@ -0,0 +1,37 @@ + "source code", + "name" => "paste", + "file_name" => "paste.code" + ] + ], + 'uojRandAvaiablePasteFileName', + 'handleUpload'); +$paste_form->succ_href = '/paste'; +$paste_form->runAtServer(); +echoUOJPageHeader("Paste!"); +$paste_form->printHTML(); +echoUOJPageFooter(); \ No newline at end of file diff --git a/web/app/controllers/paste_view.php b/web/app/controllers/paste_view.php new file mode 100644 index 0000000..2072cf0 --- /dev/null +++ b/web/app/controllers/paste_view.php @@ -0,0 +1,10 @@ +runAtServer(); + + $paste_deleter = new UOJForm('paste_deleter'); + $paste_deleter->addInput('paste_deleter_name', 'text', 'Paste ID', '', + function ($x, &$vdata) { + if (DB::selectCount("select count(*) from pastes where `index`='$x'")==0) { + return '不合法'; + } + $vdata['name'] = $x; + return ''; + }, + null + ); + $paste_deleter->handle = function(&$vdata) { + DB::delete("delete from pastes where `index` = '${vdata['name']}'"); + }; + $paste_deleter->runAtServer(); $judgerlist_cols = array('judger_name', 'password'); $judgerlist_config = array(); @@ -328,6 +344,10 @@ EOD; 'judger' => array( 'name' => '评测机管理', 'url' => '/super-manage/judger' + ), + 'paste' => array( + 'name' => 'Paste管理', + 'url' => '/super-manage/paste' ) ); @@ -458,6 +478,11 @@ EOD;

评测机列表

+ +
+

删除Paste

+ printHTML(); ?> +
diff --git a/web/app/libs/uoj-html-lib.php b/web/app/libs/uoj-html-lib.php index b46d987..d5db92b 100644 --- a/web/app/libs/uoj-html-lib.php +++ b/web/app/libs/uoj-html-lib.php @@ -393,6 +393,59 @@ function echoSubmissionsList($cond, $tail, $config, $user) { }, $table_config); } +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") . <<${paste['creator']} +HTML; + + switch ($file_language) { + case 'C++': + case 'C++11': + $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 '
'; + echo '
'; + echo '

Paste!

'; + echo '
'; + echo '
'; + echo '
'.$file_content."\n".'
'; + echo '
'; + echo ''; + echo '
'; + + $zip_file->close(); +} function echoSubmissionContent($submission, $requirement) { $zip_file = new ZipArchive(); diff --git a/web/app/libs/uoj-rand-lib.php b/web/app/libs/uoj-rand-lib.php index 2e221c1..49e427b 100644 --- a/web/app/libs/uoj-rand-lib.php +++ b/web/app/libs/uoj-rand-lib.php @@ -31,3 +31,7 @@ function uojRandAvaiableSubmissionFileName() { } return uojRandAvaiableFileName("/submission/$num/"); } + +function uojRandAvaiablePasteFileName() { + return uojRandAvaiableFileName('/paste/'); +} diff --git a/web/app/route.php b/web/app/route.php index 87372a7..551c6d0 100644 --- a/web/app/route.php +++ b/web/app/route.php @@ -64,6 +64,9 @@ Route::group([ Route::any('/download.php', '/download.php'); Route::any('/click-zan', '/click_zan.php'); + + Route::any('/paste', '/paste_post.php'); + Route::any('/pastes/{rand_str_id}', '/paste_view.php'); } ); diff --git a/web/app/storage/paste/.gitkeep b/web/app/storage/paste/.gitkeep new file mode 100644 index 0000000..e69de29