Rev 1041 | Rev 1055 | 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 | |||
1050 | daniel-mar | 20 | use ViaThinkSoft\OIDplus\OIDplus; |
21 | use ViaThinkSoft\OIDplus\OIDplusLanguagePlugin; |
||
364 | daniel-mar | 22 | use MatthiasMullie\Minify; |
362 | daniel-mar | 23 | |
364 | 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'); |
362 | daniel-mar | 28 | |
364 | daniel-mar | 29 | $files = array(); |
30 | |||
490 | daniel-mar | 31 | // Note: Currently we do not use process_file() like in oidplus.min.js.php to fix relative paths |
32 | // since this script currently has no relvate resources that need to be loaded |
||
597 | daniel-mar | 33 | $files[] = __DIR__ . '/../vendor/emn178/js-sha3/src/sha3.js'; // https://github.com/emn178/js-sha3 |
34 | $files[] = __DIR__ . '/../vendor/components/jquery/jquery.js'; |
||
364 | daniel-mar | 35 | |
1041 | daniel-mar | 36 | $files[] = 'var DEFAULT_LANGUAGE = '.json_encode(OIDplus::getDefaultLang()).';'; |
364 | daniel-mar | 37 | |
1050 | daniel-mar | 38 | OIDplus::registerAllPlugins('language', OIDplusLanguagePlugin::class, null); |
362 | daniel-mar | 39 | $translation_array = OIDplus::getTranslationArray(); |
364 | daniel-mar | 40 | $files[] = 'var language_messages = '.json_encode($translation_array).';'; |
362 | daniel-mar | 41 | |
1036 | daniel-mar | 42 | //$tbl_prefix = OIDplus::baseConfig()->getValue('TABLENAME_PREFIX',''); |
362 | daniel-mar | 43 | //$files[] = 'var language_tblprefix = '.json_encode($tbl_prefix).';'; |
1036 | daniel-mar | 44 | $files[] = 'var language_tblprefix = "<tableprefix>";'; // hide TABLENAME_PREFIX from the client |
362 | daniel-mar | 45 | |
580 | daniel-mar | 46 | $files[] = 'var setupdir = "'.((OIDplus::isSSL() ? "https" : "http") . "://" . $_SERVER["HTTP_HOST"] . dirname($_SERVER['REQUEST_URI'])).'/";'; |
702 | daniel-mar | 47 | $files[] = 'var rebuild_callbacks = [];'; // Ask the database or captcha plugins for verification of their data |
48 | $files[] = /*db*/'var rebuild_config_callbacks = [];'; // Get config strings to be placed in the baseconfig file // TODO: rename to dbrebuild_config_callbacks |
||
49 | $files[] = /*db*/'var plugin_combobox_change_callbacks = [];'; // TODO: rename to dbplugin_combobox_change_callbacks |
||
50 | $files[] = /*captcha*/'var captcha_rebuild_config_callbacks = [];'; // Get config strings to be placed in the baseconfig file |
||
51 | $files[] = /*captcha*/'var captcha_plugin_combobox_change_callbacks = [];'; |
||
362 | daniel-mar | 52 | |
702 | daniel-mar | 53 | $manifests = OIDplus::getAllPluginManifests('database,captcha', true); |
411 | daniel-mar | 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 | |||
982 | daniel-mar | 64 | $files[] = __DIR__ . '/../includes/oidplus_functions.js'; |
65 | $files[] = __DIR__ . '/../includes/oidplus_language.js'; |
||
448 | daniel-mar | 66 | $files[] = __DIR__ . '/includes/setup_base.js'; |
362 | daniel-mar | 67 | |
364 | daniel-mar | 68 | # --- |
69 | |||
70 | $minifier = null; |
||
71 | $out = ''; |
||
72 | |||
73 | foreach ($files as $file) { |
||
74 | if (OIDplus::baseConfig()->getValue('MINIFY_JS', true)) { |
||
75 | if (is_null($minifier)) { |
||
76 | $minifier = new Minify\JS($file); |
||
77 | } else { |
||
78 | $minifier->add($file); |
||
79 | } |
||
80 | } else { |
||
81 | if (file_exists($file)) { |
||
82 | $out .= file_get_contents($file)."\n"; |
||
83 | } else { |
||
84 | $out .= "$file\n"; |
||
85 | } |
||
86 | } |
||
87 | } |
||
88 | |||
89 | if (OIDplus::baseConfig()->getValue('MINIFY_JS', true)) { |
||
90 | $out = $minifier->minify(); |
||
91 | } |
||
92 | |||
93 | # --- |
||
94 | |||
481 | daniel-mar | 95 | if (OIDplus::baseConfig()->getValue('DEBUG')) { |
96 | // In debug mode, we might get PHP error messages (see "error_reporting" above), |
||
97 | // so it would be severe if we would allow ETAG! (since $out does not contain the PHP error messages!) |
||
98 | header('Content-Type:application/javascript'); |
||
99 | echo $out; |
||
100 | } else { |
||
101 | httpOutWithETag($out, 'application/javascript', 'oidplus_setup.js'); |
||
102 | } |