From 58310f8845ba4c74b06a01cab3a76d40776a3d9d Mon Sep 17 00:00:00 2001 From: Jean-Michel Vedrine Date: Thu, 1 Nov 2012 11:16:01 +0100 Subject: [PATCH] MDL-32865 CLOZE Questions imported from another course end up with broken image links --- question/format/xml/format.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/question/format/xml/format.php b/question/format/xml/format.php index 1a0e992e9ab..45ec077301e 100644 --- a/question/format/xml/format.php +++ b/question/format/xml/format.php @@ -440,7 +440,21 @@ class qformat_xml extends qformat_default { $qo->name = $this->clean_question_name($this->import_text($question['#']['name'][0]['#']['text'])); $qo->questiontextformat = $questiontext['format']; $qo->questiontext = $qo->questiontext['text']; - $qo->questiontextfiles = array(); + $qo->questiontextfiles = $this->import_files($this->getpath($question, + array('#', 'questiontext', 0, '#', 'file'), array(), false)); + + // Backwards compatibility, deal with the old image tag. + $filedata = $this->getpath($question, array('#', 'image_base64', '0', '#'), null, false); + $filename = $this->getpath($question, array('#', 'image', '0', '#'), null, false); + if ($filedata && $filename) { + $data = new stdClass(); + $data->content = $filedata; + $data->encoding = 'base64'; + // Question file areas don't support subdirs, so convert path to filename if necessary. + $data->name = clean_param(str_replace('/', '_', $filename), PARAM_FILE); + $qo->questiontextfiles[] = $data; + $qo->questiontext .= ' '; + } // restore files in generalfeedback $qo->generalfeedback = $this->getpath($question,