| Línea 29... |
Línea 29... |
| 29 |
* @package tiny_media
|
29 |
* @package tiny_media
|
| 30 |
* @copyright 2022 Andrew Lyons <andrew@nicols.co.uk>
|
30 |
* @copyright 2022 Andrew Lyons <andrew@nicols.co.uk>
|
| 31 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
31 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
| 32 |
*/
|
32 |
*/
|
| 33 |
class plugininfo extends plugin implements plugin_with_buttons, plugin_with_menuitems, plugin_with_configuration {
|
33 |
class plugininfo extends plugin implements plugin_with_buttons, plugin_with_menuitems, plugin_with_configuration {
|
| 34 |
/**
|
- |
|
| 35 |
* Whether the plugin is enabled
|
- |
|
| 36 |
*
|
34 |
|
| 37 |
* @param context $context The context that the editor is used within
|
- |
|
| 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
|
- |
|
| 40 |
* @param editor $editor The editor instance in which the plugin is initialised
|
- |
|
| 41 |
* @return boolean
|
35 |
#[\Override]
|
| 42 |
*/
|
- |
|
| 43 |
public static function is_enabled(
|
36 |
public static function is_enabled(
|
| 44 |
context $context,
|
37 |
context $context,
|
| 45 |
array $options,
|
38 |
array $options,
|
| 46 |
array $fpoptions,
|
39 |
array $fpoptions,
|
| 47 |
?editor $editor = null
|
40 |
?editor $editor = null
|
| 48 |
): bool {
|
41 |
): bool {
|
| 49 |
// Disabled if:
|
42 |
// Disabled if:
|
| 50 |
// - Not logged in or guest.
|
43 |
// - Not logged in or guest.
|
| 51 |
// - Files are not allowed.
|
44 |
// - Files are not allowed.
|
| 52 |
// - Only URL are supported.
|
45 |
// - Only URL are supported.
|
| - |
|
46 |
// - Don't have the correct capability.
|
| 53 |
$canhavefiles = !empty($options['maxfiles']);
|
47 |
$canhavefiles = !empty($options['maxfiles']);
|
| 54 |
$canhaveexternalfiles = !empty($options['return_types']) && ($options['return_types'] & FILE_EXTERNAL);
|
48 |
$canhaveexternalfiles = !empty($options['return_types']) && ($options['return_types'] & FILE_EXTERNAL);
|
| Línea 55... |
Línea 49... |
| 55 |
|
49 |
|
| - |
|
50 |
return isloggedin() && !isguestuser() && ($canhavefiles || $canhaveexternalfiles) &&
|
| - |
|
51 |
has_capability('tiny/media:use', $context);
|
| - |
|
52 |
}
|
| - |
|
53 |
|
| - |
|
54 |
#[\Override]
|
| - |
|
55 |
public static function is_enabled_for_external(context $context, array $options): bool {
|
| - |
|
56 |
// Assume files are allowed.
|
| - |
|
57 |
$options['maxfiles'] = 1;
|
| 56 |
return isloggedin() && !isguestuser() && ($canhavefiles || $canhaveexternalfiles);
|
58 |
return self::is_enabled($context, $options, []);
|
| Línea 57... |
Línea 59... |
| 57 |
}
|
59 |
}
|
| 58 |
|
60 |
|
| 59 |
public static function get_available_buttons(): array {
|
61 |
public static function get_available_buttons(): array {
|