1 # Plugin for TWiki Enterprise Collaboration Platform, http://TWiki.org/
3 # Copyright (C) 2000-2003 Andrea Sterbini, a.sterbini@flashnet.it
4 # Copyright (C) 2001-2006 Peter Thoeny, peter@thoeny.org
5 # and TWiki Contributors. All Rights Reserved. TWiki Contributors
6 # are listed in the AUTHORS file in the root of this distribution.
7 # NOTE: Please extend that file, not this notice.
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License
11 # as published by the Free Software Foundation; either version 2
12 # of the License, or (at your option) any later version. For
13 # more details read LICENSE in the root of this distribution.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 # For licensing info read LICENSE file in the TWiki root.
20 # change the package name and $pluginName!!!
22 package TWiki
::Contrib
::ObjaviContrib
;
24 # Always use strict to enforce variable scoping
27 require TWiki
::Func
; # The plugins API
28 require TWiki
::Plugins
; # For the API version
30 # $VERSION is referred to by TWiki, and is the only global variable that
31 # *must* exist in this package.
32 use vars
qw( $VERSION $RELEASE $SHORTDESCRIPTION $debug $pluginName $NO_PREFS_IN_TOPIC );
34 use File::Temp qw/ tempfile /;
35 use List::Compare::Functional qw( get_unique );
37 # This should always be $Rev$ so that TWiki can determine the checked-in
38 # status of the plugin. It is used by the build automation tools, so
39 # you should leave it alone.
42 # This is a free-form string you can use to "name" your own plugin version.
43 # It is *not* used by the build automation tools, but is reported as part
44 # of the version number in PLUGINDESCRIPTIONS.
45 $RELEASE = 'TWiki-4.2';
47 # Short description of this plugin
48 # One line description, is shown in the %TWIKIWEB%.TextFormattingRules topic:
49 $SHORTDESCRIPTION = 'Empty Plugin used as a template for new Plugins';
51 # You must set $NO_PREFS_IN_TOPIC to 0 if you want your plugin to use preferences
52 # stored in the plugin topic. This default is required for compatibility with
53 # older plugins, but imposes a significant performance penalty, and
54 # is not recommended. Instead, use $TWiki::cfg entries set in LocalSite.cfg, or
55 # if you want the users to be able to change settings, then use standard TWiki
56 # preferences that can be defined in your Main.TWikiPreferences and overridden
57 # at the web and topic level.
58 $NO_PREFS_IN_TOPIC = 1;
60 # Name of this Plugin, only used in this module
61 $pluginName = 'ObjaviContrib';
68 ---++ initPlugin($topic, $web, $user, $installWeb) -> $boolean
69 * =$topic= - the name of the topic in the current CGI query
70 * =$web= - the name of the web in the current CGI query
71 * =$user= - the login name of the user
72 * =$installWeb= - the name of the web the plugin is installed in
76 Called to initialise the plugin. If everything is OK, should return
77 a non-zero value. On non-fatal failure, should write a message
78 using TWiki::Func::writeWarning and return 0. In this case
79 %FAILEDPLUGINS% will indicate which plugins failed.
81 In the case of a catastrophic failure that will prevent the whole
82 installation from working safely, this handler may use 'die', which
83 will be trapped and reported in the browser.
85 You may also call =TWiki::Func::registerTagHandler= here to register
86 a function to handle variables that have standard TWiki syntax - for example,
87 =%MYTAG{"my param" myarg="My Arg"}%. You can also override internal
88 TWiki variable handling functions this way, though this practice is unsupported
91 __Note:__ Please align variables names with the Plugin name, e.g. if
92 your Plugin is called FooBarPlugin, name variables FOOBAR and/or
93 FOOBARSOMETHING. This avoids namespace issues.
99 my( $topic, $web, $user, $installWeb ) = @_;
101 # check for Plugins.pm versions
102 if( $TWiki::Plugins
::VERSION
< 1.026 ) {
103 TWiki
::Func
::writeWarning
( "Version mismatch between $pluginName and Plugins.pm" );
107 # my $setting = $TWiki::cfg{Plugins}{EmptyPlugin}{ExampleSetting} || 0;
108 # $debug = $TWiki::cfg{Plugins}{EmptyPlugin}{Debug} || 0;
111 ## TWiki::Func::registerRESTHandler('example', \&restExample);
118 ---++ restExample($session) -> $text
120 This is an example of a sub to be called by the =rest= script. The parameter is:
121 * =$session= - The TWiki object associated to this session.
123 Additional parameters can be recovered via de query object in the $session.
125 For more information, check TWiki:TWiki.TWikiScripts#rest
127 *Since:* TWiki::Plugins::VERSION 1.1
133 return "This is an example of a REST invocation\n\n";
138 my ($webName, $userName, $thePathInfo, $query) = @_;
140 my $htmlData = <<END;
143 <title>OBJAVI!</title>
144 <meta http-equiv="Content-Type" content="text/html; charset=en_GB" />
145 <meta name="robots" content="noindex" />
146 <link rel="icon" href="http://www.flossmanuals.net/pub/TWiki//FlossSkin2/fl2.ico" type="image/x-icon" /> <link rel="shortcut icon" href="http://www.flossmanuals.net/pub/TWiki/FlossSkin2/fl2.ico" type="image/x-icon" />
147 <link rel=StyleSheet href="http://www.flossmanuals.net/pub/TWiki/FlossSkin2/typography_cover.css" type="text/css" media="screen"/>
148 <style type="text/css">
166 url('http://www.flossmanuals.net/pub/TWiki/FlossSkin2/header_bg.gif');
167 background-position: 600px 0px; /* this places the orange background at
168 an offset, making sure it doesn't underlap the left side of the gif */
169 background-repeat: no-repeat;
186 </head><body background="http://www.flossmanuals.net/pub/TWiki/FlossSkin2/background.gif" style="margin:0;color:#000000;text-decoration:none;">
187 <div id="header"><img id="header_imagemap" width="465" height="95" alt="FlossManuals menu" src='http://www.flossmanuals.net/pub/TWiki/FlossSkin2/objavib_entireheader4.gif' border=0 usemap='#map'></div>
189 <div style="position:absolute;left:270px;top:130px;">
190 <table cellpadding="0" cellspacing="0" summary="" style="table-layout:fixed;width:730;border: 5px solid #666666;padding-right: 0px;padding-left: 0px;padding-bottom: 0px;padding-top: 0px;margin-left : 10px;margin-top:10;background:#FFF7F0;">
193 <div class="ds-contentcontainer">
194 <div style="margin-left:1.2em;">
196 <img src="http://www.flossmanuals.net/pub/TWiki/FlossSkin2/objavib.gif">
198 This is the BETA publisher for FLOSS Manuals. Using OBJAVI you can export your manual to print ready source for upload and sale on Lulu.com
200 All design is managed by CSS. You can alter the CSS in the below text box and the PDF will be formatted accordingly. </p><p>This site is for testing only.
206 <form action="" method="POST">
208 <select name="webName">
211 my @websList = TWiki
::Func
::getListOfWebs
("user, public");
213 my @websExclude = split /,/, TWiki
::Func
::getPreferencesValue
( "REMIXWEBEXCLUDE", "Main");
215 foreach my $web (get_unique
([\
@websList, \
@websExclude ])) {
216 $htmlData .= '<option value="'.$web.'">'.$web.'</option>';
224 Text for Title page :<br>
225 <input type="text" name="title" />
229 <input type="text" name="header" />
233 <input type="text" name="license" value="GPL"/>
235 ISBN Number (optional) :
237 <input type="text" name="isbn" />
242 <textarea name="css" cols="60" rows="20">
245 open(DT
, "</var/www/floss/pub/TWiki/Pisa/fm-book.css");
253 <button>OBJAVI!</button>
255 </div></td></tr></table>
261 print "Content-Type: text/html\r\n\r\n";
267 my ($web, $num_heading, @chapters) = @_;
271 $htmlData .= "</div></fmsection><p></p>\n";
274 foreach my $a (@chapters) {
275 my $topicData = TWiki
::Func
::readTopicText
($web, $a);
277 $topicData = TWiki
::Func
::expandCommonVariables
($topicData, "neki topic", $web);
278 $topicData = TWiki
::Func
::renderText
($topicData, $web);
281 foreach my $line (split(/\n/,$topicData)) {
282 # if($line =~ /<h1>(.+)<\/h1>/) {
283 if($line =~ /<h1>(.+)/) {
284 $s .= '<h1><span class="fminitial">'.($num_heading+$n).'.</span> '.$1.'';
289 $line =~ s/%META:\w+{.*?}%//gs;
290 $line =~ s/src=\"/src=\"\/var\
/www/gs;
298 (undef, $filename) = tempfile
("/tmp/objaviXXXXX", UNLINK
=> 0);
299 (undef, $filename2) = tempfile
("/tmp/objaviXXXXX", UNLINK
=> 0);
301 open(DT
, ">$filename");
305 my @args = ('/usr/bin/tidy', "-q", "-f", "/dev/null", "-o", "$filename2", "$filename");
310 open(DT
, "<$filename2");
319 # if($s2 =~ /.*\<body\>(.+)\<\/body\>.*/) {
334 my ($webName, $userName, $thePathInfo, $query) = @_;
338 #print "Content-type: text/plain\r\n\r\n";
339 print "Content-type: application/pdf\r\nContent-Disposition: attachment; filename=\"fm.pdf\"\r\n\r\n";
341 my $web = $query->param("webName");
342 my $customCss =$query->param("css");
343 my $customTitle =$query->param("title");
344 my $customHeader =$query->param("header");
345 my $customISBN =$query->param("isbn");
346 my $customLicense =$query->param("license");
348 my $tocData = TWiki
::Func
::readAttachment
( $web, "_index", "TOC.txt");
349 my $current_heading = 1;
352 my @lines = split /\n/, $tocData;
355 for(my $i = 0; $i < (@lines/3); $i++) {
356 my $topicName = $lines[$i*3+1];
357 my $description = $lines[$i*3+2];
358 my $topicID = $lines[$i*3];
360 if($topicID eq "0") {
362 if($current_heading+$num_heading != 1) {
363 $htmlData .= _showHeading
($web, $current_heading, @chapters);
366 $current_heading = $current_heading + $num_heading;
370 # $current_heading = $current_heading + $num_heading;
374 $htmlData .= "<fmsection>\n";
375 $htmlData .= '<h0>'.$description."</h0>\n";
376 $htmlData .= '<div class="fmtoc">';
379 } elsif($topicID eq "1") {
380 push @chapters, $topicName;
381 $htmlData .= ($current_heading+$num_heading).'. '.$description.'<br/>';
387 $htmlData .= _showHeading
($web, $current_heading, @chapters);
389 my $tmpl = TWiki
::Func
::readTemplate
("basic", "pisa");
391 $tmpl =~ s/%%BODY%%/$htmlData/gs;
392 $tmpl =~ s/%%STYLE%%/$customCss/gs;
393 $tmpl =~ s/%%CUSTOMHEADER%%/$customHeader/gs;
394 $tmpl =~ s/%%CUSTOMTITLE%%/$customTitle/gs;
395 $tmpl =~ s/%%CUSTOMISBN%%/$customISBN/gs;
396 $tmpl =~ s/%%CUSTOMLICENSE%%/$customLicense/gs;
399 $tmpl = TWiki
::Func
::expandCommonVariables
($tmpl, "neki topic", $web);
400 $tmpl = TWiki
::Func
::renderText
($tmpl, $web);
402 # my $willchange=$TWiki::cfg{"InstallDirectory"}";
403 my $willchange = "/var/www/floss";
404 my (undef, $filename) = tempfile
("$willchange/pub/TWiki/Pisa/objaviXXXXX", UNLINK
=> 0);
406 open(FH
, ">$filename");
412 my @args = ('/var/www/floss/pub/TWiki/Pisa/objavi.sh', $filename);
413 #my @args = ('/usr/bin/python2.4', 'pisa/pisa.py', "-x", $filename, "-" );
414 #chdir("$willchange/pub/TWiki/Pisa/");
415 system(@args) or print STDERR
"couldn't exec pisa: $!";
416 # disabled for debugging - lf
419 #00:43 < fileneed> cd /var/www/floss_clean/pub/TWiki/Pisa
420 #00:43 < fileneed> python2.4 pisa-3.0.19-fm/pisa.py -x index.xhtml