Skip to content

Commit

Permalink
New: Autodetection with recursive scan of subdirectories.
Browse files Browse the repository at this point in the history
  • Loading branch information
SammysHP committed Sep 29, 2012
1 parent e2d9ed5 commit 8a00b78
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
5 changes: 4 additions & 1 deletion config.php.skel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
* If true, this script tries to find all directories in "autodetectroot".
* (See next option "autodetectroot".)
*
* WARNING: Not yet implemented!
* WARNING: Scans all subdirectories of $config['autodetectroot'] on each
* request!
*
* Experimental, use with care!
*
* Values: true, false
*/
Expand Down
28 changes: 27 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,39 @@ function generateImageUrl($album, $image = null, $html = true) {
return $url;
}

function directoryScanner($directory) {
$result = array();
$containsImage = false;
$content = scandir($directory);

foreach ($content as $entry) {
if (strstr($entry, ".jpg")
|| strstr($entry, ".jpeg")
|| strstr($entry, ".png")
|| strstr($entry, ".gif")) {
$containsImage = true;
}

if (is_dir($directory . '/' . $entry) && substr($entry, 0, 1) != ".") {
$result = $result + directoryScanner($directory . '/' . $entry);
}
}

if ($containsImage) {
$title = substr(strrchr("/" . $directory, "/"), 1);
$result[$title] = $directory;
}

return $result;
}

// Redirect to selected album
if (isset($_POST['album'])) {
header('Location: ' . generateImageUrl($_POST['album']));
die();
}

$directories = $config['albums'];
$directories = $config['autodetect'] ? directoryScanner($config['autodetectroot']) : $config['albums'];

$album = $_GET['album'];
$image = $_GET['image'];
Expand Down

0 comments on commit 8a00b78

Please sign in to comment.