Proyectos de Subversion Moodle

Rev

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