|
/***************************************************
Compare functions for files.php and photogallery.php
***************************************************/
function name_cmp($a, $b)
{
return strcasecmp($a["name"], $b["name"]);
}
function date_cmp($a, $b)
{
return $a["date"] > $b["date"];
}
function size_cmp($a, $b)
{
return $a["size"] > $b["size"];
}
function descr_cmp($a, $b)
{
return strcasecmp($a["descr"], $b["descr"]);
}
function type_cmp($a, $b)
{
return strcasecmp($a["type"], $b["type"]);
}
?>
/*
Script by Tuomas Airaksinen
and Maarten den Braber
Ideas from imgconvert.sh by Garrett LeSage
Published under GNU General Public Licence (GPL)
You should get whole license information in COPYING
file distributed with this file. For more information
see http://www.gnu.org */
$version = "v1.1.5";
$action = $_GET["action"];
$picture = $_GET["picture"];
$number = $_GET["number"];
$pagenum = $_GET["pagenum"];
#-----------------------------------------------------------------
# Help text above the gallery - LUXEMBOURGISH
$help_lux = "Op d'Fotoën klicken fir se ze vergréisseren";
$backtogallery_lux = "Zerëck an d'Iwwersiicht";
$pagestr_lux = "Sait";
# Help text above the gallery - FRENCH
$help_fr = "Cliquer sur les photos pour les agrandir";
$backtogallery_fr = "Retour au contenu";
$pagestr_fr = "Page";
#-----------------------------------------------------------------
if ($language == "lux")
{
$help = $help_lux;
$backtogallery = $backtogallery_lux;
$pagestr = $pagestr_lux;
}
else
{
$help = $help_fr;
$backtogallery = $backtogallery_fr;
$pagestr = $pagestr_fr;
}
# Tags for the start of a picture-table
$tablestart = "";
/*
See http://tuma.stc.cx/gallery.php for more info
*/
# we make an array which contains list of images (-> sorting)
$othumbdir = dir($thumbdir);
$pictures = array();
while($entry = $othumbdir->read())
{
if(is_file("$thumbdir/$entry") && is_readable("$thumbdir/$entry"))
{
array_push($pictures, array("name" => $entry,
"date" => filemtime("$thumbdir/$entry"),
"size" => filesize("$thumbdir/$entry")));
}
}
$othumbdir->close();
#then we can sort information as ordered
if(! $sort)
$sort = "name";
usort($pictures, $sort . "_cmp");
if (! $included )
{
echo "\n";
echo "Fotogalerie\n";
}
if (! $number)
$number = $defnumber;
if (! $pagenum)
$pagenum = 1;
/* Some helper functions */
function get_pictinfo($picture)
{
global $infofile;
# Read the infofile
$fp=fopen($infofile,"r");
$contents=fread($fp, filesize($infofile));
fclose($fp);
$start = strpos($contents,$picture) + strlen($picture);
$tmpstr = substr($contents,$start,strlen($contents));
$stop = strpos($tmpstr, "\n");
$pictinfo = substr($contents,$start,$stop);
return $pictinfo;
}
/*function num2picture($num)
{
global $thumbdir;
$othumbdir = dir($thumbdir);
for($count=0; $count<=($num+1); $count++)
{
$entry=$othumbdir->read();
}
$othumbdir->close;
return $entry;
}
function picture2num($picture)
{
global $thumbdir;
$count = 0;
$othumbdir = dir($thumbdir);
while($entry=$othumbdir->read())
{
$count++;
if($entry == $picture)
break;
}
$othumbdir->close;
return $count - 2; // we don't count . and .. (which are first)
}
*/
function num2picture($num)
{
global $pictures;
reset($pictures);
$num--;
for($count=0; $count<=($num); $count++)
{
list(, $entry) = each($pictures);
}
return $entry["name"];
}
function picture2num($picture)
{
global $pictures;
reset($pictures);
$count = 0;
foreach($pictures as $entry)
{
$count++;
if($entry["name"] == $picture)
break;
}
return $count;
}
/*echo "picture2num(0,1,2)" . picture2num(num2picture(1)) . picture2num(num2picture(2)) . picture2num(num2picture(3)) . "\n";
echo "num2picture(0,1,2)" . num2picture(1) . num2picture(2)
. num2picture(3) . "\n";*/
/* -- Gallery function ---------------------------------------------------- */
function thumbnails()
{
global $number, $pagenum, $thumbdir_links, $imgdir_links, $thumbdir,
$imgdir, $othumbdir, $oimgdir, $thisfile, $backtogallery, $titel,
$tablestart, $lines_in_row, $pagestr, $included, $pictures,
$help;
# Define the next and previous pages
$prev = $pagenum - 1;
$next = $pagenum + 1;
# Pages start with 0, but we start with 1 so substract 1
// $pagenum--;
# Define when a new page starts
$start = ($pagenum - 1) * $number + 1;
$stop = $start + $number;
// echo "DEBUG: number: $number, start: $start, stop: $stop\n total: " . ($stop - $start) . "\n";
# Header
echo "" . $titel . " - " . $pagestr . " $pagenum \n";
echo " " . $help . "";
# Loop through all the images in the directory
foreach($pictures as $element)
{
$entry = $element["name"];
$total++;
if(is_file("$thumbdir/$entry") && is_readable("$thumbdir/$entry"))
{
$count = picture2num($entry);
/*
echo " DEBUG: count: $count start: $start, stop: $stop, tulos: " .
($count < $stop && $count >= $start) . "\n";
*/
if($count < $stop && $count >= $start)
{
$newline = $count - $start;
$countloop++;
if ($newline == 0 || $countloop == $lines_in_row)
{
$countloop=0;
if ($newline < ($lines_in_row - 1))
{
echo "$tablestart\n";
}
else
{
echo " \n";
}
}
echo "";
echo "$count. " . get_pictinfo($entry) . " ";
#echo "$imgdir/$entry\n"; /*
if(is_file("$imgdir/$entry"))
{
echo "" .
" ";
echo "
| \n";
}
else
{
echo " ";
echo " \n";
}
$count++;
}
}
}
echo " \n";
$gallery_prev = "" .
"[<<]";
$gallery_next = "" .
"[>>]";
$totalpages = ceil($total / $number);
$gallery_pages = 1;
while ( $totalpages >= $gallery_pages )
{
if ($gallery_pages == $pagenum)
$gallery_number = "$gallery_number$gallery_pages \n";
else
$gallery_number = "$gallery_number$gallery_pages \n";
$gallery_pages++;
}
if ( $pagenum == 1 )
{
$gallery_prev = "[<<]";
}
if ( $pagenum == $totalpages )
{
$gallery_next = "[>>]";
}
echo "\n\n\n";
echo "$gallery_prev\n \n\n";
echo "" . $pagestr . ":\n\n $gallery_number\n";
echo " \n$gallery_next\n";
}
/* -- Show full size picture -------------------------------------- */
function fullsize()
{
global $picture, $infofile, $thumbdir, $imgdir,
$thumbdir_links, $imgdir_links, $othumbdir,
$oimgdir, $thisfile, $backtogallery,
$tablestart,$number, $included;
# Find previous and next
$current = picture2num($picture);
$count = picture2num("dontfindme.xyz") - 2 ;
$prev = num2picture($current - 1);
$next = num2picture($current + 1);
$pagenum = ceil($current / $number);
echo " $current. " . get_pictinfo($picture) . "\n";
$thumb_prev = "" .
"[<<] ";
$thumb_index = ""
. "" . $backtogallery . "";
$thumb_next = " "
. "[>>]\n";
if ($current == 1)
{
$thumb_prev = "[<<] ";
}
if ($next == "")
{
$thumb_next = "   [>>]";
}
$browsestr = "$thumb_prev $thumb_index $thumb_next";
echo "$browsestr
\n";
if(is_file("$imgdir/$picture"))
echo " \n";
else
{
user_error("[no fullsized-image for this image, showing thumbnail instead]", E_USER_WARNING);
echo " \n";
}
echo " $browsestr
\n";
}
/* -- Switches ------------------------------------------------------------ */
function gallery()
{
global $version, $action, $oimgdir, $othumbdir, $imgdir_links,
#global $version, $oimgdir, $othumbdir, $imgdir_links,
$thumbdir_links, $imgdir, $thumbdir;
$othumbdir = dir($thumbdir);
$oimgdir = dir($imgdir);
switch($action)
{
case "gallery" :
thumbnails();
break;
case "full" :
#echo "full";
fullsize();
break;
default :
thumbnails();
break;
}
$othumbdir->close();
$oimgdir->close();
}
if(! $included)
{
#global $action;
#echo $action;
gallery();
echo "";
}
?>
|