Skip to content

Commit

Permalink
question XML import/export MDL-18916 Fix import of questions with ima…
Browse files Browse the repository at this point in the history
…ges exported from Moodle 1.9.

Thanks again to Patrick Pollet
  • Loading branch information
timhunt committed Nov 19, 2010
1 parent ae440de commit 06f1bd0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
6 changes: 1 addition & 5 deletions question/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -880,12 +880,8 @@ function writefiles($files, $encoding='base64') {
if ($file->is_directory()) {
continue;
}
$string .= '<file ';
$string .= ('name="' . $file->get_filename() . '"');
$string .= (' encoding="' . $encoding . '"');
$string .= '>';
$string .= '<file name="' . $file->get_filename() . '" encoding="' . $encoding . '">';
$string .= base64_encode($file->get_content());
//$string .= 'base64';
$string .= '</file>';
}
return $string;
Expand Down
17 changes: 12 additions & 5 deletions question/format/xml/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,6 @@ function import_headers($question) {
$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();

Expand All @@ -176,6 +171,18 @@ function import_headers($question) {
$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 .= ' <img src="@@PLUGINFILE@@/' . $filename . '" />';
}

// restore files in generalfeedback
$qo->generalfeedback = $this->getpath($question, array('#','generalfeedback',0,'#','text',0,'#'), $qo->generalfeedback, true);
$qo->generalfeedbackfiles = array();
Expand Down

0 comments on commit 06f1bd0

Please sign in to comment.