Permalink
Browse files

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

… and encodes unicode strings for javascript
  • Loading branch information...
1 parent a99a407 commit fb1a72d5c2fc61a4dbb9a213d78c6b75fc0098d6 @gbateson gbateson committed Oct 21, 2010
Showing with 35 additions and 32 deletions.
  1. +1 −1 mod/hotpot/template/default.php
  2. +34 −31 mod/hotpot/template/v6.php
@@ -66,7 +66,7 @@ function bool_value($tags, $more_tags="[0]['#']") {
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) {
View
@@ -1,4 +1,4 @@
-<?PHP
+<?PHP
class hotpot_xml_quiz_template extends hotpot_xml_template_default {
// left and right items for JMatch
@@ -9,13 +9,13 @@ class hotpot_xml_quiz_template extends hotpot_xml_template_default {
function hotpot_xml_quiz_template(&$parent) {
$this->parent = &$parent;
-
+
$get_js = optional_param('js', false);
$get_css = optional_param('css', false);
if (!empty($get_css)) {
// set $this->css
- $this->v6_expand_StyleSheet();
+ $this->v6_expand_StyleSheet();
} else if (!empty($get_js)) {
// set $this->js
@@ -107,7 +107,8 @@ function v6_expand_IncorrectIndicator() {
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');
@@ -172,7 +173,7 @@ function v6_expand_ReadingTitle() {
return empty($value) ? '' : ('<h3 class="ExerciseSubtitle">'.$value.'</h3>');
}
- // timer
+ // timer
function v6_expand_Timer() {
return $this->int_value('data,timer,include-timer');
@@ -184,7 +185,7 @@ function v6_expand_Seconds() {
return $this->parent->xml_value('data,timer,seconds');
}
- // send results
+ // send results
function v6_expand_SendResults() {
return $this->parent->xml_value('hotpot-config-file,'.$this->parent->quiztype.',send-email');
@@ -306,7 +307,7 @@ function v6_expand_NavBarColor() {
}
function v6_expand_NavLightColor() {
$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() {
$color = $this->parent->xml_value('hotpot-config-file,global,nav-bar-color');
@@ -333,6 +334,8 @@ function v6_expand_NavButtons() {
function v6_expand_NavBarJS() {
return $this->v6_expand_NavButtons();
}
+
+ // switch off scorm
function v6_expand_Scorm12() {
return false;
}
@@ -524,8 +527,8 @@ function jmix_OpenPunctuation($tags) {
$chars = array();
// 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/ps.html
+ // http://www.sql-und-xml.de/unicode-database/pi.html
+ // http://www.sql-und-xml.de/unicode-database/ps.html
$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';
$pattern = "/(&#x($pi|$ps);)/i";
@@ -537,7 +540,7 @@ function jmix_OpenPunctuation($tags) {
$value = strtr($value, $ENTITIES);
if (preg_match_all($pattern, $value, $matches)) {
$chars = array_merge($chars, $matches[0]);
- }
+ }
$i++;
}
@@ -659,7 +662,7 @@ function v6_expand_RemainingWords() {
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 @@ function v6_expand_ItemArray() {
$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 @@ function v6_expand_ItemArray() {
}
// 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 @@ function v6_expand_ItemArray() {
$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]['#']");
@@ -926,7 +929,7 @@ function v6_expand_ClozeBody() {
$gap .= '<select id="Gap'.$q.'"><option value=""></option>'.$dropdownlist.'</select>';
} else {
// 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;
}
@@ -1086,13 +1089,13 @@ function v6_expand_CaseSensitive() {
// 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');
@@ -1296,7 +1299,7 @@ function v6_expand_QuestionOutput() {
$str .= '<p class="QuestionText">'.$question_text.'</p>';
if (
- $question_type==HOTPOT_JQUIZ_SHORTANSWER ||
+ $question_type==HOTPOT_JQUIZ_SHORTANSWER ||
$question_type==HOTPOT_JQUIZ_HYBRID
) {
$size = 9; // default size
@@ -1334,13 +1337,13 @@ function v6_expand_QuestionOutput() {
}
if (
- $question_type==HOTPOT_JQUIZ_MULTICHOICE ||
+ $question_type==HOTPOT_JQUIZ_MULTICHOICE ||
$question_type==HOTPOT_JQUIZ_HYBRID ||
$question_type==HOTPOT_JQUIZ_MULTISELECT
) {
switch ($question_type) {
- case HOTPOT_JQUIZ_MULTICHOICE:
+ case HOTPOT_JQUIZ_MULTICHOICE:
$str .= '<ol class="MCAnswers">'."\n";
break;
case HOTPOT_JQUIZ_HYBRID:
@@ -1452,16 +1455,16 @@ function v6_expand_ShowOneByOneCaptionJS() {
// 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,16 +1482,16 @@ 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)) {
- $char = html_entity_decode($matches[0]);
+ } else if (preg_match('/&[^;]+;/', $char, $matches)) {
+ $char = html_entity_decode($matches[0]);
$ord = empty($char) ? 0 : ord($char);
// not an html entity
@@ -1507,6 +1510,6 @@ function hotpot_keypad_sort_value($char) {
}
return $sort_value;
-}
+}
?>

0 comments on commit fb1a72d

Please sign in to comment.