| 1 |
efrain |
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 |
namespace tiny_recordrtc;
|
|
|
18 |
|
|
|
19 |
use context;
|
|
|
20 |
use editor_tiny\editor;
|
|
|
21 |
use editor_tiny\plugin;
|
|
|
22 |
use editor_tiny\plugin_with_buttons;
|
|
|
23 |
use editor_tiny\plugin_with_configuration;
|
| 1441 |
ariadna |
24 |
use editor_tiny\plugin_with_configuration_for_external;
|
| 1 |
efrain |
25 |
use editor_tiny\plugin_with_menuitems;
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* Tiny RecordRTC plugin.
|
|
|
29 |
*
|
|
|
30 |
* @package tiny_recordrtc
|
|
|
31 |
* @copyright 2022 Stevani Andolo <stevani@hotmail.com.au>
|
|
|
32 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
33 |
*/
|
| 1441 |
ariadna |
34 |
class plugininfo extends plugin implements
|
|
|
35 |
plugin_with_buttons,
|
|
|
36 |
plugin_with_menuitems,
|
|
|
37 |
plugin_with_configuration,
|
|
|
38 |
plugin_with_configuration_for_external {
|
|
|
39 |
|
|
|
40 |
#[\Override]
|
| 1 |
efrain |
41 |
public static function is_enabled(
|
|
|
42 |
context $context,
|
|
|
43 |
array $options,
|
|
|
44 |
array $fpoptions,
|
|
|
45 |
?editor $editor = null
|
|
|
46 |
): bool {
|
|
|
47 |
// Disabled if:
|
|
|
48 |
// - Not logged in or guest.
|
|
|
49 |
// - Files are not allowed.
|
| 1441 |
ariadna |
50 |
// - Doesn't have the correct capability.
|
| 1 |
efrain |
51 |
$canhavefiles = !empty($options['maxfiles']);
|
| 1441 |
ariadna |
52 |
return isloggedin() && !isguestuser() && $canhavefiles && has_capability('tiny/recordrtc:use', $context);
|
| 1 |
efrain |
53 |
}
|
|
|
54 |
|
| 1441 |
ariadna |
55 |
#[\Override]
|
|
|
56 |
public static function is_enabled_for_external(context $context, array $options): bool {
|
|
|
57 |
// Assume files are allowed.
|
|
|
58 |
$options['maxfiles'] = 1;
|
|
|
59 |
return self::is_enabled($context, $options, []);
|
|
|
60 |
}
|
|
|
61 |
|
| 1 |
efrain |
62 |
public static function get_available_buttons(): array {
|
|
|
63 |
return [
|
|
|
64 |
'tiny_recordrtc/tiny_recordrtc_image',
|
|
|
65 |
];
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
public static function get_available_menuitems(): array {
|
|
|
69 |
return [
|
|
|
70 |
'tiny_recordrtc/tiny_recordrtc_image',
|
|
|
71 |
];
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
public static function get_plugin_configuration_for_context(
|
|
|
75 |
context $context,
|
|
|
76 |
array $options,
|
|
|
77 |
array $fpoptions,
|
|
|
78 |
?editor $editor = null
|
|
|
79 |
): array {
|
|
|
80 |
$sesskey = sesskey();
|
| 1441 |
ariadna |
81 |
$allowedtypes = explode(',', get_config('tiny_recordrtc', 'allowedtypes'));
|
| 1 |
efrain |
82 |
$audiobitrate = get_config('tiny_recordrtc', 'audiobitrate');
|
|
|
83 |
$videobitrate = get_config('tiny_recordrtc', 'videobitrate');
|
| 1441 |
ariadna |
84 |
$screenbitrate = get_config('tiny_recordrtc', 'screenbitrate');
|
| 1 |
efrain |
85 |
$audiotimelimit = get_config('tiny_recordrtc', 'audiotimelimit');
|
|
|
86 |
$videotimelimit = get_config('tiny_recordrtc', 'videotimelimit');
|
| 1441 |
ariadna |
87 |
$screentimelimit = get_config('tiny_recordrtc', 'screentimelimit');
|
|
|
88 |
[$videoscreenwidth, $videoscreenheight] = explode(',', get_config('tiny_recordrtc', 'screensize'));
|
|
|
89 |
$audiortcformat = (int) get_config('tiny_recordrtc', 'audiortcformat');
|
| 1 |
efrain |
90 |
|
|
|
91 |
// Update $allowedtypes to account for capabilities.
|
| 1441 |
ariadna |
92 |
$audioallowed = false;
|
|
|
93 |
$videoallowed = false;
|
|
|
94 |
$screenallowed = false;
|
|
|
95 |
$allowedpausing = (bool) get_config('tiny_recordrtc', 'allowedpausing');
|
|
|
96 |
foreach ($allowedtypes as $value) {
|
|
|
97 |
switch ($value) {
|
|
|
98 |
case constants::TINYRECORDRTC_AUDIO_TYPE:
|
|
|
99 |
if (has_capability('tiny/recordrtc:recordaudio', $context)) {
|
|
|
100 |
$audioallowed = true;
|
|
|
101 |
}
|
|
|
102 |
break;
|
|
|
103 |
case constants::TINYRECORDRTC_VIDEO_TYPE:
|
|
|
104 |
if (has_capability('tiny/recordrtc:recordvideo', $context)) {
|
|
|
105 |
$videoallowed = true;
|
|
|
106 |
}
|
|
|
107 |
break;
|
|
|
108 |
case constants::TINYRECORDRTC_SCREEN_TYPE:
|
|
|
109 |
if (has_capability('tiny/recordrtc:recordscreen', $context)) {
|
|
|
110 |
$screenallowed = true;
|
|
|
111 |
}
|
|
|
112 |
break;
|
|
|
113 |
default:
|
|
|
114 |
break;
|
|
|
115 |
}
|
| 1 |
efrain |
116 |
}
|
|
|
117 |
|
|
|
118 |
$maxrecsize = get_max_upload_file_size();
|
|
|
119 |
if (!empty($options['maxbytes'])) {
|
|
|
120 |
$maxrecsize = min($maxrecsize, $options['maxbytes']);
|
|
|
121 |
}
|
|
|
122 |
$params = [
|
|
|
123 |
'contextid' => $context->id,
|
|
|
124 |
'sesskey' => $sesskey,
|
|
|
125 |
'allowedtypes' => $allowedtypes,
|
|
|
126 |
'audiobitrate' => $audiobitrate,
|
|
|
127 |
'videobitrate' => $videobitrate,
|
| 1441 |
ariadna |
128 |
'screenbitrate' => $screenbitrate,
|
| 1 |
efrain |
129 |
'audiotimelimit' => $audiotimelimit,
|
|
|
130 |
'videotimelimit' => $videotimelimit,
|
| 1441 |
ariadna |
131 |
'screentimelimit' => $screentimelimit,
|
|
|
132 |
'maxrecsize' => $maxrecsize,
|
|
|
133 |
'videoscreenwidth' => $videoscreenwidth,
|
|
|
134 |
'videoscreenheight' => $videoscreenheight,
|
|
|
135 |
'audiortcformat' => $audiortcformat,
|
| 1 |
efrain |
136 |
];
|
|
|
137 |
|
|
|
138 |
$data = [
|
|
|
139 |
'params' => $params,
|
|
|
140 |
'fpoptions' => $fpoptions
|
|
|
141 |
];
|
|
|
142 |
|
|
|
143 |
return [
|
|
|
144 |
'data' => $data,
|
|
|
145 |
'videoAllowed' => $videoallowed,
|
|
|
146 |
'audioAllowed' => $audioallowed,
|
| 1441 |
ariadna |
147 |
'screenAllowed' => $screenallowed,
|
|
|
148 |
'pausingAllowed' => $allowedpausing,
|
| 1 |
efrain |
149 |
];
|
|
|
150 |
}
|
| 1441 |
ariadna |
151 |
|
|
|
152 |
#[\Override]
|
|
|
153 |
public static function get_plugin_configuration_for_external(context $context): array {
|
|
|
154 |
$settings = self::get_plugin_configuration_for_context($context, [], []);
|
|
|
155 |
return [
|
|
|
156 |
'videoallowed' => $settings['videoAllowed'] ? '1' : '0',
|
|
|
157 |
'audioallowed' => $settings['audioAllowed'] ? '1' : '0',
|
|
|
158 |
'screenallowed' => $settings['screenAllowed'] ? '1' : '0',
|
|
|
159 |
'pausingallowed' => $settings['pausingAllowed'] ? '1' : '0',
|
|
|
160 |
'allowedtypes' => implode(',', $settings['data']['params']['allowedtypes']),
|
|
|
161 |
'audiobitrate' => $settings['data']['params']['audiobitrate'],
|
|
|
162 |
'videobitrate' => $settings['data']['params']['videobitrate'],
|
|
|
163 |
'screenbitrate' => $settings['data']['params']['screenbitrate'],
|
|
|
164 |
'audiotimelimit' => $settings['data']['params']['audiotimelimit'],
|
|
|
165 |
'videotimelimit' => $settings['data']['params']['videotimelimit'],
|
|
|
166 |
'screentimelimit' => $settings['data']['params']['screentimelimit'],
|
|
|
167 |
'maxrecsize' => (string) $settings['data']['params']['maxrecsize'],
|
|
|
168 |
'videoscreenwidth' => $settings['data']['params']['videoscreenwidth'],
|
|
|
169 |
'videoscreenheight' => $settings['data']['params']['videoscreenheight'],
|
|
|
170 |
'audiortcformat' => (string) $settings['data']['params']['audiortcformat'],
|
|
|
171 |
];
|
|
|
172 |
}
|
| 1 |
efrain |
173 |
}
|