Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class filter_vdocipher extends moodle_text_filter
private static $playerTheme;
private static $width;
private static $height;
private static $speedOptions;
public function filter($text, array $options = array())
{
self::$csk = get_config('filter_vdocipher', 'csk');
Expand All @@ -47,6 +48,7 @@ public function filter($text, array $options = array())
self::$playerTheme = '9ae8bbe8dd964ddc9bdb932cca1cb59a';
}
self::$watermark = get_config('filter_vdocipher', 'watermark');
self::$speedOptions = get_config('filter_vdocipher', 'speedOptions');
if (strpos($text, '[vdo ') === false) {
return $text;
}
Expand Down Expand Up @@ -145,10 +147,37 @@ function eval_date($matches)
});
</script>
EOF;
}
if (self::validSpeed()) {
$speedOptions = self::$speedOptions;
$output .= <<<EOF
<script>
function onVdoCipherAPIReady() {
var allVideos = vdo.getObjects();
var video_ = allVideos[allVideos.length - 1];
video_.addEventListener('load', function () {
video_.availablePlaybackRates = [$speedOptions]
});
}
</script>
EOF;

}
return $output;
}, $text);
}

private static function validSpeed() {
if (!self::$speedOptions) return false;
$speeds = explode(',', self::$speedOptions);
foreach ($speeds as $speed) {
if (!is_numeric($speed)) return false;
$floatSpeed = floatval($speed);
if ($floatSpeed < 0.2 || $floatSpeed > 2.5) return false;
}
return true;
}

private function vdo_otp($video, $otp_post_array = [])
{
$client_key = self::$csk;
Expand Down
5 changes: 4 additions & 1 deletion lang/en/filter_vdocipher.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
$string['playerVersion_desc'] = 'Setting to 1.x uses the latest and recommended video player version';

$string['playerTheme'] = 'Player Theme';
$string['playerTheme_desc'] = 'This is the player theme. Available player themes are listed in the <a href="https://www.vdocipher.com/blog/2018/10/video-player-themes/" target="_blank">Custom player skin page</a>';
$string['playerTheme_desc'] = 'This is the player theme.';

$string['speedOptions'] = 'Speed options';
$string['speedOptions_desc'] = 'Change the player menu for speed. Accepts comma-separated string with each value between 0.2 to 2.5. Can cause error if invalid.';

$string['watermark'] = 'Watermark JSON';
$string['watermark_desc'] = '(Optional) Watermark to be applied to the videos. For details on writing the annotation code <a href="https://www.vdocipher.com/blog/2014/12/add-text-to-videos-with-watermark/" target="_blank"> check this out. </a>';
Expand Down
16 changes: 11 additions & 5 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
'filter_vdocipher/csk',
get_string('csk', 'filter_vdocipher'),
get_string('csk_desc', 'filter_vdocipher'),
null,
PARAM_NOTAGS,
64
null
));

$settings->add(new admin_setting_configtext(
Expand Down Expand Up @@ -58,14 +56,22 @@
32
));

$settings->add(new admin_setting_configtext(
'filter_vdocipher/speedOptions',
get_string('speedOptions', 'filter_vdocipher'),
get_string('speedOptions_desc', 'filter_vdocipher'),
'',
PARAM_NOTAGS,
32
));

$settings->add(new admin_setting_configtext(
'filter_vdocipher/playerTheme',
get_string('playerTheme', 'filter_vdocipher'),
get_string('playerTheme_desc', 'filter_vdocipher'),
'9ae8bbe8dd964ddc9bdb932cca1cb59a',
PARAM_NOTAGS,
64,
2
64
));

$settings->add(new admin_setting_configtextarea(
Expand Down