Completed
Pull Request — master (#44)
by Jesus
02:39 queued 13s
created

lib.php ➔ bigbluebuttonbn_supports()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 17
nc 3
nop 1
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
17
/**
18
 * Library calls for Moodle and BigBlueButton.
19
 *
20
 * @package   mod_bigbluebuttonbn
21
 * @copyright 2010-2017 Blindside Networks Inc
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later
23
 * @author    Jesus Federico  (jesus [at] blindsidenetworks [dt] com)
24
 * @author    Fred Dixon  (ffdixon [at] blindsidenetworks [dt] com)
25
 */
26
27
defined('MOODLE_INTERNAL') || die;
28
29
global $CFG;
30
31
require_once($CFG->dirroot.'/calendar/lib.php');
32
require_once($CFG->dirroot.'/message/lib.php');
33
require_once($CFG->dirroot.'/mod/lti/OAuth.php');
34
require_once($CFG->libdir.'/accesslib.php');
35
require_once($CFG->libdir.'/completionlib.php');
36
require_once($CFG->libdir.'/datalib.php');
37
require_once($CFG->libdir.'/coursecatlib.php');
38
require_once($CFG->libdir.'/enrollib.php');
39
require_once($CFG->libdir.'/filelib.php');
40
require_once($CFG->libdir.'/formslib.php');
41
42
if (file_exists(dirname(__FILE__).'/vendor/firebase/php-jwt/src/JWT.php')) {
43
    require_once(dirname(__FILE__).'/vendor/firebase/php-jwt/src/JWT.php');
44
}
45
46
if (!isset($CFG->bigbluebuttonbn)) {
47
    $CFG->bigbluebuttonbn = array();
48
}
49
50
if (file_exists(dirname(__FILE__).'/config.php')) {
51
    require_once(dirname(__FILE__).'/config.php');
52
    // Old BigBlueButtonBN cfg schema. For backward compatibility.
53
    global $BIGBLUEBUTTONBN_CFG;
54
55
    if (isset($BIGBLUEBUTTONBN_CFG)) {
56
        foreach ((array) $BIGBLUEBUTTONBN_CFG as $key => $value) {
57
            $cfgkey = str_replace("bigbluebuttonbn_", "", $key);
58
            $CFG->bigbluebuttonbn[$cfgkey] = $value;
59
        }
60
    }
61
}
62
63
/*
64
 * DURATIONCOMPENSATION: Feature removed by configuration
65
 */
66
$CFG->bigbluebuttonbn['scheduled_duration_enabled'] = 0;
67
/*
68
 * Remove this block when restored
69
 */
70
71
 /** @var BIGBLUEBUTTONBN_DEFAULT_SERVER_URL string of default bigbluebutton server url */
72
const BIGBLUEBUTTONBN_DEFAULT_SERVER_URL = 'http://test-install.blindsidenetworks.com/bigbluebutton/';
73
/** @var BIGBLUEBUTTONBN_DEFAULT_SHARED_SECRET string of default bigbluebutton server shared secret */
74
const BIGBLUEBUTTONBN_DEFAULT_SHARED_SECRET = '8cd8ef52e8e101574e400365b55e11a6';
75
/** @var BIGBLUEBUTTONBN_LOG_EVENT_CREATE string of event create for bigbluebuttonbn_logs */
76
const BIGBLUEBUTTONBN_LOG_EVENT_CREATE = 'Create';
77
/** @var BIGBLUEBUTTONBN_LOG_EVENT_JOIN string of event join for bigbluebuttonbn_logs */
78
const BIGBLUEBUTTONBN_LOG_EVENT_JOIN = 'Join';
79
/** @var BIGBLUEBUTTONBN_LOG_EVENT_LOGOUT string of event logout for bigbluebuttonbn_logs */
80
const BIGBLUEBUTTONBN_LOG_EVENT_LOGOUT = 'Logout';
81
/** @var BIGBLUEBUTTONBN_LOG_EVENT_IMPORT string of event import for bigbluebuttonbn_logs */
82
const BIGBLUEBUTTONBN_LOG_EVENT_IMPORT = 'Import';
83
/** @var BIGBLUEBUTTONBN_LOG_EVENT_DELETE string of event delete for bigbluebuttonbn_logs */
84
const BIGBLUEBUTTONBN_LOG_EVENT_DELETE = 'Delete';
85
86
/**
87
 * Indicates API features that the forum supports.
88
 *
89
 * @uses FEATURE_IDNUMBER
90
 * @uses FEATURE_GROUPS
91
 * @uses FEATURE_GROUPINGS
92
 * @uses FEATURE_GROUPMEMBERSONLY
93
 * @uses FEATURE_MOD_INTRO
94
 * @uses FEATURE_BACKUP_MOODLE2
95
 * @uses FEATURE_COMPLETION_TRACKS_VIEWS
96
 * @uses FEATURE_GRADE_HAS_GRADE
97
 * @uses FEATURE_GRADE_OUTCOMES
98
 * @uses FEATURE_SHOW_DESCRIPTION
99
 * @param string $feature
100
 * @return mixed True if yes (some features may use other values)
101
 */
102
function bigbluebuttonbn_supports($feature) {
103
    if (!$feature) {
104
        return null;
105
    }
106
    $features = array(
107
        (string) FEATURE_IDNUMBER => true,
108
        (string) FEATURE_GROUPS => true,
109
        (string) FEATURE_GROUPINGS => true,
110
        (string) FEATURE_GROUPMEMBERSONLY => true,
111
        (string) FEATURE_MOD_INTRO => true,
112
        (string) FEATURE_BACKUP_MOODLE2 => true,
113
        (string) FEATURE_COMPLETION_TRACKS_VIEWS => true,
114
        (string) FEATURE_GRADE_HAS_GRADE => false,
115
        (string) FEATURE_GRADE_OUTCOMES => false,
116
        (string) FEATURE_SHOW_DESCRIPTION => true,
117
    );
118
    if (isset($features[(string) $feature])) {
119
        return $features[$feature];
120
    }
121
    return null;
122
}
123
124
/**
125
 * Given an object containing all the necessary data,
126
 * (defined by the form in mod_form.php) this function
127
 * will create a new instance and return the id number
128
 * of the new instance.
129
 *
130
 * @param object $data  An object from the form in mod_form.php
131
 * @return int The id of the newly inserted bigbluebuttonbn record
132
 */
133
function bigbluebuttonbn_add_instance($data) {
134
    global $DB;
135
    // Excecute preprocess.
136
    bigbluebuttonbn_process_pre_save($data);
137
    // Pre-set initial values.
138
    $data->presentation = bigbluebuttonbn_get_media_file($data);
139
    // Insert a record.
140
    $data->id = $DB->insert_record('bigbluebuttonbn', $data);
141
    // Encode meetingid.
142
    $meetingid = bigbluebuttonbn_encode_meetingid($data->id);
143
    // Set the meetingid column in the bigbluebuttonbn table.
144
    $DB->set_field('bigbluebuttonbn', 'meetingid', $meetingid, array('id' => $data->id));
145
    // Complete the process.
146
    bigbluebuttonbn_process_post_save($data);
147
    return $data->id;
148
}
149
150
/**
151
 * Given an object containing all the necessary data,
152
 * (defined by the form in mod_form.php) this function
153
 * will update an existing instance with new data.
154
 *
155
 * @param object $data  An object from the form in mod_form.php
156
 * @return bool Success/Fail
157
 */
158
function bigbluebuttonbn_update_instance($data) {
159
    global $DB;
160
    // Excecute preprocess.
161
    bigbluebuttonbn_process_pre_save($data);
162
    // Pre-set initial values.
163
    $data->id = $data->instance;
164
    $data->presentation = bigbluebuttonbn_get_media_file($data);
165
    // Update a record.
166
    $DB->update_record('bigbluebuttonbn', $data);
167
    // Complete the process.
168
    bigbluebuttonbn_process_post_save($data);
169
    return true;
170
}
171
172
/**
173
 * Given an ID of an instance of this module,
174
 * this function will permanently delete the instance
175
 * and any data that depends on it.
176
 *
177
 * @param int $id Id of the module instance
178
 *
179
 * @return bool Success/Failure
180
 */
181
function bigbluebuttonbn_delete_instance($id) {
182
    global $DB;
183
    $bigbluebuttonbn = $DB->get_record('bigbluebuttonbn', array('id' => $id));
184
    if (!$bigbluebuttonbn) {
185
        return false;
186
    }
187
    // TODO: End the meeting if it is running.
188
189
    // Perform delete.
190
    if (!$DB->delete_records('bigbluebuttonbn', array('id' => $bigbluebuttonbn->id))) {
191
        return false;
192
    }
193
    if (!$DB->delete_records('event', array('modulename' => 'bigbluebuttonbn', 'instance' => $bigbluebuttonbn->id))) {
194
        return false;
195
    }
196
    // Log action performed.
197
    return bigbluebuttonbn_delete_instance_log($bigbluebuttonbn);
198
}
199
200
/**
201
 * Given an ID of an instance of this module,
202
 * this function will permanently delete the data that depends on it.
203
 *
204
 * @param object $bigbluebuttonbn Id of the module instance
205
 *
206
 * @return bool Success/Failure
207
 */
208
function bigbluebuttonbn_delete_instance_log($bigbluebuttonbn) {
209
    global $DB, $USER;
210
    $log = new stdClass();
211
    $log->meetingid = $bigbluebuttonbn->meetingid;
212
    $log->courseid = $bigbluebuttonbn->course;
213
    $log->bigbluebuttonbnid = $bigbluebuttonbn->id;
214
    $log->userid = $USER->id;
215
    $log->timecreated = time();
216
    $log->log = BIGBLUEBUTTONBN_LOG_EVENT_DELETE;
217
    $sql  = "SELECT * FROM {bigbluebuttonbn_logs} ";
218
    $sql .= "WHERE bigbluebuttonbnid = ? AND log = ? AND ". $DB->sql_compare_text('meta') . " = ?";
219
    $logs = $DB->get_records_sql($sql, array($bigbluebuttonbn->id, BIGBLUEBUTTONBN_LOG_EVENT_CREATE, "{\"record\":true}"));
220
    $log->meta = "{\"has_recordings\":false}";
221
    if (!empty($logs)) {
222
        $log->meta = "{\"has_recordings\":true}";
223
    }
224
    if (!$DB->insert_record('bigbluebuttonbn_logs', $log)) {
225
        return false;
226
    }
227
    return true;
228
}
229
230
/**
231
 * Return a small object with summary information about what a
232
 * user has done with a given particular instance of this module
233
 * Used for user activity reports.
234
 * $return->time = the time they did it
235
 * $return->info = a short text description.
236
 *
237
 * @param object $course
238
 * @param object $user
239
 * @param object $mod
240
 * @param object $bigbluebuttonbn
241
 *
242
 * @return bool
243
 */
244
function bigbluebuttonbn_user_outline($course, $user, $mod, $bigbluebuttonbn) {
0 ignored issues
show
Unused Code introduced by
The parameter $mod is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
245
    global $DB;
246
    $completed = $DB->count_records('bigbluebuttonbn_logs', array('courseid' => $course->id,
247
        'bigbluebuttonbnid' => $bigbluebuttonbn->id, 'userid' => $user->id, 'log' => 'Join', ), '*');
248
    if ($completed > 0) {
249
        return fullname($user).' '.get_string('view_message_has_joined', 'bigbluebuttonbn').' '.
250
            get_string('view_message_session_for', 'bigbluebuttonbn').' '.(string) $completed.' '.
251
            get_string('view_message_times', 'bigbluebuttonbn');
252
    }
253
    return '';
254
}
255
256
/**
257
 * Print a detailed representation of what a user has done with
258
 * a given particular instance of this module, for user activity reports.
259
 *
260
 * @param object $course
261
 * @param object $user
262
 * @param object $mod
263
 * @param object $bigbluebuttonbn
264
 *
265
 * @return bool
266
 */
267
function bigbluebuttonbn_user_complete($course, $user, $mod, $bigbluebuttonbn) {
0 ignored issues
show
Unused Code introduced by
The parameter $mod is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
268
    global $DB;
269
    $completed = $DB->count_records('bigbluebuttonbn_logs', array('courseid' => $course->id,
270
        'bigbluebuttonbnid' => $bigbluebuttonbn->id, 'userid' => $user->id, 'log' => 'Join', ),
271
        '*', IGNORE_MULTIPLE);
272
    return $completed > 0;
273
}
274
275
/**
276
 * Returns all other caps used in module.
277
 *
278
 * @return string[]
279
 */
280
function bigbluebuttonbn_get_extra_capabilities() {
281
    return array('moodle/site:accessallgroups');
282
}
283
284
/**
285
 * List of view style log actions.
286
 *
287
 * @return string[]
288
 */
289
function bigbluebuttonbn_get_view_actions() {
290
    return array('view', 'view all');
291
}
292
293
/**
294
 * List of update style log actions.
295
 *
296
 * @return string[]
297
 */
298
function bigbluebuttonbn_get_post_actions() {
299
    return array('update', 'add', 'create', 'join', 'end', 'left', 'publish', 'unpublish', 'delete');
300
}
301
302
/**
303
 * Print an overview of all bigbluebuttonbn instances for the courses.
304
 *
305
 * @param array $courses
306
 * @param array $htmlarray Passed by reference
307
 *
308
 * @return void
309
 */
310
function bigbluebuttonbn_print_overview($courses, &$htmlarray) {
311
    if (empty($courses) || !is_array($courses)) {
312
        return array();
313
    }
314
    $bns = get_all_instances_in_courses('bigbluebuttonbn', $courses);
315
    foreach ($bns as $bn) {
316
        $now = time();
317
        if ($bn->openingtime and (!$bn->closingtime or $bn->closingtime > $now)) {
318
            // A bigbluebuttonbn is scheduled.
319
            if (empty($htmlarray[$bn->course]['bigbluebuttonbn'])) {
320
                $htmlarray[$bn->course]['bigbluebuttonbn'] = '';
321
            }
322
            $htmlarray[$bn->course]['bigbluebuttonbn'] = bigbluebuttonbn_print_overview_element($bn, $now);
323
        }
324
    }
325
}
326
327
/**
328
 * Print an overview of a bigbluebuttonbn instance.
329
 *
330
 * @param array $bigbluebuttonbn
331
 * @param int $now
332
 *
333
 * @return string
334
 */
335
function bigbluebuttonbn_print_overview_element($bigbluebuttonbn, $now) {
336
    global $CFG;
337
    $start = 'started_at';
338
    if ($bigbluebuttonbn->openingtime > $now) {
339
        $start = 'starts_at';
340
    }
341
    $classes = '';
342
    if ($bigbluebuttonbn->visible) {
343
        $classes = 'class="dimmed" ';
344
    }
345
    $str  = '<div class="bigbluebuttonbn overview">'."\n";
346
    $str .= '  <div class="name">'.get_string('modulename', 'bigbluebuttonbn').':&nbsp;'."\n";
347
    $str .= '    <a '.$classes.'href="'.$CFG->wwwroot.'/mod/bigbluebuttonbn/view.php?id='.$bigbluebuttonbn->coursemodule.
348
      '">'.$bigbluebuttonbn->name.'</a>'."\n";
349
    $str .= '  </div>'."\n";
350
    $str .= '  <div class="info">'.get_string($start, 'bigbluebuttonbn').': '.userdate($bigbluebuttonbn->openingtime).
351
        '</div>'."\n";
352
    $str .= '  <div class="info">'.get_string('ends_at', 'bigbluebuttonbn').': '.userdate($bigbluebuttonbn->closingtime)
353
      .'</div>'."\n";
354
    $str .= '</div>'."\n";
355
    return $str;
356
}
357
358
/**
359
 * Given a course_module object, this function returns any
360
 * "extra" information that may be needed when printing
361
 * this activity in a course listing.
362
 * See get_array_of_activities() in course/lib.php.
363
 *
364
 * @param object $coursemodule
365
 *
366
 * @return null|cached_cm_info
367
 */
368
function bigbluebuttonbn_get_coursemodule_info($coursemodule) {
369
    global $DB;
370
    $bigbluebuttonbn = $DB->get_record('bigbluebuttonbn', array('id' => $coursemodule->instance),
371
        'id, name, intro, introformat');
372
    if (!$bigbluebuttonbn) {
373
        return null;
374
    }
375
    $info = new cached_cm_info();
376
    $info->name = $bigbluebuttonbn->name;
377
    if ($coursemodule->showdescription) {
378
        // Convert intro to html. Do not filter cached version, filters run at display time.
379
        $info->content = format_module_intro('bigbluebuttonbn', $bigbluebuttonbn, $coursemodule->id, false);
380
    }
381
    return $info;
382
}
383
384
/**
385
 * Runs any processes that must run before a bigbluebuttonbn insert/update.
386
 *
387
 * @param object $bigbluebuttonbn BigBlueButtonBN form data
388
 *
389
 * @return void
390
 **/
391
function bigbluebuttonbn_process_pre_save(&$bigbluebuttonbn) {
392
    $bigbluebuttonbn->timemodified = time();
393
    if ((integer)$bigbluebuttonbn->instance == 0) {
394
        $bigbluebuttonbn->timecreated = time();
395
        $bigbluebuttonbn->timemodified = 0;
396
        // As it is a new activity, assign passwords.
397
        $bigbluebuttonbn->moderatorpass = bigbluebuttonbn_random_password(12);
398
        $bigbluebuttonbn->viewerpass = bigbluebuttonbn_random_password(12, $bigbluebuttonbn->moderatorpass);
399
    }
400
    if (!isset($bigbluebuttonbn->wait)) {
401
        $bigbluebuttonbn->wait = 0;
402
    }
403
    if (!isset($bigbluebuttonbn->record)) {
404
        $bigbluebuttonbn->record = 0;
405
    }
406
    if (!isset($bigbluebuttonbn->recordings_html)) {
407
        $bigbluebuttonbn->recordings_html = 0;
408
    }
409
    if (!isset($bigbluebuttonbn->recordings_deleted)) {
410
        $bigbluebuttonbn->recordings_deleted = 0;
411
    }
412
    if (!isset($bigbluebuttonbn->recordings_imported)) {
413
        $bigbluebuttonbn->recordings_imported = 0;
414
    }
415
    $bigbluebuttonbn->participants = htmlspecialchars_decode($bigbluebuttonbn->participants);
416
}
417
418
/**
419
 * Runs any processes that must be run after a bigbluebuttonbn insert/update.
420
 *
421
 * @param object $bigbluebuttonbn BigBlueButtonBN form data
422
 *
423
 * @return void
424
 **/
425
function bigbluebuttonbn_process_post_save(&$bigbluebuttonbn) {
426
    if (isset($bigbluebuttonbn->notification) && $bigbluebuttonbn->notification) {
427
        bigbluebuttonbn_process_post_save_notification($bigbluebuttonbn);
428
    }
429
    bigbluebuttonbn_process_post_save_event($bigbluebuttonbn);
430
}
431
432
/**
433
 * Generates a message on insert/update which is sent to all users enrolled.
434
 *
435
 * @param object $bigbluebuttonbn BigBlueButtonBN form data
436
 *
437
 * @return void
438
 **/
439
function bigbluebuttonbn_process_post_save_notification(&$bigbluebuttonbn) {
440
    $action = get_string('mod_form_field_notification_msg_modified', 'bigbluebuttonbn');
441
    if (isset($bigbluebuttonbn->add) && !empty($bigbluebuttonbn->add)) {
442
        $action = get_string('mod_form_field_notification_msg_created', 'bigbluebuttonbn');
443
    }
444
    $context = context_course::instance($bigbluebuttonbn->course);
445
    \mod_bigbluebuttonbn\locallib\notifier::notification_process($context, $bigbluebuttonbn, $action);
446
}
447
448
/**
449
 * Generates an event after a bigbluebuttonbn insert/update.
450
 *
451
 * @param object $bigbluebuttonbn BigBlueButtonBN form data
452
 *
453
 * @return void
454
 **/
455
function bigbluebuttonbn_process_post_save_event(&$bigbluebuttonbn) {
456
    global $DB;
457
    // Delete evento to the calendar when/if openingtime is NOT set.
458
    if (!isset($bigbluebuttonbn->openingtime) || !$bigbluebuttonbn->openingtime) {
459
        $DB->delete_records('event', array('modulename' => 'bigbluebuttonbn', 'instance' => $bigbluebuttonbn->id));
460
        return;
461
    }
462
    // Add evento to the calendar as openingtime is set.
463
    $event = new stdClass();
464
    $event->name = $bigbluebuttonbn->name;
465
    $event->courseid = $bigbluebuttonbn->course;
466
    $event->groupid = 0;
467
    $event->userid = 0;
468
    $event->modulename = 'bigbluebuttonbn';
469
    $event->instance = $bigbluebuttonbn->id;
470
    $event->timestart = $bigbluebuttonbn->openingtime;
471
    $event->durationtime = 0;
472
    if ($bigbluebuttonbn->closingtime) {
473
        $event->durationtime = $bigbluebuttonbn->closingtime - $bigbluebuttonbn->openingtime;
474
    }
475
    $event->id = $DB->get_field('event', 'id', array('modulename' => 'bigbluebuttonbn',
476
        'instance' => $bigbluebuttonbn->id));
477
    if ($event->id) {
478
        $calendarevent = calendar_event::load($event->id);
479
        $calendarevent->update($event);
480
        return;
481
    }
482
    calendar_event::create($event);
483
}
484
485
/**
486
 * Get a full path to the file attached as a preuploaded presentation
487
 * or if there is none, set the presentation field will be set to blank.
488
 *
489
 * @param object $bigbluebuttonbn BigBlueButtonBN form data
490
 *
491
 * @return string
492
 */
493
function bigbluebuttonbn_get_media_file(&$bigbluebuttonbn) {
494
    $draftitemid = isset($bigbluebuttonbn->presentation) ? $bigbluebuttonbn->presentation : null;
495
    $context = context_module::instance($bigbluebuttonbn->coursemodule);
496
    // Set the filestorage object.
497
    $fs = get_file_storage();
498
    // Save the file if it exists that is currently in the draft area.
499
    file_save_draft_area_files($draftitemid, $context->id, 'mod_bigbluebuttonbn', 'presentation', 0);
500
    // Get the file if it exists.
501
    $files = $fs->get_area_files($context->id, 'mod_bigbluebuttonbn', 'presentation', 0,
502
        'itemid, filepath, filename', false);
503
    // Check that there is a file to process.
504
    $filesrc = '';
505
    if (count($files) == 1) {
506
        // Get the first (and only) file.
507
        $file = reset($files);
508
        $filesrc = '/'.$file->get_filename();
509
    }
510
    return $filesrc;
511
}
512
513
/**
514
 * Serves the bigbluebuttonbn attachments. Implements needed access control ;-).
515
 *
516
 * @category files
517
 *
518
 * @param stdClass $course        course object
519
 * @param stdClass $cm            course module object
520
 * @param stdClass $context       context object
521
 * @param string   $filearea      file area
522
 * @param array    $args          extra arguments
523
 * @param bool     $forcedownload whether or not force download
524
 * @param array    $options       additional options affecting the file serving
525
 *
526
 * @return false|null false if file not found, does not return if found - justsend the file
527
 */
528
function bigbluebuttonbn_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
529
    if (!bigbluebuttonbn_pluginfile_valid($context, $filearea)) {
530
        return false;
531
    }
532
    $file = bigbluebuttonbn_pluginfile_file($course, $cm, $context, $filearea, $args);
533
    if (!$file) {
534
        return false;
535
    }
536
    // Finally send the file.
537
    send_stored_file($file, 0, 0, $forcedownload, $options); // download MUST be forced - security!
538
}
539
540
/**
541
 * Helper for validating pluginfile.
542
 * @param stdClass $context       context object
543
 * @param string   $filearea      file area
544
 *
545
 * @return false|null false if file not valid
546
 */
547
function bigbluebuttonbn_pluginfile_valid($context, $filearea) {
548
    if ($context->contextlevel != CONTEXT_MODULE) {
549
        return false;
550
    }
551
    if ($filearea !== 'presentation') {
552
        return false;
553
    }
554
    if (!array_key_exists($filearea, bigbluebuttonbn_get_file_areas())) {
555
        return false;
556
    }
557
    return true;
558
}
559
560
/**
561
 * Helper for getting pluginfile.
562
 *
563
 * @param stdClass $course        course object
564
 * @param stdClass $cm            course module object
565
 * @param stdClass $context       context object
566
 * @param string   $filearea      file area
567
 * @param array    $args          extra arguments
568
 *
569
 * @return object
570
 */
571
function bigbluebuttonbn_pluginfile_file($course, $cm, $context, $filearea, $args) {
572
    $filename = bigbluebuttonbn_pluginfile_filename($course, $cm, $context, $args);
573
    if (!$filename) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $filename of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
574
        return false;
575
    }
576
    $fullpath = "/$context->id/mod_bigbluebuttonbn/$filearea/0/".$filename;
577
    $fs = get_file_storage();
578
    $file = $fs->get_file_by_hash(sha1($fullpath));
579
    if (!$file || $file->is_directory()) {
580
        return false;
581
    }
582
    return $file;
583
}
584
585
/**
586
 * Helper for getting pluginfile name.
587
 *
588
 * @param stdClass $course        course object
589
 * @param stdClass $cm            course module object
590
 * @param stdClass $context       context object
591
 * @param array    $args          extra arguments
592
 *
593
 * @return array
594
 */
595
function bigbluebuttonbn_pluginfile_filename($course, $cm, $context, $args) {
596
    global $DB;
597
    if (count($args) > 1) {
598
        if (!$bigbluebuttonbn = $DB->get_record('bigbluebuttonbn', array('id' => $cm->instance))) {
599
            return;
600
        }
601
        $cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'mod_bigbluebuttonbn', 'presentation_cache');
602
        $noncekey = sha1($bigbluebuttonbn->id);
603
        $presentationnonce = $cache->get($noncekey);
604
        $noncevalue = $presentationnonce['value'];
605
        $noncecounter = $presentationnonce['counter'];
606
        if ($args['0'] != $noncevalue) {
607
            return;
608
        }
609
        // The nonce value is actually used twice because BigBlueButton reads the file two times.
610
        $noncecounter += 1;
611
        $cache->set($noncekey, array('value' => $noncevalue, 'counter' => $noncecounter));
612
        if ($noncecounter == 2) {
613
            $cache->delete($noncekey);
614
        }
615
        return $args['1'];
616
    }
617
    require_course_login($course, true, $cm);
618
    if (!has_capability('mod/bigbluebuttonbn:join', $context)) {
619
        return;
620
    }
621
    return implode('/', $args);
622
}
623
624
/**
625
 * Returns an array of file areas.
626
 *
627
 * @category files
628
 *
629
 * @return array a list of available file areas
630
 */
631
function bigbluebuttonbn_get_file_areas() {
632
    $areas = array();
633
    $areas['presentation'] = get_string('mod_form_block_presentation', 'bigbluebuttonbn');
634
    return $areas;
635
}
636
637
/**
638
 * Get icon mapping for font-awesome.
639
 */
640
function mod_bigbluebuttonbn_get_fontawesome_icon_map() {
641
    return [
642
        'mod_bigbluebuttonbn:i/bigbluebutton' => 'fa-bigbluebutton',
643
    ];
644
}
645