<?php
/*
* OIDplus 2.0
* Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use MatthiasMullie\Minify;
require_once __DIR__ . '/includes/oidplus.inc.php';
@ini_set('display_errors', OIDplus
::baseConfig()->getValue('DEBUG') ?
'1' : '0');
$do_minify = OIDplus::baseConfig()->getValue('MINIFY_JS', true);
$files[] = process_file(__DIR__ . '/vendor/components/jquery/jquery.js');
if (isInternetExplorer()) {
// There are several JS IE11 incompatibilities in Bootstrap 5:
// - "const getUID = prefix => {" which is another syntax of "getUID: function getUID(prefix) {"
// - "Template strings" `...`
// - let {.....} = ....
// (more?)
// We don't include bootstrap.js for Internet Explorer.
// Therefore, the page is still displayed, although without fancy JS stuff of bootstrap
// Use bootstrap 4.5.0 JS as fallback (Note that the CSS is still 5.x!)
$files[] = process_file(__DIR__ . '/vendor/bootstrap4.min.js');
$files[] = process_file(__DIR__ . '/vendor/ie11CustomProperties.min.js');
} else {
$files[] = process_file(__DIR__ . '/vendor/twbs/bootstrap/dist/js/bootstrap.js');
}
$files[] = process_file(__DIR__ . '/vendor/vakata/jstree/dist/jstree.js');
$files[] = process_file(__DIR__ . '/vendor/tinymce/tinymce/tinymce.js');
$files[] = process_file(__DIR__ . '/vendor/components/jqueryui/jquery-ui.js');
$files[] = process_file(__DIR__ . '/vendor/gedmarc/layout/dist/jquery.layout_and_plugins.js');
$files[] = process_file(__DIR__ . '/vendor/spamspan/spamspan/spamspan.js');
$files[] = process_file(__DIR__ . '/vendor/mikemcl/bignumber.js/bignumber.js');
$files[] = process_file(__DIR__ . '/vendor/emn178/js-sha3/src/sha3.js');
# ---
$files[] = 'var DEFAULT_LANGUAGE = '.json_encode(OIDplus
::DEFAULT_LANGUAGE).';';
OIDplus::registerAllPlugins('language', 'OIDplusLanguagePlugin', null);
$translation_array = OIDplus::getTranslationArray();
$files[] = 'var language_messages = '.json_encode($translation_array).';';
//$tbl_prefix = OIDplus::baseConfig()->getValue('OIDPLUS_TABLENAME_PREFIX','');
//$files[] = 'var language_tblprefix = '.json_encode($tbl_prefix).';';
$files[] = 'var language_tblprefix = "<tableprefix>";'; // hide OIDPLUS_TABLENAME_PREFIX from the client
// The CSRF token is set by index.php
$files[] = 'var csrf_token = '.js_escape
(isset($_COOKIE['csrf_token']) ?
$_COOKIE['csrf_token'] : '').';';
$files[] = 'var samesite_policy = '.js_escape(OIDplus::baseConfig()->getValue('COOKIE_SAMESITE_POLICY','Strict')).';';
$files[] = process_file(__DIR__ . '/includes/oidplus_base.js');
# ---
function process_file($filename) {
global $do_minify;
$filename_min = preg_replace('/\.[^.]+$/', '.min.js', $filename);
$filename_full = $filename;
if ($do_minify) {
$filename = $filename_min;
$filename = $filename_full;
} else {
return "console.error('Script file not found: $filename');";
}
} else {
$filename = $filename_full;
$filename = $filename_min;
} else {
return "console.error('Script file not found: $filename');";
}
}
$thisdir = __DIR__;
$thisdir = str_replace('\\', '/', $thisdir); // change Windows Backslashes into Web-Slashes
$filename = str_replace('\\', '/', $filename); // change Windows Backslashes into Web-Slashes
// 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"
$cont = str_replace("//# sourceMappingURL=", "//# sourceMappingURL=".$dir.'/', $cont);
return $cont."\n\n";
}
# ---
$manifests = OIDplus::getAllPluginManifests('*Pages,objectTypes,captcha', true); // due to interface gridGeneratorLinks (1.3.6.1.4.1.37476.2.5.2.3.6) this plugin type can also have CSS
foreach ($manifests as $manifest) {
foreach ($manifest->getJSFiles() as $js_file) {
$files[] = process_file($js_file);
}
}
# ---
if ($do_minify) {
$minifier = null;
foreach ($files as $file) {
$minifier = new Minify\JS($file);
} else {
$minifier->add($file);
}
}
$out = is_null($minifier) ?
'' : $minifier->minify();
} else {
$out = '';
foreach ($files as $file) {
} else {
$out .= "$file\n";
}
}
}
# ---
if (OIDplus::baseConfig()->getValue('DEBUG')) {
// In debug mode, we might get PHP error messages (see "error_reporting" above),
// so it would be severe if we would allow ETAG! (since $out does not contain the PHP error messages!)
header('Content-Type:application/javascript');
echo $out;
} else {
httpOutWithETag($out, 'application/javascript', 'oidplus.js');
}