From 54b8415cf5d7695b02ed3c4448dc74119804f2f6 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Wed, 19 Oct 2022 11:23:22 +0800 Subject: [PATCH] fix: 8a7930e18c35e63b8f5102dbdbde07db4bd2f5af --- web/app/models/HTML.php | 30 +++++++++++++++++++++++++++--- web/app/models/UOJMarkdown.php | 6 +++--- web/js/uoj.js | 2 +- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/web/app/models/HTML.php b/web/app/models/HTML.php index f037f09..a361aef 100644 --- a/web/app/models/HTML.php +++ b/web/app/models/HTML.php @@ -144,8 +144,10 @@ class HTML { public static function purifier() { $config = HTMLPurifier_Config::createDefault(); - //$config->set('HTML.Doctype', 'HTML 4.01 Transitional'); - $config->set('Cache.DefinitionImpl', null); + // $config->set('Cache.DefinitionImpl', null); + $config->set('HTML.DefinitionID', 'UOJ__HTML::purifier()'); + $config->set('HTML.DefinitionRev', 1); + $config->set('Output.Newline', true); $def = $config->getHTMLDefinition(true); $def->addElement('section', 'Block', 'Flow', 'Common'); @@ -155,6 +157,16 @@ class HTML { $def->addElement('header', 'Block', 'Flow', 'Common'); $def->addElement('footer', 'Block', 'Flow', 'Common'); + $extra_allowed_html = [ + 'span' => ['data-realname' => 'Text', 'data-uoj-username' => 'Number'], + ]; + + foreach ($extra_allowed_html as $element => $attributes) { + foreach ($attributes as $attribute => $type) { + $def->addAttribute($element, $attribute, $type); + } + } + return new HTMLPurifier($config); } @@ -172,6 +184,7 @@ class HTML { 'small' => [], 'del' => [], 'br' => [], + 'span' => ['data-realname' => 'Text', 'data-uoj-username' => 'Number'], ]; $config = HTMLPurifier_Config::createDefault(); @@ -181,7 +194,7 @@ class HTML { foreach ($allowed_html as $element => $attributes) { $allowed_elements[$element] = true; - foreach ($attributes as $attribute => $x) { + foreach ($attributes as $attribute => $type) { $allowed_attributes["$element.$attribute"] = true; } } @@ -189,6 +202,17 @@ class HTML { $config->set('HTML.AllowedElements', $allowed_elements); $config->set('HTML.AllowedAttributes', $allowed_attributes); + // $config->set('Cache.DefinitionImpl', null); + $config->set('HTML.DefinitionID', 'UOJ__HTML::purifier_inline()'); + $config->set('HTML.DefinitionRev', 1); + $def = $config->getHTMLDefinition(true); + + foreach ($allowed_html as $element => $attributes) { + foreach ($attributes as $attribute => $type) { + $def->addAttribute($element, $attribute, $type); + } + } + return new HTMLPurifier($config); } diff --git a/web/app/models/UOJMarkdown.php b/web/app/models/UOJMarkdown.php index 641641d..64e2ded 100644 --- a/web/app/models/UOJMarkdown.php +++ b/web/app/models/UOJMarkdown.php @@ -54,16 +54,16 @@ class UOJMarkdown extends ParsedownMath { // https://gist.github.com/ShNURoK42/b5ce8baa570975db487c protected function inlineUserMention($Excerpt) { if (preg_match('/^@([^\s]+)/', $Excerpt['text'], $matches)) { - if (validateUsername($matches[1]) && ($user = queryUser($matches[1]))) { + if (validateUsername($matches[1]) && ($user = queryUser($matches[1])) && $user['usergroup'] != 'B') { return [ 'extent' => strlen($matches[0]), 'element' => [ - 'name' => 'a', + 'name' => 'span', 'text' => '@' . $user['username'], 'attributes' => [ - 'href' => '/user/' . $user['username'], 'class' => 'uoj-username', 'data-realname' => $user['realname'], + 'data-uoj-username' => 1, ], ], ]; diff --git a/web/js/uoj.js b/web/js/uoj.js index 68d543c..3c1f465 100644 --- a/web/js/uoj.js +++ b/web/js/uoj.js @@ -428,7 +428,7 @@ $(document).ready(function() { // highlight $.fn.uoj_highlight = function() { return $(this).each(function() { - $(this).find("span.uoj-username").each(replaceWithHighlightUsername); + $(this).find("span.uoj-username, span[data-uoj-username]").each(replaceWithHighlightUsername); $(this).find(".uoj-honor").uoj_honor(); $(this).find(".uoj-testcase").uoj_testcase(); $(this).find(".uoj-score").each(function() {