forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.php
More file actions
133 lines (106 loc) · 3.16 KB
/
Copy pathbuild.php
File metadata and controls
133 lines (106 loc) · 3.16 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
// Global
// $files = dirToArray(dirname(__FILE__));
$files = dirToArray('../');
$total = 0;
foreach ($files as $key => $value)
{
if (is_array($value) && count($value) > 0)
{
$total += count($value);
}
}
function getFile() {
global $files, $dir, $filename, $title, $code;
if (isset($_GET['d']) && isset($_GET['f']))
{
$dir = urldecode($_GET['d']);
$filename = urldecode($_GET['d']) . '/' . urldecode($_GET['f']);
$title = urldecode($_GET['t']);
if (file_exists($filename))
{
$code = file_get_contents($filename);
$files = dirToArray($dir);
}
}
}
function dirToArray($dir) {
$ignore = array('.', '..', '_site', 'assets', 'states', 'wip', 'games', 'basics');
$result = array();
$root = scandir($dir);
$dirs = array_diff($root, $ignore);
// We want these 2 to appear top of the list
array_unshift($dirs, 'basics', 'games');
foreach ($dirs as $key => $value)
{
if (is_dir($dir . DIRECTORY_SEPARATOR . $value))
{
$result[$value] = dirToArray($dir . DIRECTORY_SEPARATOR . $value);
}
else
{
if (substr($value, -3) == '.js')
{
$result[] = $value;
}
}
}
return $result;
}
function printJSLinks($dir, $files, $target) {
$output = "";
foreach ($files as $key => $value)
{
$value2 = substr($value, 0, -3);
$dir = urlencode($dir);
$file = urlencode($value);
$title = urlencode($value2);
if ($target == 'viewer')
{
$output .= " <a href=\"view_lite.php?d=$dir&f=$file&t=$title\" target=\"viewer\">$value2</a></br>\n";
}
else if ($target == 'json')
{
$output .= " { \"file\": \"$file\", \"title\": \"$value2\" },\n";
}
else
{
$output .= " <li><a href=\"view_full.php?d=$dir&f=$file&t=$title\">$value2</a></li>\n";
}
}
if ($target == 'json')
{
$output = rtrim($output);
$output = substr($output, 0, -1);
$output .= "\n";
}
return $output;
}
?>
<html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
<title>Phaser Examples JSON Build Script</title>
</head>
<body>
<textarea style="width: 800px; height: 800px">
<?php
$output = "{\n";
foreach ($files as $key => $value)
{
if (is_array($value) && count($value) > 0)
{
$output .= "\"$key\": [\n";
$output .= printJSLinks($key, $value, 'json');
$output .= "],\n";
}
}
$output = rtrim($output);
$output = substr($output, 0, -1);
$output .= "\n}";
echo $output;
file_put_contents('examples.json', $output);
?>
</textarea>
</body>
</html>