<?php
/*
* OIDplus 2.0
* Copyright 2019 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';
require_once __DIR__ . '/3p/minify/src/Minify.php';
require_once __DIR__ . '/3p/minify/src/JS.php';
require_once __DIR__ . '/3p/minify/src/Exception.php';
$do_minify = OIDplus::baseConfig()->getValue('MINIFY_JS', true);
$files[] = process_file(__DIR__ . '/3p/jquery/jquery-3.5.1'.($do_minify ? '.min' : '').'.js');
$files[] = process_file(__DIR__ . '/3p/bootstrap4/js/bootstrap'.($do_minify ? '.min' : '').'.js');
$files[] = process_file(__DIR__ . '/3p/jstree/jstree'.($do_minify ? '.min' : '').'.js');
$files[] = process_file(__DIR__ . '/3p/tinymce/tinymce'.($do_minify ? '.min' : '').'.js');
$files[] = process_file(__DIR__ . '/3p/jquery-ui/jquery-ui'.($do_minify ? '.min' : '').'.js');
$files[] = process_file(__DIR__ . '/3p/layout/jquery.layout_and_plugins'.($do_minify ? '.min' : '').'.js');
$files[] = process_file(__DIR__ . '/3p/spamspan/spamspan.js'); // does not exist pre-minified
$files[] = process_file(__DIR__ . '/3p/bignumber.js/bignumber'.($do_minify ? '.min' : '').'.js');
$files[] = process_file(__DIR__ . '/3p/sha3_js/sha3.js'); // does not exist pre-minified
# ---
$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
if (!isset($_COOKIE['csrf_token'])) {
$token = OIDplus::authUtils()->genCSRFToken();
setcookie('csrf_token', $token, 0, ini_get('session.cookie_path'), '', false, true);
$files[] = 'var csrf_token = '.js_escape($token).';';
} else {
$files[] = 'var csrf_token = '.js_escape($_COOKIE['csrf_token']).';';
}
$files[] = process_file(__DIR__ . '/includes/oidplus_base.js');
# ---
function process_file($filename) {
return "console.error('Script file not found: $filename');";
} else {
// 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', true);
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";
}
}
}
# ---
httpOutWithETag($out, 'application/javascript', 'oidplus.js');