Remove HTML tags from questions and answers

This commit is contained in:
Kumi 2022-08-31 09:21:49 +00:00
parent 21094f4a51
commit ed728833da
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -133,6 +133,31 @@ if (!$fullname) {
$fullname = $shortname; $fullname = $shortname;
} }
$questionfile = $path . DIRECTORY_SEPARATOR . "questions.xml";
if (file_exists($questionfile)) {
$questions = new DOMDocument();
$questions->load($questionfile);
$questions->save($questionfile . ".bak");
$questionsection = $questions->documentElement->getElementsByTagName("questions")->item(0);
foreach ($questionsection->getElementsByTagName("question") as $question) {
$questiontext = $question->getElementsByTagName("questiontext")->item(0);
$newquestiontext = strip_tags(html_entity_decode($questiontext->textContent));
$questiontext->nodeValue = htmlentities($newquestiontext, ENT_XML1);
foreach ($question->getElementsByTagName("answer") as $answer) {
$answertext = $answer->getElementsByTagName("answertext")->item(0);
$newanswertext = strip_tags(html_entity_decode($answertext->textContent));
$answertext->nodeValue = htmlentities($newanswertext, ENT_XML1);
}
}
$questions->save($questionfile);
}
if (!$course && $DB->get_record('course', array('category' => $category->id, 'shortname' => $shortname))) { if (!$course && $DB->get_record('course', array('category' => $category->id, 'shortname' => $shortname))) {
$matches = NULL; $matches = NULL;
preg_match('/(.*)_(\d+)$/', $shortname, $matches); preg_match('/(.*)_(\d+)$/', $shortname, $matches);