first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+238
View File
@@ -0,0 +1,238 @@
<?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 <andrew@nicols.co.uk>
* @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.
$siteconfig = get_config('editor_tiny');
$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' => (object) $fpoptions,
// Default draft item ID.
'draftitemid' => 0,
'currentLanguage' => current_language(),
'branding' => property_exists($siteconfig, 'branding') ? !empty($siteconfig->branding) : true,
// Language options.
'language' => [
'currentlang' => current_language(),
'installed' => get_string_manager()->get_list_of_translations(true),
'available' => get_string_manager()->get_list_of_languages()
],
// Placeholder selectors.
// Some contents (Example: placeholder elements) are only shown in the editor, and not to users. It is unrelated to the
// real display. We created a list of placeholder selectors, so we can decide to or not to apply rules, styles... to
// these elements.
// The default of this list will be empty.
// Other plugins can register their placeholder elements to placeholderSelectors list by calling
// editor_tiny/options::registerPlaceholderSelectors.
'placeholderSelectors' => [],
// Plugin configuration.
'plugins' => $this->manager->get_plugin_configuration($context, $options, $fpoptions, $this),
];
if (defined('BEHAT_SITE_RUNNING') && BEHAT_SITE_RUNNING) {
// Add sample selectors for Behat test.
$config->placeholderSelectors = ['.behat-tinymce-placeholder'];
}
foreach ($fpoptions as $fp) {
// Guess the draftitemid for the editor.
// Note: This is the best we can do at the moment.
if (!empty($fp->itemid)) {
$config->draftitemid = $fp->itemid;
break;
}
}
$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);
}
}
+587
View File
@@ -0,0 +1,587 @@
<?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 <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class manager {
/**
* Get the configuration for all plugins.
*
* @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
* @param editor $editor The editor instance in which the plugin is initialised
*/
public function get_plugin_configuration(
context $context,
array $options = [],
array $fpoptions = [],
?editor $editor = null
): array {
// Get the list of plugins.
// Note: Disabled plugins are already removed from this list.
$plugins = $this->get_shipped_plugins();
// Fetch configuration for Moodle plugins.
$moodleplugins = \core_component::get_plugin_list_with_class('tiny', 'plugininfo');
$enabledplugins = \editor_tiny\plugininfo\tiny::get_enabled_plugins();
foreach ($moodleplugins as $plugin => $classname) {
[, $pluginname] = explode('_', $plugin, 2);
if (!in_array($pluginname, $enabledplugins)) {
// This plugin has been disabled.
continue;
}
if (!is_a($classname, plugin::class, true)) {
// Skip plugins that do not implement the plugin interface.
debugging("Plugin {$plugin} does not implement the plugin interface", DEBUG_DEVELOPER);
continue;
}
if (!$classname::is_enabled($context, $options, $fpoptions, $editor)) {
// This plugin has disabled itself for some reason.
// This is typical for media plugins where there is no file storage.
continue;
}
// Get the plugin information, which includes the list of buttons, menu items, and configuration.
$plugininfo = $classname::get_plugin_info(
$context,
$options,
$fpoptions,
$editor
);
// We suffix the plugin name for Moodle plugins with /plugin to avoid conflicts with Tiny plugins.
$plugins["{$plugin}/plugin"] = $plugininfo;
}
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_tinymce_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_tinymce_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 built-in TinyMCE plugins which we want to disable.
*
* These are usually disabled because we have replaced them, or they are not compatible with Moodle in some way.
*
* @return string[]
*/
protected function get_disabled_tinymce_plugins(): array {
return [
// Disable the image and media plugins.
// These are not generally compatible with Moodle.
'image',
'media',
// Use the Moodle autosave plugin instead.
'autosave',
// Disable the Template plugin for now.
'template',
// Disable the preview plugin as it does not support Moodle filters.
'preview',
// Use the Moodle link plugin instead.
'link',
];
}
/**
* 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',
],
],
];
}
}
+85
View File
@@ -0,0 +1,85 @@
<?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 <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class plugin {
/**
* Whether the plugin is enabled
*
* @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
* @param editor $editor The editor instance in which the plugin is initialised
* @return boolean
*/
public static function is_enabled(
context $context,
array $options,
array $fpoptions,
?editor $editor = null
): bool {
return true;
}
/**
* Get the plugin information for the 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
* @param editor $editor The editor instance in which the plugin is initialised
* @return array
*/
final public static function get_plugin_info(
context $context,
array $options,
array $fpoptions,
?editor $editor = null
): 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();
}
if (is_a(static::class, plugin_with_configuration::class, true)) {
$plugindata['config'] = static::get_plugin_configuration_for_context($context, $options, $fpoptions, $editor);
}
return $plugindata;
}
}
@@ -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 <andrew@nicols.co.uk>
* @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,44 @@
<?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 <andrew@nicols.co.uk>
* @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
* @param editor $editor The editor instance in which the plugin is initialised
* @return array
*/
public static function get_plugin_configuration_for_context(
context $context,
array $options,
array $fpoptions,
?editor $editor = null
): 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 <andrew@nicols.co.uk>
* @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;
}
+151
View File
@@ -0,0 +1,151 @@
<?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 <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tiny extends \core\plugininfo\base {
public static function plugintype_supports_disabling(): bool {
return true;
}
/**
* 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' => 'editorsettingstiny',
]);
}
/**
* 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;
/** @var \admin_root $ADMIN */
$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 {
if (!file_exists($this->full_path('settings.php'))) {
return null;
}
return "tiny_{$this->name}_settings";
}
public static function get_enabled_plugins(): array {
$pluginmanager = \core_plugin_manager::instance();
$plugins = $pluginmanager->get_installed_plugins('tiny');
if (!$plugins) {
return [];
}
// Filter to return only enabled plugins.
$enabled = [];
foreach (array_keys($plugins) as $pluginname) {
$disabled = get_config("tiny_{$pluginname}", 'disabled');
if (empty($disabled)) {
$enabled[$pluginname] = $pluginname;
}
}
return $enabled;
}
public static function enable_plugin(string $plugin, int $enabled): bool {
$pluginname = "tiny_{$plugin}";
$oldvalue = !empty(get_config($pluginname, 'disabled'));
$disabled = empty($enabled);
$haschanged = false;
// Only set value if there is no config setting or if the value is different from the previous one.
if (!$oldvalue && $disabled) {
set_config('disabled', $disabled, $pluginname);
$haschanged = true;
} else if ($oldvalue && !$disabled) {
unset_config('disabled', $pluginname);
$haschanged = true;
}
if ($haschanged) {
add_to_config_log('disabled', $oldvalue, $disabled, $pluginname);
\core_plugin_manager::reset_caches();
}
return $haschanged;
}
}
@@ -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 <andrew@nicols.co.uk>
* @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:reason';
}
}
@@ -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\table;
use moodle_url;
/**
* Tiny admin settings.
*
* @package editor_tiny
* @copyright 2023 Andrew Lyons <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class plugin_management_table extends \core_admin\table\plugin_management_table {
protected function get_plugintype(): string {
return 'tiny';
}
public function guess_base_url(): void {
$this->define_baseurl(
new moodle_url('/admin/settings.php', ['section' => 'editorsettingstiny'])
);
}
protected function get_action_url(array $params = []): moodle_url {
return new moodle_url('/lib/editor/tiny/subplugins.php', $params);
}
}