Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

prevent backslashes being inserted before #-sign in HTML entities by …

…converting html-entities to UTF-8 when importing from Hot Potatoes quizzes into Moodle 's standard Quiz module
  • Loading branch information...
commit 0cf15fb3e6815c781aefa096adc8b7ace0d47b6f 1 parent c966aa2
gbateson authored

Showing 1 changed file with 19 additions and 14 deletions. Show diff stats Hide diff stats

  1. +19 14 question/format/hotpot/format.php
33 question/format/hotpot/format.php
@@ -133,7 +133,7 @@ function process_jcloze(&$xml, &$questions) {
133 133 $q = 0;
134 134 while ($text = $xml->xml_value($tags, $exercise."[$q]")) {
135 135 // add next bit of text
136   - $question->questiontext .= addslashes($text);
  136 + $question->questiontext .= $this->hotpot_prepare_str($text);
137 137
138 138 // check for a gap
139 139 $question_record = $exercise."['question-record'][$q]['#']";
@@ -165,9 +165,9 @@ function process_jcloze(&$xml, &$questions) {
165 165 // add answers
166 166 $a = 0;
167 167 while (($answer=$question_record."['answer'][$a]['#']") && $xml->xml_value($tags, $answer)) {
168   - $text = addslashes($xml->xml_value($tags, $answer."['text'][0]['#']"));
  168 + $text = $this->hotpot_prepare_str($xml->xml_value($tags, $answer."['text'][0]['#']"));
169 169 $correct = $xml->xml_value($tags, $answer."['correct'][0]['#']");
170   - $feedback = addslashes($xml->xml_value($tags, $answer."['feedback'][0]['#']"));
  170 + $feedback = $this->hotpot_prepare_str($xml->xml_value($tags, $answer."['feedback'][0]['#']"));
171 171 if ($text) {
172 172 // set score (0=0%, 1=100%)
173 173 $fraction = empty($correct) ? 0 : 1;
@@ -226,8 +226,8 @@ function process_jcross(&$xml, &$questions) {
226 226 $question->qtype = SHORTANSWER;
227 227 $question->name = $this->hotpot_get_title($xml, $x, true);
228 228
229   - $question->questiontext = addslashes($text);
230   - $question->answer = array(addslashes($answer));
  229 + $question->questiontext = $this->hotpot_prepare_str($text);
  230 + $question->answer = array($this->hotpot_prepare_str($answer));
231 231 $question->fraction = array(1);
232 232 $question->feedback = array('');
233 233
@@ -270,8 +270,8 @@ function process_jmatch(&$xml, &$questions) {
270 270 $right = $xml->xml_value($tags, $pair."['right-item'][0]['#']['text'][0]['#']");
271 271 if ($left && $right) {
272 272 $match_count++;
273   - $question->subquestions[$p] = addslashes($left);
274   - $question->subanswers[$p] = addslashes($right);
  273 + $question->subquestions[$p] = $this->hotpot_prepare_str($left);
  274 + $question->subanswers[$p] = $this->hotpot_prepare_str($right);
275 275 }
276 276 $p++;
277 277 }
@@ -310,7 +310,7 @@ function process_jmix(&$xml, &$questions) {
310 310 $i = 0;
311 311 $segments = array();
312 312 while ($segment = $xml->xml_value($tags, $exercise."['main-order'][0]['#']['segment'][$i]['#']")) {
313   - $segments[] = addslashes($segment);
  313 + $segments[] = $this->hotpot_prepare_str($segment);
314 314 $segment_count++;
315 315 $i++;
316 316 }
@@ -328,7 +328,7 @@ function process_jmix(&$xml, &$questions) {
328 328 $question->answer[$a] = $answer;
329 329 $question->fraction[$a] = 1;
330 330 $question->feedback[$a] = '';
331   - $answer = addslashes($xml->xml_value($tags, $exercise."['alternate'][$a]['#']"));
  331 + $answer = $this->hotpot_prepare_str($xml->xml_value($tags, $exercise."['alternate'][$a]['#']"));
332 332 $a++;
333 333 }
334 334 $question->defaultgrade = $segment_count * $defaultgrade;
@@ -361,7 +361,7 @@ function process_jquiz(&$xml, &$questions) {
361 361 $question->name = $this->hotpot_get_title($xml, $q, true);
362 362
363 363 $text = $xml->xml_value($tags, $question_record."['question'][0]['#']");
364   - $question->questiontext = addslashes($text);
  364 + $question->questiontext = $this->hotpot_prepare_str($text);
365 365
366 366 if ($xml->xml_value($tags, $question_record."['answers']")) {
367 367 // HP6 JQuiz
@@ -434,8 +434,8 @@ function process_jquiz(&$xml, &$questions) {
434 434 }
435 435 }
436 436 $question->fraction[] = $fraction;
437   - $question->feedback[] = addslashes($xml->xml_value($tags, $answer."['feedback'][0]['#']"));
438   - $question->answer[] = addslashes($xml->xml_value($tags, $answer."['text'][0]['#']"));
  437 + $question->feedback[] = $this->hotpot_prepare_str($xml->xml_value($tags, $answer."['feedback'][0]['#']"));
  438 + $question->answer[] = $this->hotpot_prepare_str($xml->xml_value($tags, $answer."['text'][0]['#']"));
439 439 $a++;
440 440 }
441 441 $questions[] = $question;
@@ -458,14 +458,14 @@ function hotpot_get_title(&$xml, $x, $flag=false) {
458 458 if ($x || $flag) {
459 459 $title .= ' ('.($x+1).')';
460 460 }
461   - return addslashes($title);
  461 + return $this->hotpot_prepare_str($title);
462 462 }
463 463 function hotpot_get_instructions(&$xml) {
464 464 $text = $xml->xml_value('hotpot-config-file,instructions');
465 465 if (empty($text)) {
466 466 $text = "Hot Potatoes $xml->quiztype";
467 467 }
468   - return addslashes($text);
  468 + return $this->hotpot_prepare_str($text);
469 469 }
470 470 function hotpot_get_reading(&$xml) {
471 471 $str = '';
@@ -478,6 +478,11 @@ function hotpot_get_reading(&$xml) {
478 478 $str .= "<P>$text</P>";
479 479 }
480 480 }
  481 + return $this->hotpot_prepare_str($str);
  482 + }
  483 + function hotpot_prepare_str($str) {
  484 + // convert html entities to unicode and add slashes
  485 + $str = preg_replace('/&#[x0-9A-F]+;/ie', "html_entity_decode('\\0',ENT_NOQUOTES,'UTF-8')", $str);
481 486 return addslashes($str);
482 487 }
483 488 } // end class

0 comments on commit 0cf15fb

Please sign in to comment.
Something went wrong with that request. Please try again.