-
Notifications
You must be signed in to change notification settings - Fork 20
/
OpencastV3.class.php
439 lines (375 loc) · 14.4 KB
/
OpencastV3.class.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
<?php
/**
* OpencastV3.class.php - A course plugin for Stud.IP which includes an opencast player
*/
require_once __DIR__ . '/bootstrap.php';
use Opencast\Models\Helpers;
use Opencast\Models\SeminarSeries;
use Opencast\Models\Videos;
use Opencast\Models\WidgetHelper;
use Opencast\AppFactory;
use Opencast\RouteMap;
use Opencast\VersionHelper;
use Opencast\Providers\Perm;
use Courseware\CoursewarePlugin;
class OpencastV3 extends StudipPlugin implements SystemPlugin, StandardPlugin, CoursewarePlugin, PortalPlugin
{
const GETTEXT_DOMAIN = 'opencast';
public $assetsUrl;
/**
* Initialize a new instance of the plugin.
*/
public function __construct()
{
parent::__construct();
bindtextdomain(static::GETTEXT_DOMAIN, $this->getPluginPath() . '/locale');
bind_textdomain_codeset(static::GETTEXT_DOMAIN, 'UTF-8');
$this->assetsUrl = rtrim($this->getPluginURL(), '/') . '/assets';
if ($GLOBALS['perm']->have_perm('root')) {
$config = new Navigation($this->_('Opencast Einstellungen'), PluginEngine::getURL($this, [], 'admin#/admin'));
if (Navigation::hasItem('/admin/config') && !Navigation::hasItem('/admin/config/oc-config')) {
Navigation::addItem('/admin/config/oc-config', $config);
}
}
if ($GLOBALS['perm']->have_perm('autor') && Helpers::getConfigurationstate()) {
/*
if (!\Config::get()->OPENCAST_MEDIA_ROLES || (
\Config::get()->OPENCAST_MEDIA_ROLES && (
Perm::hasRole('Medienadmin')
|| Perm::hasRole('Medientutor')
|| $GLOBALS['perm']->have_perm('dozent')
)
)) {
*/
// only show main navigation, if media roles are disabled or user has a media role
$videos = new Navigation($this->_('Opencast Videos'));
$videos->setDescription($this->_('Opencast Aufzeichnungen'));
$videos->setImage(Icon::create($this->assetsUrl . '/images/opencast-courseware.svg'));
$videos->setURL(PluginEngine::getURL($this, [], 'contents/index#/contents/videos'));
// use correct navigation for Stud.IP Versions below 5
VersionHelper::get()->addMainNavigation($videos);
// }
}
$this->addStylesheet("assets/css/courseware.scss");
$this->addStylesheet("assets/css/opencast.scss");
VersionHelper::get()->registerCoursewareBlock($this);
}
/**
* Plugin localization for a single string.
* This method supports sprintf()-like execution if you pass additional
* parameters.
*
* @param String $string String to translate
* @return translated string
*/
public function _($string)
{
$result = static::GETTEXT_DOMAIN === null
? $string
: dcgettext(static::GETTEXT_DOMAIN, $string, LC_MESSAGES);
if ($result === $string) {
$result = _($string);
}
if (func_num_args() > 1) {
$arguments = array_slice(func_get_args(), 1);
$result = vsprintf($result, $arguments);
}
return $result;
}
/**
* Plugin localization for plural strings.
* This method supports sprintf()-like execution if you pass additional
* parameters.
*
* @param String $string0 String to translate (singular)
* @param String $string1 String to translate (plural)
* @param mixed $n Quantity factor (may be an array or array-like)
* @return translated string
*/
public function _n($string0, $string1, $n)
{
if (is_array($n)) {
$n = count($n);
}
$result = static::GETTEXT_DOMAIN === null
? $string0
: dngettext(static::GETTEXT_DOMAIN, $string0, $string1, $n);
if ($result === $string0 || $result === $string1) {
$result = ngettext($string0, $string1, $n);
}
if (func_num_args() > 3) {
$arguments = array_slice(func_get_args(), 3);
$result = vsprintf($result, $arguments);
}
return $result;
}
/**
* This method takes care of the Navigation
*
* @param string $course_id
* @param int $last_visit
* @param string $user_id
*/
public function getIconNavigation($course_id, $last_visit, $user_id = null)
{
require_once __DIR__ . '/vendor/autoload.php';
$navigation = new Navigation(
$this->_('Opencast Videos'),
PluginEngine::getURL($this, [], 'course/#/course/videos')
);
$navigation->setImage(Icon::create('opencast'));
// Get number of new videos since last visit
$new_videos = Videos::getNumberOfNewCourseVideos($course_id, $last_visit, $user_id);
if ($new_videos > 0) {
if ($new_videos == 1) {
$text = $this->_('neues Video');
} else {
$text = $this->_('neue Videos');
}
$navigation->setImage(Icon::create('opencast', Icon::ROLE_ATTENTION, [
'title' => $new_videos . ' ' . $text,
]));
$navigation->setBadgeNumber($new_videos);
}
return $navigation;
}
/**
* Return a template (an instance of the Flexi_Template class)
* to be rendered on the course summary page. Return NULL to
* render nothing for this plugin.
*
* The template will automatically get a standard layout, which
* can be configured via attributes set on the template:
*
* title title to display, defaulAppFactoryts to plugin name
* icon_url icon for this plugin (if any)
* admin_url admin link for this plugin (if any)
* admin_title title for admin link (default: Administration)
*
* @return object template object to render or NULL
*/
public function getInfoTemplate($course_id)
{
return null;
}
public function getTabNavigation($course_id)
{
require_once __DIR__ . '/vendor/autoload.php';
if (!$this->isActivated($course_id) || !Helpers::getConfigurationstate()) {
return;
}
$title = 'Opencast Videos';
if (SeminarSeries::getVisibilityForCourse($course_id, true) == 'invisible') {
$title .= " (" . $this->_('versteckt') . ")";
}
$main = new Navigation(
$this->_($title),
PluginEngine::getURL($this, [], 'course#/course/videos')
);
$main->setImage(Icon::create('opencast'));
// We need subnavs in order for responsive view to work properly.
$main->addSubNavigation('videos', new Navigation(
$this->_('Videos'),
PluginEngine::getURL($this, ['target_view' => 'videos'], 'course#/course/videos')
));
if ($GLOBALS['perm']->have_studip_perm('tutor', $course_id) &&
Config::get()->OPENCAST_ALLOW_SCHEDULER &&
Helpers::checkCourseDefaultPlaylist($course_id)) {
$main->addSubNavigation('schedule', new Navigation(
$this->_('Aufzeichnungen planen'),
PluginEngine::getURL($this, ['target_view' => 'schedule'], 'course#/course/schedule')
));
}
return ['opencast' => $main];
}
/**
* return a list of ContentElement-objects, containing
* everything new in this module
*
* @param string $course_id the course-id to get the new stuff for
* @param int $last_visit when was the last time the user visited this module
* @param string $user_id the user to get the notification-objects for
*
* @return array an array of ContentElement-objects
*/
public function getNotificationObjects($course_id, $since, $user_id)
{
return false;
}
/**
* @inherits
*
* Overwrite default metadata-function to return correctly encoded strings
* depending on Stud.IP version
*
* @return array correctly encoded metadata
*/
public function getMetadata()
{
$metadata = parent::getMetadata();
$metadata['pluginname'] = $this->_("Opencast Videos");
$metadata['displayname'] = $this->_("Opencast Videos");
$description = $this->_(
"Mit diesem Tool können Videos aus dem Vorlesungsaufzeichnungssystem "
. "(Opencast) in einer Stud.IP-Veranstaltung angezeigt werden. Die Videos können aus dem eigenen "
. "Videobereich der Veranstaltung hinzugefügt, direkt in der Veranstaltung hochgeladen oder "
. "mit dem Online-Tool Opencast Studio auch direkt selbst erstellt werden. "
. "Auch auch komplette Wiedergabelisten können eingebunden werden. "
);
if (Config::get()->OPENCAST_ALLOW_SCHEDULER) {
$description .= $this->_("Darüberhinaus ist es mit "
. "dieser Integration möglich die komplette Aufzeichnungsplanung für eine Veranstaltung "
. "abzubilden. Voraussetzung hierfür sind entsprechende Einträge im Ablaufplan und eine "
. "gebuchte Ressource mit einem Opencast-Capture-Agent."
);
}
$metadata['description'] = $description;
$metadata['summary'] = $this->_("Videos & Vorlesungsaufzeichnung");
return $metadata;
}
/**
* Return the name of this plugin.
*/
public function getPluginName()
{
return 'Opencast';
}
/**
* Returns whether the plugin may be activated in a certain context.
*
* @param Range $context
* @return bool
*/
public function isActivatableForContext(Range $context)
{
if ($context->getSemType()->getClass()['studygroup_mode']) {
if (\Config::get()->OPENCAST_ALLOW_STUDYGROUP_CONF) {
return true;
}
return false;
}
return true;
}
/**
* {@inheritdoc}
*/
public function perform($unconsumed_path)
{
require_once __DIR__ . '/vendor/autoload.php';
if (substr($unconsumed_path, 0, 3) == 'api') {
// make sure, slim knows if we are running https, see https://github.com/elan-ev/studip-opencast-plugin/issues/816
if (strpos($GLOBALS['ABSOLUTE_URI_STUDIP'], 'https') === 0) {
$_SERVER['HTTPS'] = 'on';
}
$appFactory = new AppFactory();
$app = $appFactory->makeApp($this);
$app->setBasePath(rtrim(PluginEngine::getLink($this, [], null, true), '/'));
$app->group('/api', RouteMap::class);
$app->run();
} else {
$css = VersionHelper::get()->getVersionSpecificStylesheet();
if ($css) {
$this->addStylesheet($css);
}
$trails_root = $this->getPluginPath() . '/app';
$dispatcher = new Trails_Dispatcher(
$trails_root,
rtrim(PluginEngine::getURL($this, null, ''), '/'),
'index'
);
$dispatcher->current_plugin = $this;
$dispatcher->dispatch($unconsumed_path);
}
}
public function getAssetsUrl()
{
return $this->assetsUrl;
}
/**
* Implement this method to register more block types.
*
* You get the current list of block types and must return an updated list
* containing your own block types.
*
* @param array $otherBlockTypes the current list of block types
*
* @return array the updated list of block types
*/
public function registerBlockTypes(array $otherBlockTypes): array
{
$otherBlockTypes[] = OpencastBlockV3::class;
return $otherBlockTypes;
}
/**
* Implement this method to register more container types.
*
* You get the current list of container types and must return an updated list
* containing your own container types.
*
* @param array $otherContainerTypes the current list of container types
*
* @return array the updated list of container types
*/
public function registerContainerTypes(array $otherContainerTypes): array
{
return $otherContainerTypes;
}
/**
* get the plugin manifest from PluginManager getPluginManifest method
*
* @return Array $metadata the manifest metadata of this plugin
*/
public static function getPluginManifestInfo()
{
$plugin_manager = \PluginManager::getInstance();
$this_plugin = $plugin_manager->getPluginInfo(__CLASS__);
$plugin_path = \get_config('PLUGINS_PATH') . '/' .$this_plugin['path'];
$manifest = $plugin_manager->getPluginManifest($plugin_path);
return $manifest;
}
/**
* @inherited
*/
public static function onEnable($plugin_id)
{
// add nobody role to plugin for it to function correctly
foreach (RolePersistence::getAllRoles() as $role) {
if ($role->systemtype && $role->rolename == 'Nobody') {
RolePersistence::assignPluginRoles($plugin_id, [$role->roleid]);
break;
}
}
RolePersistence::expirePluginCache();
}
/**
* Return the template for the widget.
*
* @return Flexi_PhpTemplate The template containing the widget contents
*/
public function getPortalTemplate()
{
global $perm;
// We need to use "nobody" rights for Upload Slides,
// but in here we have to prevent that right,
// in order to not to show the template in login page and so on.
if ('nobody' === $GLOBALS['user']->id) {
return;
}
$template_factory = new Flexi_TemplateFactory(__DIR__ . "/templates");
$template = $template_factory->open("widget.php");
$upcomings = WidgetHelper::getUpcomingLivestreams();
$items['upcomings'] = $upcomings;
$template->set_attribute('items', $items);
$empty_text = $this->_('Derzeit finden keine Livestreams in den gebuchten Kursen statt.');
if ($perm->have_perm('admin') || $perm->have_perm('root')) {
$empty_text = $this->_('Um Leistungsprobleme zu vermeiden, ist diese Funktion für Administratoren dauerhaft deaktiviert.');
}
$texts = [
'empty' => $empty_text,
'upcomings' => $this->_('Kommende Liveevents'),
'code' => $code
];
$template->set_attribute('texts', $texts);
return $template;
}
}