diff --git a/mod/lesson/format.php b/mod/lesson/format.php index 228413d1655..14115257654 100644 --- a/mod/lesson/format.php +++ b/mod/lesson/format.php @@ -285,6 +285,7 @@ class qformat_default { var $displayerrors = true; var $category = null; var $questionids = array(); + protected $importcontext = null; var $qtypeconvert = array('numerical' => LESSON_PAGE_NUMERICAL, 'multichoice' => LESSON_PAGE_MULTICHOICE, 'truefalse' => LESSON_PAGE_TRUEFALSE, @@ -297,6 +298,10 @@ class qformat_default { return false; } + function set_importcontext($context) { + $this->importcontext = $context; + } + function importpreprocess() { // Does any pre-processing that may be desired return true; @@ -410,6 +415,15 @@ class qformat_default { $this->questionids[] = $question->id; + // Import images in question text. + if (isset($question->questiontextitemid)) { + $questiontext = file_save_draft_area_files($question->questiontextitemid, + $this->importcontext->id, 'mod_lesson', 'page_contents', $newpageid, + null , $question->questiontext); + // Update content with recoded urls. + $DB->set_field("lesson_pages", "contents", $questiontext, array("id" => $newpageid)); + } + // Now to save all the answers and type-specific options $question->lessonid = $lesson->id; // needed for foreign key @@ -603,7 +617,12 @@ class qformat_default { protected function format_question_text($question) { $formatoptions = new stdClass(); $formatoptions->noclean = true; - return html_to_text(format_text($question->questiontext, + // The html_to_text call strips out all URLs, but format_text complains + // if it finds @@PLUGINFILE@@ tokens. So, we need to replace + // @@PLUGINFILE@@ with a real URL, but it doesn't matter what. + // We use http://example.com/. + $text = str_replace('@@PLUGINFILE@@/', 'http://example.com/', $question->questiontext); + return html_to_text(format_text($text, $question->questiontextformat, $formatoptions), 0, false); } diff --git a/mod/lesson/import.php b/mod/lesson/import.php index 4f3814c72d3..b57edd793b0 100644 --- a/mod/lesson/import.php +++ b/mod/lesson/import.php @@ -82,6 +82,8 @@ if ($data = $mform->get_data()) { require_once($formatclassfile); $format = new $formatclass(); + $format->set_importcontext($context); + // Do anything before that we need to if (! $format->importpreprocess()) { print_error('preprocesserror', 'lesson');