This repository has been archived by the owner on Mar 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
joined-js.php
55 lines (52 loc) · 1.5 KB
/
joined-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
50
51
52
53
54
55
<?php
$ver = "";
if (isset($_GET['v'])) {
$v = str_replace(".", "", trim($_GET['v']));
if ($v != "" && ctype_alnum($v)) {
$ver = ".v".$v;
}
}
if (isset($_GET['files'])) {
$joined = md5($_GET['files']).$ver;
if (is_file("./js/".$joined.".joined.js")) {
ob_start("ob_gzhandler");
header("Content-type:text/javascript;charset=utf-8");
//Caching
$cacheTime = filemtime("./js/".$joined.".joined.js");
header("Cache-Control: must-revalidate");
header("Last-Modified: ".gmdate("D, d M Y H:i:s",$cacheTime)." GMT");
header("Expires: " . gmdate("D, d M Y H:i:s", $cacheTime + 86400) . " GMT");
header('Cache-Control: max-age=604800');
readfile("./js/".$joined.".joined.js", false);
}
else {
$files = explode("|", str_replace(".", "", $_GET['files']));
$valid = array();
foreach($files as $v){
if (is_file("./js/".$v.".js")) $valid[] = $v;
}
if (count($valid)>0) {
ob_start("ob_gzhandler");
$joined = md5(join("|",$valid)).$ver;
if (is_file("./js/".$joined.".joined.js")) {
header("Content-type:text/javascript;charset=utf-8");
readfile("./js/".$joined.".joined.js", false);
}
else {
header("Content-type:text/javascript;charset=utf-8");
$buffer = "";
foreach($valid as $f) {
readfile("./js/".$f.".js", false);
echo "\n\n";
}
$fp = @fopen("./js/".$joined.".joined.js","w+");
@fwrite($fp,ob_get_contents());
@fclose($fp);
}
}
else {
die("/"."* nothing to write *"."/");
}
}
}
?>