mirror of
https://github.com/moodle/moodle.git
synced 2025-03-21 08:00:37 +01:00
MDL-56486 workshop: Use filetypes utility class to check submitted files
This commit is contained in:
parent
f9a8d98047
commit
5a0865a1b1
mod/workshop
@ -133,19 +133,20 @@ class workshop_assessment_form extends moodleform {
|
|||||||
$errors = parent::validation($data, $files);
|
$errors = parent::validation($data, $files);
|
||||||
|
|
||||||
if (isset($data['feedbackauthorattachment_filemanager']) and isset($this->workshop->overallfeedbackfiletypes)) {
|
if (isset($data['feedbackauthorattachment_filemanager']) and isset($this->workshop->overallfeedbackfiletypes)) {
|
||||||
$whitelist = workshop::normalize_file_extensions($this->workshop->overallfeedbackfiletypes);
|
$filetypesutil = new \core_form\filetypes_util();
|
||||||
|
$whitelist = $filetypesutil->normalize_file_types($this->workshop->overallfeedbackfiletypes);
|
||||||
if ($whitelist) {
|
if ($whitelist) {
|
||||||
$draftfiles = file_get_drafarea_files($data['feedbackauthorattachment_filemanager']);
|
$draftfiles = file_get_drafarea_files($data['feedbackauthorattachment_filemanager']);
|
||||||
if ($draftfiles) {
|
if ($draftfiles) {
|
||||||
$wrongfiles = array();
|
$wrongfiles = array();
|
||||||
foreach ($draftfiles->list as $file) {
|
foreach ($draftfiles->list as $file) {
|
||||||
if (!workshop::is_allowed_file_type($file->filename, $whitelist)) {
|
if (!$filetypesutil->is_allowed_file_type($file->filename, $whitelist)) {
|
||||||
$wrongfiles[] = $file->filename;
|
$wrongfiles[] = $file->filename;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($wrongfiles) {
|
if ($wrongfiles) {
|
||||||
$a = array(
|
$a = array(
|
||||||
'whitelist' => workshop::clean_file_extensions($whitelist),
|
'whitelist' => implode(', ', $whitelist),
|
||||||
'wrongfiles' => implode(', ', $wrongfiles),
|
'wrongfiles' => implode(', ', $wrongfiles),
|
||||||
);
|
);
|
||||||
$errors['feedbackauthorattachment_filemanager'] = get_string('err_wrongfileextension', 'mod_workshop', $a);
|
$errors['feedbackauthorattachment_filemanager'] = get_string('err_wrongfileextension', 'mod_workshop', $a);
|
||||||
|
@ -2515,9 +2515,8 @@ class workshop {
|
|||||||
'return_types' => FILE_INTERNAL | FILE_CONTROLLED_LINK,
|
'return_types' => FILE_INTERNAL | FILE_CONTROLLED_LINK,
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($acceptedtypes = self::normalize_file_extensions($this->submissionfiletypes)) {
|
$filetypesutil = new \core_form\filetypes_util();
|
||||||
$options['accepted_types'] = $acceptedtypes;
|
$options['accepted_types'] = $filetypesutil->normalize_file_types($this->overallfeedbackfiletypes);
|
||||||
}
|
|
||||||
|
|
||||||
return $options;
|
return $options;
|
||||||
}
|
}
|
||||||
@ -2557,9 +2556,8 @@ class workshop {
|
|||||||
'return_types' => FILE_INTERNAL | FILE_CONTROLLED_LINK,
|
'return_types' => FILE_INTERNAL | FILE_CONTROLLED_LINK,
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($acceptedtypes = self::normalize_file_extensions($this->overallfeedbackfiletypes)) {
|
$filetypesutil = new \core_form\filetypes_util();
|
||||||
$options['accepted_types'] = $acceptedtypes;
|
$options['accepted_types'] = $filetypesutil->normalize_file_types($this->overallfeedbackfiletypes);
|
||||||
}
|
|
||||||
|
|
||||||
return $options;
|
return $options;
|
||||||
}
|
}
|
||||||
|
@ -95,19 +95,20 @@ class workshop_submission_form extends moodleform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isset($data['attachment_filemanager']) and isset($this->_customdata['workshop']->submissionfiletypes)) {
|
if (isset($data['attachment_filemanager']) and isset($this->_customdata['workshop']->submissionfiletypes)) {
|
||||||
$whitelist = workshop::normalize_file_extensions($this->_customdata['workshop']->submissionfiletypes);
|
$filetypesutil = new \core_form\filetypes_util();
|
||||||
|
$whitelist = $filetypesutil->normalize_file_types($this->_customdata['workshop']->submissionfiletypes);
|
||||||
if ($whitelist) {
|
if ($whitelist) {
|
||||||
$draftfiles = file_get_drafarea_files($data['attachment_filemanager']);
|
$draftfiles = file_get_drafarea_files($data['attachment_filemanager']);
|
||||||
if ($draftfiles) {
|
if ($draftfiles) {
|
||||||
$wrongfiles = array();
|
$wrongfiles = array();
|
||||||
foreach ($draftfiles->list as $file) {
|
foreach ($draftfiles->list as $file) {
|
||||||
if (!workshop::is_allowed_file_type($file->filename, $whitelist)) {
|
if (!$filetypesutil->is_allowed_file_type($file->filename, $whitelist)) {
|
||||||
$wrongfiles[] = $file->filename;
|
$wrongfiles[] = $file->filename;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($wrongfiles) {
|
if ($wrongfiles) {
|
||||||
$a = array(
|
$a = array(
|
||||||
'whitelist' => workshop::clean_file_extensions($whitelist),
|
'whitelist' => implode(', ', $whitelist),
|
||||||
'wrongfiles' => implode(', ', $wrongfiles),
|
'wrongfiles' => implode(', ', $wrongfiles),
|
||||||
);
|
);
|
||||||
$errors['attachment_filemanager'] = get_string('err_wrongfileextension', 'mod_workshop', $a);
|
$errors['attachment_filemanager'] = get_string('err_wrongfileextension', 'mod_workshop', $a);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user