mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-08 12:18:43 +00:00
Added pastes
This commit is contained in:
parent
bd76d2c296
commit
07f7782ae4
@ -697,6 +697,23 @@ LOCK TABLES `user_system_msg` WRITE;
|
|||||||
/*!40000 ALTER TABLE `user_system_msg` DISABLE KEYS */;
|
/*!40000 ALTER TABLE `user_system_msg` DISABLE KEYS */;
|
||||||
/*!40000 ALTER TABLE `user_system_msg` ENABLE KEYS */;
|
/*!40000 ALTER TABLE `user_system_msg` ENABLE KEYS */;
|
||||||
UNLOCK TABLES;
|
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 */;
|
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
|
||||||
|
|
||||||
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
|
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
|
||||||
|
3
web/.gitignore
vendored
3
web/.gitignore
vendored
@ -3,6 +3,7 @@
|
|||||||
app/.config.php
|
app/.config.php
|
||||||
app/storage/tmp/*
|
app/storage/tmp/*
|
||||||
app/storage/submission/*
|
app/storage/submission/*
|
||||||
|
app/storage/paste/*
|
||||||
!app/storage/tmp/.gitkeep
|
!app/storage/tmp/.gitkeep
|
||||||
!app/storage/submission/.gitkeep
|
!app/storage/submission/.gitkeep
|
||||||
|
!app/storage/paste/.gitkeep
|
||||||
|
37
web/app/controllers/paste_post.php
Normal file
37
web/app/controllers/paste_post.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
requirePHPLib('form');
|
||||||
|
requirePHPLib('judger');
|
||||||
|
|
||||||
|
if ($myUser == null) {
|
||||||
|
becomeMsgPage("请先登录!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function handleUpload($zip_file_name, $content, $tot_size) {
|
||||||
|
global $myUser;
|
||||||
|
$esc_content = DB::escape(json_encode($content));
|
||||||
|
$index = uojRandString(20);
|
||||||
|
$esc_index = DB::escape($index);
|
||||||
|
while (DB::selectFirst("select count(*) as count from pastes where `index` = '$esc_index'")['count'] != "0") {
|
||||||
|
$index = uojRandString(20);
|
||||||
|
$esc_index = DB::escape($index);
|
||||||
|
}
|
||||||
|
DB::query("insert into pastes (`index`, `creator`, `content`) values ('$esc_index', '${myUser['username']}', '$esc_content')");
|
||||||
|
redirectTo("/pastes/".$index);
|
||||||
|
}
|
||||||
|
|
||||||
|
$paste_form = newSubmissionForm('paste',
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'type' => "source code",
|
||||||
|
"name" => "paste",
|
||||||
|
"file_name" => "paste.code"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'uojRandAvaiablePasteFileName',
|
||||||
|
'handleUpload');
|
||||||
|
$paste_form->succ_href = '/paste';
|
||||||
|
$paste_form->runAtServer();
|
||||||
|
echoUOJPageHeader("Paste!");
|
||||||
|
$paste_form->printHTML();
|
||||||
|
echoUOJPageFooter();
|
10
web/app/controllers/paste_view.php
Normal file
10
web/app/controllers/paste_view.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$paste_id = $_GET['rand_str_id'];
|
||||||
|
|
||||||
|
$paste = DB::selectFirst("select * from pastes where `index` = '".DB::escape($paste_id)."'");
|
||||||
|
|
||||||
|
$REQUIRE_LIB['shjs'] = "";
|
||||||
|
echoUOJPageHeader("Paste!");
|
||||||
|
echoPasteContent($paste);
|
||||||
|
echoUOJPageFooter();
|
@ -265,6 +265,22 @@
|
|||||||
};
|
};
|
||||||
$judger_deleter->runAtServer();
|
$judger_deleter->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_cols = array('judger_name', 'password');
|
||||||
$judgerlist_config = array();
|
$judgerlist_config = array();
|
||||||
$judgerlist_header_row = <<<EOD
|
$judgerlist_header_row = <<<EOD
|
||||||
@ -328,6 +344,10 @@ EOD;
|
|||||||
'judger' => array(
|
'judger' => array(
|
||||||
'name' => '评测机管理',
|
'name' => '评测机管理',
|
||||||
'url' => '/super-manage/judger'
|
'url' => '/super-manage/judger'
|
||||||
|
),
|
||||||
|
'paste' => array(
|
||||||
|
'name' => 'Paste管理',
|
||||||
|
'url' => '/super-manage/paste'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -458,6 +478,11 @@ EOD;
|
|||||||
</div>
|
</div>
|
||||||
<h3>评测机列表</h3>
|
<h3>评测机列表</h3>
|
||||||
<?php echoLongTable($judgerlist_cols, 'judger_info', "1=1", '', $judgerlist_header_row, $judgerlist_print_row, $judgerlist_config) ?>
|
<?php echoLongTable($judgerlist_cols, 'judger_info', "1=1", '', $judgerlist_header_row, $judgerlist_print_row, $judgerlist_config) ?>
|
||||||
|
<?php elseif ($cur_tab === 'paste'): ?>
|
||||||
|
<div>
|
||||||
|
<h4>删除Paste</h4>
|
||||||
|
<?php $paste_deleter->printHTML(); ?>
|
||||||
|
</div>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -393,6 +393,59 @@ function echoSubmissionsList($cond, $tail, $config, $user) {
|
|||||||
}, $table_config);
|
}, $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") . <<<HTML
|
||||||
|
: <a href="/user/profile/${paste['creator']}">${paste['creator']}</a>
|
||||||
|
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 '<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) {
|
function echoSubmissionContent($submission, $requirement) {
|
||||||
$zip_file = new ZipArchive();
|
$zip_file = new ZipArchive();
|
||||||
|
@ -31,3 +31,7 @@ function uojRandAvaiableSubmissionFileName() {
|
|||||||
}
|
}
|
||||||
return uojRandAvaiableFileName("/submission/$num/");
|
return uojRandAvaiableFileName("/submission/$num/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function uojRandAvaiablePasteFileName() {
|
||||||
|
return uojRandAvaiableFileName('/paste/');
|
||||||
|
}
|
||||||
|
@ -64,6 +64,9 @@ Route::group([
|
|||||||
Route::any('/download.php', '/download.php');
|
Route::any('/download.php', '/download.php');
|
||||||
|
|
||||||
Route::any('/click-zan', '/click_zan.php');
|
Route::any('/click-zan', '/click_zan.php');
|
||||||
|
|
||||||
|
Route::any('/paste', '/paste_post.php');
|
||||||
|
Route::any('/pastes/{rand_str_id}', '/paste_view.php');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
0
web/app/storage/paste/.gitkeep
Normal file
0
web/app/storage/paste/.gitkeep
Normal file
Loading…
Reference in New Issue
Block a user