#!/usr/bin/perl #################################################################### # My Photo Gallery Script # Version shown in the variable set below # # This script is part of the FuzzyMonkey.org Script Archive at # www.fuzzymonkey.org and is released under the GPL license. Please # see the included LICENSE.txt file for details. # #################################################################### #if you had to install Image Magick as NON-root, please add the # use lib line #use lib "/home/username/local/lib/site_perl/5.6.0/i686-linux/"; #use lib "/home/username/local/lib/site_perl/5.6.0/"; use CGI(-debug); use CGI::Carp qw(fatalsToBrowser); use Image::Magick; require "./sitevariables.pl"; require "./common.pl"; require "./imagemagick.pl"; if($exif=~ /yes/i){ use Image::Info qw(image_info); } srand(); ############ BEGIN MAIN PROGRAM ################################ $version = "4.03"; $cur = CGI->new(); $content = ""; $page = 1; $mode = "default"; unless($resize_quality){$resize_quality="90";} unless($thumbnails_per_page){$thumbnails_per_page ="100";} if(!$directory_selection){$directory_selection = 'directory.gif';} #get cookies @cookies=split(/;/,$ENV{'HTTP_COOKIE'}); foreach $cookie (@cookies) { ($name,$value) = split (/=/,$cookie); $crumbs{$name}=$value; } if($cur->param("maxWidth")) { $maxWidth= $cur->param("maxWidth"); print "Set-Cookie: maxWidth=$maxWidth\n"; #set a cookie for the maxWidth preference } else { $maxWidth = 640; #check for cookie if($cur->cookie('maxWidth')){$maxWidth=$cur->cookie('maxWidth');} } if($cur->param("mode")) { $mode = $cur->param("mode"); } if($cur->param("album")) { $selectedalbum = $cur->param("album"); $htmlalbum = $selectedalbum; $htmlalbum =~ s/ /%20/g; if(-e "$photoroot/$selectedalbum/lock"){ if($cur->cookie('username') || $cur->param("username")){ $found = "no"; $username_cookie = $cur->cookie('username'); $password_cookie = $cur->cookie('password'); $username_form = $cur->param("username"); $password_form = $cur->param("password"); open(LOCKFILE,"<$photoroot/$selectedalbum/lock"); while(){ chomp; next unless $_; ($username_file,$password_file) = split(/=/,$_); if(($username_cookie eq $username_file)&&($password_cookie eq $password_file)){ $found = "yes"; } if(($username_form eq $username_file)&&($password_form eq $password_file)){ $found = "yes"; } } close(LOCKFILE); unless($found eq "yes"){ $mode = "askpassword"; } }else{ $mode = "askpassword"; } } } if($cur->param("page")) { $page = $cur->param("page"); } if($cur->param("picture")) { $selectedpicture= $cur->param("picture"); $htmlpicture = $selectedpicture; $htmlpicture =~ s/ /%20/g; $htmlpicture =~ s/#/%23/g; } if($cur->param("movie")) { $selectedmovie = $cur->param("movie"); $htmlmovie = $selectedmovie; $htmlmovie =~ s/ /%20/g; } if($cur->param("username")){ $username = $cur->param("username"); $password = $cur->param("password"); print "Set-Cookie:username=$username\n"; print "Set-Cookie:password=$password\n"; } checkforbadthings(); if($mode eq "default"){ $selectedalbum = ''; $mode = "view"; } if($mode eq "view"){ $content .= check_data_directories($selectedalbum); $content .= checkdirectories($selectedalbum); #check for thumbnail and descriptions directories $content .= generatealbum("$selectedalbum"); } if($mode eq "viewpicture"){ if($cur->param("comment")){ #getcomment(); } $content .= generatepicture($selectedalbum,$selectedpicture); } if($mode eq "askpassword"){ $content .= passwordform(); } printpage($content,"template.html"); ############ BEGIN SUBROUTINES ################################# ################################################################ # takes the selected album and makes sure that we have all of # the directories that we need up to that point ############################################################### sub check_data_directories($){ my $directory = $_[0]; my $return; my @steps; my $step; my $sofar; @steps = split (/\//,"$directory"); #$return .= "checking data directories for $directory
"; foreach $step (@steps){ $step =~ s/\///gi; if($sofar){ $sofar = "$sofar/$step" }else{ $sofar = "$dataroot/$step"; } unless(-e "$sofar"){ #$return .= "creating $sofar with 755 permissions
"; mkdir("$sofar",0755)||dienice("Could not create data directory! $!"); } } return $return; } sub generatealbum ($) { my $return; my $selectedalbum = $_[0]; #sanity check #if(!$selectedalbum){ #dienice("No album was selected"); #$content .= "warning: no album was selected
"; #} $return .= print_location($selectedalbum, pageParams()); $_[0] =~ s/ /\\ /g; #fix spaces for globbing and file opening ########################################### #get the hits and stuff for this album ########################################### my $hits = logpicture("$selectedalbum/"); my $hitstring = "
album viewed $hits times
"; ########################################### #check for description of this album ########################################### my $description; if(open (INFILE, "$dataroot/$selectedalbum/descriptions/album.txt")){ $description .= ''; flock (INFILE, 2); #locks the file for exclusive access. while(){ $description .= "$_"; } flock (INFILE, 8); #unlocks the file close(INFILE); } unless($description){ $description =""; } if($smiley =~ /yes/i){ $description = make_faces($description); } $description =~ s/\n/
/g; #$return .= ""; my @files= glob "$photoroot/$_[0]/*"; #find a better way to do this my $count =0; # Hack to sort Directories first. -KWP 11/05/2003 @files = sort {(-d $b) <=> (-d $a) || $a cmp $b} @files; # take only those files in the current page. If the 1024, site-images, etc. # are in this directory, then they're included in the count even though they # are not displayed. my ($start, $end, $total_pages) = pageBounds(scalar(@files)); @files = @files[$start..$end]; $return .= "
\n"; $return .= generatepagewidget( "index.cgi?mode=view\&album=$selectedalbum", $total_pages, $page ); $return .="
\n"; $return .= ""; foreach $file (@files){ if(-d $file){ # it is a directory unless (($file =~ /1024/) ||($file =~ /800/) ||($file =~ /640/) ||($file =~ /320/) ||($file =~ /site-images/) ||($file =~ /comments/) ||($file =~ /descriptions/) ||($file =~ /thumbnails/)){ $file =~ s/.*\/(.*)/$1/g; my $cgihtmlalbum = $selectedalbum; $cgihtmlalbum =~ s/ /+/g; my $cgihtmlsubdirectory = $file; $cgihtmlsubdirectory =~ s/ /+/g; my $prettysubdirectory = $file; $prettysubdirectory = makepretty($prettysubdirectory); $count++; if(-e "$dataroot/$selectedalbum/$file/descriptions/directory.gif"){ $folder_picture = "$dataurl/$selectedalbum/$file/descriptions/directory.gif"; }else{ if(-e "$photoroot/$selectedalbum/$file/lock"){ $folder_picture = "$dataurl/site-images/$directory_selection"; $folder_picture =~ s/(.*)\.(.*)/$1-locked.$2/; }else{ $folder_picture = "$dataurl/site-images/$directory_selection"; } } $return .= ""; } }elsif($file =~ /\.(jpg|png|gif)\b/i){ #this is a supported image format (jpeg,png, or gif) fileinfo($file); $file =~ s/.*\/(.*)/$1/g; ################################################ # lets check for a thumbnail ################### ################################################ my $thumbnail = $file; #$thumbnail =~ s/(.*)\.(jpg|png|gif)\b/$1.jpg/i; unless(-e "$dataroot/$selectedalbum/thumbnails/$thumbnail"){ resize("$photoroot/$selectedalbum/$file","$dataroot/$selectedalbum/thumbnails/$thumbnail",$previewWidth,$resize_quality); if($mag_on_thumbnails =~ /yes/i){ overlay("$dataroot/$selectedalbum/thumbnails/$thumbnail","$dataroot/$selectedalbum/thumbnails/$thumbnail","$dataroot/site-images/mag.png"); } } my $cgihtmlalbum = $selectedalbum; $cgihtmlalbum =~ s/ /+/g; my $cgihtmlpicture = $file; $cgihtmlpicture =~ s/ /+/g; $cgihtmlpicture =~ s/&/%26/g; my $prettypicture = makepretty($file); #fix spaces for old netscape and such $thumbnail =~ s/ /%20/g; $thumbnail =~ s/#/%23/g; my $comments_text = ""; if((-e "$dataroot/$selectedalbum/comments/$file.txt") && ($indicate_comments =~ /yes/i)){ $comments_text = "\"Comments"; } #NOTE to self: each line below has a tag because the new #netscape was putting a funky line because of the line break $return .= "\n"; $count++; #not to me....this line broken ... get extention and look it up to display icon }elsif( ($file =~ /.*(\..*)\b/i) && (defined $filetypes{"$1"})){ fileinfo($file); my $ext = $1; $file =~ s/.*\/(.*)/$1/g; my $htmlfile = $file; $htmlfile =~ s/ /%20/g; $htmlfile =~ s/#/%23/g; $return .= ""; $count++; }else{ #we don't know what kind of file this is fileinfo($file); $file =~ s/.*\/(.*)/$1/g; unless($file eq "lock" || $file eq "Thumbs.db"){ my $htmlfile = $file; $htmlfile =~ s/ /%20/g; $htmlfile =~ s/#/%23/g; $return .= ""; $count++; } } if($count >= $thumbnails_per_row){ $count =0; $return .= "\n"; } } $return .= "

$prettysubdirectory
\"$file\"
$prettypicture$comments_text
$time

$file
$time ($kfilesize)

$file
$time ($kfilesize)
"; $return .= "

\n"; $return .= generatepagewidget( "index.cgi?mode=view\&album=$selectedalbum", $total_pages, $page ); $return .="
\n"; return $return; } ########################################################### # Generates the CGI parameters needed to direct an album # to the current page. # by Todd Gamblin 5/29/2004 ########################################################### sub pageParams { $page = 1 unless $page; my $pageParams; $pageParams = "page=$page" unless ($thumbnails_per_page =~ /off/i); return $pageParams; } ########################################################### # Given a total number of files, returns a triple like so: # # ($startIndex, $endIndex, $totalPages) # # where start index is the first file to be on the page, # end index is the last to be on the page, and total # pages is the total number of pages in the album. # # by Todd Gamblin 5/29/2004 ########################################################### sub pageBounds { my ($total_files) = @_; my $last_file = $total_files - 1; return (0, $last_file, 1) if ($thumbnails_per_page =~ /off/i); my $start_file = ($page - 1) * $thumbnails_per_page; if ($start_file < 0 || $start_file > $last_file) { $start_file = 0; $page = 1; } my $end_file = $start_file + $thumbnails_per_page - 1; if ($end_file > $last_file) { $end_file = $last_file; } my $total_pages = int($total_files / $thumbnails_per_page); $total_pages++ if ($total_files % $thumbnails_per_page); #take ceiling return ($start_file, $end_file, $total_pages); } ########################################################### # Given a base URL, the total number of pages, and the # current page, generates a widget to move between pages # and returns the html for it. # by Todd Gamblin 5/29/2004 ########################################################### sub generatepagewidget { my ($baseurl, $total_pages, $current_page) = @_; return if ($total_pages == 1 || ($thumbnails_per_page =~ /off/i)); my $return; $return .= "\n"; $return .= "\n"; if ($current_page > 1) { my $prev = $current_page - 1; $return .= ""; } $return .= ""; if ($current_page < $total_pages) { my $next = $current_page + 1; $return .= ""; } $return .= "
Page: "; $return .= "\"<-\"\n"; $return .= ""; foreach $i (1..$total_pages) { if ($i == $current_page) { $return .= "$i"; } else { $return .= "$i"; } $return .=" "; } $return .= ""; $return .= "\"-\"> "; $return .= "
"; return $return; } sub checkforbadthings { $selectedalbum =~ s/\\//g; $selectedpicture =~ s/\\//g; $selectedalbum =~ s/\*//g; $selectedpicture =~ s/\*//g; $selectedpicture =~ s/\(//g; $selectedpicture =~ s/\}//g; $selectedalbum =~ s/\(//g; $selectedalbum =~ s/\}//g; if($selectedalbum =~ /\.\./){ hacking_attempt("

Attempted hack detected!

Your malicious behavior has been caught and logged. Depending on where you live, there could be severe criminal penalties associated with computer crimes. The webmaster may use this information to prosecute you to the full extent of the law. In short, don't do this anymore. Even just poking around could land you in serious trouble!

"); } if($selectedpicture=~ /\.\./){ hacking_attempt("

Attempted hack detected!

Your malicious behavior has been caught and logged. Depending on where you live, there could be severe criminal penalties associated with computer crimes. The webmaster may use this information to prosecute you to the full extent of the law. In short, don't do this anymore. Even just poking around could land you in serious trouble!

"); } if($cur->param("q") =~ /\.\./){ hacking_attempt("Illegal! You should be ashamed. "); } } sub passwordform{ my $return; $return .= "
This gallery requires a username and passord.
Username
Password
"; return $return; } # Extract the EXIF data from a picture sub get_exifdata ($) { my $value; my $exifdata=""; my $info = image_info("$_[0]"); # make and model my $Make = $info->{'Make'}; my $Model = $info->{'Model'}; if ((defined($Make)) || (defined($Model))){ $value = ($Model =~ /$Make/) ? "$Model" : "$Make $Model"; $exifdata .= exifentry("Camera", $value); } # exposure time $value = ''; if (defined($info->{'ExposureTime'}[1])){ if (($info->{'ExposureTime'}[1] > $info->{'ExposureTime'}[0]) && ($info->{'ExposureTime'}[0] != 0)){ $value = "1/" . sprintf("%.0f", $info->{'ExposureTime'}[1] / $info->{'ExposureTime'}[0]); }elsif ($info->{'ExposureTime'}[1] != 0){ $value = $info->{'ExposureTime'}[0] / $info->{'ExposureTime'}[1]; } }elsif (defined($info->{'ShutterSpeedValue'}[1]) && ($info->{'ShutterSpeedValue'}[1] != 0)){ $value = 2**($info->{'ShutterSpeedValue'}[0] / $info->{'ShutterSpeedValue'}[1]); if ($value < 1){ $value = 1 / $value; }else{ $value = "1/" . sprintf("%.0f", $value); } } if ($value){ if ($value =~ /\..../){ $value = sprintf("%.2f", $value); } $exifdata .= exifentry("Exposure", "$value sec."); } # aperture (f number) $value = ''; if (defined($info->{'FNumber'}[1]) && ($info->{'FNumber'}[1] != 0)){ $value = $info->{'FNumber'}[0] / $info->{'FNumber'}[1]; }elsif (defined($info->{'ApertureValue'}[1]) && ($info->{'ApertureValue'}[1] != 0)){ $value = sqrt(2)**($info->{'ApertureValue'}[0] / $info->{'ApertureValue'}[1]); } if ($value){ if ($value =~ /\.../){ $value = sprintf("%.1f", $value); } $exifdata .= exifentry("Aperture", "f/$value"); } #focal length if (defined($info->{'FocalLength'}[1]) && ($info->{'FocalLength'}[1] != 0)) { $value = $info->{'FocalLength'}[0] / $info->{'FocalLength'}[1]; if ($value =~ /\..../){ $value = sprintf("%.2f", $value); } $exifdata .= exifentry("Focal length", $value . " mm"); } # ISO speed if (defined($info->{'ISOSpeedRatings'})){ $exifdata .= exifentry("ISO",$info->{'ISOSpeedRatings'}); } # focus distance if (defined($info->{'SubjectDistance'}[1]) && ($info->{'SubjectDistance'}[1] != 0)){ $value = $info->{'SubjectDistance'}[0] / $info->{'SubjectDistance'}[1]; if ($value =~ /\...../){ $value = sprintf("%.3f", $value); } $exifdata .= exifentry("Focus", $value . " m"); } # flash if (defined($info->{'Flash'})) { my $value = (($info->{'Flash'} =~ /fired/i) || ($info->{'Flash'} =~ /yes/i) || ($info->{'Flash'} == 1)) ? "Yes" : "No"; $exifdata .= exifentry("Flash", $value); } # date and time if (defined($info->{'DateTimeOriginal'}) && ($info->{'DateTimeOriginal'} ne '0000:00:00 00:00:00')){ my $cam_date = $info->{'DateTimeOriginal'}; my ($date,$time) = split(/ /,"$cam_date"); my ($year,$month,$day) = split(/:/,"$date"); my ($hours,$minutes,$seconds) = split(/:/,"$time"); my @months = ("","Jan","Feb","Mar","Apr","May","Jun", "Jul","Aug","Sep","Oct","Nov","Dec"); $month = $months[$month]; if($hours > 11 && $hours != 0){ $hours = $hours - 12; $ampm = "PM"; }else{ if($hours == 0){$hours = 12;} $ampm = "AM"; } $exifdata .= exifentry("Date taken", "$month $day, $year at $hours:$minutes:$seconds $ampm"); } # comment if (defined($info->{'Comment'}) && ($info->{'Comment'} ne "")) { $exifdata .= exifentry("Comment", $info->{'Comment'}); } if (defined($info->{'UserComment'}) && ($info->{'UserComment'} ne "")) { $usercomment = $info->{'UserComment'}; $usercomment =~ s/ASCII//g; $usercomment =~ s/[^\w\s]//g; $exifdata .= exifentry("User comment", $usercomment); } if ($exifdata){ $exifdata = "
Embedded EXIF data
$exifdata
"; } return $exifdata; } # format an EXIF table entry sub exifentry($$) { return "\n\t\t$_[0]:$_[1]"; } sub generatepicture { my $return; getPrevNextButtons($selectedalbum, $selectedpicture); #get width and height my($imageToPing) = Image::Magick->new; my($itemToDisplay) = "$photoroot/$selectedalbum/$selectedpicture"; $x = $imageToPing->Read($itemToDisplay); warn $x if $x; ($width,$height) = $imageToPing->Get('width','height'); undef $imageToPing; #fixing spaces for cgi link my $cgihtmlalbum = $selectedalbum; $cgihtmlalbum =~ s/ /+/g; my $shutterflytext; if($allowshutterfly =~ /YES/i){ my $thumbnail = $htmlpicture; $thumbnail =~ s/(.*)\.(jpg|png|gif)\b/$1.jpg/i; $shutterflytext = "
from shutterfly.com"; $shutterflytext =~ s/\n//g; } my $clubphototext; if($allowclubphoto =~ /YES/i){ my $thumbnail = $htmlpicture; $thumbnail =~ s/(.*)\.(jpg|png|gif)\b/$1.jpg/i; $clubphototext = < from ClubPhoto.com HTML $clubphototext =~ s/\n//g; } $saveWidth = $width; $saveHeight= $height; $sizewarning = ""; if(($width >= $maxWidth) || ($height >= $maxWidth)){ $content .= createNewWidthPicture(); #fix a few things when printing the picture out $htmlpicture = "$maxWidth/$htmlpicture"; if($width > $height){ $height =int ($height/($width/$maxWidth)); $width = int ($maxWidth); }else{ $width = int ($width/($height/$maxWidth)); $height = int ($maxWidth); } $sizewarning = "(viewing at $width x $height)"; } my $resizebutton ="
"; my ($prettypicture) = $selectedpicture; $prettypicture = makepretty($prettypicture); $return .= print_location($selectedalbum, pageParams()); my $table_width = $width; if($table_width < 320){ $table_width = 320; } $return .= "

"; my $picture = "$photoroot/$selectedalbum/$selectedpicture"; fileinfo($picture); my $hits = logpicture("$selectedalbum/$selectedpicture"); my $hitstring = ""; my $description = getdescription($selectedalbum,$selectedpicture); if($smiley =~ /yes/i){ $description = make_faces($description); } my $commentmsg =''; if($allowcomments =~ /YES/i){ $commentmsg = "Users may add comments below"; } $shadowwidth=$width -16; #lower left shadow is 16 pixels wide. Current table layout requires the bottom shadow to that much less. if($exif=~ /yes/i){ $exifdata = get_exifdata("$picture"); }else{ $exifdata = ""; } # $return .= "
$prev $prettypicture $next
viewed: $hits times
$description
"; if($shadow =~ /yes/i){ $return .= "
"; $return .="
"; }else{ $return .= "
"; } if(($width < $maxWidth) && ($height < $maxWidth)){ $return .= ""; }else{ $return .= ""; } if($shadow =~ /yes/i){ $return .= "
 
"; } $return .="
$description
$hitstring "; $return .="
uploaded: $time
file size: $kfilesize
image size: $saveWidth x $saveHeight $sizewarning
 
$resizebutton
 
$shutterflytext $clubphototext
$exifdata
$prev $prevThumb $pictureNumber out of $numberofpictures $nextThumb $next
"; if($allowcomments =~ /YES/i) { $return .= "
"; $return .= getcomments(); $return .= "
"; } my $shutterflytext; if($allowshutterfly =~ /YES/i){ $shutterflytext="
This gallery has support for Shutterfly. Click the \"order this photo\" button to quickly and easily order high-quality photographic prints of your favorite pictures through Shutterfly.com"; } $return .= "$shutterflytext"; $return .= "
"; return $return; } sub logpicture { #needs to have the name of the picture passed as an argument. Opens log file. Increments for #that picture, and write the data file back out. #open datafile and get info if(-e "$dataroot/$selectedalbum/log.txt"){ # only if it exists open (INFILE, "$dataroot/$selectedalbum/log.txt")|| dienice("I could not open the log file! If this is your first time running it, please manually create a blank data file. You need a blank text file called log.txt in the same directory as the index.cgi. This file should be rw by whatever user your web server runs as."); flock (INFILE, 2); #locks the file for exclusive access. while(){ chomp(); my ($picture,$hits) = split(/=/,$_); #read in each timeslot one per line $picturelog{"$picture"} = $hits; } flock (INFILE, 8); #unlocks the file close(INFILE); } #incriment hit counter for the current picture $picturelog{$_[0]}++; #re-write data file with new info open(OUTFILE,">$dataroot/$selectedalbum/log.txt") || dienice("Cound not open data file for writing!"); flock (OUTFILE, 2); foreach $key (sort keys %picturelog) { print OUTFILE "$key=$picturelog{\"$key\"}\n"; } flock (OUTFILE, 8); close(OUTFILE); return $picturelog{$_[0]}; } sub getdescription($$) { my $return = ""; #open datafile if(open (INFILE, "$dataroot/$_[0]/descriptions/$_[1].txt")){ flock (INFILE, 2); #locks the file for exclusive access. while(){ $_ =~ s/[\r\f]/
/gi; $_ =~ s/\n//gi; $return .= "$_"; } flock (INFILE, 8); #unlocks the file close(INFILE); } $return = "
$return
"; return $return; } sub makepretty { my $pretty = $_[0]; if($prettypicturenames =~ /YES/i) { if($remove_leading_numbers =~ /yes/i){ $pretty =~ s/^[0-9]*//g; } $pretty =~ s/_/ /g; $pretty =~ s/-/ /g; $pretty =~ s/ / /g; $pretty =~ s/(.*)\..*/\1/g; } return $pretty; } ######################################################################### ## open comments file and return a pretty table of the comments########## ######################################################################### sub getcomments { my $return; my $count=0; my @comments; my $selecteditem; #make comments directory if it doesn't exist unless(-e "$dataroot/$selectedalbum/comments"){ #print "Making directory $photoroot/$selectedalbum/comments...

"; mkdir("$dataroot/$selectedalbum/comments",0755) || dienice("Error, could not make comments directory please check the permissions!

"); } #little trick to get comments on movies to work :-) if(!($selectedpicture)){ $selectedpicture = $selectedmovie; } #open datafile if(open (INFILE, "$dataroot/$selectedalbum/comments/$selectedpicture.txt")){ flock (INFILE, 2); #locks the file for exclusive access. while(){ chomp(); push (@comments,$_); } flock (INFILE, 8); #unlocks the file close(INFILE); } my $cgihtmlalbum = $selectedalbum; $cgihtmlalbum =~ s/ /+/g; my $cgihtmlpicture = $selectedpicture; $cgihtmlpicture =~ s/ /+/g; $return .= "
"; $return .= ""; my $commentcolor ="$commentcolor1"; foreach $comment (@comments) { $count++; my ($time,$name,$email,$comment) = split(/=/,$comment,4); #alternate row colors if($commentcolor eq "$commentcolor1"){ $commentcolor = $commentcolor2; }else { $commentcolor = $commentcolor1; } my $email_comment; if ($email){ $email_comment = "";} if($smiley =~ /yes/i){ $comment = make_faces($comment); } $return .=" "; } unless($count){ $return .= ""; } $mode = $cur->param("mode"); if($mode =~ /picture/i){ $return .= " "; } else { $return .= " "; } $return .="
Comments
$name $says[int(rand(@says))] :  $email_comment
$comment
$time
There are currently no comments for this item.
Add Comment
Name:
Email (optional):
Comments:
Add Comment
Name:
Email:
Comments:
"; return $return; } ######################################################################### # takes comments from a form and adds them to the comments file ######### ######################################################################### sub getcomment { my $name = $cur->param("name"); my $email= $cur->param("email"); my $comment = $cur->param("comment"); my $time = localtime(time()); my $email_comment; my $body; $name= &stripBadHtml($name); unless($name){$name = "anonymous";} $email = &stripBadHtml($email); $comment = &stripBadHtml($comment); $comment =~s /\n/
/g; #little trick to get comments on movies to work :-) if(!($selectedpicture)){ $selectedpicture = $selectedmovie; } #append new comment to data file if(open(OUTFILE,">>$dataroot/$selectedalbum/comments/$selectedpicture.txt")) { flock (OUTFILE, 2); print OUTFILE "$time=$name=$email=$comment\n"; flock (OUTFILE, 8); close(OUTFILE); if($email_comments_to_admin =~ /YES/i){ $body = "$name ($email) posted a comment to your photo gallery at $ENV{'HTTP_REFERER'} on $time. \nAlbum:\t\t$selectedalbum\nPicture:\t$selectedpicture\n\nThey commented:\n$comment \nProvided by a a FREE script from http://www.fuzzymonkey.org/"; email("comment posted on photo gallery",$admin_email,$email,$email,$body); } return $picturelog{$_[0]}; }else { dienice("There was an error writing to the comments file. This script does not have the proper file permissions to write to the comments file! Please see the README or the CGI tutorial on fuzzymonkey.org for more information."); } } # searches current directory for current picture in order to get previous # and next pictures. This will be used to make previous and next buttons. # the text for the previous and next buttons will be stored in # global varaibles $next and prev # also sets the $page variable to the page that the current picture is on. sub getPrevNextButtons { my $album = $_[0]; my $picture = $_[1]; $album =~ s/ /\\ /g; #make spaces glob friendly my @files= glob ("$photoroot/$album/*"); $album =~ s/\\ /+/g; #make glob friendly spaces, cgi friendly my @pictures; # discard directories, record offset of current picture, # total number of pictures, and page number of current image. my $offset = -1; $numberofpictures = 0; #for use in the main script for ($i=0; $i < (@files); $i++) { my $file = @files[$i]; if ($files[$i] eq "$photoroot/$_[0]/$picture") { # know pic's offset $offset = $numberofpictures; #to know which picture out of how many we are viewing $pictureNumber = $offset + 1; #know what page the pic's on (note that this count includes dirs) $page = int($pictureNumber / $thumbnails_per_page); $page++ if ($pictureNumber % $thumbnails_per_page); #take ceiling } if($file =~ /\.(jpg|png|gif)\b/i) { push(@pictures, $file); $numberofpictures++; } } if ($offset < 0) { dienice("Not found: $picture"); # pic wasn't there. } $prev = ' '; $next = ' '; $prevThumb = ' '; $nextThumb = ' '; # make next and prev buttons if($offset > 0) { #this is not the first picture, so we make a prev button my $prevPicture = $pictures[$offset-1]; $prevPicture =~ s#.*/##; # remove directory crap my $htmlprevPictureThumb = $prevPicture; #make a version for html (for thumbnail) $htmlprevPictureThumb =~ s/ /%20/g; $htmlprevPictureThumb =~ s/#/%23/g; #$htmlprevPictureThumb =~ s/(.*)\.(jpg|png|gif)\b/$1.jpg/i; $prevPicture =~ s/ /+/g; # make a cgi link friendly one $prevPicture =~ s/&/%26/g;# thanks to Andrew I Baznikin for fixing '&' in pictures $prev = "  previous"; $prevThumb = " "; } if($offset < ((@pictures)-1)){ #this is not the last picture we make next button #prepair picture for link (get ride of #directory info and spaces my $nextPicture = $pictures[$offset+1]; $nextPicture =~ s#.*/##; my $htmlnextPictureThumb = $nextPicture; #make a version for html (for thumbnail) $htmlnextPictureThumb =~ s/ /%20/g; $htmlnextPictureThumb =~ s/#/%23/g; #$htmlnextPictureThumb =~ s/(.*)\.(jpg|png|gif)\b/$1.jpg/i; $nextPicture =~ s/ /+/g; $nextPicture =~ s/&/%26/g; # thanks to Andrew I Baznikin for fixing '&' in pictures $next = " next "; $nextThumb = " "; } } ############################################################################## # Creates a new picture in the subdirectory for the current width ############################################################################## sub createNewWidthPicture{ my $return; #Make sure it is an allowed width if(!($maxWidth eq 320 ||$maxWidth eq 640 || $maxWidth eq 800 || $maxWidth eq 1024 || $maxWidth eq 9999)){ dienice("$maxWidth is an invalid parameter for the picture width!"); } #make directory for smaller pictures if it doesn't exist unless(-e "$dataroot/$selectedalbum/$maxWidth"){ #print "Making directory $photoroot/$selectedalbum/$maxWidth ...

"; mkdir("$dataroot/$selectedalbum/$maxWidth",0755) || dienice("Error, could not make directory for this size image please check the permissions!

"); } #create smaller size if it doesnt exist or the thumbnail is older than the picture unless((-e "$dataroot/$selectedalbum/$maxWidth/$selectedpicture")){ resize("$photoroot/$selectedalbum/$selectedpicture", "$dataroot/$selectedalbum/$maxWidth/$selectedpicture",$maxWidth,$resize_quality); } return $return; } sub make_faces($){ my $text = $_[0]; unless($text && $smiley){return;} #skip if we don't have any text #or we don't have smiley turned on $text =~ s/[:=][-o^]?\)//g; $text =~ s/[:=][-o^]?P//gi; $text =~ s/[:=][-o^]?D//g; $text =~ s/[:=][-o^]?[0O]//g; $text =~ s/[;=][-o^]?\)//g; $text =~ s/[:=][-o^]?\|//g; $text =~ s/[:=][-o^]?[\\]//g; $text =~ s/[:=][-o^][\/]{1,1}//g; #$text =~ s/o/test/g; return $text; } sub printsearchmatch { my $album = $_[0]; $album =~ s/\\ /+/g; #make web link friendly $album =~ s/ /+/g; #make web link friendly my $picture = $_[1]; $picture =~ s/\\ /+/g; #make web link friendly $picture =~ s/ /+/g; #make web link friendly if($picture =~ /.*\.(mpg|avi|mov|ram)/){ # we have a movie $mode = 'viewmovie'; $arg = "movie=$picture"; } else { $mode = 'viewpicture'; $arg = "picture=$picture"; } my $return = "
Image: $picture
Album: $album
Found in: $_[2]

"; return $return; } #####################################################3 #subs from slashdot to remove bad html ##################################################### # Thanks to Slashdot for these # Approved HTML tags for HTML posting @approvedtags = ( 'B','I','P .*','P','A', 'LI','OL','UL','EM','BR', 'STRONG','BLOCKQUOTE', 'HR','DIV .*','DIV','TT' ); sub stripBadHtml { my ($str) = @_; $str =~ s/(\S{90})/$1 /g; $str =~ s/<(?!.*?>)//; $str =~ s/<(.*?)>/approvetag($1,@approvedtags)/sge; #replace tags with approved ones return $str; } sub approvetag { my ($tag,@apptag) = @_; $tag =~ s/^\s*?(.*)\s*?$/$1/e; #trim leading and trailing spaces if (uc(substr ($tag, 0, 2)) eq 'A ') { $tag =~ s/^.*?href="?(.*?)"?$/A HREF="$1"/i; #enforce "s return "<" . $tag . ">"; } foreach my $goodtag (@apptag) { $tag = uc $tag; if ($tag eq $goodtag || $tag eq '/' . $goodtag) {return "<" . $tag . ">";} #check against my list of tags } return ""; }