S2OJ/web/app/controllers/paste_post.php

38 lines
1.0 KiB
PHP
Raw Normal View History

2020-08-05 16:24:34 +00:00
<?php
requirePHPLib('form');
requirePHPLib('judger');
2022-03-17 04:00:03 +00:00
if (!Auth::check()) {
becomeMsgPage(UOJLocale::get('need login'));
2020-08-05 16:24:34 +00:00
}
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);
}
2020-08-13 17:29:26 +00:00
DB::query("insert into pastes (`index`, `creator`, `content`, `created_at`) values ('$esc_index', '${myUser['username']}', '$esc_content', '".date('Y-m-d H:i:s')."')");
2020-08-05 16:24:34 +00:00
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();
2022-03-17 04:00:03 +00:00
echoUOJPageFooter();