-
Notifications
You must be signed in to change notification settings - Fork 2
/
RtfContrib.pm
84 lines (67 loc) · 2.35 KB
/
RtfContrib.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Plugin for Foswiki Collaboration Platform, http://foswiki.org/
#
# Copyright (C) 2007-2016 MichaelDaum http://michaeldaumconsulting.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. For
# more details read LICENSE in the root of this distribution.
#
# 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.
package Foswiki::Contrib::RtfContrib;
use strict;
use warnings;
our $VERSION = '2.11';
our $RELEASE = '09 Sep 2016';
our $SHORTDESCRIPTION = 'Extension to translate Foswiki markup to RTF';
################################################################################
sub export {
my $session = shift;
$Foswiki::Plugins::SESSION = $session;
my $query = Foswiki::Func::getCgiQuery();
my $converterName = $query->param('converter');
my $impl;
if ($converterName) {
$impl =
$Foswiki::cfg{RtfContrib}{Converters}{$converterName} ||
$Foswiki::cfg{RtfContrib}{Converters}{$converterName} ;
}
# create a new converter
my $converter = newConverter($session, $impl);
# generate the rtf
my ($result, $errorMsg) = $converter->genRtf();
if ($errorMsg) {
$session->writeCompletePage("ERROR: $errorMsg\n\n", 'view');
return;
}
# write the rtf file
$converter->cacheRtf($result);
# prepair the answer to the request
my $viewNow = $query->param('view') || '';
$viewNow = ($viewNow eq 'on')?1:0;
if ($viewNow) {
$session->writeCompletePage($result, 'rtf', 'application/rtf');
} else {
my $url =
$session->getScriptUrl(1, 'oops', $converter->{web}, $converter->{topic},
template => 'oopsrtf',
param1 => $converter->getUrlName(),
);
$session->redirect($url);
}
}
################################################################################
sub newConverter {
my ($session, $impl) = @_;
$impl ||= $Foswiki::cfg{RtfContrib}{DefaultConverter}
|| $Foswiki::cfg{RtfContrib}{DefaultConverter}
|| 'Foswiki::Contrib::RtfContrib::Converter';
#print STDERR "impl=$impl\n";
eval 'use '.$impl;
die $@ if $@;
return $impl->new($session);
}
1;