# # Gallery # # # gallery.pl -- Builds photo gallery # More information: http://www.downes.ca/edurss02.htm # # by Stephen Downes # Version 0.2 - January 2, 2006 # # # Copyright 2006 Stephen Downes, National Research Council Canada # Prerelease - please do not distribute - I'll GPL it when it's ready # #------------------------------------------------------------------------------- # # Build Gallery # #--------------------------------------------------------------------------------- sub build_gallery { # Builds a photo gallery # input expected: gallery id (which in turn will be associated (we hope) with a set of photo files # template name, which will be used to display individual photos # Note: this script expects use GD; and use Image::GD::Thumbnail; to have been loaded, to make thumbnails my ($dbh,$gallery,$template,$reindex) = @_; my @photo_list; my @photo_ids; my @bigtmblist; my @tinythblist; $page->{title} = "Build Gallery"; print &header($dbh,$vars,$options,$person); # Get the Template my $stmt = qq|SELECT template_description from template WHERE template_title = ? LIMIT 1|; my $sth = $dbh->prepare($stmt); $sth->execute($template); my $ref = $sth -> fetchrow_hashref(); my $template_text = $ref->{template_description}; # Get Gallery directory my $stmt = qq|SELECT * from post WHERE post_id = ? LIMIT 1|; my $sth = $dbh->prepare($stmt); $sth->execute($gallery); my $ref = $sth -> fetchrow_hashref(); my $gallery_dir = $ref->{post_dir}; my $page_title = $ref->{post_title}; # Get the list of photos my $stmtb = qq|SELECT * from file WHERE file_post = ? ORDER BY file_crdate|; my $sthb = $dbh->prepare($stmtb); $sthb->execute($gallery); my $photo_counter = 0; my $page_descs = {}; while (my $refb = $sthb -> fetchrow_hashref()) { next unless ($refb->{file_file} =~ /(jpg|jpeg)/i); # JPG Images only push @photo_list,$refb->{file_file}; push @photo_ids,$refb->{file_id}; my $dscn=$photo_counter+1; $page_descs->{$dscn} = qq|

$refb->{file_description}|; $page_descs->{$dscn} .= " ".&nice_date($refb->{file_crdate},"month").".

"; $photo_counter++; } my $index_text = "";my $gt_ind; my $page_counter = 0; foreach my $photo (@photo_list) { my $file_id = @photo_ids[$page_counter]; $page_counter++; my $photofile = $Site->{st_base} . $photo; my $photourl = $Site->{st_url} . $photo; # Load your source image unless (open IN, "$photofile") { die "Could not open $photofile: $!"; next; } my $srcImage = GD::Image->newFromJpeg(*IN); close IN; next unless ($srcImage); my ($tiny_thumb,$gt) = &make_thumbnail($srcImage,100,$photo); unless ($gt_ind) { $gt_ind = $gt; } my ($med_thumb) = &make_thumbnail($srcImage,600,$photo); my $ph_text = $template_text; my $pg_file = $Site->{st_base}."photos/".$gallery_dir."/".$page_counter.".htm"; my $pg_url = $Site->{st_url}."photos/".$gallery_dir."/".$page_counter.".htm"; my $prev_url; if ($page_counter eq "1") { $prev_url = $Site->{st_url}."photos/".$gallery_dir."/index.htm"; } else { my $prev = $page_counter-1; $prev_url = $Site->{st_url}."photos/".$gallery_dir."/".$prev.".htm"; } my $next_url; if ($page_counter eq $photo_counter) { $next_url = $Site->{st_url}."photos/".$gallery_dir."/index.htm"; } else { my $next = $page_counter+1; $next_url = $Site->{st_url}."photos/".$gallery_dir."/".$next.".htm"; } $ph_text =~ s//$Site->{st_url}$med_thumb/; $ph_text =~ s|||g; $ph_text =~ s|||g; $ph_text =~ s//$photourl/g; $ph_text =~ s//$page_title - $page_counter/g; $ph_text =~ s//$file_id/g; $ph_text =~ s//$page_descs->{$page_counter}/g; my $gnav = qq||; $ph_text =~ s|