This commit is contained in:
mindforge
2005-09-07 13:59:28 +00:00
parent 74971fdad9
commit 9fe710159f
2 changed files with 33 additions and 15 deletions
@@ -42,10 +42,8 @@
// Fix the questiontext fields of old questions
set_field('quiz_questions', 'questiontext', addslashes($parsableanswerdef), 'id', $wrapped->id);
} else {
$parsableanswerdef = str_replace('&#', '&\#', $wrapped->questiontext);
$parsableanswerdef = $wrapped->questiontext;
}
//echo "{#$key}<br />";
//echo $parsableanswerdef.'<br />';
$question->questiontext = str_replace("{#$key}", $parsableanswerdef, $question->questiontext);
}
}
@@ -308,6 +308,7 @@ class quiz_embedded_cloze_qtype extends quiz_default_questiontype {
$teststate = clone($state);
$state->raw_grade = 0;
foreach($question->options->questions as $key => $wrapped) {
$state->responses[$key] = html_entity_decode($state->responses[$key]);
$teststate->responses = array('' => $state->responses[$key]);
$teststate->raw_grade = 0;
if (false === $QUIZ_QTYPES[$wrapped->qtype]
@@ -356,20 +357,32 @@ function quiz_qtype_multianswer_extract_question($text) {
//// quiz/format/multianswer/format.php
////////////////////////////////////////////////
// Undo the automatic addslashes, because we want to analyze the text - we need to remember this later and addslashes again!
$text = stripslashes($text);
// We need to allow entities (e.g. &#1085;) in answers. This is difficulty,
// because the '#' character is used as delimiter between answer and
// feedback as well as inside entities. The HTML editor automatically
// replaces '&' with '&amp;', so we undo this to get back the entities we
// originally wanted. However, this code leaves all &amp; alone, if they
// are not followed by 2 to 9 characters and a final semicolon. This allows
// to have an answer end on '&' with the feedback (e.g. answer&amp;#feedback).
// When the plain text editor is used, the &amp; needs to be typed out
// explicitly in this case.
$text = preg_replace('/&amp;(#[0-9a-fx]{2,6}?);/', '&$1;', $text);
// REGULAR EXPRESSION CONSTANTS
// I do not know any way to make this easier
// Regexes are always awkard when defined but more comprehensible
// when used as constants in the executive code
// Handle the entity encoded ampersand in entities (e.g. &amp;lt; -> &lt;)
$text = preg_replace('/&amp;(.{2,9}?;)/', '&${1}', $text);
$text = stripslashes($text);
// ANSWER_ALTERNATIVE regexes
define("ANSWER_ALTERNATIVE_FRACTION_REGEX",
'=|%(-?[0-9]+)%');
// for the syntax '(?<!' see http://www.perl.com/doc/manual/html/pod/perlre.html#item_C
define("ANSWER_ALTERNATIVE_ANSWER_REGEX",
'.+?(?<!\\\\)(?=[~#}]|$)');
'.+?(?<!\\\\|&)(?=[~#}]|$)');
//'[^~#}]+');
define("ANSWER_ALTERNATIVE_FEEDBACK_REGEX",
'.*?(?<!\\\\)(?=[~}]|$)');
@@ -453,7 +466,7 @@ function quiz_qtype_multianswer_extract_question($text) {
$wrapped->answer = array();
$wrapped->fraction = array();
$wrapped->feedback = array();
$wrapped->questiontext = addslashes(str_replace('&\#', '&#', $answerregs[0]));
$wrapped->questiontext = addslashes($answerregs[0]); // here we don't want multianswer_escape, because this is editing time information
$wrapped->questiontextformat = 0;
$remainingalts = $answerregs[ANSWER_REGEX_ALTERNATIVES];
@@ -466,16 +479,16 @@ function quiz_qtype_multianswer_extract_question($text) {
} else {
$wrapped->fraction[] = '0';
}
$wrapped->feedback[] = addslashes(str_replace('&\#', '&#',
$wrapped->feedback[] = multianswer_escape(
isset($altregs[ANSWER_ALTERNATIVE_REGEX_FEEDBACK])
? $altregs[ANSWER_ALTERNATIVE_REGEX_FEEDBACK] : ''));
? $altregs[ANSWER_ALTERNATIVE_REGEX_FEEDBACK] : '');
if (!empty($answerregs[ANSWER_REGEX_ANSWER_TYPE_NUMERICAL])
&& ereg(NUMERICAL_ALTERNATIVE_REGEX,
$altregs[ANSWER_ALTERNATIVE_REGEX_ANSWER],
$numregs) )
{
$wrapped->answer[] =
addslashes($numregs[NUMERICAL_CORRECT_ANSWER]);
multianswer_escape($numregs[NUMERICAL_CORRECT_ANSWER]);
if ($numregs[NUMERICAL_ABS_ERROR_MARGIN]) {
$wrapped->tolerance[] =
$numregs[NUMERICAL_ABS_ERROR_MARGIN];
@@ -483,8 +496,8 @@ function quiz_qtype_multianswer_extract_question($text) {
$wrapped->tolerance[] = 0;
}
} else { // Tolerance can stay undefined for non numerical questions
$wrapped->answer[] = addslashes(str_replace('&\#', '&#',
$altregs[ANSWER_ALTERNATIVE_REGEX_ANSWER]));
$wrapped->answer[] = multianswer_escape(
$altregs[ANSWER_ALTERNATIVE_REGEX_ANSWER]);
}
$tmp = explode($altregs[0], $remainingalts, 2);
$remainingalts = $tmp[1];
@@ -495,8 +508,15 @@ function quiz_qtype_multianswer_extract_question($text) {
$question->questiontext = implode("{#$positionkey}",
explode($answerregs[0], $question->questiontext, 2));
}
$question->questiontext = addslashes(str_replace('&\#', '&#', $question->questiontext));
$question->questiontext = multianswer_escape($question->questiontext);
return $question;
}
function multianswer_escape($text) {
$text = str_replace("&amp;", "&", $text);
$text = str_replace('\#', '#', $text);
$text = html_entity_decode($text);
return addslashes($text);
}
?>