Skip to content

Commit

Permalink
Theme Support Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
cbadusch authored and georgmaisser committed Nov 14, 2023
1 parent 3fbbe02 commit 1cb66cc
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,32 +316,42 @@ function mooduell_pluginfile($course, $cm, $context, $filearea, $args, $forcedow

// Make sure the filearea is one of those used by the plugin.
// if ($filearea !== 'aliasavatar' && $filearea !== 'themepicture') {
// return false;
// return false;
// }

if ($filearea === 'themefile') {
$fs = get_file_storage();
$fs = $fs->get_area_files($context->id, 'mod_mooduell', 'themefile');
$file = end($fs);
if (!$file) {
return false; // The file does not exist.
}
// We can now send the file back to the browser - in this case with a cache lifetime of 1 day and no filtering.
send_stored_file($file, 86400, 0, $forcedownload, $options);
} else {
// isloggedin();

// Leave this line out if you set the itemid to null in make_pluginfile_url (set $itemid to 0 instead).
$itemid = array_shift($args); // The first item in the $args array.

// isloggedin();

// Leave this line out if you set the itemid to null in make_pluginfile_url (set $itemid to 0 instead).
$itemid = array_shift($args); // The first item in the $args array.
// Extract the filename / filepath from the $args array.
$filename = array_pop($args); // The last item in the $args array.
if (!$args) {
$filepath = '/';
} else {
$filepath = '/'.implode('/', $args).'/';
}

// Extract the filename / filepath from the $args array.
$filename = array_pop($args); // The last item in the $args array.
if (!$args) {
$filepath = '/';
} else {
$filepath = '/'.implode('/', $args).'/';
// Retrieve the file from the Files API.
$fs = get_file_storage();
$file = $fs->get_file($context->id, 'mod_mooduell', $filearea, $itemid, $filepath, $filename);
if (!$file) {
return false; // The file does not exist.
}
// We can now send the file back to the browser - in this case with a cache lifetime of 1 day and no filtering.
send_stored_file($file, 86400, 0, $forcedownload, $options);
}

// Retrieve the file from the Files API.
$fs = get_file_storage();
$file = $fs->get_file($context->id, 'mod_mooduell', $filearea, $itemid, $filepath, $filename);
if (!$file) {
return false; // The file does not exist.
}
// We can now send the file back to the browser - in this case with a cache lifetime of 1 day and no filtering.
send_stored_file($file, 86400, 0, $forcedownload, $options);
};

/**
Expand Down

0 comments on commit 1cb66cc

Please sign in to comment.