# ========================= 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: TWiki::Func::writeDebug( "TableFolderListing pre-binding is $TableFolderListing"); # &TableFolderListing; $_[0] =~ s/%TableFolderListing%/&_TableFolderListing()/; TWiki::Func::writeDebug( "TableFolderListing post-binding is $TableFolderListing"); # $_[0] =~ s/%XYZ{(.*?)}%/&handleXyz($1)/ge; } # ========================= sub _TableFolderListing { # Open the directory containing the approved pdf's and read the names into a array opendir (Approveddir, '/c/ApprovedPdfs/') || die 'Unable to open Approvedpdfs'." $!\n"; @approvedpdfs = readdir (Approveddir); die "unable to read the contents of F:\\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 $TableFolderListing = $TableFolderListing."\n"; TWiki::Func::writeDebug( "TableFolderListing within the sub is $TableFolderListing"); return $TableFolderListing; } # ========================== 1;