\n";
}
}
}
function getWindowTitle() {
global $my_album, $album, $picture, $files;
echo "
$my_album";
if ($album!="") {
echo " ::: ";
echo getAlbumTitleText();
}
if ($picture!="") {
echo " ::: ";
echo getPictureTitleText();
}
echo "\n";
}
function getThanksTo() {
echo "";
}
# ****************************************************************************************
# Common functions to all three programs
# ****************************************************************************************
function getAlbumTitleText($path="") {
global $album, $my_album, $lang;
if ($path=="") {
$path="$album/";
}
$albumfile = "album.txt";
if (file_exists("${path}album_$lang.txt")) {
$albumfile = "album_$lang.txt";
}
if (file_exists("${path}$albumfile")) {
$album_file = file("${path}$albumfile", "r");
$text = $album_file[0];
return trim($text);
} else {
if ($path==".") {
return trim("$my_album");
} else {
$path_parts = pathinfo("$path");
return trim($path_parts["basename"]);
}
}
}
function getAlbumDescriptionText($path="") {
global $album, $lang;
$text="";
if ($path=="") {
$path="$album/";
}
$albumfile = "album.txt";
if (file_exists("${path}album_$lang.txt")) {
$albumfile = "album_$lang.txt";
}
if (file_exists("${path}$albumfile")) {
$album_file = file("${path}$albumfile", "r");
$current = 1;
while ($current <= sizeof($album_file)) {
$text .= "$album_file[$current]";
$current++;
}
}
return $text;
}
function getPictureTitleText($path="", $pic="") {
global $album, $files, $picture, $lang, $captions_array;
$pathalbum=$album;
if ($path!="") {
$pathalbum=$path;
}
if (empty($captions_array)) {
getPicturesCaptionFromOneFile("$pathalbum/");
}
$tmp_picturename = $files[$picture];
if ($pic!="") {
$tmp_picturename = $pic;
}
if (array_key_exists("$tmp_picturename", $captions_array)) {
return $captions_array["$tmp_picturename"][1];
}
$picturename = getFilename($tmp_picturename);
$picturefile = "$picturename.txt";
if (file_exists("${pathalbum}/$picturename_$lang.txt")) {
$picturefile = "$picturename_$lang.txt";
}
if (file_exists("${pathalbum}/$picturefile")) {
$picture_file = file("${pathalbum}/$picturefile", "r");
return trim("$picture_file[0]");
}
else {
return trim("$picturename");
}
}
function getPictureTitleDescriptionText() {
global $album, $files, $picture, $lang, $captions_array;
if (empty($captions_array)) {
getPicturesCaptionFromOneFile();
}
if (array_key_exists("$files[$picture]", $captions_array)) {
return $captions_array["$files[$picture]"][2];
}
$text="";
$picturename = getFilename($files[$picture]);
$picturefile = "$picturename.txt";
if (file_exists("${album}/$picturename_$lang.txt")) {
$picturefile = "$picturename_$lang.txt";
}
if (file_exists("${album}/$picturefile")) {
$picture_file = file("${album}/$picturefile", "r");
$current = 1;
while ($current <= sizeof($picture_file)) {
$text .= "$picture_file[$current]\n";
$current++;
}
}
return $text;
}
# ****************************************************************************************
# 'Private' functions
# ****************************************************************************************
function getFilename($filewithextension) {
$position = strrpos($filewithextension, ".");
if ($position > 1)
return substr($filewithextension, 0, $position);
else
return $filewithextension;
}
function isValidPictureDirectory($dir) {
global $not_browsable_folder;
return !(in_array ($dir, $not_browsable_folder));
}
function isValidPictureFile($file) {
return (eregi("jpg$",$file) || eregi("jpeg$",$file) || eregi("gif$",$file) || eregi("png$",$file));
}
function getPictureSize($toPicture) {
global $album;
$size = getimagesize ("$album/$toPicture");
return "width=\"$size[0]\" height=\"$size[1]\"";
}
function getThumbnailSize($toPicture) {
global $album, $thumb, $thumb_resize, $thumb_minimum_resize;
$thumbPath = getThumbnailPath($toPicture);
if (!file_exists("$thumbPath")) {
return "";
}
$size = getimagesize ("$thumbPath");
if ($thumb) {
return "width=\"$size[0]\" height=\"$size[1]\"";
} else {
if (($size[0]<=$thumb_minimum_resize)|($size[1]<=$thumb_minimum_resize)) {
return "width=\"$size[0]\" height=\"$size[1]\"";
} else {
$width=round($size[0]*$thumb_resize/100);
$height=round($size[1]*$thumb_resize/100);
if (($width>=$thumb_minimum_resize)&&($height>=$thumb_minimum_resize)) {
return "width=\"$width\" height=\"$height\"";
} else {
if ($width<=$height) {
$width=$thumb_minimum_resize;
$height=round($size[1]*($thumb_minimum_resize/$size[0]));
return "width=\"$width\" height=\"$height\"";
} else {
$height=$thumb_minimum_resize;
$width=round($size[0]*($thumb_minimum_resize/$size[1]));
return "width=\"$width\" height=\"$height\"";
}
}
}
}
}
function getThumbnailPath($toPicture) {
global $album, $thumb, $thumb_dir, $thumb_prefix;
if ($thumb) {
return "$album/$thumb_dir/$thumb_prefix$toPicture";
} else {
return "$album/$toPicture";
}
}
function sortPictures($ar, $path) {
global $sortpicture;
switch ($sortpicture) {
case 'adn':
sort($ar);
break;
case 'ddn':
rsort($ar);
break;
case 'adcd':
case 'ddcd':
$tmp_ar=array();
foreach ($ar as $entry) {
$tmp_ar[$entry] = filemtime("${path}/${entry}");
}
if ($sortpicture=='adcd') {
asort($tmp_ar);
} else {
arsort($tmp_ar);
}
$ar=array_keys($tmp_ar);
break;
case 'aan':
case 'dan':
$tmp_ar=array();
foreach ($ar as $entry) {
$tmp_ar[$entry] = getPictureTitleText("${path}", "${entry}");
}
if ($sortpicture=='aan') {
asort($tmp_ar);
} else {
arsort($tmp_ar);
}
$ar=array_keys($tmp_ar);
break;
case 'asd':
case 'dsd':
$tmp_ar=array();
foreach ($ar as $entry) {
$tmp_ar[$entry] = filesize("${path}/${entry}");
}
if ($sortpicture=='asd') {
asort($tmp_ar);
} else {
arsort($tmp_ar);
}
$ar=array_keys($tmp_ar);
break;
default:
sort($ar);
break;
}
return $ar;
}
function getPicturesCaptionFromOneFile($path="") {
global $captions_filename, $captions_filename_separator, $captions_array, $album, $lang;
$captions_array=array();
$pathalbum=$path;
if ($path=="") {
$pathalbum="$album/";
}
$filename = getFilename($captions_filename);
$captionfile = "$filename.txt";
if (file_exists("${pathalbum}$filename_$lang.txt")) {
$captionfile = "$filename_$lang.txt";
}
if (file_exists("${pathalbum}$captionfile")) {
$tmp_caption_file=file("${pathalbum}$captionfile", "r");
foreach ($tmp_caption_file as $entry) {
$captions=explode("$captions_filename_separator", $entry);
$captions_array[$captions[0]]=$captions;
}
}
return $captions_array;
}
?>