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;
49 $this->
ctrl = $this->dic->ctrl();
50 $this->
tabs = $this->dic->tabs();
51 $this->
toolbar = $this->dic->toolbar();
52 $this->
lng = $this->dic->language();
53 $this->tpl = $this->dic->ui()->mainTemplate();
54 $this->request = $this->dic->http()->request();
55 $this->
refinery = $this->dic->refinery();
68 $this->
lng->loadLanguageModule(
'mathjax');
70 $cmd = $this->
ctrl->getCmd(
'editSettings');
78 $this->tpl->setContent(
'unknown command: ' . $cmd);
87 $testcode =
'f(x)=\int_{-\infty}^x e^{-t^2}dt';
90 $factory = $this->dic->ui()->factory()->input()->field();
93 $checkbox_transformation = $this->
refinery->custom()->transformation(
static function ($v) {
94 if (is_array($v) || is_bool($v)) {
97 return ($v ===
'checked');
101 $client_enabled = $factory->optionalGroup(
104 'client_polyfill_url' => $factory->url(
105 $this->lng->txt(
'mathjax_polyfill_url'),
107 $this->
lng->txt(
'mathjax_polyfill_url_desc_line1'),
108 $this->
lng->txt(
'mathjax_polyfill_url_desc_line2')
111 ->withValue($config->getClintPolyfillUrl()),
113 'client_script_url' => $factory->url(
114 $this->lng->txt(
'mathjax_script_url'),
117 sprintf($this->
lng->txt(
'mathjax_script_url_desc_line1'), $config->getMathJax2DefaultUrl()),
118 sprintf($this->
lng->txt(
'mathjax_script_url_desc_line2'), $config->getMathJax3DefaultUrl()),
120 )->withRequired(
true)
121 ->withValue($config->getClientScriptUrl()),
123 'client_limiter' => $factory->select(
124 $this->lng->txt(
'mathjax_limiter'),
125 $config->getClientLimiterOptions(),
126 $this->
lng->txt(
'mathjax_limiter_info')
127 )->withRequired(
true)
128 ->withValue($config->getClientLimiter()),
130 'client_test' => $factory->text(
131 $this->lng->txt(
'mathjax_test_expression'),
132 $this->
lng->txt(
'mathjax_test_expression_info_client')
134 $config->withClientEnabled(
true)
135 ->withServerEnabled(
false),
139 ->insertLatexImages(
'<p>[tex]' . $testcode .
'[/tex]</p>')
140 )->withDisabled(
true)->withValue($testcode)
143 $this->
lng->txt(
'mathjax_enable_client'),
144 $this->
lng->txt(
'mathjax_enable_client_info') .
' ' .
145 $this->
renderLink(
'mathjax_home_link',
'https://www.mathjax.org')
149 $server_enabled = $factory->optionalGroup(
151 'server_address' => $factory->url(
152 $this->lng->txt(
'mathjax_server_address'),
153 $this->
lng->txt(
'mathjax_server_address_info')
154 )->withRequired(
true)
155 ->withValue($config->getServerAddress()),
157 'server_timeout' => $factory->numeric(
158 $this->lng->txt(
'mathjax_server_timeout'),
159 $this->
lng->txt(
'mathjax_server_timeout_info')
161 ->
withValue($config->getServerTimeout()),
163 'server_for_browser' => $factory->checkbox(
164 $this->lng->txt(
'mathjax_server_for_browser'),
165 $this->
lng->txt(
'mathjax_server_for_browser_info')
166 )->
withValue($config->isServerForBrowser()),
168 'server_for_export' => $factory->checkbox(
169 $this->lng->txt(
'mathjax_server_for_export'),
170 $this->
lng->txt(
'mathjax_server_for_export_info')
171 )->
withValue($config->isServerForExport()),
173 'server_for_pdf' => $factory->checkbox(
174 $this->lng->txt(
'mathjax_server_for_pdf'),
175 $this->
lng->txt(
'mathjax_server_for_pdf_info')
178 'cache_size' => $factory->text(
179 $this->lng->txt(
'mathjax_server_cache_size'),
180 $this->
lng->txt(
'mathjax_server_cache_size_info') .
' ' .
181 $this->
renderLink(
'mathjax_server_clear_cache', $this->
ctrl->getLinkTarget($this,
'clearCache'),
false)
184 'server_test' => $factory->text(
185 $this->
lng->txt(
'mathjax_test_expression'),
186 $this->
lng->txt(
'mathjax_test_expression_info_server')
188 $config->withClientEnabled(
false)
189 ->withServerEnabled(
true)
190 ->withServerForBrowser(
true),
194 ->insertLatexImages(
'<p>[tex]' . $testcode .
'[/tex]</p>')
195 )->withDisabled(
true)->withValue($testcode)
197 $this->
lng->txt(
'mathjax_enable_server'),
198 $this->
lng->txt(
'mathjax_enable_server_info') .
' ' .
199 $this->
renderLink(
'mathjax_server_installation',
'./components/ILIAS/MathJax/docs/install-server.md')
205 $form = $this->dic->ui()->factory()->input()->container()->form()->standard($this->
ctrl->getFormAction($this), [
206 'mathjax' => $factory->section([], $this->
lng->txt(
'mathjax_settings')),
207 'client_enabled' => $config->isClientEnabled() ? $client_enabled : $client_enabled->withValue(
null),
208 'server_enabled' => $config->isServerEnabled() ? $server_enabled : $server_enabled->withValue(
null)
212 if ($this->request->getMethod() ===
"POST") {
213 $form = $form->withRequest($this->request);
214 $data = $form->getData();
219 if (is_array(
$data[
'client_enabled'])) {
220 $client_data =
$data[
'client_enabled'];
221 $config = $config->withClientEnabled(
true)
222 ->withClientPolyfillUrl((
string) $client_data[
'client_polyfill_url'])
223 ->withClientScriptUrl((
string) $client_data[
'client_script_url'])
224 ->withClientLimiter((
int) $client_data[
'client_limiter']);
226 $config = $config->withClientEnabled(
false);
229 if (is_array(
$data[
'server_enabled'])) {
230 $server_data =
$data[
'server_enabled'];
231 $config = $config->withServerEnabled(
true)
232 ->withServerAddress((
string) $server_data[
'server_address'])
233 ->withServerTimeout((
int) $server_data[
'server_timeout'])
234 ->withServerForBrowser((
bool) $server_data[
'server_for_browser'])
235 ->withServerForExport((
bool) $server_data[
'server_for_export'])
236 ->withServerForPdf((
bool) $server_data[
'server_for_pdf']);
238 $config = $config->withServerEnabled(
false);
242 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
"settings_saved"),
true);
243 $this->
ctrl->redirect($this);
247 $this->tpl->setContent($this->dic->ui()->renderer()->render($form));
256 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'mathjax_server_cache_cleared'),
true);
257 $this->
ctrl->redirect($this);
263 protected function renderLink(
string $langvar,
string $url,
bool $new_tab =
true): string
265 $link = $this->dic->ui()->factory()->link()->standard(
266 $this->
lng->txt($langvar),
269 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
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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
A factory that builds ilSettings that can be used for DI.
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.
__construct()
Constructor.
editSettings()
Edit the MathJax settings.
Repository for storing and loading the MathJax configuration.