Rev 429 | Rev 462 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 429 | Rev 448 | ||
---|---|---|---|
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * OIDplus 2.0 |
4 | * OIDplus 2.0 |
5 | * Copyright 2019 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2019 Daniel Marschall, ViaThinkSoft |
6 | * |
6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * you may not use this file except in compliance with 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 |
9 | * You may obtain a copy of the License at |
10 | * |
10 | * |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | * |
12 | * |
13 | * Unless required by applicable law or agreed to in writing, software |
13 | * Unless required by applicable law or agreed to in writing, software |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | * See the License for the specific language governing permissions and |
16 | * See the License for the specific language governing permissions and |
17 | * limitations under the License. |
17 | * limitations under the License. |
18 | */ |
18 | */ |
19 | 19 | ||
20 | use MatthiasMullie\Minify; |
20 | use MatthiasMullie\Minify; |
21 | 21 | ||
22 | require_once __DIR__ . '/includes/oidplus.inc.php'; |
22 | require_once __DIR__ . '/includes/oidplus.inc.php'; |
23 | require_once __DIR__ . '/3p/minify/src/Minify.php'; |
23 | require_once __DIR__ . '/3p/minify/src/Minify.php'; |
24 | require_once __DIR__ . '/3p/minify/src/JS.php'; |
24 | require_once __DIR__ . '/3p/minify/src/JS.php'; |
25 | require_once __DIR__ . '/3p/minify/src/Exception.php'; |
25 | require_once __DIR__ . '/3p/minify/src/Exception.php'; |
26 | 26 | ||
27 | error_reporting(E_ALL); |
27 | error_reporting(E_ALL); |
28 | 28 | ||
29 | $files = array(); |
29 | $files = array(); |
30 | 30 | ||
31 | $do_minify = OIDplus::baseConfig()->getValue('MINIFY_JS', true); |
31 | $do_minify = OIDplus::baseConfig()->getValue('MINIFY_JS', true); |
32 | 32 | ||
33 | $files[] = process_file(__DIR__ . '/3p/jquery/jquery-3.5.1'.($do_minify ? '.min' : '').'.js'); |
33 | $files[] = process_file(__DIR__ . '/3p/jquery/jquery-3.5.1'.($do_minify ? '.min' : '').'.js'); |
34 | $files[] = process_file(__DIR__ . '/3p/bootstrap4/js/bootstrap'.($do_minify ? '.min' : '').'.js'); |
34 | $files[] = process_file(__DIR__ . '/3p/bootstrap4/js/bootstrap'.($do_minify ? '.min' : '').'.js'); |
35 | $files[] = process_file(__DIR__ . '/3p/jstree/jstree'.($do_minify ? '.min' : '').'.js'); |
35 | $files[] = process_file(__DIR__ . '/3p/jstree/jstree'.($do_minify ? '.min' : '').'.js'); |
36 | $files[] = process_file(__DIR__ . '/3p/tinymce/tinymce'.($do_minify ? '.min' : '').'.js'); |
36 | $files[] = process_file(__DIR__ . '/3p/tinymce/tinymce'.($do_minify ? '.min' : '').'.js'); |
37 | $files[] = process_file(__DIR__ . '/3p/jquery-ui/jquery-ui'.($do_minify ? '.min' : '').'.js'); |
37 | $files[] = process_file(__DIR__ . '/3p/jquery-ui/jquery-ui'.($do_minify ? '.min' : '').'.js'); |
38 | $files[] = process_file(__DIR__ . '/3p/layout/jquery.layout_and_plugins'.($do_minify ? '.min' : '').'.js'); |
38 | $files[] = process_file(__DIR__ . '/3p/layout/jquery.layout_and_plugins'.($do_minify ? '.min' : '').'.js'); |
39 | $files[] = process_file(__DIR__ . '/3p/spamspan/spamspan.js'); // does not exist pre-minified |
39 | $files[] = process_file(__DIR__ . '/3p/spamspan/spamspan.js'); // does not exist pre-minified |
40 | $files[] = process_file(__DIR__ . '/3p/bignumber.js/bignumber'.($do_minify ? '.min' : '').'.js'); |
40 | $files[] = process_file(__DIR__ . '/3p/bignumber.js/bignumber'.($do_minify ? '.min' : '').'.js'); |
41 | $files[] = process_file(__DIR__ . '/3p/sha3_js/sha3.js'); // does not exist pre-minified |
41 | $files[] = process_file(__DIR__ . '/3p/sha3_js/sha3.js'); // does not exist pre-minified |
42 | 42 | ||
43 | # --- |
43 | # --- |
44 | 44 | ||
45 | $files[] = 'var DEFAULT_LANGUAGE = '.json_encode(OIDplus::DEFAULT_LANGUAGE).';'; |
45 | $files[] = 'var DEFAULT_LANGUAGE = '.json_encode(OIDplus::DEFAULT_LANGUAGE).';'; |
46 | 46 | ||
47 | OIDplus::registerAllPlugins('language', 'OIDplusLanguagePlugin', null); |
47 | OIDplus::registerAllPlugins('language', 'OIDplusLanguagePlugin', null); |
48 | $translation_array = OIDplus::getTranslationArray(); |
48 | $translation_array = OIDplus::getTranslationArray(); |
49 | $files[] = 'var language_messages = '.json_encode($translation_array).';'; |
49 | $files[] = 'var language_messages = '.json_encode($translation_array).';'; |
50 | 50 | ||
51 | //$tbl_prefix = OIDplus::baseConfig()->getValue('OIDPLUS_TABLENAME_PREFIX',''); |
51 | //$tbl_prefix = OIDplus::baseConfig()->getValue('OIDPLUS_TABLENAME_PREFIX',''); |
52 | //$files[] = 'var language_tblprefix = '.json_encode($tbl_prefix).';'; |
52 | //$files[] = 'var language_tblprefix = '.json_encode($tbl_prefix).';'; |
53 | $files[] = 'var language_tblprefix = "<tableprefix>";'; // hide OIDPLUS_TABLENAME_PREFIX from the client |
53 | $files[] = 'var language_tblprefix = "<tableprefix>";'; // hide OIDPLUS_TABLENAME_PREFIX from the client |
54 | 54 | ||
55 | if (!isset($_COOKIE['csrf_token'])) { |
55 | if (!isset($_COOKIE['csrf_token'])) { |
56 | $token = OIDplus::authUtils()->genCSRFToken(); |
56 | $token = OIDplus::authUtils()->genCSRFToken(); |
57 | setcookie('csrf_token', $token, 0, ini_get('session.cookie_path'), '', false, true); |
57 | setcookie('csrf_token', $token, 0, ini_get('session.cookie_path'), '', false, true); |
58 | $files[] = 'var csrf_token = '.js_escape($token).';'; |
58 | $files[] = 'var csrf_token = '.js_escape($token).';'; |
59 | } else { |
59 | } else { |
60 | $files[] = 'var csrf_token = '.js_escape($_COOKIE['csrf_token']).';'; |
60 | $files[] = 'var csrf_token = '.js_escape($_COOKIE['csrf_token']).';'; |
61 | } |
61 | } |
62 | 62 | ||
63 | $files[] = process_file(__DIR__ . '/oidplus_base.js'); |
63 | $files[] = process_file(__DIR__ . '/includes/oidplus_base.js'); |
64 | 64 | ||
65 | # --- |
65 | # --- |
66 | 66 | ||
67 | function process_file($filename) { |
67 | function process_file($filename) { |
68 | if (!file_exists($filename)) { |
68 | if (!file_exists($filename)) { |
69 | return "console.error('Script file not found: $filename');"; |
69 | return "console.error('Script file not found: $filename');"; |
70 | } else { |
70 | } else { |
71 | $dir = dirname((strpos($filename, __DIR__.'/') === 0) ? substr($filename, strlen(__DIR__.'/')) : $filename); |
71 | $dir = dirname((strpos($filename, __DIR__.'/') === 0) ? substr($filename, strlen(__DIR__.'/')) : $filename); |
72 | $cont = file_get_contents($filename); |
72 | $cont = file_get_contents($filename); |
73 | 73 | ||
74 | // 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 |
74 | // 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 |
75 | $cont = str_replace("//# sourceMappingURL=", "//# sourceMappingURL=".$dir.'/', $cont); |
75 | $cont = str_replace("//# sourceMappingURL=", "//# sourceMappingURL=".$dir.'/', $cont); |
76 | 76 | ||
77 | return $cont."\n\n"; |
77 | return $cont."\n\n"; |
78 | } |
78 | } |
79 | } |
79 | } |
80 | 80 | ||
81 | # --- |
81 | # --- |
82 | 82 | ||
83 | $manifests = OIDplus::getAllPluginManifests('*Pages', true); |
83 | $manifests = OIDplus::getAllPluginManifests('*Pages', true); |
84 | foreach ($manifests as $manifest) { |
84 | foreach ($manifests as $manifest) { |
85 | foreach ($manifest->getJSFiles() as $js_file) { |
85 | foreach ($manifest->getJSFiles() as $js_file) { |
86 | $files[] = process_file($js_file); |
86 | $files[] = process_file($js_file); |
87 | } |
87 | } |
88 | } |
88 | } |
89 | 89 | ||
90 | # --- |
90 | # --- |
91 | 91 | ||
92 | if ($do_minify) { |
92 | if ($do_minify) { |
93 | $minifier = null; |
93 | $minifier = null; |
94 | foreach ($files as $file) { |
94 | foreach ($files as $file) { |
95 | if (is_null($minifier)) { |
95 | if (is_null($minifier)) { |
96 | $minifier = new Minify\JS($file); |
96 | $minifier = new Minify\JS($file); |
97 | } else { |
97 | } else { |
98 | $minifier->add($file); |
98 | $minifier->add($file); |
99 | } |
99 | } |
100 | } |
100 | } |
101 | $out = is_null($minifier) ? '' : $minifier->minify(); |
101 | $out = is_null($minifier) ? '' : $minifier->minify(); |
102 | } else { |
102 | } else { |
103 | $out = ''; |
103 | $out = ''; |
104 | foreach ($files as $file) { |
104 | foreach ($files as $file) { |
105 | if (file_exists($file)) { |
105 | if (file_exists($file)) { |
106 | $out .= file_get_contents($file)."\n"; |
106 | $out .= file_get_contents($file)."\n"; |
107 | } else { |
107 | } else { |
108 | $out .= "$file\n"; |
108 | $out .= "$file\n"; |
109 | } |
109 | } |
110 | } |
110 | } |
111 | } |
111 | } |
112 | 112 | ||
113 | # --- |
113 | # --- |
114 | 114 | ||
115 | httpOutWithETag($out, 'application/javascript', 'oidplus.js'); |
115 | httpOutWithETag($out, 'application/javascript', 'oidplus.js'); |
116 | 116 |