Rev 490 | Rev 561 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
362 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
511 | daniel-mar | 5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
362 | 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 | |||
364 | daniel-mar | 20 | use MatthiasMullie\Minify; |
362 | daniel-mar | 21 | |
364 | daniel-mar | 22 | require_once __DIR__ . '/../includes/oidplus.inc.php'; |
462 | daniel-mar | 23 | |
364 | daniel-mar | 24 | require_once __DIR__ . '/../3p/minify/src/Minify.php'; |
25 | require_once __DIR__ . '/../3p/minify/src/JS.php'; |
||
26 | require_once __DIR__ . '/../3p/minify/src/Exception.php'; |
||
362 | daniel-mar | 27 | |
462 | daniel-mar | 28 | error_reporting(OIDplus::baseConfig()->getValue('DEBUG') ? E_ALL : 0); |
486 | daniel-mar | 29 | @ini_set('display_errors', OIDplus::baseConfig()->getValue('DEBUG') ? 1 : 0); |
362 | daniel-mar | 30 | |
364 | daniel-mar | 31 | $files = array(); |
32 | |||
490 | daniel-mar | 33 | // Note: Currently we do not use process_file() like in oidplus.min.js.php to fix relative paths |
34 | // since this script currently has no relvate resources that need to be loaded |
||
364 | daniel-mar | 35 | $files[] = __DIR__ . '/../3p/sha3_js/sha3.js'; // https://github.com/emn178/js-sha3 |
36 | |||
37 | $files[] = 'var DEFAULT_LANGUAGE = '.json_encode(OIDplus::DEFAULT_LANGUAGE).';'; |
||
38 | |||
362 | daniel-mar | 39 | OIDplus::registerAllPlugins('language', 'OIDplusLanguagePlugin', null); |
40 | $translation_array = OIDplus::getTranslationArray(); |
||
364 | daniel-mar | 41 | $files[] = 'var language_messages = '.json_encode($translation_array).';'; |
362 | daniel-mar | 42 | |
43 | //$tbl_prefix = OIDplus::baseConfig()->getValue('OIDPLUS_TABLENAME_PREFIX',''); |
||
44 | //$files[] = 'var language_tblprefix = '.json_encode($tbl_prefix).';'; |
||
364 | daniel-mar | 45 | $files[] = 'var language_tblprefix = "<tableprefix>";'; // hide OIDPLUS_TABLENAME_PREFIX from the client |
362 | daniel-mar | 46 | |
364 | daniel-mar | 47 | $files[] = 'var setupdir = "'.((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://" . $_SERVER["HTTP_HOST"] . dirname($_SERVER['REQUEST_URI'])).'/";'; |
48 | $files[] = 'var rebuild_callbacks = [];'; |
||
49 | $files[] = 'var rebuild_config_callbacks = [];'; |
||
50 | $files[] = 'var plugin_combobox_change_callbacks = [];'; |
||
362 | daniel-mar | 51 | |
380 | daniel-mar | 52 | OIDplus::registerAllPlugins('database', 'OIDplusDatabasePlugin', array('OIDplus','registerDatabasePlugin')); |
411 | daniel-mar | 53 | $manifests = OIDplus::getAllPluginManifests('database', true); |
54 | foreach ($manifests as $manifest) { |
||
55 | foreach ($manifest->getJsFilesSetup() as $js_file) { |
||
429 | daniel-mar | 56 | if (!file_exists($js_file)) { |
57 | $files[] = "console.error('Script file not found: $js_file');"; |
||
58 | } else { |
||
59 | $files[] = $js_file; |
||
60 | } |
||
411 | daniel-mar | 61 | } |
362 | daniel-mar | 62 | } |
63 | |||
448 | daniel-mar | 64 | $files[] = __DIR__ . '/includes/setup_base.js'; |
362 | daniel-mar | 65 | |
364 | daniel-mar | 66 | # --- |
67 | |||
68 | $minifier = null; |
||
69 | $out = ''; |
||
70 | |||
71 | foreach ($files as $file) { |
||
72 | if (OIDplus::baseConfig()->getValue('MINIFY_JS', true)) { |
||
73 | if (is_null($minifier)) { |
||
74 | $minifier = new Minify\JS($file); |
||
75 | } else { |
||
76 | $minifier->add($file); |
||
77 | } |
||
78 | } else { |
||
79 | if (file_exists($file)) { |
||
80 | $out .= file_get_contents($file)."\n"; |
||
81 | } else { |
||
82 | $out .= "$file\n"; |
||
83 | } |
||
84 | } |
||
85 | } |
||
86 | |||
87 | if (OIDplus::baseConfig()->getValue('MINIFY_JS', true)) { |
||
88 | $out = $minifier->minify(); |
||
89 | } |
||
90 | |||
91 | # --- |
||
92 | |||
481 | daniel-mar | 93 | if (OIDplus::baseConfig()->getValue('DEBUG')) { |
94 | // In debug mode, we might get PHP error messages (see "error_reporting" above), |
||
95 | // so it would be severe if we would allow ETAG! (since $out does not contain the PHP error messages!) |
||
96 | header('Content-Type:application/javascript'); |
||
97 | echo $out; |
||
98 | } else { |
||
99 | httpOutWithETag($out, 'application/javascript', 'oidplus_setup.js'); |
||
100 | } |