~kosova/+junk/tuxfamily-twiki

« back to all changes in this revision

Viewing changes to foswiki/lib/Foswiki/Plugins/SpreadSheetPlugin.pm

  • Committer: James Michael DuPont
  • Date: 2009-07-18 19:58:49 UTC
  • Revision ID: jamesmikedupont@gmail.com-20090718195849-vgbmaht2ys791uo2
added foswiki

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
 
2
#
 
3
# Copyright (C) 2001-2007 Peter Thoeny, peter@thoeny.org
 
4
# Copyright (C) 2008-2009 Foswiki Contributors
 
5
#
 
6
# This program is free software; you can redistribute it and/or
 
7
# modify it under the terms of the GNU General Public License
 
8
# as published by the Free Software Foundation; either version 2
 
9
# of the License, or (at your option) any later version. For
 
10
# more details read LICENSE in the root of this distribution.
 
11
#
 
12
# This program is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
# GNU General Public License for more details, published at
 
16
# http://www.gnu.org/copyleft/gpl.html
 
17
#
 
18
# As per the GPL, removal of this notice is prohibited.
 
19
#
 
20
# =========================
 
21
#
 
22
# This is Foswiki's Spreadsheet Plugin.
 
23
#
 
24
 
 
25
package Foswiki::Plugins::SpreadSheetPlugin;
 
26
 
 
27
 
 
28
# =========================
 
29
use vars qw(
 
30
        $web $topic $user $installWeb $debug $skipInclude $doInit
 
31
    );
 
32
 
 
33
our $VERSION = '$Rev: 3890 (2009-05-11) $';
 
34
our $RELEASE = '11 May 2009';
 
35
our $NO_PREFS_IN_TOPIC = 1;
 
36
our $SHORTDESCRIPTION = 'Add spreadsheet calculations like "$SUM($ABOVE())" to Foswiki tables and other topic text';
 
37
 
 
38
$doInit = 0;
 
39
 
 
40
# =========================
 
41
sub initPlugin
 
42
{
 
43
    ( $topic, $web, $user, $installWeb ) = @_;
 
44
 
 
45
    # check for Plugins.pm versions
 
46
    if( $Foswiki::Plugins::VERSION < 1 ) {
 
47
        Foswiki::Func::writeWarning( "Version mismatch between SpreadSheetPlugin and Plugins.pm" );
 
48
        return 0;
 
49
    }
 
50
 
 
51
    # Get plugin debug flag
 
52
    $debug = Foswiki::Func::getPreferencesFlag( "SPREADSHEETPLUGIN_DEBUG" ) || 0;
 
53
 
 
54
    # Flag to skip calc if in include
 
55
    $skipInclude = Foswiki::Func::getPreferencesFlag( "SPREADSHEETPLUGIN_SKIPINCLUDE" ) || 1;
 
56
 
 
57
    # Plugin correctly initialized
 
58
    Foswiki::Func::writeDebug( "- Foswiki::Plugins::SpreadSheetPlugin::initPlugin( $web.$topic ) is OK" ) if $debug;
 
59
    $doInit = 1;
 
60
    return 1;
 
61
}
 
62
 
 
63
# =========================
 
64
sub commonTagsHandler
 
65
{
 
66
### my ( $text, $topic, $web ) = @_;   # do not uncomment, use $_[0], $_[1]... instead
 
67
 
 
68
    Foswiki::Func::writeDebug( "- SpreadSheetPlugin::commonTagsHandler( $_[2].$_[1] )" ) if $debug;
 
69
 
 
70
    if( ( $_[3] ) && ( $skipInclude ) ) {
 
71
        # bail out, handler called from an %INCLUDE{}%
 
72
        return;
 
73
    }
 
74
    unless( $_[0] =~ /%CALC\{.*?\}%/ ) {
 
75
        # nothing to do
 
76
        return;
 
77
    }
 
78
 
 
79
    require Foswiki::Plugins::SpreadSheetPlugin::Calc;
 
80
 
 
81
    if( $doInit ) {
 
82
        $doInit = 0;
 
83
        Foswiki::Plugins::SpreadSheetPlugin::Calc::init( $web, $topic, $debug );
 
84
    }
 
85
    Foswiki::Plugins::SpreadSheetPlugin::Calc::CALC( @_ );
 
86
}
 
87
 
 
88
1;
 
89
 
 
90
# EOF