first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+117
View File
@@ -0,0 +1,117 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Main class for plugin 'media_vimeo'
*
* @package media_vimeo
* @copyright 2016 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Player that embeds Vimeo links.
*
* @package media_vimeo
* @copyright 2016 Marina Glancy
* @author 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
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);
// 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),
];
// Return the rendered template.
return $OUTPUT->render_from_template('media_vimeo/embed', $context);
}
/**
* Get Vimeo video ID.
* @return string
*/
protected function get_video_id(): string {
return $this->get_video_id_with_code() ?? $this->matches[1] ?? '';
}
/**
* Get video id with code.
* @return string|null If NULL then the URL does not contain the code.
*/
protected function get_video_id_with_code(): ?string {
$id = $this->matches[2] ?? null;
if (!empty($id)) {
$code = $this->matches[3] ?? null;
if (!empty($code)) {
return "{$id}?h={$code}";
}
return $id;
}
return null;
}
/**
* Returns regular expression to match vimeo URLs.
* @return string
*/
protected function get_regex() {
// Initial part of link.
$start = '~^https?://vimeo\.com/';
// Middle bit: either 123456789 or 123456789/abdef12345.
$middle = '(([0-9]+)/([0-9a-f]+)|[0-9]+)';
return $start . $middle . core_media_player_external::END_LINK_REGEX_PART;
}
public function get_embeddable_markers() {
return array('vimeo.com/');
}
/**
* Default rank
* @return int
*/
public function get_rank() {
return 1010;
}
}
@@ -0,0 +1,46 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Privacy provider implementation for media_vimeo.
*
* @package media_vimeo
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace media_vimeo\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy provider implementation for media_vimeo.
*
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
@@ -0,0 +1,29 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Strings for plugin 'media_vimeo'
*
* @package media_vimeo
* @copyright 2016 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$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.';
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

+32
View File
@@ -0,0 +1,32 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Settings file for plugin 'media_vimeo'
*
* @package media_vimeo
* @copyright 2023 Matt Porritt <matt.porritt@moodle.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
if ($ADMIN->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));
}
@@ -0,0 +1,53 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template media_vimeo/embed
This template will render the Vimeo embeded player
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.
* embedurl: The URL to the video.
Example context (json):
{
"lang": "en",
"width": 640,
"height": 360,
"style": "position:absolute; top:0; left:0; width:100%; height:100%;",
"embedurl": "https://player.vimeo.com/video/226053498"
}
}}
<!DOCTYPE html>
<html lang="{{lang}}">
<head>
<title>{{#str}} pluginname, media_vimeo {{/str}}</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body style="margin:0; padding:0">
<iframe {{#style}}style="{{style}}" {{/style}}
{{#width}}width="{{width}}" {{/width}}
{{#height}}height="{{height}}" {{/height}}
src="{{{embedurl}}}" allow="fullscreen" loading="lazy">
</iframe>
</body>
</html>
@@ -0,0 +1,41 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template media_vimeo/embed
This template will render the Vimeo embeded player.
Variables required for this template:
* title: The title of the video.
* width: The width of the video.
* height: The height of the video.
* embedurl: The URL to the video.
Example context (json):
{
"title": "Vimeo video",
"width": 640,
"height": 360,
"embedurl": "https://player.vimeo.com/video/226053498"
}
}}
<span class="mediaplugin mediaplugin_vimeo">
<iframe title="{{title}}" width="{{width}}" height="{{height}}" style="border:0;"
src="{{{embedurl}}}" allow="fullscreen" loading="lazy"></iframe>
</span>
+245
View File
@@ -0,0 +1,245 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace media_vimeo;
use core_media_manager;
/**
* Test script for media embedding.
*
* @package media_vimeo
* @copyright 2016 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class player_test extends \advanced_testcase {
/**
* Pre-test setup. Preserves $CFG.
*/
public function setUp(): void {
parent::setUp();
// Reset $CFG and $SERVER.
$this->resetAfterTest();
// Consistent initial setup: all players disabled.
\core\plugininfo\media::set_enabled_plugins('vimeo');
// Pretend to be using Firefox browser (must support ogg for tests to work).
\core_useragent::instance(true, 'Mozilla/5.0 (X11; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0 ');
}
/**
* Test that plugin is returned as enabled media plugin.
*/
public function test_is_installed(): void {
$sortorder = \core\plugininfo\media::get_enabled_plugins();
$this->assertEquals(['vimeo' => 'vimeo'], $sortorder);
}
/**
* Test embedding without media filter (for example for displaying URL resorce).
*/
public function test_embed_url(): void {
global $CFG;
$url = new \moodle_url('http://vimeo.com/1176321');
$manager = core_media_manager::instance();
$embedoptions = array(
core_media_manager::OPTION_TRUSTED => true,
core_media_manager::OPTION_BLOCK => true,
);
$this->assertTrue($manager->can_embed_url($url, $embedoptions));
$content = $manager->embed_url($url, 'Test & file', 0, 0, $embedoptions);
$this->assertMatchesRegularExpression('~mediaplugin_vimeo~', $content);
$this->assertMatchesRegularExpression('~</iframe>~', $content);
$this->assertMatchesRegularExpression('~width="' . $CFG->media_default_width . '" height="' .
$CFG->media_default_height . '"~', $content);
// Repeat sending the specific size to the manager.
$content = $manager->embed_url($url, 'New file', 123, 50, $embedoptions);
$this->assertMatchesRegularExpression('~width="123" height="50"~', $content);
}
/**
* Test that mediaplugin filter replaces a link to the supported file with media tag.
*
* filter_mediaplugin is enabled by default.
*/
public function test_embed_link(): void {
global $CFG;
$url = new \moodle_url('http://vimeo.com/1176321');
$text = \html_writer::link($url, 'Watch this one');
$content = format_text($text, FORMAT_HTML);
$this->assertMatchesRegularExpression('~mediaplugin_vimeo~', $content);
$this->assertMatchesRegularExpression('~</iframe>~', $content);
$this->assertMatchesRegularExpression('~width="' . $CFG->media_default_width . '" height="' .
$CFG->media_default_height . '"~', $content);
}
/**
* Test that mediaplugin filter adds player code on top of <video> tags.
*
* filter_mediaplugin is enabled by default.
*/
public function test_embed_media(): void {
global $CFG;
$url = new \moodle_url('http://vimeo.com/1176321');
$trackurl = new \moodle_url('http://example.org/some_filename.vtt');
$text = '<video controls="true"><source src="'.$url.'"/>' .
'<track src="'.$trackurl.'">Unsupported text</video>';
$content = format_text($text, FORMAT_HTML);
$this->assertMatchesRegularExpression('~mediaplugin_vimeo~', $content);
$this->assertMatchesRegularExpression('~</iframe>~', $content);
$this->assertMatchesRegularExpression('~width="' . $CFG->media_default_width . '" height="' .
$CFG->media_default_height . '"~', $content);
// Video tag, unsupported text and tracks are removed.
$this->assertDoesNotMatchRegularExpression('~</video>~', $content);
$this->assertDoesNotMatchRegularExpression('~<source\b~', $content);
$this->assertDoesNotMatchRegularExpression('~Unsupported text~', $content);
$this->assertDoesNotMatchRegularExpression('~<track\b~i', $content);
// Video with dimensions and source specified as src attribute without <source> tag.
$text = '<video controls="true" width="123" height="35" src="'.$url.'">Unsupported text</video>';
$content = format_text($text, FORMAT_HTML);
$this->assertMatchesRegularExpression('~mediaplugin_vimeo~', $content);
$this->assertMatchesRegularExpression('~</iframe>~', $content);
$this->assertMatchesRegularExpression('~width="123" height="35"~', $content);
}
/**
* Test embedding without media filter (for example for displaying URL resorce)
* and test that player plugin is parsing the URL with the code.
*/
public function test_embed_url_with_code(): void {
global $CFG;
$url = new \moodle_url('https://vimeo.com/1176321/abcdef12345');
$manager = core_media_manager::instance();
$embedoptions = array(
core_media_manager::OPTION_TRUSTED => true,
core_media_manager::OPTION_BLOCK => true,
);
$this->assertTrue($manager->can_embed_url($url, $embedoptions));
$content = $manager->embed_url($url, 'Test & file', 0, 0, $embedoptions);
// Video source URL is contains the new vimeo embedded URL format.
$this->assertStringContainsString('player.vimeo.com/video/1176321?h=abcdef12345', $content);
$this->assertMatchesRegularExpression('~mediaplugin_vimeo~', $content);
$this->assertMatchesRegularExpression('~</iframe>~', $content);
$this->assertMatchesRegularExpression('~width="' . $CFG->media_default_width . '" height="' .
$CFG->media_default_height . '"~', $content);
// Repeat sending the specific size to the manager.
$content = $manager->embed_url($url, 'New file', 123, 50, $embedoptions);
$this->assertMatchesRegularExpression('~width="123" height="50"~', $content);
}
/**
* Test that mediaplugin filter replaces a link to the supported file with media tag
* and test that player plugin is parsing the URL with the code.
*
* filter_mediaplugin is enabled by default.
*/
public function test_embed_link_with_code(): void {
global $CFG;
$url = new \moodle_url('https://vimeo.com/1176321/abcdef12345');
$text = \html_writer::link($url, 'Watch this one');
$content = format_text($text, FORMAT_HTML);
// Video source URL is contains the new vimeo embedded URL format.
$this->assertStringContainsString('player.vimeo.com/video/1176321?h=abcdef12345', $content);
$this->assertMatchesRegularExpression('~mediaplugin_vimeo~', $content);
$this->assertMatchesRegularExpression('~</iframe>~', $content);
$this->assertMatchesRegularExpression('~width="' . $CFG->media_default_width . '" height="' .
$CFG->media_default_height . '"~', $content);
}
/**
* Test that mediaplugin filter adds player code on top of <video> tags
* and test that player plugin is parse the URL with the code.
*
* filter_mediaplugin is enabled by default.
*/
public function test_embed_media_with_code(): void {
global $CFG;
$url = new \moodle_url('https://vimeo.com/1176321/abcdef12345');
$trackurl = new \moodle_url('http://example.org/some_filename.vtt');
$text = '<video controls="true"><source src="'.$url.'"/>' .
'<track src="'.$trackurl.'">Unsupported text</video>';
$content = format_text($text, FORMAT_HTML);
// Video source URL is contains the new vimeo embedded URL format.
$this->assertStringContainsString('player.vimeo.com/video/1176321?h=abcdef12345', $content);
$this->assertMatchesRegularExpression('~mediaplugin_vimeo~', $content);
$this->assertMatchesRegularExpression('~</iframe>~', $content);
$this->assertMatchesRegularExpression('~width="' . $CFG->media_default_width . '" height="' .
$CFG->media_default_height . '"~', $content);
// Video tag, unsupported text and tracks are removed.
$this->assertDoesNotMatchRegularExpression('~</video>~', $content);
$this->assertDoesNotMatchRegularExpression('~<source\b~', $content);
$this->assertDoesNotMatchRegularExpression('~Unsupported text~', $content);
$this->assertDoesNotMatchRegularExpression('~<track\b~i', $content);
// Video with dimensions and source specified as src attribute without <source> tag.
$text = '<video controls="true" width="123" height="35" src="'.$url.'">Unsupported text</video>';
$content = format_text($text, FORMAT_HTML);
$this->assertMatchesRegularExpression('~mediaplugin_vimeo~', $content);
$this->assertMatchesRegularExpression('~</iframe>~', $content);
$this->assertMatchesRegularExpression('~width="123" height="35"~', $content);
}
/**
* Test that mediaplugin filter skip the process when the URL is invalid.
*/
public function test_skip_invalid_url_format_with_code(): void {
$url = new \moodle_url('https://vimeo.com/_________/abcdef12345s');
$text = \html_writer::link($url, 'Invalid Vimeo URL');
$content = format_text($text, FORMAT_HTML);
$this->assertStringNotContainsString('player.vimeo.com/video/_________?h=abcdef12345s', $content);
$this->assertDoesNotMatchRegularExpression('~mediaplugin_vimeo~', $content);
$this->assertDoesNotMatchRegularExpression('~</iframe>~', $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);
}
}
+29
View File
@@ -0,0 +1,29 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Version details
*
* @package media_vimeo
* @copyright 2016 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'media_vimeo'; // Full name of the plugin (used for diagnostics).
+73
View File
@@ -0,0 +1,73 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* A script to embed vimeo videos via the site (so vimeo privacy restrictions by domain will work in the mobile app).
*
* The site is doing a double frame embedding:
* - First, the media player replaces the vimeo link with an iframe pointing to vimeo.
* - Second, the app replaces the previous iframe link with a link to this file that includes again the iframe to vimeo.
* Thanks to these changes, the video is embedded in a page in the site server so the privacy restrictions will work.
*
* Note 1: Vimeo privacy restrictions seems to be based on the Referer HTTP header.
* Note 2: This script works even if the plugin is disabled (some users could be using the vimeo embedding code).
*
* @package media_vimeo
* @copyright 2017 Juan Leyva
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('NO_MOODLE_COOKIES', true);
require_once(__DIR__ . '/../../../config.php');
require_once($CFG->dirroot . '/webservice/lib.php');
global $OUTPUT;
$token = required_param('token', PARAM_ALPHANUM);
$video = required_param('video', PARAM_ALPHANUM); // Video ids are numeric, but it's more solid to expect things like 00001.
$width = optional_param('width', 0, PARAM_INT);
$height = optional_param('height', 0, PARAM_INT);
$h = optional_param('h', '', PARAM_ALPHANUM); // Security hash for restricted videos.
// Authenticate the user.
$webservicelib = new webservice();
$webservicelib->authenticate_user($token);
$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.
if (empty($width) && empty($height)) {
// Use the full page. The video will keep the ratio.
$context['style'] = "position:absolute; top:0; left:0; width:100%; height:100%;";
} else {
$context['width'] = $width;
$context['height'] = $height;
}
// Output the rendered template.
echo $OUTPUT->render_from_template('media_vimeo/appembed', $context);