From ed728833da1088e3a5f35a342ad0720a740bf197 Mon Sep 17 00:00:00 2001 From: Kumi Date: Wed, 31 Aug 2022 09:21:49 +0000 Subject: [PATCH] Remove HTML tags from questions and answers --- import_cli.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/import_cli.php b/import_cli.php index 2143b04..7446c15 100644 --- a/import_cli.php +++ b/import_cli.php @@ -133,6 +133,31 @@ if (!$fullname) { $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))) { $matches = NULL; preg_match('/(.*)_(\d+)$/', $shortname, $matches);