Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
/**
18
 * Tiny equation plugin.
19
 *
20
 * @package    tiny_equation
21
 * @copyright  2022 Huong Nguyen <huongnv13@gmail.com>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace tiny_equation;
26
 
27
use context;
28
use context_system;
29
use editor_tiny\editor;
30
use editor_tiny\plugin;
31
use editor_tiny\plugin_with_buttons;
32
use editor_tiny\plugin_with_configuration;
33
use editor_tiny\plugin_with_menuitems;
34
use filter_manager;
35
 
36
/**
37
 * Tiny equation plugin.
38
 *
39
 * @package    tiny_equation
40
 * @copyright  2022 Huong Nguyen <huongnv13@gmail.com>
41
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42
 */
43
class plugininfo extends plugin implements plugin_with_buttons, plugin_with_menuitems, plugin_with_configuration {
44
 
45
    public static function get_available_buttons(): array {
46
        return [
47
            'tiny_equation/equation',
48
        ];
49
    }
50
 
51
    public static function get_available_menuitems(): array {
52
        return [
53
            'tiny_equation/equation',
54
        ];
55
    }
56
 
57
    public static function get_plugin_configuration_for_context(context $context, array $options, array $fpoptions,
58
        ?editor $editor = null): array {
59
        $texexample = '$$\pi$$';
60
        // Format a string with the active filter set.
61
        // If it is modified - we assume that some sort of text filter is working in this context.
62
        $formatoptions = [
63
            'context' => $context,
64
        ];
65
 
66
        $result = format_text($texexample, true, $formatoptions);
67
        $texfilteractive = ($texexample !== $result);
68
 
69
        if (isset($options['context'])) {
70
            $context = $options['context'];
71
        } else {
72
            $context = context_system::instance();
73
        }
74
 
75
        $libraries = [
76
            [
77
                'key' => 'group1',
78
                'groupname' => get_string('librarygroup1', 'tiny_equation'),
79
                'elements' => explode("\n", trim(get_config('tiny_equation', 'librarygroup1'))),
80
                'active' => true,
81
            ],
82
            [
83
                'key' => 'group2',
84
                'groupname' => get_string('librarygroup2', 'tiny_equation'),
85
                'elements' => explode("\n", trim(get_config('tiny_equation', 'librarygroup2'))),
86
            ],
87
            [
88
                'key' => 'group3',
89
                'groupname' => get_string('librarygroup3', 'tiny_equation'),
90
                'elements' => explode("\n", trim(get_config('tiny_equation', 'librarygroup3'))),
91
            ],
92
            [
93
                'key' => 'group4',
94
                'groupname' => get_string('librarygroup4', 'tiny_equation'),
95
                'elements' => explode("\n", trim(get_config('tiny_equation', 'librarygroup4'))),
96
            ]
97
        ];
98
 
99
        return [
100
            'texfilter' => $texfilteractive,
101
            'contextid' => $context->id,
102
            'libraries' => $libraries,
103
            'texdocsurl' => get_docs_url('Using_TeX_Notation'),
104
        ];
105
    }
106
}