-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_index.php
50 lines (47 loc) · 1.71 KB
/
create_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
<?php
if (!php_sapi_name() == "cli") {
echo "Script can only be run through CLI";
}
$thisFolder = dirname(__FILE__) . DIRECTORY_SEPARATOR;
/* Create master json file */
file_put_contents('index.json', json_encode(dirtree($thisFolder)));
/* Create subfolder json files */
foreach (dirtree($thisFolder) as $k => $dir) {
if (is_dir($thisFolder . $k)) {
$jsonFile = $thisFolder . $k . DIRECTORY_SEPARATOR . 'index.json';
$directory = dirtree($thisFolder . $k);
file_put_contents($jsonFile, json_encode($directory));
}
if ($k === 'reward' || $k === 'raid') {
foreach ($dir as $ks => $subdir) {
if (is_dir($thisFolder . $k . DIRECTORY_SEPARATOR . $ks)) {
$jsonFile = $thisFolder . $k . DIRECTORY_SEPARATOR . $ks . DIRECTORY_SEPARATOR . 'index.json';
$directory = dirtree($thisFolder . $k . DIRECTORY_SEPARATOR . $ks);
file_put_contents($jsonFile, json_encode($directory));
}
}
}
}
function dirtree($dir, $ignoreEmpty=false) {
if (!$dir instanceof DirectoryIterator) {
$dir = new DirectoryIterator((string)$dir);
}
$dirs = [];
$files = [];
foreach ($dir as $node) {
if ($node->isDir() && !$node->isDot()) {
$tree = dirtree($node->getPathname(), $ignoreEmpty);
if (!$ignoreEmpty || count($tree)) {
$dirs[$node->getFilename()] = $tree;
}
} elseif ($node->isFile()) {
$name = $node->getFilename();
if (!str_ends_with($name, '.json') && !str_ends_with($name, '.php')) {
$files[] = $name;
}
}
}
asort($dirs);
sort($files);
return array_merge($dirs, $files);
}