ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
latex.php
Go to the documentation of this file.
1 <?php
2 
3 $steps = 0;
4 while (!file_exists('ilias.ini.php')) {
5  chdir('..');
6  ++$steps;
7 }
8 
9 require_once 'Services/Init/classes/class.ilInitialisation.php';
11 
16 global $DIC;
17 $ilIliasIniFile = $DIC['ilIliasIniFile'];
18 $ilUser = $DIC['ilUser'];
19 
20 global $DIC;
21 
22 $htdocs = $ilIliasIniFile->readVariable('server', 'absolute_path') . '/';
23 $weburl = $ilIliasIniFile->readVariable('server', 'absolute_path') . '/';
24 if (defined('ILIAS_HTTP_PATH')) {
25  $weburl = substr(ILIAS_HTTP_PATH, 0, strrpos(ILIAS_HTTP_PATH, '/node_modules')) . '/';
26 }
28 
29 if ($DIC->http()->request()->getMethod() == "GET" && isset($DIC->http()->request()->getQueryParams()['tex'])) {
30  $text = ilMathJax::getInstance()->insertLatexImages(
31  '[tex]' .
32  ilUtil::stripSlashes((string) ($DIC->http()->request()->getQueryParams()['tex'] ?? '')) .
33  '[/tex]'
34  );
35  $responseStream = \ILIAS\Filesystem\Stream\Streams::ofString($text);
36  $DIC->http()->saveResponse($DIC->http()->response()->withBody($responseStream));
37  $DIC->http()->sendResponse();
38  $DIC->http()->close();
39 }
40 
41 $tpl = new ilRTEGlobalTemplate(__DIR__ . '/tpl.latex.html', true, true);
42 $tpl->setVariable("ILIAS_INST_PATH", $iliasHttpPath);
43 
44 $tpl->resetJavascript();
45 
46 require_once 'Services/jQuery/classes/class.iljQueryUtil.php';
48 if (strpos($jquery_path, './') === 0) {
49  $jquery_path = substr($jquery_path, 2);
50 } elseif (strpos($jquery_path, '.') === 0) {
51  $jquery_path = substr($jquery_path, 1);
52 }
53 
54 $mathJaxSetting = new ilSetting('MathJax');
55 if ($mathJaxSetting->get('enable_server') && $mathJaxSetting->get('server_for_browser')) {
56  $tpl->setCurrentBlock('js_on_change_server_math_jax');
57  $tpl->touchBlock('js_on_change_server_math_jax');
58  $tpl->parseCurrentBlock();
59 } elseif ($mathJaxSetting->get('enable')) {
60  $pathToMathJax = $mathJaxSetting->get('path_to_mathjax');
61  if (
62  false === strpos($pathToMathJax, '//') &&
63  false === strpos($pathToMathJax, 'https://') &&
64  false === strpos($pathToMathJax, 'http://')
65  ) {
66  $pathToMathJax = str_repeat('../', $steps) . $pathToMathJax;
67  }
68  $tpl->addJavaScript($pathToMathJax);
69 
70  $tpl->setCurrentBlock('js_on_change_math_jax');
71  $tpl->setVariable('DELIMITER', (int) $mathJaxSetting->get('limiter'));
72  $tpl->parseCurrentBlock();
73 } elseif (strlen($ilIliasIniFile->readVariable('tools', 'latex'))) {
74  $tpl->setCurrentBlock('js_on_change_latex');
75  $tpl->setVariable('LATEX_URL', $ilIliasIniFile->readVariable('tools', 'latex'));
76  $tpl->parseCurrentBlock();
77 }
78 
79 $tpl->addJavaScript(str_repeat('../', $steps) . $jquery_path, true, 1);
80 $tpl->fillJavaScriptFiles(true);
81 $tpl->printToStdout('DEFAULT', false, true);
$weburl
Definition: latex.php:23
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
if(strpos($jquery_path, './')===0) elseif(strpos($jquery_path, '.')===0) $mathJaxSetting
Definition: latex.php:54
static initILIAS()
ilias initialisation
$jquery_path
Definition: latex.php:47
$steps
Definition: latex.php:3
$ilIliasIniFile
Definition: latex.php:17
static ofString(string $string)
Creates a new stream with an initial value.
Definition: Streams.php:43
global $DIC
Definition: latex.php:16
static getInstance()
Singleton: get instance for use in ILIAS requests with a config loaded from the settings.
$htdocs
Definition: latex.php:22
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
static getLocaljQueryPath()
if(defined('ILIAS_HTTP_PATH')) $iliasHttpPath
Definition: latex.php:27
$ilUser
Definition: latex.php:18