Merge branch 'MDL-79920-main' of https://github.com/davewoloszyn/moodle
[moodle.git] / admin / editors.php
blobee9e635695e3d0689cf02a9cf6b7aafac0db2416
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.
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/>.
17 /**
18 * A page to manage editor plugins.
20 * @package core_admin
21 * @copyright 2023 Andrew Lyons <andrew@nicols.co.uk>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once('../config.php');
26 require_once($CFG->libdir . '/adminlib.php');
27 require_once($CFG->libdir . '/tablelib.php');
29 $action = required_param('action', PARAM_ALPHANUMEXT);
30 $plugin = required_param('plugin', PARAM_PLUGIN);
32 $PAGE->set_url('/admin/editors.php', ['action' => $action, 'editor' => $plugin]);
33 $PAGE->set_context(context_system::instance());
35 require_admin();
36 require_sesskey();
38 $returnurl = new moodle_url('/admin/settings.php', ['section' => 'manageeditors']);
40 // Get currently installed and enabled auth plugins.
41 $availableeditors = editors_get_available();
42 if (!empty($plugin) && empty($availableeditors[$plugin])) {
43 redirect($returnurl);
46 $activeeditors = explode(',', $CFG->texteditors);
47 foreach ($activeeditors as $key => $active) {
48 if (empty($availableeditors[$active])) {
49 unset($activeeditors[$key]);
53 switch ($action) {
54 case 'disable':
55 // Remove from enabled list.
56 $class = \core_plugin_manager::resolve_plugininfo_class('editor');
57 $class::enable_plugin($plugin, false);
58 break;
60 case 'enable':
61 // Add to enabled list.
62 if (!in_array($plugin, $activeeditors)) {
63 $class = \core_plugin_manager::resolve_plugininfo_class('editor');
64 $class::enable_plugin($plugin, true);
66 break;
68 case 'down':
69 $key = array_search($plugin, $activeeditors);
70 if ($key !== false) {
71 // Move down the list.
72 if ($key < (count($activeeditors) - 1)) {
73 $fsave = $activeeditors[$key];
74 $activeeditors[$key] = $activeeditors[$key + 1];
75 $activeeditors[$key + 1] = $fsave;
76 add_to_config_log('editor_position', $key, $key + 1, $plugin);
77 set_config('texteditors', implode(',', $activeeditors));
78 core_plugin_manager::reset_caches();
81 break;
83 case 'up':
84 $key = array_search($plugin, $activeeditors);
85 if ($key !== false) {
86 // Move up the list.
87 if ($key >= 1) {
88 $fsave = $activeeditors[$key];
89 $activeeditors[$key] = $activeeditors[$key - 1];
90 $activeeditors[$key - 1] = $fsave;
91 add_to_config_log('editor_position', $key, $key - 1, $plugin);
92 set_config('texteditors', implode(',', $activeeditors));
93 core_plugin_manager::reset_caches();
96 break;
98 default:
99 break;
102 redirect($returnurl);