From 3c215fa3d2e5368d0ac73a55c2e08a8805e8afc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Wed, 14 Sep 2016 12:14:56 +0200 Subject: [PATCH] MDL-55957 workshop: Fix the embedded files serving There was a bug with serving the files from the areas instructauthors, instructreviewers and conclusion. These three areas should not use the itemid in the plugininfo URLs. But they did use 0 as the itemid which broke the file previews when browsing via server files repository. The first part of the patch fixes all relevant calls to file_rewrite_pluginfile_urls() so that null is now properly used instead of zero. The second part of the fix is that we no longer delete the first $args element in the workshop_pluginfile() function - the itemid is not supposed to appear there now. The last part of the patch is that instead of repeating the same code block copy&pasted for each file area in workshop_pluginfile(), we now have a single block covering them all. --- mod/workshop/assessment.php | 2 +- mod/workshop/exassessment.php | 2 +- mod/workshop/exsubmission.php | 2 +- mod/workshop/lib.php | 32 ++------------------------------ mod/workshop/submission.php | 2 +- mod/workshop/view.php | 6 +++--- 6 files changed, 9 insertions(+), 37 deletions(-) diff --git a/mod/workshop/assessment.php b/mod/workshop/assessment.php index a75b44e8c0172..6aad44bde1161 100644 --- a/mod/workshop/assessment.php +++ b/mod/workshop/assessment.php @@ -265,7 +265,7 @@ // for evaluating the assessment if (trim($workshop->instructreviewers)) { $instructions = file_rewrite_pluginfile_urls($workshop->instructreviewers, 'pluginfile.php', $PAGE->context->id, - 'mod_workshop', 'instructreviewers', 0, workshop::instruction_editors_options($PAGE->context)); + 'mod_workshop', 'instructreviewers', null, workshop::instruction_editors_options($PAGE->context)); print_collapsible_region_start('', 'workshop-viewlet-instructreviewers', get_string('instructreviewers', 'workshop')); echo $output->box(format_text($instructions, $workshop->instructreviewersformat, array('overflowdiv'=>true)), array('generalbox', 'instructions')); print_collapsible_region_end(); diff --git a/mod/workshop/exassessment.php b/mod/workshop/exassessment.php index 9ffbcbe69de14..4a5afee9e9614 100644 --- a/mod/workshop/exassessment.php +++ b/mod/workshop/exassessment.php @@ -143,7 +143,7 @@ // for evaluating the assessment if (trim($workshop->instructreviewers)) { $instructions = file_rewrite_pluginfile_urls($workshop->instructreviewers, 'pluginfile.php', $PAGE->context->id, - 'mod_workshop', 'instructreviewers', 0, workshop::instruction_editors_options($PAGE->context)); + 'mod_workshop', 'instructreviewers', null, workshop::instruction_editors_options($PAGE->context)); print_collapsible_region_start('', 'workshop-viewlet-instructreviewers', get_string('instructreviewers', 'workshop')); echo $output->box(format_text($instructions, $workshop->instructreviewersformat, array('overflowdiv'=>true)), array('generalbox', 'instructions')); print_collapsible_region_end(); diff --git a/mod/workshop/exsubmission.php b/mod/workshop/exsubmission.php index 327ea2e848243..10a2da193d7fa 100644 --- a/mod/workshop/exsubmission.php +++ b/mod/workshop/exsubmission.php @@ -187,7 +187,7 @@ // while reading the submitted answer if (trim($workshop->instructauthors)) { $instructions = file_rewrite_pluginfile_urls($workshop->instructauthors, 'pluginfile.php', $PAGE->context->id, - 'mod_workshop', 'instructauthors', 0, workshop::instruction_editors_options($PAGE->context)); + 'mod_workshop', 'instructauthors', null, workshop::instruction_editors_options($PAGE->context)); print_collapsible_region_start('', 'workshop-viewlet-instructauthors', get_string('instructauthors', 'workshop')); echo $output->box(format_text($instructions, $workshop->instructauthorsformat, array('overflowdiv'=>true)), array('generalbox', 'instructions')); print_collapsible_region_end(); diff --git a/mod/workshop/lib.php b/mod/workshop/lib.php index 13d343485d17d..6892c3e0ea724 100644 --- a/mod/workshop/lib.php +++ b/mod/workshop/lib.php @@ -1302,8 +1302,8 @@ function workshop_pluginfile($course, $cm, $context, $filearea, array $args, $fo require_login($course, true, $cm); - if ($filearea === 'instructauthors') { - array_shift($args); // itemid is ignored here + if ($filearea === 'instructauthors' or $filearea === 'instructreviewers' or $filearea === 'conclusion') { + // The $args are supposed to contain just the path, not the item id. $relativepath = implode('/', $args); $fullpath = "/$context->id/mod_workshop/$filearea/0/$relativepath"; @@ -1311,34 +1311,6 @@ function workshop_pluginfile($course, $cm, $context, $filearea, array $args, $fo if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { send_file_not_found(); } - - // finally send the file - send_stored_file($file, null, 0, $forcedownload, $options); - - } else if ($filearea === 'instructreviewers') { - array_shift($args); // itemid is ignored here - $relativepath = implode('/', $args); - $fullpath = "/$context->id/mod_workshop/$filearea/0/$relativepath"; - - $fs = get_file_storage(); - if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { - send_file_not_found(); - } - - // finally send the file - send_stored_file($file, null, 0, $forcedownload, $options); - - } else if ($filearea === 'conclusion') { - array_shift($args); // itemid is ignored here - $relativepath = implode('/', $args); - $fullpath = "/$context->id/mod_workshop/$filearea/0/$relativepath"; - - $fs = get_file_storage(); - if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { - send_file_not_found(); - } - - // finally send the file send_stored_file($file, null, 0, $forcedownload, $options); } else if ($filearea === 'submission_content' or $filearea === 'submission_attachment') { diff --git a/mod/workshop/submission.php b/mod/workshop/submission.php index c8e49d06575e1..9f8e5cd1f0deb 100644 --- a/mod/workshop/submission.php +++ b/mod/workshop/submission.php @@ -296,7 +296,7 @@ // while reading the submitted answer if (trim($workshop->instructauthors)) { $instructions = file_rewrite_pluginfile_urls($workshop->instructauthors, 'pluginfile.php', $PAGE->context->id, - 'mod_workshop', 'instructauthors', 0, workshop::instruction_editors_options($PAGE->context)); + 'mod_workshop', 'instructauthors', null, workshop::instruction_editors_options($PAGE->context)); print_collapsible_region_start('', 'workshop-viewlet-instructauthors', get_string('instructauthors', 'workshop')); echo $output->box(format_text($instructions, $workshop->instructauthorsformat, array('overflowdiv'=>true)), array('generalbox', 'instructions')); print_collapsible_region_end(); diff --git a/mod/workshop/view.php b/mod/workshop/view.php index f66d2cc1a9307..1fb8fa10719d8 100644 --- a/mod/workshop/view.php +++ b/mod/workshop/view.php @@ -148,7 +148,7 @@ case workshop::PHASE_SUBMISSION: if (trim($workshop->instructauthors)) { $instructions = file_rewrite_pluginfile_urls($workshop->instructauthors, 'pluginfile.php', $PAGE->context->id, - 'mod_workshop', 'instructauthors', 0, workshop::instruction_editors_options($PAGE->context)); + 'mod_workshop', 'instructauthors', null, workshop::instruction_editors_options($PAGE->context)); print_collapsible_region_start('', 'workshop-viewlet-instructauthors', get_string('instructauthors', 'workshop')); echo $output->box(format_text($instructions, $workshop->instructauthorsformat, array('overflowdiv'=>true)), array('generalbox', 'instructions')); print_collapsible_region_end(); @@ -333,7 +333,7 @@ } if (trim($workshop->instructreviewers)) { $instructions = file_rewrite_pluginfile_urls($workshop->instructreviewers, 'pluginfile.php', $PAGE->context->id, - 'mod_workshop', 'instructreviewers', 0, workshop::instruction_editors_options($PAGE->context)); + 'mod_workshop', 'instructreviewers', null, workshop::instruction_editors_options($PAGE->context)); print_collapsible_region_start('', 'workshop-viewlet-instructreviewers', get_string('instructreviewers', 'workshop')); echo $output->box(format_text($instructions, $workshop->instructreviewersformat, array('overflowdiv'=>true)), array('generalbox', 'instructions')); print_collapsible_region_end(); @@ -554,7 +554,7 @@ case workshop::PHASE_CLOSED: if (trim($workshop->conclusion)) { $conclusion = file_rewrite_pluginfile_urls($workshop->conclusion, 'pluginfile.php', $workshop->context->id, - 'mod_workshop', 'conclusion', 0, workshop::instruction_editors_options($workshop->context)); + 'mod_workshop', 'conclusion', null, workshop::instruction_editors_options($workshop->context)); print_collapsible_region_start('', 'workshop-viewlet-conclusion', get_string('conclusion', 'workshop')); echo $output->box(format_text($conclusion, $workshop->conclusionformat, array('overflowdiv'=>true)), array('generalbox', 'conclusion')); print_collapsible_region_end();