19 declare(strict_types=1);
29 protected \ILIAS\DI\Container
$dic;
32 protected \ilLanguage
$lng;
33 protected \ilGlobalTemplateInterface
$tpl;
35 protected \Psr\Http\Message\ServerRequestInterface
$request;
51 $this->
ctrl = $this->dic->ctrl();
52 $this->
tabs = $this->dic->tabs();
53 $this->
toolbar = $this->dic->toolbar();
54 $this->
lng = $this->dic->language();
55 $this->tpl = $this->dic->ui()->mainTemplate();
56 $this->request = $this->dic->http()->request();
57 $this->
refinery = $this->dic->refinery();
72 $this->
lng->loadLanguageModule(
'mathjax');
74 $cmd = $this->
ctrl->getCmd(
'editSettings');
82 $this->tpl->setContent(
'unknown command: ' . $cmd);
91 $testcode =
'f(x)=\int_{-\infty}^x e^{-t^2}dt';
94 $factory = $this->dic->ui()->factory()->input()->field();
97 $checkbox_transformation = $this->
refinery->custom()->transformation(
static function ($v) {
98 if (is_array($v) || is_bool($v)) {
101 return ($v ===
'checked');
105 $client_enabled = $factory->optionalGroup(
108 'client_polyfill_url' => $factory->url(
109 $this->lng->txt(
'mathjax_polyfill_url'),
111 $this->
lng->txt(
'mathjax_polyfill_url_desc_line1'),
112 $this->
lng->txt(
'mathjax_polyfill_url_desc_line2')
115 ->withValue($config->getClintPolyfillUrl())
116 ->withDisabled(!$this->writable),
118 'client_script_url' => $factory->url(
119 $this->
lng->txt(
'mathjax_script_url'),
122 sprintf($this->
lng->txt(
'mathjax_script_url_desc_line1'), $config->getMathJax2DefaultUrl()),
123 sprintf($this->
lng->txt(
'mathjax_script_url_desc_line2'), $config->getMathJax3DefaultUrl()),
125 )->withRequired(
true)
126 ->withValue($config->getClientScriptUrl())
127 ->withDisabled(!$this->writable),
129 'client_limiter' => $factory->select(
130 $this->
lng->txt(
'mathjax_limiter'),
131 $config->getClientLimiterOptions(),
132 $this->
lng->txt(
'mathjax_limiter_info')
133 )->withRequired(
true)
134 ->withValue($config->getClientLimiter())
135 ->withDisabled(!$this->writable),
137 'client_test' => $factory->text(
138 $this->
lng->txt(
'mathjax_test_expression'),
139 $this->
lng->txt(
'mathjax_test_expression_info_client')
141 $config->withClientEnabled(
true)
142 ->withServerEnabled(
false),
146 ->insertLatexImages(
'<p>[tex]' . $testcode .
'[/tex]</p>')
147 )->withDisabled(
true)->withValue($testcode)
150 $this->
lng->txt(
'mathjax_enable_client'),
151 $this->
lng->txt(
'mathjax_enable_client_info') .
' ' .
152 $this->
renderLink(
'mathjax_home_link',
'https://www.mathjax.org')
154 ->withDisabled(!$this->writable);
157 $server_enabled = $factory->optionalGroup(
159 'server_address' => $factory->url(
160 $this->lng->txt(
'mathjax_server_address'),
161 $this->
lng->txt(
'mathjax_server_address_info')
162 )->withRequired(
true)
163 ->withValue($config->getServerAddress())
164 ->withDisabled(!$this->writable),
166 'server_timeout' => $factory->numeric(
167 $this->
lng->txt(
'mathjax_server_timeout'),
168 $this->
lng->txt(
'mathjax_server_timeout_info')
171 ->withDisabled(!$this->writable),
173 'server_for_browser' => $factory->checkbox(
174 $this->
lng->txt(
'mathjax_server_for_browser'),
175 $this->
lng->txt(
'mathjax_server_for_browser_info')
176 )->
withValue($config->isServerForBrowser())
177 ->withDisabled(!$this->writable),
179 'server_for_export' => $factory->checkbox(
180 $this->
lng->txt(
'mathjax_server_for_export'),
181 $this->
lng->txt(
'mathjax_server_for_export_info')
182 )->
withValue($config->isServerForExport())
183 ->withDisabled(!$this->writable),
185 'server_for_pdf' => $factory->checkbox(
186 $this->
lng->txt(
'mathjax_server_for_pdf'),
187 $this->
lng->txt(
'mathjax_server_for_pdf_info')
189 ->withDisabled(!$this->writable),
191 'cache_size' => $factory->text(
192 $this->
lng->txt(
'mathjax_server_cache_size'),
193 $this->
lng->txt(
'mathjax_server_cache_size_info') .
' ' .
194 $this->
renderLink(
'mathjax_server_clear_cache', $this->
ctrl->getLinkTarget($this,
'clearCache'),
false)
196 ->withDisabled(!$this->writable),
198 'server_test' => $factory->text(
199 $this->
lng->txt(
'mathjax_test_expression'),
200 $this->
lng->txt(
'mathjax_test_expression_info_server')
202 $config->withClientEnabled(
false)
203 ->withServerEnabled(
true)
204 ->withServerForBrowser(
true),
208 ->insertLatexImages(
'<p>[tex]' . $testcode .
'[/tex]</p>')
209 )->withDisabled(
true)->withValue($testcode)
211 $this->
lng->txt(
'mathjax_enable_server'),
212 $this->
lng->txt(
'mathjax_enable_server_info') .
' ' .
213 $this->
renderLink(
'mathjax_server_installation',
'./components/ILIAS/MathJax/docs/install-server.md')
215 ->withDisabled(!$this->writable);
220 $form = $this->dic->ui()->factory()->input()->container()->form()->standard($this->
ctrl->getFormAction($this), [
221 'mathjax' => $factory->section([], $this->
lng->txt(
'mathjax_settings')),
222 'client_enabled' => $config->isClientEnabled() ? $client_enabled : $client_enabled->withValue(null),
223 'server_enabled' => $config->isServerEnabled() ? $server_enabled : $server_enabled->withValue(null)
226 if (!$this->writable) {
227 $form = $form->withSubmitLabel($this->
lng->txt(
'refresh'));
231 if ($this->writable && $this->request->getMethod() ===
"POST") {
232 $form = $form->withRequest($this->request);
233 $data = $form->getData();
238 if (is_array(
$data[
'client_enabled'])) {
239 $client_data =
$data[
'client_enabled'];
240 $config = $config->withClientEnabled(
true)
241 ->withClientPolyfillUrl((
string) $client_data[
'client_polyfill_url'])
242 ->withClientScriptUrl((
string) $client_data[
'client_script_url'])
243 ->withClientLimiter((
int) $client_data[
'client_limiter']);
245 $config = $config->withClientEnabled(
false);
248 if (is_array(
$data[
'server_enabled'])) {
249 $server_data =
$data[
'server_enabled'];
250 $config = $config->withServerEnabled(
true)
251 ->withServerAddress((
string) $server_data[
'server_address'])
252 ->withServerTimeout((
int) $server_data[
'server_timeout'])
253 ->withServerForBrowser((
bool) $server_data[
'server_for_browser'])
254 ->withServerForExport((
bool) $server_data[
'server_for_export'])
255 ->withServerForPdf((
bool) $server_data[
'server_for_pdf']);
257 $config = $config->withServerEnabled(
false);
261 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
"settings_saved"),
true);
262 $this->
ctrl->redirect($this);
266 $this->tpl->setContent($this->dic->ui()->renderer()->render($form));
275 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'mathjax_server_cache_cleared'),
true);
276 $this->
ctrl->redirect($this);
282 protected function renderLink(
string $langvar,
string $url,
bool $new_tab =
true): string
284 $link = $this->dic->ui()->factory()->link()->standard(
285 $this->
lng->txt($langvar),
288 return $this->dic->ui()->renderer()->render($link);
renderLink(string $langvar, string $url, bool $new_tab=true)
Render an html link.
Factory for objects used by ilMathJax.
repository()
description: > Example for rendering a repository card
executeCommand()
Execute a command This should be overridden in the child classes note: permissions are already checke...
ilGlobalTemplateInterface $tpl
ilMathJaxConfigRespository $repository
__construct(bool $writable)
Constructor.
clearCache()
Clear the directory with cached LaTeX graphics.
GUI for MathJax Settings This GUI maintains the MathJax config stored in the ILIAS settings Since ILI...
ILIAS Refinery Factory $refinery
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Psr Http Message ServerRequestInterface $request
static getIndependent(ilMathJaxConfig $config, ilMathJaxFactory $factory)
Get an independent instance with a specific config for use in unit tests or on the mathjax settings p...
static getInstance()
Singleton: get instance for use in ILIAS requests with a config loaded from the settings.
editSettings()
Edit the MathJax settings.
Repository for storing and loading the MathJax configuration.