IMAGE BROWSER

# yet another very simple image browser

# $CUSTOM_CHARSET = “UTF-8″;

# preferences
$ALBUMS_ROOT = “albums”;
$LEGAL_FILE_EXTENSIONS = array(“JPG”,”GIF”);
$THUMBNAIL_WIDTH=200;

# see if the user chose an album
$ALBUM = “”;
if(isset($HTTP_GET_VARS["album"]))
{
$ALBUM = $HTTP_GET_VARS["album"];
# delete foul parameters
$ALBUM = preg_replace(array(“/\.\./”,”/^\//”,”/\/$/”),”",$ALBUM);
$ALBUM = preg_replace(“/\/\//”,”/”,$ALBUM);
}

$file_extns_regex = “/(“.join(“|”,$LEGAL_FILE_EXTENSIONS).”)$/i”;

# root dir
$imgroot = $_SERVER['DOCUMENT_ROOT'].$ALBUMS_ROOT;

# read the categories
$cats = array();

$d = dir($imgroot);
while (false !== ($entry = $d->read()))
{
$current_dir = $imgroot.”/”.$entry;

if(is_dir($current_dir) && ($entry != “.”) && ($entry != “..”))
{
# see if there are albums inside this category
$album_dir = dir($current_dir);
$album_entries = array();
while (false !== ($album_entry = $album_dir->read()))
{
$current_dir = $imgroot.”/”.$entry.”/”.$album_entry;
if(is_dir($current_dir) && ($album_entry != “.”) && ($album_entry != “..”))
{
$filestats = stat($current_dir);
$filetime = $filestats[9]; #mtime
array_push($album_entries, array($album_entry => $filetime));
}
}
$cats[$entry] = $album_entries;
}
}
$d->close();

$LEFT_NAV = “”;
foreach($cats as $catname => $albums)
{
$LEFT_NAV .= “

$catname

“;
foreach($albums as $album)
{
$LEFT_NAV .= “

“.key($album).”

“;
}
}

# determine default album
if($ALBUM != “”)
{
$current_album = $ALBUM;
}
else
{
$catnames = array_keys($cats);
$firstcat = $catnames[0];
$albums = $cats[$firstcat][0];
$albumnames = array_keys($albums);

$firstalbum = $albumnames[0];
$current_album = $firstcat.”/”.$firstalbum ;
}

$album_dir = $imgroot.”/”.$current_album;
$album_url = $ALBUMS_ROOT.”/”.$current_album;

$CAT_NAME = preg_replace(“/^(.+?)\/.*$/”,”$1″, $current_album);
$ALBUM_NAME = preg_replace(“/^.+?\/(.+)$/”,”$1″, $current_album);

$DOCTITLE = “ravn.de Fotoalbum: $CAT_NAME – $ALBUM_NAME”;
$SPITZMARKE = “$CAT_NAME”;
$HEADLINE = “Album: $ALBUM_NAME”;
include “components/header.inc.php”;

?>


?>

?>

# if a file named “intro.htm” exists inside the album directory, we printout that. Else we only print the album’s name.
$intro_file = $album_dir.”/intro.htm”;
if(file_exists($intro_file))
{
print file_get_contents($intro_file);
}
else
{
print “Album: $current_album”;
}
?>

# $d = dir($album_dir);

#while (false !== ($entry = $d->read()))

$album_entries = scandir($album_dir);
$imgcount = 0;

foreach($album_entries as $entry)
{
$current_dir = $album_dir.”/”.$entry;
if(!is_dir($current_dir))
{
if(preg_match($file_extns_regex, $entry))
{
$urlpath = $album_url.”/”.$entry;
$filepath = $album_dir.”/”.$entry;

# get image caption

$exif = exif_read_data ($filepath,0,true);
# Let’s first try and get the EXIF-Tag “Comments”
$imageComments = fixText($exif["IFD0"]["Comments"]);
# This was empty? Let’s go for the EXIF-Tag “Description”
if(empty($imageComments)) $imageComments = fixText($exif["IFD0"]["ImageDescription"]);
# Also no luck? Let’s go for that strange thing that e.g. Picasa uses
if(empty($imageComments)) $imageComments = readPicasaCaption($absolute_file);
++$imgcount;
?>

 

}

function alter_value(&$a)
{
$a = urldecode($a);
$a = split(‘/’, $a);
array_walk($a, ‘_do_urlencode’);
$a = implode(“/”, $a);
$a = preg_replace(“/\+/”,”%20″,$a);
return $a;
}

function _do_urlencode(&$value, $key)
{
$value = urlencode($value);
}

function sp_urlencode($path)
{
# return (“000″.$path);
$a = array();
$a = split(“/”, $path);

foreach($a as &$b)
{
$b = preg_replace(“/ß/”,”%DF”,$b);
$b = urlencode($b);
$b = preg_replace(“/%25/”,”%”,$b);
$b = preg_replace(“/\+/”,”%20″,$b);
}
return implode(“/”, $a);
}

function readPicasaCaption($image_path){
$size = getimagesize ( $image_path, $info);
if(is_array($info)) {
$iptc = iptcparse($info["APP13"]);
$c = count ($iptc["2#120"]);
for ($i=0; $i <$c; $i++)
{
$title=$iptc["2#120"][$i];
}
}
if($title != “”)
return $title;
else
return ”; #$image_path;
}
?>

include “components/footer.inc.php”;
?>