# Blosxom Plugin: static_gallery -*-cperl-*- # Author: Jason Blevins # Version: 2008-02-20 # License: GPL (see below) # Documentation: Type "perldoc static_gallery", or scroll down. # Blosxom Home/Docs/Licensing: http://blosxom.sourceforge.net # # This plugin is based on the pictureindex plugin by Bill Ward from which # much of the code here was taken or derived from. package static_gallery; use warnings; use strict; use vars qw/ @flavours $use_head $use_foot $image_pages $desc $image_url $index_url $link_url $name $alt_text $next_url $prev_url $short_desc $thumb_url $width $height $large_url /; # ----- Mandatory configuration ----- # For which flavours should we generate individual image pages? @flavours = qw/ html / unless defined @flavours; # ----- Optional configuration ----- # Should we store individual image pages in the static output directory? $image_pages = 1 unless defined $image_pages; # Should we apply the flavour's head and foot templates to image pages? $use_head = 0 unless defined $use_head; $use_foot = 0 unless defined $use_foot; # ----- End configuration ----- my $package = 'static_gallery'; my (@images, @thumbs, %title, %caption); sub start { # Only run in static mode return 0 unless $blosxom::static_or_dynamic eq 'static'; # Load the default templates while () { last if /^(__END__)$/; my ($flavour, $comp, $txt) = /^(\S+)\s(\S+)(?:\s(.*))?$/ or next; $txt =~ s/\\n/\n/mg; $blosxom::template{$flavour}{$package.$comp} .= $txt . "\n"; } return 1; } # Designed to be called as an interpolate_function action. # sub get { my ($self, $attr, $content) = @_; # Load templates my $preview_tmpl = _load_template("$package.preview"); my $thumb_tmpl = _load_template("$package.thumb"); my $image_tmpl = _load_template("$package.image"); my $head_tmpl = _load_template('head'); my $foot_tmpl = _load_template('foot'); my $base_url = $blosxom::url . $blosxom::path . '/'; # Parse the list of images @images = (); foreach my $line (split "\n", $content) { if ($line =~ m/^(\S+):\s*{(.+?)}\s*(.*)$/) { push @images, $1; $title{$1} = $2; $caption{$1} = $3; } } if ($pagetype::pagetype ne 'story') { # This is not a story page, generate and return the preview only. my $img = $attr->{preview} || $images[0]; ($name, $desc, $short_desc, $alt_text) = _get_info($img); $link_url = _get_link_url($blosxom::path); $thumb_url = $base_url . $attr->{thumb}; $thumb_url =~ s/\$1/$img/g; return interpolate($preview_tmpl); } else { @thumbs = (); for (my $i = 0; $i < @images; $i++) { # Build thumbnail information my $img = $images[$i]; ($name, $desc, $short_desc, $alt_text) = _get_info($img); $link_url = _get_link_url($blosxom::path, $img); $thumb_url = $base_url . $attr->{thumb}; $thumb_url =~ s/\$1/$img/g; $image_url = $base_url . $attr->{image}; $image_url =~ s/\$1/$img/g; if ($attr->{large}) { $large_url = $base_url . $attr->{large}; $large_url =~ s/\$1/$img/g; } else { undef $large_url; } # NEEDS_WORK: Assumes images reside under $blosxom::datadir. my $image_file = "$blosxom::datadir/$blosxom::path/$image_url"; ($height, $width) = imgsize($image_file) if -f $image_file; $index_url = _get_index_url($blosxom::path); # Generate next and previous links if ($i > 0) { $prev_url = _get_link_url($blosxom::path, $images[$i-1]); } else { undef $prev_url; } if ($i+1 < @images) { $next_url = _get_link_url($blosxom::path, $images[$i+1]); } else { undef $next_url; } # Apply thumbnail template push @thumbs, interpolate($thumb_tmpl); # Generate and store individual image pages if ($image_pages) { my $image_fn = join('/', $blosxom::static_dir, $blosxom::path, "$img.$blosxom::flavour"); # Assume directory exists since we are processing this page open IMAGE, "> $image_fn"; print IMAGE &$blosxom::interpolate($head_tmpl) if $use_head; print IMAGE interpolate($image_tmpl); print IMAGE &$blosxom::interpolate($foot_tmpl) if $use_foot; close IMAGE; } } return join("", '
    ', @thumbs, '
'); } } # Returns the name, description, short description, and alternate text for a # given image. # sub _get_info { my ($img) = @_; $name = $title{$img}; $short_desc = $desc = $caption{$img}; $short_desc =~ s/\..*$/./; $alt_text = $short_desc || $desc; $alt_text =~ s/".*/.../s; return ($name, $desc, $short_desc, $alt_text); } sub _get_index_url { my($path) = @_; if ($blosxom::plugins{'index_override'} and ($blosxom::fn eq $index_override::indexfile)) { return "$blosxom::url$path/"; } else { return "$blosxom::url$path/$blosxom::fn"; } } sub _get_link_url { my($path, $name) = @_; my $url = _get_index_url($path); return $name ? "$blosxom::url$path/" . CGI::escape($name) . ".$blosxom::flavour" : $url; } sub _load_template { my ($bit) = @_; return &$blosxom::template($blosxom::path, $bit, $blosxom::flavour); } sub interpolate { my ($template) = @_; my $result = &$blosxom::interpolate($template); return $result; } 1; __DATA__ error thumb
error thumb $static_gallery::alt_text error thumb

$static_gallery::short_desc [more] $static_gallery::desc

error thumb
error preview
$static_gallery::alt_text
[more]
error image

Click the image to go to the next in the series.

Previous Return to Thumbnails Next
$static_gallery::alt_textwidth="$static_gallery::width" height="$static_gallery::height" />
$static_gallery::desc
PreviousReturn to Thumbnails Next
__END__ =head1 NAME Blosxom Plug-in: static_gallery =head1 SYNOPSIS =head1 VERSION 2008-02-20 =head1 AUTHORS Jason Blevins William R. Ward =head1 INSTALLATION AND CONFIGURATION The C subroutine should be called via C as follows: <@static_gallery.get output="yes" thumb="/path/to/$1-thumbnail.jpg" image="/path/to/$1-normal.jpg" large="/path/to/$1-large.jpg" preview="002"> 001: { } A foggy Christmas in Chicago. 002: { } A foggy Christmas in Chicago. =head1 SEE ALSO Blosxom Home/Docs/Licensing: http://blosxom.sourceforge.net Blosxom Plugin Docs: http://blosxom.sourceforge.net/documentation/developers/plugins.html =head1 BUGS Send bug reports and comments to Jason Blevins . =head1 VERSION HISTORY 2008-02-20: Initial revision. =head1 LICENSE Copyright (c) 2008 Jason Blevins Copyright (c) 2004 William R. Ward This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA