MDL-28564 question type importing, improve Jamie's fix.
This commit is contained in:
@@ -1011,6 +1011,20 @@ class qformat_xml extends qformat_default {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a string, and wrap it in a CDATA secion, if that is required to make
|
||||
* the output XML valid.
|
||||
* @param string $string a string
|
||||
* @return string the string, wrapped in CDATA if necessary.
|
||||
*/
|
||||
public function xml_escape($string) {
|
||||
if (!empty($string) && htmlspecialchars($string) != $string) {
|
||||
return "<![CDATA[{$string}]]>";
|
||||
} else {
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates <text></text> tags, processing raw text therein
|
||||
* @param string $raw the content to output.
|
||||
@@ -1020,11 +1034,7 @@ class qformat_xml extends qformat_default {
|
||||
*/
|
||||
public function writetext($raw, $indent = 0, $short = true) {
|
||||
$indent = str_repeat(' ', $indent);
|
||||
|
||||
// if required add CDATA tags
|
||||
if (!empty($raw) && htmlspecialchars($raw) != $raw) {
|
||||
$raw = "<![CDATA[$raw]]>";
|
||||
}
|
||||
$raw = $this->xml_escape($raw);
|
||||
|
||||
if ($short) {
|
||||
$xml = "$indent<text>$raw</text>\n";
|
||||
@@ -1467,7 +1477,7 @@ class qformat_xml extends qformat_default {
|
||||
$output .= " <clearwrong/>\n";
|
||||
}
|
||||
if (!empty($hint->options)) {
|
||||
$output .= ' <options>' . htmlspecialchars($hint->options) . "</options>\n";
|
||||
$output .= ' <options>' . $this->xml_escape($hint->options) . "</options>\n";
|
||||
}
|
||||
$output .= " </hint>\n";
|
||||
return $output;
|
||||
|
||||
@@ -986,7 +986,7 @@ class question_type {
|
||||
array_shift($extraquestionfields);
|
||||
$expout='';
|
||||
foreach ($extraquestionfields as $field) {
|
||||
$exportedvalue = self::wrap_html_special_chars($question->options->$field);
|
||||
$exportedvalue = $format->xml_escape($question->options->$field);
|
||||
$expout .= " <$field>{$exportedvalue}</$field>\n";
|
||||
}
|
||||
|
||||
@@ -1003,22 +1003,15 @@ class question_type {
|
||||
$expout .= " </feedback>\n";
|
||||
if (is_array($extraanswersfields)) {
|
||||
foreach ($extraanswersfields as $field) {
|
||||
$exportedvalue = self::wrap_html_special_chars($answer->$field);
|
||||
$expout .= " <$field>{$exportedvalue}</$field>\n";
|
||||
$exportedvalue = $format->xml_escape($answer->$field);
|
||||
$expout .= " <{$field}>{$exportedvalue}</{$field}>\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$expout .= " </answer>\n";
|
||||
}
|
||||
return $expout;
|
||||
}
|
||||
protected static function wrap_html_special_chars($text) {
|
||||
if (!empty($text) && htmlspecialchars($text) != $text) {
|
||||
$text = '<![CDATA[' . $text . ']]>';
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract function implemented by each question type. It runs all the code
|
||||
|
||||
Reference in New Issue
Block a user