diff --git a/media/player/vimeo/classes/plugin.php b/media/player/vimeo/classes/plugin.php index db03d74345d..56e24cfd95e 100644 --- a/media/player/vimeo/classes/plugin.php +++ b/media/player/vimeo/classes/plugin.php @@ -35,21 +35,29 @@ defined('MOODLE_INTERNAL') || die(); class media_vimeo_plugin extends core_media_player_external { protected function embed_external(moodle_url $url, $name, $width, $height, $options) { global $OUTPUT; + + $donottrack = get_config('media_vimeo', 'donottrack'); $videoid = $this->get_video_id(); $info = s($name); + $params = []; // Note: resizing via url is not supported, user can click the fullscreen // button instead. iframe embedding is not xhtml strict but it is the only // option that seems to work on most devices. self::pick_video_size($width, $height); - $embedurl = new moodle_url("https://player.vimeo.com/video/$videoid"); + // Add do not track parameter. + if ($donottrack) { + $params['dnt'] = 1; + } + + $embedurl = new moodle_url("https://player.vimeo.com/video/$videoid", $params); // Template context. $context = [ - 'width' => $width, - 'height' => $height, - 'title' => $info, - 'embedurl' => $embedurl->out(false), + 'width' => $width, + 'height' => $height, + 'title' => $info, + 'embedurl' => $embedurl->out(false), ]; // Return the rendered template. diff --git a/media/player/vimeo/lang/en/media_vimeo.php b/media/player/vimeo/lang/en/media_vimeo.php index 90777a56954..c19741c8000 100644 --- a/media/player/vimeo/lang/en/media_vimeo.php +++ b/media/player/vimeo/lang/en/media_vimeo.php @@ -25,3 +25,5 @@ $string['pluginname'] = 'Vimeo'; $string['pluginname_help'] = 'The video-sharing website vimeo.com.'; $string['privacy:metadata'] = 'The Vimeo media plugin does not store any personal data.'; +$string['donottrack'] = 'Enable do not track Vimeo links'; +$string['donottrack_desc'] = 'If enabled, the player will not track any session data, including all cookies and analytics.'; diff --git a/media/player/vimeo/settings.php b/media/player/vimeo/settings.php new file mode 100644 index 00000000000..a6856bb1779 --- /dev/null +++ b/media/player/vimeo/settings.php @@ -0,0 +1,32 @@ +. + +/** + * Settings file for plugin 'media_vimeo' + * + * @package media_vimeo + * @copyright 2023 Matt Porritt fulltree) { + // Add a settings checkbox to enable or disable do not track vimeo links. + $settings->add(new admin_setting_configcheckbox('media_vimeo/donottrack', + new lang_string('donottrack', 'media_vimeo'), + new lang_string('donottrack_desc', 'media_vimeo'), 0)); +} diff --git a/media/player/vimeo/templates/appembed.mustache b/media/player/vimeo/templates/appembed.mustache index f940149fcc4..1091e352c0f 100644 --- a/media/player/vimeo/templates/appembed.mustache +++ b/media/player/vimeo/templates/appembed.mustache @@ -21,6 +21,7 @@ in a special format for the Moodle mobile app. Variables required for this template: + * lang: The language of the user. * width: The width of the video. * height: The height of the video. * style: The style info for iframe. @@ -28,6 +29,7 @@ Example context (json): { + "lang": "en", "width": 640, "height": 360, "style": "position:absolute; top:0; left:0; width:100%; height:100%;", @@ -35,10 +37,11 @@ } }} - - + + - + {{#str}} pluginname, media_vimeo {{/str}} + diff --git a/media/player/vimeo/tests/player_test.php b/media/player/vimeo/tests/player_test.php index 041af3129c5..5c8e5909ec1 100644 --- a/media/player/vimeo/tests/player_test.php +++ b/media/player/vimeo/tests/player_test.php @@ -225,4 +225,21 @@ class player_test extends \advanced_testcase { $this->assertDoesNotMatchRegularExpression('~mediaplugin_vimeo~', $content); $this->assertDoesNotMatchRegularExpression('~~', $content); } + + /** + * Test that Vimeo media plugin renders embed code correctly + * when the "do not track" config options is set to true. + * + * @covers \media_vimeo_plugin::embed_external + */ + public function test_vimeo_donottrack(): void { + // Turn on the do not track option. + set_config('donottrack', true, 'media_vimeo'); + + // Test that the embed code contains the do not track param in the url. + $url = new \moodle_url('https://vimeo.com/226053498'); + $text = \html_writer::link($url, 'Watch this one'); + $content = format_text($text, FORMAT_HTML); + $this->assertMatchesRegularExpression('~dnt=1~', $content); + } } diff --git a/media/player/vimeo/version.php b/media/player/vimeo/version.php index ccc9b17a5f4..426c9b999d6 100644 --- a/media/player/vimeo/version.php +++ b/media/player/vimeo/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2023042400; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2023062500; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2023041800; // Requires this Moodle version. $plugin->component = 'media_vimeo'; // Full name of the plugin (used for diagnostics). diff --git a/media/player/vimeo/wsplayer.php b/media/player/vimeo/wsplayer.php index f4ea6f4e949..0d23e80bea7 100644 --- a/media/player/vimeo/wsplayer.php +++ b/media/player/vimeo/wsplayer.php @@ -48,11 +48,16 @@ $h = optional_param('h', '', PARAM_ALPHANUM); // Security hash for restricted vi $webservicelib = new webservice(); $webservicelib->authenticate_user($token); -$params = []; +$params = ['lang' => current_language()]; if (!empty($h)) { $params['h'] = $h; } +// Add do not track parameter. +if (get_config('media_vimeo', 'donottrack')) { + $params['dnt'] = 1; +} + $embedurl = new moodle_url("https://player.vimeo.com/video/$video", $params); $context = ['embedurl' => $embedurl->out(false)]; // Template context. @@ -65,4 +70,4 @@ if (empty($width) && empty($height)) { } // Output the rendered template. -echo $OUTPUT->render_from_template('media_youtube/appembed', $context); +echo $OUTPUT->render_from_template('media_vimeo/appembed', $context);