From 7ec83d5bcccb402cc9f745977b84a1196801866a Mon Sep 17 00:00:00 2001
From: Tobias Reischmann <tobias.reischmann@wi.uni-muenster.de>
Date: Fri, 6 Apr 2018 09:38:13 +0200
Subject: [PATCH] Introduced engage_url

in order to differentiate between the url of the External API and the
url of the engage server. Opencast can be configured to serve both under
different endpoints.
---
 filter.php                  | 18 +++++++++++-------
 lang/en/filter_opencast.php |  4 +++-
 settings.php                |  4 ++++
 version.php                 |  2 +-
 4 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/filter.php b/filter.php
index fda0c3a..754791f 100644
--- a/filter.php
+++ b/filter.php
@@ -69,24 +69,28 @@ class filter_opencast extends moodle_text_filter {
                 } else if ($video) {
                     $video = false;
                     if (substr($match, 0, 7) === "<source") {
-                        // Get apiurl from opencast tool.
-                        $apiurl = get_config('tool_opencast', 'apiurl');
+                        // Get baseurl either from engageurl setting or from opencast tool.
+                        $baseurl = get_config('filter_opencast', 'engageurl');
+                        if (empty($baseurl)) {
+                            $baseurl = get_config('tool_opencast', 'apiurl');
+                        }
+
 
                         // Check if video is from opencast.
-                        if (strpos($match, $apiurl) === false) {
+                        if (strpos($match, $baseurl) === false) {
                             continue;
                         }
 
-                        if (strpos($apiurl, 'http') !== 0) {
-                            $apiurl = 'http://' . $apiurl;
+                        if (strpos($baseurl, 'http') !== 0) {
+                            $baseurl = 'http://' . $baseurl;
                         }
 
                         // Extract id.
                         $id = substr($match, strpos($match, 'api/') + 4, 36);
-                        $src = $CFG->wwwroot . '/filter/opencast/player/core.html?id=' . $id . '&ocurl=' . urlencode($apiurl);
+                        $src = $CFG->wwwroot . '/filter/opencast/player/core.html?id=' . $id . '&ocurl=' . urlencode($baseurl);
 
                         // Create link to video.
-                        $link = $apiurl . '/engage/theodul/ui/core.html?id=' . $id;
+                        $link = $baseurl . '/engage/theodul/ui/core.html?id=' . $id;
 
                         // Collect the needed data being submitted to the template.
                         $mustachedata = new stdClass();
diff --git a/lang/en/filter_opencast.php b/lang/en/filter_opencast.php
index cd97c6d..e853fb5 100644
--- a/lang/en/filter_opencast.php
+++ b/lang/en/filter_opencast.php
@@ -28,4 +28,6 @@ $string['pluginname'] = 'Opencast Filter';
 $string['setting_consumerkey'] = 'Consumer key';
 $string['setting_consumerkey_desc'] = 'LTI Consumer key';
 $string['setting_consumersecret'] = 'Consumer secret';
-$string['setting_consumersecret_desc'] = 'LTI Consumer secret';
\ No newline at end of file
+$string['setting_consumersecret_desc'] = 'LTI Consumer secret';
+$string['setting_engageurl'] = 'URL of the Opencast Engange server';
+$string['setting_engageurl_desc'] = 'If empty, the base URL of the admin tool is used.';
\ No newline at end of file
diff --git a/settings.php b/settings.php
index 7d27e0a..9851cb9 100644
--- a/settings.php
+++ b/settings.php
@@ -30,4 +30,8 @@ if ($ADMIN->fulltree) {
     $settings->add(new admin_setting_configpasswordunmask('filter_opencast/consumersecret',
         get_string('setting_consumersecret', 'filter_opencast'),
         get_string('setting_consumersecret_desc', 'filter_opencast'), ''));
+    $settings->add(new admin_setting_configtext('filter_opencast/engageurl',
+        get_string('setting_engageurl', 'filter_opencast'),
+        get_string('setting_engageurl_desc', 'filter_opencast'), ''));
+
 }
diff --git a/version.php b/version.php
index 3d007ef..649b823 100644
--- a/version.php
+++ b/version.php
@@ -25,7 +25,7 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$plugin->version = 2018021501;        // The current plugin version (Date: YYYYMMDDXX).
+$plugin->version = 2018031900;        // The current plugin version (Date: YYYYMMDDXX).
 $plugin->requires = 2017050500;        // Requires this Moodle version.
 $plugin->component = 'filter_opencast'; // Full name of the plugin.
 $plugin->dependencies = array('tool_opencast' => ANY_VERSION);
-- 
GitLab