<?php
////////////////////////////////////////////
///////////////CONFIG SETTINGS//////////////
////////////////////////////////////////////
////////////http://www.rilet.com////////////
////////////////////////////////////////////
// Title
$title = "photos";
// Administrator Password
$password = "password";
// Set a number of pictures to display per
// page while viewing in gallery view
$pictures = "12";
// Display "View All" on main menu.
// This setting is best set to "off" if
// you are concerned about server load.
$view_all = "on";
// Maximum picture size before it is
// reduced while viewing photo as a
// full size image
$picture_width = "800";
$picture_height = "600";
// Folder for storing photos (w/o trailing slash)
$image_folder = "gallery";
// Display method for gallery view-
// "height", "width" or "none".
$viewtype="height";
// Set a maximum height and width for
// pictures displayed in gallery
$width = 100;
$height = 100;
//////////END OF CONFIGURATION SETTINGS::: DO NOT EDIT BELOW THIS LINE!!!
@$x = $_GET['x'];
if ($x != "resize"){
echo'
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html>
<head><meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>'. $title .' | Photo Gallery v 1.2.2</title>
<style>
a {color:white;}
a:hover {color:#003366;}
body {
background:#0099CC;
color:#DDDDDD;
font:12pt Comic Sans MS;
}
img {border:1px solid white;}
.gallery:hover {border:1px dotted #888888;}
#title{
text-align:center;
}
#gallery{
width:600px;
margin:auto;
}
#nav{text-align:center;}
#image {text-align:center;}
</style>
</head>
<body>
';
}
// Resize for gallery
//////////////////////////////////////////////////////////////////////////////////
if ($x == "resize"){
// The file
$filename = $_GET['filename'];
$filename = "$image_folder".'/'."$filename";
header('Content-type: image/jpeg');
list($width_orig, $height_orig) = getimagesize($filename);
if ($viewtype == "height"){
$width = ($height / $height_orig) * $width_orig;
}else if ($viewtype == "width"){
$height = ($width / $width_orig) * $height_orig;
}else if ($viewtype == "none"){
if ($width_orig < $height_orig) {
$width = ($height / $height_orig) * $width_orig;
} else {
$height = ($width / $width_orig) * $height_orig;
}
}
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($image_p, null, 100);
imagedestroy($image_p);
// Gallery view-by-page
}else if ($x == "gallery"){
@$view = $_GET['page'];
if (empty($view)){
$view = 0;
}
$view_plus = $view+$pictures;
$view_minus = $view-$pictures;
echo'<div id="title">'. $title .'</div><div id="gallery">';
$file = glob("$image_folder/*.*");
$file = array_slice($file, $view, $pictures);
//sort by date...
foreach ($file as $files){
$file = str_replace("$image_folder".'/', "", $files);
echo '<a href="gallery.php?x=photo&view='. $file .'&return=gallery&page='. $view .'" title="'. $file .'"><img src="gallery.php?x=resize&filename='. $file .'" class="gallery" /></a>'."\n";
}
echo'</div>
<div id="nav"><a href="?x=gallery&page='. $view_minus .'">⇐⇐</a> | <a href="gallery.php">Home</a> | <a href="?x=gallery&page='. $view_plus .'">⇒⇒</a></div>';
// Individual Photo
}else if ($x == "photo"){
@$view = $_GET['view'];
@$return = $_GET['return'];
@$page = $_GET['page'];
$size = getimagesize("$image_folder".'/'."$view");
$w = $size[0];
$h = $size[1];
echo'<div id="image">';
if ($w > $picture_width || $h > $picture_height){
echo'<img src="'. $image_folder .'/'. $view .'" height="90%" width="90%" />';
}else{
echo'<img src="'. $image_folder .'/'. $view .'" />';
}
//Display Comment.
echo"<br>";
include("gallery.csv");
echo @$caption["$view"];
echo'</div>
<div id="nav"><a href="gallery.php?x='. $return .'&page='. $page .'">Back</a></div>';
// Gallery view-all
}else if ($x == "all"){
$handle = opendir("$image_folder");
echo'<div id="title">'. $title .'</div><div id="gallery">';
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file != ".DS_Store" && $file != "Thumbs.db") {
echo '<a href="gallery.php?x=photo&view='. $file .'&return=all" alt="'. $file .'" title="'. $file .'"><img src="gallery.php?x=resize&filename='. $file .'" class="gallery" /></a>'."\n";
}
}
echo'</div>
<div id="nav"><a href="gallery.php">Back</a></div>';
closedir($handle);
// Begin admin pages
}else if ($x == "admin"){
@$y = $_GET['y'];
if (isset($y)){
// Check for password or error
$pass = $_POST['pass'];
if ($pass == $password){
// Main page
if ($y == "admin"){
echo'<p><big>Admin page</big><br />
<a href="gallery.php">Home</a></p>
<hr />
<form enctype="multipart/form-data" action="gallery.php?x=admin&y=upload" method="post">
<input name="imagefile" type="file" />
<input type="hidden" name="pass" value="'. $pass .'" />
<input type="submit" value="Upload" /><br>
Note <input type="text" name="caption" style="width:13em;" maxlength="150">
</form>
<hr>
';
$handle = opendir("$image_folder");
require("gallery.csv");
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
@$thecaption = $caption["$file"];
echo'<form action="gallery.php?x=admin&y=delete" method="post"><a href="'. $image_folder .''. $file .'" title="'. $file .'">View</a> | ';
echo'<a href="#" onCLick="alert(\'This is a spaceholder until a caption edit function is added.\')">Edit</a> | ';
echo'<input type="hidden" name="delete" value="'.$file.'"><input type="hidden" name="pass" value="'.$pass.'">
<input type="hidden" name="caption" value="'.$thecaption.'"><input type="submit" value="Delete" onCLick="return confirm(\'Are you SURE you want to delete this entry?\')"> ';
echo"$file<br /></form>\n";
}
}
closedir($handle);
echo'<hr>';
// Upload page
}else if ($y == "upload"){
if ($_FILES['imagefile']['type'] == "image/jpeg"){
$name = $_FILES['imagefile']['name'];
//Code to add captions to file.
@$caption = trim(stripslashes(strip_tags($_POST['caption'])));
$file = file_get_contents("gallery.csv");
$fp = fopen("gallery.csv", "w+");
if(!$fp){ //Check to make sure file is writable, halts the script if not.
print "The file \"gallery.csv\" could not be written to.";
exit;
}
// Limits the shout size entered by the user.
if (strlen($caption) >= 200) {
$caption = substr($caption, 0, 200);
$caption = $caption."...";
}
$caption = "\$caption['$name'] = \"$caption\";";
$caption = str_replace( '?>', $caption, $file );
fwrite($fp, "$caption\n?>");
fclose($fp);
//Code to upload image to server.
copy ($_FILES['imagefile']['tmp_name'], "$image_folder".$_FILES['imagefile']['name'])
or die ("Could not copy");
echo "";
echo "Name: $name<br>";
echo "Size: ".$_FILES['imagefile']['size']."<br>";
echo "Upload Done....";
echo '<form action="gallery.php?x=admin&y=admin" method="post"><input type="hidden" name="pass" value="'. $pass .'"><input type="submit" value="Continue"></form>';
}
else {
echo "<br><br>Could Not Copy, Wrong Filetype $name<br>";
}
// To edit a caption
//////////////////////////////////////////////////////////////////////////////
}else if ($y == "edit_caption"){
echo"This is a dummy page until I can get around to writing it.";
// To delete a file
}else if ($y == "delete"){
$delete = $_POST['delete'];
$caption = $_POST['caption'];
$handle = opendir("$image_folder");
unlink("$image_folder"."$delete")
or die("There was an error deleting the file!");
closedir($handle);
$file = file_get_contents("gallery.csv");
$fp = fopen("gallery.csv", "w+");
$caption = "\$caption['$delete'] = \"$caption\";";
echo"$caption";
$update = str_replace( "$caption", '', $file );
fwrite($fp, "$update");
fclose($fp);
echo'File deleted<br /><form action="gallery.php?x=admin&y=admin" method="post"><input type="hidden" name="pass" value="'. $pass .'"><input type="submit" value="Continue"></form>
';
}
}else{
echo "bad password";
}
// Login page
//////////////////////////////////////////////////////////////////////////////
}else{
echo'
<form action="gallery.php?x=admin&y=admin" method="post"><p>Login:<br />
<input name="pass" type="password" /><input value="Log in" type="submit" />
</p></form>
';
}
// Main Menu
//////////////////////////////////////////////////////////////////////////////////
}else{
echo'
'. $title .'
<ul>
<li><a href="gallery.php?x=gallery">View</a></li>';
if ($view_all == "on"){
echo'<li><a href="gallery.php?x=all" onCLick="return confirm(\'Warning: This page may take a while to load, and is not recomended for users with slower connections. Do you still want to view all?\')">View all</a></li>';
}
echo'<li><a href="gallery.php?x=admin">Administer</a></li>
</ul>
';
}
if ($x != "resize"){
echo"</body></html>";
}
?>