//////////////////////////////////////////////////////////////////////////////// // PhotoFrame http://photoframe.sf.net $version = "6.2"; // // by Martin Dougiamas http://dougiamas.com // // Photoframe displays a directory of images (JPEG, PNG, GIF) simply and easily. // It will also create thumbnails and display JPEG captions if it finds them. // Guests can leave comments, and it supports Imagemagick as well as PHP GD. // I am placing this script in the Public Domain - use it as you wish. // // Requirements: A web server with this software (note minimum versions): // - PHP 4.0.2 http://www.php.net // AND EITHER THESE // - GD 1.8.3 http://www.boutell.com/gd // - libjpeg 6b http://www.ijg.org/ // OR // - Imagemagick http://www.imagemagick.org/ // // How to use: 1. Store all your images in a directory on your server // 2. Save this file in that directory as index.php // 3. Make sure the web server has write permissions so // that it can write in a sub directory (thumbnails etc). // eg mkdir thumb ; chown nobody thumb // (optional) 4. Change any of the settings below to suit. You can // also put these in a separate file called config.php // (optional) 5. Add an intro.html file if you like. // (optional) 6. Add header.html and footer.html files if you want // to change page colours, layout or styles. // (optional) 7. Add a sortfile if you want to control the order of // the photos, rather than the default alphabetical order. // Just make a simple text file with one filename per line. // eg ls -1 *.jpg *.png > sortfile // (and then edit with vi) // //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // config.php - these settings are the default ones. You can either // change them here or create a file called "config.php" // that contains override settings. The advantage of a // separate file is that you can upgrade the script and // keep all your settings. $title = "Our 1973 Boler"; // Title for the overall web page $marginsize = 150; // Size of the side frame, and thumbnails $marginside = "left"; // Margin frame location: "left" or "right" $thumb = "thumb"; // Sub-directory where thumbnails are stored $imagequality = 70; // Quality of reduced images, range 0 - 100 $fullwindow = false; // Display images to fill browser window? $imageresize = 640; // You can rescale all images to fit within // a boundary square of this size (eg 800). // These rescaled images are cached on disk. // To just use original images, specify 0 $pagecolor = "#FFFFFF"; // Background color of all pages $textcolor = "#000000"; // Text color for all pages $linkcolor = "#000055"; // Link color for all pages $vlinkcolor = "#550055"; // Visited link color for all pages $background = ""; // Background image for all pages $stylesheet = ""; // Full URL to a stylesheet for all pages. // HTML text tags used:
,
Error: $message
"; } function PrintHeader($pagetitle="", $meta="") { // Special case when meta = "margin" global $headerfile; global $stylesheet; global $lang; global $pagecolor, $textcolor, $linkcolor, $vlinkcolor, $background; echo "\n"; echo ""; echo "$title
\n"; } echo ""; } function PrintRecentComments($recent) { global $thumb, $marginsize, $marginside, $scriptname; global $ss, $lang, $timeoffset; if (! $recent) { return; } $imagelist = GetFileList(); $comments = array(); foreach ($imagelist as $filename) { $commentfile = "$thumb/$filename.txt"; if (file_exists($commentfile)) { $file = file($commentfile); foreach ($file as $line) { $line = chop($line)."###$filename"; $comments[] = $line; } } } rsort($comments); $count = 0; echo "";
echo "";
echo $ss[$lang]["from"].": ".$comm[1].", ".date("l, j F Y, g:i A", $comm[0]+($timeoffset*3600))." "; echo "
| ";
}
echo ""; echo ""; if (file_exists($thumbimage)) { echo ""; } else { echo "$caption"; } echo ""; echo " | "; if ($marginside == "right") { echo "";
echo "";
echo $ss[$lang]["from"].": ".$comm[1].", ".date("l, j F Y, g:i A", $comm[0]+($timeoffset*3600))." "; echo "
| ";
}
echo "
\n"; foreach ($commentfiles as $commenttype => $commentfile) { if ($commenttype == "unmoderated" and !isadmin()) { continue; } if (file_exists($commentfile)) { $comments = file($commentfile); foreach ($comments as $comment) { $comm = explode ("###", $comment); echo ""; echo $ss[$lang]["from"].": ".$comm[1].", ".date("l, j F Y, g:i A", $comm[0]+($timeoffset*3600))."
"; echo "".$comm[2]."
\n"; if (isadmin()) { echo ""; if ($commenttype == "unmoderated") { echo "approve "; echo "delete"; } else { echo "delete"; } echo "
"; } echo "
\n"; } } } echo "
That message has been approved
"; } } function PrintCommentForm($filename) { global $scriptname, $textcolor, $pagecolor; global $ss, $lang; ?> } function AddComment($filename, $name, $message, $messageline="") { // Clean up a given comment and add to the appropriate database global $thumb, $email, $title, $moderate, $SERVER_NAME, $REQUEST_URI, $REMOTE_HOST; if (ereg( "\\.\\.", $filename)) { // using ".." in the filename PrintError("That filename ($filename) was not secure."); return; } if (!$name and !$messageline) { PrintError("You need to fill out your name."); return; } if (!$message and !$messageline) { PrintError("There was no message to post."); return; } if ($moderate and !$messageline) { $commentfile = "$thumb/$filename.mod"; } else { $commentfile = "$thumb/$filename.txt"; } if ($file = fopen ($commentfile, "a") ) { if ($messageline) { fwrite($file, "$messageline"); } else { $timenow = time(); $name = strip_tags($name); $message = stripslashes(strip_tags($message, "")); if ($email) { // Try and send the comment via email $urlstart = "http://$SERVER_NAME$REQUEST_URI?image=".rawurlencode($filename); if ($moderate) { $approveurl = "Approve: $urlstart&acomment=$timenow\n\n"; } $deleteurl = "Delete: $urlstart&dcomment=$timenow&ctype=mod\n\n"; mail($email, "Comment added: $title", "From: $name ($REMOTE_HOST)\n\n". "$message\n\n". "http://$SERVER_NAME$REQUEST_URI?image=".rawurlencode($filename)."\n\n". $approveurl . $deleteurl, "From: $email"); } $message = nl2br($message); $message = strtr($message, "\r", " "); $message = strtr($message, "\n", " "); fwrite($file, "$timenow###$name###$message\n"); } fclose($file); } else { PrintError("Could not add comment for $filename"); } } function CleanCaption ($caption) { $caption = strtr($caption, "\r", " "); $caption = strtr($caption, "\n", " "); $caption = htmlentities(strip_tags($caption)); return $caption; } function GetImageCaption($image, $clean=false) { global $thumb, $captionmethod, $rdjpgcom, $identify; switch ($captionmethod) { case "imagemagick": if (file_exists($image)) { Exec("$identify -ping -format \"%c\" \"$image\"", $captionlines); } else { return ""; } break; case "rdjpgcom": if (file_exists($image)) { Exec("$rdjpgcom \"$image\"", $captionlines); } else { return ""; } break; case "capfile": $capfile = "$thumb/$image".".cap"; if (file_exists($capfile)) { $captionlines = file($capfile); } else { return ""; } break; case "filename": return $image; break; default: return ""; break; } foreach ($captionlines as $captionline) { $caption .= "$captionline "; } $caption = stripslashes($caption); if ($clean) { $caption = CleanCaption($caption); } return $caption; } function SetImageCaption($image, $caption) { global $thumb, $captionmethod, $wrjpgcom; $TEMPFILE = "$thumb/ttttmpfile.jpg"; if (file_exists($TEMPFILE)) { unlink($TEMPFILE); } $caption = stripslashes($caption); switch ($captionmethod) { case "rdjpgcom": if (!eregi("\.jpe?g$", $image)) { PrintError("$image is probably not a JPEG file"); return false; } $command = "$wrjpgcom -replace -comment ".EscapeShellArg($caption)." ".EscapeShellArg($image); Exec("$command > $TEMPFILE"); if (file_exists($TEMPFILE) and filesize($TEMPFILE) > 0) { return rename($TEMPFILE, $image); } break; case "capfile": $capfile = "$thumb/$image".".cap"; if (! $file = fopen ($capfile, "w")) { PrintError("Could not open the caption file $capfile"); return false; } if (! fwrite($file, $caption)) { PrintError("Could not write the caption to the caption file $capfile"); return false; } return true; break; } return false; } function ReadImageFromFile($filename, $type) { $imagetypes = ImageTypes(); switch ($type) { case 1 : if ($imagetypes & IMG_GIF) return $im = ImageCreateFromGIF($filename); break; case 2 : if ($imagetypes & IMG_JPEG) return ImageCreateFromJPEG($filename); break; case 3 : if ($imagetypes & IMG_PNG) return ImageCreateFromPNG($filename); break; default: return 0; } } function WriteImageToFile($im, $filename, $type) { global $imagequality; switch ($type) { case 1 : return ImageGIF($im, $filename); case 2 : return ImageJpeg($im, $filename, $imagequality); case 3 : return ImagePNG($im, $filename); default: return false; } } function ResizeImage($image, $newimage, $newwidth, $newheight=0) { // Returns true if new image was created, else false // If newheight is not specified then image is scaled in proportion // to newwidth. If newheight is specified, then newheight and newwidth // represent a bounding box to fit image into global $imagemethod; switch ($imagemethod) { case "imagemagick": return ResizeImageUsingIM($image, $newimage, $newwidth, $newheight); break; case "gd1": case "gd2": return ResizeImageUsingGD($image, $newimage, $newwidth, $newheight); break; case "manual": return true; break; default: return false; break; } } function ResizeImageUsingGD($image, $newimage, $newwidth, $newheight) { global $imagemethod; $size = GetImageSize($image); $width = $size[0]; $height = $size[1]; $type = $size[2]; if ($im = ReadImageFromFile($image, $type)) { if ($newheight && ($width < $height)) { $newwidth = ($newheight / $height) * $width; } else { $newheight = ($newwidth / $width) * $height; } if ($imagemethod == "gd2") { $im2 = ImageCreateTrueColor($newwidth,$newheight); } else { $im2 = ImageCreate($newwidth,$newheight); } if ($imagemethod == "gd2") { ImageCopyResampled($im2,$im,0,0,0,0,$newwidth,$newheight,$width,$height); } else { ImageCopyResized($im2,$im,0,0,0,0,$newwidth,$newheight,$width,$height); } if (WriteImageToFile($im2, $newimage, $type)) { return true; } } return false; } function ResizeImageUsingIM($image, $newimage, $newwidth, $newheight) { global $identify, $convert, $imagequality; if (! $sizeinfo = Exec("$identify -ping -format \"%w %h\" \"$image\"")) { return false; } $size = explode(" ", $sizeinfo); $width = $size[0]; $height = $size[1]; if (!$width) { return false; } if ($newheight && ($width < $height)) { $newwidth = ($newheight / $height) * $width; } else { $newheight = ($newwidth / $width) * $height; } Exec("$convert -geometry \"$newwidth"."x"."$newheight\" -quality \"$imagequality\" \"$image\" \"$newimage\""); return file_exists($newimage); } function PrintSlideshowForm ($nextimage, $slide=0) { global $scriptname; global $ss, $lang; $common = "$scriptname?image=$nextimage&slide="; $options = array (2 => "2 ".$ss[$lang]["seconds"], 5 => "5 ".$ss[$lang]["seconds"], 7 => "7 ".$ss[$lang]["seconds"], 10 => "10 ".$ss[$lang]["seconds"], 20 => "20 ".$ss[$lang]["seconds"], 30 => "30 ".$ss[$lang]["seconds"], 40 => "40 ".$ss[$lang]["seconds"], 50 => "50 ".$ss[$lang]["seconds"], 60 => "60 ".$ss[$lang]["seconds"]); echo ""; } function isadmin() { global $password, $PFCOOKIE; if ($password and isset($PFCOOKIE)) { if ($PFCOOKIE == md5($password) ) { return true; } } return false; } function clean_filename($string) { $string = eregi_replace("\.\.", "", $string); $string = eregi_replace("[^([:alnum:]|\.)]", "_", $string); return eregi_replace("_+", "_", $string); } /// Individual pages are created here /// if ($admin) { if (isadmin()) { $intro = "true"; } else if ($admin == $password) { $seconds = 60*60*24*354; setCookie ('PFCOOKIE', "", time() - 3600, "/"); setCookie ('PFCOOKIE', md5($admin), time()+$seconds, "/"); $PFCOOKIE = md5($admin); $intro = "true"; } else { PrintHeader("Administrator Login"); echo ""; echo ""; } } if ($logout) { if (isadmin()) { $seconds = 60*60*24*354; setCookie ('PFCOOKIE', "", time() - 3600, "/"); $PFCOOKIE = NULL; } $intro = "true"; } if ($editcaption) { PrintHeader("Editing a caption"); $image = urldecode($editcaption); if (!isadmin()) { PrintError("This is an admin-only function"); die; } if (ereg( "\\.\\.", $image)) { // using ".." in the filename PrintError("That filename ($image) was not secure."); die; } if ($captionmethod == "rdjpgcom" or $captionmethod == "capfile") { if ($newcaption) { if (! SetImageCaption($image, $newcaption)) { PrintError("Could not save the new caption, sorry"); } echo "
"; echo "
Caption saved.
"; echo ""; } else { $caption = stripslashes(GetImageCaption($image)); echo ""; echo "
Caption for \"$image\"
"; echo ""; } } else { PrintError("You can't edit captions unless $captionmethod is rdjpgcom or capfile"); } die; } if ($deleteimage) { PrintHeader("Deleting an image"); if (!isadmin()) { PrintError("This is an admin-only function"); die; } if (ereg( "\\.\\.", $deleteimage)) { // using ".." in the filename PrintError("That filename ($deleteimage) was not secure."); die; } if (! unlink($deleteimage) ) { PrintError("An error occurred while deleting the image - try doing it manually."); } else { echo "Image deleted
"; } if (file_exists("$thumb/$deleteimage")) { if (! unlink("$thumb/$deleteimage")) { PrintError("An error occurred while deleting the thumbnail ($thumb/$deleteimage)"); } else { echo "Thumbnail image deleted
"; } } if (file_exists("$thumb/$imageresize$deleteimage")) { if (! unlink("$thumb/$imageresize$deleteimage")) { PrintError("An error occurred while deleting the reduced image ($thumb/$imageresize$deleteimage)"); } else { echo "Reduced size image deleted
"; } } if (file_exists("$thumb/$deleteimage.txt")) { if (! unlink("$thumb/$deleteimage.txt")) { PrintError("An error occurred while deleting the comments ($thumb/$deleteimage.txt)"); } else { echo "Guest comments deleted
"; } } if (file_exists("$thumb/$deleteimage.cap")) { if (! unlink("$thumb/$deleteimage.cap")) { PrintError("An error occurred while deleting the caption ($thumb/$deleteimage.cap)"); } else { echo "Caption file deleted
"; } } echo ""; die; } if ($upload) { if (!isadmin()) { PrintError("This is an admin-only function"); die; } if (!is_uploaded_file($imagefile["tmp_name"]) or $imagefile["size"] == 0) { PrintError("That was not a valid file."); } else { $imagefile_name = clean_filename($imagefile["name"]); if ($imagefile_name) { if (! move_uploaded_file($imagefile["tmp_name"], $imagefile_name)) { PrintError("Could not store file in this directory"); } else { echo "Uploaded $imagefile_name [".$imagefile["type"]."]
"; echo ""; die; } } else { PrintError("This file had a wierd filename"); } } $intro = "true"; } if ($intro) { // Print initial info in main frame PrintHeader($title); if (file_exists($introfile)) { include($introfile); } else { echo "". $ss[$lang]["selectr"] ."
"; } else { echo "". $ss[$lang]["selectl"] ."
"; } } if ($guestcomment && $recentcount) { echo ""; echo "$recentcount ". $ss[$lang]["recent"]; echo "
"; } if (isadmin()) { echo "You are logged in as administrator
"; echo ""; echo ""; echo "\n";
foreach ($imagelist as $image) {
$thumbimage = $thumb."/".$image;
$thumb_exists = file_exists($thumbimage);
if (!$thumb_exists) { // Try to create the thumbnail
set_time_limit(30);
$thumbwidth = $margin - 20;
$thumb_exists = ResizeImage($image, $thumbimage, $thumbwidth);
}
$caption = GetImageCaption($image, $clean=true);
$image = rawurlencode($image);
$thumbimage = $thumb."/".$image;
if ($datenames) { // Add date to comments
$imageyear = substr($image, 0, 4);
$imagemonth = substr($image, 4, 2);
$imageday = substr($image, 6, 2);
$caption = date("j-M-y ", mktime (0, 0, 0, $imagemonth, $imageday, $imageyear)) . $caption;
}
// The d=d.html was added to help dumb caches
echo "";
if ($thumb_exists) {
echo "";
} else {
echo "$caption";
}
echo "
\n";
}
echo "
";
if (!isadmin()) {
echo "Admin";
} else {
echo "Logout";
}
echo "
Made with
";
echo "Photo Frame $version
Your comment was stored and is awaiting moderation
"; } $image = $comment; } if ($image) { if (ereg( "\\.\\.", $image)) { // using ".." in the filename PrintError("That filename ($image) was not secure."); die; } $cleanimage = $image; $image = urldecode($image); if (!file_exists($image)) { PrintError("Strangely, that picture doesn't exist"); die; } $imagelist = GetFileList(); GetNeighbours($imagelist, $image, $previmage, $nextimage); $caption = GetImageCaption($image); if ($slide && $nextimage) { $meta=""; } else { $meta = ""; $slide = "0"; } PrintHeader(CleanCaption($caption), $meta); echo ""; } if ($nextimage) { echo " | "; echo " | "; PrintSlideshowForm($nextimage, $slide); echo " | "; } echo "
\n";
if ($imageresize && ! $originalimage) {
$rimage = "$thumb/$imageresize$image";
$cleanrimage = "$thumb/$imageresize".rawurlencode("$image");
if (! file_exists("$rimage")) {
$imageresize = ResizeImage($image, $rimage, $imageresize, $imageresize);
}
if ($imageresize) {
$filesize = (integer) (filesize($image) / 1024);
echo "";
echo "";
echo "\n";
} else {
echo "\n";
}
} else {
echo "\n";
}
if ($datenames) {
$imageyear = substr($image, 0, 4);
$imagemonth = substr($image, 4, 2);
$imageday = substr($image, 6, 2);
echo "
";
echo date("j F, Y", mktime (0, 0, 0, $imagemonth, $imageday, $imageyear));
echo "
\n";
}
if (isadmin()) {
echo "
Delete this image and all comments";
}
echo "
".$ss[$lang]["comments"]."