| 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 editor_tiny;
|
|
|
18 |
|
|
|
19 |
use context;
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* Tiny Editor Plugin class.
|
|
|
23 |
*
|
|
|
24 |
* This class must be implemented by any Moodle plugin adding TinyMCE features.
|
|
|
25 |
*
|
|
|
26 |
* It should optionally implement the following interfaces:
|
|
|
27 |
* - plugin_with_buttons: to add buttons to the TinyMCE toolbar
|
|
|
28 |
* - plugin_with_menuitems
|
|
|
29 |
* - plugin_with_configuration: to add configuration to the TinyMCE editor
|
|
|
30 |
*
|
|
|
31 |
* @package editor_tiny
|
|
|
32 |
* @copyright 2021 Andrew Lyons <andrew@nicols.co.uk>
|
|
|
33 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
34 |
*/
|
|
|
35 |
abstract class plugin {
|
|
|
36 |
/**
|
| 1441 |
ariadna |
37 |
* Whether the plugin is enabled and accessible (e.g. capability checks).
|
| 1 |
efrain |
38 |
*
|
|
|
39 |
* @param context $context The context that the editor is used within
|
|
|
40 |
* @param array $options The options passed in when requesting the editor
|
|
|
41 |
* @param array $fpoptions The filepicker options passed in when requesting the editor
|
|
|
42 |
* @param editor $editor The editor instance in which the plugin is initialised
|
|
|
43 |
* @return boolean
|
|
|
44 |
*/
|
|
|
45 |
public static function is_enabled(
|
|
|
46 |
context $context,
|
|
|
47 |
array $options,
|
|
|
48 |
array $fpoptions,
|
|
|
49 |
?editor $editor = null
|
|
|
50 |
): bool {
|
| 1441 |
ariadna |
51 |
$plugin = $options['pluginname'];
|
|
|
52 |
$capability = "tiny/$plugin:use";
|
|
|
53 |
if (!get_capability_info($capability)) {
|
|
|
54 |
// Debug warning that the capability does not exist.
|
|
|
55 |
debugging(
|
|
|
56 |
'The tiny ' . $plugin . ' plugin does not define the standard capability ' . $capability ,
|
|
|
57 |
DEBUG_DEVELOPER
|
|
|
58 |
);
|
|
|
59 |
return true;
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
return has_capability($capability, $context);
|
| 1 |
efrain |
63 |
}
|
|
|
64 |
|
|
|
65 |
/**
|
| 1441 |
ariadna |
66 |
* Whether the plugin is enabled and accessible for external functions.
|
|
|
67 |
*
|
|
|
68 |
* @param context $context The context that the editor is used within.
|
|
|
69 |
* @param array $options Additional options:
|
|
|
70 |
* - pluginname: Name of the plugin, without the "tiny_" prefix.
|
|
|
71 |
* @return bool
|
|
|
72 |
*/
|
|
|
73 |
public static function is_enabled_for_external(context $context, array $options): bool {
|
|
|
74 |
return static::is_enabled($context, $options, []);
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
/**
|
| 1 |
efrain |
78 |
* Get the plugin information for the plugin.
|
|
|
79 |
*
|
|
|
80 |
* @param context $context The context that the editor is used within
|
|
|
81 |
* @param array $options The options passed in when requesting the editor
|
|
|
82 |
* @param array $fpoptions The filepicker options passed in when requesting the editor
|
|
|
83 |
* @param editor $editor The editor instance in which the plugin is initialised
|
|
|
84 |
* @return array
|
|
|
85 |
*/
|
|
|
86 |
final public static function get_plugin_info(
|
|
|
87 |
context $context,
|
|
|
88 |
array $options,
|
|
|
89 |
array $fpoptions,
|
|
|
90 |
?editor $editor = null
|
|
|
91 |
): array {
|
|
|
92 |
$plugindata = [];
|
|
|
93 |
|
|
|
94 |
if (is_a(static::class, plugin_with_buttons::class, true)) {
|
|
|
95 |
$plugindata['buttons'] = static::get_available_buttons();
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
if (is_a(static::class, plugin_with_menuitems::class, true)) {
|
|
|
99 |
$plugindata['menuitems'] = static::get_available_menuitems();
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
if (is_a(static::class, plugin_with_configuration::class, true)) {
|
|
|
103 |
$plugindata['config'] = static::get_plugin_configuration_for_context($context, $options, $fpoptions, $editor);
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
return $plugindata;
|
|
|
107 |
}
|
|
|
108 |
}
|