Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 18... Línea 18...
18
 
18
 
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_configuration;
22
use editor_tiny\plugin_with_configuration;
23
use editor_tiny\plugin_with_configuration_for_external;
Línea 23... Línea 24...
23
use tiny_premium\manager;
24
use tiny_premium\manager;
24
 
25
 
25
/**
26
/**
26
 * Tiny Premium plugin.
27
 * Tiny Premium plugin.
27
 *
28
 *
28
 * @package     tiny_premium
29
 * @package     tiny_premium
29
 * @copyright   2023 David Woloszyn <david.woloszyn@moodle.com>
30
 * @copyright   2023 David Woloszyn <david.woloszyn@moodle.com>
30
 * @license     https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31
 * @license     https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Línea 31... Línea -...
31
 */
-
 
32
class plugininfo extends plugin implements plugin_with_configuration {
-
 
33
 
-
 
34
    /**
-
 
35
     * Determine if the plugin should be enabled by checking the capability and if the Tiny Premium API key is set.
-
 
36
     *
-
 
37
     * @param context $context The context that the editor is used within
-
 
38
     * @param array $options The options passed in when requesting the editor
32
 */
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
33
class plugininfo extends plugin implements plugin_with_configuration, plugin_with_configuration_for_external {
41
     * @return bool
34
 
42
     */
35
    #[\Override]
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
Línea 48... Línea 41...
48
    ): bool {
41
    ): bool {
49
        return has_capability('tiny/premium:accesspremium', $context) && (get_config('tiny_premium', 'apikey') != false);
42
        return has_capability('tiny/premium:use', $context) && (get_config('tiny_premium', 'apikey') != false);
50
    }
43
    }
Línea 62... Línea 55...
62
        context $context,
55
        context $context,
63
        array $options,
56
        array $options,
64
        array $fpoptions,
57
        array $fpoptions,
65
        ?editor $editor = null
58
        ?editor $editor = null
66
    ): array {
59
    ): array {
-
 
60
        $allowedplugins = [];
-
 
61
 
-
 
62
        foreach (manager::get_enabled_plugins() as $plugin) {
-
 
63
            if (has_capability("tiny/premium:use{$plugin}", $context)) {
-
 
64
                $allowedplugins[] = $plugin;
-
 
65
            }
-
 
66
        }
-
 
67
 
-
 
68
        return [
-
 
69
            'premiumplugins' => implode(',', $allowedplugins),
-
 
70
        ];
-
 
71
    }
-
 
72
 
-
 
73
    #[\Override]
-
 
74
    public static function get_plugin_configuration_for_external(context $context): array {
-
 
75
        $settings = self::get_plugin_configuration_for_context($context, [], []);
67
        return [
76
        return [
68
            'premiumplugins' => implode(',', manager::get_enabled_plugins()),
77
            'premiumplugins' => $settings['premiumplugins'],
69
        ];
78
        ];
70
    }
79
    }
71
}
80
}