MDL-39507 questions: fix pluginfile URLs before format_text.

This commit is contained in:
Jean-Michel Vedrine
2013-08-12 10:37:11 +01:00
committed by Tim Hunt
parent cda44a165a
commit 4cb50d230b
6 changed files with 19 additions and 12 deletions
+5
View File
@@ -1214,6 +1214,11 @@ function question_categorylist($categoryid) {
return $categorylist;
}
function to_plain_text($text, $format, $options) {
$text = str_replace('@@PLUGINFILE@@/', 'http://example.com/', $text);
return html_to_text(format_text($text, $format, $options), 0, false);
}
//===========================
// Import/Export Functions
//===========================
+2 -2
View File
@@ -936,8 +936,8 @@ class qformat_default {
global $DB;
$formatoptions = new stdClass();
$formatoptions->noclean = true;
return html_to_text(format_text($question->questiontext,
$question->questiontextformat, $formatoptions), 0, false);
return to_plain_text($question->questiontext,
$question->questiontextformat, $formatoptions);
}
}
+5 -2
View File
@@ -66,8 +66,11 @@ class qformat_xhtml extends qformat_default {
// add header
$expout .= "<h3>$question->name</h3>\n";
// Format and add the question text
$expout .= '<p class="questiontext">' . format_text($question->questiontext,
// Format and add the question text.
$text = question_rewrite_question_urls($question->questiontext, 'pluginfile.php',
$question->contextid, 'question', $filearea,
'', $question->id);
$expout .= '<p class="questiontext">' . format_text($text,
$question->questiontextformat) . "</p>\n";
// selection depends on question type
+1 -2
View File
@@ -72,8 +72,7 @@ class qtype_essay_question extends question_with_responses {
if (isset($response['answer'])) {
$formatoptions = new stdClass();
$formatoptions->para = false;
return html_to_text(format_text(
$response['answer'], FORMAT_HTML, $formatoptions), 0, false);
return html_to_text($response['answer'], FORMAT_HTML, $formatoptions);
} else {
return null;
}
+4 -4
View File
@@ -203,9 +203,9 @@ class qtype_multichoice extends question_type {
$responses = array();
foreach ($questiondata->options->answers as $aid => $answer) {
$responses[$aid] = new question_possible_response(html_to_text(format_text(
$responses[$aid] = new question_possible_response(to_plain_text(
$answer->answer, $answer->answerformat, array('noclean' => true)),
0, false), $answer->fraction);
$answer->fraction);
}
$responses[null] = question_possible_response::no_response();
@@ -215,9 +215,9 @@ class qtype_multichoice extends question_type {
foreach ($questiondata->options->answers as $aid => $answer) {
$parts[$aid] = array($aid =>
new question_possible_response(html_to_text(format_text(
new question_possible_response(to_plain_text(
$answer->answer, $answer->answerformat, array('noclean' => true)),
0, false), $answer->fraction));
$answer->fraction));
}
return $parts;
+2 -2
View File
@@ -317,7 +317,7 @@ abstract class question_definition {
* @return string the equivalent plain text.
*/
public function html_to_text($text, $format) {
return html_to_text(format_text($text, $format, array('noclean' => true)), 0, false);
return to_plain_text($text, $format, array('noclean' => true));
}
/** @return the result of applying {@link format_text()} to the question text. */
@@ -966,4 +966,4 @@ class question_first_matching_answer_grading_strategy implements question_gradin
}
return null;
}
}
}