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 = "www.galutschek.at"; // Title for the overall web page
$marginsize = 130; // 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 = 500; // 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
$margincolor = "#FFFFFF"; // Used if set, else margincolor = pagecolor
$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 = "../../stylesheet/styles.css"; // Full URL to a stylesheet for all pages.
// HTML text tags used:
\n";
}
function DeleteComment($filename, $dcomment, $ctype="") {
// Given an image filename and a comment ID (time) to
// delete, it reads the file and rewrites it, leaving
// out the specified line. Returns the deleted line.
global $thumb, $ss, $lang, $timeoffset, $scriptname;
if ($ctype == "mod") {
$commentfile = "$thumb/$filename.mod";
} else {
$commentfile = "$thumb/$filename.txt";
}
$len = strlen($dcomment);
if (file_exists($commentfile)) {
$comments = file($commentfile);
rename($commentfile, $commentfile.".bak");
if ($file = fopen ($commentfile, "a")) {
foreach ($comments as $comment) {
if (substr($comment, 0, $len) == $dcomment) {
$deletedcomment = $comment;
} else {
fwrite($file, "$comment");
}
}
unlink($commentfile.".bak");
} else { // some error occurred ... try to undo the mess
PrintError("Could not delete comment from file!");
rename($commentfile.".bak", $commentfile);
}
} else {
PrintError("No comments exist for this image! ($filename)");
}
return $deletedcomment;
}
function ApproveComment($filename, $commentid) {
// Given an image filename and a comment ID (time) to
// approve, it moves the comment from the .mod file
// to the .txt file
if ($commentline = DeleteComment($filename, $commentid, "mod")) {
AddComment($filename, "", "", $commentline);
echo "
That message has been approved
";
}
}
function PrintCommentForm($filename) {
global $scriptname, $textcolor, $pagecolor;
global $ss, $lang;
?>
"));
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";
} else {
$deleteurl = "Delete: $urlstart&dcomment=$timenow\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;
$caption = "";
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;
Exec("$identify -ping -format \"%w %h\" \"$image\"", $sizeinfo);
if (! $sizeinfo ) {
return false;
}
$size = explode(" ", $sizeinfo[0]);
$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 "
";
echo "";
exit;
}
}
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 "";
}
} 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 "
";
die;
}
if ($upload) {
PrintHeader("Uploading and storing files");
if (!isadmin()) {
PrintError("This is an admin-only function");
die;
}
if (count($imagefile['name'])) {
foreach ($imagefile['name'] as $key => $name) {
if (is_uploaded_file($imagefile['tmp_name'][$key]) and $imagefile['size'][$key] > 0) {
$imagefile_name = clean_filename($name);
if ($imagefile_name) {
if (move_uploaded_file($imagefile['tmp_name'][$key], $imagefile_name)) {
echo "
";
die;
}
if ($margin) { // Create a list of thumbnails
if (!file_exists($thumb)) {
if ( ! mkdir($thumb, 0755)) {
PrintError("Could not create thumb dir - check write permissions");
die;
}
}
PrintHeader("$title: Thumbnails", "margin");
$imagelist = GetFileList();
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);
}
if (! $caption = GetImageCaption($image, $clean=true)) {
$caption = $image;
}
$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 "