Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

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