From: <de...@de...> - 2007-02-01 15:55:31
|
Author: CrawfordCurrie Date: 2007-02-01 09:49:26 -0600 (Thu, 01 Feb 2007) New Revision: 12708 Added: twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/Config.spec Removed: twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/PDFWriter.pm Modified: twiki/branches/MAIN/twikiplugins/PublishContrib/data/TWiki/PublishContrib.txt twiki/branches/MAIN/twikiplugins/PublishContrib/data/TWiki/PublishWeb.txt twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/Publish.pm twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/DEPENDENCIES twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/MANIFEST twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/file.pm twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/ftp.pm twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/pdf.pm twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/tgz.pm twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/zip.pm Log: Item2725: Item3515: fixed. Added UI for FTP. Added .spec file. Added (some) doc for FTP. Modified: twiki/branches/MAIN/twikiplugins/PublishContrib/data/TWiki/PublishContrib.txt =================================================================== --- twiki/branches/MAIN/twikiplugins/PublishContrib/data/TWiki/PublishContrib.txt 2007-02-01 12:58:33 UTC (rev 12707) +++ twiki/branches/MAIN/twikiplugins/PublishContrib/data/TWiki/PublishContrib.txt 2007-02-01 15:49:26 UTC (rev 12708) @@ -1,6 +1,6 @@ -%META:TOPICINFO{author="TWikiContributor" date="1164720531" format="1.1" reprev="1.2" version="1.2"}% +%META:TOPICINFO{author="TWikiAdminGroup" date="1170262421" format="1.1" version="1.2"}% ---+!! <nop>%TOPIC% -*Generates a static view of a web, as HTML files on disc, or as a =PDF=, or as a =zip= or =tgz= archive file.* +*Generates a static view of a web, as HTML files on disc, or as a =PDF=, or as a =zip= or =tgz= archive file, or by uploading directly to an FTP server.* <!-- @@ -33,14 +33,11 @@ * Powerful support for choosing what content gets published * Any links to the 'pub' areas of topics in the web are automatically resolved and the referenced files copied * Any links to images outside the TWiki are resolved, and the image is stored in the output (requires LWP) - * Output in HTML or PDF. HTML can be compressed + * Output in HTML or PDF. HTML can be compressed in different archive formats. * Full support for hierarchical webs * Multiple instances (e.g. dev, test, prod) can be specified * Templates (such as viewprint) can also be generated, and the links are fixed up appropritately - * Able to publish HTML and referenced files directly to a remote server via ftp (using the =ftp= publish format) - * generates a sitemal.xml, default.htm, index.html and google site verification file - * uses extra parameters (ftppublish, destinationftpserver, destinationftppath, destinationftpusername, destinationftppassword, googlefile, defaultpage) - * requires Net::FTP to ftp, only if ftppublish=ftp + * Able to publish HTML and referenced files directly to a remote server via ftp ---++ Usage ---+++ Publish Form @@ -124,21 +121,113 @@ <tr> <td>Output format</td> <td> - <select name="format" class="twikiSelect"> + <select name="format" class="twikiSelect" onchange="toggle('ftp','ftpoptions')"> <option value="">file</option> <option value="zip">zip</option> <option value="tgz">tgz</option> <option value="pdf">pdf</option> + <option value="ftp">ftp</option> </select><br /> *WARNING* The rendered data can get pretty big, and the process itself puts - a heavy load on the server when using compression on large webs. + a heavy load on the server, especially when using compression on large webs. </td> <td> =format= </td> </tr> <tr> - <td>Extra options</td> + <td>FTP options (only relevant if Output format is =ftp=) + +The FTP output format generates a sitemap.xml, and can also generate +default.htm, index.html and google site verification files. + +The format generator was written by TWiki:Main.SvenDowideit, who neglected +to document it, so these option descriptions are 'best guess'. +</td> + <td colspan=2> + <table class="twikiTable"> + <tr> + <td> + Destination FTP server + </td> + <td> + <input type="text" size="40" name="destinationftpserver" value="" /> + </td> + <td> + =destinationftpserver= + </td> + </tr> + <tr> + <td> + Path to upload to on server + </td> + <td> + <input type="text" size="40" name="destinationftppath" value="" /> + </td> + <td> + =destinationftppath= + </td> + </tr> + <tr> + <td> + FTP username + </td> + <td> + <input type="text" size="40" name="destinationftpusername" value="" /> + </td> + <td> + =destinationftpusername= + </td> + </tr> + <tr> + <td> + FTP Password + </td> + <td> + <input type="password" size="40" name="destinationftppassword" value="" /> + </td> + <td> + =destinationftppassword= + </td> + </tr> + <tr> + <td> + Google file + </td> + <td> + <input type="text" size="40" name="googlefile" value="" /> + </td> + <td> + =googlefile= + </td> + </tr> + <tr> + <td> + Name of topic to use to generate default.htm, index.html + </td> + <td> + <input type="text" size="40" name="defaultpage" value="" /> + </td> + <td> + =defaultpage= + </td> + </tr> + <tr> + <td> + Relative URL used in sitemap + </td> + <td> + <input type="text" size="40" name="relativeurl" value="" /> + </td> + <td> + =relativeurl= + </td> + </tr> + </table> + </td> +</tr> +<tr> + <td>Other extra options</td> <td> Some output generators support extra options (e.g. PDF; you can add =htmldoc= command-line parameters here e.g =--linkstyle underline=)<br /> <textarea rows="5" cols="80" class="twikiInputField">%URLPARAM{"genopt" default=""}%</textarea> @@ -168,6 +257,7 @@ ---+++ Regular Expressions A perl regular expression. You can use a simple string here, which will be matched exactly, or you can read up on perl regular expressions on the web. +#PublishTopic ---+++ Using a Publish Topic You can create a publish topic in a web that contains all the details needed to publish that web. This is just a topic with a series of standard TWiki variable settings in it. You can use the PublishWeb topic in this web as a template for your own topics. @@ -191,54 +281,46 @@ Another good trick is to set up a special "publishing" web. Create topics in the web that %INCLUDE the topics from *other* webs that you want to publish. You can use [[VarSTARTSECTION][STARTSECTION]] and [[VarENDSECTION][ENDSECTION]] to highlight what you want published. This way the "publishing" web gives you a view of exactly what will be in the published output, without the need for special publishing tags. ----++ Settings - * Name of the perl package - * Set STUB = %$STUB% - * Short description - * Set SHORTDESCRIPTION = Generate static HTML for a TWiki Web +<!-- +Required for admin + * Set STUB = %$STUB% + * Set SHORTDESCRIPTION = Generate static output (HTML, PDF) for a TWiki Web +--> ---++ Known problems * Doesn't handle revision info tags in templates * Plugin tags that create complex HTML (such as TWiki:Plugins/TWikiDrawPlugin =DRAWING= tags) are not handled correctly. - * Links to excluded topics still get generated as links + * Links to excluded topics still get generated as (broken) links ---++ Installation Instructions ---+++ Dependencies Note: If you want to generate PDF files, you will need an installation of =htmldoc=. =htmldoc= is available from http://www.easysw.com/htmldoc/ for free, but you are *strongly* recommended to buy the commercial version. Your support for OSS projects helps make OSS possible. - * Download and unpack the archive in your twiki installation directory. Contents: - | *File:* | *Description:* | -%$MANIFEST% - * =perl= ==%TOPIC%_installer.pl== =install= to automatically check and install other TWiki modules that this module depends on, and configure the plugin. This script also includes an =uninstall= option should you ever wish to remove the plugin from your installation, and an =upgrade= option that will automatically download and install the latest version of the add-on. - * If the install script fails for any reason, you may need to define the configuration yourself. Edit =LocalSite.cfg= and add the following lines: -<verbatim> -$TWiki::cfg{PublishContrib}{Dir} = "dir_path"; -$TWiki::cfg{PublishContrib}{URL} = "url_path"; -</verbatim> -Where =dir_path= is the file system path to your publish directory on the server, and =url_path= is the URL of the same directory. +%$INSTALL_INSTRUCTIONS% ---+++ Additional install steps +Run =configure= and complete the installation in the *PublishContrib* section. + ---++++ =PDF= output 1 install htmldoc from http://www.easysw.com/htmldoc/ - 1 Add the following line to =LocalSite.cfg= -<verbatim> -$TWiki::cfg{PublishContrib}{PDFCmd} = 'htmldoc --webpage --links --linkstyle plain --outfile %FILE|F% %EXTRAS|U% %FILES|F%'; -</verbatim> -Note that =htmldoc= can also be used to generate !PostScript by using the =-t= option in the =Generator Options= field above. See the =htmldoc= man pages for details. +Note that =htmldoc= can also be used to generate !PostScript by using the =-t= option in the =Other extra options= field above. See the =htmldoc= man pages for details. + ---++++ =.tgz= (tar) output 1 Install Archive::Tar and everything it depends on + ---++++ =.zip= output 1 Install Archive::Zip and everything it depends on ---++ Info -This add-on started as the TWiki:Plugins/GenHTMLAddon, written by TWiki:Main/CrawfordCurrie at Motorola. It was then rewritten by TWiki:Main/EricScouten, and then fixed and enhanced by TWiki:Main/CrawfordCurrie (http://c-dot.co.uk) +This add-on started as the TWiki:Plugins/GenHTMLAddon, written by TWiki:Main/CrawfordCurrie at Motorola. It was then rewritten by TWiki:Main/EricScouten, and then fixed and enhanced by TWiki:Main/CrawfordCurrie (http://c-dot.co.uk). It has been further extended by TWiki:Main/SvenDowideit and TWiki:Main/MartinCleaver. -| Authors: | TWiki:Main/CrawfordCurrie, TWiki:Main/EricScouten | +| Authors: | TWiki:Main/CrawfordCurrie, TWiki:Main/EricScouten, TWiki:Main.SvenDowideit, TWiki:Main.MartinCleaver| | Dependencies: | %$DEPENDENCIES% | | Version: | %$VERSION% | | Change History: | | +| 12708 | Added UI for FTP. Added .spec file. Fixed Bugs:Item3515 and Bugs:Item2725 | | 12028 | Michael Daum - create a new TWiki object for every topic, don't reuse the current one (Bugs:Item3139) | | 10412 | Correction to the correction for anchors. | | 10345 | Correction to support anchors in URLs properly | Modified: twiki/branches/MAIN/twikiplugins/PublishContrib/data/TWiki/PublishWeb.txt =================================================================== --- twiki/branches/MAIN/twikiplugins/PublishContrib/data/TWiki/PublishWeb.txt 2007-02-01 12:58:33 UTC (rev 12707) +++ twiki/branches/MAIN/twikiplugins/PublishContrib/data/TWiki/PublishWeb.txt 2007-02-01 15:49:26 UTC (rev 12708) @@ -1,4 +1,4 @@ -%META:TOPICINFO{author="TWikiContributor" date="1144227587" format="1.1" version="$Rev$"}% +%META:TOPICINFO{author="TWikiAdminGroup" date="1170262421" format="1.1" version="1.2"}% This is a template topic for use with PublishContrib. It illustrates how to set up a topic in a web to simplify publishing. @@ -29,4 +29,3 @@ <input type="hidden" name="ping" value="%SERVERTIME%" /> <input type="submit" class="twikiSubmit" value="Publish using this topic" /> </form> - Modified: twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/Publish.pm =================================================================== --- twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/Publish.pm 2007-02-01 12:58:33 UTC (rev 12707) +++ twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/Publish.pm 2007-02-01 15:49:26 UTC (rev 12708) @@ -12,7 +12,7 @@ # Copyright (C) 2001 Peter Thoeny, Peter@Thoeny.com # Copyright (C) 2001 Sven Dowideit, sv...@oz... # Copyright (C) 2001 Motorola Ltd. -# Copyright (C) 2005 Crawford Currie, http://c-dot.co.uk +# Copyright (C) 2005-2007 Crawford Currie, http://c-dot.co.uk # Copyright (C) 2006 Martin Cleaver, http://www.cleaver.org # # This program is free software; you can redistribute it and/or @@ -37,9 +37,6 @@ use vars qw( $VERSION $RELEASE $ob $cb $br $os $cs ); -# This should always be $Rev$ so that TWiki can determine the checked-in -# status of the plugin. It is used by the build automation tools, so -# you should leave it alone. $VERSION = '$Rev$'; $ob = ''; @@ -52,12 +49,9 @@ my $debug = 0; my $templatesWanted = 'view'; my $templateLocation = ""; #_PublishContrib"; # used to prefix alternate template renderings -my %templatesReferenced = (); # this determine which templates (e.g. view, viewprint, viuehandheld, etc) have been referred to and thus should be generated. +my %templatesReferenced = (); # this determines which templates (e.g. view, viewprint, viuehandheld, etc) have been referred to and thus should be generated. -# This is a free-form string you can use to "name" your own plugin version. -# It is *not* used by the build automation tools, but is reported as part -# of the version number in PLUGINDESCRIPTIONS. -$RELEASE = 'Dakar'; +$RELEASE = 'TWiki-4'; # Main rendering loop. sub publish { @@ -80,12 +74,12 @@ $session->{webName} = $web; $TWiki::Plugins::SESSION = $session; - + #don't add extra markup for topics we're not linking too - #NEWTOPICBGCOLOR, NEWTOPICFONTCOLOR NEWTOPICLINKSYMBOL LINKTOOLTIPINFO - $TWiki::Plugins::SESSION->{renderer}->{NEWLINKSYMBOL} = ''; - $TWiki::Plugins::SESSION->{renderer}->{NEWTOPICBGCOLOR} = ''; - $TWiki::Plugins::SESSION->{renderer}->{NEWTOPICFONTCOLOR} = ''; + #NEWTOPICBGCOLOR, NEWTOPICFONTCOLOR NEWTOPICLINKSYMBOL LINKTOOLTIPINFO + $TWiki::Plugins::SESSION->{renderer}->{NEWLINKSYMBOL} = ''; + $TWiki::Plugins::SESSION->{renderer}->{NEWTOPICBGCOLOR} = ''; + $TWiki::Plugins::SESSION->{renderer}->{NEWTOPICFONTCOLOR} = ''; my ($inclusions, $exclusions, $filter, $skin, $genopt, $format); $genopt = ''; @@ -168,8 +162,8 @@ mkdir($TWiki::cfg{PublishContrib}{Dir}, 0777); $ok = !($!); } - die "Can't publish because no useable publish directory was found. Please notify your TWiki administrator" unless -d $TWiki::cfg{PublishContrib}{Dir}; - die "Can't publish because publish URL was not set. Please notify your TWiki administrator" unless $TWiki::cfg{PublishContrib}{URL}; + die "Can't publish because no useable {PublishContrib}{Dir} was found. Please notify your TWiki administrator" unless -d $TWiki::cfg{PublishContrib}{Dir}; + die "Can't publish because {PublishContrib}{URL} was not set. Please notify your TWiki administrator" unless $TWiki::cfg{PublishContrib}{URL}; my $tmp = TWiki::Func::formatTime(time()); $tmp =~s/^(\d+)\s+(\w+)\s+(\d+).*/$1_$2_$3/g; @@ -211,7 +205,9 @@ my @templatesWanted = split /,/, $templatesWanted; foreach my $template (@templatesWanted) { - $template =~ s/^\s+//, s/\s+\z//; + next unless $template; + $template =~ s/^\s+//; + $template =~ s/\s+$//; $templatesReferenced{$template} = 1; print "-- template=$template$br" if $debug; my $dir = $TWiki::cfg{PublishContrib}{Dir}._dirForTemplate($template); @@ -223,7 +219,7 @@ '("'.$dir.'","'.$web.'","'. $genopt.'")'; die $@ if $@; - + $archive->{params} = $query->Vars; publishWeb($web, TWiki::Func::getWikiName(), $inclusions, @@ -238,14 +234,20 @@ if ($#difference > 0) { print "${ob}Templates Used = ",join(",", @templatesReferenced), "$br". "Templates Specified = ".join(",", @templatesWanted)."$br"; - print "${os}WARNING: there is a difference between what you specified and what you needed. Consider changing the TEMPLATES setting so it has all Templates Used.${cs}$br"; + print <<BLAH; +${os}WARNING: there is a difference between what you specified and what you +needed. Consider changing the TEMPLATES setting so it has all Templates +Used. $cs$br +BLAH } - my $text = 'Published to <a href="'. - $TWiki::cfg{PublishContrib}{URL}.'/'.$archive->{id}.'">'. - $archive->{id}.'</a>'."$br$br"; + my $landed = $archive->close(); - $archive->close(); + my $text = <<TEXT; +Published to <a href="$TWiki::cfg{PublishContrib}{URL}$landed"> +$landed +</a>$br$br +TEXT $text = TWiki::Func::expandCommonVariables( $text, $topic, $web ); $text = TWiki::Func::renderText( $text, $web ); @@ -255,8 +257,8 @@ print $footer; } -sub arrayDiff { # from http://perl.active-venture.com/pod/perlfaq4-dataarrays.html +sub arrayDiff { my ($array1, $array2) = @_; my (@union, @intersection, @difference); @union = @intersection = @difference = (); @@ -265,7 +267,7 @@ foreach my $element (keys %count) { push @union, $element; push @{ $count{$element} > 1 ? \@intersection : \@difference }, $element; - } + } return @difference; } @@ -308,7 +310,6 @@ } print $br; } - return } # Publish one topic from web. @@ -453,7 +454,6 @@ "---- Changed to $newLink$br" if $debug; $templatesReferenced{$template} = 1; return "href='$newLink'"; - } # Where alternative templates (e.g. viewprint) renderings end up @@ -620,7 +620,6 @@ my $link = shift; $link =~ s!<a .*?>!!gi; $link =~ s!</a>!!gi; - return $link; } Added: twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/Config.spec =================================================================== --- twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/Config.spec 2007-02-01 12:58:33 UTC (rev 12707) +++ twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/Config.spec 2007-02-01 15:49:26 UTC (rev 12708) @@ -0,0 +1,12 @@ +#---+ Publish Contrib +# **PATH** +# File path to the directory where published files will be generated. +# you will normally want this to be visible via a URL, so the TWiki +# pub directory is a good choice. +$TWiki::cfg{PublishContrib}{Dir} = '$TWiki::cfg{PubDir}/publish/'; +# **URL** +# URL path of the directory you defined above. +$TWiki::cfg{PublishContrib}{URL} = '$TWiki::cfg{PubUrl}/publish/'; +# **COMMAND** +# Command-line for the PDF generator program +$TWiki::cfg{PublishContrib}{PDFCmd} = 'htmldoc --webpage --links --linkstyle plain --outfile %FILE|F% %EXTRAS|U% %FILES|F%'; Modified: twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/DEPENDENCIES =================================================================== --- twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/DEPENDENCIES 2007-02-01 12:58:33 UTC (rev 12707) +++ twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/DEPENDENCIES 2007-02-01 15:49:26 UTC (rev 12708) @@ -1,6 +1,8 @@ -File::Spec,>=3.12,cpan,Required. Used to analyse URL paths. -Archive::Zip,>=1.05,cpan,Optional. Required to generate .zip output -Archive::Tar,>=1.29,cpan,Optional. Required to generate .tgz output -LWP,>=5.805,cpan,Optional. Used to include images referenced by absolute URL -Net::FTP,>=2.75,cpan,Optional. Used by ftp publishing to upload to ftp +File::Spec,>0,cpan,Required. Used to analyse URL paths. +File::Copy,>0,cpan,Required. Used to move files around. +File::Path,>0,cpan,Required to manipulate directories. +LWP,>0,cpan,Optional. Used to include images referenced by absolute URLs +Archive::Zip,>=0,cpan,Optional. Required to generate .zip output +Archive::Tar,>=0,cpan,Optional. Required to generate .tgz output +Net::FTP,>0,cpan,Optional. Required for ftp publishing. htmldoc,,c,Optional. Required to generate .pdf output Modified: twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/MANIFEST =================================================================== --- twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/MANIFEST 2007-02-01 12:58:33 UTC (rev 12707) +++ twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/MANIFEST 2007-02-01 15:49:26 UTC (rev 12708) @@ -1,10 +1,10 @@ -data/TWiki/PublishContrib.txt -data/TWiki/PublishWeb.txt -lib/TWiki/Contrib/Publish.pm -lib/TWiki/Contrib/PublishContrib/file.pm -lib/TWiki/Contrib/PublishContrib/zip.pm -lib/TWiki/Contrib/PublishContrib/tgz.pm -lib/TWiki/Contrib/PublishContrib/pdf.pm -lib/TWiki/Contrib/PublishContrib/PDFWriter.pm -lib/TWiki/Contrib/PublishContrib/ftp.pm -bin/publish +data/TWiki/PublishContrib.txt 0644 +data/TWiki/PublishWeb.txt 0644 +lib/TWiki/Contrib/Publish.pm 0444 +lib/TWiki/Contrib/PublishContrib/file.pm 0444 +lib/TWiki/Contrib/PublishContrib/zip.pm 0444 +lib/TWiki/Contrib/PublishContrib/tgz.pm 0444 +lib/TWiki/Contrib/PublishContrib/pdf.pm 0444 +lib/TWiki/Contrib/PublishContrib/ftp.pm 0444 +lib/TWiki/Contrib/PublishContrib/Config.spec 0444 +bin/publish 0555 Deleted: twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/PDFWriter.pm =================================================================== --- twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/PDFWriter.pm 2007-02-01 12:58:33 UTC (rev 12707) +++ twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/PDFWriter.pm 2007-02-01 15:49:26 UTC (rev 12708) @@ -1,54 +0,0 @@ -# PDF writer module for PublishContrib -# -# Copyright (C) 2005 Crawford Currie, http://c-dot.co.uk -# Copyright (C) 2006 Martin Cleaver, http://www.cleaver.org -# -# 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 -# -# PDF Writer module for PublishContrib -# - -use strict; - -package TWiki::Contrib::PublishContrib::PDFWriter; - -use Error qw( :try ); - -sub writePdf { - my $this = shift; - my ($pdf, $filesRef, $debug) = @_; - my $cmd = $TWiki::cfg{PublishContrib}{PDFCmd}; - die "{PublishContrib}{PDFCmd} not defined" unless $cmd; - my @extras = split( /\s+/, $this->{genopt} ); - my @args = ( FILE => $pdf, - FILES => $filesRef, - EXTRAS => \@extras); - - $ENV{HTMLDOC_DEBUG} = 1; # see man htmldoc - goes to apache err log - $ENV{HTMLDOC_NOCGI} = 1; # see man htmldoc - $TWiki::Plugins::SESSION->{sandbox}->{TRACE} = 1; - $this->{REAL_SAFE_PIPE_OPEN} = - $this->{EMULATED_SAFE_PIPE_OPEN} = 0; - - print "Running '".$cmd."'\n" if $debug; - my( $data, $exit ) = - $TWiki::Plugins::SESSION->{sandbox}->sysCommand( $cmd, @args ); - - # Dangerous to the point of being suicidal! Commented out by CC - # in response to Item3515. $this->{path} and $this->{web} are - # never set! - #File::Path::rmtree("$this->{path}/$this->{web}", 0, 1 ); - - die "htmldoc failed: $exit $data" if $exit; -} - -1; Modified: twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/file.pm =================================================================== --- twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/file.pm 2007-02-01 12:58:33 UTC (rev 12707) +++ twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/file.pm 2007-02-01 15:49:26 UTC (rev 12708) @@ -18,19 +18,16 @@ package TWiki::Contrib::PublishContrib::file; -use Error qw( :try ); +use File::Copy; +use File::Path; sub new { - my( $class, $path, $web ) = @_; + my( $class, $path, $web, $genopt ) = @_; my $this = bless( {}, $class ); $this->{path} = $path; $this->{web} = $web; - $this->{id} = $web; - $this->{root} = "$this->{path}/$web/WebHome.html"; + $this->{genopt} = $genopt; - eval "use File::Copy;use File::Path;"; - die $@ if $@; - File::Path::mkpath("$this->{path}/$web"); return $this; @@ -40,6 +37,7 @@ my( $this, $name ) = @_; my $d = "$this->{web}/$name"; File::Path::mkpath("$this->{path}/$d"); + push( @{$this->{dirs}}, $d ); } sub addString { @@ -48,14 +46,22 @@ open(F, ">$this->{path}/$f") || die "Cannot write $f: $!"; print F $string; close(F); + push( @{$this->{files}}, $f ); } sub addFile { my( $this, $from, $to ) = @_; - File::Copy::copy( $from, "$this->{path}/$this->{web}/$to" ); + my $f = "$this->{web}/$to"; + File::Copy::copy( $from, "$this->{path}/$f" ); + push( @{$this->{files}}, $f ); } sub close { + my $this = shift; + # Generate sitemap.html + my $links = join("<br />\n", + map { "<a href='$_'>$_</a>" } @{$this->{files}} ); + return $this->{web}; } 1; Modified: twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/ftp.pm =================================================================== --- twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/ftp.pm 2007-02-01 12:58:33 UTC (rev 12707) +++ twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/ftp.pm 2007-02-01 15:49:26 UTC (rev 12708) @@ -18,46 +18,30 @@ use strict; package TWiki::Contrib::PublishContrib::ftp; +use base 'TWiki::Contrib::PublishContrib::file'; -use Error qw( :try ); -use TWiki::Contrib::PublishContrib::file; - -my $debug = 1; -@TWiki::Contrib::PublishContrib::ftp::ISA = qw( TWiki::Contrib::PublishContrib::file ); - -sub new { - my( $class, $path, $web, $genopt, $baseUrl ) = @_; - my $this = bless( $class->SUPER::new( $path, $web , $genopt, $baseUrl), $class ); - - return $this; -} - sub addString { my( $this, $string, $file) = @_; filterHtml(\$string) if( $file =~ /\.html$/ ); $this->SUPER::addString( $string, $file ); - push( @{$this->{files}}, "$this->{path}/$this->{web}/$file" ); push( @{$this->{remotefiles}}, "$file" ); if( $file =~ /(.*)\.html?$/ ) { my $topic = $1; push( @{$this->{urls}}, "$file" ); - - #write link from index.html to actual topic - if ((defined($this->{params}->{defaultpage})) && - ($topic eq $this->{params}->{defaultpage})) { + #write link from index.html to actual topic + if ($this->{params}->{defaultpage} && + $topic eq $this->{params}->{defaultpage}) { $this->addString( $string, 'default.htm' ); $this->addString( $string, 'index.html' ); print '(default.htm, index.html)'; } } - } sub addFile { my( $this, $from, $to ) = @_; $this->SUPER::addFile( $from, $to ); - push( @{$this->{files}}, "$this->{path}/$this->{web}/$to" ); push( @{$this->{remotefiles}}, "$to" ); } @@ -69,9 +53,8 @@ $this->addString($sitemap, 'sitemap.xml'); print 'Published sitemap.xml<br />'; #write google verification files (comma seperated list) - if (defined($this->{params}->{googlefile})) { + if ($this->{params}->{googlefile}) { my @files = split(/[,\s]+/, $this->{params}->{googlefile}); - for my $file (@files) { my $simplehtml = '<html><title>'.$file.'</title><body>just for google</body></html>'; $this->addString($simplehtml, $file); @@ -79,25 +62,30 @@ } } - $this->SUPER::close(); - - #use LWP to ftp to server (ftppublish) - #TODO: clean up ftp site, removing/archiving/backing up old version - if ($this->{params}->{ftppublish} eq 'ftp') { - die "destinationftpserver param not defined" unless (defined($this->{params}->{destinationftpserver})); - die "destinationftppath param not defined" unless (defined($this->{params}->{destinationftppath})); - die "destinationftpusername param not defined" unless (defined($this->{params}->{destinationftpusername})); - die "destinationftppassword param not defined" unless (defined($this->{params}->{destinationftppassword})); - - #well, i'd love to use LWP, but it tells me "400 Library does not allow method POST for 'ftp:' URLs" + my $landed = $this->SUPER::close(); + # use LWP to ftp to server + # TODO: clean up ftp site, removing/archiving/backing up old version + if ($this->{params}->{destinationftpserver}) { + die "destinationftppath param not defined" + unless (defined($this->{params}->{destinationftppath})); + die "destinationftpusername param not defined" + unless (defined($this->{params}->{destinationftpusername})); + die "destinationftppassword param not defined" + unless (defined($this->{params}->{destinationftppassword})); + + $landed = $this->{params}->{destinationftpserver}; + + #well, i'd love to use LWP, but it tells me "400 Library does not + #allow method POST for 'ftp:' URLs" + require Net::FTP; - my $ftp = Net::FTP->new($this->{params}->{destinationftpserver}, Debug => 0) - or die "Cannot connect to $this->{params}->{destinationftpserver}: $@"; + my $ftp = Net::FTP->new($this->{params}->{destinationftpserver}, + Debug => 0) + or die "Cannot connect to $this->{params}->{destinationftpserver}: $@"; $ftp->login($this->{params}->{destinationftpusername}, $this->{params}->{destinationftppassword}) - or die "Cannot login ", $ftp->message; - + or die "Cannot login ", $ftp->message; $ftp->binary(); my $destinationftppath = $this->{params}->{destinationftppath}; @@ -107,7 +95,7 @@ if ( $destinationftppath ne '') { $ftp->mkdir($destinationftppath, 1); $ftp->cwd($destinationftppath) - or die "Cannot change working directory ", $ftp->message; + or die "Cannot change working directory ", $ftp->message; } my $fastUpload = $this->{params}->{fastupload} || 0; @@ -116,27 +104,24 @@ my $localfilePath = "$this->{path}/$this->{web}/$remoteFilename"; if ( $remoteFilename =~ /^\/?(.*\/)([^\/]*)$/ ) { $ftp->mkdir($1, 1) - or die "Cannot create directory ", $ftp->message; + or die "Cannot create directory ", $ftp->message; } - #TODO: this is a really crap way to reduce upload times #remote time and local times don't match, will have to base it on twiki revisions and sending a manifest #for eg, add username, topic mod date and rev to sitemap, and download and compare #and similar for big files - ie attachments. my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, - $atime,$mtime,$ctime,$blksize,$blocks) - = stat($localfilePath); + $atime,$mtime,$ctime,$blksize,$blocks) + = stat($localfilePath); my $remoteSize = $ftp->size($remoteFilename); my $remoteMTime = $ftp->mdtm($remoteFilename); - #print "($remoteMTime eq $mtime) && ($remoteSize eq $size) "; if (($fastUpload eq 1) && ($remoteSize eq $size) && (!( $remoteFilename =~ /(.*)\.html?$/ ))) { #file's already there print "<b>skipped</b> uploading $remoteFilename to $this->{params}->{destinationftpserver} <br />"; } else { $ftp->put($localfilePath, $remoteFilename) - or die "put failed ", $ftp->message; - + or die "put failed ", $ftp->message; print "<b>FTPed</b> $remoteFilename to $this->{params}->{destinationftpserver} <br />"; } } @@ -144,7 +129,7 @@ $ftp->quit; } - + return $landed; } #=============================================================================== @@ -167,11 +152,14 @@ my $topicTemplatePre = "<url>\n<loc>"; my $topicTemplatePost = "</loc>\n</url>"; -die "relativeurl param not defined" unless (defined($this->{params}->{relativeurl})); + die "relativeurl param not defined" unless (defined($this->{params}->{relativeurl})); - my $urls = join("\n", - map( {$topicTemplatePre.$this->{params}->{relativeurl}.'/'.$_.$topicTemplatePost."\n";} @$filesRef )); - + my $urls = join("\n", + map { + "$topicTemplatePre$this->{params}->{relativeurl}". + "/$this->{path}/$_$topicTemplatePost\n" + } @$filesRef ); + $map =~ s/%URLS%/$urls/; return $map; Modified: twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/pdf.pm =================================================================== --- twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/pdf.pm 2007-02-01 12:58:33 UTC (rev 12707) +++ twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/pdf.pm 2007-02-01 15:49:26 UTC (rev 12708) @@ -18,40 +18,50 @@ use strict; package TWiki::Contrib::PublishContrib::pdf; +use base 'TWiki::Contrib::PublishContrib::file'; -use Error qw( :try ); -use TWiki::Contrib::PublishContrib::file; -use TWiki::Contrib::PublishContrib::PDFWriter; - -@TWiki::Contrib::PublishContrib::pdf::ISA = qw( TWiki::Contrib::PublishContrib::file ); +use File::Path; -my $publishWeb; - sub new { my( $class, $path, $web, $genopt ) = @_; - my $this = bless( $class->SUPER::new( $path, "${web}_$$" ), $class ); - $this->{genopt} = $genopt; - $publishWeb = $web; - return $this; + return $class->SUPER::new( $path, "${web}_$$", $genopt ); } -sub addString { - my( $this, $string, $file) = @_; - $this->SUPER::addString( $string, $file ); - push( @{$this->{files}}, "$this->{path}/$this->{web}/$file" ) - if( $file =~ /\.html$/ ); -} +sub close { + my $this = shift; + my $dir = $this->{path}; + if ($this->{web} =~ m!^(.*)/.*?$!) { + $dir .= $1; + } + eval { File::Path::mkpath($dir) }; + die $@ if ($@); -sub addFile { - my( $this, $from, $to ) = @_; - $this->SUPER::addFile( $from, $to ); - push( @{$this->{files}}, "$this->{path}/$this->{web}/$to" ) - if( $to =~ /\.html$/ ); -} + my @files = map { "$this->{path}/$_" } + grep { /\.html$/ } @{$this->{files}}; -sub close { - my $this = shift; - TWiki::Contrib::PublishContrib::PDFWriter->writePdf( "$this->{path}/$publishWeb.pdf", \@{$this->{files}} ); + my $cmd = $TWiki::cfg{PublishContrib}{PDFCmd}; + die "{PublishContrib}{PDFCmd} not defined" unless $cmd; + + my $landed = "$this->{web}.pdf"; + my @extras = split( /\s+/, $this->{genopt} ); + + $ENV{HTMLDOC_DEBUG} = 1; # see man htmldoc - goes to apache err log + $ENV{HTMLDOC_NOCGI} = 1; # see man htmldoc + $TWiki::Plugins::SESSION->{sandbox}->{TRACE} = 1; + + my( $data, $exit ) = + $TWiki::Plugins::SESSION->{sandbox}->sysCommand( + $cmd, + FILE => "$this->{path}$landed", + FILES => \@files, + EXTRAS => \@extras ); + die "htmldoc failed: $exit/$data/$@" if $exit; + + # Get rid of the temporaries + unlink(@{$this->{files}}); + + die "htmldoc failed: $exit $data" if $exit; + return $landed; } 1; Modified: twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/tgz.pm =================================================================== --- twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/tgz.pm 2007-02-01 12:58:33 UTC (rev 12707) +++ twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/tgz.pm 2007-02-01 15:49:26 UTC (rev 12708) @@ -19,6 +19,7 @@ package TWiki::Contrib::PublishContrib::tgz; use TWiki::Func; +use File::Path; sub new { my( $class, $path, $web ) = @_; @@ -29,7 +30,6 @@ eval "use Archive::Tar"; die $@ if $@; $this->{tar} = Archive::Tar->new(); - $this->{id} = $this->{web}.'.tgz'; return $this; } @@ -54,7 +54,15 @@ sub close { my $this = shift; - $this->{tar}->write( "$this->{path}/$this->{id}", 1 ); + my $dir = $this->{path}; + if ($this->{web} =~ m!^(.*)/.*?$!) { + $dir .= $1; + } + eval { File::Path::mkpath($dir) }; + die $@ if ($@); + my $landed = "$this->{web}.tgz"; + $this->{tar}->write( "$this->{path}$landed", 1 ); + return $landed; } 1; Modified: twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/zip.pm =================================================================== --- twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/zip.pm 2007-02-01 12:58:33 UTC (rev 12707) +++ twiki/branches/MAIN/twikiplugins/PublishContrib/lib/TWiki/Contrib/PublishContrib/zip.pm 2007-02-01 15:49:26 UTC (rev 12708) @@ -19,6 +19,7 @@ package TWiki::Contrib::PublishContrib::zip; use TWiki::Func; +use File::Path; sub new { my( $class, $path, $web ) = @_; @@ -29,7 +30,6 @@ eval "use Archive::Zip qw( :ERROR_CODES :CONSTANTS )"; die $@ if $@; $this->{zip} = Archive::Zip->new(); - $this->{id} = $this->{web}.'.zip'; return $this; } @@ -51,7 +51,15 @@ sub close { my $this = shift; - $this->{zip}->writeToFileNamed( "$this->{path}/$this->{id}" ); + my $dir = $this->{path}; + if ($this->{web} =~ m!^(.*)/.*?$!) { + $dir .= $1; + } + eval { File::Path::mkpath($dir) }; + die $@ if ($@); + my $landed = "$this->{web}.zip"; + $this->{zip}->writeToFileNamed( "$this->{path}$landed" ); + return $landed; } 1; |