-
Notifications
You must be signed in to change notification settings - Fork 12
/
lib.php
90 lines (84 loc) · 3.97 KB
/
lib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?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/>.
/**
* Library functions for MathType for TinyMCE.
*
* @package tinymce
* @subpackage tiny_mce_wiris
* @copyright WIRIS Europe (Maths for more S.L)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tinymce_tiny_mce_wiris extends editor_tinymce_plugin {
protected $buttons = array('tiny_mce_wiris_formulaEditor', 'tiny_mce_wiris_CAS');
/**
* Set plugin init parameters.
*
* @param array $params The parameters to be updated.
* @param context $context The context that the editor is used within.
* @param array $options The options passed in when requesting the editor.
*/
protected function update_init_params(array &$params, context $context,
array $options = null) {
global $PAGE, $CFG, $COURSE;
// We need to know if MathType filter are active in the context of the course.
// If not MathTYPe filter should be disabled.
// Set Course parameters to be retrieved by Telemetry.
$params['moodleCourseCategory'] = $COURSE->category;
$params['moodleCourseName'] = $COURSE->fullname;
$params['moodleVersion'] = $CFG->branch;
// Get MathType and Chemistry buttons enabled configuration.
$editorisactive = get_config('filter_wiris', 'editor_enable');
$chemistryisactive = get_config('filter_wiris', 'chem_editor_enable');
if (!get_config('filter_wiris', 'allow_editorplugin_active_course')) {
$context = context_course::instance($COURSE->id);
$activefilters = filter_get_active_in_context($context);
// Moodle 2.4 array key: filter/wiris instead of wiris.
$filterwirisactive = array_key_exists('wiris', $activefilters) || array_key_exists('filter/wiris', $activefilters);
if (!$filterwirisactive) {
return;
} else {
// Filter disabled at activity level.
$pagecontext = $PAGE->context;
// Check if context is context module.
// We need to check only module context. Other contexts (like block context)
// shouldn't be checked.
if ($pagecontext instanceof context_module) {
$activefilters = filter_get_active_in_context($PAGE->context);
// Moodle 2.4 array key: filter/wiris instead of wiris.
$filterwirisactive = array_key_exists('wiris', $activefilters);
$filterwirisactive = $filterwirisactive || array_key_exists('filter/wiris', $activefilters);
if (!$filterwirisactive) {
return;
}
}
}
}
$PAGE->requires->strings_for_js(
array(
'error_connection'
),
'tinymce_tiny_mce_wiris');
// Add button after emoticon button in advancedbuttons3.
if ($editorisactive) {
$added = $this->add_button_after($params, 3, 'tiny_mce_wiris_formulaEditor', '', false);
}
if ($chemistryisactive) {
$added = $this->add_button_after($params, 3, 'tiny_mce_wiris_formulaEditorChemistry', '', false);
}
// Add JS file using 'plugin.min.js' instead of default name.
$this->add_js_plugin($params);
}
}