feat(web/contest/self_reviews): markdown support
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Baoshuo Ren 2022-10-12 19:19:54 +08:00
parent 60ba1a5829
commit 0d0b8b0ba7
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
3 changed files with 11 additions and 8 deletions

View File

@ -563,6 +563,7 @@ EOD;
<div class="col-md-6">
<h4>修改我的赛后总结</h4>
<div class="small">赛后总结支持 Markdown 语法。</div>
<?php $self_reviews_update_form->printHTML(); ?>
</div>
<?php endif ?>

View File

@ -41,7 +41,10 @@ $col_names = array('contest_id');
$header_row .= '<th style="width: 35em;">'.UOJLocale::get('contests::contest self review').'</th>';
$header_row .= '</tr>';
$print_row = function($row) {
$parsedown = HTML::parsedown();
$purifier = HTML::purifier_inline();
$print_row = function($row) use ($parsedown, $purifier) {
global $username;
$contest_id = $row['contest_id'];
@ -49,9 +52,6 @@ $col_names = array('contest_id');
$contest_problems = queryContestProblems($contest_id);
$n_contest_problems = count($contest_problems);
$result = '';
$purifier = HTML::purifier_inline();
for ($i = 0; $i < $n_contest_problems; $i++) {
$problem_id = $contest_problems[$i]['problem_id'];
$problem = queryProblemBrief($problem_id);
@ -65,12 +65,12 @@ $col_names = array('contest_id');
$problem_review_id = "review-$contest_id-$i";
$result .= '<td>' . chr(ord('A') + $i) . '. <a href="/problem/' . $problem_id . '">' . $problem['title'] . '</a></td>';
$result .= '<td>' . $purifier->purify($problem_self_review != null ? $problem_self_review['content'] : '') . '</td>';
$result .= '<td>' . $purifier->purify($problem_self_review != null ? $parsedown->line($problem_self_review['content']) : '') . '</td>';
if ($i == 0) {
$contest_review_id = "review-$contest_id-overall";
$contest_self_review = DB::selectFirst("select content from contests_reviews where contest_id = $contest_id and problem_id = -1 and poster = '$username'");
$result .= '<td rowspan="' . $n_contest_problems . '">' . $purifier->purify($contest_self_review != null ? $contest_self_review['content'] : '') . '</td>';
$result .= '<td rowspan="' . $n_contest_problems . '">' . $purifier->purify($contest_self_review != null ? $parsedown->line($contest_self_review['content']) : '') . '</td>';
}
$result .= '</tr>';

View File

@ -112,7 +112,9 @@ function calcStandings($contest, $contest_data, &$score, &$standings, $update_co
}
if ($show_reviews) {
$parsedown = HTML::parsedown();
$purifier = HTML::purifier_inline();
foreach ($contest_data['people'] as $person) {
foreach ($contest_data['problems'] as $key => $problem) {
$review_result = DB::selectFirst("select content from contests_reviews where contest_id = {$contest['id']} and problem_id = {$problem} and poster = '{$person[0]}'");
@ -122,7 +124,7 @@ function calcStandings($contest, $contest_data, &$score, &$standings, $update_co
}
if ($review_result['content']) {
$score[$person[0]][$key][] = $purifier->purify($review_result['content']);
$score[$person[0]][$key][] = $purifier->purify($parsedown->line($review_result['content']));
}
}
}
@ -147,7 +149,7 @@ function calcStandings($contest, $contest_data, &$score, &$standings, $update_co
$review_result = DB::selectFirst("select content from contests_reviews where contest_id = {$contest['id']} and problem_id = -1 and poster = '{$person[0]}'");
if ($review_result['content']) {
$cur[] = $purifier->purify($review_result['content']);
$cur[] = $purifier->purify($parsedown->line($review_result['content']));
}
}