ILIAS  release_8 Revision v8.24
ilMathJaxSettingsGUI Class Reference

GUI for MathJax Settings This GUI maintains the MathJax config stored in the ILIAS settings Since ILIAS 8 these settings can also be written by the ILIAS setup @ilCtrl_Calls ilMathJaxSettingsGUI: More...

+ Collaboration diagram for ilMathJaxSettingsGUI:

Public Member Functions

 __construct ()
 Constructor. More...
 
 executeCommand ()
 Execute a command This should be overridden in the child classes note: permissions are already checked in the object gui. More...
 

Protected Member Functions

 editSettings ()
 Edit the MathJax settings. More...
 
 clearCache ()
 Clear the directory with cached LaTeX graphics. More...
 
 renderLink (string $langvar, string $url, bool $new_tab=true)
 Render an html link. More...
 

Protected Attributes

ILIAS DI Container $dic
 
ilCtrl $ctrl
 
ilTabsGUI $tabs
 
ilLanguage $lng
 
ilGlobalTemplateInterface $tpl
 
ilToolbarGUI $toolbar
 
Psr Http Message ServerRequestInterface $request
 
ILIAS Refinery Factory $refinery
 
ilMathJaxConfigRespository $repository
 

Detailed Description

GUI for MathJax Settings This GUI maintains the MathJax config stored in the ILIAS settings Since ILIAS 8 these settings can also be written by the ILIAS setup @ilCtrl_Calls ilMathJaxSettingsGUI:

Definition at line 27 of file class.ilMathJaxSettingsGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilMathJaxSettingsGUI::__construct ( )

Constructor.

Definition at line 43 of file class.ilMathJaxSettingsGUI.php.

44 {
45 global $DIC;
46
47 // ILIAS dependencies
48 $this->dic = $DIC;
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();
56
57 $factory = new ilSettingsFactory($DIC->database());
58 $this->repository = new ilMathJaxConfigSettingsRepository($factory->settingsFor('MathJax'));
59 }
Repository for storing and loading the MathJax configuration.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
$factory
Definition: metadata.php:75

References $DIC, $factory, ILIAS\Repository\ctrl(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), ILIAS\UI\examples\Deck\repository(), ILIAS\Repository\tabs(), and ILIAS\Repository\toolbar().

+ Here is the call graph for this function:

Member Function Documentation

◆ clearCache()

ilMathJaxSettingsGUI::clearCache ( )
protected

Clear the directory with cached LaTeX graphics.

Definition at line 253 of file class.ilMathJaxSettingsGUI.php.

253 : void
254 {
255 ilMathJax::getInstance()->clearCache();
256 $this->tpl->setOnScreenMessage('success', $this->lng->txt('mathjax_server_cache_cleared'), true);
257 $this->ctrl->redirect($this);
258 }
static getInstance()
Singleton: get instance for use in ILIAS requests with a config loaded from the settings.

References ILIAS\Repository\ctrl(), ilMathJax\getInstance(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ editSettings()

ilMathJaxSettingsGUI::editSettings ( )
protected

Edit the MathJax settings.

Definition at line 85 of file class.ilMathJaxSettingsGUI.php.

85 : void
86 {
87 $testcode = 'f(x)=\int_{-\infty}^x e^{-t^2}dt';
88
89 $config = $this->repository->getConfig();
90 $factory = $this->dic->ui()->factory()->input()->field();
91
92 // needed for the optional groups
93 $checkbox_transformation = $this->refinery->custom()->transformation(static function ($v) {
94 if (is_array($v) || is_bool($v)) {
95 return $v;
96 }
97 return ($v === 'checked');
98 });
99
100 // client-side rendering settings
101 $client_enabled = $factory->optionalGroup(
102 [
103
104 'client_polyfill_url' => $factory->url(
105 $this->lng->txt('mathjax_polyfill_url'),
106 implode('<br />', [
107 $this->lng->txt('mathjax_polyfill_url_desc_line1'),
108 $this->lng->txt('mathjax_polyfill_url_desc_line2')
109 ])
110 )
111 ->withValue($config->getClintPolyfillUrl()),
112
113 'client_script_url' => $factory->url(
114 $this->lng->txt('mathjax_script_url'),
115 implode('<br />', [
116 // Mantis #41564
117 sprintf($this->lng->txt('mathjax_script_url_desc_line1'), $config->getMathJax2DefaultUrl()),
118 sprintf($this->lng->txt('mathjax_script_url_desc_line2'), $config->getMathJax3DefaultUrl()),
119 ])
120 )->withRequired(true) // mantis #31645
121 ->withValue($config->getClientScriptUrl()),
122
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()),
129
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),
136 new ilMathJaxFactory()
137 )
139 ->insertLatexImages('<p>[tex]' . $testcode . '[/tex]</p>')
140 )->withDisabled(true)->withValue($testcode)
141
142 ],
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')
146 )->withAdditionalTransformation($checkbox_transformation);
147
148 // server-side rendering settings
149 $server_enabled = $factory->optionalGroup(
150 [
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()),
156
157 'server_timeout' => $factory->numeric(
158 $this->lng->txt('mathjax_server_timeout'),
159 $this->lng->txt('mathjax_server_timeout_info')
160 )//->withRequired(true) // mantis #31645
161 ->withValue($config->getServerTimeout()),
162
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()),
167
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()),
172
173 'server_for_pdf' => $factory->checkbox(
174 $this->lng->txt('mathjax_server_for_pdf'),
175 $this->lng->txt('mathjax_server_for_pdf_info')
176 )->withValue($config->isServerForPdf()),
177
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)
182 )->withDisabled(true)->withValue(ilMathJax::getInstance()->getCacheSize()),
183
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),
191 new ilMathJaxFactory()
192 )
194 ->insertLatexImages('<p>[tex]' . $testcode . '[/tex]</p>')
195 )->withDisabled(true)->withValue($testcode)
196 ],
197 $this->lng->txt('mathjax_enable_server'),
198 $this->lng->txt('mathjax_enable_server_info') . ' ' .
199 $this->renderLink('mathjax_server_installation', './Services/MathJax/docs/install-server.md')
200 )->withAdditionalTransformation($checkbox_transformation);
201
202
203 // build the settings form
204 // uncheck optional groups, if not enabled, see https://mantis.ilias.de/view.php?id=26476
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)
209 ]);
210
211 // apply posted inputs if form is saved
212 if ($this->request->getMethod() === "POST") {
213 $form = $form->withRequest($this->request);
214 $data = $form->getData();
215 }
216
217 // posted inputs exist and are ok => save data
218 if (isset($data)) {
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']);
225 } else {
226 $config = $config->withClientEnabled(false);
227 }
228
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']);
237 } else {
238 $config = $config->withServerEnabled(false);
239 }
240 $this->repository->updateConfig($config);
241
242 $this->tpl->setOnScreenMessage('success', $this->lng->txt("settings_saved"), true);
243 $this->ctrl->redirect($this);
244 }
245
246 // form is not posted or has valisation errors
247 $this->tpl->setContent($this->dic->ui()->renderer()->render($form));
248 }
Factory for objects used by ilMathJax.
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...
const PURPOSE_BROWSER
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:85
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:59

References $config, $data, $factory, ILIAS\Repository\ctrl(), ilMathJax\getIndependent(), ilMathJax\getInstance(), ILIAS\Repository\lng(), ilMathJax\PURPOSE_BROWSER, ILIAS\Repository\refinery(), ILIAS\UI\examples\Deck\repository(), and ILIAS\UI\Implementation\Component\Input\withValue().

+ Here is the call graph for this function:

◆ executeCommand()

ilMathJaxSettingsGUI::executeCommand ( )

Execute a command This should be overridden in the child classes note: permissions are already checked in the object gui.

Definition at line 66 of file class.ilMathJaxSettingsGUI.php.

66 : void
67 {
68 $this->lng->loadLanguageModule('mathjax');
69
70 $cmd = $this->ctrl->getCmd('editSettings');
71 switch ($cmd) {
72 case 'editSettings':
73 case 'clearCache':
74 $this->$cmd();
75 break;
76
77 default:
78 $this->tpl->setContent('unknown command: ' . $cmd);
79 }
80 }

References ILIAS\Repository\ctrl(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ renderLink()

ilMathJaxSettingsGUI::renderLink ( string  $langvar,
string  $url,
bool  $new_tab = true 
)
protected

Render an html link.

Definition at line 263 of file class.ilMathJaxSettingsGUI.php.

263 : string
264 {
265 $link = $this->dic->ui()->factory()->link()->standard(
266 $this->lng->txt($langvar),
267 $url
268 )->withOpenInNewViewport($new_tab);
269 return $this->dic->ui()->renderer()->render($link);
270 }
$url

References $url, and ILIAS\Repository\lng().

+ Here is the call graph for this function:

Field Documentation

◆ $ctrl

ilCtrl ilMathJaxSettingsGUI::$ctrl
protected

Definition at line 30 of file class.ilMathJaxSettingsGUI.php.

◆ $dic

ILIAS DI Container ilMathJaxSettingsGUI::$dic
protected

Definition at line 29 of file class.ilMathJaxSettingsGUI.php.

◆ $lng

ilLanguage ilMathJaxSettingsGUI::$lng
protected

Definition at line 32 of file class.ilMathJaxSettingsGUI.php.

◆ $refinery

ILIAS Refinery Factory ilMathJaxSettingsGUI::$refinery
protected

Definition at line 36 of file class.ilMathJaxSettingsGUI.php.

◆ $repository

ilMathJaxConfigRespository ilMathJaxSettingsGUI::$repository
protected

Definition at line 38 of file class.ilMathJaxSettingsGUI.php.

◆ $request

Psr Http Message ServerRequestInterface ilMathJaxSettingsGUI::$request
protected

Definition at line 35 of file class.ilMathJaxSettingsGUI.php.

◆ $tabs

ilTabsGUI ilMathJaxSettingsGUI::$tabs
protected

Definition at line 31 of file class.ilMathJaxSettingsGUI.php.

◆ $toolbar

ilToolbarGUI ilMathJaxSettingsGUI::$toolbar
protected

Definition at line 34 of file class.ilMathJaxSettingsGUI.php.

◆ $tpl

ilGlobalTemplateInterface ilMathJaxSettingsGUI::$tpl
protected

Definition at line 33 of file class.ilMathJaxSettingsGUI.php.


The documentation for this class was generated from the following file: