forked from UbiCastTeam/moodle-mod_ubicast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocallib.php
151 lines (123 loc) · 4.86 KB
/
locallib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?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/>.
/**
* Private ubicast module utility functions
*
* @package mod_ubicast
* @copyright 2013 UbiCast {@link https://www.ubicast.eu}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/filelib.php');
require_once($CFG->libdir.'/resourcelib.php');
// Needed to get `lti_sign_parameters` and `lti_post_launch_html`.
require_once($CFG->dirroot.'/mod/lti/locallib.php');
/**
* Launch an external tool activity.
*
* @param array $cm Course Module instance
* @param string $target MediaServer LTI page relative path
* @return string The HTML code containing the javascript code for the launch
*/
function ubicast_launch_tool($course, $cm, $target) {
global $CFG;
// Default LTI config.
$typeconfig = null;
if (!empty($cm)) {
$typeconfig = (array) $cm;
} else {
$typeconfig = (array) $course;
}
$typeconfig['acceptgrades'] = '1';
$typeconfig['allowroster'] = '0';
$typeconfig['forcessl'] = '0';
$typeconfig['sendemailaddr'] = '1';
$typeconfig['sendname'] = '1';
// Default the organizationid if not specified.
if (empty($typeconfig['organizationid'])) {
$urlparts = parse_url($CFG->wwwroot);
$typeconfig['organizationid'] = $urlparts['host'];
}
// Get LTI secret and key from config.
$config = get_config('ubicast');
$key = $config->ubicast_ltikey;
$secret = $config->ubicast_ltisecret;
$endpoint = $config->ubicast_url.'/lti/'.$target;
$endpoint = trim($endpoint);
$orgid = $typeconfig['organizationid'];
$instance = $cm;
if (empty($cm)) {
$instance = new stdClass();
$instance->id = 0;
$instance->course = $course->id;
$instance->resource_link_id = $course->id.'-admin';
}
$allparams = lti_build_request($instance, $typeconfig, $course);
$requestparams = array_merge($allparams, lti_build_standard_request($instance, $orgid, false));
$requestparams['launch_presentation_document_target'] = 'iframe';
if (!empty($key) && !empty($secret)) {
$parms = lti_sign_parameters($requestparams, $endpoint, "POST", $key, $secret);
$endpointurl = new \moodle_url($endpoint);
$endpointparams = $endpointurl->params();
// Strip querystring params in endpoint url from $parms to avoid duplication.
if (!empty($endpointparams) && !empty($parms)) {
foreach (array_keys($endpointparams) as $paramname) {
if (isset($parms[$paramname])) {
unset($parms[$paramname]);
}
}
}
} else {
$parms = $requestparams;
}
$debuglaunch = false;
$content = lti_post_launch_html($parms, $endpoint, $debuglaunch);
echo $content;
}
function ubicast_display_media($ubicastresource, $cm, $course) {
global $CFG, $PAGE, $OUTPUT;
$title = $ubicastresource->name;
// Page header.
$PAGE->set_title($course->shortname.': '.$ubicastresource->name);
$PAGE->set_heading($course->fullname);
$PAGE->set_activity_record($ubicastresource);
echo $OUTPUT->header();
// Page body.
$config = get_config('ubicast');
$key = $config->ubicast_ltikey;
$secret = $config->ubicast_ltisecret;
$iframeurl = $CFG->wwwroot.'/mod/ubicast/launch.php?id='.$cm->id.'&mediaid='.$ubicastresource->mediaid;
if (empty($key) || empty($secret)) {
$iframeurl = $config->ubicast_url.'/permalink/'.$ubicastresource->mediaid.'/iframe/';
}
$code = '
<iframe class="mediaserver-iframe" style="width: 100%; height: 800px;" src="'.$iframeurl.'" frameborder="0"
allow="autoplay; encrypted-media" allowfullscreen="allowfullscreen"></iframe>
<script type="text/javascript" src="'.$CFG->wwwroot.'/mod/ubicast/statics/iframe_manager.js?_=5"></script>
';
echo $code;
// Page intro.
if (!isset($ignoresettings)) {
if (trim(strip_tags($ubicastresource->intro))) {
echo $OUTPUT->box_start('mod_introbox', 'ubicastintro');
echo format_module_intro('ubicast', $ubicastresource, $cm->id);
echo $OUTPUT->box_end();
}
}
// Page footer.
echo $OUTPUT->footer();
die;
}