Skip to content

Commit 8a00b78

Browse files
committed
New: Autodetection with recursive scan of subdirectories.
1 parent e2d9ed5 commit 8a00b78

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

config.php.skel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
* If true, this script tries to find all directories in "autodetectroot".
55
* (See next option "autodetectroot".)
66
*
7-
* WARNING: Not yet implemented!
7+
* WARNING: Scans all subdirectories of $config['autodetectroot'] on each
8+
* request!
9+
*
10+
* Experimental, use with care!
811
*
912
* Values: true, false
1013
*/

index.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,39 @@ function generateImageUrl($album, $image = null, $html = true) {
3030
return $url;
3131
}
3232

33+
function directoryScanner($directory) {
34+
$result = array();
35+
$containsImage = false;
36+
$content = scandir($directory);
37+
38+
foreach ($content as $entry) {
39+
if (strstr($entry, ".jpg")
40+
|| strstr($entry, ".jpeg")
41+
|| strstr($entry, ".png")
42+
|| strstr($entry, ".gif")) {
43+
$containsImage = true;
44+
}
45+
46+
if (is_dir($directory . '/' . $entry) && substr($entry, 0, 1) != ".") {
47+
$result = $result + directoryScanner($directory . '/' . $entry);
48+
}
49+
}
50+
51+
if ($containsImage) {
52+
$title = substr(strrchr("/" . $directory, "/"), 1);
53+
$result[$title] = $directory;
54+
}
55+
56+
return $result;
57+
}
58+
3359
// Redirect to selected album
3460
if (isset($_POST['album'])) {
3561
header('Location: ' . generateImageUrl($_POST['album']));
3662
die();
3763
}
3864

39-
$directories = $config['albums'];
65+
$directories = $config['autodetect'] ? directoryScanner($config['autodetectroot']) : $config['albums'];
4066

4167
$album = $_GET['album'];
4268
$image = $_GET['image'];

0 commit comments

Comments
 (0)