21,10 → 21,37 |
// 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. |
|
if (!isset($_SERVER['HTTP_USER_AGENT'])) die(); |
define('REQUIRED_POLYFILLS', array( |
'fetch', // Internet Explorer |
'URL' // Internet Explorer |
)); |
|
define('MINIFY_POLYFILL', true); |
|
define('POLYFILL_CACHE_MAX_AGE', 24*60*60); |
|
# --- |
|
header('Content-Type:application/javascript'); |
|
if (!isset($_SERVER['HTTP_USER_AGENT'])) die('/* ERROR: No User Agent available */'); |
|
$ua = $_SERVER['HTTP_USER_AGENT']; |
|
if (MINIFY_POLYFILL) { |
$cache_file = __DIR__ . '/userdata/cache/.polyfill_'.md5(implode(',',REQUIRED_POLYFILLS)).'_'.md5($ua).'.min.js'; |
} else { |
$cache_file = __DIR__ . '/userdata/cache/.polyfill_'.md5(implode(',',REQUIRED_POLYFILLS)).'_'.md5($ua).'.js'; |
} |
|
if (!file_exists($cache_file) || (time()-filemtime($cache_file)) > POLYFILL_CACHE_MAX_AGE) { |
|
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)); |
} |
|
$opts = [ |
"http" => [ |
"method" => "GET", |
31,10 → 58,34 |
"header" => "User-Agent: ".$ua."\r\n" |
] |
]; |
|
$context = stream_context_create($opts); |
$out = file_get_contents('https://polyfill.io/v3/polyfill.min.js?features=fetch%2CURL', false, $context); |
$cont = @file_get_contents($url, false, $context); |
|
if ($cont === false) { |
|
if (file_exists($cache_file)) { |
$out = file_get_contents($cache_file); |
} else { |
die('/* ERROR: polyfill.io not available and no cache file exists! */'); |
} |
|
} else { |
|
$ua = str_replace('*/', '', $ua); |
$cont = '/* Polyfill '.$url.' for '.$ua.' */'.$cont; // TODO: escape |
|
@file_put_contents($cache_file, $cont); |
|
$out = $cont; |
|
} |
|
} else { |
|
$out = file_get_contents($cache_file); |
|
} |
|
# --- |
|
$etag = md5($out); |
43,7 → 94,5 |
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; |
} |
|