forked from moodle-an-hochschulen/moodle-theme_boost_union
-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderers.php
199 lines (178 loc) · 8.54 KB
/
renderers.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?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/>.
/**
* Boost Union renderer class. This file is currently only used to extend the mod_h5p and mod_hvp renderers.
*
* @package theme_boost_union
* @copyright 2022 Nina Herrmann <[email protected]>
* @copyright on behalf of Alexander Bias, lern.link GmbH <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Extend the core_h5p renderer.
*
* @package theme_boost_union
* @copyright 2022 Nina Herrmann <[email protected]>
* @copyright on behalf of Alexander Bias, lern.link GmbH <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class theme_boost_union_core_h5p_renderer extends \core_h5p\output\renderer {
/**
* Add CSS styles when H5P content is displayed in core_h5p.
*
* @param array $styles Styles that will be applied.
* @param array $libraries Libraries that wil be shown.
* @param string $embedtype How the H5P is displayed.
*/
public function h5p_alter_styles(&$styles, $libraries, $embedtype) {
global $CFG;
// Build the H5P CSS file URL.
$h5pcssurl = new core\url('/theme/boost_union/h5p/styles.php');
// Add the CSS file path and a version (to support browser caching) to H5P.
$styles[] = (object) [
'path' => $h5pcssurl->out(),
'version' => '?ver='.theme_get_revision(),
];
// If the local_och5pcore plugin is installed, add some more styles.
if (file_exists($CFG->dirroot.'/local/och5pcore/version.php')) {
// If H5P interactive videos are installed.
if (isset($libraries['H5P.InteractiveVideo']) && $libraries['H5P.InteractiveVideo']['majorVersion'] == '1') {
// Adding H5PEditor css file.
$h5peditoravurl = new core\url('/local/och5pcore/lib/style/H5PEditor.AV.css');
$styles[] = (object) [
'path' => $h5peditoravurl->out(),
'version' => '?ver='.theme_get_revision(),
];
// Adding opencast font css file.
$ocfontsurl = new core\url('/local/och5pcore/lib/style/oc-fonts.css');
$styles[] = (object) [
'path' => $ocfontsurl->out(),
'version' => '?ver='.theme_get_revision(),
];
}
}
}
/**
* Add scripts when an H5P is displayed.
*
* @param array $scripts Scripts that will be applied.
* @param array $libraries Libraries that will be displayed.
* @param string $embedtype How the H5P is displayed.
*/
public function h5p_alter_scripts(&$scripts, $libraries, $embedtype) {
global $CFG;
// If the local_och5pcore plugin is installed, add some more scripts.
if (file_exists($CFG->dirroot.'/local/och5pcore/version.php')) {
// If H5P interactive videos are installed.
if (isset($libraries['H5P.InteractiveVideo']) && $libraries['H5P.InteractiveVideo']['majorVersion'] == '1') {
// Adding LTI related script into scripts array.
$h5prunltiurl = new core\url('/local/och5pcore/lib/js/H5PRunLTI.js');
$scripts[] = (object) [
'path' => $h5prunltiurl->out(),
'version' => '?ver='.theme_get_revision(),
];
// Adding editor script to scripts array.
$h5peditoravurl = new core\url('/local/och5pcore/lib/js/H5PEditor.AV.js');
$scripts[] = (object) [
'path' => $h5peditoravurl->out(),
'version' => '?ver='.theme_get_revision(),
];
}
}
}
}
// Only if mod_hvp is installed.
if (file_exists($CFG->dirroot.'/mod/hvp/renderer.php')) {
// Load the mod_hvp renderer.
require_once($CFG->dirroot.'/mod/hvp/renderer.php');
// If the mod_hvp_renderer exists now.
if (class_exists('mod_hvp_renderer')) {
/**
* Add CSS styles when H5P content is displayed in mod_hvp.
*
* @package theme_boost_union
* @copyright 2022 Nina Herrmann <[email protected]>
* @copyright on behalf of Alexander Bias, lern.link GmbH <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class theme_boost_union_mod_hvp_renderer extends mod_hvp_renderer {
/**
* Add styles when an H5(V)P is displayed.
*
* @param array $styles Styles that will be applied.
* @param array $libraries Libraries that wil be shown.
* @param string $embedtype How the H5P is displayed.
*/
public function hvp_alter_styles(&$styles, $libraries, $embedtype) {
global $CFG;
// Build the H5P CSS file URL.
$h5pcssurl = new core\url('/theme/boost_union/h5p/styles.php');
// Add the CSS file path and a version (to support browser caching) to H5P.
$styles[] = (object)[
'path' => $h5pcssurl->out(),
'version' => '?ver='.theme_get_revision(),
];
// If the local_och5p plugin is installed, add some more styles.
if (file_exists($CFG->dirroot.'/local/och5p/version.php')) {
// If H5P interactive videos are installed.
if (isset($libraries['H5P.InteractiveVideo']) && $libraries['H5P.InteractiveVideo']['majorVersion'] == '1') {
// Adding H5PEditor css file.
$h5peditoravurl = new core\url('/local/och5p/lib/style/H5PEditor.AV.css');
$styles[] = (object) [
'path' => $h5peditoravurl->out(),
'version' => '?ver='.theme_get_revision(),
];
// Adding opencast font css file.
$ocfontsurl = new core\url('/local/och5p/lib/style/oc-fonts.css');
$styles[] = (object) [
'path' => $ocfontsurl->out(),
'version' => '?ver='.theme_get_revision(),
];
}
}
}
/**
* Add scripts when an H5P is displayed.
*
* @param array $scripts Scripts that will be applied.
* @param array $libraries Libraries that will be displayed.
* @param string $embedtype How the H5P is displayed.
*/
public function hvp_alter_scripts(&$scripts, $libraries, $embedtype) {
global $CFG;
// If the local_och5p plugin is installed, add some more scripts.
if (file_exists($CFG->dirroot.'/local/och5p/version.php')) {
// If H5P interactive videos are installed.
if (isset($libraries['H5P.InteractiveVideo']) && $libraries['H5P.InteractiveVideo']['majorVersion'] == '1') {
// Adding LTI related script into scripts array.
$h5prunltiurl = new core\url('/local/och5p/lib/js/H5PRunLTI.js');
$scripts[] = (object) [
'path' => $h5prunltiurl->out(),
'version' => '?ver='.theme_get_revision(),
];
// Adding editor script to scripts array.
$h5peditoravurl = new core\url('/local/och5p/lib/js/H5PEditor.AV.js');
$scripts[] = (object) [
'path' => $h5peditoravurl->out(),
'version' => '?ver='.theme_get_revision(),
];
}
}
}
}
}
}