diff -rc --new-file Apache-Gallery-1.0.1-cpan/lib/Apache/Gallery/Template.pm Apache-Gallery-1.0.1.1/lib/Apache/Gallery/Template.pm *** Apache-Gallery-1.0.1-cpan/lib/Apache/Gallery/Template.pm 1969-12-31 16:00:00.000000000 -0800 --- Apache-Gallery-1.0.1.1/lib/Apache/Gallery/Template.pm 2011-03-21 22:20:46.000000000 -0700 *************** *** 0 **** --- 1,180 ---- + # This is for internal use by Apache::Gallery + package Apache::Gallery::Template; + + use strict; + use base qw(Class::Accessor); + use Apache::Gallery; + + our $VERSION = $Apache::Gallery::VERSION; + our %tclasses = ( + # map templating classes to Apache::Gallery::Template subclasses for them + "Text::Template" => "Apache::Gallery::Template::Text", + "Template" => "Apache::Gallery::Template::TT2", + ); + + # make accessors + Apache::Gallery::Template->mk_ro_accessors(qw(templates dir tclass)); + + # instantiate an Apache::Gallery::Template + sub new { + my $class = shift; + my $self = {}; + my %params = @_; + foreach my $p ( "templates", "dir", "tclass", "broken", "scratch" ) { + if ( exists $params{$p}) { + $self->{$p} = $params{$p}; + } + } + + # default to Text::Template because Apache::Gallery started with it + if ( ! defined $self->{tclass}) { + $self->{tclass} = "Text::Template"; + } + + # determine subclass for this object based on templating class specified + my $subclass; + eval "require ".$self->{tclass}; # fail if it doesn't exist + if ( $class eq "Apache::Gallery::Template" ) { + # more specific subclass available from tclass parameter + # default to Apache::Gallery::Template::Text + $subclass = "Apache::Gallery::Template::Text"; + if ( exists $tclasses{$self->{tclass}}) { + $subclass = $tclasses{$self->{tclass}}; + } + } else { + # subclass already specified + $subclass = $class; + } + bless $self, $subclass; + + # perform subclass-specific initialization + $self->initialize(); + return $self; + } + + # gulp read a file into a string + sub gulp + { + my ( $self, $file ) = @_; + + my $size = -s $file; + if ( open ( FILE, $file )) { + my $text; + read FILE, $text, $size; + close FILE; + return $text; + } + return undef; + } + + # force use of a subclass - should never get here due to subclass lookup + sub notinsubclass + { + die "use a subclass of Apache::Gallery::Template\n"; + } + sub initialize { notinsubclass; } + sub do { notinsubclass; } + + # subclass to handle Text::Template + package Apache::Gallery::Template::Text; + use base qw(Apache::Gallery::Template); + + # initialize for Text::Template + sub initialize + { + my $self = shift; + $self->{template_objs} = {}; + my $dir = $self->dir; + $self->{suffix} = "tpl"; + my $broken = $self->{broken}; + + # load template files as Text::Template objects into hash + for my $template_name (keys %{$self->{templates}}) { + my $path = $dir."/".$self->{templates}{$template_name}."." + .$self->{suffix}; + my $tt_obj = Text::Template->new(TYPE => 'FILE', + SOURCE => $path, + BROKEN => $broken, + BROKEN_ARG => [$template_name, $path ], + ) + or die "Unable to create new Text::Template object for $template_name: $Text::Template::ERROR"; + $self->{template_objs}{$template_name} = $tt_obj; + } + } + + # process template with Text::Template + sub do + { + my $self = shift; + my $tmpl = shift; + my $vars = shift; + $vars->{scratch} = $self->{scratch}; # scratch available in all templates + + if ( !exists $self->{template_objs}{$tmpl}) { + my $broken = $self->{broken}; + return &$broken( name => $tmpl, file => "unknown", + error => "not found" ); + } + return $self->{template_objs}{$tmpl}->fill_in( HASH => $vars ); + } + + # subclass to handle Template Toolkit 2 + package Apache::Gallery::Template::TT2; + use base qw(Apache::Gallery::Template); + + # initialize for Template Toolkit 2 + sub initialize + { + my $self = shift; + my $dir = $self->dir; + $self->{suffix} = "tt2"; + + # set up Template Toolkit object + $self->{tt2_obj} = Template->new( { INCLUDE_PATH => $dir } ); + + # load template files as text into hash + $self->{text} = {}; + $self->{paths} = {}; + for my $template_name (keys %{$self->{templates}}) { + my $path = $dir."/".$self->{templates}{$template_name}."." + .$self->{suffix}; + $self->{text}{$template_name} = $self->gulp( $path ); + $self->{paths}{$template_name} = $path; + } + } + + # process template with Template Toolkit 2 + sub do + { + my $self = shift; + my $tmpl = shift; + my $vars = shift; + $vars->{scratch} = $self->{scratch}; # scratch available in all templates + + # substitute lower-case variable names when in conflict with reserved word + # note: BACK is not a reserved word - included for consistency w/ NEXT + foreach my $rw ( "META", "NEXT", "BACK" ) { + if ( exists $vars->{$rw}) { + $vars->{lc($rw)} = $vars->{$rw}; + } + } + + # error if the named template does not match one which was loaded + if ( !exists $self->{text}{$tmpl}) { + my $broken = $self->{broken}; + return &$broken( name => $tmpl, file => "unknown", + error => "not found" ); + } + + # process template + my $template = $self->{text}{$tmpl}; + my $result; + if ( ! $self->{tt2_obj}->process( \$template, $vars, \$result )) { + my $broken = $self->{broken}; + return &$broken( name => $tmpl, file => $self->{paths}{$tmpl}, + error => $self->{tt2_obj}->error ); + } + return $result; + } + + 1; diff -rc --new-file Apache-Gallery-1.0.1-cpan/lib/Apache/Gallery.pm Apache-Gallery-1.0.1.1/lib/Apache/Gallery.pm *** Apache-Gallery-1.0.1-cpan/lib/Apache/Gallery.pm 2011-02-23 11:46:15.000000000 -0800 --- Apache-Gallery-1.0.1.1/lib/Apache/Gallery.pm 2011-03-21 22:22:38.000000000 -0700 *************** *** 7,13 **** use vars qw($VERSION); ! $VERSION = "1.0.1"; BEGIN { --- 7,13 ---- use vars qw($VERSION); ! $VERSION = "1.0.1.1"; BEGIN { *************** *** 40,45 **** --- 40,46 ---- } } + use Apache::Gallery::Template; use Image::Info qw(image_info); use Image::Size qw(imgsize); use Image::Imlib2; *************** *** 62,67 **** --- 63,69 ---- sub handler { + my $scratch = {}; #scratchpad space for templates my $r = shift or Apache2::RequestUtil->request(); unless (($r->method eq 'HEAD') or ($r->method eq 'GET')) { *************** *** 151,157 **** my $fileinfo = stat($file); my $nonce = md5_base64($fileinfo->ino.$fileinfo->mtime); ! if ($r->headers_in->{"If-None-Match"} eq $nonce) { return Apache2::Const::HTTP_NOT_MODIFIED(); } --- 153,159 ---- my $fileinfo = stat($file); my $nonce = md5_base64($fileinfo->ino.$fileinfo->mtime); ! if ($r->headers_in->{"If-None-Match"} && $r->headers_in->{"If-None-Match"} eq $nonce) { return Apache2::Const::HTTP_NOT_MODIFIED(); } *************** *** 207,223 **** # Instead of reading the templates every single time # we need them, create a hash of template names and ! # the associated Text::Template objects. ! my %templates = create_templates({layout => "$tpl_dir/layout.tpl", ! index => "$tpl_dir/index.tpl", ! directory => "$tpl_dir/directory.tpl", ! picture => "$tpl_dir/picture.tpl", ! file => "$tpl_dir/file.tpl", ! comment => "$tpl_dir/dircomment.tpl", ! nocomment => "$tpl_dir/nodircomment.tpl", ! rss => "$tpl_dir/rss.tpl", ! rss_item => "$tpl_dir/rss_item.tpl", ! navdirectory => "$tpl_dir/navdirectory.tpl", }); --- 209,226 ---- # Instead of reading the templates every single time # we need them, create a hash of template names and ! # the associated template objects. ! my $templates = create_templates( $r, $scratch, ! {layout => "layout", ! index => "index", ! directory => "directory", ! picture => "picture", ! file => "file", ! comment => "dircomment", ! nocomment => "nodircomment", ! rss => "rss", ! rss_item => "rss_item", ! navdirectory => "navdirectory", }); *************** *** 361,367 **** $dirtitle =~ s/_/ /g if $r->dir_config('GalleryUnderscoresToSpaces'); $tpl_vars{FILES} .= ! $templates{directory}->fill_in(HASH=> {FILEURL => uri_escape($fileurl, $escape_rule), FILE => $dirtitle, } ); --- 364,370 ---- $dirtitle =~ s/_/ /g if $r->dir_config('GalleryUnderscoresToSpaces'); $tpl_vars{FILES} .= ! $templates->do( "directory", {FILEURL => uri_escape($fileurl, $escape_rule), FILE => $dirtitle, } ); *************** *** 386,392 **** } $tpl_vars{FILES} .= ! $templates{file}->fill_in(HASH => {%tpl_vars, FILEURL => uri_escape($fileurl, $escape_rule), ALT => "Size: $size Bytes", FILE => $file, --- 389,395 ---- } $tpl_vars{FILES} .= ! $templates->do( "file", {%tpl_vars, FILEURL => uri_escape($fileurl, $escape_rule), ALT => "Size: $size Bytes", FILE => $file, *************** *** 415,421 **** HEIGHT => (grep($rotate==$_, (1, 3)) ? $thumbnailwidth : $thumbnailheight), WIDTH => (grep($rotate==$_, (1, 3)) ? $thumbnailheight : $thumbnailwidth), SELECT => $select_mode?'  ':'',); ! $tpl_vars{FILES} .= $templates{picture}->fill_in(HASH => {%tpl_vars, %file_vars, }, ); --- 418,430 ---- HEIGHT => (grep($rotate==$_, (1, 3)) ? $thumbnailwidth : $thumbnailheight), WIDTH => (grep($rotate==$_, (1, 3)) ? $thumbnailheight : $thumbnailwidth), SELECT => $select_mode?'  ':'',); ! if ( $r->dir_config('GalleryIndexImageComments')) { ! my @tmp = split (/\//, $filename); ! my $picfilename = $file; ! my $path = (join "/", @tmp)."/"; ! read_image_comment( $r, $path, $picfilename, $imageinfo, \%tpl_vars ); ! } ! $tpl_vars{FILES} .= $templates->do( "picture", {%tpl_vars, %file_vars, }, ); *************** *** 428,434 **** TITLE => $file, CONTENT => uri_escape($uri."/.cache/".$content_image_width."x".$content_image_height."-".$file, $escape_rule) ); ! $tpl_vars{ITEMS} .= $templates{rss_item}->fill_in(HASH => { %item_vars }); } --- 437,443 ---- TITLE => $file, CONTENT => uri_escape($uri."/.cache/".$content_image_width."x".$content_image_height."-".$file, $escape_rule) ); ! $tpl_vars{ITEMS} .= $templates->do( "rss_item", { %item_vars }); } *************** *** 446,452 **** $r->document_root =~ m/(.*)\/$/; my $root_path = $1; - print STDERR "$filename vs $root_path\n"; if ($filename ne $root_path) { unless (opendir (PARENT_DIR, $parent_filename)) { show_error ($r, 500, $!, "Unable to access parent directory $parent_filename: $!"); --- 455,460 ---- *************** *** 472,478 **** foreach my $neighbour_directory (@neighbour_directories) { if ($parent_filename.'/'.$neighbour_directory eq $filename) { if ($neightbour_counter > 0) { - print STDERR "prev directory is " .$neighbour_directories[$neightbour_counter-1] ."\n"; my $linktext = $neighbour_directories[$neightbour_counter-1]; if (-e $parent_filename.'/'.$neighbour_directories[$neightbour_counter-1] . ".folder") { $linktext = get_filecontent($parent_filename.'/'.$neighbour_directories[$neightbour_counter-1] . ".folder"); --- 480,485 ---- *************** *** 482,489 **** LINK_NAME => "<<< $linktext", DIR_FILES => "", ); ! $tpl_vars{PREV_DIR_FILES} = $templates{navdirectory}->fill_in(HASH=> {%info}); ! print STDERR $tpl_vars{PREV_DIR_FILES} ."\n"; } if ($neightbour_counter < scalar @neighbour_directories - 1) { --- 489,495 ---- LINK_NAME => "<<< $linktext", DIR_FILES => "", ); ! $tpl_vars{PREV_DIR_FILES} = $templates->do( "navdirectory", {%info}); } if ($neightbour_counter < scalar @neighbour_directories - 1) { *************** *** 496,503 **** LINK_NAME => "$linktext >>>", DIR_FILES => "", ); ! $tpl_vars{NEXT_DIR_FILES} = $templates{navdirectory}->fill_in(HASH=> {%info}); ! print STDERR "next directory is " .$neighbour_directories[$neightbour_counter+1] ."\n"; } } $neightbour_counter++; --- 502,508 ---- LINK_NAME => "$linktext >>>", DIR_FILES => "", ); ! $tpl_vars{NEXT_DIR_FILES} = $templates->do( "navdirectory", {%info}); } } $neightbour_counter++; *************** *** 509,526 **** my %comment_vars; $comment_vars{COMMENT} = $comment_ref->{COMMENT} . '
' if $comment_ref->{COMMENT}; $comment_vars{TITLE} = $comment_ref->{TITLE} if $comment_ref->{TITLE}; ! $tpl_vars{DIRCOMMENT} = $templates{comment}->fill_in(HASH => \%comment_vars); $tpl_vars{TITLE} = $comment_ref->{TITLE} if $comment_ref->{TITLE}; } else { ! $tpl_vars{DIRCOMMENT} = $templates{nocomment}->fill_in(HASH=>\%tpl_vars); } if ($cgi->param('rss')) { ! $tpl_vars{MAIN} = $templates{rss}->fill_in(HASH => \%tpl_vars); $r->content_type('application/rss+xml'); } else { ! $tpl_vars{MAIN} = $templates{index}->fill_in(HASH => \%tpl_vars); ! $tpl_vars{MAIN} = $templates{layout}->fill_in(HASH => \%tpl_vars); $r->content_type('text/html'); } --- 514,531 ---- my %comment_vars; $comment_vars{COMMENT} = $comment_ref->{COMMENT} . '
' if $comment_ref->{COMMENT}; $comment_vars{TITLE} = $comment_ref->{TITLE} if $comment_ref->{TITLE}; ! $tpl_vars{DIRCOMMENT} = $templates->do( "comment", \%comment_vars); $tpl_vars{TITLE} = $comment_ref->{TITLE} if $comment_ref->{TITLE}; } else { ! $tpl_vars{DIRCOMMENT} = $templates->do( "nocomment", \%tpl_vars); } if ($cgi->param('rss')) { ! $tpl_vars{MAIN} = $templates->do( "rss", \%tpl_vars); $r->content_type('application/rss+xml'); } else { ! $tpl_vars{MAIN} = $templates->do( "index", \%tpl_vars); ! $tpl_vars{MAIN} = $templates->do( "layout", \%tpl_vars); $r->content_type('text/html'); } *************** *** 568,587 **** my $tpl_dir = $r->dir_config('GalleryTemplateDir'); ! my %templates = create_templates({layout => "$tpl_dir/layout.tpl", ! picture => "$tpl_dir/showpicture.tpl", ! navpicture => "$tpl_dir/navpicture.tpl", ! info => "$tpl_dir/info.tpl", ! scale => "$tpl_dir/scale.tpl", ! scaleactive => "$tpl_dir/scaleactive.tpl", ! orig => "$tpl_dir/orig.tpl", ! refresh => "$tpl_dir/refresh.tpl", ! interval => "$tpl_dir/interval.tpl", ! intervalactive => "$tpl_dir/intervalactive.tpl", ! slideshowisoff => "$tpl_dir/slideshowisoff.tpl", ! slideshowoff => "$tpl_dir/slideshowoff.tpl", ! pictureinfo => "$tpl_dir/pictureinfo.tpl", ! nopictureinfo => "$tpl_dir/nopictureinfo.tpl", }); my %tpl_vars; --- 573,593 ---- my $tpl_dir = $r->dir_config('GalleryTemplateDir'); ! my $templates = create_templates( $r, $scratch, ! {layout => "layout", ! picture => "showpicture", ! navpicture => "navpicture", ! info => "info", ! scale => "scale", ! scaleactive => "scaleactive", ! orig => "orig", ! refresh => "refresh", ! interval => "interval", ! intervalactive => "intervalactive", ! slideshowisoff => "slideshowisoff", ! slideshowoff => "slideshowoff", ! pictureinfo => "pictureinfo", ! nopictureinfo => "nopictureinfo", }); my %tpl_vars; *************** *** 638,644 **** $nav_vars{PICTURE} = uri_escape(".cache/$cached", $escape_rule); $nav_vars{DIRECTION} = "« prev"; $nav_vars{ACCESSKEY} = "P"; ! $tpl_vars{BACK} = $templates{navpicture}->fill_in(HASH => \%nav_vars); } else { $tpl_vars{BACK} = " "; --- 644,650 ---- $nav_vars{PICTURE} = uri_escape(".cache/$cached", $escape_rule); $nav_vars{DIRECTION} = "« prev"; $nav_vars{ACCESSKEY} = "P"; ! $tpl_vars{BACK} = $templates->do( "navpicture", \%nav_vars); } else { $tpl_vars{BACK} = " "; *************** *** 662,668 **** $nav_vars{DIRECTION} = "next »"; $nav_vars{ACCESSKEY} = "N"; ! $tpl_vars{NEXT} = $templates{navpicture}->fill_in(HASH => \%nav_vars); $tpl_vars{NEXTURL} = uri_escape($nextpicture, $escape_rule); } else { --- 668,674 ---- $nav_vars{DIRECTION} = "next »"; $nav_vars{ACCESSKEY} = "N"; ! $tpl_vars{NEXT} = $templates->do( "navpicture", \%nav_vars); $tpl_vars{NEXTURL} = uri_escape($nextpicture, $escape_rule); } else { *************** *** 673,688 **** } my $foundcomment = 0; ! if (-f $path . '/' . $picfilename . '.comment') { ! my $comment_ref = get_comment($path . '/' . $picfilename . '.comment'); $foundcomment = 1; - $tpl_vars{COMMENT} = $comment_ref->{COMMENT} . '
' if $comment_ref->{COMMENT}; - $tpl_vars{TITLE} = $comment_ref->{TITLE} if $comment_ref->{TITLE}; - } elsif ($r->dir_config('GalleryCommentExifKey')) { - my $comment = decode("utf8", $imageinfo->{$r->dir_config('GalleryCommentExifKey')}); - $tpl_vars{COMMENT} = encode("iso-8859-1", $comment); - } else { - $tpl_vars{COMMENT} = ''; } my @infos = split /, /, $r->dir_config('GalleryInfo') ? $r->dir_config('GalleryInfo') : 'Picture Taken => DateTimeOriginal, Flash => Flash'; --- 679,687 ---- } my $foundcomment = 0; ! read_image_comment( $r, $path, $picfilename, $imageinfo, \%tpl_vars ); ! if ( $tpl_vars{TITLE} or $tpl_vars{COMMENT}) { $foundcomment = 1; } my @infos = split /, /, $r->dir_config('GalleryInfo') ? $r->dir_config('GalleryInfo') : 'Picture Taken => DateTimeOriginal, Flash => Flash'; *************** *** 700,706 **** my %info_vars; $info_vars{KEY} = $human_key; $info_vars{VALUE} = $value; ! $tpl_vars{INFO} .= $templates{info}->fill_in(HASH => \%info_vars); } if ($exif_mode eq 'variables') { --- 699,705 ---- my %info_vars; $info_vars{KEY} = $human_key; $info_vars{VALUE} = $value; ! $tpl_vars{INFO} .= $templates->do( "info", \%info_vars); } if ($exif_mode eq 'variables') { *************** *** 734,740 **** if ($exif_mode eq 'namevalue' && $foundinfo or $foundcomment) { ! $tpl_vars{PICTUREINFO} = $templates{pictureinfo}->fill_in(HASH => \%tpl_vars); unless (defined($exifvalues)) { $tpl_vars{EXIFVALUES} = ""; --- 733,739 ---- if ($exif_mode eq 'namevalue' && $foundinfo or $foundcomment) { ! $tpl_vars{PICTUREINFO} = $templates->do( "pictureinfo", \%tpl_vars); unless (defined($exifvalues)) { $tpl_vars{EXIFVALUES} = ""; *************** *** 742,748 **** } else { ! $tpl_vars{PICTUREINFO} = $templates{nopictureinfo}->fill_in(HASH => \%tpl_vars); } # Fill in sizes and determine if any are smaller than the --- 741,747 ---- } else { ! $tpl_vars{PICTUREINFO} = $templates->do( "nopictureinfo", \%tpl_vars); } # Fill in sizes and determine if any are smaller than the *************** *** 756,765 **** $sizes_vars{SIZE} = $size; $sizes_vars{WIDTH} = $size; if ($width == $size) { ! $tpl_vars{SIZES} .= $templates{scaleactive}->fill_in(HASH => \%sizes_vars); } else { ! $tpl_vars{SIZES} .= $templates{scale}->fill_in(HASH => \%sizes_vars); } $scaleable = 1; } --- 755,764 ---- $sizes_vars{SIZE} = $size; $sizes_vars{WIDTH} = $size; if ($width == $size) { ! $tpl_vars{SIZES} .= $templates->do( "scaleactive", \%sizes_vars); } else { ! $tpl_vars{SIZES} .= $templates->do( "scale", \%sizes_vars); } $scaleable = 1; } *************** *** 770,782 **** $sizes_vars{IMAGEURI} = uri_escape($r->uri(), $escape_rule); $sizes_vars{SIZE} = $original_size; $sizes_vars{WIDTH} = $original_size; ! $tpl_vars{SIZES} .= $templates{scaleactive}->fill_in(HASH => \%sizes_vars); } $tpl_vars{IMAGEURI} = uri_escape($r->uri(), $escape_rule); if ($r->dir_config('GalleryAllowOriginal')) { ! $tpl_vars{SIZES} .= $templates{orig}->fill_in(HASH => \%tpl_vars); } my @slideshow_intervals = split (/ /, $r->dir_config('GallerySlideshowIntervals') ? $r->dir_config('GallerySlideshowIntervals') : '3 5 10 15 30'); --- 769,781 ---- $sizes_vars{IMAGEURI} = uri_escape($r->uri(), $escape_rule); $sizes_vars{SIZE} = $original_size; $sizes_vars{WIDTH} = $original_size; ! $tpl_vars{SIZES} .= $templates->do( "scaleactive", \%sizes_vars); } $tpl_vars{IMAGEURI} = uri_escape($r->uri(), $escape_rule); if ($r->dir_config('GalleryAllowOriginal')) { ! $tpl_vars{SIZES} .= $templates->do( "orig", \%tpl_vars); } my @slideshow_intervals = split (/ /, $r->dir_config('GallerySlideshowIntervals') ? $r->dir_config('GallerySlideshowIntervals') : '3 5 10 15 30'); *************** *** 788,805 **** $slideshow_vars{WIDTH} = ($width > $height ? $width : $height); if ($cgi->param('slideshow') && $cgi->param('slideshow') == $interval and $nextpicture) { ! $tpl_vars{SLIDESHOW} .= $templates{intervalactive}->fill_in(HASH => \%slideshow_vars); } else { ! $tpl_vars{SLIDESHOW} .= $templates{interval}->fill_in(HASH => \%slideshow_vars); } } if ($cgi->param('slideshow') and $nextpicture) { ! $tpl_vars{SLIDESHOW} .= $templates{slideshowoff}->fill_in(HASH => \%tpl_vars); unless ((grep $cgi->param('slideshow') == $_, @slideshow_intervals)) { show_error($r, 200, "Invalid interval", "Invalid slideshow interval choosen"); --- 787,804 ---- $slideshow_vars{WIDTH} = ($width > $height ? $width : $height); if ($cgi->param('slideshow') && $cgi->param('slideshow') == $interval and $nextpicture) { ! $tpl_vars{SLIDESHOW} .= $templates->do( "intervalactive", \%slideshow_vars); } else { ! $tpl_vars{SLIDESHOW} .= $templates->do( "interval", \%slideshow_vars); } } if ($cgi->param('slideshow') and $nextpicture) { ! $tpl_vars{SLIDESHOW} .= $templates->do( "slideshowoff", \%tpl_vars); unless ((grep $cgi->param('slideshow') == $_, @slideshow_intervals)) { show_error($r, 200, "Invalid interval", "Invalid slideshow interval choosen"); *************** *** 809,823 **** $tpl_vars{URL} = uri_escape($nextpicture, $escape_rule); $tpl_vars{WIDTH} = ($width > $height ? $width : $height); $tpl_vars{INTERVAL} = $cgi->param('slideshow'); ! $tpl_vars{META} .= $templates{refresh}->fill_in(HASH => \%tpl_vars); } else { ! $tpl_vars{SLIDESHOW} .= $templates{slideshowisoff}->fill_in(HASH => \%tpl_vars); } ! $tpl_vars{MAIN} = $templates{picture}->fill_in(HASH => \%tpl_vars); ! $tpl_vars{MAIN} = $templates{layout}->fill_in(HASH => \%tpl_vars); $r->content_type('text/html'); $r->headers_out->{'Content-Length'} = length($tpl_vars{MAIN}); --- 808,822 ---- $tpl_vars{URL} = uri_escape($nextpicture, $escape_rule); $tpl_vars{WIDTH} = ($width > $height ? $width : $height); $tpl_vars{INTERVAL} = $cgi->param('slideshow'); ! $tpl_vars{META} .= $templates->do( "refresh", \%tpl_vars); } else { ! $tpl_vars{SLIDESHOW} .= $templates->do( "slideshowisoff", \%tpl_vars); } ! $tpl_vars{MAIN} = $templates->do( "picture", \%tpl_vars); ! $tpl_vars{MAIN} = $templates->do( "layout", \%tpl_vars); $r->content_type('text/html'); $r->headers_out->{'Content-Length'} = length($tpl_vars{MAIN}); *************** *** 1318,1330 **** my $rotate = 0; - print STDERR "orientation: ".$imageinfo->{Orientation}."\n"; # Check to see if the image contains the Orientation EXIF key, # but allow user to override using rotate if (!defined($r->dir_config("GalleryAutoRotate")) || $r->dir_config("GalleryAutoRotate") eq "1") { if (defined($imageinfo->{Orientation})) { - print STDERR $imageinfo->{Orientation}."\n"; if ($imageinfo->{Orientation} eq 'right_top') { $rotate=1; } --- 1317,1327 ---- *************** *** 1378,1384 **** } while () { - chomp; $comment_ref->{COMMENT} .= $_; } close(FH); --- 1375,1380 ---- *************** *** 1392,1399 **** my $tpl = $r->dir_config('GalleryTemplateDir'); ! my %templates = create_templates({layout => "$tpl/layout.tpl", ! error => "$tpl/error.tpl", }); my %tpl_vars; --- 1388,1396 ---- my $tpl = $r->dir_config('GalleryTemplateDir'); ! my $templates = create_templates( $r, {}, ! {layout => "layout", ! error => "error", }); my %tpl_vars; *************** *** 1402,1410 **** $tpl_vars{ERRORTITLE} = "Error! $errortitle"; $tpl_vars{ERROR} = $error; ! $tpl_vars{MAIN} = $templates{error}->fill_in(HASH => \%tpl_vars); ! $tpl_vars{PAGE} = $templates{layout}->fill_in(HASH => \%tpl_vars); $r->status($statuscode); $r->content_type('text/html'); --- 1399,1407 ---- $tpl_vars{ERRORTITLE} = "Error! $errortitle"; $tpl_vars{ERROR} = $error; ! $tpl_vars{MAIN} = $templates->do( "error", \%tpl_vars); ! $tpl_vars{PAGE} = $templates->do( "layout", \%tpl_vars); $r->status($statuscode); $r->content_type('text/html'); *************** *** 1579,1616 **** return @files; } ! # Create Text::Template objects used by Apache::Gallery. Takes a # hashref of template_name, template_filename pairs, and returns a # list of template_name, texttemplate_object pairs. sub create_templates { my $templates = shift; # This routine is called whenever a template has an error. Prints # the error to STDERR and sticks the error in the output ! sub tt_broken { my %args = @_; # Pull out the name and filename from the arg option [see ! # Text::Template for details] ! @args{qw(name file)} = @{$args{arg}}; print STDERR qq(Template $args{name} ("$args{file}") is broken: $args{error}); # Don't include the file name in the output, as the user can see this. return qq(); } ! ! my %texttemplate_objects; ! ! for my $template_name (keys %$templates) { ! my $tt_obj = Text::Template->new(TYPE => 'FILE', ! SOURCE => $$templates{$template_name}, ! BROKEN => \&tt_broken, ! BROKEN_ARG => [$template_name, $$templates{$template_name}], ! ) ! or die "Unable to create new Text::Template object for $template_name: $Text::Template::ERROR"; ! $texttemplate_objects{$template_name} = $tt_obj; ! } ! return %texttemplate_objects; } sub log_error { --- 1576,1619 ---- return @files; } ! # Create template objects used by Apache::Gallery. Takes a # hashref of template_name, template_filename pairs, and returns a # list of template_name, texttemplate_object pairs. sub create_templates { + my $r = shift; + my $scratch = shift; my $templates = shift; # This routine is called whenever a template has an error. Prints # the error to STDERR and sticks the error in the output ! sub tmpl_broken { my %args = @_; # Pull out the name and filename from the arg option [see ! # Text::Template or Template Toolkit for details] ! if ( exists $args{arg}) { ! @args{qw(name file)} = @{$args{arg}}; ! } print STDERR qq(Template $args{name} ("$args{file}") is broken: $args{error}); # Don't include the file name in the output, as the user can see this. return qq(); } + # look up template directory from Apache config + my $tpl_dir = $r->dir_config('GalleryTemplateDir'); ! # look up templating class from Apache config ! # default to Text::Template... Apache::Gallery originally written for it ! my $tpl_class = $r->dir_config('GalleryTemplateClass'); ! if ( !defined $tpl_class ) { ! $tpl_class = "Text::Template"; ! } ! ! # instantiate and return Apache::Gallery::Template object ! return Apache::Gallery::Template->new ( dir => $tpl_dir, ! tclass => $tpl_class, ! templates => $templates, ! broken => \&tmpl_broken, ! scratch => $scratch ); } sub log_error { *************** *** 1621,1626 **** --- 1624,1645 ---- } } + # read per-image .comment file if present + sub read_image_comment + { + my ( $r, $path, $picfilename, $imageinfo, $tpl_vars_ref ) = @_; + if (-f $path . '/' . $picfilename . '.comment') { + my $comment_ref = get_comment($path . '/' . $picfilename . '.comment'); + $tpl_vars_ref->{COMMENT} = $comment_ref->{COMMENT} . '
' if $comment_ref->{COMMENT}; + $tpl_vars_ref->{TITLE} = $comment_ref->{TITLE} if $comment_ref->{TITLE}; + } elsif ($r->dir_config('GalleryCommentExifKey')) { + my $comment = decode("utf8", $imageinfo->{$r->dir_config('GalleryCommentExifKey')}); + $tpl_vars_ref->{COMMENT} = encode("iso-8859-1", $comment); + } else { + $tpl_vars_ref->{COMMENT} = ''; + } + } + 1; =head1 NAME *************** *** 1678,1683 **** --- 1697,1720 ---- No default value, this option is required. + =item B + + This defines the Perl templating class which Apache::Gallery uses for + processing its templates. Since Apache::Gallery started with Text::Template, + that is the default value. In order to use Template Toolkit 2, set this + value to its class name "Template". + + Different directories on the same Apache server may have Text::Template + or Template Toolkit without conflict. However, it is critically important + to select the correct templating system for the files in a given + GalleryTemplateDir directory. Text::Template files use a .tpl suffix. + Template Toolkit files use a .tt2 suffix. No changes are necessary in + a gallery image directory to use either templating system. + + Text::Template example: B + + TT2 example: B + =item B With this option you can define which EXIF information you would like *************** *** 1899,1905 **** Set this option to 1 to convert underscores to spaces in the listing of directory names. ! =back =item B --- 1936,1948 ---- Set this option to 1 to convert underscores to spaces in the listing of directory names. ! =item B ! ! Set this option if you want per-image $COMMENT variables to work in the ! picture.tpl template, which is used on thumbnail index pages. ! This is disabled by default because it takes more time to read the ! comment files for each image, ! and should only be done if you actually want it. =item B *************** *** 1911,1916 **** --- 1954,1961 ---- Set this option to 1 to enable generation of a media RSS feed. This can be used e.g. together with the PicLens plugin from http://piclens.com + =back + =head1 FEATURES =over 4 *************** *** 1980,1985 **** --- 2025,2034 ---- =item B =item B + Required if using Text::Template for template processing. + + =item B