0,0 → 1,93 |
<?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'; |
|
error_reporting(E_ALL); |
|
$files = array(); |
|
$files[] = __DIR__ . '/../3p/sha3_js/sha3.js'; // https://github.com/emn178/js-sha3 |
|
$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 |
|
$files[] = 'var setupdir = "'.((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://" . $_SERVER["HTTP_HOST"] . dirname($_SERVER['REQUEST_URI'])).'/";'; |
$files[] = 'var rebuild_callbacks = [];'; |
$files[] = 'var rebuild_config_callbacks = [];'; |
$files[] = 'var plugin_combobox_change_callbacks = [];'; |
|
$found_db_plugins = 0; |
OIDplus::registerAllPlugins('database', 'OIDplusDatabasePlugin', null); |
foreach (get_declared_classes() as $c) { |
if (is_subclass_of($c, 'OIDplusDatabasePlugin')) { |
$files[] = $c::setupJS(); |
} |
} |
|
$files[] = __DIR__ . '/setup_base.js'; |
|
# --- |
|
$minifier = null; |
$out = ''; |
|
foreach ($files as $file) { |
if (OIDplus::baseConfig()->getValue('MINIFY_JS', true)) { |
if (is_null($minifier)) { |
$minifier = new Minify\JS($file); |
} else { |
$minifier->add($file); |
} |
} else { |
if (file_exists($file)) { |
$out .= file_get_contents($file)."\n"; |
} else { |
$out .= "$file\n"; |
} |
} |
} |
|
if (OIDplus::baseConfig()->getValue('MINIFY_JS', true)) { |
$out = $minifier->minify(); |
} |
|
# --- |
|
$etag = md5($out); |
header("Etag: $etag"); |
header('Content-MD5: '.$etag); // RFC 2616 clause 14.15 |
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && (trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag)) { |
header("HTTP/1.1 304 Not Modified"); |
} else { |
header('Content-Type:application/javascript'); |
echo $out; |
} |