Skip to content

Commit

Permalink
MDL-55957 workshop: Fix the embedded files serving
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mudrd8mz committed Sep 14, 2016
1 parent b022c2c commit 3c215fa
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 37 deletions.
2 changes: 1 addition & 1 deletion mod/workshop/assessment.php
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion mod/workshop/exassessment.php
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion mod/workshop/exsubmission.php
Expand Up @@ -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();
Expand Down
32 changes: 2 additions & 30 deletions mod/workshop/lib.php
Expand Up @@ -1302,43 +1302,15 @@ 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";

$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 === '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') {
Expand Down
2 changes: 1 addition & 1 deletion mod/workshop/submission.php
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions mod/workshop/view.php
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 3c215fa

Please sign in to comment.