-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
58 lines (46 loc) · 1.25 KB
/
index.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
56
57
58
<?php
function getFilesFromDir($dir) {
$files = array();
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if(is_dir($dir.'/'.$file)) {
$dir2 = $dir.'/'.$file;
$files[] = getFilesFromDir($dir2);
}
else {
$files[] = $dir.'/'.$file;
}
}
}
closedir($handle);
}
return arrayFlat($files);
}
function arrayFlat($array) {
foreach($array as $a) {
if(is_array($a)) {
$tmp = array_merge($tmp, arrayFlat($a));
}
else {
$tmp[] = $a;
}
}
return $tmp;
}
function wrapInTags($array) {
$buffer = "";
foreach($array as $script) {
if(substr($script, -3) != '.js') continue;
$buffer .= "<script type=\"text/javascript\" src=\"$script\"></script>\r\n";
}
return $buffer;
}
$gameClasses = getFilesFromDir("js/Game");
$threeXClasses = getFilesFromDir("js/THREE");
$utilsClasses = getFilesFromDir("js/Utils");
$scriptArray = array_merge($gameClasses, $threeXClasses, $utilsClasses);
$scripts = wrapInTags($scriptArray);
$tmpl = file_get_contents("index.html");
echo str_replace('<!--scripts-->', $scripts, $tmpl);
?>