-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtree.php
98 lines (81 loc) · 2.86 KB
/
tree.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
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
<html>
<head>
<title>INDEX</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<style type="text/css">
.file {
background-image:url('file.png');
background-repeat:no-repeat;
background-position:left center;
padding-left:20px;
}
.folder {
background-image:url('closed.png');
background-repeat:no-repeat;
background-position:left center;
padding-left:20px;
}
.folder.opened {
background-image:url('open.png');
}
</style>
</head>
<body>
<?php
// setup php environment
set_time_limit(0);
spl_autoload_register();
// end output buffer
ob_end_flush();
// create game folder object
$gameFolder = new \riotDecode\GameFolder('C:\\Riot Games\\League of Legends\\');
// build file tree
$fileTree = [];
foreach($gameFolder->getRiotArchiveFiles() as $rafFile) {
foreach($rafFile->getFiles() as $file) {
$currentArray = &$fileTree;
$pathBits = explode('/', $file->getPath());
for($i = 0; $i < sizeof($pathBits) - 1; $i++) {
if(!array_key_exists($pathBits[$i], $currentArray)) {
$currentArray[$pathBits[$i]] = [];
}
$currentArray = &$currentArray[$pathBits[$i]];
}
if(!array_key_exists($pathBits[$i], $currentArray)) {
$currentArray[$pathBits[$i]] = $pathBits[$i];
}
}
}
function sortTree($tree) {
ksort($tree);
$folders = [];
$files = [];
foreach($tree as $key => $value) {
if(is_string($value)) {
$files[$key] = $value;
} else {
$folders[$key] = sortTree($value);
}
}
$result = [];
foreach($folders as $key => $value) $result[$key] = $value;
foreach($files as $key => $value) $result[$key] = $value;
return $result;
}
function outputTree($tree, $level = 0, $relativePath = '') {
static $element = 0;
foreach($tree as $key => $value) {
if(is_string($value)) {
echo '<a href="content.php?file=' . urlencode($relativePath . DIRECTORY_SEPARATOR . $value) . '" class="file" style="display:inline-block;" id="element' . $element . '" target="content">' . $value . '</a><br />';
} else {
echo '<div class="folder" style="cursor:pointer;display:inline-block;" onclick="$(this).toggleClass(\'opened\');$(\'#element' . ++$element . '\').toggle()">' . $key . '</div><br />';
echo '<div style="padding-left:16px;display:none;" id="element' . $element . '">';
outputTree($value, $level + 1, $relativePath . DIRECTORY_SEPARATOR . $key);
echo '</div>';
}
}
}
outputTree(sortTree($fileTree));
?>
</body>
</html>