2022-09-28 11:48:49 +00:00
|
|
|
<?php
|
2022-11-06 02:26:21 +00:00
|
|
|
requireLib('hljs');
|
|
|
|
requireLib('mathjax');
|
|
|
|
requirePHPLib('form');
|
|
|
|
requirePHPLib('judger');
|
|
|
|
|
|
|
|
Auth::check() || redirectToLogin();
|
|
|
|
UOJProblem::init(UOJRequest::get('id')) || UOJResponse::page404();
|
2022-11-11 23:10:34 +00:00
|
|
|
UOJProblem::cur()->userCanView(Auth::user(), ['ensure' => true]);
|
2022-11-06 02:26:21 +00:00
|
|
|
|
|
|
|
if (!UOJProblem::cur()->userCanManage(Auth::user())) {
|
|
|
|
UOJProblem::cur()->userPermissionCodeCheck(Auth::user(), UOJProblem::cur()->getExtraConfig('view_solution_type')) || UOJResponse::page403();
|
|
|
|
|
|
|
|
foreach (UOJProblem::cur()->findInContests() as $cp) {
|
|
|
|
if ($cp->contest->progress() == CONTEST_IN_PROGRESS && $cp->contest->userHasRegistered(Auth::user())) {
|
|
|
|
UOJResponse::page403();
|
|
|
|
}
|
2022-09-28 11:48:49 +00:00
|
|
|
}
|
2022-11-06 02:26:21 +00:00
|
|
|
}
|
2022-09-28 11:48:49 +00:00
|
|
|
|
2022-11-06 02:26:21 +00:00
|
|
|
if (UOJRequest::post('submit-remove_solution') === 'remove_solution') {
|
|
|
|
crsf_defend();
|
2022-10-07 09:29:26 +00:00
|
|
|
|
2022-11-06 02:26:21 +00:00
|
|
|
$blog = UOJBlog::query(UOJRequest::post('blog_id'));
|
2022-09-28 11:48:49 +00:00
|
|
|
|
2022-11-06 02:26:21 +00:00
|
|
|
if (!$blog || !$blog->userCanView(Auth::user())) {
|
|
|
|
dieWithAlert('博客不存在。');
|
2022-10-03 00:49:23 +00:00
|
|
|
}
|
|
|
|
|
2022-11-06 02:26:21 +00:00
|
|
|
if (!UOJProblem::cur()->userCanManage(Auth::user()) && $blog->info['poster'] != Auth::id()) {
|
|
|
|
dieWithAlert('您没有权限移除该题解。');
|
2022-09-28 11:48:49 +00:00
|
|
|
}
|
|
|
|
|
2022-11-06 02:26:21 +00:00
|
|
|
if ($blog->info['poster'] != Auth::id()) {
|
|
|
|
sendSystemMsg(
|
|
|
|
$blog->info['poster'],
|
|
|
|
'题解移除通知',
|
2023-02-13 10:46:06 +00:00
|
|
|
"<p>" . UOJUser::getLink($blog->info['poster'], ['color' => false]) . " 您好:</p>" .
|
|
|
|
"<p>您为问题 " . UOJProblem::cur()->getLink(['with' => 'id']) . " 提交的题解 " . $blog->getLink() . " 已被管理员移除。</p>"
|
2022-11-06 02:26:21 +00:00
|
|
|
);
|
2022-10-03 01:11:43 +00:00
|
|
|
}
|
2022-09-28 11:48:49 +00:00
|
|
|
|
2022-11-06 02:26:21 +00:00
|
|
|
DB::delete([
|
|
|
|
"delete from problems_solutions",
|
|
|
|
"where", [
|
|
|
|
"problem_id" => UOJProblem::info('id'),
|
|
|
|
"blog_id" => $blog->info['id'],
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
dieWithAlert('移除成功!');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (UOJProblem::cur()->userCanManage(Auth::user()) || UOJProblem::cur()->userPermissionCodeCheck(Auth::user(), UOJProblem::cur()->getExtraConfig('submit_solution_type'))) {
|
2022-12-24 03:01:04 +00:00
|
|
|
$add_new_solution_form = new UOJForm('add_new_solution');
|
2023-02-02 03:39:22 +00:00
|
|
|
$add_new_solution_form->addInput('blog_id_2', [
|
|
|
|
'div_class' => 'flex-grow-1',
|
|
|
|
'placeholder' => '博客 ID',
|
|
|
|
'validator_php' => function ($blog_id, &$vdata) {
|
|
|
|
$blog = UOJBlog::query($blog_id);
|
|
|
|
|
|
|
|
if (!$blog) {
|
|
|
|
return '博客不存在';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$blog->userCanManage(Auth::user())) {
|
|
|
|
if ($blog->info['poster'] != Auth::id()) {
|
2022-12-24 03:01:04 +00:00
|
|
|
if ($blog->info['is_hidden']) {
|
2023-02-02 03:39:22 +00:00
|
|
|
return '博客不存在';
|
2022-12-24 03:01:04 +00:00
|
|
|
}
|
2023-02-02 03:39:22 +00:00
|
|
|
|
|
|
|
return '只能提交本人撰写的博客';
|
2022-09-28 11:48:49 +00:00
|
|
|
}
|
2023-02-02 03:39:22 +00:00
|
|
|
}
|
2022-09-28 11:48:49 +00:00
|
|
|
|
2023-02-02 03:39:22 +00:00
|
|
|
if (!UOJProblem::cur()->userCanManage(Auth::user())) {
|
|
|
|
if ($blog->info['is_hidden']) {
|
|
|
|
return '只能提交公开的博客';
|
2022-09-28 11:48:49 +00:00
|
|
|
}
|
2023-02-02 03:39:22 +00:00
|
|
|
}
|
2022-09-28 11:48:49 +00:00
|
|
|
|
2023-02-02 03:39:22 +00:00
|
|
|
if ($problem_id = $blog->getSolutionProblemId()) {
|
|
|
|
return "该博客已经是题目 #$problem_id 的题解";
|
|
|
|
}
|
2022-09-28 11:48:49 +00:00
|
|
|
|
2023-02-02 03:39:22 +00:00
|
|
|
$vdata['blog'] = $blog;
|
|
|
|
|
|
|
|
return '';
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
$add_new_solution_form->config['form']['class'] = 'd-flex';
|
2023-02-07 11:07:53 +00:00
|
|
|
$add_new_solution_form->config['submit_container']['class'] = 'ms-2 flex-shrink-0';
|
2022-12-24 03:01:04 +00:00
|
|
|
$add_new_solution_form->config['submit_button']['text'] = '发布';
|
|
|
|
$add_new_solution_form->handle = function (&$vdata) {
|
2022-11-06 02:26:21 +00:00
|
|
|
DB::insert([
|
|
|
|
"insert into problems_solutions",
|
|
|
|
DB::bracketed_fields(["problem_id", "blog_id"]),
|
2022-12-24 03:01:04 +00:00
|
|
|
"values", DB::tuple([UOJProblem::info('id'), $vdata['blog']->info['id']]),
|
2022-11-06 02:26:21 +00:00
|
|
|
]);
|
|
|
|
};
|
|
|
|
$add_new_solution_form->runAtServer();
|
2023-01-14 00:44:59 +00:00
|
|
|
|
|
|
|
if (UOJUser::checkPermission(Auth::user(), 'blogs.create')) {
|
|
|
|
$quick_add_new_solution_form = new UOJForm('quick_add_new_solution');
|
|
|
|
$quick_add_new_solution_form->config['submit_container']['class'] = '';
|
|
|
|
$quick_add_new_solution_form->config['submit_button']['class'] = 'btn btn-link text-decoration-none p-0';
|
|
|
|
$quick_add_new_solution_form->config['submit_button']['text'] = '快速新建文章';
|
|
|
|
$quick_add_new_solution_form->handle = function () {
|
|
|
|
DB::insert([
|
|
|
|
"insert into blogs",
|
|
|
|
"(title, content, content_md, poster, is_hidden, post_time, active_time)",
|
|
|
|
"values", DB::tuple([
|
|
|
|
'【题解】' . UOJProblem::cur()->getTitle(), '', '',
|
|
|
|
Auth::id(), false, DB::now(), DB::now()
|
|
|
|
])
|
|
|
|
]);
|
|
|
|
|
|
|
|
$blog_id = DB::insert_id();
|
|
|
|
|
2023-01-17 05:56:53 +00:00
|
|
|
DB::insert([
|
|
|
|
"insert into problems_solutions",
|
|
|
|
DB::bracketed_fields(["problem_id", "blog_id"]),
|
|
|
|
"values", DB::tuple([UOJProblem::info('id'), $blog_id]),
|
|
|
|
]);
|
|
|
|
|
2023-01-14 00:44:59 +00:00
|
|
|
redirectTo(HTML::blog_url(Auth::id(), "/post/{$blog_id}/write"));
|
|
|
|
die();
|
|
|
|
};
|
|
|
|
$quick_add_new_solution_form->runAtServer();
|
|
|
|
}
|
2022-11-06 02:26:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$pag_config = [
|
|
|
|
'page_len' => 5,
|
|
|
|
'col_names' => ['blog_id', 'zan'],
|
|
|
|
'table_name' => 'problems_solutions inner join blogs on blogs.id = problems_solutions.blog_id',
|
|
|
|
'cond' => ["problem_id" => UOJProblem::info('id')],
|
|
|
|
'post_filter' => function ($row) {
|
|
|
|
$blog = UOJBlog::query($row['blog_id']);
|
|
|
|
|
|
|
|
// 根据实际使用需要,题目管理员可以通过题解页面看到其他用户提交的题解,并且即使该题解对应的博客是隐藏状态也会照常显示
|
|
|
|
// 如需仅允许超级管理员查看,请将下一行改为 return $blog->userCanView(Auth::user());
|
|
|
|
return $blog->userCanView(Auth::user()) || UOJProblem::cur()->userCanManage(Auth::user());
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
$pag_config['tail'] = "order by zan desc, post_time desc, id asc";
|
|
|
|
$pag = new Paginator($pag_config);
|
|
|
|
?>
|
2022-09-28 11:48:49 +00:00
|
|
|
|
2022-11-07 07:44:01 +00:00
|
|
|
<?php echoUOJPageHeader(UOJLocale::get('problems::solutions') . ' - ' . HTML::stripTags(UOJProblem::cur()->getTitle(['with' => 'id']))) ?>
|
2022-09-28 11:48:49 +00:00
|
|
|
|
|
|
|
<div class="row">
|
2022-11-06 02:26:21 +00:00
|
|
|
<!-- Left col -->
|
|
|
|
<div class="col-lg-9">
|
|
|
|
<div class="card card-default mb-2">
|
|
|
|
<div class="card-body">
|
|
|
|
<h1 class="card-title text-center">
|
|
|
|
<?= UOJProblem::cur()->getTitle(['with' => 'id']) ?>
|
|
|
|
</h1>
|
|
|
|
</div>
|
2022-09-28 11:48:49 +00:00
|
|
|
|
2022-11-06 02:26:21 +00:00
|
|
|
<ul class="list-group list-group-flush">
|
|
|
|
<?php foreach ($pag->get() as $row) : ?>
|
|
|
|
<?php
|
|
|
|
$blog = UOJBlog::query($row['blog_id']);
|
|
|
|
$poster = UOJUser::query($blog->info['poster']);
|
|
|
|
?>
|
|
|
|
<li class="list-group-item">
|
|
|
|
<div class="mb-3">
|
|
|
|
<span class="me-2 d-inline-block">
|
|
|
|
<a class="text-decoration-none" href="<?= HTML::url('/user/' . $poster['username']) ?>">
|
2023-02-07 11:36:48 +00:00
|
|
|
<img src="<?= HTML::avatar_addr($poster, 64) ?>" width="32" height="32" class="rounded uoj-user-avatar" />
|
2022-11-06 02:26:21 +00:00
|
|
|
</a>
|
|
|
|
<?= UOJUser::getLink($poster) ?>
|
|
|
|
</span>
|
|
|
|
<span class="text-muted small d-inline-block">
|
|
|
|
<?= UOJLocale::get('post time') ?>:
|
|
|
|
<time class="text-muted"><?= $blog->info['post_time'] ?></time>
|
|
|
|
</span>
|
|
|
|
<?php if ($blog->info['is_hidden']) : ?>
|
|
|
|
<span class="badge text-bg-danger ms-2">
|
|
|
|
<i class="bi bi-eye-slash-fill"></i>
|
|
|
|
<?= UOJLocale::get('hidden') ?>
|
|
|
|
</span>
|
|
|
|
<?php endif ?>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="markdown-body">
|
|
|
|
<?= $blog->queryContent()['content'] ?>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<ul class="mt-3 text-end list-inline">
|
|
|
|
<?php if (UOJProblem::cur()->userCanManage(Auth::user()) || $poster['username'] == Auth::id()) : ?>
|
|
|
|
<li class="list-inline-item">
|
|
|
|
<form class="d-inline-block" method="POST" onsubmit="return confirm('你真的要移除这篇题解吗?移除题解不会删除对应博客。')">
|
|
|
|
<input type="hidden" name="_token" value="<?= crsf_token() ?>">
|
|
|
|
<input type="hidden" name="blog_id" value="<?= $blog->info['id'] ?>">
|
|
|
|
<button class="btn btn-link text-decoration-none text-danger p-0 mt-0" type="submit" name="submit-remove_solution" value="remove_solution">
|
|
|
|
移除
|
|
|
|
</button>
|
|
|
|
</form>
|
|
|
|
</li>
|
|
|
|
<?php endif ?>
|
|
|
|
<?php if ($blog->userCanManage(Auth::user())) : ?>
|
|
|
|
<li class="list-inline-item">
|
|
|
|
<a class="d-inline-block align-middle" href="<?= $blog->getUriForWrite() ?>">
|
|
|
|
修改
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
<?php endif ?>
|
|
|
|
<li class="list-inline-item">
|
|
|
|
<a class="d-inline-block align-middle" href="<?= $blog->getBlogUri() ?>">
|
|
|
|
在 Ta 的博客上查看
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
<li class="list-inline-item">
|
|
|
|
<?= ClickZans::getBlock('B', $blog->info['id'], $blog->info['zan']) ?>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
<?php endforeach ?>
|
|
|
|
<?php if ($pag->isEmpty()) : ?>
|
|
|
|
<div class="text-center text-muted py-4">
|
|
|
|
暂无题解
|
|
|
|
</div>
|
|
|
|
<?php endif ?>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<?= $pag->pagination() ?>
|
2022-09-28 11:48:49 +00:00
|
|
|
</div>
|
2022-11-11 23:10:34 +00:00
|
|
|
<!-- end left col -->
|
2022-11-06 02:26:21 +00:00
|
|
|
|
2022-11-11 23:10:34 +00:00
|
|
|
<!-- right col -->
|
2022-11-06 02:26:21 +00:00
|
|
|
<aside class="col-lg-3 mt-3 mt-lg-0">
|
2022-12-04 12:44:51 +00:00
|
|
|
<!-- 题目导航 -->
|
2022-11-06 02:26:21 +00:00
|
|
|
<div class="card card-default mb-2">
|
|
|
|
<ul class="nav nav-pills nav-fill flex-column" role="tablist">
|
|
|
|
<li class="nav-item text-start">
|
|
|
|
<a href="/problem/<?= UOJProblem::info('id') ?>" class="nav-link" role="tab">
|
|
|
|
<i class="bi bi-journal-text"></i>
|
|
|
|
<?= UOJLocale::get('problems::statement') ?>
|
|
|
|
</a>
|
|
|
|
</li>
|
2022-12-06 06:51:09 +00:00
|
|
|
<li class="nav-item text-start">
|
|
|
|
<a href="/problem/<?= UOJProblem::info('id') ?>#submit" class="nav-link" role="tab">
|
|
|
|
<i class="bi bi-upload"></i>
|
|
|
|
<?= UOJLocale::get('problems::submit') ?>
|
|
|
|
</a>
|
|
|
|
</li>
|
2022-11-06 02:26:21 +00:00
|
|
|
<li class="nav-item text-start">
|
|
|
|
<a href="#" class="nav-link active" role="tab">
|
|
|
|
<i class="bi bi-journal-bookmark"></i>
|
|
|
|
<?= UOJLocale::get('problems::solutions') ?>
|
|
|
|
</a>
|
|
|
|
</li>
|
2022-11-23 08:31:37 +00:00
|
|
|
<li class="nav-item text-start">
|
|
|
|
<a class="nav-link" href="/submissions?problem_id=<?= UOJProblem::info('id') ?>">
|
|
|
|
<i class="bi bi-list-ul"></i>
|
|
|
|
<?= UOJLocale::get('submissions') ?>
|
|
|
|
</a>
|
|
|
|
</li>
|
2022-11-06 02:26:21 +00:00
|
|
|
<li class="nav-item text-start">
|
|
|
|
<a class="nav-link" href="/problem/<?= UOJProblem::info('id') ?>/statistics">
|
|
|
|
<i class="bi bi-graph-up"></i>
|
|
|
|
<?= UOJLocale::get('problems::statistics') ?>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
<?php if (UOJProblem::cur()->userCanManage(Auth::user())) : ?>
|
|
|
|
<li class="nav-item text-start">
|
|
|
|
<a class="nav-link" href="/problem/<?= UOJProblem::info('id') ?>/manage/statement" role="tab">
|
|
|
|
<i class="bi bi-sliders"></i>
|
|
|
|
<?= UOJLocale::get('problems::manage') ?>
|
2022-09-28 11:48:49 +00:00
|
|
|
</a>
|
2022-10-08 02:06:44 +00:00
|
|
|
</li>
|
2022-11-06 02:26:21 +00:00
|
|
|
<?php endif ?>
|
|
|
|
</ul>
|
2022-12-04 12:44:51 +00:00
|
|
|
</div>
|
|
|
|
|
2022-11-06 02:26:21 +00:00
|
|
|
<div class="card card-default mb-2">
|
2023-02-16 08:57:42 +00:00
|
|
|
<div class="card-header fw-bold">
|
2022-11-06 02:26:21 +00:00
|
|
|
增加题解
|
|
|
|
</div>
|
|
|
|
<div class="card-body">
|
|
|
|
<?php if (isset($add_new_solution_form)) : ?>
|
|
|
|
<?php $add_new_solution_form->printHTML(); ?>
|
|
|
|
<?php else : ?>
|
|
|
|
您当前无法为本题新增题解。
|
|
|
|
<?php endif ?>
|
|
|
|
</div>
|
2023-01-14 00:44:59 +00:00
|
|
|
<?php if (isset($quick_add_new_solution_form)) : ?>
|
|
|
|
<div class="card-footer bg-transparent">
|
|
|
|
<?php $quick_add_new_solution_form->printHTML() ?>
|
|
|
|
</div>
|
|
|
|
<?php endif ?>
|
2022-11-06 02:26:21 +00:00
|
|
|
</div>
|
2022-09-28 11:48:49 +00:00
|
|
|
|
2023-01-14 00:44:59 +00:00
|
|
|
<?php uojIncludeView('sidebar') ?>
|
2022-11-06 02:26:21 +00:00
|
|
|
</aside>
|
2023-01-14 00:44:59 +00:00
|
|
|
<!-- end right col -->
|
2022-09-28 11:48:49 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<?php echoUOJPageFooter() ?>
|