# # TWiki WikiClone ($wikiversion has version info) # # Copyright (C) 2000-2001 Andrea Sterbini, a.sterbini@flashnet.it # Copyright (C) 2001 Peter Thoeny, Peter@Thoeny.com # # 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, published at # http://www.gnu.org/copyleft/gpl.html # # ========================= # # README: # # AllPixPlugin.pm (GPL) 2002 Henry Strickland strick@yak.SnPeAtM # # This plugin changes %ALLPIX% to a table of thumbnails # of all attached images of the current topic that have thumbnails. # # (Use Toby Cabot's thumbnailing patch -- # see http://TWiki.org/cgi-bin/view/Codev/TWikiPhotoAlbum ) # # ========================= # # Each plugin is a package that contains the subs: # # initPlugin ( $topic, $web, $user, $installWeb ) # commonTagsHandler ( $text, $topic, $web ) # startRenderingHandler( $text, $web ) # outsidePREHandler ( $text ) # insidePREHandler ( $text ) # endRenderingHandler ( $text ) # # initPlugin is required, all other are optional. # For increased performance, all handlers except initPlugin are # disabled. To enable a handler remove the leading DISABLE_ from # the function name. # # NOTE: To interact with TWiki use the official TWiki functions # in the &TWiki::Func module. Do not reference any functions or # variables elsewhere in TWiki!! # ========================= package TWiki::Plugins::AllPixPlugin; # change the package name!!! # ========================= use vars qw( $web $topic $user $installWeb $VERSION $debug $exampleCfgVar ); $VERSION = '1.000'; # ========================= sub initPlugin { ( $topic, $web, $user, $installWeb ) = @_; # check for Plugins.pm versions if( $TWiki::Plugins::VERSION < 1 ) { &TWiki::Func::writeWarning( "Version mismatch between AllPixPlugin and Plugins.pm" ); return 0; } # Get plugin preferences, the variable defined by: * Set EXAMPLE = ... #$exampleCfgVar = &TWiki::Prefs::getPreferencesValue( "ALLPIXPLUGIN_EXAMPLE" ) || "default"; # Get plugin debug flag $debug = &TWiki::Func::getPreferencesFlag( "ALLPIXPLUGIN_DEBUG" ); # Plugin correctly initialized &TWiki::Func::writeDebug( "- TWiki::Plugins::AllPixPlugin::initPlugin( $web.$topic ) is OK" ) if $debug; return 1; } # ========================= sub handleAllPix { # we take no parameters yet # This code read the pub directory, rather than the Meta: #--#my $ok = opendir APD, "$TWiki::pubDir/$web/$topic"; #--#return "(CantOpendir $TWiki::pubDir/$web/$topic)" if ! $ok; #--#my @jpgs = readdir APD; #--#closedir APD; # get all attachments from meta data my ( $meta, $text ) = TWiki::Store::readTopic( $web, $topic ); my @att = $meta->find( "FILEATTACHMENT" ); # pick out the JPGs with thumbnails # also get their comments. # @jpgs will alternate: filename comment filename comment... my @jpgs = (); my $z = ""; foreach my $i (@att) { my $s= $$i{"name"}; next unless $s =~ /^[A-Za-z0-9].*[.][Jj][Pp][Ee]?[Gg]/; next unless -s "$TWiki::pubDir/$web/$topic/$s.thumb.jpeg"; push @jpgs, $s; push @jpgs, $$i{"comment"}; } return "(No Images)" if (! @jpgs); my $z = "\n\n"; while ( @jpgs ) { $z.= "\n"; for ( $i=0; $i<2; ++$i ) { if ( @jpgs ) { my $j = shift @jpgs; my $comment = shift @jpgs; $z.= "\n"; } else { $z.= "\n"; } } $z.= "\n\n" } return $z . "
"; $z.= "   $comment  
 
\n\n"; } sub commonTagsHandler { ### my ( $text, $topic, $web ) = @_; # do not uncomment, use $_[0], $_[1]... instead &TWiki::Func::writeDebug( "- AllPixPlugin::commonTagsHandler( $_[2].$_[1] )" ) if $debug; # This is the place to define customized tags and variables # Called by sub handleCommonTags, after %INCLUDE:"..."% # do custom extension rule, like for example: # $_[0] =~ s/%XYZ%/&handleXyz()/geo; # $_[0] =~ s/%XYZ{(.*?)}%/&handleXyz($1)/geo; $_[0] =~ s/%ALLPIX%/&handleAllPix()/geo; $_[0] =~ s/%ALLPIX{(.*?)}%/&handleAllPix($1)/geo; # no params yet } # ========================= sub DISABLE_startRenderingHandler { ### my ( $text, $web ) = @_; # do not uncomment, use $_[0], $_[1] instead &TWiki::Func::writeDebug( "- AllPixPlugin::startRenderingHandler( $_[1].$topic )" ) if $debug; # This handler is called by getRenderedVersion just before the line loop # do custom extension rule, like for example: # $_[0] =~ s/old/new/go; } # ========================= sub DISABLE_outsidePREHandler { ### my ( $text ) = @_; # do not uncomment, use $_[0] instead # &TWiki::Func::writeDebug( "- AllPixPlugin::outsidePREHandler( $web.$topic )" ) if $debug; # This handler is called by getRenderedVersion, in loop outside of
 tag.
    # This is the place to define customized rendering rules.
    # Note: This is an expensive function to comment out.
    # Consider startRenderingHandler instead
}

# =========================
sub DISABLE_insidePREHandler
{
### my ( $text ) = @_;   # do not uncomment, use $_[0] instead

#   &TWiki::Func::writeDebug( "- AllPixPlugin::insidePREHandler( $web.$topic )" ) if $debug;

    # This handler is called by getRenderedVersion, in loop inside of 
 tag.
    # This is the place to define customized rendering rules.
    # Note: This is an expensive function to comment out.
    # Consider startRenderingHandler instead
}

# =========================
sub DISABLE_endRenderingHandler
{
### my ( $text ) = @_;   # do not uncomment, use $_[0] instead

    &TWiki::Func::writeDebug( "- AllPixPlugin::endRenderingHandler( $web.$topic )" ) if $debug;

    # This handler is called by getRenderedVersion just after the line loop

}

# =========================

1;