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/**
18 * Defines classes used for plugin info.
19 *
20 * @package    core
21 * @copyright  2013 Petr Skoda {@link http://skodak.org}
22 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24namespace core\plugininfo;
25
26use moodle_url, part_of_admin_tree, admin_settingpage;
27
28defined('MOODLE_INTERNAL') || die();
29
30
31/**
32 * Class for HTML editors
33 */
34class editor extends base {
35    /**
36     * Finds all enabled plugins, the result may include missing plugins.
37     * @return array|null of enabled plugins $pluginname=>$pluginname, null means unknown
38     */
39    public static function get_enabled_plugins() {
40        global $CFG;
41
42        if (empty($CFG->texteditors)) {
43            return array('atto'=>'atto', 'tinymce'=>'tinymce', 'textarea'=>'textarea');
44        }
45
46        $enabled = array();
47        foreach (explode(',', $CFG->texteditors) as $editor) {
48            $enabled[$editor] = $editor;
49        }
50
51        return $enabled;
52    }
53
54    public function get_settings_section_name() {
55        return 'editorsettings' . $this->name;
56    }
57
58    public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) {
59        global $CFG, $USER, $DB, $OUTPUT, $PAGE; // In case settings.php wants to refer to them.
60        $ADMIN = $adminroot; // May be used in settings.php.
61        $plugininfo = $this; // Also can be used inside settings.php.
62        $editor = $this;     // Also can be used inside settings.php.
63
64        if (!$this->is_installed_and_upgraded()) {
65            return;
66        }
67
68        if (!$hassiteconfig or !file_exists($this->full_path('settings.php'))) {
69            return;
70        }
71
72        $section = $this->get_settings_section_name();
73
74        $settings = new admin_settingpage($section, $this->displayname, 'moodle/site:config', $this->is_enabled() === false);
75        include($this->full_path('settings.php')); // This may also set $settings to null.
76
77        if ($settings) {
78            $ADMIN->add($parentnodename, $settings);
79        }
80    }
81
82    /**
83     * Basic textarea editor can not be uninstalled.
84     */
85    public function is_uninstall_allowed() {
86        if ($this->name === 'textarea') {
87            return false;
88        } else {
89            return true;
90        }
91    }
92
93    /**
94     * Return URL used for management of plugins of this type.
95     * @return moodle_url
96     */
97    public static function get_manage_url() {
98        return new moodle_url('/admin/settings.php', array('section'=>'manageeditors'));
99    }
100}
101