-
Notifications
You must be signed in to change notification settings - Fork 38
/
SpreadSheetPlugin.pm
executable file
·125 lines (97 loc) · 3.75 KB
/
SpreadSheetPlugin.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# See bottom of file for license and copyright information
#
# This is Foswiki's Spreadsheet Plugin.
package Foswiki::Plugins::SpreadSheetPlugin;
use strict;
use warnings;
# =========================
use vars qw(
$web $topic $user $installWeb $debug $skipInclude $doneInit
);
our $VERSION = '1.25';
our $RELEASE = '17 May 2023';
our $NO_PREFS_IN_TOPIC = 1;
our $SHORTDESCRIPTION =
'Add spreadsheet calculations like "$SUM($ABOVE())" to Foswiki tables and other topic text';
$doneInit = 0;
# =========================
sub initPlugin {
( $topic, $web, $user, $installWeb ) = @_;
# check for Plugins.pm versions
if ( $Foswiki::Plugins::VERSION < 1 ) {
Foswiki::Func::writeWarning(
"Version mismatch between SpreadSheetPlugin and Plugins.pm");
return 0;
}
# Get plugin debug flag
$debug = Foswiki::Func::getPreferencesFlag("SPREADSHEETPLUGIN_DEBUG") || 0;
# Following code is for a registered tag handler that does the same as
# CALC but in a tag handler instead of in commonTagsHandler. That means
# you can't use table references, but you can rely on the execution order
# relative to other macros.
Foswiki::Func::registerTagHandler(
"CALCULATE",
sub {
my ( $session, $attributes, $topic, $web ) = @_;
init( $web, $topic, $debug );
$Foswiki::Plugins::SpreadSheetPlugin::Calc::rPos = 0;
$Foswiki::Plugins::SpreadSheetPlugin::Calc::cPos = 0;
return Foswiki::Plugins::SpreadSheetPlugin::Calc::_doCalc(
$attributes->{_DEFAULT} );
}
);
# Flag to skip calc if in include
$skipInclude =
Foswiki::Func::getPreferencesFlag("SPREADSHEETPLUGIN_SKIPINCLUDE");
my $skipIncludePref =
Foswiki::Func::getPreferencesValue("SPREADSHEETPLUGIN_SKIPINCLUDE");
$skipInclude = 1 unless defined $skipIncludePref && $skipIncludePref ne '';
# Plugin correctly initialized
Foswiki::Func::writeDebug(
"- Foswiki::Plugins::SpreadSheetPlugin::initPlugin( $web.$topic ) is OK"
) if $debug;
$doneInit = 0;
return 1;
}
# =========================
sub init {
return if $doneInit;
$doneInit = 1;
require Foswiki::Plugins::SpreadSheetPlugin::Calc;
Foswiki::Plugins::SpreadSheetPlugin::Calc::init(@_);
}
# =========================
sub commonTagsHandler {
### my ( $text, $topic, $web ) = @_; # do not uncomment, use $_[0], $_[1]... instead
Foswiki::Func::writeDebug(
"- SpreadSheetPlugin::commonTagsHandler( $_[2].$_[1] )")
if $debug;
if ( ( $_[3] ) && ($skipInclude) ) {
# bail out, handler called from an %INCLUDE{}%
return;
}
unless ( $_[0] =~ m/%CALC\{.*?\}%/ ) {
# nothing to do
return;
}
init( $web, $topic, $debug );
Foswiki::Plugins::SpreadSheetPlugin::Calc::CALC(@_);
}
1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2017 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Additional copyrights apply to some or all of the code in this
file as follows:
Copyright (C) 2001-2007 Peter Thoeny, peter@thoeny.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. 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.
As per the GPL, removal of this notice is prohibited.