Commit d329a1ea authored by Juan Leyva's avatar Juan Leyva
Browse files

MDL-53175 filter: Fix text formatting for the book and page modules

parent 296ab1e2
......@@ -429,8 +429,21 @@ function book_pluginfile($course, $cm, $context, $filearea, $args, $forcedownloa
if ($args[0] == 'index.html') {
$filename = "index.html";
// We need to rewrite the pluginfile URLs so the media filters can work.
$content = file_rewrite_pluginfile_urls($chapter->content, 'webservice/pluginfile.php', $context->id, 'mod_book', 'chapter',
$chapter->id);
$formatoptions = new stdClass;
$formatoptions->noclean = true;
$formatoptions->overflowdiv = true;
$formatoptions->context = $context;
$content = format_text($content, $chapter->contentformat, $formatoptions);
// Remove @@PLUGINFILE@@/.
$content = str_replace('@@PLUGINFILE@@/', '', $chapter->content);
$options = array('reverse' => true);
$content = file_rewrite_pluginfile_urls($content, 'webservice/pluginfile.php', $context->id, 'mod_book', 'chapter',
$chapter->id, $options);
$content = str_replace('@@PLUGINFILE@@/', '', $content);
$titles = "";
// Format the chapter titles.
......@@ -451,12 +464,7 @@ function book_pluginfile($course, $cm, $context, $filearea, $args, $forcedownloa
}
}
$formatoptions = new stdClass;
$formatoptions->noclean = true;
$formatoptions->overflowdiv = true;
$formatoptions->context = $context;
$content = $titles . format_text($content, $chapter->contentformat, $formatoptions);
$content = $titles . $content;
send_file($content, $filename, 0, 0, true, true);
} else {
......
......@@ -231,9 +231,17 @@ function booktool_exportimscp_chapter_content($chapter, $context) {
$options->noclean = true;
$options->context = $context;
$chaptercontent = str_replace('@@PLUGINFILE@@/', '', $chapter->content);
// We need to rewrite the pluginfile URLs so the media filters can work.
$chaptercontent = file_rewrite_pluginfile_urls($chapter->content, 'pluginfile.php', $context->id, 'mod_book', 'chapter',
$chapter->id);
$chaptercontent = format_text($chaptercontent, $chapter->contentformat, $options);
// Now remove again the full pluginfile URLs.
$options = array('reverse' => true);
$chaptercontent = file_rewrite_pluginfile_urls($chaptercontent, 'pluginfile.php', $context->id, 'mod_book', 'chapter',
$chapter->id, $options);
$chaptercontent = str_replace('@@PLUGINFILE@@/', '', $chaptercontent);
$chaptertitle = format_string($chapter->title, true, array('context'=>$context));
$content = '';
......
......@@ -338,15 +338,21 @@ function page_pluginfile($course, $cm, $context, $filearea, $args, $forcedownloa
return false;
}
// remove @@PLUGINFILE@@/
$content = str_replace('@@PLUGINFILE@@/', '', $page->content);
// We need to rewrite the pluginfile URLs so the media filters can work.
$content = file_rewrite_pluginfile_urls($page->content, 'webservice/pluginfile.php', $context->id, 'mod_page', 'content',
$page->revision);
$formatoptions = new stdClass;
$formatoptions->noclean = true;
$formatoptions->overflowdiv = true;
$formatoptions->context = $context;
$content = format_text($content, $page->contentformat, $formatoptions);
// Remove @@PLUGINFILE@@/.
$options = array('reverse' => true);
$content = file_rewrite_pluginfile_urls($content, 'webservice/pluginfile.php', $context->id, 'mod_page', 'content',
$page->revision, $options);
$content = str_replace('@@PLUGINFILE@@/', '', $content);
send_file($content, $filename, 0, 0, true, true);
} else {
$fs = get_file_storage();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment