";
/* trace path */
$patharray = explode("/",$path);
$path = ""; $parent="";
$page = "main";
$username = "";
$password = "";
foreach($patharray as $dir) if ($dir != "") {
//echo "Inspecting directory '".$dir."'
\n";
if ($dir == "..") {
head($head, "ERROR");
echo "log with \"..\" not allowed.
\n";
tail();
return;
}
/* parse log */
$file = $base . "/". $path . "log";
error_reporting(0);
$fd = fopen($file, "r");
error_reporting(E_ALL);
if ($fd) {
while (!feof($fd)) {
$buffer = fgets($fd, 4096);
if (!strncmp($buffer, "#dir ", 5)) {
$temp = substr($buffer, 5, -1);
// $temp2 = strstr($temp, " ");
// if ($temp2) {
// $temp = explode(" ", $temp);
// $temp = $temp[0];
// }
if (!strcmp($temp, $dir))
break;
} else
if (!strncmp($buffer, "#password ", 10)) {
$username = $page;
$password = substr($buffer, 10, -1);
} else
if (!strncmp($buffer, "#image ", 7)) {
}
}
if (feof($fd)) {
head($head, "ERROR");
echo "Directory '$dir' is not defined in 'log' file '$file'.
\n";
tail();
return;
}
fclose($fd);
} else {
head($head, "ERROR");
echo "Failed to open 'log' file '$file'..
\n";
tail();
return;
}
/* append dir to current path */
$parent = $path;
$path = $path . $dir . "/";
$page = $dir;
}
$title = $page;
/* parse log */
$file = $base . "/" . $path . "log";
error_reporting(0);
$fd = fopen($file, "r");
$dironly = 1;
error_reporting(E_ALL);
if ($fd) {
$count = 0;
while (!feof($fd)) {
$buffer = fgets($fd, 4096);
if (!strncmp($buffer, "#img ", 5)) {
$count++;
$dironly = 0;
} else
if (!strncmp($buffer, "#dir ", 5)) {
$count++;
} else
if (!strncmp($buffer, "#title ", 7)) {
$title = substr($buffer, 7, -1);
} else
if (!strncmp($buffer, "#password ", 10)) {
$username = $page;
$password = substr($buffer, 10, -1);
}
}
fclose($fd);
} else {
head($head, "ERROR");
echo "Failed to open 'log' file '$file'.
\n";
gendir($base . "/" . $path);
tail();
return;
}
/* check password */
if ($password && (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || $username != $_SERVER['PHP_AUTH_USER'] || $password != $_SERVER['PHP_AUTH_PW'])) {
header("WWW-Authenticate: Basic realm=\"Enter user '$username' and password\"");
header("HTTP/1.0 401 Unauthorized");
echo "You are not authorized!";
exit;
}
if ($index == "true") {
head($head, $title);
echo "
\n";
//echo "Back\n";
echo "Back\n";
echo "
\n";
echo "".htmlspecialchars($title, ENT_COMPAT | ENT_HTML401, 'ISO-8859-1')."
\n";
index($title, $base, $path, $file, 6, $limit, 0, 150, 1, 0, 1);
echo "\n";
tail();
return;
}
/* create page */
head($head, $title);
/* offset selection */
echo "\n";
echo "";
if ($path)
echo "Back\n";
if (!$dironly)
echo "Thumbnails\n";
$i = 0; $j = 0;
if ($count >= $limit && !$dironly) {
while($i < $count) {
$j++;
if ($i == $offset)
echo "$j\n";
else
echo "$j\n";
$i += $limit;
}
}
echo "";
echo "
\n";
echo "".htmlspecialchars($title, ENT_COMPAT | ENT_HTML401, 'ISO-8859-1')."
\n";
echo "\n";
$fd = fopen($file, "r");
if ($fd) {
$i = 0;
while (!feof($fd)) {
$buffer = fgets($fd, 4096);
if (!strncmp($buffer, "#title ", 7))
;
else if (!strncmp($buffer, "#password ", 10))
;
else if (!strncmp($buffer, "#dirimg ", 8))
;
else if (!strncmp($buffer, "#img ", 5)) {
if ($i == $offset+$limit && !$dironly)
break;
if ($i >= $offset || $dironly)
img($base, $path, substr($buffer, 5, -1), 1000, $i);
$i++;
}
else if (!strncmp($buffer, "#dir ", 5)) {
if ($i == $offset+$limit && !$dironly)
break;
$i++;
if ($i >= $offset || $dironly) {
// $temp = substr($buffer, 5, -1);
// $temp2 = strstr($temp, " ");
// if ($temp2) {
// $temp = explode(" ", $temp);
// subdir($base, $path, $temp[0], $temp2, $limit, $dironly);
// } else {
// subdir($base, $path, $temp, "", $limit, $dironly);
// }
subdir($base, $path, substr($buffer, 5, -1), "", $limit, $dironly);
echo "
\n";
}
}
else if (!strncmp($buffer, "#media ", 7)) {
if ($i >= $offset || $dironly) {
media($path, substr($buffer, 7, -1));
}
}
else if (!strncmp($buffer, "#tags ", 6)) {
if ($i >= $offset || $dironly) {
tags(substr($buffer, 6, -1));
}
}
else if (!strncmp($buffer, "#", 1)) {
;
}
else {
/* Kommentare nur vor dem ersten Bild || Kommentare ueber und unter dem Bild || Alle, wenn kein Limit verwendet wird (dironly) */
if (($i == 0 && $offset == 0) || $i >= $offset || $dironly) {
echo "".htmlspecialchars(substr($buffer, 0, -1), ENT_COMPAT | ENT_HTML401, 'ISO-8859-1')."\n";
echo "
\n";
}
}
}
fclose($fd);
}
if ($i < $count)
echo "\n";
echo "
";
echo "";
echo "";
if ($path)
echo "Back\n";
if ($i < $count)
echo "Next\n";
echo "";
echo "";
echo "
";
tail();
function head($ver, $tit)
{
echo "\n";
echo "\n";
echo "$ver - $tit\n";
# echo "\n";
echo "\n";
echo "\n";
echo "\n";
echo "\n";
}
function tail()
{
echo "\n";
echo "\n";
}
function convert($path, $name, $base, $size)
{
/* scale image, if not yet scaled */
$src = $path . "/" . $name;
$file = $base . "/" . $src;
$psrc = $path . "pre_" . $size . "_" . $name . ".jpg";
$pfile = $base . "/" . $psrc;
error_reporting(0);
$fd = fopen($pfile, "r");
error_reporting(E_ALL);
if (!$fd) {
system("/usr/bin/convert \"" . $file . "\" -quality 50 -resize " . $size . "x" . $size . " \"" . $pfile . "\"");
} else
fclose($fd);
return $psrc;
}
/* $limit = maximum number of images to display on a page (global value)
$_limit = maximum number of images to display in the created table
*/
function index($title, $base, $path, $file, $cols, $limit, $_limit, $size, $ref, $dironly, $thumbs)
{
$i = 0;
$dirimg = "";
error_reporting(0);
$fd = fopen($file, "r");
error_reporting(E_ALL);
if (!$fd)
return;
if ($_limit)
echo "\n";
else
echo "\n";
while (!feof($fd)) {
$buffer = fgets($fd, 4096);
if (($thumbs || $dirimg == "") && !strncmp($buffer, "#img ", 5)) {
if ($i % $cols == 0)
echo "\n";
/* scale image, if not yet scaled */
$name = substr($buffer, 5, -1);
$psrc = convert($path . "/", $name, $base, $size);
$src = $path . "/" . $name;
/* present image */
echo "\n";
if ($ref)
echo " \n";
else
echo " \n";
echo " | \n";
$i++;
if (($i % $cols) == 0)
echo "
\n";
/* maximum number of images reached */
if ($i == $_limit)
break;
}
if (!strncmp($buffer, "#dirimg ", 8)) {
$dirimg = substr($buffer, 8, -1);
}
}
fclose($fd);
if ($dirimg && !($thumbs)) {
echo "\n";
$psrc = convert($path . "/", $dirimg, $base, $size * 2);
echo " \n";
echo " |
\n";
} else if ($i) {
if (($i % $cols) && ($cols - ($i % $cols) > 0)) {
echo " | \n";
echo "\n";
}
} else {
echo "| \n";
echo $title;
echo " |
\n";
}
echo "
\n";
}
function img($base, $path, $name, $size, $index)
{
$psrc = convert($path, $name, $base, $size);
$src = $path . "/" . $name;
/* present image */
echo "\n";
echo "\n";
echo "
\n";
echo "[$name]\n";
echo "\n";
echo "
\n";
}
function subdir($base, $path, $dir, $name, $limit, $dironly)
{
$file = $base . "/" . $path . $dir . "/log";
if (!$name) {
error_reporting(0);
$fd = fopen($file, "r");
error_reporting(E_ALL);
if ($fd) {
while (!feof($fd)) {
$buffer = fgets($fd, 4096);
if (!strncmp($buffer, "#title ", 7)) {
$name = substr($buffer, 7, -1);
}
}
fclose($fd);
}
}
if (!$name)
$name = $dir;
echo "\n";
echo "| \n";
echo "\n";
echo "\n";
index($name, $base, $path . $dir, $file, 2, 0, 4, 150, 0, $dironly, 0);
# index($name, $base, $path . $dir, $file, 4, 0, 4, 150, 0, $dironly, 0);
echo " | \n";
echo "\n";
echo "\n";
echo "$name\n";
echo " |
\n";
echo "\n";
}
function media($path, $name)
{
}
function tags($tags)
{
}
function gendir($dir)
{
printf("Creating " . $dir . "log with the following content:
\n");
$files = array();
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if (!strncmp($file, "pre_", 4))
continue;
if ($file[0] == '.')
continue;
if ($file == "log")
continue;
echo "filename: $file : filetype: " . filetype($dir . $file) . "
\n";
if (filetype($dir . $file) == "link")
$files[] = "#dir $file";
if (filetype($dir . $file) == "dir")
$files[] = "#dir $file";
if (filetype($dir . $file) == "file")
$files[] = "#img $file";
}
closedir($dh);
} else
printf("
Failed to open dir
\n");
$fd = fopen($dir . "log", "w");
if (!$fd) {
return;
}
sort($files);
printf("
Sorting:
\n");
foreach( $files as $file ) {
printf("$file
\n");
fprintf($fd, "$file\n");
}
printf("
Reload to see the result.
\n");
fclose($fd);
} else
printf("
Failed to read dir, because it is no directory
\n");
}
?>