MDL-67547 mod_forum: convert pluginfile URLs prior to export.

This commit is contained in:
Paul Holden
2020-05-26 00:54:51 +01:00
parent 233a51ad21
commit f8f5a2f6da
+7 -7
View File
@@ -120,7 +120,7 @@ if ($form->is_cancelled()) {
'messageformat', 'messagetrust', 'attachment', 'totalscore', 'mailnow', 'deleted', 'privatereplyto',
'privatereplytofullname', 'wordcount', 'charcount'];
$canviewfullname = has_capability('moodle/site:viewfullnames', $forum->get_context());
$canviewfullname = has_capability('moodle/site:viewfullnames', $context);
$datamapper = $legacydatamapperfactory->get_post_data_mapper();
$exportdata = new ArrayObject($datamapper->to_legacy_objects($posts));
@@ -132,7 +132,7 @@ if ($form->is_cancelled()) {
$dataformat,
$fields,
$iterator,
function($exportdata) use ($fields, $striphtml, $humandates, $canviewfullname) {
function($exportdata) use ($fields, $striphtml, $humandates, $canviewfullname, $context) {
$data = new stdClass();
foreach ($fields as $field) {
@@ -149,6 +149,11 @@ if ($form->is_cancelled()) {
$data->privatereplytofullname = fullname($user, $canviewfullname);
}
if ($field == 'message') {
$data->message = file_rewrite_pluginfile_urls($data->message, 'pluginfile.php', $context->id, 'mod_forum',
'post', $data->id);
}
// Convert any boolean fields to their integer equivalent for output.
if (is_bool($data->$field)) {
$data->$field = (int) $data->$field;
@@ -156,11 +161,6 @@ if ($form->is_cancelled()) {
}
if ($striphtml) {
// The following call to html_to_text uses the option that 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/.
$data->message = str_replace('@@PLUGINFILE@@/', 'http://example.com/', $data->message);
$data->message = html_to_text(format_text($data->message, $data->messageformat), 0, false);
$data->messageformat = FORMAT_PLAIN;
}