From 6c23d0d40351eccdc50086ee5cfe6aa4ea1eb7a7 Mon Sep 17 00:00:00 2001 From: Jean-Michel Vedrine Date: Thu, 9 May 2013 07:51:14 +0200 Subject: [PATCH] MDL-39507 questions: fix pluginfile URLs before format_text. --- lib/questionlib.php | 5 +++++ question/format.php | 4 ++-- question/format/xhtml/format.php | 5 ++++- question/type/essay/question.php | 3 +-- question/type/multichoice/questiontype.php | 8 ++++---- question/type/questionbase.php | 2 +- 6 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/questionlib.php b/lib/questionlib.php index 9984b71cd59..07cb05afb6b 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -1219,6 +1219,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 //=========================== diff --git a/question/format.php b/question/format.php index df9e40b1e69..377ac2c2fef 100644 --- a/question/format.php +++ b/question/format.php @@ -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); } } diff --git a/question/format/xhtml/format.php b/question/format/xhtml/format.php index 9d1963d5181..28011874039 100644 --- a/question/format/xhtml/format.php +++ b/question/format/xhtml/format.php @@ -66,7 +66,10 @@ class qformat_xhtml extends qformat_default { $expout .= "

$question->name

\n"; // Format and add the question text. - $expout .= '

' . format_text($question->questiontext, + $text = question_rewrite_question_urls($question->questiontext, 'pluginfile.php', + $question->contextid, 'question', $filearea, + '', $question->id); + $expout .= '

' . format_text($text, $question->questiontextformat) . "

\n"; // Selection depends on question type. diff --git a/question/type/essay/question.php b/question/type/essay/question.php index aee24fa746c..75d085d6e34 100644 --- a/question/type/essay/question.php +++ b/question/type/essay/question.php @@ -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; } diff --git a/question/type/multichoice/questiontype.php b/question/type/multichoice/questiontype.php index 5a15f8b9f17..ff29604ca06 100644 --- a/question/type/multichoice/questiontype.php +++ b/question/type/multichoice/questiontype.php @@ -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; diff --git a/question/type/questionbase.php b/question/type/questionbase.php index 37d6eb25466..8c49f6c35cf 100644 --- a/question/type/questionbase.php +++ b/question/type/questionbase.php @@ -333,7 +333,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. */