Rev 1041 | Rev 1060 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
112 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
778 | daniel-mar | 5 | * Copyright 2019 - 2022 Daniel Marschall, ViaThinkSoft |
112 | daniel-mar | 6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||
8 | * you may not use this file except in compliance with the License. |
||
9 | * You may obtain a copy of the License at |
||
10 | * |
||
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
12 | * |
||
13 | * Unless required by applicable law or agreed to in writing, software |
||
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
16 | * See the License for the specific language governing permissions and |
||
17 | * limitations under the License. |
||
18 | */ |
||
19 | |||
1050 | daniel-mar | 20 | use ViaThinkSoft\OIDplus\OIDplus; |
21 | use ViaThinkSoft\OIDplus\OIDplusLanguagePlugin; |
||
112 | daniel-mar | 22 | use MatthiasMullie\Minify; |
23 | |||
261 | daniel-mar | 24 | require_once __DIR__ . '/includes/oidplus.inc.php'; |
462 | daniel-mar | 25 | |
26 | error_reporting(OIDplus::baseConfig()->getValue('DEBUG') ? E_ALL : 0); |
||
592 | daniel-mar | 27 | @ini_set('display_errors', OIDplus::baseConfig()->getValue('DEBUG') ? '1' : '0'); |
112 | daniel-mar | 28 | |
215 | daniel-mar | 29 | $files = array(); |
112 | daniel-mar | 30 | |
417 | daniel-mar | 31 | $do_minify = OIDplus::baseConfig()->getValue('MINIFY_JS', true); |
215 | daniel-mar | 32 | |
597 | daniel-mar | 33 | $files[] = process_file(__DIR__ . '/vendor/components/jquery/jquery.js'); |
652 | daniel-mar | 34 | if (isInternetExplorer()) { |
35 | // There are several JS IE11 incompatibilities in Bootstrap 5: |
||
641 | daniel-mar | 36 | // - "const getUID = prefix => {" which is another syntax of "getUID: function getUID(prefix) {" |
37 | // - "Template strings" `...` |
||
38 | // - let {.....} = .... |
||
39 | // (more?) |
||
40 | // We don't include bootstrap.js for Internet Explorer. |
||
41 | // Therefore, the page is still displayed, although without fancy JS stuff of bootstrap |
||
42 | // Use bootstrap 4.5.0 JS as fallback (Note that the CSS is still 5.x!) |
||
43 | $files[] = process_file(__DIR__ . '/vendor/bootstrap4.min.js'); |
||
44 | $files[] = process_file(__DIR__ . '/vendor/ie11CustomProperties.min.js'); |
||
652 | daniel-mar | 45 | } else { |
46 | $files[] = process_file(__DIR__ . '/vendor/twbs/bootstrap/dist/js/bootstrap.js'); |
||
641 | daniel-mar | 47 | } |
597 | daniel-mar | 48 | $files[] = process_file(__DIR__ . '/vendor/vakata/jstree/dist/jstree.js'); |
49 | $files[] = process_file(__DIR__ . '/vendor/tinymce/tinymce/tinymce.js'); |
||
50 | $files[] = process_file(__DIR__ . '/vendor/components/jqueryui/jquery-ui.js'); |
||
51 | $files[] = process_file(__DIR__ . '/vendor/gedmarc/layout/dist/jquery.layout_and_plugins.js'); |
||
52 | $files[] = process_file(__DIR__ . '/vendor/spamspan/spamspan/spamspan.js'); |
||
53 | $files[] = process_file(__DIR__ . '/vendor/emn178/js-sha3/src/sha3.js'); |
||
833 | daniel-mar | 54 | if (!isInternetExplorer()) { |
55 | // Non IE gets Toast instead of alert() for some message types |
||
56 | // (BS5 Utils is not compatible with Internet Explorer) |
||
57 | $files[] = process_file(__DIR__ . '/vendor/script47/bs5-utils/dist/js/Bs5Utils.js'); |
||
58 | } |
||
417 | daniel-mar | 59 | |
368 | daniel-mar | 60 | # --- |
61 | |||
1041 | daniel-mar | 62 | $files[] = 'var DEFAULT_LANGUAGE = '.json_encode(OIDplus::getDefaultLang()).';'; |
368 | daniel-mar | 63 | |
1050 | daniel-mar | 64 | OIDplus::registerAllPlugins('language', OIDplusLanguagePlugin::class, null); |
368 | daniel-mar | 65 | $translation_array = OIDplus::getTranslationArray(); |
66 | $files[] = 'var language_messages = '.json_encode($translation_array).';'; |
||
67 | |||
1036 | daniel-mar | 68 | //$tbl_prefix = OIDplus::baseConfig()->getValue('TABLENAME_PREFIX',''); |
368 | daniel-mar | 69 | //$files[] = 'var language_tblprefix = '.json_encode($tbl_prefix).';'; |
1036 | daniel-mar | 70 | $files[] = 'var language_tblprefix = "<tableprefix>";'; // hide TABLENAME_PREFIX from the client |
368 | daniel-mar | 71 | |
564 | daniel-mar | 72 | // The CSRF token is set by index.php |
818 | daniel-mar | 73 | // TODO: can there race-conditions if we set csrf_token here? Or should we set it as inline-script in index.php ? |
564 | daniel-mar | 74 | $files[] = 'var csrf_token = '.js_escape(isset($_COOKIE['csrf_token']) ? $_COOKIE['csrf_token'] : '').';'; |
424 | daniel-mar | 75 | |
561 | daniel-mar | 76 | $files[] = 'var samesite_policy = '.js_escape(OIDplus::baseConfig()->getValue('COOKIE_SAMESITE_POLICY','Strict')).';'; |
77 | |||
982 | daniel-mar | 78 | $files[] = process_file(__DIR__ . '/includes/oidplus_functions.js'); |
79 | $files[] = process_file(__DIR__ . '/includes/oidplus_language.js'); |
||
448 | daniel-mar | 80 | $files[] = process_file(__DIR__ . '/includes/oidplus_base.js'); |
215 | daniel-mar | 81 | |
368 | daniel-mar | 82 | # --- |
83 | |||
420 | daniel-mar | 84 | function process_file($filename) { |
462 | daniel-mar | 85 | global $do_minify; |
86 | |||
87 | $filename_min = preg_replace('/\.[^.]+$/', '.min.js', $filename); |
||
88 | $filename_full = $filename; |
||
89 | |||
90 | if ($do_minify) { |
||
91 | if (file_exists($filename_min)) { |
||
92 | $filename = $filename_min; |
||
93 | } else if (file_exists($filename_full)) { |
||
94 | $filename = $filename_full; |
||
95 | } else { |
||
96 | return "console.error('Script file not found: $filename');"; |
||
97 | } |
||
429 | daniel-mar | 98 | } else { |
462 | daniel-mar | 99 | if (file_exists($filename_full)) { |
100 | $filename = $filename_full; |
||
101 | } else if (file_exists($filename_min)) { |
||
102 | $filename = $filename_min; |
||
103 | } else { |
||
104 | return "console.error('Script file not found: $filename');"; |
||
105 | } |
||
106 | } |
||
420 | daniel-mar | 107 | |
490 | daniel-mar | 108 | $thisdir = __DIR__; |
109 | $thisdir = str_replace('\\', '/', $thisdir); // change Windows Backslashes into Web-Slashes |
||
110 | $filename = str_replace('\\', '/', $filename); // change Windows Backslashes into Web-Slashes |
||
111 | $dir = dirname((strpos($filename, $thisdir.'/') === 0) ? substr($filename, strlen($thisdir.'/')) : $filename); |
||
462 | daniel-mar | 112 | $cont = file_get_contents($filename); |
420 | daniel-mar | 113 | |
673 | daniel-mar | 114 | // TODO: WHY???? "DevTools failed to load SourceMap: Could not load content for http://localhost/oidplus/bootstrap.css.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE" |
462 | daniel-mar | 115 | $cont = str_replace("//# sourceMappingURL=", "//# sourceMappingURL=".$dir.'/', $cont); |
116 | |||
117 | return $cont."\n\n"; |
||
420 | daniel-mar | 118 | } |
119 | |||
120 | # --- |
||
121 | |||
778 | daniel-mar | 122 | $manifests = OIDplus::getAllPluginManifests(implode(',',OIDplus::INTERACTIVE_PLUGIN_TYPES), true); // due to interface gridGeneratorLinks (1.3.6.1.4.1.37476.2.5.2.3.6) this plugin type can also have CSS |
307 | daniel-mar | 123 | foreach ($manifests as $manifest) { |
124 | foreach ($manifest->getJSFiles() as $js_file) { |
||
420 | daniel-mar | 125 | $files[] = process_file($js_file); |
277 | daniel-mar | 126 | } |
127 | } |
||
112 | daniel-mar | 128 | |
368 | daniel-mar | 129 | # --- |
362 | daniel-mar | 130 | |
417 | daniel-mar | 131 | if ($do_minify) { |
368 | daniel-mar | 132 | $minifier = null; |
133 | foreach ($files as $file) { |
||
261 | daniel-mar | 134 | if (is_null($minifier)) { |
135 | $minifier = new Minify\JS($file); |
||
136 | } else { |
||
137 | $minifier->add($file); |
||
138 | } |
||
368 | daniel-mar | 139 | } |
849 | daniel-mar | 140 | $out = is_null($minifier) ? '' : $minifier->minify(); /** @phpstan-ignore-line */ |
368 | daniel-mar | 141 | } else { |
142 | $out = ''; |
||
143 | foreach ($files as $file) { |
||
364 | daniel-mar | 144 | if (file_exists($file)) { |
145 | $out .= file_get_contents($file)."\n"; |
||
146 | } else { |
||
147 | $out .= "$file\n"; |
||
148 | } |
||
215 | daniel-mar | 149 | } |
150 | } |
||
151 | |||
368 | daniel-mar | 152 | # --- |
218 | daniel-mar | 153 | |
481 | daniel-mar | 154 | if (OIDplus::baseConfig()->getValue('DEBUG')) { |
155 | // In debug mode, we might get PHP error messages (see "error_reporting" above), |
||
156 | // so it would be severe if we would allow ETAG! (since $out does not contain the PHP error messages!) |
||
157 | header('Content-Type:application/javascript'); |
||
158 | echo $out; |
||
159 | } else { |
||
160 | httpOutWithETag($out, 'application/javascript', 'oidplus.js'); |
||
693 | daniel-mar | 161 | } |