Skip to content

Commit bd70589

Browse files
Merge pull request #93 from wiris/v4.12.2
feat: add new settings - mathjax compat, calc & graph url, maxconnect…
2 parents f46f8ab + 576c40c commit bd70589

File tree

5 files changed

+99
-15
lines changed

5 files changed

+99
-15
lines changed

classes/MoodleConfiguration.class.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ public function get($key) {
4848
return $quizzeshandurl;
4949
}
5050
}
51+
if ($key == 'quizzes.calc.url') {
52+
$quizzescalcurl = get_config('qtype_wq', 'quizzescalcurl');
53+
if (isset($quizzescalcurl) && !empty($quizzescalcurl)) {
54+
return $quizzescalcurl;
55+
}
56+
}
57+
if ($key == 'quizzes.graph.url') {
58+
$quizzesgraphurl = get_config('qtype_wq', 'quizzesgraphurl');
59+
if (isset($quizzesgraphurl) && !empty($quizzesgraphurl)) {
60+
return $quizzesgraphurl;
61+
}
62+
}
5163
if ($key == 'quizzes.wirislauncher.url') {
5264
$quizzeswirislauncherurl = get_config('qtype_wq', 'quizzeswirislauncherurl');
5365
if (isset($quizzeswirislauncherurl) && !empty($quizzeswirislauncherurl)) {
@@ -72,7 +84,12 @@ public function get($key) {
7284
if ($key == 'quizzes.httpproxy.pass' && $moodleproxyenabled && $proxypassenabled) {
7385
return $CFG->proxypassword;
7486
}
75-
87+
if ($key == 'quizzes.maxconnections') {
88+
$maxconnectionsdisabled = get_config('qtype_wq', 'maxconnections_disabled');
89+
if ($maxconnectionsdisabled) {
90+
return '-1';
91+
}
92+
}
7693
if ($key == 'quizzes.cache.dir') {
7794
return $CFG->dataroot . '/filter/wiris/cache';
7895
}

lang/en/qtype_wq.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797

9898
$string['compatibility_settings'] = 'Compatibility settings';
9999
$string['compatibility_settings_text'] = '';
100-
$string['filtercodes_compatibility_enabled'] = 'Compatibility with Filter Codes filter';
100+
$string['filtercodes_compatibility_enabled'] = 'FilterCodes compatibility';
101101
$string['filtercodes_compatibility_enabled_help'] = 'The Filter Codes filter is not compatible with certain WirisQuizzes features if the option "Escape tags" is selected. Enabling this option solves the compatibility problem. Do not enable it in any other situation.';
102102

103103
$string['privacy:metadata:qtype_wq'] = 'Information about user\'s correct answer for a given WirisQuizzes question type';
@@ -111,3 +111,15 @@
111111

112112
$string['corruptquestion_edit'] = 'WARNING: This question was corrupted and its mathematical data was lost from the database. We have tried to restore everything we could, but you need to rebuild the CalcMe algorithm if your question had one, and any custom input options and validation options. Contact with your administrator for further information.';
113113
$string['corruptquestion_attempt'] = 'The question {$a->questionname} was corrupted and could not be loaded. Please contact with your teacher so they can fix it.';
114+
115+
$string['quizzescalcurl'] = 'CalcMe URL';
116+
$string['quizzescalcurl_help'] = 'URL where to load the CalcMe web app.';
117+
118+
$string['quizzesgraphurl'] = 'Graph tool URL';
119+
$string['quizzesgraphurl_help'] = 'URL where to load the tool used for graph rendering and graphical answer questions.';
120+
121+
$string['maxconnections_disabled'] = 'Disable max connections protection';
122+
$string['maxconnections_disabled_help'] = 'Disables the protection mechanism that limits the number of concurrent connections to the WirisQuizzes server. Only enable this setting if your usage of WirisQuizzes reaches the concurrency limit and be mindful that your infrastructure will need to handle the increased number of concurrent connections to our server.';
123+
124+
$string['mathjax_compatibity'] = 'MathJax compatibility';
125+
$string['mathjax_compatibity_help'] = '(Experimental) Enables compatibility with MathJax. This option is only needed if you want to use MathJax instead of MathType to render LaTeX formulas in WirisQuizzes questions. Formulas created with MathType or WirisQuizzes will still be rendered by MathType. For the best performance, we recommend using MathType to render all formulas.';

question.php

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,24 +184,49 @@ public function format_text($text, $format, $qa, $component, $filearea, $itemid,
184184
$text = $this->base->format_text($text, $format, $qa, $component, $filearea, $itemid, $clean);
185185
$format = FORMAT_HTML;
186186
}
187-
$text = $this->expand_variables($text);
188-
187+
$text = $this->expand_variables($text);
189188
return $this->base->format_text($text, $format, $qa, $component, $filearea, $itemid, $clean);
190189
}
191190

191+
private function mathml_to_safe($input) {
192+
$safe = array('«', '»', '¨', '§', '`');
193+
$mathml = array('<', '>', '"', '&', '\'');
194+
return str_replace($mathml, $safe, $input);
195+
}
196+
192197
public function expand_variables($text) {
193198
if (isset($this->wirisquestioninstance)) {
194199
$text = $this->wirisquestioninstance->expandVariables($text);
195200
}
196-
return $this->filtercodes_compatibility($text);
201+
202+
if (get_config('qtype_wq', 'filtercodes_compatibility')) {
203+
$text = $this->filtercodes_compatibility($text);
204+
}
205+
if (get_config('qtype_wq', 'mathjax_compatibity')) {
206+
$text = $this->mathjax_compatibility($text);
207+
}
208+
209+
return $text;
210+
}
211+
212+
/**
213+
* If MathType is in client mode and we want to use MathJax to render LaTeX,
214+
* the MathJax plugin can conflict with standard MathML due to supporting
215+
* HTML inside formulae. This function replaces MathML special chars with a MathType's
216+
* safe enconding so MathJax does not interact with it.
217+
*/
218+
private function mathjax_compatibility($text) {
219+
return preg_replace_callback('/<math.*?<\/math>/s',
220+
function ($matches) {
221+
return $this->mathml_to_safe($matches[0]);
222+
},
223+
$text
224+
);
197225
}
198226

199227
private function filtercodes_compatibility($text) {
200-
$configfiltercodes = get_config('qtype_wq', 'filtercodes_compatibility');
201-
if (isset($configfiltercodes) && $configfiltercodes == '1') {
202-
$text = str_replace('[{', '[[{', $text);
203-
$text = str_replace('}]', '}]]', $text);
204-
}
228+
$text = str_replace('[{', '[[{', $text);
229+
$text = str_replace('}]', '}]]', $text);
205230
return $text;
206231
}
207232

settings.php

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,39 @@
4747
'qtype_wq/quizzesserviceurl',
4848
get_string('quizzesserviceurl', 'qtype_wq'),
4949
get_string('quizzesserviceurl_help', 'qtype_wq'),
50-
'http://www.wiris.net/demo/quizzes',
50+
'https://www.wiris.net/demo/quizzes',
5151
PARAM_URL
5252
));
5353

5454
$settings->add(new admin_setting_configtext(
5555
'qtype_wq/quizzeseditorurl',
5656
get_string('quizzeseditorurl', 'qtype_wq'),
5757
get_string('quizzeseditorurl_help', 'qtype_wq'),
58-
'http://www.wiris.net/demo/editor',
58+
'https://www.wiris.net/demo/editor',
5959
PARAM_URL
6060
));
6161

6262
$settings->add(new admin_setting_configtext(
6363
'qtype_wq/quizzeshandurl',
6464
get_string('quizzeshandurl', 'qtype_wq'),
6565
get_string('quizzeshandurl_help', 'qtype_wq'),
66-
'http://www.wiris.net/demo/hand',
66+
'https://www.wiris.net/demo/hand',
67+
PARAM_URL
68+
));
69+
70+
$settings->add(new admin_setting_configtext(
71+
'qtype_wq/quizzescalcurl',
72+
get_string('quizzescalcurl', 'qtype_wq'),
73+
get_string('quizzescalcurl_help', 'qtype_wq'),
74+
'https://calcme.com',
75+
PARAM_URL
76+
));
77+
78+
$settings->add(new admin_setting_configtext(
79+
'qtype_wq/quizzesgraphurl',
80+
get_string('quizzesgraphurl', 'qtype_wq'),
81+
get_string('quizzesgraphurl_help', 'qtype_wq'),
82+
'https://www.wiris.net/demo/graph',
6783
PARAM_URL
6884
));
6985

@@ -91,6 +107,13 @@
91107
'0'
92108
));
93109

110+
$settings->add(new admin_setting_configcheckbox(
111+
'qtype_wq/maxconnections_disabled',
112+
get_string('maxconnections_disabled', 'qtype_wq'),
113+
get_string('maxconnections_disabled_help', 'qtype_wq'),
114+
'0'
115+
));
116+
94117
$settings->add(new admin_setting_heading(
95118
'qtype_wq/compatibility_settings',
96119
get_string('compatibility_settings', 'qtype_wq'),
@@ -104,6 +127,13 @@
104127
'0'
105128
));
106129

130+
$settings->add(new admin_setting_configcheckbox(
131+
'qtype_wq/mathjax_compatibity',
132+
get_string('mathjax_compatibity', 'qtype_wq'),
133+
get_string('mathjax_compatibity_help', 'qtype_wq'),
134+
'0'
135+
));
136+
107137
$settings->add(new admin_setting_heading(
108138
'qtype_wq/troubleshooting_settings',
109139
get_string('troubleshooting_settings', 'qtype_wq'),

version.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
defined('MOODLE_INTERNAL') || die();
1818

19-
$plugin->version = 2024121901;
19+
$plugin->version = 2024121902;
2020
$plugin->requires = 2015111600; // Moodle 3.0.
21-
$plugin->release = '4.12.1';
21+
$plugin->release = '4.12.2';
2222
$plugin->maturity = MATURITY_STABLE;
2323
$plugin->component = 'qtype_wq';
2424
$plugin->dependencies = array(

0 commit comments

Comments
 (0)