Commit fb1a72d5 authored by Gordon Bateson's avatar Gordon Bateson
Browse files

MDL-24779 mod/hotpot tidy up calls to js_value() method which escapes and...

MDL-24779 mod/hotpot tidy up calls to js_value() method which escapes and encodes unicode strings for javascript
parent a99a407b
......@@ -66,7 +66,7 @@ class hotpot_xml_template_default {
function int_value($tags, $more_tags="[0]['#']") {
return intval($this->parent->xml_value($tags, $more_tags));
}
function js_value($tags, $more_tags="[0]['#']", $convert_to_unicode=false) {
function js_value($tags, $more_tags="[0]['#']", $convert_to_unicode=true) {
return $this->js_safe($this->parent->xml_value($tags, $more_tags), $convert_to_unicode);
}
function js_safe($str, $convert_to_unicode=false) {
......
......@@ -107,7 +107,8 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default {
return $this->js_value('hotpot-config-file,global,incorrect-indicator');
}
function v6_expand_LastQCaption() {
return $this->parent->xml_value('hotpot-config-file,global,last-q-caption');
$caption = $this->parent->xml_value('hotpot-config-file,global,last-q-caption');
return ($caption=='<=' ? '&lt;=' : $caption);
}
function v6_expand_NextCorrect() {
$value = $this->js_value('hotpot-config-file,'.$this->parent->quiztype.',next-correct-part');
......@@ -333,6 +334,8 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default {
function v6_expand_NavBarJS() {
return $this->v6_expand_NavButtons();
}
// switch off scorm
function v6_expand_Scorm12() {
return false;
}
......@@ -659,7 +662,7 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default {
return $this->parent->xml_value('hotpot-config-file,'.$this->parent->quiztype.',remaining-words');
}
function v6_expand_TimesUp() {
return $this->js_safe($this->parent->xml_value('hotpot-config-file,global,times-up'));
return $this->js_value('hotpot-config-file,global,times-up');
}
// nav bar
......@@ -826,7 +829,7 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default {
$a = 0;
$aa = 0;
while (($answer=$question."['answer'][$a]['#']") && $this->parent->xml_value($tags, $answer)) {
$text = $this->js_value($tags, $answer."['text'][0]['#']", true);
$text = $this->js_value($tags, $answer."['text'][0]['#']");
if (strlen($text)) {
if ($aa==0) { // first time only
$str .= "\n";
......@@ -841,7 +844,7 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default {
}
// add clue, if any answers were found
if ($aa) {
$clue = $this->js_value($tags, $question."['clue'][0]['#']", true);
$clue = $this->js_value($tags, $question."['clue'][0]['#']");
$str .= "I[$q][2] = '$clue';\n";
}
$q++;
......@@ -854,15 +857,15 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default {
$question_type = $this->int_value($tags, $question."['question-type'][0]['#']");
$weighting = $this->int_value($tags, $question."['weighting'][0]['#']");
$clue = $this->js_value($tags, $question."['clue'][0]['#']", true);
$clue = $this->js_value($tags, $question."['clue'][0]['#']");
$answers = $question."['answers'][0]['#']";
$a = 0;
$aa = 0;
while (($answer = $answers."['answer'][$a]['#']") && $this->parent->xml_value($tags, $answer)) {
$text = $this->js_value($tags, $answer."['text'][0]['#']", true);
$feedback = $this->js_value($tags, $answer."['feedback'][0]['#']", true);
$text = $this->js_value($tags, $answer."['text'][0]['#']");
$feedback = $this->js_value($tags, $answer."['feedback'][0]['#']");
$correct = $this->int_value($tags, $answer."['correct'][0]['#']");
$percent = $this->int_value($tags, $answer."['percent-correct'][0]['#']");
$include = $this->int_value($tags, $answer."['include-in-mc-options'][0]['#']");
......@@ -1086,13 +1089,13 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default {
// JCross quiztype
function v6_expand_CluesAcrossLabel() {
return $this->js_value('hotpot-config-file,'.$this->parent->quiztype.',clues-across');
$this->parent->xml_value('hotpot-config-file,'.$this->parent->quiztype.',clues-across');
}
function v6_expand_CluesDownLabel() {
return $this->js_value('hotpot-config-file,'.$this->parent->quiztype.',clues-down');
$this->parent->xml_value('hotpot-config-file,'.$this->parent->quiztype.',clues-down');
}
function v6_expand_EnterCaption() {
return $this->js_value('hotpot-config-file,'.$this->parent->quiztype.',enter-caption');
$this->parent->xml_value('hotpot-config-file,'.$this->parent->quiztype.',enter-caption');
}
function v6_expand_ShowHideClueList() {
$value = $this->int_value('hotpot-config-file,'.$this->parent->quiztype.',include-clue-list');
......@@ -1452,16 +1455,16 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default {
// hp6checkshortanswers.js_ (JQuiz)
function v6_expand_CorrectList() {
return $this->parent->xml_value('hotpot-config-file,'.$this->parent->quiztype.',correct-answers');
return $this->js_value('hotpot-config-file,'.$this->parent->quiztype.',correct-answers');
}
function v6_expand_HybridTries() {
return $this->parent->xml_value('hotpot-config-file,'.$this->parent->quiztype.',short-answer-tries-on-hybrid-q');
}
function v6_expand_PleaseEnter() {
return $this->parent->xml_value('hotpot-config-file,'.$this->parent->quiztype.',enter-a-guess');
return $this->js_value('hotpot-config-file,'.$this->parent->quiztype.',enter-a-guess');
}
function v6_expand_PartlyIncorrect() {
return $this->parent->xml_value('hotpot-config-file,'.$this->parent->quiztype.',partly-incorrect');
return $this->js_value('hotpot-config-file,'.$this->parent->quiztype.',partly-incorrect');
}
function v6_expand_ShowAnswerCaption() {
return $this->parent->xml_value('hotpot-config-file,'.$this->parent->quiztype.',show-answer-caption');
......@@ -1479,15 +1482,15 @@ function hotpot_sort_keypad_chars($a, $b) {
function hotpot_keypad_sort_value($char) {
// hexadecimal
if (preg_match('|&#x([0-9A-F]+);|ie', $char, $matches)) {
if (preg_match('/&#x([0-9A-F]+);/i', $char, $matches)) {
$ord = hexdec($matches[1]);
// decimal
} else if (preg_match('|&#(\d+);|i', $char, $matches)) {
} else if (preg_match('/&#(\d+);/i', $char, $matches)) {
$ord = intval($matches[1]);
// other html entity
} else if (preg_match('|&[^;]+;|', $char, $matches)) {
} else if (preg_match('/&[^;]+;/', $char, $matches)) {
$char = html_entity_decode($matches[0]);
$ord = empty($char) ? 0 : ord($char);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment