From 1cb66ccffab257fff3ff984041dc1bf39f435db1 Mon Sep 17 00:00:00 2001 From: cbadusch Date: Tue, 31 Oct 2023 18:50:11 +0100 Subject: [PATCH] Theme Support Plugin --- lib.php | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/lib.php b/lib.php index 8f4296c..68b5275 100755 --- a/lib.php +++ b/lib.php @@ -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); }; /**