diff --git a/filter.php b/filter.php
index 17971e4cd2bc848119e23bca4e5bb8b825b192fb..38213314d0e81e0d80151b6860ee2f5b33eaeb1b 100644
--- a/filter.php
+++ b/filter.php
@@ -56,105 +56,114 @@ class filter_opencast extends moodle_text_filter
}
foreach (\tool_opencast\local\settings_api::get_ocinstances() as $ocinstance) {
- $episodeurl = get_config('filter_opencast', 'episodeurl_' . $ocinstance->id);
- if (!$episodeurl) {
+ $episodeurls = get_config('filter_opencast', 'episodeurl_' . $ocinstance->id);
+
+ if (!$episodeurls) {
continue;
}
- $urlparts = parse_url($episodeurl);
- $baseurl = $urlparts['scheme'] . '://' . $urlparts['host'];
- if (isset($urlparts['port'])) {
- $baseurl .= $urlparts['port'];
- }
+ foreach (explode("\n", $episodeurls) as $episodeurl) {
+ $episodeurl = trim($episodeurl);
- if (empty($episodeurl) || stripos($text, $baseurl) === false) {
- continue;
- }
+ $urlparts = parse_url($episodeurl);
+ $baseurl = $urlparts['scheme'] . '://' . $urlparts['host'];
+ if (isset($urlparts['port'])) {
+ $baseurl .= $urlparts['port'];
+ }
- // Looking for tags.
- $matches = preg_split('/(<[^>]*>)/i', $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
- if ($matches) {
- $renderer = $PAGE->get_renderer('filter_opencast');
- $video = false;
- $width = false;
- $height = false;
-
- foreach ($matches as $match) {
- // Check if the match is a video tag.
- if (substr($match, 0, 6) === "<video") {
- $video = true;
- preg_match('/width="([0-9]+)"/', $match, $width);
- preg_match('/height="([0-9]+)"/', $match, $height);
- $width = $width ? $width[1] : $width;
- $height = $height ? $height[1] : $height;
- } else if ($video) {
- $video = false;
- if (substr($match, 0, 7) === "<source") {
-
- // Check if video is from opencast.
- if (strpos($match, $baseurl) === false) {
- $width = $height = false;
- continue;
- }
+ if (empty($episodeurl) || stripos($text, $baseurl) === false) {
+ continue;
+ }
- // Extract url.
- preg_match_all('/<source[^>]+src=([\'"])(?<src>.+?)\1[^>]*>/i', $match, $result);
+ // Looking for tags.
+ $matches = preg_split('/(<[^>]*>)/i', $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
+ if ($matches) {
+ $renderer = $PAGE->get_renderer('filter_opencast');
+ $video = false;
+ $width = false;
+ $height = false;
+
+ foreach ($matches as $match) {
+ // Check if the match is a video tag.
+ if (substr($match, 0, 6) === "<video") {
+ $video = true;
+ preg_match('/width="([0-9]+)"/', $match, $width);
+ preg_match('/height="([0-9]+)"/', $match, $height);
+ $width = $width ? $width[1] : $width;
+ $height = $height ? $height[1] : $height;
+ } else if ($video) {
+ $video = false;
+ if (substr($match, 0, 7) === "<source") {
+
+ // Check if video is from opencast.
+ if (strpos($match, $baseurl) === false) {
+ $width = $height = false;
+ continue;
+ }
- // Change url for loading the (Paella) Player.
- $link = $result['src'][0];
+ // Extract url.
+ preg_match_all('/<source[^>]+src=([\'"])(?<src>.+?)\1[^>]*>/i', $match, $result);
- // Get episode id from link.
- $episoderegex = "/" . preg_quote($episodeurl, "/") . "/";
- $episoderegex = preg_replace('/\\\\\[EPISODEID\\\]/', '([0-9a-zA-Z\-]+)', $episoderegex);
- $nummatches = preg_match_all($episoderegex, $link, $episodeid);
+ // Change url for loading the (Paella) Player.
+ $link = $result['src'][0];
- if (!$nummatches) {
- $width = $height = false;
- continue;
- }
+ // Get episode id from link.
+ $episoderegex = "/" . preg_quote($episodeurl, "/") . "/";
+ $episoderegex = preg_replace('/\\\\\[EPISODEID\\\]/', '([0-9a-zA-Z\-]+)', $episoderegex);
+ $nummatches = preg_match_all($episoderegex, $link, $episodeid);
- $data = paella_transform::get_paella_data_json($ocinstance->id, $episodeid[1][0]);
+ if (!$nummatches) {
+ $width = $height = false;
+ continue;
+ }
- // Collect the needed data being submitted to the template.
- $mustachedata = new stdClass();
- $mustachedata->playerid = 'ocplayer_' . $i++;
- $mustachedata->configurl = get_config('filter_opencast', 'configurl_' . $ocinstance->id);
- if (strpos($mustachedata->configurl, 'http') === false) {
- $mustachedata->configurl = (new moodle_url($mustachedata->configurl))->out();
- }
+ $data = paella_transform::get_paella_data_json($ocinstance->id, $episodeid[1][0]);
- $mustachedata->data = json_encode($data);
- $mustachedata->width = $width;
- $mustachedata->height = $height;
- $mustachedata->modplayerpath = (new moodle_url('/mod/opencast/player.html'))->out();
-
- if (count($data['streams']) === 1) {
- $sources = $data['streams'][0]['sources'];
- $res = $sources[array_key_first($sources)][0]['res'];
- $resolution = $res['w'] . '/' . $res['h'];
- $mustachedata->resolution = $resolution;
-
- if ($width xor $height) {
- if ($width) {
- $mustachedata->height = $width * ($res['h'] / $res['w']);
- } else if ($height) {
- $mustachedata->width = $height * ($res['w'] / $res['h']);
- }
+ if (!$data) {
+ continue;
}
- } else {
- if ($width && $height) {
- $mustachedata->width = $width;
- $mustachedata->height = $height;
+
+ // Collect the needed data being submitted to the template.
+ $mustachedata = new stdClass();
+ $mustachedata->playerid = 'ocplayer_' . $i++;
+ $mustachedata->configurl = get_config('filter_opencast', 'configurl_' . $ocinstance->id);
+ if (strpos($mustachedata->configurl, 'http') === false) {
+ $mustachedata->configurl = (new moodle_url($mustachedata->configurl))->out();
}
- }
- $newtext = $renderer->render_player($mustachedata);
+ $mustachedata->data = json_encode($data);
+ $mustachedata->width = $width;
+ $mustachedata->height = $height;
+ $mustachedata->modplayerpath = (new moodle_url('/mod/opencast/player.html'))->out();
+
+ if (count($data['streams']) === 1) {
+ $sources = $data['streams'][0]['sources'];
+ $res = $sources[array_key_first($sources)][0]['res'];
+ $resolution = $res['w'] . '/' . $res['h'];
+ $mustachedata->resolution = $resolution;
+
+ if ($width xor $height) {
+ if ($width) {
+ $mustachedata->height = $width * ($res['h'] / $res['w']);
+ } else if ($height) {
+ $mustachedata->width = $height * ($res['w'] / $res['h']);
+ }
+ }
+ } else {
+ if ($width && $height) {
+ $mustachedata->width = $width;
+ $mustachedata->height = $height;
+ }
+ }
- // Replace video tag.
- $text = preg_replace('/<video(?:(?!<\/video>).)*?' . preg_quote($match, '/') . '.*?<\/video>/',
- $newtext, $text, 1);
+ $newtext = $renderer->render_player($mustachedata);
+
+ // Replace video tag.
+ $text = preg_replace('/<video(?:(?!<\/video>).)*?' . preg_quote($match, '/') . '.*?<\/video>/',
+ $newtext, $text, 1);
+ }
+ $width = $height = false;
}
- $width = $height = false;
}
}
}
diff --git a/lang/en/filter_opencast.php b/lang/en/filter_opencast.php
index 7ce950d290360b8e2b981f461c459960c2b3634d..50da383ae40279383c474796e599da6b17de5ba6 100644
--- a/lang/en/filter_opencast.php
+++ b/lang/en/filter_opencast.php
@@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die();
$string['filtername'] = 'Opencast';
$string['pluginname'] = 'Opencast Filter';
$string['privacy:metadata'] = 'The Opencast filter plugin does not store any personal data.';
-$string['setting_episodeurl'] = 'URL template for filtering';
-$string['setting_episodeurl_desc'] = 'URLs matching this template are replaced with the Opencast player. You must use the placeholder [EPISODEID] to indicate where the episode ID is contained in the URL e.g. http://stable.opencast.de/play/[EPISODEID]';
+$string['setting_episodeurl'] = 'URL templates for filtering';
+$string['setting_episodeurl_desc'] = 'URLs matching this template are replaced with the Opencast player. You must use the placeholder [EPISODEID] to indicate where the episode ID is contained in the URL e.g. http://stable.opencast.de/play/[EPISODEID]. If you want to filter for multiple URLs, enter each URL in a new line.';
$string['setting_configurl'] = 'URL to Paella config.json';
$string['setting_configurl_desc'] = 'URL of the config.json used by Paella Player. Can either be a absolute URL or a URL relative to the wwwroot.';
diff --git a/settings.php b/settings.php
index d61b975e7d20999fa8a035d5750cf9bd5cc42d12..2a703b40c51e5e887a441ebca6729e0f8213ca0c 100644
--- a/settings.php
+++ b/settings.php
@@ -27,9 +27,9 @@ if ($ADMIN->fulltree) {
$ocinstances = \tool_opencast\local\settings_api::get_ocinstances();
foreach ($ocinstances as $instance) {
- $settings->add(new admin_setting_configtext('filter_opencast/episodeurl_' . $instance->id,
+ $settings->add(new admin_setting_configtextarea('filter_opencast/episodeurl_' . $instance->id,
get_string('setting_episodeurl', 'filter_opencast'),
- get_string('setting_episodeurl_desc', 'filter_opencast'), ''));
+ get_string('setting_episodeurl_desc', 'filter_opencast'), '', PARAM_RAW_TRIMMED, '30', '4'));
$settings->add(new admin_setting_configtext('filter_opencast/configurl_' . $instance->id,
new lang_string('setting_configurl', 'filter_opencast'),
diff --git a/version.php b/version.php
index c2301f8a157d42104256c678bcc39d1dbb45483f..24dc816e9608bc3e4df61d4e0b355003bc2cfb58 100644
--- a/version.php
+++ b/version.php
@@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die();
$plugin->maturity = MATURITY_STABLE;
$plugin->release = 'v3.11-r1';
-$plugin->version = 2021101900; // The current plugin version (Date: YYYYMMDDXX).
+$plugin->version = 2021101901; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2020061500; // Requires this Moodle version.
$plugin->component = 'filter_opencast'; // Full name of the plugin.
$plugin->dependencies = array(