-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
110 lines (103 loc) · 3.47 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Resource list</title>
<style>
body {
background-color: white;
padding: 1em;
}
.menu {
-webkit-column-width: 150px;
-moz-column-width: 150px;
column-width: 150px;
}
.item {
page-break-inside: avoid !important;
break-inside: avoid !important;
-webkit-column-break-inside: avoid !important;
column-break-inside: avoid: !important;
}
</style>
</head>
<body>
<?php
date_default_timezone_set('US/Eastern');
$sort = isset($_GET['sort'])?$_GET['sort']:'date';
$dirs = array();
$dir = opendir("."); // open the cwd..also do an err check.
while(false != ($subdir = readdir($dir))) {
if(is_dir($subdir) && ! in_array($subdir, [".", "..", "css", "images", "save", "log"])) {
$stat = stat("./$subdir");
$data = array(
'name'=>$subdir,
'mtime'=>$stat['mtime'],
);
$subdir_dir = opendir($subdir); // open the cwd..also do an err check.
$files = array();
while(false != ($subfile = readdir($subdir_dir))) {
$filepath= './'.$subdir.'/'.$subfile;
if(is_link($filepath)) {
$stat = stat($filepath);
$files[] = array(
'name'=>$subfile,
'mtime'=>$stat['mtime'],
);
}
}
if ($files) {
usort($files, function($a, $b) {return $a['mtime'] > $b['mtime'] ? -1 : ($a['mtime'] == $b['mtime'] ? 0 : 1);});
$data['files'] = $files;
$data['mtime'] = $files[0]['mtime'];
$dirs[] = $data;
}
}
}
usort($dirs, function($a, $b) {
global $sort;
if($sort=='date') {
return $a['mtime'] > $b['mtime'] ? -1 : ($a['mtime'] == $b['mtime'] ? 0 : 1);
} else {
return strnatcmp($a['name'], $b['name']);
}
});
echo '<div class="sort">Sort by: '.($sort=='name'?'<strong>Name</strong>':'<a href="?sort=name">Name</a>').' | '.($sort=='date'?'<strong>Last Generated</strong>':'<a href="?sort=date">Last Generated</a>').'</div>';
echo '<div><h1 style="padding-bottom:0;margin-bottom:0">Resources:</h1>';
echo '<p>(Sorted by '.($sort=='date'?'date last generated, descending':'name, ascending').')</p>';
echo '<div class="menu">';
foreach($dirs as $data) {
$files = $data['files'];
if ($files) {
$mtime = $files[0]['mtime'];
echo '<div class="item"><a class="menu-item" href="#'.$data['name'].'">'.$data['name'].'</a><br/><em>('.date("Y-m-d", $mtime).')</em></div>'."\n";
}
}
echo '</div></div>';
// print.
foreach($dirs as $data) {
$files = $data['files'];
$dir = $data['name'];
if ($files) {
usort($files, function($a, $b) {
global $sort;
if($sort=='date') {
return $a['mtime'] > $b['mtime'] ? -1 : ($a['mtime'] == $b['mtime'] ? 0 : 1);
} else {
return strnatcmp($a['name'], $b['name']);
}
});
echo "<h2 id='".$dir."'>".$dir."</h2>\n";
echo "<p>\n";
foreach($files as $file_data) {
$file = $file_data['name'];
$filepath = './'.$dir.'/'.$file;
$realfile = './'.$dir.'/'.basename(readlink($filepath));
echo '<a href="'.$realfile.'">'.basename($realfile).'</a> <em>('.date ("Y-m-d H:i:s", filemtime($filepath)).')</em><br/>'."\n";
}
echo "</p>\n";
}
}
?>
</body>
</html>