From 261cbbacc15ef1732a357d689908c91c15e0617a Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Wed, 18 Apr 2012 15:56:09 +0200 Subject: [PATCH] MDL-32471 preview thumbnails support for activity modules Activity module's xxx_pluginfile() now accepts the $options parameter that is to be passed to the send_stored_file() function. --- lib/filelib.php | 4 +-- mod/assignment/lib.php | 11 +++++--- .../type/online/assignment.class.php | 5 ++-- mod/assignment/type/upgrade.txt | 7 ++++++ .../type/upload/assignment.class.php | 7 +++--- .../type/uploadsingle/assignment.class.php | 4 +-- mod/data/lib.php | 5 ++-- mod/feedback/lib.php | 5 ++-- mod/folder/lib.php | 5 ++-- mod/forum/lib.php | 6 ++--- mod/glossary/lib.php | 5 ++-- mod/imscp/lib.php | 7 +++--- mod/lesson/lib.php | 5 ++-- mod/page/lib.php | 5 ++-- mod/quiz/lib.php | 10 +++++--- mod/resource/lib.php | 5 ++-- mod/scorm/lib.php | 5 ++-- mod/upgrade.txt | 3 +++ mod/wiki/lib.php | 6 +++-- mod/workshop/form/accumulative/lib.php | 5 ++-- mod/workshop/form/comments/lib.php | 5 ++-- mod/workshop/form/numerrors/lib.php | 5 ++-- mod/workshop/form/rubric/lib.php | 5 ++-- mod/workshop/lib.php | 25 ++++++++++--------- 24 files changed, 95 insertions(+), 60 deletions(-) create mode 100644 mod/assignment/type/upgrade.txt diff --git a/lib/filelib.php b/lib/filelib.php index ea0e4fcd8d6..1d4a019cb36 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -3946,10 +3946,10 @@ function file_pluginfile($relativepath, $forcedownload, $preview = null) { $filefunctionold = $modname.'_pluginfile'; if (function_exists($filefunction)) { // if the function exists, it must send the file and terminate. Whatever it returns leads to "not found" - $filefunction($course, $cm, $context, $filearea, $args, $forcedownload); + $filefunction($course, $cm, $context, $filearea, $args, $forcedownload, array('preview' => $preview)); } else if (function_exists($filefunctionold)) { // if the function exists, it must send the file and terminate. Whatever it returns leads to "not found" - $filefunctionold($course, $cm, $context, $filearea, $args, $forcedownload); + $filefunctionold($course, $cm, $context, $filearea, $args, $forcedownload, array('preview' => $preview)); } send_file_not_found(); diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index a6c145eb03d..52d4a41194c 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -1971,11 +1971,15 @@ class assignment_base { } /** + * Sends a file + * * @param string $filearea * @param array $args + * @param bool $forcedownload whether or not force download + * @param array $options additional options affecting the file serving * @return bool */ - function send_file($filearea, $args) { + function send_file($filearea, $args, $forcedownload, array $options=array()) { debugging('plugin does not implement file sending', DEBUG_DEVELOPER); return false; } @@ -3079,9 +3083,10 @@ function assignment_get_participants($assignmentid) { * @param string $filearea file area * @param array $args extra arguments * @param bool $forcedownload whether or not force download + * @param array $options additional options affecting the file serving * @return bool false if file not found, does not return if found - just send the file */ -function assignment_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) { +function assignment_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) { global $CFG, $DB; if ($context->contextlevel != CONTEXT_MODULE) { @@ -3098,7 +3103,7 @@ function assignment_pluginfile($course, $cm, $context, $filearea, $args, $forced $assignmentclass = 'assignment_'.$assignment->assignmenttype; $assignmentinstance = new $assignmentclass($cm->id, $assignment, $cm, $course); - return $assignmentinstance->send_file($filearea, $args); + return $assignmentinstance->send_file($filearea, $args, $forcedownload, $options); } /** * Checks if a scale is being used by an assignment diff --git a/mod/assignment/type/online/assignment.class.php b/mod/assignment/type/online/assignment.class.php index 0985666d170..6adf048044f 100644 --- a/mod/assignment/type/online/assignment.class.php +++ b/mod/assignment/type/online/assignment.class.php @@ -375,7 +375,7 @@ class assignment_online extends assignment_base { } } - public function send_file($filearea, $args) { + public function send_file($filearea, $args, $forcedownload, $options) { global $USER; require_capability('mod/assignment:view', $this->context); @@ -391,7 +391,8 @@ class assignment_online extends assignment_base { } session_get_instance()->write_close(); // unlock session during fileserving - send_stored_file($file, 60*60, 0, true); + + send_stored_file($file, 60*60, 0, true, $options); } /** diff --git a/mod/assignment/type/upgrade.txt b/mod/assignment/type/upgrade.txt new file mode 100644 index 00000000000..20a9f6f4188 --- /dev/null +++ b/mod/assignment/type/upgrade.txt @@ -0,0 +1,7 @@ +This file describes changes in the assignment type API and DB structures. +Information provided here is intended especially for developers. + +=== 2.3 === + +API changes: +* send_file() methods now accept $forcedownload and $options parameters diff --git a/mod/assignment/type/upload/assignment.class.php b/mod/assignment/type/upload/assignment.class.php index 0b537d5adb4..f4fee1d2cfc 100644 --- a/mod/assignment/type/upload/assignment.class.php +++ b/mod/assignment/type/upload/assignment.class.php @@ -614,7 +614,7 @@ class assignment_upload extends assignment_base { die; } - function send_file($filearea, $args) { + function send_file($filearea, $args, $forcedownload, $options) { global $CFG, $DB, $USER; require_once($CFG->libdir.'/filelib.php'); @@ -638,7 +638,8 @@ class assignment_upload extends assignment_base { if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { return false; } - send_stored_file($file, 0, 0, true); // download MUST be forced - security! + + send_stored_file($file, 0, 0, true, $options); // download MUST be forced - security! } else if ($filearea === 'response') { $submissionid = (int)array_shift($args); @@ -658,7 +659,7 @@ class assignment_upload extends assignment_base { if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { return false; } - send_stored_file($file, 0, 0, true); + send_stored_file($file, 0, 0, true, $options); } return false; diff --git a/mod/assignment/type/uploadsingle/assignment.class.php b/mod/assignment/type/uploadsingle/assignment.class.php index a3998d89dd6..b7b3071a4da 100644 --- a/mod/assignment/type/uploadsingle/assignment.class.php +++ b/mod/assignment/type/uploadsingle/assignment.class.php @@ -300,7 +300,7 @@ class assignment_uploadsingle extends assignment_base { return true; } - function send_file($filearea, $args) { + function send_file($filearea, $args, $forcedownload, $options) { global $CFG, $DB, $USER; require_once($CFG->libdir.'/filelib.php'); @@ -329,7 +329,7 @@ class assignment_uploadsingle extends assignment_base { return false; } - send_stored_file($file, 0, 0, true); // download MUST be forced - security! + send_stored_file($file, 0, 0, true, $options); // download MUST be forced - security! } function extend_settings_navigation($node) { diff --git a/mod/data/lib.php b/mod/data/lib.php index e6737d9bec8..d816cc3cff5 100644 --- a/mod/data/lib.php +++ b/mod/data/lib.php @@ -2963,9 +2963,10 @@ function mod_data_get_file_info($browser, $areas, $course, $cm, $context, $filea * @param string $filearea file area * @param array $args extra arguments * @param bool $forcedownload whether or not force download + * @param array $options additional options affecting the file serving * @return bool false if file not found, does not return if found - justsend the file */ -function data_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) { +function data_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) { global $CFG, $DB; if ($context->contextlevel != CONTEXT_MODULE) { @@ -3028,7 +3029,7 @@ function data_pluginfile($course, $cm, $context, $filearea, $args, $forcedownloa } // finally send the file - send_stored_file($file, 0, 0, true); // download MUST be forced - security! + send_stored_file($file, 0, 0, true, $options); // download MUST be forced - security! } return false; diff --git a/mod/feedback/lib.php b/mod/feedback/lib.php index 296655975a1..2e95a1017a8 100644 --- a/mod/feedback/lib.php +++ b/mod/feedback/lib.php @@ -182,9 +182,10 @@ function feedback_update_instance($feedback) { * @param string $filearea file area * @param array $args extra arguments * @param bool $forcedownload whether or not force download + * @param array $options additional options affecting the file serving * @return bool false if file not found, does not return if found - justsend the file */ -function feedback_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) { +function feedback_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) { global $CFG, $DB; if ($filearea === 'item' or $filearea === 'template') { @@ -273,7 +274,7 @@ function feedback_pluginfile($course, $cm, $context, $filearea, $args, $forcedow } // finally send the file - send_stored_file($file, 0, 0, true); // download MUST be forced - security! + send_stored_file($file, 0, 0, true, $options); // download MUST be forced - security! return false; } diff --git a/mod/folder/lib.php b/mod/folder/lib.php index 9abc5c21376..365dd923aab 100644 --- a/mod/folder/lib.php +++ b/mod/folder/lib.php @@ -293,9 +293,10 @@ function folder_get_file_info($browser, $areas, $course, $cm, $context, $fileare * @param string $filearea file area * @param array $args extra arguments * @param bool $forcedownload whether or not force download + * @param array $options additional options affecting the file serving * @return bool false if file not found, does not return if found - just send the file */ -function folder_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) { +function folder_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) { global $CFG, $DB; if ($context->contextlevel != CONTEXT_MODULE) { @@ -323,7 +324,7 @@ function folder_pluginfile($course, $cm, $context, $filearea, $args, $forcedownl // finally send the file // for folder module, we force download file all the time - send_stored_file($file, 86400, 0, true); + send_stored_file($file, 86400, 0, true, $options); } /** diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 96fe4781eb5..9ad53b1003c 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -4108,9 +4108,10 @@ function forum_get_file_info($browser, $areas, $course, $cm, $context, $filearea * @param string $filearea file area * @param array $args extra arguments * @param bool $forcedownload whether or not force download + * @param array $options additional options affecting the file serving * @return bool false if file not found, does not return if found - justsend the file */ -function forum_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) { +function forum_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) { global $CFG, $DB; if ($context->contextlevel != CONTEXT_MODULE) { @@ -4162,9 +4163,8 @@ function forum_pluginfile($course, $cm, $context, $filearea, $args, $forcedownlo return false; } - // finally send the file - send_stored_file($file, 0, 0, true); // download MUST be forced - security! + send_stored_file($file, 0, 0, true, $options); // download MUST be forced - security! } /** diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index a2da16dd758..3f19d2081cd 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -1538,9 +1538,10 @@ function mod_glossary_get_file_info($browser, $areas, $course, $cm, $context, $f * @param string $filearea file area * @param array $args extra arguments * @param bool $forcedownload whether or not force download + * @param array $options additional options affecting the file serving * @return bool false if file not found, does not return if found - justsend the file */ -function glossary_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) { +function glossary_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) { global $CFG, $DB; if ($context->contextlevel != CONTEXT_MODULE) { @@ -1590,7 +1591,7 @@ function glossary_pluginfile($course, $cm, $context, $filearea, $args, $forcedow } // finally send the file - send_stored_file($file, 0, 0, true); // download MUST be forced - security! + send_stored_file($file, 0, 0, true, $options); // download MUST be forced - security! } else if ($filearea === 'export') { require_login($course, false, $cm); diff --git a/mod/imscp/lib.php b/mod/imscp/lib.php index 517047a0b79..f57a22763eb 100644 --- a/mod/imscp/lib.php +++ b/mod/imscp/lib.php @@ -337,9 +337,10 @@ function imscp_get_file_info($browser, $areas, $course, $cm, $context, $filearea * @param string $filearea file area * @param array $args extra arguments * @param bool $forcedownload whether or not force download + * @param array $options additional options affecting the file serving * @return bool false if file not found, does not return if found - justsend the file */ -function imscp_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) { +function imscp_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) { global $CFG, $DB; if ($context->contextlevel != CONTEXT_MODULE) { @@ -367,7 +368,7 @@ function imscp_pluginfile($course, $cm, $context, $filearea, $args, $forcedownlo } // finally send the file - send_stored_file($file, 86400, 0, $forcedownload); + send_stored_file($file, 86400, 0, $forcedownload, $options); } else if ($filearea === 'backup') { if (!has_capability('moodle/course:managefiles', $context)) { @@ -383,7 +384,7 @@ function imscp_pluginfile($course, $cm, $context, $filearea, $args, $forcedownlo } // finally send the file - send_stored_file($file, 86400, 0, $forcedownload); + send_stored_file($file, 86400, 0, $forcedownload, $options); } else { return false; diff --git a/mod/lesson/lib.php b/mod/lesson/lib.php index 0157f0ee43d..b3252fcfe41 100644 --- a/mod/lesson/lib.php +++ b/mod/lesson/lib.php @@ -876,9 +876,10 @@ function lesson_get_import_export_formats($type) { * @param string $filearea file area * @param array $args extra arguments * @param bool $forcedownload whether or not force download + * @param array $options additional options affecting the file serving * @return bool false if file not found, does not return if found - justsend the file */ -function lesson_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) { +function lesson_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) { global $CFG, $DB; if ($context->contextlevel != CONTEXT_MODULE) { @@ -917,7 +918,7 @@ function lesson_pluginfile($course, $cm, $context, $filearea, $args, $forcedownl } // finally send the file - send_stored_file($file, 0, 0, $forcedownload); // download MUST be forced - security! + send_stored_file($file, 0, 0, $forcedownload, $options); // download MUST be forced - security! } /** diff --git a/mod/page/lib.php b/mod/page/lib.php index 6d960f8530b..4512f5e7fca 100644 --- a/mod/page/lib.php +++ b/mod/page/lib.php @@ -360,9 +360,10 @@ function page_get_file_info($browser, $areas, $course, $cm, $context, $filearea, * @param string $filearea file area * @param array $args extra arguments * @param bool $forcedownload whether or not force download + * @param array $options additional options affecting the file serving * @return bool false if file not found, does not return if found - just send the file */ -function page_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) { +function page_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) { global $CFG, $DB; require_once("$CFG->libdir/resourcelib.php"); @@ -418,7 +419,7 @@ function page_pluginfile($course, $cm, $context, $filearea, $args, $forcedownloa } // finally send the file - send_stored_file($file, 86400, 0, $forcedownload); + send_stored_file($file, 86400, 0, $forcedownload, $options); } } diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 8720e253183..1e29c528596 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -1655,9 +1655,10 @@ function quiz_extend_settings_navigation($settings, $quiznode) { * @param string $filearea file area * @param array $args extra arguments * @param bool $forcedownload whether or not force download + * @param array $options additional options affecting the file serving * @return bool false if file not found, does not return if found - justsend the file */ -function quiz_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) { +function quiz_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) { global $CFG, $DB; if ($context->contextlevel != CONTEXT_MODULE) { @@ -1687,7 +1688,7 @@ function quiz_pluginfile($course, $cm, $context, $filearea, $args, $forcedownloa if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { return false; } - send_stored_file($file, 0, 0, true); + send_stored_file($file, 0, 0, true, $options); } /** @@ -1704,10 +1705,11 @@ function quiz_pluginfile($course, $cm, $context, $filearea, $args, $forcedownloa * @param int $slot the id of a question in this quiz attempt. * @param array $args the remaining bits of the file path. * @param bool $forcedownload whether the user must be forced to download the file. + * @param array $options additional options affecting the file serving * @return bool false if file not found, does not return if found - justsend the file */ function mod_quiz_question_pluginfile($course, $context, $component, - $filearea, $qubaid, $slot, $args, $forcedownload) { + $filearea, $qubaid, $slot, $args, $forcedownload, array $options=array()) { global $CFG; require_once($CFG->dirroot . '/mod/quiz/locallib.php'); @@ -1739,7 +1741,7 @@ function mod_quiz_question_pluginfile($course, $context, $component, send_file_not_found(); } - send_stored_file($file, 0, 0, $forcedownload); + send_stored_file($file, 0, 0, $forcedownload, $options); } /** diff --git a/mod/resource/lib.php b/mod/resource/lib.php index 2b109b60e22..978f2048c54 100644 --- a/mod/resource/lib.php +++ b/mod/resource/lib.php @@ -382,9 +382,10 @@ function resource_get_file_info($browser, $areas, $course, $cm, $context, $filea * @param string $filearea file area * @param array $args extra arguments * @param bool $forcedownload whether or not force download + * @param array $options additional options affecting the file serving * @return bool false if file not found, does not return if found - just send the file */ -function resource_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) { +function resource_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) { global $CFG, $DB; require_once("$CFG->libdir/resourcelib.php"); @@ -443,7 +444,7 @@ function resource_pluginfile($course, $cm, $context, $filearea, $args, $forcedow } // finally send the file - send_stored_file($file, 86400, $filter, $forcedownload); + send_stored_file($file, 86400, $filter, $forcedownload, $options); } /** diff --git a/mod/scorm/lib.php b/mod/scorm/lib.php index 2ad8a133713..98490316dc1 100644 --- a/mod/scorm/lib.php +++ b/mod/scorm/lib.php @@ -927,9 +927,10 @@ function scorm_get_file_info($browser, $areas, $course, $cm, $context, $filearea * @param string $filearea file area * @param array $args extra arguments * @param bool $forcedownload whether or not force download + * @param array $options additional options affecting the file serving * @return bool false if file not found, does not return if found - just send the file */ -function scorm_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) { +function scorm_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) { global $CFG; if ($context->contextlevel != CONTEXT_MODULE) { @@ -968,7 +969,7 @@ function scorm_pluginfile($course, $cm, $context, $filearea, $args, $forcedownlo } // finally send the file - send_stored_file($file, $lifetime, 0, false); + send_stored_file($file, $lifetime, 0, false, $options); } /** diff --git a/mod/upgrade.txt b/mod/upgrade.txt index 62b3918fccc..3419e8200a7 100644 --- a/mod/upgrade.txt +++ b/mod/upgrade.txt @@ -7,6 +7,9 @@ information provided here is intended especially for developers. required changes in code: * define the capability mod/xxx:addinstance (and the corresponding lang string) (unless your mod is a MOD_ARCHETYPE_SYSTEM). +* xxx_pluginfile() is now given the 7th parameter (hopefully the last one) that + contains additional options for the file serving. The array should be re-passed + to send_stored_file(). === 2.2 === diff --git a/mod/wiki/lib.php b/mod/wiki/lib.php index 9dbd3f110e8..ff84aeaab46 100644 --- a/mod/wiki/lib.php +++ b/mod/wiki/lib.php @@ -445,8 +445,10 @@ function wiki_scale_used_anywhere($scaleid) { * @param string $filearea file area * @param array $args extra arguments * @param bool $forcedownload whether or not force download + * @param array $options additional options affecting the file serving + * @return bool false if the file was not found, just send the file otherwise and do not return anything */ -function wiki_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) { +function wiki_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) { global $CFG; if ($context->contextlevel != CONTEXT_MODULE) { @@ -477,7 +479,7 @@ function wiki_pluginfile($course, $cm, $context, $filearea, $args, $forcedownloa $lifetime = isset($CFG->filelifetime) ? $CFG->filelifetime : 86400; - send_stored_file($file, $lifetime, 0); + send_stored_file($file, $lifetime, 0, $options); } } diff --git a/mod/workshop/form/accumulative/lib.php b/mod/workshop/form/accumulative/lib.php index 2a266281c00..6a3a54db808 100644 --- a/mod/workshop/form/accumulative/lib.php +++ b/mod/workshop/form/accumulative/lib.php @@ -38,9 +38,10 @@ require_once($CFG->libdir . '/gradelib.php'); // to handle float vs de * @param string $filearea file area * @param array $args extra arguments * @param bool $forcedownload whether or not force download + * @param array $options additional options affecting the file serving * @return bool */ -function workshopform_accumulative_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload) { +function workshopform_accumulative_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload, array $options=array()) { global $DB; if ($context->contextlevel != CONTEXT_MODULE) { @@ -72,7 +73,7 @@ function workshopform_accumulative_pluginfile($course, $cm, $context, $filearea, } // finally send the file - send_stored_file($file); + send_stored_file($file, 0, 0, $forcedownload, $options); } /** diff --git a/mod/workshop/form/comments/lib.php b/mod/workshop/form/comments/lib.php index 1e7723f1059..408ecf42745 100644 --- a/mod/workshop/form/comments/lib.php +++ b/mod/workshop/form/comments/lib.php @@ -38,9 +38,10 @@ require_once($CFG->libdir . '/gradelib.php'); // to handle float vs de * @param string $filearea file area * @param array $args extra arguments * @param bool $forcedownload whether or not force download + * @param array $options additional options affecting the file serving * @return bool */ -function workshopform_comments_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload) { +function workshopform_comments_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload, array $options=array()) { global $DB; if ($context->contextlevel != CONTEXT_MODULE) { @@ -72,7 +73,7 @@ function workshopform_comments_pluginfile($course, $cm, $context, $filearea, arr } // finally send the file - send_stored_file($file); + send_stored_file($file, 0, 0, $forcedownload, $options); } /** diff --git a/mod/workshop/form/numerrors/lib.php b/mod/workshop/form/numerrors/lib.php index 2fd0ce90549..3e461dd88a3 100644 --- a/mod/workshop/form/numerrors/lib.php +++ b/mod/workshop/form/numerrors/lib.php @@ -38,9 +38,10 @@ require_once($CFG->libdir . '/gradelib.php'); // to handle float vs de * @param string $filearea file area * @param array $args extra arguments * @param bool $forcedownload whether or not force download + * @param array $options additional options affecting the file serving * @return bool */ -function workshopform_numerrors_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload) { +function workshopform_numerrors_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload, array $options=array()) { global $DB; if ($context->contextlevel != CONTEXT_MODULE) { @@ -72,7 +73,7 @@ function workshopform_numerrors_pluginfile($course, $cm, $context, $filearea, ar } // finally send the file - send_stored_file($file); + send_stored_file($file, 0, 0, $forcedownload, $options); } /** diff --git a/mod/workshop/form/rubric/lib.php b/mod/workshop/form/rubric/lib.php index 1361c66ebfb..eb6425d9f8d 100644 --- a/mod/workshop/form/rubric/lib.php +++ b/mod/workshop/form/rubric/lib.php @@ -38,9 +38,10 @@ require_once($CFG->libdir . '/gradelib.php'); // to handle float vs de * @param string $filearea file area * @param array $args extra arguments * @param bool $forcedownload whether or not force download + * @param array $options additional options affecting the file serving * @return bool */ -function workshopform_rubric_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload) { +function workshopform_rubric_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload, array $options=array()) { global $DB; if ($context->contextlevel != CONTEXT_MODULE) { @@ -72,7 +73,7 @@ function workshopform_rubric_pluginfile($course, $cm, $context, $filearea, array } // finally send the file - send_stored_file($file); + send_stored_file($file, 0, 0, $forcedownload, $options); } /** diff --git a/mod/workshop/lib.php b/mod/workshop/lib.php index 7dc9a6e35b1..655c5ddc39c 100644 --- a/mod/workshop/lib.php +++ b/mod/workshop/lib.php @@ -1221,15 +1221,16 @@ function workshop_get_file_areas($course, $cm, $context) { * @package mod_workshop * @category files * - * @param stdClass $course - * @param stdClass $cm - * @param stdClass $context - * @param string $filearea - * @param array $args - * @param bool $forcedownload - * @return void this should never return to the caller + * @param stdClass $course the course object + * @param stdClass $cm the course module object + * @param stdClass $context the workshop's context + * @param string $filearea the name of the file area + * @param array $args extra arguments (itemid, path) + * @param bool $forcedownload whether or not force download + * @param array $options additional options affecting the file serving + * @return bool false if the file not found, just send the file otherwise and do not return anything */ -function workshop_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload) { +function workshop_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload, array $options=array()) { global $DB, $CFG; if ($context->contextlevel != CONTEXT_MODULE) { @@ -1246,7 +1247,7 @@ function workshop_pluginfile($course, $cm, $context, $filearea, array $args, $fo array_shift($args); // we do not use itemids here $relativepath = implode('/', $args); - $fullpath = "/$context->id/mod_workshop/$filearea/0/$relativepath"; // beware, slashes are not used here! + $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()) { @@ -1256,7 +1257,7 @@ function workshop_pluginfile($course, $cm, $context, $filearea, array $args, $fo $lifetime = isset($CFG->filelifetime) ? $CFG->filelifetime : 86400; // finally send the file - send_stored_file($file, $lifetime, 0); + send_stored_file($file, $lifetime, 0, $forcedownload, $options); } if ($filearea === 'instructreviewers') { @@ -1277,7 +1278,7 @@ function workshop_pluginfile($course, $cm, $context, $filearea, array $args, $fo $lifetime = isset($CFG->filelifetime) ? $CFG->filelifetime : 86400; // finally send the file - send_stored_file($file, $lifetime, 0); + send_stored_file($file, $lifetime, 0, $forcedownload, $options); } else if ($filearea === 'submission_content' or $filearea === 'submission_attachment') { $itemid = (int)array_shift($args); @@ -1296,7 +1297,7 @@ function workshop_pluginfile($course, $cm, $context, $filearea, array $args, $fo } // finally send the file // these files are uploaded by students - forcing download for security reasons - send_stored_file($file, 0, 0, true); + send_stored_file($file, 0, 0, true, $options); } return false;