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 { ...@@ -66,7 +66,7 @@ class hotpot_xml_template_default {
function int_value($tags, $more_tags="[0]['#']") { function int_value($tags, $more_tags="[0]['#']") {
return intval($this->parent->xml_value($tags, $more_tags)); 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); return $this->js_safe($this->parent->xml_value($tags, $more_tags), $convert_to_unicode);
} }
function js_safe($str, $convert_to_unicode=false) { function js_safe($str, $convert_to_unicode=false) {
......
<?PHP <?PHP
class hotpot_xml_quiz_template extends hotpot_xml_template_default { class hotpot_xml_quiz_template extends hotpot_xml_template_default {
// left and right items for JMatch // left and right items for JMatch
...@@ -9,13 +9,13 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default { ...@@ -9,13 +9,13 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default {
function hotpot_xml_quiz_template(&$parent) { function hotpot_xml_quiz_template(&$parent) {
$this->parent = &$parent; $this->parent = &$parent;
$get_js = optional_param('js', false); $get_js = optional_param('js', false);
$get_css = optional_param('css', false); $get_css = optional_param('css', false);
if (!empty($get_css)) { if (!empty($get_css)) {
// set $this->css // set $this->css
$this->v6_expand_StyleSheet(); $this->v6_expand_StyleSheet();
} else if (!empty($get_js)) { } else if (!empty($get_js)) {
// set $this->js // set $this->js
...@@ -107,7 +107,8 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default { ...@@ -107,7 +107,8 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default {
return $this->js_value('hotpot-config-file,global,incorrect-indicator'); return $this->js_value('hotpot-config-file,global,incorrect-indicator');
} }
function v6_expand_LastQCaption() { 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() { function v6_expand_NextCorrect() {
$value = $this->js_value('hotpot-config-file,'.$this->parent->quiztype.',next-correct-part'); $value = $this->js_value('hotpot-config-file,'.$this->parent->quiztype.',next-correct-part');
...@@ -172,7 +173,7 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default { ...@@ -172,7 +173,7 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default {
return empty($value) ? '' : ('<h3 class="ExerciseSubtitle">'.$value.'</h3>'); return empty($value) ? '' : ('<h3 class="ExerciseSubtitle">'.$value.'</h3>');
} }
// timer // timer
function v6_expand_Timer() { function v6_expand_Timer() {
return $this->int_value('data,timer,include-timer'); return $this->int_value('data,timer,include-timer');
...@@ -184,7 +185,7 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default { ...@@ -184,7 +185,7 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default {
return $this->parent->xml_value('data,timer,seconds'); return $this->parent->xml_value('data,timer,seconds');
} }
// send results // send results
function v6_expand_SendResults() { function v6_expand_SendResults() {
return $this->parent->xml_value('hotpot-config-file,'.$this->parent->quiztype.',send-email'); return $this->parent->xml_value('hotpot-config-file,'.$this->parent->quiztype.',send-email');
...@@ -306,7 +307,7 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default { ...@@ -306,7 +307,7 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default {
} }
function v6_expand_NavLightColor() { function v6_expand_NavLightColor() {
$color = $this->parent->xml_value('hotpot-config-file,global,nav-bar-color'); $color = $this->parent->xml_value('hotpot-config-file,global,nav-bar-color');
return $this->get_halfway_color($color, '#ffffff'); return $this->get_halfway_color($color, '#ffffff');
} }
function v6_expand_NavShadeColor() { function v6_expand_NavShadeColor() {
$color = $this->parent->xml_value('hotpot-config-file,global,nav-bar-color'); $color = $this->parent->xml_value('hotpot-config-file,global,nav-bar-color');
...@@ -333,6 +334,8 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default { ...@@ -333,6 +334,8 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default {
function v6_expand_NavBarJS() { function v6_expand_NavBarJS() {
return $this->v6_expand_NavButtons(); return $this->v6_expand_NavButtons();
} }
// switch off scorm
function v6_expand_Scorm12() { function v6_expand_Scorm12() {
return false; return false;
} }
...@@ -524,8 +527,8 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default { ...@@ -524,8 +527,8 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default {
$chars = array(); $chars = array();
// unicode punctuation designations (pi="initial quote", ps="open") // unicode punctuation designations (pi="initial quote", ps="open")
// http://www.sql-und-xml.de/unicode-database/pi.html // http://www.sql-und-xml.de/unicode-database/pi.html
// http://www.sql-und-xml.de/unicode-database/ps.html // http://www.sql-und-xml.de/unicode-database/ps.html
$pi = '0022|0027|00AB|2018|201B|201C|201F|2039'; $pi = '0022|0027|00AB|2018|201B|201C|201F|2039';
$ps = '0028|005B|007B|0F3A|0F3C|169B|201A|201E|2045|207D|208D|2329|23B4|2768|276A|276C|276E|2770|2772|2774|27E6|27E8|27EA|2983|2985|2987|2989|298B|298D|298F|2991|2993|2995|2997|29D8|29DA|29FC|3008|300A|300C|300E|3010|3014|3016|3018|301A|301D|FD3E|FE35|FE37|FE39|FE3B|FE3D|FE3F|FE41|FE43|FE47|FE59|FE5B|FE5D|FF08|FF3B|FF5B|FF5F|FF62'; $ps = '0028|005B|007B|0F3A|0F3C|169B|201A|201E|2045|207D|208D|2329|23B4|2768|276A|276C|276E|2770|2772|2774|27E6|27E8|27EA|2983|2985|2987|2989|298B|298D|298F|2991|2993|2995|2997|29D8|29DA|29FC|3008|300A|300C|300E|3010|3014|3016|3018|301A|301D|FD3E|FE35|FE37|FE39|FE3B|FE3D|FE3F|FE41|FE43|FE47|FE59|FE5B|FE5D|FF08|FF3B|FF5B|FF5F|FF62';
$pattern = "/(&#x($pi|$ps);)/i"; $pattern = "/(&#x($pi|$ps);)/i";
...@@ -537,7 +540,7 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default { ...@@ -537,7 +540,7 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default {
$value = strtr($value, $ENTITIES); $value = strtr($value, $ENTITIES);
if (preg_match_all($pattern, $value, $matches)) { if (preg_match_all($pattern, $value, $matches)) {
$chars = array_merge($chars, $matches[0]); $chars = array_merge($chars, $matches[0]);
} }
$i++; $i++;
} }
...@@ -659,7 +662,7 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default { ...@@ -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'); return $this->parent->xml_value('hotpot-config-file,'.$this->parent->quiztype.',remaining-words');
} }
function v6_expand_TimesUp() { 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 // nav bar
...@@ -826,7 +829,7 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default { ...@@ -826,7 +829,7 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default {
$a = 0; $a = 0;
$aa = 0; $aa = 0;
while (($answer=$question."['answer'][$a]['#']") && $this->parent->xml_value($tags, $answer)) { 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 (strlen($text)) {
if ($aa==0) { // first time only if ($aa==0) { // first time only
$str .= "\n"; $str .= "\n";
...@@ -841,7 +844,7 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default { ...@@ -841,7 +844,7 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default {
} }
// add clue, if any answers were found // add clue, if any answers were found
if ($aa) { 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"; $str .= "I[$q][2] = '$clue';\n";
} }
$q++; $q++;
...@@ -854,15 +857,15 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default { ...@@ -854,15 +857,15 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default {
$question_type = $this->int_value($tags, $question."['question-type'][0]['#']"); $question_type = $this->int_value($tags, $question."['question-type'][0]['#']");
$weighting = $this->int_value($tags, $question."['weighting'][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]['#']"; $answers = $question."['answers'][0]['#']";
$a = 0; $a = 0;
$aa = 0; $aa = 0;
while (($answer = $answers."['answer'][$a]['#']") && $this->parent->xml_value($tags, $answer)) { while (($answer = $answers."['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]['#']");
$feedback = $this->js_value($tags, $answer."['feedback'][0]['#']", true); $feedback = $this->js_value($tags, $answer."['feedback'][0]['#']");
$correct = $this->int_value($tags, $answer."['correct'][0]['#']"); $correct = $this->int_value($tags, $answer."['correct'][0]['#']");
$percent = $this->int_value($tags, $answer."['percent-correct'][0]['#']"); $percent = $this->int_value($tags, $answer."['percent-correct'][0]['#']");
$include = $this->int_value($tags, $answer."['include-in-mc-options'][0]['#']"); $include = $this->int_value($tags, $answer."['include-in-mc-options'][0]['#']");
...@@ -926,7 +929,7 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default { ...@@ -926,7 +929,7 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default {
$gap .= '<select id="Gap'.$q.'"><option value=""></option>'.$dropdownlist.'</select>'; $gap .= '<select id="Gap'.$q.'"><option value=""></option>'.$dropdownlist.'</select>';
} else { } else {
// minimum gap size // minimum gap size
if (! $gapsize = $this->int_value('hotpot-config-file,'.$this->parent->quiztype.',minimum-gap-size')) { if (! $gapsize = $this->int_value('hotpot-config-file,'.$this->parent->quiztype.',minimum-gap-size')) {
$gapsize = 6; $gapsize = 6;
} }
...@@ -1086,13 +1089,13 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default { ...@@ -1086,13 +1089,13 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default {
// JCross quiztype // JCross quiztype
function v6_expand_CluesAcrossLabel() { 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() { 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() { 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() { function v6_expand_ShowHideClueList() {
$value = $this->int_value('hotpot-config-file,'.$this->parent->quiztype.',include-clue-list'); $value = $this->int_value('hotpot-config-file,'.$this->parent->quiztype.',include-clue-list');
...@@ -1296,7 +1299,7 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default { ...@@ -1296,7 +1299,7 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default {
$str .= '<p class="QuestionText">'.$question_text.'</p>'; $str .= '<p class="QuestionText">'.$question_text.'</p>';
if ( if (
$question_type==HOTPOT_JQUIZ_SHORTANSWER || $question_type==HOTPOT_JQUIZ_SHORTANSWER ||
$question_type==HOTPOT_JQUIZ_HYBRID $question_type==HOTPOT_JQUIZ_HYBRID
) { ) {
$size = 9; // default size $size = 9; // default size
...@@ -1334,13 +1337,13 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default { ...@@ -1334,13 +1337,13 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default {
} }
if ( if (
$question_type==HOTPOT_JQUIZ_MULTICHOICE || $question_type==HOTPOT_JQUIZ_MULTICHOICE ||
$question_type==HOTPOT_JQUIZ_HYBRID || $question_type==HOTPOT_JQUIZ_HYBRID ||
$question_type==HOTPOT_JQUIZ_MULTISELECT $question_type==HOTPOT_JQUIZ_MULTISELECT
) { ) {
switch ($question_type) { switch ($question_type) {
case HOTPOT_JQUIZ_MULTICHOICE: case HOTPOT_JQUIZ_MULTICHOICE:
$str .= '<ol class="MCAnswers">'."\n"; $str .= '<ol class="MCAnswers">'."\n";
break; break;
case HOTPOT_JQUIZ_HYBRID: case HOTPOT_JQUIZ_HYBRID:
...@@ -1452,16 +1455,16 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default { ...@@ -1452,16 +1455,16 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default {
// hp6checkshortanswers.js_ (JQuiz) // hp6checkshortanswers.js_ (JQuiz)
function v6_expand_CorrectList() { 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() { function v6_expand_HybridTries() {
return $this->parent->xml_value('hotpot-config-file,'.$this->parent->quiztype.',short-answer-tries-on-hybrid-q'); return $this->parent->xml_value('hotpot-config-file,'.$this->parent->quiztype.',short-answer-tries-on-hybrid-q');
} }
function v6_expand_PleaseEnter() { 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() { 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() { function v6_expand_ShowAnswerCaption() {
return $this->parent->xml_value('hotpot-config-file,'.$this->parent->quiztype.',show-answer-caption'); return $this->parent->xml_value('hotpot-config-file,'.$this->parent->quiztype.',show-answer-caption');
...@@ -1479,16 +1482,16 @@ function hotpot_sort_keypad_chars($a, $b) { ...@@ -1479,16 +1482,16 @@ function hotpot_sort_keypad_chars($a, $b) {
function hotpot_keypad_sort_value($char) { function hotpot_keypad_sort_value($char) {
// hexadecimal // 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]); $ord = hexdec($matches[1]);
// decimal // decimal
} else if (preg_match('|&#(\d+);|i', $char, $matches)) { } else if (preg_match('/&#(\d+);/i', $char, $matches)) {
$ord = intval($matches[1]); $ord = intval($matches[1]);
// other html entity // other html entity
} else if (preg_match('|&[^;]+;|', $char, $matches)) { } else if (preg_match('/&[^;]+;/', $char, $matches)) {
$char = html_entity_decode($matches[0]); $char = html_entity_decode($matches[0]);
$ord = empty($char) ? 0 : ord($char); $ord = empty($char) ? 0 : ord($char);
// not an html entity // not an html entity
...@@ -1507,6 +1510,6 @@ function hotpot_keypad_sort_value($char) { ...@@ -1507,6 +1510,6 @@ function hotpot_keypad_sort_value($char) {
} }
return $sort_value; return $sort_value;
} }
?> ?>
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