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;
|
|
|
23 |
use tiny_premium\manager;
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Tiny Premium plugin.
|
|
|
27 |
*
|
|
|
28 |
* @package tiny_premium
|
|
|
29 |
* @copyright 2023 David Woloszyn <david.woloszyn@moodle.com>
|
|
|
30 |
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
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
|
|
|
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 bool
|
|
|
42 |
*/
|
|
|
43 |
public static function is_enabled(
|
|
|
44 |
context $context,
|
|
|
45 |
array $options,
|
|
|
46 |
array $fpoptions,
|
|
|
47 |
?editor $editor = null
|
|
|
48 |
): bool {
|
|
|
49 |
return has_capability('tiny/premium:accesspremium', $context) && (get_config('tiny_premium', 'apikey') != false);
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
/**
|
|
|
53 |
* Get a list of enabled Tiny Premium plugins set by the admin.
|
|
|
54 |
*
|
|
|
55 |
* @param context $context The context that the editor is used within
|
|
|
56 |
* @param array $options The options passed in when requesting the editor
|
|
|
57 |
* @param array $fpoptions The filepicker options passed in when requesting the editor
|
|
|
58 |
* @param editor|null $editor The editor instance in which the plugin is initialised
|
|
|
59 |
* @return array
|
|
|
60 |
*/
|
|
|
61 |
public static function get_plugin_configuration_for_context(
|
|
|
62 |
context $context,
|
|
|
63 |
array $options,
|
|
|
64 |
array $fpoptions,
|
|
|
65 |
?editor $editor = null
|
|
|
66 |
): array {
|
|
|
67 |
return [
|
|
|
68 |
'premiumplugins' => implode(',', manager::get_enabled_plugins()),
|
|
|
69 |
];
|
|
|
70 |
}
|
|
|
71 |
}
|