Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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_premium;
18
 
19
use context;
20
use editor_tiny\editor;
21
use editor_tiny\plugin;
22
use editor_tiny\plugin_with_configuration;
1441 ariadna 23
use editor_tiny\plugin_with_configuration_for_external;
1 efrain 24
use tiny_premium\manager;
25
 
26
/**
27
 * Tiny Premium plugin.
28
 *
29
 * @package     tiny_premium
30
 * @copyright   2023 David Woloszyn <david.woloszyn@moodle.com>
31
 * @license     https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 */
1441 ariadna 33
class plugininfo extends plugin implements plugin_with_configuration, plugin_with_configuration_for_external {
1 efrain 34
 
1441 ariadna 35
    #[\Override]
1 efrain 36
    public static function is_enabled(
37
        context $context,
38
        array $options,
39
        array $fpoptions,
40
        ?editor $editor = null
41
    ): bool {
1441 ariadna 42
        return has_capability('tiny/premium:use', $context) && (get_config('tiny_premium', 'apikey') != false);
1 efrain 43
    }
44
 
45
    /**
46
     * Get a list of enabled Tiny Premium plugins set by the admin.
47
     *
48
     * @param context $context The context that the editor is used within
49
     * @param array $options The options passed in when requesting the editor
50
     * @param array $fpoptions The filepicker options passed in when requesting the editor
51
     * @param editor|null $editor The editor instance in which the plugin is initialised
52
     * @return array
53
     */
54
    public static function get_plugin_configuration_for_context(
55
        context $context,
56
        array $options,
57
        array $fpoptions,
58
        ?editor $editor = null
59
    ): array {
1441 ariadna 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
 
1 efrain 68
        return [
1441 ariadna 69
            'premiumplugins' => implode(',', $allowedplugins),
1 efrain 70
        ];
71
    }
1441 ariadna 72
 
73
    #[\Override]
74
    public static function get_plugin_configuration_for_external(context $context): array {
75
        $settings = self::get_plugin_configuration_for_context($context, [], []);
76
        return [
77
            'premiumplugins' => $settings['premiumplugins'],
78
        ];
79
    }
1 efrain 80
}