This repository was archived by the owner on Jan 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlistminutes.php
More file actions
executable file
·64 lines (56 loc) · 1.76 KB
/
listminutes.php
File metadata and controls
executable file
·64 lines (56 loc) · 1.76 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
<?php
function dirList ($dir, $level = 0)
{
$results = array();
$files = scandir($dir, $level==0); // If $level is 0 (top directory) sort DESC (parameter=1), otherwise sort ASC
// Remove unwanted entries
if (($idx = array_search('minutes_pre1990_unknown-01.png', $files)) !== FALSE) unset($files[$idx]);
if (($idx = array_search('README.md', $files)) !== FALSE) unset($files[$idx]);
$files = array_values($files);
// Move subdirectories to the top of the list
if ($level != 0) {
for($i=count($files)-1, $j=0 ; $i >= $j ; $i--) {
if (is_dir($dir.'/'.$files[$i])) {
array_unshift($files, $files[$i]); // Move directory to the front of the array
unset($files[$i+1]); // Remove it from it's current location to avoid duplicates ($i+1 because we've been shifted down 1)
$i++; // Indexes above current location have shifted down, correct this so we don't jump over the next file
$j++; // Directories that have been moved to the top must be ignored
}
}
}
foreach($files as $file){
if ($file[0] == '.') {
continue;
}
// if the file is actually a directory
if (is_dir($dir.'/'.$file)) {
$d = array('name' => $file);
$list = dirList($dir.'/'.$file, $level+1); // recursion
$d['contents'] = $list;
$results['dirs'][] = $d;
} else {
switch(strtolower(substr($file, -3, 3))) {
case 'gif':
case 'jpg':
case 'jpeg':
case 'bmp':
case 'png':
$thumbnail = 'png';
break;
case 'pdf':
$thumbnail = 'pdf';
break;
case 'txt':
$thumbnail = 'txt';
break;
default:
$thumbnail = 'unknown';
}
$results['files'][] = array('name' => $file, 'thumb' => $thumbnail, 'path' => $dir.'/'.$file);
}
}
return $results;
}
$files = dirList('minutes');
echo json_encode($files);
?>