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

This commit is contained in:
Juan Leyva
2016-03-30 09:32:35 +01:00
parent 7cd6eefe28
commit d77bdd910c
3 changed files with 34 additions and 12 deletions
+16 -8
View File
@@ -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 {
@@ -597,4 +605,4 @@ function book_export_contents($cm, $baseurl) {
array_unshift($contents, $structurefile);
return $contents;
}
}
+9 -1
View File
@@ -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 = '';
+9 -3
View File
@@ -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();