/*
Trip Pictures v1.0
Created by Paul O'Russa
Last modified 4/21/2005
Three possible modes:
index - specify "f" - shows the index page for all the days
day - specify "f" and "d" - shows the thumbs for the current day
pic - specify "f", "d", and "p" - shows the picture for the given index
*/
//Initialize our global variables.
$file = "";
$day = "";
$picture = "";
$mode = "";
$params = "";
$arDays = array();
$tripDesc = "";
//Get the f, d, and p querystring parameters and read the INI file.
getParams();
//Comb through the INI settings to create our days with the pictures.
parseFile();
/*print "
}
elseif ($mode == "day") {
$enablePrev = false;
$enableNext = false;
//See if we should display the previous/next day buttons.
if ($day > 1)
$enablePrev = true;
if ($day < count($arDays))
$enableNext = true;
?>
if ($enablePrev) { ?> } ?>
click a picture to view a larger version
if ($enableNext) { ?> } ?>
//Loop through eavery picture in the current day and display in a table.
$count = 0;
$part2 = "";
foreach (array_keys($arDays["day$day"]["pics"]) as $picsKeys) {
$arDay = $arDays["day$day"]["pics"][$picsKeys];
if ($count % 5 == 0) {
if ($count >= 5) {
print '
}
elseif ($mode == "pic") {
//If the picture has a description, use that, else use the picture's filename.
if (isset($arDays["day$day"]["pics"]["$picture"][1]))
$photoDesc = $arDays["day$day"]["pics"]["$picture"][1];
else
$photoDesc = $arDays["day$day"]["pics"]["$picture"][0];
//See if we should display the next/previous picture buttons and calculate which picture they go to.
$prevPic = true;
$nextPic = true;
$newDay1 = $day;
$newPic1 = $picture - 1;
$newDay2 = $day;
$newPic2 = $picture + 1;
//Hide the previous picture button if there is no previous picture.
if ($day == 1 && $picture == 1)
$prevPic = false;
//Hide the next picture button if there is no next picture.
if ($day >= count($arDays) && $picture == count($arDays["day$day"]["pics"]))
$nextPic = false;
//See if we need to set the previous picture button to the last picture in the previous day.
if ($prevPic && $picture == 1) {
$newDay1--;
$newPic1 = count($arDays["day$newDay1"]["pics"]);
}
//See if we need tp set the next picture button to the first picture on the next day.
if ($nextPic && $picture >= count($arDays["day$day"]["pics"]) ) {
$newDay2++;
$newPic2 = 1;
}
?>
if ($prevPic) { ?> } ?>
if ($nextPic) { ?> } ?>
}
?>
function getParams() {
global $file, $day, $picture, $params, $mode;
if (isset($_GET['f']))
$file = $_GET['f'];
if (isset($_GET['d']))
$day = $_GET['d'];
if (isset($_GET['p']))
$picture = $_GET['p'];
//Get the mode from the parameters.
if ($file && !$day && !$picture)
$mode = "index";
elseif ($file && $day && !$picture)
$mode = "day";
elseif ($file && $day && $picture)
$mode = "pic";
else
die("Invalid parameters!");
//print "MODE: $mode ";
$fullFile = "";
if ($file != "") {
$fullFile = "./" . $file . "/pics.ini";
}
if (!is_file($fullFile))
die("Could not find ini file: " . $fullFile);
//Open the INI file containing the list of pictures and descriptions.
$params = file($fullFile) or die('Could not read ini file!');
}
function parseFile() {
global $params, $arDays, $tripDesc;
$dayIndex = 0;
$picIndex = 0;
$first = 1;
foreach ($params as $line) {
$line = rtrim($line, "\n\r");
//print "|$line| ";
//Skip empty lines.
if ($line == "") {
continue;
}
//If this is the top line containing the trip description...
if ($first == 1) {
//print "FIRST LINE ";
$tripDesc = $line;
$first = 0;
}
//Else if this is the start of a new day, get the day's information...
elseif (strtolower(substr($line, 0, 3)) == "day") {
$dayIndex++;
$picIndex = 0;
$arLine = split("\t", $line);
if (count($arLine) < 3) {
$arDays["day$dayIndex"]["thumb"] = "";
$arDays["day$dayIndex"]["desc"] = "Invalid day format! Please check your pics.ini file.";
}
else {
$arDays["day$dayIndex"]["thumb"] = $arLine[1];
$arDays["day$dayIndex"]["desc"] = $arLine[2];
}
//print "DAY LINE: $dayIndex ";
}
//Else this is a picture line...
else {
$picIndex++;
$arDays["day$dayIndex"]["pics"]["$picIndex"] = split("\t", $line);
//print "IMAGE LINE: $dayIndex - $line ";
}
}
}
?>