From 2a0079c83c5fe79588b4c82d7df92f670c915c6e Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Sun, 27 Oct 2019 11:28:52 +0100 Subject: [PATCH] Minor - Update from 1.11.x --- tests/scripts/fix_mimetex.php | 128 ++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 tests/scripts/fix_mimetex.php diff --git a/tests/scripts/fix_mimetex.php b/tests/scripts/fix_mimetex.php new file mode 100644 index 0000000000..5d742d77db --- /dev/null +++ b/tests/scripts/fix_mimetex.php @@ -0,0 +1,128 @@ + $content + ]; + Database::update('c_quiz_question', $params, ['id = ? and c_id = ?' => [$id, $courseId]]); + + $sql = "SELECT iid, answer, comment FROM c_quiz_answer WHERE question_id = $id and c_id = $courseId"; + $result = Database::query($sql); + $items = Database::store_result($result, 'ASSOC'); + foreach ($items as $item) { + $id = $item['iid']; + $answer = fixText($item['answer']); + $comment = fixText($item['comment']); + $params = [ + 'answer' => $answer, + 'comment' => $comment, + ]; + Database::update('c_quiz_answer', $params, ['iid = ? ' => $id]); + } +} + +function fixText($content) +{ + $debug = false; + if (strpos($content, 'mimetex.cgi') !== false) { + $content = preg_replace('/[\r\n]+/', '', $content); + //$debug = true; + if ($debug) { + var_dump($content); + } + } + + $matches = []; + if (preg_match_all('/(.*?)/', $content, $matches)) { + $count = count($matches[0]); + for ($i = 0; $i <= $count; $i++) { + if (isset($matches[0]) && isset($matches[0][$i])) { + $value = "`".$matches[1][$i]."`"; + $content = str_replace($matches[0][$i], $value, $content); + } + } + } + + $matches = []; + /*(.*)? + (.*)?*/ + // if (preg_match_all('/(.*)?/', $content, $matches)) { + if (preg_match_all('/(.*?)`".$matches[3][$i]."`"; + $content = str_replace($matches[0][$i], $value, $content); + } + } + } + + $matches = []; + if (preg_match_all('/(.*?)/', $content, $matches)) { + $count = count($matches[0]); + for ($i = 0; $i <= $count; $i++) { + if (isset($matches[0]) && isset($matches[0][$i])) { + $value = "`".$matches[3][$i]."`"; + $content = str_replace($matches[0][$i], $value, $content); + } + } + } + + $matches = []; + if (preg_match_all('/(.*?)`".$matches[3][$i]."`"; + $content = str_replace($matches[0][$i], $value, $content); + } + } + } + + $matches = []; + if (preg_match_all('/(.*?)/', $content, $matches)) { + $count = count($matches[0]); + for ($i = 0; $i <= $count; $i++) { + if (isset($matches[0]) && isset($matches[0][$i])) { + $value = "`".$matches[3][$i]."`"; + $content = str_replace($matches[0][$i], $value, $content); + } + } + } + + $matches = []; + if (preg_match_all('//', $content, $matches)) { + $count = count($matches[0]); + for ($i = 0; $i <= $count; $i++) { + if (isset($matches[0]) && isset($matches[0][$i])) { + $value = "`".$matches[3][$i]."`"; + $content = str_replace($matches[0][$i], $value, $content); + } + } + } + + if ($debug) { + var_dump($content); + } + + return $content; +}