files _POST if files sizeof files files submit exit err function secur

 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
56
57
58
59
$files = $_POST;
if(!$files || sizeof($files) < 1 || !$files['submit'])
exit(" err ;>");
function secure($i){
return preg_replace("/[\'\"\s?!%]/","",$i);
}
$files = array_map("secure", $files);
$filename = md5(serialize($files));
$cache = "sources/cache/$filename.js";
if( !file_exists($cache) ) {
include "pack.php";
$map = parse_ini_file("sources/map.ini", true);
$result = array();
$script = "";
function loadModule( $name ){
global $map, $result;
if(!$map[$name])
return false;
$item = $map[$name];
if(!in_array($name, $result) ){
$result[$item['num']] = $name;
if( $item['depends'] ) {
$list = explode(',', $item['depends']);
foreach( $list as $l )
loadModule($l);
return true;
}
} else
return false;
}
foreach( $files as $file )
loadModule($file);
ksort($result);
foreach( $result as $r )
$script .= file_get_contents("sources/$r.txt");
$script = preg_replace( "/\s},\s}/", "}}", $script);
$packer = new JavaScriptPacker($script, 'None', false, true);
$script = $packer->pack();
file_put_contents( $cache, $script );
}
header('Content-type: text/javascript');
header('Content-Disposition: attachment; filename="Konstruktor.js"');
readfile( $cache );