<?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.
*/
// We do this stuff to avoid that the client includes an external JavaScript from polyfill.io,
// since some users might have a problem with that (in regards privacy of their IP address etc.)
// So, the OIDplus webserver will act as proxy.
// see https://polyfill.io/v3/url-builder/
const REQUIRED_POLYFILLS
= array(
// Internet Explorer for various AJAX calls
'fetch',
'URL',
// Internet Explorer for OIDplusPagePublicWhois.js, OIDplusPageAdminSoftwareUpdate.js, and OIDplusPageAdminColors.js
'String.prototype.includes',
// Internet Explorer for TinyMCE if it is included inside oidplus.min.js.php ( https://github.com/tinymce/tinymce/blob/5c1702a119e683f93e03ecc2231f11d17ce57395/modules/tinymce/src/core/main/ts/api/EditorManager.ts#L271 )
'document.currentScript'
);
const MINIFY_POLYFILL = true; // TODO: put into baseconfig?
const POLYFILL_CACHE_MAX_AGE = 24 * 60 * 60; // 1 day, TODO: put into baseconfig?
# ---
require_once __DIR__ . '/includes/functions.inc.php';
if (!isset($_SERVER['HTTP_USER_AGENT'])) {
$out = '/* ERROR: No User Agent available */';
httpOutWithETag($out, 'application/javascript', 'polyfill'.(MINIFY_POLYFILL ? '.min' : '').'.js');
}
$ua = $_SERVER['HTTP_USER_AGENT'];
if (MINIFY_POLYFILL) {
$cache_file = __DIR__
. '/userdata/cache/js_polyfill_'.md5(implode(',',REQUIRED_POLYFILLS
)).'_'.md5($ua).'.min.js';
} else {
$cache_file = __DIR__
. '/userdata/cache/js_polyfill_'.md5(implode(',',REQUIRED_POLYFILLS
)).'_'.md5($ua).'.js';
}
if (MINIFY_POLYFILL) {
$url = 'https://polyfill.io/v3/polyfill.min.js?features='.urlencode(implode(',',REQUIRED_POLYFILLS
));
} else {
$url = 'https://polyfill.io/v3/polyfill.js?features='.urlencode(implode(',',REQUIRED_POLYFILLS
));
}
$cont = url_get_contents($url, $ua);
if ($cont === false) {
// In case polyfill.io is down, don't delay further requests
// Instead, try again after the next max cache age
} else {
$out = '/* ERROR: polyfill.io ('.$url.') not available and no cache file exists! */';
httpOutWithETag($out, 'application/javascript', 'polyfill'.(MINIFY_POLYFILL ? '.min' : '').'.js');
}
} else {
$cont = '/* Polyfill '.$url.' for '.$ua.' */'.$cont;
if (POLYFILL_CACHE_MAX_AGE > 0) {
}
$out = $cont;
}
} else {
}
# ---
if (!$out) $out = '';
httpOutWithETag($out, 'application/javascript', 'polyfill'.(MINIFY_POLYFILL ? '.min' : '').'.js');