Merge branch 'MDL-53175-29' of git://github.com/jleyva/moodle into MOODLE_29_STABLE
This commit is contained in:
+8
-2
@@ -445,6 +445,8 @@ function file_prepare_draft_area(&$draftitemid, $contextid, $component, $fileare
|
||||
|
||||
/**
|
||||
* Convert encoded URLs in $text from the @@PLUGINFILE@@/... form to an actual URL.
|
||||
* Passing a new option reverse = true in the $options var will make the function to convert actual URLs in $text to encoded URLs
|
||||
* in the @@PLUGINFILE@@ form.
|
||||
*
|
||||
* @category files
|
||||
* @global stdClass $CFG
|
||||
@@ -454,7 +456,7 @@ function file_prepare_draft_area(&$draftitemid, $contextid, $component, $fileare
|
||||
* @param string $component
|
||||
* @param string $filearea helps identify the file area.
|
||||
* @param int $itemid helps identify the file area.
|
||||
* @param array $options text and file options ('forcehttps'=>false)
|
||||
* @param array $options text and file options ('forcehttps'=>false), use reverse = true to reverse the behaviour of the function.
|
||||
* @return string the processed text.
|
||||
*/
|
||||
function file_rewrite_pluginfile_urls($text, $file, $contextid, $component, $filearea, $itemid, array $options=null) {
|
||||
@@ -479,7 +481,11 @@ function file_rewrite_pluginfile_urls($text, $file, $contextid, $component, $fil
|
||||
$baseurl = str_replace('http://', 'https://', $baseurl);
|
||||
}
|
||||
|
||||
return str_replace('@@PLUGINFILE@@/', $baseurl, $text);
|
||||
if (!empty($options['reverse'])) {
|
||||
return str_replace($baseurl, '@@PLUGINFILE@@/', $text);
|
||||
} else {
|
||||
return str_replace('@@PLUGINFILE@@/', $baseurl, $text);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -951,6 +951,26 @@ EOF;
|
||||
$this->assertSame(0, $extcurl->get_errno());
|
||||
$this->assertSame('', $contents);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test file_rewrite_pluginfile_urls.
|
||||
*/
|
||||
public function test_file_rewrite_pluginfile_urls() {
|
||||
|
||||
$syscontext = context_system::instance();
|
||||
$originaltext = 'Fake test with an image <img src="@@PLUGINFILE@@/image.png">';
|
||||
|
||||
// Do the rewrite.
|
||||
$finaltext = file_rewrite_pluginfile_urls($originaltext, 'pluginfile.php', $syscontext->id, 'user', 'private', 0);
|
||||
$this->assertContains("pluginfile.php", $finaltext);
|
||||
|
||||
// Now undo.
|
||||
$options = array('reverse' => true);
|
||||
$finaltext = file_rewrite_pluginfile_urls($finaltext, 'pluginfile.php', $syscontext->id, 'user', 'private', 0, $options);
|
||||
|
||||
// Compare the final text is the same that the original.
|
||||
$this->assertEquals($originaltext, $finaltext);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+16
-8
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user