Rev 419 | Rev 424 | 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 |
||
5 | * Copyright 2019 Daniel Marschall, ViaThinkSoft |
||
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'; |
112 | daniel-mar | 23 | require_once __DIR__ . '/3p/minify/src/Minify.php'; |
24 | require_once __DIR__ . '/3p/minify/src/JS.php'; |
||
25 | require_once __DIR__ . '/3p/minify/src/Exception.php'; |
||
26 | |||
27 | error_reporting(E_ALL); |
||
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 | |
420 | daniel-mar | 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'); |
||
35 | $files[] = process_file(__DIR__ . '/3p/jstree/jstree'.($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'); |
||
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 |
||
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 |
||
417 | daniel-mar | 42 | |
368 | daniel-mar | 43 | # --- |
44 | |||
45 | $files[] = 'var DEFAULT_LANGUAGE = '.json_encode(OIDplus::DEFAULT_LANGUAGE).';'; |
||
46 | |||
47 | OIDplus::registerAllPlugins('language', 'OIDplusLanguagePlugin', null); |
||
48 | $translation_array = OIDplus::getTranslationArray(); |
||
49 | $files[] = 'var language_messages = '.json_encode($translation_array).';'; |
||
50 | |||
51 | //$tbl_prefix = OIDplus::baseConfig()->getValue('OIDPLUS_TABLENAME_PREFIX',''); |
||
52 | //$files[] = 'var language_tblprefix = '.json_encode($tbl_prefix).';'; |
||
53 | $files[] = 'var language_tblprefix = "<tableprefix>";'; // hide OIDPLUS_TABLENAME_PREFIX from the client |
||
54 | |||
420 | daniel-mar | 55 | $files[] = process_file(__DIR__ . '/oidplus_base.js'); |
215 | daniel-mar | 56 | |
368 | daniel-mar | 57 | # --- |
58 | |||
420 | daniel-mar | 59 | function process_file($filename) { |
60 | $dir = dirname((strpos($filename, __DIR__.'/') === 0) ? substr($filename, strlen(__DIR__.'/')) : $filename); |
||
61 | $cont = file_get_contents($filename); |
||
62 | |||
63 | // 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 |
||
64 | $cont = str_replace("//# sourceMappingURL=", "//# sourceMappingURL=".$dir.'/', $cont); |
||
65 | |||
66 | return $cont."\n\n"; |
||
67 | } |
||
68 | |||
69 | # --- |
||
70 | |||
307 | daniel-mar | 71 | $manifests = OIDplus::getAllPluginManifests('*Pages', true); |
72 | foreach ($manifests as $manifest) { |
||
73 | foreach ($manifest->getJSFiles() as $js_file) { |
||
420 | daniel-mar | 74 | $files[] = process_file($js_file); |
277 | daniel-mar | 75 | } |
76 | } |
||
112 | daniel-mar | 77 | |
368 | daniel-mar | 78 | # --- |
362 | daniel-mar | 79 | |
417 | daniel-mar | 80 | if ($do_minify) { |
368 | daniel-mar | 81 | $minifier = null; |
82 | foreach ($files as $file) { |
||
261 | daniel-mar | 83 | if (is_null($minifier)) { |
84 | $minifier = new Minify\JS($file); |
||
85 | } else { |
||
86 | $minifier->add($file); |
||
87 | } |
||
368 | daniel-mar | 88 | } |
89 | $out = is_null($minifier) ? '' : $minifier->minify(); |
||
90 | } else { |
||
91 | $out = ''; |
||
92 | foreach ($files as $file) { |
||
364 | daniel-mar | 93 | if (file_exists($file)) { |
94 | $out .= file_get_contents($file)."\n"; |
||
95 | } else { |
||
96 | $out .= "$file\n"; |
||
97 | } |
||
215 | daniel-mar | 98 | } |
99 | } |
||
100 | |||
368 | daniel-mar | 101 | # --- |
218 | daniel-mar | 102 | |
379 | daniel-mar | 103 | httpOutWithETag($out, 'application/javascript', 'oidplus.js'); |