diff --git a/mod/book/lib.php b/mod/book/lib.php index 8c3f1f761d0..e578bc8574a 100644 --- a/mod/book/lib.php +++ b/mod/book/lib.php @@ -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; -} \ No newline at end of file +} diff --git a/mod/book/tool/exportimscp/locallib.php b/mod/book/tool/exportimscp/locallib.php index 6bc14ef978e..2892e579927 100644 --- a/mod/book/tool/exportimscp/locallib.php +++ b/mod/book/tool/exportimscp/locallib.php @@ -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 = ''; diff --git a/mod/page/lib.php b/mod/page/lib.php index 4fcf7e44a43..b7eae05a6be 100644 --- a/mod/page/lib.php +++ b/mod/page/lib.php @@ -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();