MDL-75078 editor_tiny: Hola TinyMCE 6
Part of MDL-75966 This commit adds TinyMCE version 6.1 into Moodle core. A basic editor implementation is included, along with Moodle loader, and basic Plugin API for Moodle. The Plugin API will be extended and improved in future changes. A new subplugin is defined for this plugin.
This commit is contained in:
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace editor_tiny;
|
||||
|
||||
/**
|
||||
* Tiny Editor.
|
||||
*
|
||||
* @package editor_tiny
|
||||
* @copyright 2021 Andrew Lyons <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class editor extends \texteditor {
|
||||
|
||||
/** @var manager The Tiny Manager instace */
|
||||
protected $manager;
|
||||
|
||||
/** @var \stdClass|null The default configuration to use if none is provided */
|
||||
protected static $defaultconfiguration = null;
|
||||
|
||||
/**
|
||||
* Instantiate the new editor instance.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->manager = new manager();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default configuration for the editor.
|
||||
*
|
||||
* @param manager $manager The editor manager
|
||||
*/
|
||||
public static function set_default_configuration(manager $manager): void {
|
||||
global $PAGE;
|
||||
|
||||
if (self::is_default_configuration_set()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$context = $PAGE->context;
|
||||
|
||||
$config = (object) [
|
||||
'css' => $PAGE->theme->editor_css_url()->out(false),
|
||||
'context' => $context->id,
|
||||
'plugins' => $manager->get_plugin_configuration($context, [], []),
|
||||
];
|
||||
|
||||
$config = json_encode($config);
|
||||
$inlinejs = <<<EOF
|
||||
M.util.js_pending('editor_tiny/editor:defaultConfiguration');
|
||||
require(['editor_tiny/editor'], (Tiny) => {
|
||||
Tiny.configureDefaultEditor({$config});
|
||||
M.util.js_complete('editor_tiny/editor:defaultConfiguration');
|
||||
});
|
||||
EOF;
|
||||
|
||||
$PAGE->requires->js_amd_inline($inlinejs);
|
||||
|
||||
self::$defaultconfiguration = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the current defautl configuration.
|
||||
*
|
||||
* @return \stdClass|null The default configuration or null if not set.
|
||||
*/
|
||||
public static function get_default_configuration(): ?\stdClass {
|
||||
return self::$defaultconfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the default configuration.
|
||||
*/
|
||||
public static function reset_default_configuration(): void {
|
||||
self::$defaultconfiguration = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the default configuration is set.
|
||||
*
|
||||
* @return bool True if the default configuration is set.
|
||||
*/
|
||||
public static function is_default_configuration_set(): bool {
|
||||
return !empty(self::$defaultconfiguration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the current browser supported by this editor?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function supported_by_browser() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* List of supported text field formats.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_supported_formats() {
|
||||
return [
|
||||
FORMAT_HTML => FORMAT_HTML,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns text format preferred by this editor.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_preferred_format() {
|
||||
return FORMAT_HTML;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this editor support picking from repositories?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function supports_repositories() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this editor for given element.
|
||||
*
|
||||
* @param string $elementid
|
||||
* @param array $options
|
||||
* @param null $fpoptions
|
||||
*/
|
||||
public function use_editor($elementid, array $options = null, $fpoptions = null) {
|
||||
global $PAGE;
|
||||
|
||||
// Ensure that the default configuration is set.
|
||||
self::set_default_configuration($this->manager);
|
||||
|
||||
if ($fpoptions === null) {
|
||||
$fpoptions = [];
|
||||
}
|
||||
|
||||
$context = $PAGE->context;
|
||||
|
||||
if (isset($options['context']) && ($options['context'] instanceof \context)) {
|
||||
// A different context was provided.
|
||||
// Use that instead.
|
||||
$context = $options['context'];
|
||||
}
|
||||
|
||||
// Generate the configuration for this editor.
|
||||
$config = (object) [
|
||||
// The URL to the CSS file for the editor.
|
||||
'css' => $PAGE->theme->editor_css_url()->out(false),
|
||||
|
||||
// The current context for this page or editor.
|
||||
'context' => $context->id,
|
||||
|
||||
// File picker options.
|
||||
'filepicker' => $fpoptions,
|
||||
|
||||
// Plugin configuration.
|
||||
'plugins' => $this->manager->get_plugin_configuration($context, $options, $fpoptions),
|
||||
];
|
||||
|
||||
$configoptions = json_encode(convert_to_array($config));
|
||||
|
||||
// Note: This is not ideal but the editor does not have control over any HTML output.
|
||||
// The Editor API only allows you to run JavaScript.
|
||||
// In the future we will extend the editor API to allow it to generate the textarea, or attributes to use in the
|
||||
// textarea or its wrapper.
|
||||
// For now we cannot use the `js_call_amd()` API call because it warns if the parameters passed exceed a
|
||||
// relatively low character limit.
|
||||
$config = json_encode($config);
|
||||
$inlinejs = <<<EOF
|
||||
M.util.js_pending('editor_tiny/editor');
|
||||
require(['editor_tiny/editor'], (Tiny) => {
|
||||
Tiny.setupForElementId({
|
||||
elementId: "${elementid}",
|
||||
options: ${configoptions},
|
||||
});
|
||||
M.util.js_complete('editor_tiny/editor');
|
||||
});
|
||||
EOF;
|
||||
|
||||
$PAGE->requires->js_amd_inline($inlinejs);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,561 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace editor_tiny;
|
||||
|
||||
use context;
|
||||
|
||||
/**
|
||||
* Tiny Editor Plugin manager.
|
||||
*
|
||||
* @package editor_tiny
|
||||
* @copyright 2021 Andrew Lyons <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class manager {
|
||||
|
||||
public function get_plugin_configuration(
|
||||
context $context,
|
||||
array $options = [],
|
||||
array $fpoptions = []
|
||||
): array {
|
||||
$disabledplugins = $this->get_disabled_plugins();
|
||||
|
||||
$plugins = $this->get_shipped_plugins();
|
||||
|
||||
// Fetch configuration for Moodle plugins.
|
||||
$moodleplugins = \core_component::get_plugin_list_with_class('tiny', 'plugininfo');
|
||||
foreach ($moodleplugins as $plugin => $classname) {
|
||||
if (in_array($plugin, $disabledplugins)) {
|
||||
// Skip getting data for disabled plugins.
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!is_a($classname, plugin::class, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$plugininfo = $classname::get_plugin_info();
|
||||
|
||||
$config = $classname::get_plugin_configuration_for_context(
|
||||
$context,
|
||||
$options,
|
||||
$fpoptions
|
||||
);
|
||||
|
||||
if (!empty($config)) {
|
||||
$plugininfo['config'] = $config;
|
||||
}
|
||||
|
||||
$plugins["{$plugin}/plugin"] = $plugininfo;
|
||||
}
|
||||
|
||||
$plugins = array_filter($plugins, function ($plugin) use ($disabledplugins) {
|
||||
return !in_array($plugin, $disabledplugins);
|
||||
}, ARRAY_FILTER_USE_KEY);
|
||||
|
||||
return $plugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of the buttons provided by this plugin.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected function get_tinymce_buttons(): array {
|
||||
// The following list is defined at:
|
||||
// https://www.tiny.cloud/docs/advanced/available-toolbar-buttons/#thecoretoolbarbuttons.
|
||||
return [
|
||||
// These are always available, without requiring additional plugins.
|
||||
'aligncenter',
|
||||
'alignjustify',
|
||||
'alignleft',
|
||||
'alignnone',
|
||||
'alignright',
|
||||
'blockquote',
|
||||
'backcolor',
|
||||
'bold',
|
||||
'copy',
|
||||
'cut',
|
||||
'fontselect',
|
||||
'fontsizeselect',
|
||||
'forecolor',
|
||||
'formatselect',
|
||||
'h1',
|
||||
'h2',
|
||||
'h3',
|
||||
'h4',
|
||||
'h5',
|
||||
'h6',
|
||||
'indent',
|
||||
'italic',
|
||||
'language',
|
||||
'lineheight',
|
||||
'newdocument',
|
||||
'outdent',
|
||||
'paste',
|
||||
'redo',
|
||||
'remove',
|
||||
'removeformat',
|
||||
'selectall',
|
||||
'strikethrough',
|
||||
'styleselect',
|
||||
'subscript',
|
||||
'superscript',
|
||||
'underline',
|
||||
'undo',
|
||||
'visualaid',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of the menu items provided by this plugin.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected function get_tinymce_menuitems(): array {
|
||||
// The following list is defined at:
|
||||
// https://www.tiny.cloud/docs/advanced/available-menu-items/#thecoremenuitems.
|
||||
return [
|
||||
'align' => 'format',
|
||||
'backcolor' => 'format',
|
||||
'blockformats' => 'format',
|
||||
'bold' => 'format',
|
||||
'codeformat' => 'format',
|
||||
'copy' => 'copy',
|
||||
'cut' => 'copy',
|
||||
'forecolor' => 'format',
|
||||
'formats' => 'format',
|
||||
'fontformats' => 'format',
|
||||
'fontsizes' => 'format',
|
||||
'italic' => 'format',
|
||||
'language' => 'format',
|
||||
'lineheight' => 'format',
|
||||
'newdocument' => 'file',
|
||||
'paste' => 'copy',
|
||||
'redo' => 'copy',
|
||||
'removeformat' => 'format',
|
||||
'selectall' => 'edit',
|
||||
'strikethrough' => 'format',
|
||||
'subscript' => 'format',
|
||||
'superscript' => 'format',
|
||||
'underline' => 'format',
|
||||
'undo' => 'copy',
|
||||
'visualaid' => 'view',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of all available plugins, including both TinyMCE shipped, and Moodle add-onis.
|
||||
*
|
||||
* Each plugin is returned as an array element containing:
|
||||
* - a list of buttons (if applicable); and
|
||||
* - a list of menuitems (if applicable).
|
||||
*
|
||||
* Note: Not all plugins include buttons, and not all plugins include menuitems.
|
||||
* These array keys are optional.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_available_plugins(): array {
|
||||
$plugins = $this->get_shipped_plugins();
|
||||
$plugins += $this->get_moodle_plugins();
|
||||
|
||||
$disabledplugins = $this->get_disabled_plugins();
|
||||
$plugins = array_filter($plugins, function ($plugin) use ($disabledplugins) {
|
||||
return !in_array($plugin, $disabledplugins);
|
||||
}, ARRAY_FILTER_USE_KEY);
|
||||
|
||||
return $plugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of all available plugins built into TinyMCE and not shipped as separate Moodle plugins.
|
||||
*
|
||||
* Each plugin is returned as an array element containing:
|
||||
* - a list of buttons (if applicable); and
|
||||
* - a list of menuitems (if applicable).
|
||||
*
|
||||
* Note: Not all plugins include buttons, and not all plugins include menuitems.
|
||||
* These array keys are optional.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_shipped_plugins(): array {
|
||||
$plugins = $this->get_tinymce_plugins();
|
||||
if ($this->premium_plugins_enabled()) {
|
||||
$plugins += $this->get_premium_plugins();
|
||||
}
|
||||
|
||||
$disabledplugins = $this->get_disabled_plugins();
|
||||
return array_filter($plugins, function($plugin) use ($disabledplugins) {
|
||||
return !in_array($plugin, $disabledplugins);
|
||||
}, ARRAY_FILTER_USE_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of the core plugins with their button, and menuitem, configuration.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
protected function get_tinymce_plugins(): array {
|
||||
// The following list is defined at:
|
||||
// https://www.tiny.cloud/docs/advanced/available-toolbar-buttons/#thecoretoolbarbuttons.
|
||||
return [
|
||||
'anchor' => [
|
||||
'buttons' => [
|
||||
'anchor',
|
||||
],
|
||||
'menuitems' => [
|
||||
'anchor' => 'insert',
|
||||
],
|
||||
],
|
||||
'autosave' => [
|
||||
'buttons' => [
|
||||
'restoredraft',
|
||||
],
|
||||
'menuitems' => [
|
||||
'restoredraft' => 'file',
|
||||
],
|
||||
],
|
||||
'charmap' => [
|
||||
'buttons' => [
|
||||
'charmap',
|
||||
],
|
||||
'menuitems' => [
|
||||
'charmap' => 'insert',
|
||||
],
|
||||
],
|
||||
'code' => [
|
||||
'buttons' => [
|
||||
'code',
|
||||
],
|
||||
'menuitems' => [
|
||||
'code' => 'view',
|
||||
],
|
||||
],
|
||||
'codesample' => [
|
||||
'buttons' => [
|
||||
'codesample',
|
||||
],
|
||||
'menutiems' => [
|
||||
'codesample' => 'insert',
|
||||
],
|
||||
],
|
||||
'directionality' => [
|
||||
'buttons' => [
|
||||
'ltr',
|
||||
'rtl',
|
||||
],
|
||||
],
|
||||
'emoticons' => [
|
||||
'buttons' => [
|
||||
'emoticons',
|
||||
],
|
||||
'menuitems' => [
|
||||
'emoticons' => 'insert',
|
||||
],
|
||||
],
|
||||
'fullscreen' => [
|
||||
'buttons' => [
|
||||
'fullscreen',
|
||||
],
|
||||
'menuitems' => [
|
||||
'fullscreen' => 'view',
|
||||
],
|
||||
],
|
||||
'help' => [
|
||||
'buttons' => [
|
||||
'help',
|
||||
],
|
||||
'menuitems' => [
|
||||
'help' => 'help',
|
||||
],
|
||||
],
|
||||
'image' => [
|
||||
'buttons' => [
|
||||
'image',
|
||||
],
|
||||
'menuitems' => [
|
||||
'image' => 'insert',
|
||||
],
|
||||
],
|
||||
'insertdatetime' => [
|
||||
'buttons' => [
|
||||
'insertdatetime',
|
||||
],
|
||||
'menuitems' => [
|
||||
'insertdatetime' => 'insert',
|
||||
],
|
||||
],
|
||||
'link' => [
|
||||
'buttons' => [
|
||||
'link',
|
||||
'openlink',
|
||||
'unlink',
|
||||
],
|
||||
'menuitems' => [
|
||||
'link' => 'insert',
|
||||
],
|
||||
],
|
||||
'lists' => [
|
||||
'buttons' => [
|
||||
'bullist',
|
||||
'numlist',
|
||||
],
|
||||
],
|
||||
'media' => [
|
||||
'buttons' => [
|
||||
'media',
|
||||
],
|
||||
'menuitems' => [
|
||||
'media' => 'insert',
|
||||
],
|
||||
],
|
||||
'nonbreaking' => [
|
||||
'buttons' => [
|
||||
'nonbreaking',
|
||||
],
|
||||
'menuitems' => [
|
||||
'nonbreaking' => 'insert',
|
||||
],
|
||||
],
|
||||
'pagebreak' => [
|
||||
'buttons' => [
|
||||
'pagebreak',
|
||||
],
|
||||
'menuitems' => [
|
||||
'pagebreak' => 'insert',
|
||||
],
|
||||
],
|
||||
'preview' => [
|
||||
'buttons' => [
|
||||
'preview',
|
||||
],
|
||||
'menuitems' => [
|
||||
'preview' => 'file',
|
||||
],
|
||||
],
|
||||
'quickbars' => [
|
||||
'buttons' => [
|
||||
'quickimage',
|
||||
'quicklink',
|
||||
'quicktable',
|
||||
],
|
||||
],
|
||||
'save' => [
|
||||
'buttons' => [
|
||||
'cancel',
|
||||
'save',
|
||||
],
|
||||
],
|
||||
'searchreplace' => [
|
||||
'buttons' => [
|
||||
'searchreplace',
|
||||
],
|
||||
'menuitems' => [
|
||||
'searchreplace' => 'edit',
|
||||
],
|
||||
],
|
||||
'table' => [
|
||||
'buttons' => [
|
||||
'table',
|
||||
'tablecellprops',
|
||||
'tablecopyrow',
|
||||
'tablecutrow',
|
||||
'tabledelete',
|
||||
'tabledeletecol',
|
||||
'tabledeleterow',
|
||||
'tableinsertdialog',
|
||||
'tableinsertcolafter',
|
||||
'tableinsertcolbefore',
|
||||
'tableinsertrowafter',
|
||||
'tableinsertrowbefore',
|
||||
'tablemergecells',
|
||||
'tablepasterowafter',
|
||||
'tablepasterowbefore',
|
||||
'tableprops',
|
||||
'tablerowprops',
|
||||
'tablesplitcells',
|
||||
'tableclass',
|
||||
'tablecellclass',
|
||||
'tablecellvalign',
|
||||
'tablecellborderwidth',
|
||||
'tablecellborderstyle',
|
||||
'tablecaption',
|
||||
'tablecellbackgroundcolor',
|
||||
'tablecellbordercolor',
|
||||
'tablerowheader',
|
||||
'tablecolheader',
|
||||
],
|
||||
'menuitems' => [
|
||||
'inserttable' => 'table',
|
||||
'tableprops' => 'table',
|
||||
'deletetable' => 'table',
|
||||
'cell' => 'table',
|
||||
'tablemergecells' => 'table',
|
||||
'tablesplitcells' => 'table',
|
||||
'tablecellprops' => 'table',
|
||||
'column' => 'table',
|
||||
'tableinsertcolumnbefore' => 'table',
|
||||
'tableinsertcolumnafter' => 'table',
|
||||
'tablecutcolumn' => 'table',
|
||||
'tablecopycolumn' => 'table',
|
||||
'tablepastecolumnbefore' => 'table',
|
||||
'tablepastecolumnafter' => 'table',
|
||||
'tabledeletecolumn' => 'table',
|
||||
'row' => 'table',
|
||||
'tableinsertrowbefore' => 'table',
|
||||
'tableinsertrowafter' => 'table',
|
||||
'tablecutrow' => 'table',
|
||||
'tablecopyrow' => 'table',
|
||||
'tablepasterowbefore' => 'table',
|
||||
'tablepasterowafter' => 'table',
|
||||
'tablerowprops' => 'table',
|
||||
'tabledeleterow' => 'table',
|
||||
],
|
||||
],
|
||||
'template' => [
|
||||
'buttons' => [
|
||||
'template',
|
||||
],
|
||||
'menuitems' => [
|
||||
'template' => 'insert',
|
||||
],
|
||||
],
|
||||
'visualblocks' => [
|
||||
'buttons' => [
|
||||
'visualblocks',
|
||||
],
|
||||
'menuitems' => [
|
||||
'visualblocks' => 'view',
|
||||
],
|
||||
],
|
||||
'visualchars' => [
|
||||
'buttons' => [
|
||||
'visualchars',
|
||||
],
|
||||
'menuitems' => [
|
||||
'visualchars' => 'view',
|
||||
],
|
||||
],
|
||||
'wordcount' => [
|
||||
'buttons' => [
|
||||
'wordcount',
|
||||
],
|
||||
'menuitems' => [
|
||||
'wordcount' => 'tools',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of the disabled plugins.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected function get_disabled_plugins(): array {
|
||||
return [
|
||||
// Disable the image and media plugins.
|
||||
// These are not generally compatible with Moodle.
|
||||
'image',
|
||||
'media',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of the Moodle plugins with their button, and menuitem, configuration.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
protected function get_moodle_plugins(): array {
|
||||
$plugins = \core_component::get_plugin_list_with_class('tiny', 'plugininfo');
|
||||
|
||||
$pluginconfig = [];
|
||||
foreach ($plugins as $pluginname => $classname) {
|
||||
if (!is_a($classname, plugin::class, true)) {
|
||||
continue;
|
||||
}
|
||||
// Module name => [buttons, menuitems].
|
||||
$pluginconfig["{$pluginname}/plugin"] = $classname::get_plugin_info();
|
||||
}
|
||||
|
||||
return $pluginconfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether premium plugins are configured and enabled.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function premium_plugins_enabled(): bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of the Tiny Premium plugins with their button, and menuitem, configuration.
|
||||
*
|
||||
* Note: This only includes _compatible_ premium plugins.
|
||||
* Some premium plugins *may not* be compatible with Moodle, and some may require additional configuration.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
protected function get_premium_plugins(): array {
|
||||
return [
|
||||
'a11ycheck' => [
|
||||
'buttons' => [
|
||||
'a11ycheck',
|
||||
],
|
||||
'menuitems' => [
|
||||
'a11ycheck',
|
||||
],
|
||||
],
|
||||
'advcode' => [
|
||||
'buttons' => [
|
||||
'code',
|
||||
],
|
||||
'menuitems' => [
|
||||
'code',
|
||||
],
|
||||
],
|
||||
'footnotes' => [
|
||||
'buttons' => [
|
||||
'footnotes',
|
||||
'footnotesupdate',
|
||||
],
|
||||
'menuitems' => [
|
||||
'footnotes',
|
||||
'footnotesupdate',
|
||||
],
|
||||
],
|
||||
'mergetags' => [
|
||||
'buttons' => [
|
||||
'mergetags',
|
||||
],
|
||||
'menuitems' => [
|
||||
'mergetags',
|
||||
],
|
||||
],
|
||||
'autocorrect' => [
|
||||
'menuitems' => [
|
||||
'autocorrect',
|
||||
'capitalization',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace editor_tiny;
|
||||
|
||||
use context;
|
||||
|
||||
/**
|
||||
* Tiny Editor Plugin class.
|
||||
*
|
||||
* This class must be implemented by any Moodle plugin adding TinyMCE features.
|
||||
*
|
||||
* It should optionally implement the following interfaces:
|
||||
* - plugin_with_buttons: to add buttons to the TinyMCE toolbar
|
||||
* - plugin_with_menuitems
|
||||
* - plugin_with_configuration: to add configuration to the TinyMCE editor
|
||||
*
|
||||
* @package editor_tiny
|
||||
* @copyright 2021 Andrew Lyons <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
abstract class plugin {
|
||||
public static function get_plugin_info(): array {
|
||||
$plugindata = [];
|
||||
|
||||
if (is_a(static::class, plugin_with_buttons::class, true)) {
|
||||
$plugindata['buttons'] = static::get_available_buttons();
|
||||
}
|
||||
|
||||
if (is_a(static::class, plugin_with_menuitems::class, true)) {
|
||||
$plugindata['menuitems'] = static::get_available_menuitems();
|
||||
}
|
||||
|
||||
return $plugindata;
|
||||
}
|
||||
|
||||
public static function get_plugin_configuration_for_context(
|
||||
context $context,
|
||||
array $options,
|
||||
array $fpoptions
|
||||
): array {
|
||||
if (is_a(static::class, plugin_with_configuration::class, true)) {
|
||||
return static::get_plugin_configuration_for_context($context, $options, $fpoptions);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace editor_tiny;
|
||||
|
||||
/**
|
||||
* Tiny Editor.
|
||||
*
|
||||
* @package editor_tiny
|
||||
* @copyright 2021 Andrew Lyons <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
interface plugin_with_buttons {
|
||||
/**
|
||||
* Get a list of the buttons provided by this plugin.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public static function get_available_buttons(): array;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace editor_tiny;
|
||||
|
||||
use context;
|
||||
|
||||
/**
|
||||
* An interface representing a plugin with menu items.
|
||||
*
|
||||
* @package editor_tiny
|
||||
* @copyright 2021 Andrew Lyons <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
interface plugin_with_configuration {
|
||||
/**
|
||||
* Get a list of the menu items provided by this plugin.
|
||||
*
|
||||
* @param context $context The context that the editor is used within
|
||||
* @param array $options The options passed in when requesting the editor
|
||||
* @param array $fpoptions The filepicker options passed in when requesting the editor
|
||||
* @return array
|
||||
*/
|
||||
public static function get_plugin_configuration_for_context(
|
||||
context $context,
|
||||
array $options,
|
||||
array $fpoptions
|
||||
): array;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace editor_tiny;
|
||||
|
||||
/**
|
||||
* An interface representing a plugin with menu items.
|
||||
*
|
||||
* @package editor_tiny
|
||||
* @copyright 2021 Andrew Lyons <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
interface plugin_with_menuitems {
|
||||
/**
|
||||
* Get a list of the menu items provided by this plugin.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public static function get_available_menuitems(): array;
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace editor_tiny\plugininfo;
|
||||
|
||||
use moodle_url;
|
||||
|
||||
/**
|
||||
* Subplugin info class.
|
||||
*
|
||||
* @package editor_tiny
|
||||
* @copyright 2022 Andrew Lyons <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tiny extends \core\plugininfo\base {
|
||||
|
||||
/**
|
||||
* These subplugins can be uninstalled.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_uninstall_allowed(): bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return URL used for management of plugins of this type.
|
||||
*
|
||||
* @return moodle_url
|
||||
*/
|
||||
public static function get_manage_url(): moodle_url {
|
||||
return new moodle_url('/admin/settings.php', [
|
||||
'section' => 'editosettingstiny',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Include the settings.php file from subplugins if provided.
|
||||
*
|
||||
* This is a copy of very similar implementations from various other subplugin areas.
|
||||
*
|
||||
* @param \part_of_admin_tree $adminroot
|
||||
* @param string $parentnodename
|
||||
* @param bool $hassiteconfig whether the current user has moodle/site:config capability
|
||||
*/
|
||||
public function load_settings(\part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig): void {
|
||||
// In case settings.php wants to refer to them.
|
||||
global $CFG, $USER, $DB, $OUTPUT, $PAGE;
|
||||
|
||||
$ADMIN = $adminroot; // May be used in settings.php.
|
||||
$plugininfo = $this; // Also can be used inside settings.php.
|
||||
|
||||
if (!$this->is_installed_and_upgraded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$hassiteconfig || !file_exists($this->full_path('settings.php'))) {
|
||||
return;
|
||||
}
|
||||
|
||||
$section = $this->get_settings_section_name();
|
||||
$settings = new \admin_settingpage(
|
||||
$section,
|
||||
$this->displayname,
|
||||
'moodle/site:config',
|
||||
$this->is_enabled() === false
|
||||
);
|
||||
|
||||
// This may also set $settings to null.
|
||||
include($this->full_path('settings.php'));
|
||||
|
||||
if ($settings) {
|
||||
$ADMIN->add($parentnodename, $settings);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the settings section name.
|
||||
* This is used to get the setting links in the Tiny sub-plugins table.
|
||||
*
|
||||
* @return null|string the settings section name.
|
||||
*/
|
||||
public function get_settings_section_name(): ?string {
|
||||
return "tiny_{$this->name}_settings";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace editor_tiny\privacy;
|
||||
|
||||
/**
|
||||
* Privacy Subsystem implementation for the TinyMCE Editor.
|
||||
*
|
||||
* @package editor_tiny
|
||||
* @copyright 2022 Andrew Lyons <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class provider implements \core_privacy\local\metadata\null_provider {
|
||||
|
||||
/**
|
||||
* Return the langstring identifier for the reason that no privacy provider needs to be implemented for this plugin.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_reason(): string {
|
||||
return 'privacy:metadata';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user