Index: lib/TWiki/Plugins/TablePlugin.pm =================================================================== RCS file: /cvsroot/magware/sources/twikiplugins/TablePlugin/lib/TWiki/Plugins/TablePlugin.pm,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -w -c -r1.1.1.1 -r1.2 *** lib/TWiki/Plugins/TablePlugin.pm 18 Oct 2005 01:47:20 -0000 1.1.1.1 --- lib/TWiki/Plugins/TablePlugin.pm 19 Oct 2005 00:02:44 -0000 1.2 *************** *** 39,47 **** @fields $upchar $downchar $diamondchar $url $curTablePre @isoMonth %mon2num $initSort $initDirection $pluginAttrs $prefsAttrs @rowspan ); ! $VERSION = '1.013'; # 01 Aug 2004 $translationToken = "\0"; $currTablePre = ""; $upchar = ""; --- 39,48 ---- @fields $upchar $downchar $diamondchar $url $curTablePre @isoMonth %mon2num $initSort $initDirection $pluginAttrs $prefsAttrs @rowspan + $exportCsvFlag $exportCsvData ); ! $VERSION = '1.013'; # 19 Oct 2005 -- extensions for exporting CSV by MILS $translationToken = "\0"; $currTablePre = ""; $upchar = ""; *************** *** 173,178 **** --- 174,183 ---- @dataColor = ( ); undef $initSort; + # EXPORTCSV + $exportCsvFlag = 0; + $exportCsvData = ""; + handleTableAttrs( $pluginAttrs ); # Plugin setting handleTableAttrs( $prefsAttrs ); # Preferences setting } *************** *** 248,253 **** --- 253,262 ---- $tmp = TWiki::Func::extractNameValuePair( $args, "datacolor" ); @dataColor = split( /,\s*/, $tmp ) if( $tmp ); + # EXPORTCSV + $tmp = TWiki::Func::extractNameValuePair( $args, "exportcsv" ); + $exportCsvFlag = 1 if ($tmp == 1 or $tmp eq "on"); + return "$currTablePre"; } *************** *** 528,533 **** --- 537,553 ---- next if( $fcell->[2] eq "X" ); # data was there so sort could work with col spanning $type = $fcell->[2]; my $cell = $fcell->[0]; + + # EXPORTCSV + if ($exportCsvFlag) { + (my $c = $cell) =~ s/\"/\"\"/og; # escape quotes + $c =~ s/ / /og; + $c =~ s/\[\[[^\]]+\]\[([^\]]+)\]\]/$1/go; # extract label from [[...][...]] link + $c =~ s/<[^>]+>//go; # strip HTML + $c =~ s/^ *//go; # strip leading space space + $exportCsvData .= qq("$c",); + } + my $attr = $fcell->[1]; if( $type eq "th" ) { # reset data color count to start with first color after each table heading *************** *** 607,615 **** --- 627,648 ---- $text .= "\n"; $rowCount++; $dataColorCount++; + + # EXPORTCSV + $exportCsvData .= "\n" if ($exportCsvFlag); } $text .= "$currTablePre\n"; + + # EXPORTCSV + if ($exportCsvFlag) { + my $fname = "_table${tableCount}.csv"; + saveCsvFile($fname,$exportCsvData); + my $link = TWiki::Func::getUrlHost.TWiki::Func::getPubUrlPath()."/$web/$topic/$fname"; + $text = "[[$link][Download as CSV]]".$text; + } + setDefaults(); + return $text; } *************** *** 625,628 **** --- 658,682 ---- } # ========================= + sub saveCsvFile + { + my ($csvFilename, $csvText) = @_; + + # Create web directory "pub/$web" if needed + my $dir = TWiki::Func::getPubDir() . "/$web"; + unless( -e "$dir" ) { + umask( 002 ); + mkdir( $dir, 0775 ); + } + # Create topic directory "pub/$web/$topic" if needed + $dir .= "/$topic"; + unless( -e "$dir" ) { + umask( 002 ); + mkdir( $dir, 0775 ); + } + + &TWiki::Func::saveFile("$dir/$csvFilename", $csvText); + } + + # ========================= 1;