-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
128 lines (125 loc) · 3.35 KB
/
Copy pathindex.php
File metadata and controls
128 lines (125 loc) · 3.35 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
<html>
<head>
<title>Dir View</title>
<style>
body{
margin: 0;
padding: 0;
}
.container{
display: flex;
flex-direction: row;
height: 100%;
}
.browse{
overflow: scroll;
max-width: 20%;
flex-grow: 1;
flex-shrink: 2;
}
.preview{
overflow: scroll;
background: #a0a0a0;
width: auto;
flex-grow: 2;
flex-shrink: 1;
}
.dir{
}
.file{
}
.dir-a{
background-color: #dbdbdb;
font-size: smaller;
}
.file-a{
background-color: #f0f0f0;
font-size: smaller;
}
.entry{
display: block;
padding: 5px;
margin: 1px;
white-space: nowrap;
}
.dir-contents{
display: flex;
flex-direction: column;
}
</style>
</head>
<body>
<div class="container">
<div class="browse">
<div style="width:100%;display:table;">
<?php
$indent = " ";
function getDirContents($dir, &$tree) {
$files = scandir($dir);
foreach ($files as $key => $value) {
$path = $dir . DIRECTORY_SEPARATOR . $value;
if (!is_dir($path)) {
if (pathinfo($value)['extension']=="html") {
$tree[] = $path;
}
} else if ($value[0] != ".") {
$tree[$value] = array();
$subtree = getDirContents($path, $tree[$value]);
if (count($subtree)==0) {
unset($tree[$value]);
}
}
}
return $tree;
}
function printTree($tree, $depth=0){
global $indent;
foreach($tree as $key => $value) {
if (is_array($value)){
echo "<div class=\"dir\"><a class=\"dir-a entry\">" . str_repeat($indent, $depth) . "📁 $key</a>\n";
echo "<div class=\"dir-contents\" style=\"display: none;\">\n";
printTree($value, $depth+1);
echo "</div></div>\n";
} else {
$filename = pathinfo($value)['filename'];
$url = substr($value, 2);
echo "<div class=\"file\"><a class=\"file-a entry\" name=\"$url\">" . str_repeat($indent, $depth) . "📄 $filename</a></div>\n";
}
}
}
$tree = array();
$tree = getDirContents('.', $tree);
printTree($tree);
?>
</div>
</div>
<div class="preview">
<div>
<iframe style="width:100%; height:100%;" id="preview"></iframe>
</div>
</div>
</div>
<script type="text/javascript">
menus = function() {
var dirContent = this.parentElement.querySelector(".dir-contents");
console.log(dirContent);
if (dirContent.style.display === "none") {
dirContent.style.display = "block";
} else {
dirContent.style.display = "none";
}
};
preview = function() {
document.getElementById('preview').src = this.name;
}
var submenu = document.getElementsByClassName("dir-a");
for (var i = 0; i < submenu.length; i++) {
submenu[i].addEventListener('click', menus);
}
submenu = document.getElementsByClassName("file-a");
for (var i = 0; i < submenu.length; i++) {
submenu[i].addEventListener('click', preview);
}
</script>
</body>
</html>