Skip to content
Browse files

MDL-39507 questions: fix pluginfile URLs before format_text.

  • Loading branch information...
1 parent ea3f5b5 commit cda91161dfe0a306f452bbc03c72ea3088fe0f4d Jean-Michel Vedrine committed with timhunt
View
5 lib/questionlib.php
@@ -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
//===========================
View
4 question/format.php
@@ -936,8 +936,8 @@ protected function format_question_text($question) {
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);
}
}
View
7 question/format/xhtml/format.php
@@ -66,8 +66,11 @@ protected function writequestion($question) {
// 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
View
3 question/type/essay/question.php
@@ -70,8 +70,7 @@ public function summarise_response(array $response) {
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;
}
View
8 question/type/multichoice/questiontype.php
@@ -203,9 +203,9 @@ public function get_possible_responses($questiondata) {
$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 @@ public function get_possible_responses($questiondata) {
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;
View
4 question/type/questionbase.php
@@ -317,7 +317,7 @@ public function format_text($text, $format, $qa, $component, $filearea, $itemid,
* @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 @@ public function get_correct_answer() {
}
return null;
}
-}
+}

0 comments on commit cda9116

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