# Plugin for TWiki Collaboration Platform, http://TWiki.org/ # # Copyright (C) 2000-2003 Andrea Sterbini, a.sterbini@flashnet.it # Copyright (C) 2000-2004 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 # # ========================= # # This is the default TWiki plugin. Use EmptyPlugin.pm as a template # for your own plugins; see TWiki.TWikiPlugins for details. # # Each plugin is a package that may contain these functions: VERSION: # # earlyInitPlugin ( ) 1.020 # initPlugin ( $topic, $web, $user, $installWeb ) 1.000 # initializeUserHandler ( $loginName, $url, $pathInfo ) 1.010 # registrationHandler ( $web, $wikiName, $loginName ) 1.010 # beforeCommonTagsHandler ( $text, $topic, $web ) 1.024 # commonTagsHandler ( $text, $topic, $web ) 1.000 # afterCommonTagsHandler ( $text, $topic, $web ) 1.024 # startRenderingHandler ( $text, $web ) 1.000 # outsidePREHandler ( $text ) 1.000 # insidePREHandler ( $text ) 1.000 # endRenderingHandler ( $text ) 1.000 # beforeEditHandler ( $text, $topic, $web ) 1.010 # afterEditHandler ( $text, $topic, $web ) 1.010 # beforeSaveHandler ( $text, $topic, $web ) 1.010 # afterSaveHandler ( $text, $topic, $web, $errors ) 1.020 # renderFormFieldForEditHandler( $name, $type, $size, $value, $attributes, $possibleValues) # writeHeaderHandler ( $query ) 1.010 Use only in one Plugin # redirectCgiQueryHandler ( $query, $url ) 1.010 Use only in one Plugin # getSessionValueHandler ( $key ) 1.010 Use only in one Plugin # setSessionValueHandler ( $key, $value ) 1.010 Use only in one Plugin # # initPlugin is required, all other are optional. # For increased performance, unused handlers are disabled. To # enable a handler remove the leading DISABLE_ from the function # name. Remove disabled handlers you do not need. # # 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::FolderDisplayPlugin; # change the package name and $pluginName!!! # ========================= use vars qw( @approvedpdfs $name $approvedpdfs $target_dir @file_attribs $file_attribs $delimiter $TableFolderListing ); use vars qw( $web $topic $user $installWeb $VERSION $pluginName $debug $exampleCfgVar ); $VERSION = '1.021'; $pluginName = 'FolderDisplayPlugin'; # Name of this Plugin # ========================= sub initPlugin { ( $topic, $web, $user, $installWeb ) = @_; # check for Plugins.pm versions if( $TWiki::Plugins::VERSION < 1.021 ) { TWiki::Func::writeWarning( "Version mismatch between $pluginName and Plugins.pm" ); return 0; } # Get plugin debug flag $debug = TWiki::Func::getPluginPreferencesFlag( "DEBUG" ); # Get plugin preferences, the variable defined by: * Set EXAMPLE = ... #$exampleCfgVar = TWiki::Func::getPluginPreferencesValue( "EXAMPLE" ) || "default"; # Plugin correctly initialized TWiki::Func::writeDebug( "- TWiki::Plugins::${pluginName}::initPlugin( $web.$topic ) is OK" ) if $debug; return 1; } # ========================= sub commonTagsHandler { ### my ( $text, $topic, $web ) = @_; # do not uncomment, use $_[0], $_[1]... instead TWiki::Func::writeDebug( "- ${pluginName}::commonTagsHandler( $_[2].$_[1] )" ) if $debug; # This is the place to define customized tags and variables # Called by TWiki::handleCommonTags, after %INCLUDE:"..."% # do custom extension rule, like for example: $_[0] =~ s/%TableFolderListing%/$TableFolderListing/g; # $_[0] =~ s/%XYZ{(.*?)}%/&handleXyz($1)/ge; } # ========================= sub TableFolderListing # Open the directory containing the approved pdf's and read the names into a array # Note that @approvedpdfs = readdir (Approveddir) || die *doesn't* work because || imposes # a scalar result being read into @approvedpdfs opendir (Approveddir, '/c/ApprovedPdfs/') || die 'unable to open ApprovedPdfs Directory:'." $!\n"; @approvedpdfs = readdir (Approveddir); die "unable to read the contents of C:\\IM\ Documentation: $!\n" unless @approvedpdfs; closedir (Approveddir); my $TableFolderListing = ""; # split the array into the three component parts and strip off the file extension foreach $approvedpdfs (@approvedpdfs) { if (-d $approvedpdfs) {next;} $approvedpdfs =~ s/\.pdf$//; my @file_attribs = split (/\ -\ /, $approvedpdfs); # now rejoin the component parts with bar (|) as a seperator foreach $file_attribs (@file_attribs) { $TableFolderListing = $TableFolderListing . '|' . $file_attribs; }; $TableFolderListing = $TableFolderListing.'|'."\n"; }; # $_[0] =~ s/%TableFolderListing%/$TableFolderListing/g # test print $TableFolderListing # print $TableFolderListing."\n";