diff --git a/web/app/controllers/new_remote_problem.php b/web/app/controllers/new_remote_problem.php index 0cb4562..f5f750b 100644 --- a/web/app/controllers/new_remote_problem.php +++ b/web/app/controllers/new_remote_problem.php @@ -98,6 +98,12 @@ $new_remote_problem_form->handle = function (&$vdata) { ]); $id = DB::insert_id(); + dataNewProblem($id); + + if ($data['type'] == 'pdf') { + file_put_contents(UOJContext::storagePath() , "/problem_resources/$id/statement.pdf", $data['pdf_data']); + $data['statement'] = "
\n" . $data['statement']; + } DB::insert([ "insert into problems_contents", @@ -105,7 +111,6 @@ $new_remote_problem_form->handle = function (&$vdata) { "values", DB::tuple([$id, HTML::purifier(['a' => ['target' => 'Enum#_blank']])->purify($data['statement']), '', '']) ]); - dataNewProblem($id); DB::insert([ "insert into problems_tags", diff --git a/web/app/controllers/problem.php b/web/app/controllers/problem.php index 70abace..1575b6d 100644 --- a/web/app/controllers/problem.php +++ b/web/app/controllers/problem.php @@ -2,6 +2,7 @@ requireLib('bootstrap5'); requireLib('hljs'); requireLib('mathjax'); +requireLib('pdf.js'); requirePHPLib('form'); requirePHPLib('judger'); diff --git a/web/app/controllers/problem_statement_manage.php b/web/app/controllers/problem_statement_manage.php index a97ac67..e4a6d77 100644 --- a/web/app/controllers/problem_statement_manage.php +++ b/web/app/controllers/problem_statement_manage.php @@ -144,6 +144,11 @@ if (UOJProblem::info('type') == 'remote') { ], ]); + if ($data['type'] == 'pdf') { + file_put_contents(UOJContext::storagePath() . "/problem_resources/" . UOJProblem::info('id') . "/statement.pdf", $data['pdf_data']); + $data['statement'] = '' . "\n" . $data['statement']; + } + DB::update([ "update problems_contents", "set", [ diff --git a/web/app/models/HTML.php b/web/app/models/HTML.php index 7ac1312..a3c839b 100644 --- a/web/app/models/HTML.php +++ b/web/app/models/HTML.php @@ -436,6 +436,10 @@ class HTML { $def->addElement('footer', 'Block', 'Flow', 'Common'); mergeConfig($extra_allowed_html, [ + 'div' => [ + 'data-pdf' => 'Text', + 'data-src' => 'URI', + ], 'span' => [ 'class' => 'Enum#uoj-username', 'data-realname' => 'Text', diff --git a/web/app/models/UOJBlogEditor.php b/web/app/models/UOJBlogEditor.php index d4e23f1..7d9bc21 100644 --- a/web/app/models/UOJBlogEditor.php +++ b/web/app/models/UOJBlogEditor.php @@ -9,7 +9,7 @@ class UOJBlogEditor { public $post_data = []; public $show_editor = true; public $show_tags = true; - + public $label_text = [ 'title' => '标题', 'tags' => '标签(多个标签用逗号隔开)', @@ -19,15 +19,15 @@ class UOJBlogEditor { 'private' => '未公开', 'public' => '公开' ]; - + public $validator = array(); - + function __construct() { global $REQUIRE_LIB; $REQUIRE_LIB['blog-editor'] = ''; - + $this->validator = [ - 'title' => function(&$title) { + 'title' => function (&$title) { if ($title == '') { return '标题不能为空'; } @@ -39,13 +39,13 @@ class UOJBlogEditor { } return ''; }, - 'content_md' => function(&$content_md) { + 'content_md' => function (&$content_md) { if (strlen($content_md) > 1000000) { return '内容过长'; } return ''; }, - 'tags' => function(&$tags) { + 'tags' => function (&$tags) { $tags = str_replace(',', ',', $tags); $tags_raw = explode(',', $tags); if (count($tags_raw) > 10) { @@ -58,10 +58,10 @@ class UOJBlogEditor { continue; } if (strlen($tag) > 30) { - return '标签 “' . HTML::escape($tag) .'” 太长'; + return '标签 “' . HTML::escape($tag) . '” 太长'; } if (in_array($tag, $tags, true)) { - return '标签 “' . HTML::escape($tag) .'” 重复出现'; + return '标签 “' . HTML::escape($tag) . '” 重复出现'; } $tags[] = $tag; } @@ -69,7 +69,7 @@ class UOJBlogEditor { } ]; } - + public function validate($name) { if (!isset($_POST["{$this->name}_{$name}"])) { return '不能为空'; @@ -98,14 +98,14 @@ class UOJBlogEditor { die(json_encode($errors)); } crsf_defend(); - + $this->post_data['is_hidden'] = isset($_POST["{$this->name}_is_hidden"]) ? 1 : 0; - + $purifier = HTML::purifier(); $parsedown = HTML::parsedown(); - + $this->post_data['title'] = HTML::escape($this->post_data['title']); - + if ($this->show_editor) { if ($this->type == 'blog') { $this->post_data['content'] = $parsedown->text($this->post_data['content_md']); @@ -113,7 +113,7 @@ class UOJBlogEditor { if (preg_match('/^.*.*$/m', $this->post_data['content'], $matches, PREG_OFFSET_CAPTURE)) { $content_less = substr($this->post_data['content'], 0, $matches[0][1]); $content_more = substr($this->post_data['content'], $matches[0][1] + strlen($matches[0][0])); - $this->post_data['content'] = $purifier->purify($content_less).''.$purifier->purify($content_more); + $this->post_data['content'] = $purifier->purify($content_less) . '' . $purifier->purify($content_more); } else { $this->post_data['content'] = $purifier->purify($this->post_data['content']); } @@ -122,20 +122,22 @@ class UOJBlogEditor { if ($content_array === false || !is_array($content_array)) { die(json_encode(array('content_md' => '不合法的 YAML 格式'))); } - - $marked = function($md) use ($parsedown, $purifier) { + + $marked = function ($md) use ($parsedown, $purifier) { $dom = new DOMDocument; $dom->loadHTML(mb_convert_encoding($parsedown->text($md), 'HTML-ENTITIES', 'UTF-8')); $elements = $dom->getElementsByTagName('li'); - + foreach ($elements as $element) { - $element->setAttribute('class', - $element->getAttribute('class') . ' fragment'); + $element->setAttribute( + 'class', + $element->getAttribute('class') . ' fragment' + ); } return $purifier->purify($dom->saveHTML()); }; - + $config = array(); $this->post_data['content'] = ''; foreach ($content_array as $slide_name => $slide_content) { @@ -147,9 +149,9 @@ class UOJBlogEditor { } continue; } - + $this->post_data['content'] .= '