Rev 752 | Rev 818 | 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 | |||
20 | use MatthiasMullie\Minify; |
||
21 | |||
261 | daniel-mar | 22 | require_once __DIR__ . '/includes/oidplus.inc.php'; |
462 | daniel-mar | 23 | |
24 | error_reporting(OIDplus::baseConfig()->getValue('DEBUG') ? E_ALL : 0); |
||
592 | daniel-mar | 25 | @ini_set('display_errors', OIDplus::baseConfig()->getValue('DEBUG') ? '1' : '0'); |
112 | daniel-mar | 26 | |
215 | daniel-mar | 27 | $files = array(); |
112 | daniel-mar | 28 | |
417 | daniel-mar | 29 | $do_minify = OIDplus::baseConfig()->getValue('MINIFY_JS', true); |
215 | daniel-mar | 30 | |
597 | daniel-mar | 31 | $files[] = process_file(__DIR__ . '/vendor/components/jquery/jquery.js'); |
652 | daniel-mar | 32 | if (isInternetExplorer()) { |
33 | // There are several JS IE11 incompatibilities in Bootstrap 5: |
||
641 | daniel-mar | 34 | // - "const getUID = prefix => {" which is another syntax of "getUID: function getUID(prefix) {" |
35 | // - "Template strings" `...` |
||
36 | // - let {.....} = .... |
||
37 | // (more?) |
||
38 | // We don't include bootstrap.js for Internet Explorer. |
||
39 | // Therefore, the page is still displayed, although without fancy JS stuff of bootstrap |
||
40 | // Use bootstrap 4.5.0 JS as fallback (Note that the CSS is still 5.x!) |
||
41 | $files[] = process_file(__DIR__ . '/vendor/bootstrap4.min.js'); |
||
42 | $files[] = process_file(__DIR__ . '/vendor/ie11CustomProperties.min.js'); |
||
652 | daniel-mar | 43 | } else { |
44 | $files[] = process_file(__DIR__ . '/vendor/twbs/bootstrap/dist/js/bootstrap.js'); |
||
641 | daniel-mar | 45 | } |
597 | daniel-mar | 46 | $files[] = process_file(__DIR__ . '/vendor/vakata/jstree/dist/jstree.js'); |
47 | $files[] = process_file(__DIR__ . '/vendor/tinymce/tinymce/tinymce.js'); |
||
48 | $files[] = process_file(__DIR__ . '/vendor/components/jqueryui/jquery-ui.js'); |
||
49 | $files[] = process_file(__DIR__ . '/vendor/gedmarc/layout/dist/jquery.layout_and_plugins.js'); |
||
50 | $files[] = process_file(__DIR__ . '/vendor/spamspan/spamspan/spamspan.js'); |
||
51 | $files[] = process_file(__DIR__ . '/vendor/emn178/js-sha3/src/sha3.js'); |
||
417 | daniel-mar | 52 | |
368 | daniel-mar | 53 | # --- |
54 | |||
55 | $files[] = 'var DEFAULT_LANGUAGE = '.json_encode(OIDplus::DEFAULT_LANGUAGE).';'; |
||
56 | |||
57 | OIDplus::registerAllPlugins('language', 'OIDplusLanguagePlugin', null); |
||
58 | $translation_array = OIDplus::getTranslationArray(); |
||
59 | $files[] = 'var language_messages = '.json_encode($translation_array).';'; |
||
60 | |||
61 | //$tbl_prefix = OIDplus::baseConfig()->getValue('OIDPLUS_TABLENAME_PREFIX',''); |
||
62 | //$files[] = 'var language_tblprefix = '.json_encode($tbl_prefix).';'; |
||
63 | $files[] = 'var language_tblprefix = "<tableprefix>";'; // hide OIDPLUS_TABLENAME_PREFIX from the client |
||
64 | |||
564 | daniel-mar | 65 | // The CSRF token is set by index.php |
66 | $files[] = 'var csrf_token = '.js_escape(isset($_COOKIE['csrf_token']) ? $_COOKIE['csrf_token'] : '').';'; |
||
424 | daniel-mar | 67 | |
561 | daniel-mar | 68 | $files[] = 'var samesite_policy = '.js_escape(OIDplus::baseConfig()->getValue('COOKIE_SAMESITE_POLICY','Strict')).';'; |
69 | |||
448 | daniel-mar | 70 | $files[] = process_file(__DIR__ . '/includes/oidplus_base.js'); |
215 | daniel-mar | 71 | |
368 | daniel-mar | 72 | # --- |
73 | |||
420 | daniel-mar | 74 | function process_file($filename) { |
462 | daniel-mar | 75 | global $do_minify; |
76 | |||
77 | $filename_min = preg_replace('/\.[^.]+$/', '.min.js', $filename); |
||
78 | $filename_full = $filename; |
||
79 | |||
80 | if ($do_minify) { |
||
81 | if (file_exists($filename_min)) { |
||
82 | $filename = $filename_min; |
||
83 | } else if (file_exists($filename_full)) { |
||
84 | $filename = $filename_full; |
||
85 | } else { |
||
86 | return "console.error('Script file not found: $filename');"; |
||
87 | } |
||
429 | daniel-mar | 88 | } else { |
462 | daniel-mar | 89 | if (file_exists($filename_full)) { |
90 | $filename = $filename_full; |
||
91 | } else if (file_exists($filename_min)) { |
||
92 | $filename = $filename_min; |
||
93 | } else { |
||
94 | return "console.error('Script file not found: $filename');"; |
||
95 | } |
||
96 | } |
||
420 | daniel-mar | 97 | |
490 | daniel-mar | 98 | $thisdir = __DIR__; |
99 | $thisdir = str_replace('\\', '/', $thisdir); // change Windows Backslashes into Web-Slashes |
||
100 | $filename = str_replace('\\', '/', $filename); // change Windows Backslashes into Web-Slashes |
||
101 | $dir = dirname((strpos($filename, $thisdir.'/') === 0) ? substr($filename, strlen($thisdir.'/')) : $filename); |
||
462 | daniel-mar | 102 | $cont = file_get_contents($filename); |
420 | daniel-mar | 103 | |
673 | daniel-mar | 104 | // 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 | 105 | $cont = str_replace("//# sourceMappingURL=", "//# sourceMappingURL=".$dir.'/', $cont); |
106 | |||
107 | return $cont."\n\n"; |
||
420 | daniel-mar | 108 | } |
109 | |||
110 | # --- |
||
111 | |||
778 | daniel-mar | 112 | $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 | 113 | foreach ($manifests as $manifest) { |
114 | foreach ($manifest->getJSFiles() as $js_file) { |
||
420 | daniel-mar | 115 | $files[] = process_file($js_file); |
277 | daniel-mar | 116 | } |
117 | } |
||
112 | daniel-mar | 118 | |
368 | daniel-mar | 119 | # --- |
362 | daniel-mar | 120 | |
417 | daniel-mar | 121 | if ($do_minify) { |
368 | daniel-mar | 122 | $minifier = null; |
123 | foreach ($files as $file) { |
||
261 | daniel-mar | 124 | if (is_null($minifier)) { |
125 | $minifier = new Minify\JS($file); |
||
126 | } else { |
||
127 | $minifier->add($file); |
||
128 | } |
||
368 | daniel-mar | 129 | } |
130 | $out = is_null($minifier) ? '' : $minifier->minify(); |
||
131 | } else { |
||
132 | $out = ''; |
||
133 | foreach ($files as $file) { |
||
364 | daniel-mar | 134 | if (file_exists($file)) { |
135 | $out .= file_get_contents($file)."\n"; |
||
136 | } else { |
||
137 | $out .= "$file\n"; |
||
138 | } |
||
215 | daniel-mar | 139 | } |
140 | } |
||
141 | |||
368 | daniel-mar | 142 | # --- |
218 | daniel-mar | 143 | |
481 | daniel-mar | 144 | if (OIDplus::baseConfig()->getValue('DEBUG')) { |
145 | // In debug mode, we might get PHP error messages (see "error_reporting" above), |
||
146 | // so it would be severe if we would allow ETAG! (since $out does not contain the PHP error messages!) |
||
147 | header('Content-Type:application/javascript'); |
||
148 | echo $out; |
||
149 | } else { |
||
150 | httpOutWithETag($out, 'application/javascript', 'oidplus.js'); |
||
693 | daniel-mar | 151 | } |