-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.js.php
49 lines (45 loc) · 1.72 KB
/
profile.js.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
try {
$config = parse_ini_file("config.ini", true);
if (file_exists(dirname(__FILE__).$config['features'])) {
$profile_time = filemtime(dirname(__FILE__).$config['features']);
} else {
exit('Failed to open'.$config['profile']);
}
if (file_exists(dirname(__FILE__).$config['javascript_src'])) {
$js_time = filemtime(dirname(__FILE__).$config['javascript_src']);
} else {
exit('Failed to open'.$config['javascript_src']);
}
if (file_exists(dirname(__FILE__).$config['javascript_cache'])) {
$cache_time = filemtime(dirname(__FILE__).$config['javascript_cache']);
}
$debug = ($config['debug'] == '1');
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
if ($cache_time < $profile_time || $cache_time < $js_time || $debug) {
$js = file_get_contents(dirname(__FILE__).$config['javascript_src']);
$profile = simplexml_load_file(dirname(__FILE__).$config['features']);
// include all of the supplied tests
$script = "";
foreach ($profile as $feature) {
if ($feature->test) { $script .= $feature['id'].":function(){".$feature->test."},"; }
}
$script = rtrim($script, ",");
$javascript = str_replace("/*[FEATURE_DETECTION]*/", $script, $js);
if (!$debug) {
// remove all /* comments */
$javascript = preg_replace("/\\/\\*.+?\\*\\//uis", '', $javascript);
// TODO: remove all // comments
// remove all extra spaces, tabs and newlines
$javascript = preg_replace("/(\s\s+|\t|\n)/",'',$javascript);
}
file_put_contents(dirname(__FILE__).$config['javascript_cache'], $javascript);
} else {
$javascript = file_get_contents(dirname(__FILE__).$config['javascript_cache']);
}
header("content-type: application/x-javascript");
flush();
echo $javascript;
?>