Skip to content

Commit

Permalink
VID-793: Validate video js file on server
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Thies committed Apr 14, 2024
1 parent 2ff001c commit 3826ee4
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,21 @@ jobs:
fail-fast: false
matrix:
include:
- php: '8.1'
- php: '8.3'
moodle-branch: 'master'
database: 'pgsql'
- php: '8.1'
- php: '8.2'
moodle-branch: 'master'
database: 'mariadb'
- php: '8.3'
moodle-branch: 'MOODLE_404_STABLE'
database: 'pgsql'
- php: '8.2'
moodle-branch: 'MOODLE_404_STABLE'
database: 'mariadb'
- php: '8.1'
moodle-branch: 'MOODLE_403_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_403_STABLE'
database: 'mariadb'
- php: '8.0'
moodle-branch: 'MOODLE_402_STABLE'
database: 'pgsql'
Expand Down
5 changes: 5 additions & 0 deletions classes/vimeo_embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class vimeo_embed implements \renderable, \templatable {
*/
protected $record = null;

/**
* @var $uniqueid Unique id for element
*/
protected $uniqueid = null;

/**
* Constructor
*
Expand Down
4 changes: 4 additions & 0 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ public function validation($data, $files) {
}
}

foreach (array_keys(core_component::get_plugin_list('videotimeplugin')) as $name) {
$errors += component_callback("videotimeplugin_$name", 'validation', [$data, $files], []);
}

return $errors;
}

Expand Down
42 changes: 42 additions & 0 deletions plugin/videojs/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,45 @@ function videotimeplugin_videojs_config_file_areas() {
'poster',
];
}

/**
* Validates the form input
*
* @param array $data submitted data
* @param array $files submitted files
* @return array eventual errors indexed by the field name
*/
function videotimeplugin_videojs_validation($data, $files) {
$acceptedtypes = [
'audio/flac',
'audio/mp3',
'audio/ogg',
'audio/wav',
'video/mp4',
'video/mpeg',
'video/ogg',
'video/quicktime',
'video/wav',
'video/webm',
];
if (
in_array(resourcelib_guess_url_mimetype($data['vimeo_url']), $acceptedtypes)
|| mod_videotime_get_vimeo_id_from_link($data['mediafile'])
|| resourcelib_get_extension($data['vimeo_url'] == 'm3u8')
) {
return [];
}
foreach ($files as $file) {
if (
!$file->is_directory()
&& ($file->get_itemid() == $data['mediafile'])
) {
if (in_array($file->get_mimetype(), $acceptedtypes)) {
return [];
}
return ['mediafile' => get_string('invalidmediafile', 'videotimeplugin_videojs')];
}

}
return ['vimeo_url' => get_string('required')];
}

0 comments on commit 3826ee4

Please sign in to comment.