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