From 06f1bd03be3d4283ac117d37be58cbfa63d61eb8 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Fri, 19 Nov 2010 14:24:18 +0000 Subject: [PATCH] question XML import/export MDL-18916 Fix import of questions with images exported from Moodle 1.9. Thanks again to Patrick Pollet --- question/format.php | 6 +----- question/format/xml/format.php | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/question/format.php b/question/format.php index dd9344ee6de..8cb7fa9ba75 100644 --- a/question/format.php +++ b/question/format.php @@ -880,12 +880,8 @@ class qformat_default { if ($file->is_directory()) { continue; } - $string .= 'get_filename() . '"'); - $string .= (' encoding="' . $encoding . '"'); - $string .= '>'; + $string .= ''; $string .= base64_encode($file->get_content()); - //$string .= 'base64'; $string .= ''; } return $string; diff --git a/question/format/xml/format.php b/question/format/xml/format.php index 2db69907985..49f8152c256 100755 --- a/question/format/xml/format.php +++ b/question/format/xml/format.php @@ -158,11 +158,6 @@ class qformat_xml extends qformat_default { $qo->questiontext = $this->getpath($question, array('#','questiontext',0,'#','text',0,'#'), '', true ); $qo->questiontextformat = $this->trans_format( $this->getpath($question, array('#','questiontext',0,'@','format'), 'moodle_auto_format')); - $qo->image = $this->getpath($question, array('#','image',0,'#'), $qo->image ); - $image_base64 = $this->getpath( $question, array('#','image_base64','0','#'),'' ); - if (!empty($image_base64)) { - $qo->image = $this->importimagefile($qo->image, $image_base64); - } $qo->questiontextfiles = array(); @@ -176,6 +171,18 @@ class qformat_xml extends qformat_default { $qo->questiontextfiles[] = $data; } + // 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'; + $data->name = $filename; + $qo->questiontextfiles[] = $data; + $qo->questiontext .= ' '; + } + // restore files in generalfeedback $qo->generalfeedback = $this->getpath($question, array('#','generalfeedback',0,'#','text',0,'#'), $qo->generalfeedback, true); $qo->generalfeedbackfiles = array();